mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Use new device classes in GIOS integration (#54743)
* Use new device classes * Clean up
This commit is contained in:
parent
bd550c4559
commit
10058ea3f0
@ -5,7 +5,16 @@ from datetime import timedelta
|
||||
from typing import Final
|
||||
|
||||
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT
|
||||
from homeassistant.const import CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
from homeassistant.const import (
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
DEVICE_CLASS_AQI,
|
||||
DEVICE_CLASS_CO,
|
||||
DEVICE_CLASS_NITROGEN_DIOXIDE,
|
||||
DEVICE_CLASS_OZONE,
|
||||
DEVICE_CLASS_PM10,
|
||||
DEVICE_CLASS_PM25,
|
||||
DEVICE_CLASS_SULPHUR_DIOXIDE,
|
||||
)
|
||||
|
||||
from .model import GiosSensorEntityDescription
|
||||
|
||||
@ -36,47 +45,55 @@ SENSOR_TYPES: Final[tuple[GiosSensorEntityDescription, ...]] = (
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_AQI,
|
||||
name="AQI",
|
||||
device_class=DEVICE_CLASS_AQI,
|
||||
value=None,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_C6H6,
|
||||
name="C6H6",
|
||||
icon="mdi:molecule",
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_CO,
|
||||
name="CO",
|
||||
device_class=DEVICE_CLASS_CO,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_NO2,
|
||||
name="NO2",
|
||||
device_class=DEVICE_CLASS_NITROGEN_DIOXIDE,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_O3,
|
||||
name="O3",
|
||||
device_class=DEVICE_CLASS_OZONE,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_PM10,
|
||||
name="PM10",
|
||||
device_class=DEVICE_CLASS_PM10,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_PM25,
|
||||
name="PM2.5",
|
||||
device_class=DEVICE_CLASS_PM25,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
GiosSensorEntityDescription(
|
||||
key=ATTR_SO2,
|
||||
name="SO2",
|
||||
device_class=DEVICE_CLASS_SULPHUR_DIOXIDE,
|
||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
|
@ -86,7 +86,6 @@ class GiosSensor(CoordinatorEntity, SensorEntity):
|
||||
"manufacturer": MANUFACTURER,
|
||||
"entry_type": "service",
|
||||
}
|
||||
self._attr_icon = "mdi:blur"
|
||||
self._attr_name = f"{name} {description.name}"
|
||||
self._attr_unique_id = f"{coordinator.gios.station_id}-{description.key}"
|
||||
self._attrs: dict[str, Any] = {
|
||||
|
@ -18,9 +18,17 @@ from homeassistant.components.sensor import (
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||
DEVICE_CLASS_AQI,
|
||||
DEVICE_CLASS_CO,
|
||||
DEVICE_CLASS_NITROGEN_DIOXIDE,
|
||||
DEVICE_CLASS_OZONE,
|
||||
DEVICE_CLASS_PM10,
|
||||
DEVICE_CLASS_PM25,
|
||||
DEVICE_CLASS_SULPHUR_DIOXIDE,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
@ -45,7 +53,7 @@ async def test_sensor(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:molecule"
|
||||
assert state.attributes.get(ATTR_INDEX) == "bardzo dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_c6h6")
|
||||
@ -57,12 +65,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "252"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_CO
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_co")
|
||||
@ -74,12 +82,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "7"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_NITROGEN_DIOXIDE
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_no2")
|
||||
@ -91,12 +99,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "96"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_OZONE
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_o3")
|
||||
@ -108,12 +116,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "17"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM10
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_pm10")
|
||||
@ -125,12 +133,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "4"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_PM25
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_pm2_5")
|
||||
@ -142,12 +150,12 @@ async def test_sensor(hass):
|
||||
assert state.state == "4"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_SULPHUR_DIOXIDE
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) == STATE_CLASS_MEASUREMENT
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) == "bardzo dobry"
|
||||
|
||||
entry = registry.async_get("sensor.home_so2")
|
||||
@ -159,9 +167,9 @@ async def test_sensor(hass):
|
||||
assert state.state == "dobry"
|
||||
assert state.attributes.get(ATTR_ATTRIBUTION) == ATTRIBUTION
|
||||
assert state.attributes.get(ATTR_STATION) == "Test Name 1"
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_AQI
|
||||
assert state.attributes.get(ATTR_STATE_CLASS) is None
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
|
||||
entry = registry.async_get("sensor.home_aqi")
|
||||
assert entry
|
||||
@ -225,7 +233,7 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:molecule"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_c6h6")
|
||||
@ -242,7 +250,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_co")
|
||||
@ -259,7 +266,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_no2")
|
||||
@ -276,7 +282,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_o3")
|
||||
@ -293,7 +298,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_pm10")
|
||||
@ -310,7 +314,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_pm2_5")
|
||||
@ -327,7 +330,6 @@ async def test_invalid_indexes(hass):
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
|
||||
)
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:blur"
|
||||
assert state.attributes.get(ATTR_INDEX) is None
|
||||
|
||||
entry = registry.async_get("sensor.home_so2")
|
||||
|
Loading…
x
Reference in New Issue
Block a user