Skip to content

Commit

Permalink
Merge pull request #314 from henricm/gribber/master
Browse files Browse the repository at this point in the history
fix: make sure old fault codes gets cleared
  • Loading branch information
argoyle authored Mar 21, 2023
2 parents d506921 + 5715246 commit 59a42bb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
12 changes: 6 additions & 6 deletions custom_components/ferroamp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,12 +1125,12 @@ def update_state_from_events(self, events):
else:
if 0 in self._attr_extra_state_attributes:
del self._attr_extra_state_attributes[0]
for i, code in enumerate(self._fault_codes):
v = 1 << i
if x & v == v:
self._attr_extra_state_attributes[i + 1] = code
elif i + 1 in self._attr_extra_state_attributes:
del self._attr_extra_state_attributes[i + 1]
for i, code in enumerate(self._fault_codes):
v = 1 << i
if x & v == v:
self._attr_extra_state_attributes[i + 1] = code
elif i + 1 in self._attr_extra_state_attributes:
del self._attr_extra_state_attributes[i + 1]
return True


Expand Down
21 changes: 21 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,27 @@ async def test_sso_fault_codes(hass, mqtt_mock):
11: 'POWERLIMITING'
}

async_fire_mqtt_message(hass, topic, """{
"relaystatus": {"val": "0"},
"temp": {"val": "6.482"},
"wpv": {"val": "843516404273"},
"ts": {"val": "2021-03-08T08:22:42UTC"},
"udc": {"val": "769.872"},
"faultcode": {"val": "0"},
"ipv": {"val": "4.826"},
"upv": {"val": "653.012"},
"id": {"val": "12345678"}
}""")
await hass.async_block_till_done()

state = hass.states.get("sensor.ferroamp_sso_12345678_faultcode")
assert state.state == "0"
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
0: 'No errors'
}


async def test_restore_state(hass, mqtt_mock):
mock_restore_cache(
Expand Down

0 comments on commit 59a42bb

Please sign in to comment.