Skip to content

Commit

Permalink
Feature/2024.05 (#54)
Browse files Browse the repository at this point in the history
* fixes for HA 20240.05
  • Loading branch information
Pho3niX90 committed May 3, 2024
1 parent 1a14feb commit 1a4162a
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion custom_components/solis_modbus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""The Modbus Integration."""
import asyncio
import logging

import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solis_modbus/const.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DOMAIN = "solis_modbus"
CONTROLLER = "modbus_controller"
VERSION = "1.4.6"
VERSION = "1.4.7"
POLL_INTERVAL_SECONDS = 15
MANUFACTURER = "Solis"
MODEL = "S6"
4 changes: 2 additions & 2 deletions custom_components/solis_modbus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/Pho3niX90/solis_modbus/issues",
"quality_scale": "silver",
"requirements": ["pymodbus==3.5.4"],
"version": "1.4.6"
"requirements": ["pymodbus>=3.6.8"],
"version": "1.4.7"
}
7 changes: 4 additions & 3 deletions custom_components/solis_modbus/modbus_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging

from pymodbus.client import AsyncModbusTcpClient
from pymodbus.exceptions import ModbusIOException

_LOGGER = logging.getLogger(__name__)

Expand All @@ -23,7 +22,8 @@ async def connect(self):

if not await self.client.connect():
self.connect_failures += 1
raise _LOGGER.warning(f"Failed to connect to Modbus device. Will retry, failures = {self.connect_failures}")
raise _LOGGER.warning(
f"Failed to connect to Modbus device. Will retry, failures = {self.connect_failures}")
else:
self.connect_failures = 0
return True
Expand Down Expand Up @@ -67,7 +67,8 @@ async def async_write_holding_registers(self, start_register: int, values: list[
result = await self.client.write_registers(start_register, values, slave=1)
return result
except Exception as e:
raise _LOGGER.error(f"Failed to write Modbus holding registers ({start_register}), values = {values}: {str(e)}")
raise _LOGGER.error(
f"Failed to write Modbus holding registers ({start_register}), values = {values}: {str(e)}")

def close_connection(self):
self.client.close()
Expand Down
3 changes: 2 additions & 1 deletion custom_components/solis_modbus/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def __init__(self, hass, modbus_controller, entity_definition):

# Hidden Inherited Instance Attributes
self._attr_unique_id = "{}_{}_{}".format(DOMAIN, self._modbus_controller.host, self._register)
self._attr_has_entity_name = True
self._attr_name = entity_definition["name"]
self._attr_native_value = entity_definition.get("default", None)
self._attr_assumed_state = entity_definition.get("assumed", False)
Expand All @@ -131,7 +132,7 @@ def __init__(self, hass, modbus_controller, entity_definition):

async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
_LOGGER.debug(f"async_added_to_hass {self._attr_name}, {self.entity_id}, {self.unique_id}")
_LOGGER.info(f"async_added_to_hass {self._attr_name}, {self.entity_id}, {self.unique_id}")

def update(self):
"""Update Modbus data periodically."""
Expand Down
6 changes: 4 additions & 2 deletions custom_components/solis_modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ class SolisDerivedSensor(RestoreSensor, SensorEntity):
def __init__(self, hass, entity_definition):
self._hass = hass
self._attr_name = entity_definition["name"]
self._attr_has_entity_name = True
self._attr_unique_id = "{}_{}".format(DOMAIN, entity_definition["unique"])

self._device_class = SwitchDeviceClass.SWITCH
Expand Down Expand Up @@ -842,7 +843,7 @@ def update(self):
self._attr_available = True
self._attr_native_value = n_value * self._display_multiplier
self._state = n_value * self._display_multiplier
self.async_write_ha_state()
self.schedule_update_ha_state()

except ValueError as e:
_LOGGER.error(e)
Expand All @@ -869,6 +870,7 @@ def __init__(self, hass, modbus_controller, entity_definition):
self._modbus_controller = modbus_controller

self._attr_name = entity_definition["name"]
self._attr_has_entity_name = True
self._attr_unique_id = "{}_{}_{}".format(DOMAIN, self._modbus_controller.host, entity_definition["unique"])

self._register: List[int] = entity_definition["register"]
Expand Down Expand Up @@ -918,7 +920,7 @@ def update(self):
self._attr_available = True
self._attr_native_value = n_value * self._display_multiplier
self._state = n_value * self._display_multiplier
self.async_write_ha_state()
self.schedule_update_ha_state()
except ValueError as e:
_LOGGER.error(e)
# Handle communication or reading errors
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solis_modbus/switch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import logging
from datetime import timedelta
from typing import List, Any
Expand Down Expand Up @@ -68,6 +67,7 @@ def __init__(self, hass, modbus_controller, entity_definition):
self._attr_unique_id = "{}_{}_{}_{}".format(DOMAIN, self._modbus_controller.host, self._read_register,
self._bit_position)
self._attr_name = entity_definition["name"]
self._attr_has_entity_name = True
self._attr_available = False
self._attr_is_on = None

Expand Down
1 change: 1 addition & 0 deletions custom_components/solis_modbus/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self, hass, modbus_controller, entity_definition):
# Hidden Inherited Instance Attributes
self._attr_unique_id = "{}_{}_{}".format(DOMAIN, self._modbus_controller.host, self._register)
self._attr_name = entity_definition["name"]
self._attr_has_entity_name = True
self._attr_native_value = entity_definition.get("default", None)
self._attr_assumed_state = entity_definition.get("assumed", False)
self._attr_available = False
Expand Down

0 comments on commit 1a4162a

Please sign in to comment.