Skip to content

Commit

Permalink
feat: closes Pho3niX90#81 (Pho3niX90#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pho3niX90 authored Oct 26, 2024
1 parent 5aa25c9 commit 071aeea
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/dataSources/
/dataSources.local.xml
/.idea/
/myenv/
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.5.3"
VERSION = "1.5.4"
POLL_INTERVAL_SECONDS = 15
MANUFACTURER = "Solis"
MODEL = "S6"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solis_modbus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
9 changes: 6 additions & 3 deletions custom_components/solis_modbus/modbus_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions custom_components/solis_modbus/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions solis_modbus.iml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module type="WEB_MODULE" version="4">
<component name="FacetManager">
<facet type="Python" name="Python">
<configuration sdkName="Python 3.11 (solis-modbus)" />
<configuration sdkName="Python 3.12" />
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
Expand All @@ -11,6 +11,6 @@
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.11 (solis-modbus) interpreter library" level="application" />
<orderEntry type="library" name="Python 3.12 interpreter library" level="application" />
</component>
</module>

0 comments on commit 071aeea

Please sign in to comment.