Skip to content

Commit

Permalink
Merge pull request #93 from henricm/fix-relay-status-history
Browse files Browse the repository at this point in the history
fix: make relay status history available
  • Loading branch information
argoyle authored Nov 21, 2021
2 parents 5883f2c + 6ceb2f0 commit 6413cca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
18 changes: 10 additions & 8 deletions custom_components/ferroamp/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Platform for Ferroamp sensors integration."""
from __future__ import annotations

import json
import logging
import uuid
Expand Down Expand Up @@ -564,7 +566,7 @@ async def options_update_listener(hass, entry):
class FerroampSensor(SensorEntity, RestoreEntity):
"""Representation of a Ferroamp Sensor."""

def __init__(self, name, entity_prefix, unit, icon, device_id, device_name, interval, config_id, **kwargs):
def __init__(self, name, entity_prefix, unit: str | None, icon, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor."""
self._attr_name = name
self._attr_unit_of_measurement = unit
Expand Down Expand Up @@ -611,7 +613,7 @@ def handle_options_update(self, options):
class KeyedFerroampSensor(FerroampSensor):
"""Representation of a Ferroamp Sensor using a single key to extract state from MQTT-messages."""

def __init__(self, name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs):
def __init__(self, name, entity_prefix, key, unit: str | None, icon, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, unit, icon, device_id, device_name, interval, config_id, **kwargs)
self._state_key = key
Expand Down Expand Up @@ -646,7 +648,7 @@ async def async_added_to_hass(self) -> None:
class IntValFerroampSensor(KeyedFerroampSensor):
"""Representation of a Ferroamp integer value Sensor."""

def __init__(self, name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs):
def __init__(self, name, entity_prefix, key, unit: str | None, icon, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs)

Expand All @@ -668,7 +670,7 @@ def update_state_from_events(self, events) -> bool:
class StringValFerroampSensor(KeyedFerroampSensor):
"""Representation of a Ferroamp string value Sensor."""

def __init__(self, name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs):
def __init__(self, name, entity_prefix, key, unit: str | None, icon, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs)

Expand All @@ -688,7 +690,7 @@ def update_state_from_events(self, events) -> bool:
class FloatValFerroampSensor(KeyedFerroampSensor):
"""Representation of a Ferroamp float value Sensor."""

def __init__(self, name, entity_prefix, key, unit, icon, device_id, device_name, interval, precision, config_id, **kwargs):
def __init__(self, name, entity_prefix, key, unit: str | None, icon, device_id, device_name, interval, precision, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs)
self._precision = precision
Expand Down Expand Up @@ -878,7 +880,7 @@ def isfloat(self, value):
class RelayStatusFerroampSensor(KeyedFerroampSensor):
def __init__(self, name, entity_prefix, key, device_id, device_name, interval, config_id, **kwargs):
"""Initialize the sensor"""
super().__init__(name, entity_prefix, key, "", "", device_id, device_name, interval, config_id, **kwargs)
super().__init__(name, entity_prefix, key, None, "", device_id, device_name, interval, config_id, **kwargs)

def update_state_from_events(self, events):
temp = None
Expand Down Expand Up @@ -950,7 +952,7 @@ def update_state_from_events(self, events):
class ThreePhaseFerroampSensor(KeyedFerroampSensor):
"""Representation of a Ferroamp ThreePhase Sensor."""

def __init__(self, name, entity_prefix, key, unit, icon, device_id, device_name, interval, precision, config_id, **kwargs):
def __init__(self, name, entity_prefix, key, unit: str | None, icon, device_id, device_name, interval, precision, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, unit, icon, device_id, device_name, interval, config_id, **kwargs)
if self._attr_state_class is None:
Expand Down Expand Up @@ -1086,7 +1088,7 @@ class FaultcodeFerroampSensor(KeyedFerroampSensor):

def __init__(self, name, entity_prefix, key, device_id, device_name, interval, fault_codes, config_id, **kwargs):
"""Initialize the sensor."""
super().__init__(name, entity_prefix, key, "", "mdi:traffic-light", device_id, device_name, interval, config_id,
super().__init__(name, entity_prefix, key, None, "mdi:traffic-light", device_id, device_name, interval, config_id,
**kwargs)
self._fault_codes = fault_codes
self._attr_extra_state_attributes = {}
Expand Down
11 changes: 0 additions & 11 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,6 @@ async def test_setting_eso_sensor_values_via_mqtt_message(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'ESO 1 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
8: 'Not a fault, just an indication that Battery Manufacturer is not Ferroamp'
}

Expand All @@ -874,7 +873,6 @@ async def test_setting_eso_sensor_values_via_mqtt_message(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'ESO 1 Relay Status',
'icon': '',
'unit_of_measurement': ''
}

state = hass.states.get("sensor.ferroamp_eso_1_pcb_temperature")
Expand Down Expand Up @@ -1032,7 +1030,6 @@ async def test_setting_sso_sensor_values_via_mqtt_message(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
0: 'No errors'
}

Expand All @@ -1041,7 +1038,6 @@ async def test_setting_sso_sensor_values_via_mqtt_message(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Relay Status',
'icon': '',
'unit_of_measurement': ''
}

state = hass.states.get("sensor.ferroamp_sso_12345678_pcb_temperature")
Expand Down Expand Up @@ -1122,7 +1118,6 @@ async def test_trim_part_no_from_sso_id(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
0: 'No errors'
}

Expand All @@ -1131,7 +1126,6 @@ async def test_trim_part_no_from_sso_id(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Relay Status',
'icon': '',
'unit_of_measurement': ''
}

state = hass.states.get("sensor.ferroamp_sso_12345678_pcb_temperature")
Expand Down Expand Up @@ -1214,7 +1208,6 @@ async def test_sso_fault_codes(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
0: 'No errors'
}

Expand All @@ -1237,7 +1230,6 @@ async def test_sso_fault_codes(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
5: 'UNDERVOLTAGE'
}

Expand All @@ -1260,7 +1252,6 @@ async def test_sso_fault_codes(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
6: 'OVERVOLTAGE'
}

Expand All @@ -1283,7 +1274,6 @@ async def test_sso_fault_codes(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
7: 'OVERHEAT'
}

Expand All @@ -1306,7 +1296,6 @@ async def test_sso_fault_codes(hass, mqtt_mock):
assert state.attributes == {
'friendly_name': 'SSO 12345678 Faultcode',
'icon': 'mdi:traffic-light',
'unit_of_measurement': '',
11: 'POWERLIMITING'
}

Expand Down

0 comments on commit 6413cca

Please sign in to comment.