Skip to content

Commit 90185c7

Browse files
committed
fix: don't read data for inverter on/off switch
1 parent 2bd701b commit 90185c7

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

custom_components/solis_cloud_control/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(
3434

3535
@property
3636
def available(self) -> bool:
37-
if not super().available:
37+
if not self.coordinator.last_update_success:
3838
return False
3939

4040
for cid in self.cids:

custom_components/solis_cloud_control/inverters/inverter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,7 @@ def create_hybrid_inverter(
346346
def all_cids(self) -> list[int]:
347347
cids: list[int] = []
348348

349-
if self.on_off:
350-
cids.append(self.on_off.on_cid)
351-
cids.append(self.on_off.off_cid)
349+
# CIDs for on-off are write-only, so they are not included
352350
if self.storage_mode:
353351
cids.append(self.storage_mode.cid)
354352
if self.charge_discharge_settings:

custom_components/solis_cloud_control/switch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ def __init__(
110110
self._attr_is_on = True
111111
self._attr_assumed_state = True
112112

113+
@property
114+
def available(self) -> bool:
115+
if not self.coordinator.last_update_success:
116+
return False
117+
# CIDs for on-off are write only, skip availability check based on coordinator data
118+
return True
119+
113120
async def async_turn_on(self, **kwargs: dict[str, any]) -> None: # noqa: ARG002
114121
_LOGGER.info("Turning on inverter")
115122
await self.coordinator.control_no_check(self.on_off.on_cid, self.on_off.on_value)

tests/test_entity.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,13 @@ def test_available_multiple_cids(
4545
)
4646
mock_coordinator.data = coordinator_data
4747
assert entity.available == expected_available
48+
49+
def test_available_when_coordinator_unavailable(self, mock_coordinator):
50+
entity = SolisCloudControlEntity(
51+
coordinator=mock_coordinator,
52+
entity_description=EntityDescription(key="any_key", name="any name"),
53+
cids=1,
54+
)
55+
56+
entity.coordinator.last_update_success = False
57+
assert entity.available is False

tests/test_switch.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ def test_init(self, on_off_switch):
2727
assert on_off_switch.is_on is True
2828
assert on_off_switch.assumed_state is True
2929

30+
def test_available(self, on_off_switch):
31+
assert on_off_switch.available is True
32+
33+
def test_available_when_coordinator_unavailable(self, on_off_switch):
34+
on_off_switch.coordinator.last_update_success = False
35+
assert on_off_switch.available is False
36+
3037
async def test_turn_on(self, on_off_switch):
3138
await on_off_switch.async_turn_on()
3239
on_off_switch.coordinator.control_no_check.assert_awaited_once_with(

0 commit comments

Comments
 (0)