Use constants with TypedDict (#50879)

This commit is contained in:
Maciej Bieniek
2021-05-20 11:34:32 +02:00
committed by GitHub
parent ccd8e1332c
commit 3bdefc5da7
2 changed files with 33 additions and 22 deletions

View File

@@ -5,7 +5,12 @@ from typing import Any, cast
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_DEVICE_CLASS,
ATTR_ICON,
CONF_NAME,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@@ -16,6 +21,8 @@ from . import AirlyDataUpdateCoordinator
from .const import (
ATTR_API_PM1,
ATTR_API_PRESSURE,
ATTR_LABEL,
ATTR_UNIT,
ATTRIBUTION,
DEFAULT_NAME,
DOMAIN,
@@ -63,7 +70,7 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
@property
def name(self) -> str:
"""Return the name."""
return f"{self._name} {self._description['label']}"
return f"{self._name} {self._description[ATTR_LABEL]}"
@property
def state(self) -> StateType:
@@ -81,12 +88,12 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
@property
def icon(self) -> str | None:
"""Return the icon."""
return self._description["icon"]
return self._description[ATTR_ICON]
@property
def device_class(self) -> str | None:
"""Return the device_class."""
return self._description["device_class"]
return self._description[ATTR_DEVICE_CLASS]
@property
def unique_id(self) -> str:
@@ -111,4 +118,4 @@ class AirlySensor(CoordinatorEntity, SensorEntity):
@property
def unit_of_measurement(self) -> str | None:
"""Return the unit the value is expressed in."""
return self._description["unit"]
return self._description[ATTR_UNIT]