mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Fix translation keys for NAM sensors (#85245)
Co-authored-by: Maciej Bieniek <bieniu@users.noreply.github.com>
This commit is contained in:
parent
ef759e9c63
commit
f4a71ea83f
@ -1,6 +1,7 @@
|
|||||||
"""Support for the Nettigo Air Monitor service."""
|
"""Support for the Nettigo Air Monitor service."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import cast
|
from typing import cast
|
||||||
@ -70,208 +71,224 @@ PARALLEL_UPDATES = 1
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSORS: tuple[SensorEntityDescription, ...] = (
|
AQI_LEVEL_STATE_MAPPING = {
|
||||||
SensorEntityDescription(
|
"very low": "very_low",
|
||||||
|
"low": "low",
|
||||||
|
"medium": "medium",
|
||||||
|
"high": "high",
|
||||||
|
"very high": "very_high",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class NAMSensorEntityDescription(SensorEntityDescription):
|
||||||
|
"""Describes NAM sensor entity."""
|
||||||
|
|
||||||
|
mapping: dict[str, str] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
SENSORS: tuple[NAMSensorEntityDescription, ...] = (
|
||||||
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BME280_HUMIDITY,
|
key=ATTR_BME280_HUMIDITY,
|
||||||
name="BME280 humidity",
|
name="BME280 humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BME280_PRESSURE,
|
key=ATTR_BME280_PRESSURE,
|
||||||
name="BME280 pressure",
|
name="BME280 pressure",
|
||||||
native_unit_of_measurement=UnitOfPressure.HPA,
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BME280_TEMPERATURE,
|
key=ATTR_BME280_TEMPERATURE,
|
||||||
name="BME280 temperature",
|
name="BME280 temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BMP180_PRESSURE,
|
key=ATTR_BMP180_PRESSURE,
|
||||||
name="BMP180 pressure",
|
name="BMP180 pressure",
|
||||||
native_unit_of_measurement=UnitOfPressure.HPA,
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BMP180_TEMPERATURE,
|
key=ATTR_BMP180_TEMPERATURE,
|
||||||
name="BMP180 temperature",
|
name="BMP180 temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BMP280_PRESSURE,
|
key=ATTR_BMP280_PRESSURE,
|
||||||
name="BMP280 pressure",
|
name="BMP280 pressure",
|
||||||
native_unit_of_measurement=UnitOfPressure.HPA,
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_BMP280_TEMPERATURE,
|
key=ATTR_BMP280_TEMPERATURE,
|
||||||
name="BMP280 temperature",
|
name="BMP280 temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_HECA_HUMIDITY,
|
key=ATTR_HECA_HUMIDITY,
|
||||||
name="HECA humidity",
|
name="HECA humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_HECA_TEMPERATURE,
|
key=ATTR_HECA_TEMPERATURE,
|
||||||
name="HECA temperature",
|
name="HECA temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_MHZ14A_CARBON_DIOXIDE,
|
key=ATTR_MHZ14A_CARBON_DIOXIDE,
|
||||||
name="MH-Z14A carbon dioxide",
|
name="MH-Z14A carbon dioxide",
|
||||||
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
|
||||||
device_class=SensorDeviceClass.CO2,
|
device_class=SensorDeviceClass.CO2,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_PMSX003_CAQI,
|
key=ATTR_PMSX003_CAQI,
|
||||||
name="PMSx003 CAQI",
|
name="PMSx003 CAQI",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_PMSX003_CAQI_LEVEL,
|
key=ATTR_PMSX003_CAQI_LEVEL,
|
||||||
name="PMSx003 CAQI level",
|
name="PMSx003 CAQI level",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=["very low", "low", "medium", "high", "very high"],
|
mapping=AQI_LEVEL_STATE_MAPPING,
|
||||||
translation_key="caqi_level",
|
translation_key="caqi_level",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_PMSX003_P0,
|
key=ATTR_PMSX003_P0,
|
||||||
name="PMSx003 particulate matter 1.0",
|
name="PMSx003 particulate matter 1.0",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM1,
|
device_class=SensorDeviceClass.PM1,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_PMSX003_P1,
|
key=ATTR_PMSX003_P1,
|
||||||
name="PMSx003 particulate matter 10",
|
name="PMSx003 particulate matter 10",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM10,
|
device_class=SensorDeviceClass.PM10,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_PMSX003_P2,
|
key=ATTR_PMSX003_P2,
|
||||||
name="PMSx003 particulate matter 2.5",
|
name="PMSx003 particulate matter 2.5",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM25,
|
device_class=SensorDeviceClass.PM25,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SDS011_CAQI,
|
key=ATTR_SDS011_CAQI,
|
||||||
name="SDS011 CAQI",
|
name="SDS011 CAQI",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SDS011_CAQI_LEVEL,
|
key=ATTR_SDS011_CAQI_LEVEL,
|
||||||
name="SDS011 CAQI level",
|
name="SDS011 CAQI level",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=["very low", "low", "medium", "high", "very high"],
|
mapping=AQI_LEVEL_STATE_MAPPING,
|
||||||
translation_key="caqi_level",
|
translation_key="caqi_level",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SDS011_P1,
|
key=ATTR_SDS011_P1,
|
||||||
name="SDS011 particulate matter 10",
|
name="SDS011 particulate matter 10",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM10,
|
device_class=SensorDeviceClass.PM10,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SDS011_P2,
|
key=ATTR_SDS011_P2,
|
||||||
name="SDS011 particulate matter 2.5",
|
name="SDS011 particulate matter 2.5",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM25,
|
device_class=SensorDeviceClass.PM25,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SHT3X_HUMIDITY,
|
key=ATTR_SHT3X_HUMIDITY,
|
||||||
name="SHT3X humidity",
|
name="SHT3X humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SHT3X_TEMPERATURE,
|
key=ATTR_SHT3X_TEMPERATURE,
|
||||||
name="SHT3X temperature",
|
name="SHT3X temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_CAQI,
|
key=ATTR_SPS30_CAQI,
|
||||||
name="SPS30 CAQI",
|
name="SPS30 CAQI",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_CAQI_LEVEL,
|
key=ATTR_SPS30_CAQI_LEVEL,
|
||||||
name="SPS30 CAQI level",
|
name="SPS30 CAQI level",
|
||||||
icon="mdi:air-filter",
|
icon="mdi:air-filter",
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=["very low", "low", "medium", "high", "very high"],
|
mapping=AQI_LEVEL_STATE_MAPPING,
|
||||||
translation_key="caqi_level",
|
translation_key="caqi_level",
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_P0,
|
key=ATTR_SPS30_P0,
|
||||||
name="SPS30 particulate matter 1.0",
|
name="SPS30 particulate matter 1.0",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM1,
|
device_class=SensorDeviceClass.PM1,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_P1,
|
key=ATTR_SPS30_P1,
|
||||||
name="SPS30 particulate matter 10",
|
name="SPS30 particulate matter 10",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM10,
|
device_class=SensorDeviceClass.PM10,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_P2,
|
key=ATTR_SPS30_P2,
|
||||||
name="SPS30 particulate matter 2.5",
|
name="SPS30 particulate matter 2.5",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
device_class=SensorDeviceClass.PM25,
|
device_class=SensorDeviceClass.PM25,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SPS30_P4,
|
key=ATTR_SPS30_P4,
|
||||||
name="SPS30 particulate matter 4.0",
|
name="SPS30 particulate matter 4.0",
|
||||||
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
icon="mdi:molecule",
|
icon="mdi:molecule",
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_DHT22_HUMIDITY,
|
key=ATTR_DHT22_HUMIDITY,
|
||||||
name="DHT22 humidity",
|
name="DHT22 humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_DHT22_TEMPERATURE,
|
key=ATTR_DHT22_TEMPERATURE,
|
||||||
name="DHT22 temperature",
|
name="DHT22 temperature",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_SIGNAL_STRENGTH,
|
key=ATTR_SIGNAL_STRENGTH,
|
||||||
name="Signal strength",
|
name="Signal strength",
|
||||||
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
@ -280,7 +297,7 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
NAMSensorEntityDescription(
|
||||||
key=ATTR_UPTIME,
|
key=ATTR_UPTIME,
|
||||||
name="Uptime",
|
name="Uptime",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
device_class=SensorDeviceClass.TIMESTAMP,
|
||||||
@ -326,11 +343,12 @@ class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity):
|
|||||||
"""Define an Nettigo Air Monitor sensor."""
|
"""Define an Nettigo Air Monitor sensor."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
entity_description: NAMSensorEntityDescription
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator: NAMDataUpdateCoordinator,
|
coordinator: NAMDataUpdateCoordinator,
|
||||||
description: SensorEntityDescription,
|
description: NAMSensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
@ -341,6 +359,11 @@ class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType | datetime:
|
def native_value(self) -> StateType | datetime:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
|
if self.entity_description.mapping is not None:
|
||||||
|
return self.entity_description.mapping[
|
||||||
|
cast(str, getattr(self.coordinator.data, self.entity_description.key))
|
||||||
|
]
|
||||||
|
|
||||||
return cast(
|
return cast(
|
||||||
StateType, getattr(self.coordinator.data, self.entity_description.key)
|
StateType, getattr(self.coordinator.data, self.entity_description.key)
|
||||||
)
|
)
|
||||||
@ -358,6 +381,13 @@ class NAMSensor(CoordinatorEntity[NAMDataUpdateCoordinator], SensorEntity):
|
|||||||
and getattr(self.coordinator.data, self.entity_description.key) is not None
|
and getattr(self.coordinator.data, self.entity_description.key) is not None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def options(self) -> list[str] | None:
|
||||||
|
"""If the entity description provides a mapping, use that."""
|
||||||
|
if self.entity_description.mapping:
|
||||||
|
return list(self.entity_description.mapping.values())
|
||||||
|
return super().options
|
||||||
|
|
||||||
|
|
||||||
class NAMSensorUptime(NAMSensor):
|
class NAMSensorUptime(NAMSensor):
|
||||||
"""Define an Nettigo Air Monitor uptime sensor."""
|
"""Define an Nettigo Air Monitor uptime sensor."""
|
||||||
|
@ -42,11 +42,11 @@
|
|||||||
"sensor": {
|
"sensor": {
|
||||||
"caqi_level": {
|
"caqi_level": {
|
||||||
"state": {
|
"state": {
|
||||||
"very low": "Very low",
|
"very_low": "Very low",
|
||||||
"low": "Low",
|
"low": "Low",
|
||||||
"medium": "Medium",
|
"medium": "Medium",
|
||||||
"high": "High",
|
"high": "High",
|
||||||
"very high": "Very high"
|
"very_high": "Very high"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,14 +231,14 @@ async def test_sensor(hass):
|
|||||||
|
|
||||||
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_caqi_level")
|
state = hass.states.get("sensor.nettigo_air_monitor_pmsx003_caqi_level")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "very low"
|
assert state.state == "very_low"
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
||||||
assert state.attributes.get(ATTR_OPTIONS) == [
|
assert state.attributes.get(ATTR_OPTIONS) == [
|
||||||
"very low",
|
"very_low",
|
||||||
"low",
|
"low",
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
"very high",
|
"very_high",
|
||||||
]
|
]
|
||||||
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
||||||
|
|
||||||
@ -331,14 +331,14 @@ async def test_sensor(hass):
|
|||||||
|
|
||||||
state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi_level")
|
state = hass.states.get("sensor.nettigo_air_monitor_sds011_caqi_level")
|
||||||
assert state
|
assert state
|
||||||
assert state.state == "very low"
|
assert state.state == "very_low"
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
||||||
assert state.attributes.get(ATTR_OPTIONS) == [
|
assert state.attributes.get(ATTR_OPTIONS) == [
|
||||||
"very low",
|
"very_low",
|
||||||
"low",
|
"low",
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
"very high",
|
"very_high",
|
||||||
]
|
]
|
||||||
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
||||||
|
|
||||||
@ -377,11 +377,11 @@ async def test_sensor(hass):
|
|||||||
assert state.state == "medium"
|
assert state.state == "medium"
|
||||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.ENUM
|
||||||
assert state.attributes.get(ATTR_OPTIONS) == [
|
assert state.attributes.get(ATTR_OPTIONS) == [
|
||||||
"very low",
|
"very_low",
|
||||||
"low",
|
"low",
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
"very high",
|
"very_high",
|
||||||
]
|
]
|
||||||
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
assert state.attributes.get(ATTR_ICON) == "mdi:air-filter"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user