Skip to content

Commit

Permalink
Merge branch 'main' into config-flow-reconfigure
Browse files Browse the repository at this point in the history
  • Loading branch information
WillCodeForCats committed Apr 23, 2024
2 parents 70bd3d1 + a58568c commit d0e3e3b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ body:
id: diagnostic-file
attributes:
label: Diagnostic File
description: Drag and drop to attach your diagnostic file. The diagnostic file is a snapshot. Make sure it's taken at the exact time the issue is happening.
description: REQUIRED. Drag and drop to attach your diagnostic file. The diagnostic file is a snapshot. Make sure it's taken at the exact time the issue is happening. Diagnostic file is not required when reporting an issue that prevents the integration from starting.
validations:
required: true
- type: textarea
id: log-file
attributes:
label: Debug logs
description: Debug logs are not always necessary, but may be required for more complex issues. You can enable debug logs in Home Assistant. Debug logging will generate a large amount of data. Turn on debug only to observe the isseue then turn off debug during normal operation.
description: Optional. Debug logs are not always necessary, but may be required for more complex issues. You can enable debug logs in Home Assistant. Debug logging will generate a large amount of data. Turn on debug only to observe the isseue then turn off debug during normal operation. Debug logs are required when reporting an issue that prevents the integration from starting.
render: shell
- type: input
id: ha-version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: WillCodeForCats/[email protected].4
- uses: WillCodeForCats/[email protected].6
with:
python-root-list: "custom_components/solaredge_modbus_multi"
use-flake8: true
Expand Down
1 change: 1 addition & 0 deletions custom_components/solaredge_modbus_multi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class SolaredgeModbusMultiConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for SolarEdge Modbus Multi."""

VERSION = 1
MINOR_VERSION = 1

@staticmethod
@callback
Expand Down
43 changes: 39 additions & 4 deletions custom_components/solaredge_modbus_multi/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,14 @@ async def _async_init_solaredge(self) -> None:
inverter_unit_id = inverter_index + self._start_device_id

try:
_LOGGER.debug(
f"Looking for inverter at {self.hub_host} ID {inverter_unit_id}"
)
new_inverter = SolarEdgeInverter(inverter_unit_id, self)
await new_inverter.init_device()
self.inverters.append(new_inverter)

except ModbusReadError as e:
except (ModbusReadError, TimeoutError) as e:
self.disconnect()
raise HubInitFailed(f"{e}")

Expand All @@ -257,6 +260,9 @@ async def _async_init_solaredge(self) -> None:
if self._detect_meters:
for meter_id in METER_REG_BASE:
try:
_LOGGER.debug(
f"Looking for meter I{inverter_unit_id}M{meter_id}"
)
new_meter = SolarEdgeMeter(inverter_unit_id, meter_id, self)
await new_meter.init_device()

Expand All @@ -274,7 +280,7 @@ async def _async_init_solaredge(self) -> None:
self.meters.append(new_meter)
_LOGGER.debug(f"Found I{inverter_unit_id}M{meter_id}")

except ModbusReadError as e:
except (ModbusReadError, TimeoutError) as e:
self.disconnect()
raise HubInitFailed(f"{e}")

Expand All @@ -285,6 +291,9 @@ async def _async_init_solaredge(self) -> None:
if self._detect_batteries:
for battery_id in BATTERY_REG_BASE:
try:
_LOGGER.debug(
f"Looking for battery I{inverter_unit_id}B{battery_id}"
)
new_battery = SolarEdgeBattery(
inverter_unit_id, battery_id, self
)
Expand All @@ -307,7 +316,7 @@ async def _async_init_solaredge(self) -> None:
self.batteries.append(new_battery)
_LOGGER.debug(f"Found I{inverter_unit_id}B{battery_id}")

except ModbusReadError as e:
except (ModbusReadError, TimeoutError) as e:
self.disconnect()
raise HubInitFailed(f"{e}")

Expand Down Expand Up @@ -341,6 +350,10 @@ async def _async_init_solaredge(self) -> None:
self.disconnect()
raise HubInitFailed(f"Modbus error: {e}")

except TimeoutError as e:
self.disconnect()
raise HubInitFailed(f"Timeout error: {e}")

self.initalized = True

async def async_refresh_modbus_data(self) -> bool:
Expand Down Expand Up @@ -739,6 +752,8 @@ def __init__(self, device_id: int, hub: SolarEdgeModbusMultiHub) -> None:
self.site_limit_control = None

async def init_device(self) -> None:
"""Set up data about the device from modbus."""

try:
inverter_data = await self.hub.modbus_read_holding_registers(
unit=self.inverter_unit_id, address=40000, rcount=69
Expand Down Expand Up @@ -856,14 +871,27 @@ async def init_device(self) -> None:
self.manufacturer = self.decoded_common["C_Manufacturer"]
self.model = self.decoded_common["C_Model"]
self.option = self.decoded_common["C_Option"]
self.fw_version = self.decoded_common["C_Version"]
self.serial = self.decoded_common["C_SerialNumber"]
self.device_address = self.decoded_common["C_Device_address"]
self.name = f"{self.hub.hub_id.capitalize()} I{self.inverter_unit_id}"
self.uid_base = f"{self.model}_{self.serial}"

async def read_modbus_data(self) -> None:
"""Read and update dynamic modbus registers."""

try:
inverter_data = await self.hub.modbus_read_holding_registers(
unit=self.inverter_unit_id, address=40044, rcount=16
)

decoder = BinaryPayloadDecoder.fromRegisters(
inverter_data.registers, byteorder=Endian.BIG
)

self.decoded_common["C_Version"] = parse_modbus_string(
decoder.decode_string(16)
)

inverter_data = await self.hub.modbus_read_holding_registers(
unit=self.inverter_unit_id, address=40069, rcount=40
)
Expand Down Expand Up @@ -1362,6 +1390,13 @@ def online(self) -> bool:
"""Device is online."""
return self.hub.online

@property
def fw_version(self) -> str | None:
if "C_Version" in self.decoded_common:
return self.decoded_common["C_Version"]

return None

@property
def device_info(self) -> DeviceInfo:
"""Return the device info."""
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solaredge_modbus_multi/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues",
"loggers": ["custom_components.solaredge_modbus_multi"],
"requirements": ["pymodbus>=3.6.6"],
"version": "2.4.13"
"version": "2.4.14-pre.2"
}
24 changes: 12 additions & 12 deletions custom_components/solaredge_modbus_multi/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,7 +1740,8 @@ def native_value(self):
class SolarEdgeBatteryEnergyExport(SolarEdgeSensorBase):
device_class = SensorDeviceClass.ENERGY
state_class = SensorStateClass.TOTAL_INCREASING
native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
suggested_display_precision = 3
icon = "mdi:battery-charging-20"

Expand Down Expand Up @@ -1780,9 +1781,7 @@ def native_value(self):
if self._platform.allow_battery_energy_reset:
self._count = 0

return (
self._platform.decoded_model["B_Export_Energy_WH"] * 0.001
)
return self._platform.decoded_model["B_Export_Energy_WH"]

else:
if self._platform.allow_battery_energy_reset:
Expand Down Expand Up @@ -1815,7 +1814,8 @@ def native_value(self):
class SolarEdgeBatteryEnergyImport(SolarEdgeSensorBase):
device_class = SensorDeviceClass.ENERGY
state_class = SensorStateClass.TOTAL_INCREASING
native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
suggested_display_precision = 3
icon = "mdi:battery-charging-100"

Expand Down Expand Up @@ -1855,9 +1855,7 @@ def native_value(self):
if self._platform.allow_battery_energy_reset:
self._count = 0

return (
self._platform.decoded_model["B_Import_Energy_WH"] * 0.001
)
return self._platform.decoded_model["B_Import_Energy_WH"]

else:
if self._platform.allow_battery_energy_reset:
Expand Down Expand Up @@ -1890,7 +1888,8 @@ def native_value(self):
class SolarEdgeBatteryMaxEnergy(SolarEdgeSensorBase):
device_class = SensorDeviceClass.ENERGY_STORAGE
state_class = SensorStateClass.MEASUREMENT
native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
suggested_display_precision = 3

@property
Expand All @@ -1913,7 +1912,7 @@ def native_value(self):
return None

else:
return self._platform.decoded_model["B_Energy_Max"] * 0.001
return self._platform.decoded_model["B_Energy_Max"]


class SolarEdgeBatteryPowerBase(SolarEdgeSensorBase):
Expand Down Expand Up @@ -2027,7 +2026,8 @@ def native_value(self):
class SolarEdgeBatteryAvailableEnergy(SolarEdgeSensorBase):
device_class = SensorDeviceClass.ENERGY_STORAGE
state_class = SensorStateClass.MEASUREMENT
native_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
native_unit_of_measurement = UnitOfEnergy.WATT_HOUR
suggested_unit_of_measurement = UnitOfEnergy.KILO_WATT_HOUR
suggested_display_precision = 3

@property
Expand All @@ -2053,7 +2053,7 @@ def native_value(self):
return None

else:
return self._platform.decoded_model["B_Energy_Available"] * 0.001
return self._platform.decoded_model["B_Energy_Available"]


class SolarEdgeBatterySOH(SolarEdgeSensorBase):
Expand Down

0 comments on commit d0e3e3b

Please sign in to comment.