# Path: thingsboard_gateway/connectors/connector.py
# class Connector(ABC):
#     def open(self):
#     def close(self):
#     def get_name(self):
#     def is_connected(self):
#     def on_attributes_update(self, content):
#     def server_side_rpc_handler(self, content):


from simplejson import dumps
from thingsboard_gateway.connectors.connector import log
#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.




class BackwardCompatibilityAdapter:
    config_files_count = 1
    CONFIG_PATH = None

    def __init__(self, config, config_dir):
        self.__config = config
        self.__config_dir = config_dir
        BackwardCompatibilityAdapter.CONFIG_PATH = self.__config_dir
        self.__keys = ['host', 'port', 'type', 'method', 'timeout', 'byteOrder', 'wordOrder', 'retries', 'retryOnEmpty',
                       'retryOnInvalid', 'baudrate']

    @staticmethod
    def __save_json_config_file(config):
        with open(
                f'{BackwardCompatibilityAdapter.CONFIG_PATH}modbus_new_{BackwardCompatibilityAdapter.config_files_count}.json',
                'w') as file:
            file.writelines(dumps(config, sort_keys=False, indent='  ', separators=(',', ': ')))
        BackwardCompatibilityAdapter.config_files_count += 1

    def convert(self):
        if not self.__config.get('server'):
            return self.__config


# Path: thingsboard_gateway/connectors/connector.py
# class Connector(ABC):
#     def open(self):
#     def close(self):
#     def get_name(self):
#     def is_connected(self):
#     def on_attributes_update(self, content):
#     def server_side_rpc_handler(self, content):


# Path: thingsboard_gateway/connectors/modbus/backward_compability_adapter.py
from simplejson import dumps
from thingsboard_gateway.connectors.connector import log

#     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#     See the License for the specific language governing permissions and
#     limitations under the License.




class BackwardCompatibilityAdapter:
    config_files_count = 1
    CONFIG_PATH = None

    def __init__(self, config, config_dir):
        self.__config = config
        self.__config_dir = config_dir
        BackwardCompatibilityAdapter.CONFIG_PATH = self.__config_dir
        self.__keys = ['host', 'port', 'type', 'method', 'timeout', 'byteOrder', 'wordOrder', 'retries', 'retryOnEmpty',
                       'retryOnInvalid', 'baudrate']

    @staticmethod
    def __save_json_config_file(config):
        with open(
                f'{BackwardCompatibilityAdapter.CONFIG_PATH}modbus_new_{BackwardCompatibilityAdapter.config_files_count}.json',
                'w') as file:
            file.writelines(dumps(config, sort_keys=False, indent='  ', separators=(',', ': ')))
        BackwardCompatibilityAdapter.config_files_count += 1

    def convert(self):
        if not self.__config.get('server'):
            return self.__config


        log.warning(