Address late review comments for AccuWeather integration (#50866)

* Remove unnecessary converting datetime to str

* Address late comments
This commit is contained in:
Maciej Bieniek 2021-05-20 09:29:10 +02:00 committed by GitHub
parent d4d335fb9c
commit ccd8e1332c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 225 additions and 203 deletions

View file

@ -99,7 +99,7 @@ class AccuWeatherDataUpdateCoordinator(DataUpdateCoordinator[Dict[str, Any]]):
update_interval = timedelta(minutes=40) update_interval = timedelta(minutes=40)
if self.forecast: if self.forecast:
update_interval *= 2 update_interval *= 2
_LOGGER.debug("Data will be update every %s", str(update_interval)) _LOGGER.debug("Data will be update every %s", update_interval)
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval) super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=update_interval)

View file

@ -20,6 +20,8 @@ from homeassistant.components.weather import (
ATTR_CONDITION_WINDY, ATTR_CONDITION_WINDY,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ICON,
CONCENTRATION_PARTS_PER_CUBIC_METER, CONCENTRATION_PARTS_PER_CUBIC_METER,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TEMPERATURE,
LENGTH_FEET, LENGTH_FEET,
@ -37,8 +39,14 @@ from homeassistant.const import (
from .model import SensorDescription from .model import SensorDescription
API_IMPERIAL: Final = "Imperial"
API_METRIC: Final = "Metric"
ATTRIBUTION: Final = "Data provided by AccuWeather" ATTRIBUTION: Final = "Data provided by AccuWeather"
ATTR_ENABLED: Final = "enabled"
ATTR_FORECAST: Final = "forecast" ATTR_FORECAST: Final = "forecast"
ATTR_LABEL: Final = "label"
ATTR_UNIT_IMPERIAL: Final = "unit_imperial"
ATTR_UNIT_METRIC: Final = "unit_metric"
CONF_FORECAST: Final = "forecast" CONF_FORECAST: Final = "forecast"
COORDINATOR: Final = "coordinator" COORDINATOR: Final = "coordinator"
DOMAIN: Final = "accuweather" DOMAIN: Final = "accuweather"
@ -66,262 +74,262 @@ CONDITION_CLASSES: Final[dict[str, list[int]]] = {
FORECAST_SENSOR_TYPES: Final[dict[str, SensorDescription]] = { FORECAST_SENSOR_TYPES: Final[dict[str, SensorDescription]] = {
"CloudCoverDay": { "CloudCoverDay": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-cloudy", ATTR_ICON: "mdi:weather-cloudy",
"label": "Cloud Cover Day", ATTR_LABEL: "Cloud Cover Day",
"unit_metric": PERCENTAGE, ATTR_UNIT_METRIC: PERCENTAGE,
"unit_imperial": PERCENTAGE, ATTR_UNIT_IMPERIAL: PERCENTAGE,
"enabled": False, ATTR_ENABLED: False,
}, },
"CloudCoverNight": { "CloudCoverNight": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-cloudy", ATTR_ICON: "mdi:weather-cloudy",
"label": "Cloud Cover Night", ATTR_LABEL: "Cloud Cover Night",
"unit_metric": PERCENTAGE, ATTR_UNIT_METRIC: PERCENTAGE,
"unit_imperial": PERCENTAGE, ATTR_UNIT_IMPERIAL: PERCENTAGE,
"enabled": False, ATTR_ENABLED: False,
}, },
"Grass": { "Grass": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:grass", ATTR_ICON: "mdi:grass",
"label": "Grass Pollen", ATTR_LABEL: "Grass Pollen",
"unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER,
"unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER,
"enabled": False, ATTR_ENABLED: False,
}, },
"HoursOfSun": { "HoursOfSun": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-partly-cloudy", ATTR_ICON: "mdi:weather-partly-cloudy",
"label": "Hours Of Sun", ATTR_LABEL: "Hours Of Sun",
"unit_metric": TIME_HOURS, ATTR_UNIT_METRIC: TIME_HOURS,
"unit_imperial": TIME_HOURS, ATTR_UNIT_IMPERIAL: TIME_HOURS,
"enabled": True, ATTR_ENABLED: True,
}, },
"Mold": { "Mold": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:blur", ATTR_ICON: "mdi:blur",
"label": "Mold Pollen", ATTR_LABEL: "Mold Pollen",
"unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER,
"unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER,
"enabled": False, ATTR_ENABLED: False,
}, },
"Ozone": { "Ozone": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:vector-triangle", ATTR_ICON: "mdi:vector-triangle",
"label": "Ozone", ATTR_LABEL: "Ozone",
"unit_metric": None, ATTR_UNIT_METRIC: None,
"unit_imperial": None, ATTR_UNIT_IMPERIAL: None,
"enabled": False, ATTR_ENABLED: False,
}, },
"Ragweed": { "Ragweed": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:sprout", ATTR_ICON: "mdi:sprout",
"label": "Ragweed Pollen", ATTR_LABEL: "Ragweed Pollen",
"unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER,
"unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER,
"enabled": False, ATTR_ENABLED: False,
}, },
"RealFeelTemperatureMax": { "RealFeelTemperatureMax": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature Max", ATTR_LABEL: "RealFeel Temperature Max",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": True, ATTR_ENABLED: True,
}, },
"RealFeelTemperatureMin": { "RealFeelTemperatureMin": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature Min", ATTR_LABEL: "RealFeel Temperature Min",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": True, ATTR_ENABLED: True,
}, },
"RealFeelTemperatureShadeMax": { "RealFeelTemperatureShadeMax": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature Shade Max", ATTR_LABEL: "RealFeel Temperature Shade Max",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"RealFeelTemperatureShadeMin": { "RealFeelTemperatureShadeMin": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature Shade Min", ATTR_LABEL: "RealFeel Temperature Shade Min",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"ThunderstormProbabilityDay": { "ThunderstormProbabilityDay": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-lightning", ATTR_ICON: "mdi:weather-lightning",
"label": "Thunderstorm Probability Day", ATTR_LABEL: "Thunderstorm Probability Day",
"unit_metric": PERCENTAGE, ATTR_UNIT_METRIC: PERCENTAGE,
"unit_imperial": PERCENTAGE, ATTR_UNIT_IMPERIAL: PERCENTAGE,
"enabled": True, ATTR_ENABLED: True,
}, },
"ThunderstormProbabilityNight": { "ThunderstormProbabilityNight": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-lightning", ATTR_ICON: "mdi:weather-lightning",
"label": "Thunderstorm Probability Night", ATTR_LABEL: "Thunderstorm Probability Night",
"unit_metric": PERCENTAGE, ATTR_UNIT_METRIC: PERCENTAGE,
"unit_imperial": PERCENTAGE, ATTR_UNIT_IMPERIAL: PERCENTAGE,
"enabled": True, ATTR_ENABLED: True,
}, },
"Tree": { "Tree": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:tree-outline", ATTR_ICON: "mdi:tree-outline",
"label": "Tree Pollen", ATTR_LABEL: "Tree Pollen",
"unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER,
"unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER,
"enabled": False, ATTR_ENABLED: False,
}, },
"UVIndex": { "UVIndex": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-sunny", ATTR_ICON: "mdi:weather-sunny",
"label": "UV Index", ATTR_LABEL: "UV Index",
"unit_metric": UV_INDEX, ATTR_UNIT_METRIC: UV_INDEX,
"unit_imperial": UV_INDEX, ATTR_UNIT_IMPERIAL: UV_INDEX,
"enabled": True, ATTR_ENABLED: True,
}, },
"WindGustDay": { "WindGustDay": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind Gust Day", ATTR_LABEL: "Wind Gust Day",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": False, ATTR_ENABLED: False,
}, },
"WindGustNight": { "WindGustNight": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind Gust Night", ATTR_LABEL: "Wind Gust Night",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": False, ATTR_ENABLED: False,
}, },
"WindDay": { "WindDay": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind Day", ATTR_LABEL: "Wind Day",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": True, ATTR_ENABLED: True,
}, },
"WindNight": { "WindNight": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind Night", ATTR_LABEL: "Wind Night",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": True, ATTR_ENABLED: True,
}, },
} }
SENSOR_TYPES: Final[dict[str, SensorDescription]] = { SENSOR_TYPES: Final[dict[str, SensorDescription]] = {
"ApparentTemperature": { "ApparentTemperature": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "Apparent Temperature", ATTR_LABEL: "Apparent Temperature",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"Ceiling": { "Ceiling": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-fog", ATTR_ICON: "mdi:weather-fog",
"label": "Cloud Ceiling", ATTR_LABEL: "Cloud Ceiling",
"unit_metric": LENGTH_METERS, ATTR_UNIT_METRIC: LENGTH_METERS,
"unit_imperial": LENGTH_FEET, ATTR_UNIT_IMPERIAL: LENGTH_FEET,
"enabled": True, ATTR_ENABLED: True,
}, },
"CloudCover": { "CloudCover": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-cloudy", ATTR_ICON: "mdi:weather-cloudy",
"label": "Cloud Cover", ATTR_LABEL: "Cloud Cover",
"unit_metric": PERCENTAGE, ATTR_UNIT_METRIC: PERCENTAGE,
"unit_imperial": PERCENTAGE, ATTR_UNIT_IMPERIAL: PERCENTAGE,
"enabled": False, ATTR_ENABLED: False,
}, },
"DewPoint": { "DewPoint": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "Dew Point", ATTR_LABEL: "Dew Point",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"RealFeelTemperature": { "RealFeelTemperature": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature", ATTR_LABEL: "RealFeel Temperature",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": True, ATTR_ENABLED: True,
}, },
"RealFeelTemperatureShade": { "RealFeelTemperatureShade": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "RealFeel Temperature Shade", ATTR_LABEL: "RealFeel Temperature Shade",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"Precipitation": { "Precipitation": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-rainy", ATTR_ICON: "mdi:weather-rainy",
"label": "Precipitation", ATTR_LABEL: "Precipitation",
"unit_metric": LENGTH_MILLIMETERS, ATTR_UNIT_METRIC: LENGTH_MILLIMETERS,
"unit_imperial": LENGTH_INCHES, ATTR_UNIT_IMPERIAL: LENGTH_INCHES,
"enabled": True, ATTR_ENABLED: True,
}, },
"PressureTendency": { "PressureTendency": {
"device_class": "accuweather__pressure_tendency", ATTR_DEVICE_CLASS: "accuweather__pressure_tendency",
"icon": "mdi:gauge", ATTR_ICON: "mdi:gauge",
"label": "Pressure Tendency", ATTR_LABEL: "Pressure Tendency",
"unit_metric": None, ATTR_UNIT_METRIC: None,
"unit_imperial": None, ATTR_UNIT_IMPERIAL: None,
"enabled": True, ATTR_ENABLED: True,
}, },
"UVIndex": { "UVIndex": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-sunny", ATTR_ICON: "mdi:weather-sunny",
"label": "UV Index", ATTR_LABEL: "UV Index",
"unit_metric": UV_INDEX, ATTR_UNIT_METRIC: UV_INDEX,
"unit_imperial": UV_INDEX, ATTR_UNIT_IMPERIAL: UV_INDEX,
"enabled": True, ATTR_ENABLED: True,
}, },
"WetBulbTemperature": { "WetBulbTemperature": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "Wet Bulb Temperature", ATTR_LABEL: "Wet Bulb Temperature",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"WindChillTemperature": { "WindChillTemperature": {
"device_class": DEVICE_CLASS_TEMPERATURE, ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE,
"icon": None, ATTR_ICON: None,
"label": "Wind Chill Temperature", ATTR_LABEL: "Wind Chill Temperature",
"unit_metric": TEMP_CELSIUS, ATTR_UNIT_METRIC: TEMP_CELSIUS,
"unit_imperial": TEMP_FAHRENHEIT, ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT,
"enabled": False, ATTR_ENABLED: False,
}, },
"Wind": { "Wind": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind", ATTR_LABEL: "Wind",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": True, ATTR_ENABLED: True,
}, },
"WindGust": { "WindGust": {
"device_class": None, ATTR_DEVICE_CLASS: None,
"icon": "mdi:weather-windy", ATTR_ICON: "mdi:weather-windy",
"label": "Wind Gust", ATTR_LABEL: "Wind Gust",
"unit_metric": SPEED_KILOMETERS_PER_HOUR, ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR,
"unit_imperial": SPEED_MILES_PER_HOUR, ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR,
"enabled": False, ATTR_ENABLED: False,
}, },
} }

View file

@ -5,7 +5,13 @@ from typing import Any, cast
from homeassistant.components.sensor import SensorEntity from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, DEVICE_CLASS_TEMPERATURE from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_DEVICE_CLASS,
ATTR_ICON,
CONF_NAME,
DEVICE_CLASS_TEMPERATURE,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -14,7 +20,13 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from . import AccuWeatherDataUpdateCoordinator from . import AccuWeatherDataUpdateCoordinator
from .const import ( from .const import (
API_IMPERIAL,
API_METRIC,
ATTR_ENABLED,
ATTR_FORECAST, ATTR_FORECAST,
ATTR_LABEL,
ATTR_UNIT_IMPERIAL,
ATTR_UNIT_METRIC,
ATTRIBUTION, ATTRIBUTION,
COORDINATOR, COORDINATOR,
DOMAIN, DOMAIN,
@ -79,7 +91,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
else: else:
self._description = FORECAST_SENSOR_TYPES[kind] self._description = FORECAST_SENSOR_TYPES[kind]
self._sensor_data = coordinator.data[ATTR_FORECAST][forecast_day][kind] self._sensor_data = coordinator.data[ATTR_FORECAST][forecast_day][kind]
self._unit_system = "Metric" if coordinator.is_metric else "Imperial" self._unit_system = API_METRIC if coordinator.is_metric else API_IMPERIAL
self._name = name self._name = name
self.kind = kind self.kind = kind
self._device_class = None self._device_class = None
@ -90,8 +102,8 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
def name(self) -> str: def name(self) -> str:
"""Return the name.""" """Return the name."""
if self.forecast_day is not None: if self.forecast_day is not None:
return f"{self._name} {self._description['label']} {self.forecast_day}d" return f"{self._name} {self._description[ATTR_LABEL]} {self.forecast_day}d"
return f"{self._name} {self._description['label']}" return f"{self._name} {self._description[ATTR_LABEL]}"
@property @property
def unique_id(self) -> str: def unique_id(self) -> str:
@ -137,19 +149,19 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
@property @property
def icon(self) -> str | None: def icon(self) -> str | None:
"""Return the icon.""" """Return the icon."""
return self._description["icon"] return self._description[ATTR_ICON]
@property @property
def device_class(self) -> str | None: def device_class(self) -> str | None:
"""Return the device_class.""" """Return the device_class."""
return self._description["device_class"] return self._description[ATTR_DEVICE_CLASS]
@property @property
def unit_of_measurement(self) -> str | None: def unit_of_measurement(self) -> str | None:
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
if self.coordinator.is_metric: if self.coordinator.is_metric:
return self._description["unit_metric"] return self._description[ATTR_UNIT_METRIC]
return self._description["unit_imperial"] return self._description[ATTR_UNIT_IMPERIAL]
@property @property
def extra_state_attributes(self) -> dict[str, Any]: def extra_state_attributes(self) -> dict[str, Any]:
@ -169,4 +181,4 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
@property @property
def entity_registry_enabled_default(self) -> bool: def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry.""" """Return if the entity should be enabled when first added to the entity registry."""
return self._description["enabled"] return self._description[ATTR_ENABLED]

View file

@ -25,6 +25,8 @@ from homeassistant.util.dt import utc_from_timestamp
from . import AccuWeatherDataUpdateCoordinator from . import AccuWeatherDataUpdateCoordinator
from .const import ( from .const import (
API_IMPERIAL,
API_METRIC,
ATTR_FORECAST, ATTR_FORECAST,
ATTRIBUTION, ATTRIBUTION,
CONDITION_CLASSES, CONDITION_CLASSES,
@ -61,7 +63,7 @@ class AccuWeatherEntity(CoordinatorEntity, WeatherEntity):
"""Initialize.""" """Initialize."""
super().__init__(coordinator) super().__init__(coordinator)
self._name = name self._name = name
self._unit_system = "Metric" if self.coordinator.is_metric else "Imperial" self._unit_system = API_METRIC if self.coordinator.is_metric else API_IMPERIAL
@property @property
def name(self) -> str: def name(self) -> str: