Use EntityDescription - awair (#55747)

This commit is contained in:
Marc Mueller 2021-09-06 09:40:41 +02:00 committed by GitHub
parent 99ef2ae54d
commit cc6a0d2f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 154 additions and 136 deletions

View File

@ -1,4 +1,5 @@
"""Constants for the Awair component.""" """Constants for the Awair component."""
from __future__ import annotations
from dataclasses import dataclass from dataclasses import dataclass
from datetime import timedelta from datetime import timedelta
@ -6,9 +7,8 @@ import logging
from python_awair.devices import AwairDevice from python_awair.devices import AwairDevice
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ICON,
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
CONCENTRATION_PARTS_PER_BILLION, CONCENTRATION_PARTS_PER_BILLION,
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
@ -36,10 +36,6 @@ API_VOC = "volatile_organic_compounds"
ATTRIBUTION = "Awair air quality sensor" ATTRIBUTION = "Awair air quality sensor"
ATTR_LABEL = "label"
ATTR_UNIT = "unit"
ATTR_UNIQUE_ID = "unique_id"
DOMAIN = "awair" DOMAIN = "awair"
DUST_ALIASES = [API_PM25, API_PM10] DUST_ALIASES = [API_PM25, API_PM10]
@ -48,71 +44,89 @@ LOGGER = logging.getLogger(__package__)
UPDATE_INTERVAL = timedelta(minutes=5) UPDATE_INTERVAL = timedelta(minutes=5)
SENSOR_TYPES = {
API_SCORE: { @dataclass
ATTR_DEVICE_CLASS: None, class AwairRequiredKeysMixin:
ATTR_ICON: "mdi:blur", """Mixinf for required keys."""
ATTR_UNIT: PERCENTAGE,
ATTR_LABEL: "Awair score", unique_id_tag: str
ATTR_UNIQUE_ID: "score", # matches legacy format
},
API_HUMID: { @dataclass
ATTR_DEVICE_CLASS: DEVICE_CLASS_HUMIDITY, class AwairSensorEntityDescription(SensorEntityDescription, AwairRequiredKeysMixin):
ATTR_ICON: None, """Describes Awair sensor entity."""
ATTR_UNIT: PERCENTAGE,
ATTR_LABEL: "Humidity",
ATTR_UNIQUE_ID: "HUMID", # matches legacy format SENSOR_TYPE_SCORE = AwairSensorEntityDescription(
}, key=API_SCORE,
API_LUX: { icon="mdi:blur",
ATTR_DEVICE_CLASS: DEVICE_CLASS_ILLUMINANCE, native_unit_of_measurement=PERCENTAGE,
ATTR_ICON: None, name="Awair score",
ATTR_UNIT: LIGHT_LUX, unique_id_tag="score", # matches legacy format
ATTR_LABEL: "Illuminance", )
ATTR_UNIQUE_ID: "illuminance",
}, SENSOR_TYPES: tuple[AwairSensorEntityDescription, ...] = (
API_SPL_A: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: None, key=API_HUMID,
ATTR_ICON: "mdi:ear-hearing", device_class=DEVICE_CLASS_HUMIDITY,
ATTR_UNIT: SOUND_PRESSURE_WEIGHTED_DBA, native_unit_of_measurement=PERCENTAGE,
ATTR_LABEL: "Sound level", name="Humidity",
ATTR_UNIQUE_ID: "sound_level", unique_id_tag="HUMID", # matches legacy format
}, ),
API_VOC: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: None, key=API_LUX,
ATTR_ICON: "mdi:cloud", device_class=DEVICE_CLASS_ILLUMINANCE,
ATTR_UNIT: CONCENTRATION_PARTS_PER_BILLION, native_unit_of_measurement=LIGHT_LUX,
ATTR_LABEL: "Volatile organic compounds", name="Illuminance",
ATTR_UNIQUE_ID: "VOC", # matches legacy format unique_id_tag="illuminance",
}, ),
API_TEMP: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, key=API_SPL_A,
ATTR_ICON: None, icon="mdi:ear-hearing",
ATTR_UNIT: TEMP_CELSIUS, native_unit_of_measurement=SOUND_PRESSURE_WEIGHTED_DBA,
ATTR_LABEL: "Temperature", name="Sound level",
ATTR_UNIQUE_ID: "TEMP", # matches legacy format unique_id_tag="sound_level",
}, ),
API_PM25: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: None, key=API_VOC,
ATTR_ICON: "mdi:blur", icon="mdi:cloud",
ATTR_UNIT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, native_unit_of_measurement=CONCENTRATION_PARTS_PER_BILLION,
ATTR_LABEL: "PM2.5", name="Volatile organic compounds",
ATTR_UNIQUE_ID: "PM25", # matches legacy format unique_id_tag="VOC", # matches legacy format
}, ),
API_PM10: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: None, key=API_TEMP,
ATTR_ICON: "mdi:blur", device_class=DEVICE_CLASS_TEMPERATURE,
ATTR_UNIT: CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, native_unit_of_measurement=TEMP_CELSIUS,
ATTR_LABEL: "PM10", name="Temperature",
ATTR_UNIQUE_ID: "PM10", # matches legacy format unique_id_tag="TEMP", # matches legacy format
}, ),
API_CO2: { AwairSensorEntityDescription(
ATTR_DEVICE_CLASS: DEVICE_CLASS_CO2, key=API_CO2,
ATTR_ICON: "mdi:cloud", device_class=DEVICE_CLASS_CO2,
ATTR_UNIT: CONCENTRATION_PARTS_PER_MILLION, icon="mdi:cloud",
ATTR_LABEL: "Carbon dioxide", native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
ATTR_UNIQUE_ID: "CO2", # matches legacy format name="Carbon dioxide",
}, unique_id_tag="CO2", # matches legacy format
} ),
)
SENSOR_TYPES_DUST: tuple[AwairSensorEntityDescription, ...] = (
AwairSensorEntityDescription(
key=API_PM25,
icon="mdi:blur",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
name="PM2.5",
unique_id_tag="PM25", # matches legacy format
),
AwairSensorEntityDescription(
key=API_PM10,
icon="mdi:blur",
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
name="PM10",
unique_id_tag="PM10", # matches legacy format
),
)
@dataclass @dataclass

View File

@ -7,7 +7,7 @@ import voluptuous as vol
from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult from homeassistant.components.awair import AwairDataUpdateCoordinator, AwairResult
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import ATTR_ATTRIBUTION, ATTR_DEVICE_CLASS, CONF_ACCESS_TOKEN from homeassistant.const import ATTR_ATTRIBUTION, CONF_ACCESS_TOKEN
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr from homeassistant.helpers import device_registry as dr
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -22,15 +22,14 @@ from .const import (
API_SCORE, API_SCORE,
API_TEMP, API_TEMP,
API_VOC, API_VOC,
ATTR_ICON,
ATTR_LABEL,
ATTR_UNIQUE_ID,
ATTR_UNIT,
ATTRIBUTION, ATTRIBUTION,
DOMAIN, DOMAIN,
DUST_ALIASES, DUST_ALIASES,
LOGGER, LOGGER,
SENSOR_TYPE_SCORE,
SENSOR_TYPES, SENSOR_TYPES,
SENSOR_TYPES_DUST,
AwairSensorEntityDescription,
) )
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -60,16 +59,20 @@ async def async_setup_entry(
): ):
"""Set up Awair sensor entity based on a config entry.""" """Set up Awair sensor entity based on a config entry."""
coordinator = hass.data[DOMAIN][config_entry.entry_id] coordinator = hass.data[DOMAIN][config_entry.entry_id]
sensors = [] entities = []
data: list[AwairResult] = coordinator.data.values() data: list[AwairResult] = coordinator.data.values()
for result in data: for result in data:
if result.air_data: if result.air_data:
sensors.append(AwairSensor(API_SCORE, result.device, coordinator)) entities.append(AwairSensor(result.device, coordinator, SENSOR_TYPE_SCORE))
device_sensors = result.air_data.sensors.keys() device_sensors = result.air_data.sensors.keys()
for sensor in device_sensors: entities.extend(
if sensor in SENSOR_TYPES: [
sensors.append(AwairSensor(sensor, result.device, coordinator)) AwairSensor(result.device, coordinator, description)
for description in (*SENSOR_TYPES, *SENSOR_TYPES_DUST)
if description.key in device_sensors
]
)
# The "DUST" sensor for Awair is a combo pm2.5/pm10 sensor only # The "DUST" sensor for Awair is a combo pm2.5/pm10 sensor only
# present on first-gen devices in lieu of separate pm2.5/pm10 sensors. # present on first-gen devices in lieu of separate pm2.5/pm10 sensors.
@ -78,45 +81,53 @@ async def async_setup_entry(
# that data - because we can't really tell what kind of particles the # that data - because we can't really tell what kind of particles the
# "DUST" sensor actually detected. However, it's still useful data. # "DUST" sensor actually detected. However, it's still useful data.
if API_DUST in device_sensors: if API_DUST in device_sensors:
for alias_kind in DUST_ALIASES: entities.extend(
sensors.append(AwairSensor(alias_kind, result.device, coordinator)) [
AwairSensor(result.device, coordinator, description)
for description in SENSOR_TYPES_DUST
]
)
async_add_entities(sensors) async_add_entities(entities)
class AwairSensor(CoordinatorEntity, SensorEntity): class AwairSensor(CoordinatorEntity, SensorEntity):
"""Defines an Awair sensor entity.""" """Defines an Awair sensor entity."""
entity_description: AwairSensorEntityDescription
def __init__( def __init__(
self, self,
kind: str,
device: AwairDevice, device: AwairDevice,
coordinator: AwairDataUpdateCoordinator, coordinator: AwairDataUpdateCoordinator,
description: AwairSensorEntityDescription,
) -> None: ) -> None:
"""Set up an individual AwairSensor.""" """Set up an individual AwairSensor."""
super().__init__(coordinator) super().__init__(coordinator)
self._kind = kind self.entity_description = description
self._device = device self._device = device
@property @property
def name(self) -> str: def name(self) -> str | None:
"""Return the name of the sensor.""" """Return the name of the sensor."""
name = SENSOR_TYPES[self._kind][ATTR_LABEL]
if self._device.name: if self._device.name:
name = f"{self._device.name} {name}" return f"{self._device.name} {self.entity_description.name}"
return name return self.entity_description.name
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
"""Return the uuid as the unique_id.""" """Return the uuid as the unique_id."""
unique_id_tag = SENSOR_TYPES[self._kind][ATTR_UNIQUE_ID] unique_id_tag = self.entity_description.unique_id_tag
# This integration used to create a sensor that was labelled as a "PM2.5" # This integration used to create a sensor that was labelled as a "PM2.5"
# sensor for first-gen Awair devices, but its unique_id reflected the truth: # sensor for first-gen Awair devices, but its unique_id reflected the truth:
# under the hood, it was a "DUST" sensor. So we preserve that specific unique_id # under the hood, it was a "DUST" sensor. So we preserve that specific unique_id
# for users with first-gen devices that are upgrading. # for users with first-gen devices that are upgrading.
if self._kind == API_PM25 and API_DUST in self._air_data.sensors: if (
self.entity_description.key == API_PM25
and API_DUST in self._air_data.sensors
):
unique_id_tag = "DUST" unique_id_tag = "DUST"
return f"{self._device.uuid}_{unique_id_tag}" return f"{self._device.uuid}_{unique_id_tag}"
@ -127,16 +138,17 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
# If the last update was successful... # If the last update was successful...
if self.coordinator.last_update_success and self._air_data: if self.coordinator.last_update_success and self._air_data:
# and the results included our sensor type... # and the results included our sensor type...
if self._kind in self._air_data.sensors: sensor_type = self.entity_description.key
if sensor_type in self._air_data.sensors:
# then we are available. # then we are available.
return True return True
# or, we're a dust alias # or, we're a dust alias
if self._kind in DUST_ALIASES and API_DUST in self._air_data.sensors: if sensor_type in DUST_ALIASES and API_DUST in self._air_data.sensors:
return True return True
# or we are API_SCORE # or we are API_SCORE
if self._kind == API_SCORE: if sensor_type == API_SCORE:
# then we are available. # then we are available.
return True return True
@ -147,38 +159,24 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
def native_value(self) -> float: def native_value(self) -> float:
"""Return the state, rounding off to reasonable values.""" """Return the state, rounding off to reasonable values."""
state: float state: float
sensor_type = self.entity_description.key
# Special-case for "SCORE", which we treat as the AQI # Special-case for "SCORE", which we treat as the AQI
if self._kind == API_SCORE: if sensor_type == API_SCORE:
state = self._air_data.score state = self._air_data.score
elif self._kind in DUST_ALIASES and API_DUST in self._air_data.sensors: elif sensor_type in DUST_ALIASES and API_DUST in self._air_data.sensors:
state = self._air_data.sensors.dust state = self._air_data.sensors.dust
else: else:
state = self._air_data.sensors[self._kind] state = self._air_data.sensors[sensor_type]
if self._kind == API_VOC or self._kind == API_SCORE: if sensor_type in {API_VOC, API_SCORE}:
return round(state) return round(state)
if self._kind == API_TEMP: if sensor_type == API_TEMP:
return round(state, 1) return round(state, 1)
return round(state, 2) return round(state, 2)
@property
def icon(self) -> str:
"""Return the icon."""
return SENSOR_TYPES[self._kind][ATTR_ICON]
@property
def device_class(self) -> str:
"""Return the device_class."""
return SENSOR_TYPES[self._kind][ATTR_DEVICE_CLASS]
@property
def native_unit_of_measurement(self) -> str:
"""Return the unit the value is expressed in."""
return SENSOR_TYPES[self._kind][ATTR_UNIT]
@property @property
def extra_state_attributes(self) -> dict: def extra_state_attributes(self) -> dict:
"""Return the Awair Index alongside state attributes. """Return the Awair Index alongside state attributes.
@ -201,10 +199,11 @@ class AwairSensor(CoordinatorEntity, SensorEntity):
https://docs.developer.getawair.com/?version=latest#awair-score-and-index https://docs.developer.getawair.com/?version=latest#awair-score-and-index
""" """
sensor_type = self.entity_description.key
attrs = {ATTR_ATTRIBUTION: ATTRIBUTION} attrs = {ATTR_ATTRIBUTION: ATTRIBUTION}
if self._kind in self._air_data.indices: if sensor_type in self._air_data.indices:
attrs["awair_index"] = abs(self._air_data.indices[self._kind]) attrs["awair_index"] = abs(self._air_data.indices[sensor_type])
elif self._kind in DUST_ALIASES and API_DUST in self._air_data.indices: elif sensor_type in DUST_ALIASES and API_DUST in self._air_data.indices:
attrs["awair_index"] = abs(self._air_data.indices.dust) attrs["awair_index"] = abs(self._air_data.indices.dust)
return attrs return attrs

View File

@ -11,9 +11,10 @@ from homeassistant.components.awair.const import (
API_SPL_A, API_SPL_A,
API_TEMP, API_TEMP,
API_VOC, API_VOC,
ATTR_UNIQUE_ID,
DOMAIN, DOMAIN,
SENSOR_TYPE_SCORE,
SENSOR_TYPES, SENSOR_TYPES,
SENSOR_TYPES_DUST,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ICON, ATTR_ICON,
@ -44,6 +45,10 @@ from .const import (
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
SENSOR_TYPES_MAP = {
desc.key: desc for desc in (SENSOR_TYPE_SCORE, *SENSOR_TYPES, *SENSOR_TYPES_DUST)
}
async def setup_awair(hass, fixtures): async def setup_awair(hass, fixtures):
"""Add Awair devices to hass, using specified fixtures for data.""" """Add Awair devices to hass, using specified fixtures for data."""
@ -80,7 +85,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"88", "88",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -89,7 +94,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_temperature", "sensor.living_room_temperature",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_TEMP][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_TEMP].unique_id_tag}",
"21.8", "21.8",
{ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, "awair_index": 1.0}, {ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, "awair_index": 1.0},
) )
@ -98,7 +103,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_humidity", "sensor.living_room_humidity",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_HUMID][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_HUMID].unique_id_tag}",
"41.59", "41.59",
{ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, "awair_index": 0.0}, {ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE, "awair_index": 0.0},
) )
@ -107,7 +112,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_carbon_dioxide", "sensor.living_room_carbon_dioxide",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_CO2][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_CO2].unique_id_tag}",
"654.0", "654.0",
{ {
ATTR_ICON: "mdi:cloud", ATTR_ICON: "mdi:cloud",
@ -120,7 +125,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_volatile_organic_compounds", "sensor.living_room_volatile_organic_compounds",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_VOC][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_VOC].unique_id_tag}",
"366", "366",
{ {
ATTR_ICON: "mdi:cloud", ATTR_ICON: "mdi:cloud",
@ -147,7 +152,7 @@ async def test_awair_gen1_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_pm10", "sensor.living_room_pm10",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_PM10][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM10].unique_id_tag}",
"14.3", "14.3",
{ {
ATTR_ICON: "mdi:blur", ATTR_ICON: "mdi:blur",
@ -176,7 +181,7 @@ async def test_awair_gen2_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"97", "97",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -185,7 +190,7 @@ async def test_awair_gen2_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_pm2_5", "sensor.living_room_pm2_5",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_PM25][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM25].unique_id_tag}",
"2.0", "2.0",
{ {
ATTR_ICON: "mdi:blur", ATTR_ICON: "mdi:blur",
@ -210,7 +215,7 @@ async def test_awair_mint_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"98", "98",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -219,7 +224,7 @@ async def test_awair_mint_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_pm2_5", "sensor.living_room_pm2_5",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_PM25][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_PM25].unique_id_tag}",
"1.0", "1.0",
{ {
ATTR_ICON: "mdi:blur", ATTR_ICON: "mdi:blur",
@ -232,7 +237,7 @@ async def test_awair_mint_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_illuminance", "sensor.living_room_illuminance",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_LUX][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_LUX].unique_id_tag}",
"441.7", "441.7",
{ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX}, {ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX},
) )
@ -252,7 +257,7 @@ async def test_awair_glow_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"93", "93",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -272,7 +277,7 @@ async def test_awair_omni_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"99", "99",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -281,7 +286,7 @@ async def test_awair_omni_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_sound_level", "sensor.living_room_sound_level",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SPL_A][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SPL_A].unique_id_tag}",
"47.0", "47.0",
{ATTR_ICON: "mdi:ear-hearing", ATTR_UNIT_OF_MEASUREMENT: "dBa"}, {ATTR_ICON: "mdi:ear-hearing", ATTR_UNIT_OF_MEASUREMENT: "dBa"},
) )
@ -290,7 +295,7 @@ async def test_awair_omni_sensors(hass):
hass, hass,
registry, registry,
"sensor.living_room_illuminance", "sensor.living_room_illuminance",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_LUX][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_LUX].unique_id_tag}",
"804.9", "804.9",
{ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX}, {ATTR_UNIT_OF_MEASUREMENT: LIGHT_LUX},
) )
@ -325,7 +330,7 @@ async def test_awair_unavailable(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
"88", "88",
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )
@ -338,7 +343,7 @@ async def test_awair_unavailable(hass):
hass, hass,
registry, registry,
"sensor.living_room_awair_score", "sensor.living_room_awair_score",
f"{AWAIR_UUID}_{SENSOR_TYPES[API_SCORE][ATTR_UNIQUE_ID]}", f"{AWAIR_UUID}_{SENSOR_TYPES_MAP[API_SCORE].unique_id_tag}",
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
{ATTR_ICON: "mdi:blur"}, {ATTR_ICON: "mdi:blur"},
) )