Skip to content

Commit

Permalink
Update sensor entity attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Limych committed Oct 7, 2024
1 parent 8571a64 commit 16bb2bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 2 additions & 4 deletions custom_components/iaquk/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from homeassistant.components.sensor import (
ENTITY_ID_FORMAT,
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
Expand Down Expand Up @@ -76,10 +77,7 @@ def __init__(self, controller: IaqukController, sensor_type: str) -> None:
SensorStateClass.MEASUREMENT if sensor_type == SENSOR_INDEX else None
)
self._attr_device_class = (
f"{DOMAIN}__level" if sensor_type == SENSOR_LEVEL else None
)
self._attr_native_unit_of_measurement = (
"IAQI" if sensor_type == SENSOR_INDEX else None
f"{DOMAIN}__level" if sensor_type == SENSOR_LEVEL else SensorDeviceClass.AQI
)
self._attr_icon = ICON_DEFAULT if sensor_type == SENSOR_INDEX else ICON_FAIR

Expand Down
7 changes: 5 additions & 2 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from unittest.mock import patch

from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from pytest_homeassistant_custom_component.common import assert_setup_component
Expand Down Expand Up @@ -36,10 +37,11 @@ async def test_entity_initialization(hass: HomeAssistant):
assert entity.name == "Test Indoor Air Quality Index"
assert entity.should_poll is True
assert entity.available is True
assert entity.device_class == SensorDeviceClass.AQI
assert entity.state is None
assert entity.state_class == "measurement"
assert entity.state_class == SensorStateClass.MEASUREMENT
assert entity.icon == ICON_DEFAULT
assert entity.unit_of_measurement == "IAQI"
assert entity.unit_of_measurement is None
assert entity.extra_state_attributes == expected_attributes

entity = IaqukSensor(controller, SENSOR_LEVEL)
Expand All @@ -49,6 +51,7 @@ async def test_entity_initialization(hass: HomeAssistant):
assert entity.name == "Test Indoor Air Quality Level"
assert entity.should_poll is True
assert entity.available is True
assert entity.device_class == "iaquk__level"
assert entity.state is None
assert entity.state_class is None
assert entity.icon == ICON_FAIR
Expand Down

0 comments on commit 16bb2bb

Please sign in to comment.