Skip to content

Commit 8ede1fa

Browse files
Merge branch 'main' into remove-units-from-names
2 parents d623562 + f26f30e commit 8ede1fa

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

custom_components/solaredge_modbus_multi/binary_sensor.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
import logging
66

7-
from homeassistant.components.binary_sensor import BinarySensorEntity
7+
from homeassistant.components.binary_sensor import (
8+
BinarySensorDeviceClass,
9+
BinarySensorEntity,
10+
)
811
from homeassistant.config_entries import ConfigEntry
912
from homeassistant.core import HomeAssistant, callback
1013
from homeassistant.helpers.entity import EntityCategory
@@ -30,6 +33,9 @@ async def async_setup_entry(
3033
if hub.option_detect_extras and inverter.advanced_power_control:
3134
entities.append(AdvPowerControlEnabled(inverter, config_entry, coordinator))
3235

36+
if hub.option_detect_extras:
37+
entities.append(GridStatusOnOff(inverter, config_entry, coordinator))
38+
3339
if entities:
3440
async_add_entities(entities)
3541

@@ -92,3 +98,32 @@ def name(self) -> str:
9298
@property
9399
def is_on(self) -> bool:
94100
return self._platform.decoded_model["AdvPwrCtrlEn"] == 0x1
101+
102+
103+
class GridStatusOnOff(SolarEdgeBinarySensorBase):
104+
"""Grid Status On Off. This is undocumented from discussions."""
105+
106+
device_class = BinarySensorDeviceClass.POWER
107+
icon = "mdi:transmission-tower"
108+
109+
@property
110+
def available(self) -> bool:
111+
return (
112+
super().available and "I_Grid_Status" in self._platform.decoded_model.keys()
113+
)
114+
115+
@property
116+
def unique_id(self) -> str:
117+
return f"{self._platform.uid_base}_grid_status_on_off"
118+
119+
@property
120+
def name(self) -> str:
121+
return "Grid Status"
122+
123+
@property
124+
def entity_registry_enabled_default(self) -> bool:
125+
return "I_Grid_Status" in self._platform.decoded_model.keys()
126+
127+
@property
128+
def is_on(self) -> bool:
129+
return not self._platform.decoded_model["I_Grid_Status"]

custom_components/solaredge_modbus_multi/hub.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ def __init__(self, device_id: int, hub: SolarEdgeModbusMultiHub) -> None:
753753
self.global_power_control = None
754754
self.advanced_power_control = None
755755
self.site_limit_control = None
756+
self._grid_status = None
756757

757758
async def init_device(self) -> None:
758759
"""Set up data about the device from modbus."""
@@ -1300,6 +1301,45 @@ async def read_modbus_data(self) -> None:
13001301
f"No response from inverter ID {self.inverter_unit_id}"
13011302
)
13021303

1304+
""" Grid On/Off Status """
1305+
if self._grid_status is not False:
1306+
try:
1307+
inverter_data = await self.hub.modbus_read_holding_registers(
1308+
unit=self.inverter_unit_id, address=40113, rcount=2
1309+
)
1310+
1311+
decoder = BinaryPayloadDecoder.fromRegisters(
1312+
inverter_data.registers,
1313+
byteorder=Endian.BIG,
1314+
wordorder=Endian.LITTLE,
1315+
)
1316+
1317+
self.decoded_model.update(
1318+
OrderedDict(
1319+
[
1320+
("I_Grid_Status", decoder.decode_32bit_uint()),
1321+
]
1322+
)
1323+
)
1324+
self._grid_status = True
1325+
1326+
except ModbusIllegalAddress:
1327+
try:
1328+
del self.decoded_model["I_Grid_Status"]
1329+
except KeyError:
1330+
pass
1331+
1332+
self._grid_status = False
1333+
1334+
_LOGGER.debug(
1335+
(f"I{self.inverter_unit_id}: " "Grid On/Off NOT available")
1336+
)
1337+
1338+
except ModbusIOError:
1339+
raise ModbusReadError(
1340+
f"No response from inverter ID {self.inverter_unit_id}"
1341+
)
1342+
13031343
for name, value in iter(self.decoded_model.items()):
13041344
if isinstance(value, float):
13051345
display_value = float_to_hex(value)

custom_components/solaredge_modbus_multi/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"issue_tracker": "https://github.com/WillCodeForCats/solaredge-modbus-multi/issues",
1111
"loggers": ["custom_components.solaredge_modbus_multi"],
1212
"requirements": ["pymodbus>=3.6.6"],
13-
"version": "2.4.16"
13+
"version": "2.4.18"
1414
}

0 commit comments

Comments
 (0)