import logging


class ModbusClient:
    def __init__(self, *args, **kwargs):
        # print(__name__, "initialized with", args, kwargs, flush=True)
        self.log = logging.getLogger(f"{self.__class__.__name__} ({id(self)}) (dummy)")
        self.log.debug(f"__init__(*{args}, **{kwargs})")

    def connect(self):
        self._is_socket_open = True
        return self._is_socket_open

    def read_holding_registers(self, r, count=1, unit=None):
        # print(__name__, unit, str(r) + "-" + str(r + count - 1), "read", flush=True)
        return Readout([0] * count)

    def write_register(self, register, data, unit=None, **kwargs):
        self.log.debug(f"{unit}->{register} ({kwargs}) write: {data}, ", flush=True)
        return Readout()

    def write_registers(self, registers, data, unit=None, **kwargs):
        self.log.debug(f"{unit}->{registers} ({kwargs}) write: {data}, ", flush=True)
        return Readout()

    def close(self):
        self._is_socket_open = False

    def is_socket_open(self):
        return self._is_socket_open


class Readout:
    def __init__(self, data=None):
        self.registers = data

    def isError(self):
        return False
