Skip to content

Commit

Permalink
Merge pull request #116 from smarrk/dev
Browse files Browse the repository at this point in the history
Fix state_class attribute for entities
  • Loading branch information
Limych authored Oct 1, 2023
2 parents 1270de6 + fbac8d8 commit bb13a3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion custom_components/iaquk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def __init__(self, controller, sensor_type: str):

self._attr_unique_id = f"{controller.unique_id}_{sensor_type}"
self._attr_name = f"{controller.name} {SENSORS[sensor_type]}"
self._attr_state_class = STATE_CLASS_MEASUREMENT
self._attr_state_class = (
STATE_CLASS_MEASUREMENT if sensor_type == SENSOR_INDEX else None
)
self._attr_device_class = (
f"{DOMAIN}__level" if sensor_type == SENSOR_LEVEL else None
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async def test_entity_initialization(hass: HomeAssistant):
assert entity.should_poll is True
assert entity.available is True
assert entity.state is None
assert entity.state_class == "measurement"
assert entity.icon == ICON_DEFAULT
assert entity.unit_of_measurement == "IAQI"
assert entity.extra_state_attributes == expected_attributes
Expand All @@ -48,6 +49,7 @@ async def test_entity_initialization(hass: HomeAssistant):
assert entity.should_poll is True
assert entity.available is True
assert entity.state is None
assert entity.state_class is None
assert entity.icon == ICON_FAIR
assert entity.unit_of_measurement is None
assert entity.extra_state_attributes == expected_attributes
Expand Down

0 comments on commit bb13a3c

Please sign in to comment.