From 071aeea060b0917ed5808b46ad6e5ec2fa22e055 Mon Sep 17 00:00:00 2001 From: Pho3niX90 Date: Sat, 26 Oct 2024 21:41:57 +0200 Subject: [PATCH] feat: closes #81 (#83) --- .gitignore | 1 + custom_components/solis_modbus/const.py | 2 +- custom_components/solis_modbus/manifest.json | 2 +- .../solis_modbus/modbus_controller.py | 9 ++++++--- custom_components/solis_modbus/sensor.py | 16 +++++++++++++--- solis_modbus.iml | 4 ++-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 68b85f0..bc72c94 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ /dataSources/ /dataSources.local.xml /.idea/ +/myenv/ diff --git a/custom_components/solis_modbus/const.py b/custom_components/solis_modbus/const.py index d256e05..12c9367 100644 --- a/custom_components/solis_modbus/const.py +++ b/custom_components/solis_modbus/const.py @@ -1,6 +1,6 @@ DOMAIN = "solis_modbus" CONTROLLER = "modbus_controller" -VERSION = "1.5.3" +VERSION = "1.5.4" POLL_INTERVAL_SECONDS = 15 MANUFACTURER = "Solis" MODEL = "S6" diff --git a/custom_components/solis_modbus/manifest.json b/custom_components/solis_modbus/manifest.json index 1755a77..285b832 100644 --- a/custom_components/solis_modbus/manifest.json +++ b/custom_components/solis_modbus/manifest.json @@ -10,5 +10,5 @@ "issue_tracker": "https://github.com/Pho3niX90/solis_modbus/issues", "quality_scale": "silver", "requirements": ["pymodbus>=3.6.8"], - "version": "1.5.3" + "version": "1.5.4" } diff --git a/custom_components/solis_modbus/modbus_controller.py b/custom_components/solis_modbus/modbus_controller.py index 216e0f4..c2d0fd9 100644 --- a/custom_components/solis_modbus/modbus_controller.py +++ b/custom_components/solis_modbus/modbus_controller.py @@ -22,14 +22,17 @@ async def connect(self): if not await self.client.connect(): self.connect_failures += 1 - raise _LOGGER.warning( + _LOGGER.warning( f"Failed to connect to Modbus device. Will retry, failures = {self.connect_failures}") + return False # Return False if connection fails else: self.connect_failures = 0 - return True + return True except Exception as e: - raise _LOGGER.error(f"Failed to connect to Modbus device. Will retry") + _LOGGER.error(f"Failed to connect to Modbus device. Will retry. Exception: {e}") + return False # Return False if an exception occurs + async def async_read_input_register(self, register, count=1): try: diff --git a/custom_components/solis_modbus/sensor.py b/custom_components/solis_modbus/sensor.py index f111e3c..1856ced 100644 --- a/custom_components/solis_modbus/sensor.py +++ b/custom_components/solis_modbus/sensor.py @@ -9,7 +9,7 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import UnitOfFrequency, UnitOfTemperature, \ UnitOfElectricPotential, UnitOfElectricCurrent, UnitOfPower, \ - UnitOfApparentPower, PERCENTAGE, UnitOfEnergy, POWER_VOLT_AMPERE_REACTIVE, UnitOfTime + UnitOfApparentPower, UnitOfReactivePower, PERCENTAGE, UnitOfEnergy, UnitOfTime from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.event import async_track_time_interval @@ -192,7 +192,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn {"type": "SS", "name": "Solis Reactive Power", "unique": "solis_modbus_inverter_reactive_power", "register": ['33081', '33082'], "device_class": SensorDeviceClass.REACTIVE_POWER, "multiplier": 0, - "unit_of_measurement": POWER_VOLT_AMPERE_REACTIVE, "state_class": SensorStateClass.MEASUREMENT}, + "unit_of_measurement": UnitOfReactivePower.VOLT_AMPERE_REACTIVE, "state_class": SensorStateClass.MEASUREMENT}, {"type": "SS", "name": "Solis Apparent Power", "unique": "solis_modbus_inverter_apparent_power", @@ -636,6 +636,16 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn "unit_of_measurement": UnitOfPower.WATT, "state_class": SensorStateClass.MEASUREMENT, "register": ['33051', '33052']}, + {"type": "SDS", "name": "Solis PV Power 3", + "unique": "solis_modbus_inverter_dc_power_3", "device_class": SensorDeviceClass.POWER, "multiplier": 0.1, + "unit_of_measurement": UnitOfPower.WATT, "state_class": SensorStateClass.MEASUREMENT, + "register": ['33053', '33054']}, + + {"type": "SDS", "name": "Solis PV Power 4", + "unique": "solis_modbus_inverter_dc_power_4", "device_class": SensorDeviceClass.POWER, "multiplier": 0.1, + "unit_of_measurement": UnitOfPower.WATT, "state_class": SensorStateClass.MEASUREMENT, + "register": ['33055', '33056']}, + {"type": "SDS", "name": "Solis Battery Charge Power", "unique": "solis_modbus_inverter_battery_charge_power", "device_class": SensorDeviceClass.POWER, "multiplier": 0.1, @@ -824,7 +834,7 @@ def update(self): n_value = round(get_value(self)) n_value = STATUS_MAPPING.get(n_value, "Unknown") - if '33049' in self._register or '33051' in self._register: + if '33049' in self._register or '33051' in self._register or '33053' in self._register or '33055' in self._register: r1_value = self._hass.data[DOMAIN]['values'][self._register[0]] * self._multiplier r2_value = self._hass.data[DOMAIN]['values'][self._register[1]] * self._multiplier n_value = round(r1_value * r2_value) diff --git a/solis_modbus.iml b/solis_modbus.iml index 3213b43..043d827 100644 --- a/solis_modbus.iml +++ b/solis_modbus.iml @@ -2,7 +2,7 @@ - + @@ -11,6 +11,6 @@ - + \ No newline at end of file