Skip to content

Commit

Permalink
fix: correct calculation dc link voltage sensor state
Browse files Browse the repository at this point in the history
Correct calculation of dc link voltage sensor state. Seems the values where reversed

fixes #364
  • Loading branch information
bj00rn committed Jul 8, 2023
1 parent 56df5e9 commit a4a6417
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/ferroamp/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ def update_state_from_events(self, events):
if neg is None and pos is None:
return False
else:
self._attr_native_value = int(neg / count + pos / count)
self._attr_native_value = round(float(pos / count - neg / count), 2)
self._attr_extra_state_attributes = dict(neg=round(float(neg / count), 2),
pos=round(float(pos / count), 2))
return True
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ async def test_setting_ehub_sensor_values_via_mqtt_message(hass, mqtt_mock):
}

state = hass.states.get("sensor.ferroamp_dc_link_voltage")
assert state.state == "0"
assert state.state == "768.27"
assert state.attributes == {
'device_class': 'voltage',
'friendly_name': 'EnergyHub DC Link Voltage',
Expand Down

0 comments on commit a4a6417

Please sign in to comment.