Skip to content

Commit b773d49

Browse files
Merge pull request #824 from WillCodeForCats/code-quality
Add available properties to commit and restore sensors
2 parents b7a16f9 + e6ae7a8 commit b773d49

File tree

1 file changed

+28
-9
lines changed
  • custom_components/solaredge_modbus_multi

1 file changed

+28
-9
lines changed

custom_components/solaredge_modbus_multi/sensor.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def async_setup_entry(
9292
entities.append(SolarEdgeCosPhi(inverter, config_entry, coordinator))
9393

9494
""" Power Control Block """
95-
if hub.option_detect_extras and inverter.advanced_power_control:
95+
if hub.option_detect_extras:
9696
entities.append(
9797
SolarEdgeCommitControlSettings(inverter, config_entry, coordinator)
9898
)
@@ -1344,12 +1344,6 @@ def extra_state_attributes(self):
13441344
return attrs
13451345

13461346

1347-
class SolarEdgeGlobalPowerControlBlock(SolarEdgeSensorBase):
1348-
@property
1349-
def available(self) -> bool:
1350-
return super().available and self._platform.global_power_control
1351-
1352-
13531347
class StatusVendor(SolarEdgeSensorBase):
13541348
entity_category = EntityCategory.DIAGNOSTIC
13551349

@@ -1390,6 +1384,12 @@ def extra_state_attributes(self):
13901384
return None
13911385

13921386

1387+
class SolarEdgeGlobalPowerControlBlock(SolarEdgeSensorBase):
1388+
@property
1389+
def available(self) -> bool:
1390+
return super().available and self._platform.global_power_control
1391+
1392+
13931393
class SolarEdgeRRCR(SolarEdgeGlobalPowerControlBlock):
13941394
@property
13951395
def unique_id(self) -> str:
@@ -2336,7 +2336,13 @@ def native_value(self):
23362336
return self._platform.decoded_model["B_SOE"]
23372337

23382338

2339-
class SolarEdgeCommitControlSettings(SolarEdgeSensorBase):
2339+
class SolarEdgeAdvancedPowerControlBlock(SolarEdgeSensorBase):
2340+
@property
2341+
def available(self) -> bool:
2342+
return super().available and self._platform.advanced_power_control
2343+
2344+
2345+
class SolarEdgeCommitControlSettings(SolarEdgeAdvancedPowerControlBlock):
23402346
"""Entity to show the results of Commit Power Control Settings button."""
23412347

23422348
entity_category = EntityCategory.DIAGNOSTIC
@@ -2350,6 +2356,12 @@ def unique_id(self) -> str:
23502356
def name(self) -> str:
23512357
return "Commit Power Settings"
23522358

2359+
@property
2360+
def available(self) -> bool:
2361+
return (
2362+
super().available and "CommitPwrCtlSettings" in self._platform.decoded_model
2363+
)
2364+
23532365
@property
23542366
def native_value(self):
23552367
return self._platform.decoded_model["CommitPwrCtlSettings"]
@@ -2375,7 +2387,7 @@ def extra_state_attributes(self):
23752387
return attrs
23762388

23772389

2378-
class SolarEdgeDefaultControlSettings(SolarEdgeSensorBase):
2390+
class SolarEdgeDefaultControlSettings(SolarEdgeAdvancedPowerControlBlock):
23792391
"""Entity to show the results of Restore Power Control Default Settings button."""
23802392

23812393
entity_category = EntityCategory.DIAGNOSTIC
@@ -2389,6 +2401,13 @@ def unique_id(self) -> str:
23892401
def name(self) -> str:
23902402
return "Default Power Settings"
23912403

2404+
@property
2405+
def available(self) -> bool:
2406+
return (
2407+
super().available
2408+
and "RestorePwrCtlDefaults" in self._platform.decoded_model
2409+
)
2410+
23922411
@property
23932412
def native_value(self):
23942413
return self._platform.decoded_model["RestorePwrCtlDefaults"]

0 commit comments

Comments
 (0)