From d25153e4fcf14750d074f0cfab8e073195e06fbe Mon Sep 17 00:00:00 2001 From: Lars Kusch Date: Sun, 29 Dec 2024 07:59:23 +0100 Subject: [PATCH] Fixes Signed-off-by: Lars Kusch --- custom_components/solvis_control/config_flow.py | 14 ++++++++------ custom_components/solvis_control/diagonstics.py | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/custom_components/solvis_control/config_flow.py b/custom_components/solvis_control/config_flow.py index 57c063f..f393e5b 100644 --- a/custom_components/solvis_control/config_flow.py +++ b/custom_components/solvis_control/config_flow.py @@ -133,7 +133,7 @@ async def async_step_user(self, user_input: ConfigType | None = None) -> FlowRes self._abort_if_unique_id_configured() modbussocket = ModbusClient.AsyncModbusTcpClient(host=user_input[CONF_HOST], port=user_input[CONF_PORT]) try: - await self.modbus.connect() + await modbussocket.connect() _LOGGER.debug("Connected to Modbus for Solvis") except ConnectionException as exc: errors["base"] = "cannot_connect" @@ -145,11 +145,12 @@ async def async_step_user(self, user_input: ConfigType | None = None) -> FlowRes return self.async_show_form(step_id="user", data_schema=get_host_schema_config(self.data), errors=errors) else: versionsc = await modbussocket.read_input_registers(32770, 1, 1) - versionsc = str(BinaryPayloadDecoder.fromRegisters(versionsc, byteorder=Endian.BIG).decode_16bit_int()) + versionsc = str(BinaryPayloadDecoder.fromRegisters(versionsc.registers, byteorder=Endian.BIG).decode_16bit_int()) versionnbg = await modbussocket.read_input_registers(32771, 1, 1) - versionnbg = str(BinaryPayloadDecoder.fromRegisters(versionnbg, byteorder=Endian.BIG).decode_16bit_int()) + versionnbg = str(BinaryPayloadDecoder.fromRegisters(versionnbg.registers, byteorder=Endian.BIG).decode_16bit_int()) user_input["VERSIONSC"] = f"{versionsc[0]}.{versionnbg[1:3]}.{versionsc[3:5]}" user_input["VERSIONNBG"] = f"{versionnbg[0]}.{versionnbg[1:3]}.{versionnbg[3:5]}" + modbussocket.close() return await self.async_step_device() return self.async_show_form(step_id="user", data_schema=get_host_schema_config(self.data), errors=errors) @@ -205,7 +206,7 @@ async def async_step_init(self, user_input: ConfigType | None = None) -> FlowRes self.data.update(user_input) modbussocket: ModbusClient.AsyncModbusTcpClient = ModbusClient.AsyncModbusTcpClient(host=user_input[CONF_HOST], port=user_input[CONF_PORT]) try: - await self.modbus.connect() + await modbussocket.connect() _LOGGER.debug("Connected to Modbus for Solvis") except ConnectionException as exc: errors["base"] = "cannot_connect" @@ -217,11 +218,12 @@ async def async_step_init(self, user_input: ConfigType | None = None) -> FlowRes return self.async_show_form(step_id="user", data_schema=get_host_schema_config(self.data), errors=errors) else: versionsc = await modbussocket.read_input_registers(32770, 1, 1) - versionsc = str(BinaryPayloadDecoder.fromRegisters(versionsc, byteorder=Endian.BIG).decode_16bit_int()) + versionsc = str(BinaryPayloadDecoder.fromRegisters(versionsc.registers, byteorder=Endian.BIG).decode_16bit_int()) versionnbg = await modbussocket.read_input_registers(32771, 1, 1) - versionnbg = str(BinaryPayloadDecoder.fromRegisters(versionnbg, byteorder=Endian.BIG).decode_16bit_int()) + versionnbg = str(BinaryPayloadDecoder.fromRegisters(versionnbg.registers, byteorder=Endian.BIG).decode_16bit_int()) user_input["VERSIONSC"] = f"{versionsc[0]}.{versionnbg[1:3]}.{versionsc[3:5]}" user_input["VERSIONNBG"] = f"{versionnbg[0]}.{versionnbg[1:3]}.{versionnbg[3:5]}" + modbussocket.close() return await self.async_step_device() return self.async_show_form( diff --git a/custom_components/solvis_control/diagonstics.py b/custom_components/solvis_control/diagonstics.py index 5c5cfc9..9132d2d 100644 --- a/custom_components/solvis_control/diagonstics.py +++ b/custom_components/solvis_control/diagonstics.py @@ -12,7 +12,7 @@ async def async_get_config_entry_diagnostics(hass: HomeAssistant, entry: ConfigE return { "entry_data": entry.data, - "data": entry.runtime_data.data, + "data": "", }