From ccd8e1332ccc0499add8ab178f7d924368a2555c Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Thu, 20 May 2021 09:29:10 +0200 Subject: [PATCH] Address late review comments for AccuWeather integration (#50866) * Remove unnecessary converting datetime to str * Address late comments --- .../components/accuweather/__init__.py | 2 +- homeassistant/components/accuweather/const.py | 392 +++++++++--------- .../components/accuweather/sensor.py | 30 +- .../components/accuweather/weather.py | 4 +- 4 files changed, 225 insertions(+), 203 deletions(-) diff --git a/homeassistant/components/accuweather/__init__.py b/homeassistant/components/accuweather/__init__.py index 27dd4b9c196..18a4bd2dce4 100644 --- a/homeassistant/components/accuweather/__init__.py +++ b/homeassistant/components/accuweather/__init__.py @@ -99,7 +99,7 @@ class AccuWeatherDataUpdateCoordinator(DataUpdateCoordinator[Dict[str, Any]]): update_interval = timedelta(minutes=40) if self.forecast: 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) diff --git a/homeassistant/components/accuweather/const.py b/homeassistant/components/accuweather/const.py index e4ec49ce2ac..54d9b631ade 100644 --- a/homeassistant/components/accuweather/const.py +++ b/homeassistant/components/accuweather/const.py @@ -20,6 +20,8 @@ from homeassistant.components.weather import ( ATTR_CONDITION_WINDY, ) from homeassistant.const import ( + ATTR_DEVICE_CLASS, + ATTR_ICON, CONCENTRATION_PARTS_PER_CUBIC_METER, DEVICE_CLASS_TEMPERATURE, LENGTH_FEET, @@ -37,8 +39,14 @@ from homeassistant.const import ( from .model import SensorDescription +API_IMPERIAL: Final = "Imperial" +API_METRIC: Final = "Metric" ATTRIBUTION: Final = "Data provided by AccuWeather" +ATTR_ENABLED: Final = "enabled" ATTR_FORECAST: Final = "forecast" +ATTR_LABEL: Final = "label" +ATTR_UNIT_IMPERIAL: Final = "unit_imperial" +ATTR_UNIT_METRIC: Final = "unit_metric" CONF_FORECAST: Final = "forecast" COORDINATOR: Final = "coordinator" DOMAIN: Final = "accuweather" @@ -66,262 +74,262 @@ CONDITION_CLASSES: Final[dict[str, list[int]]] = { FORECAST_SENSOR_TYPES: Final[dict[str, SensorDescription]] = { "CloudCoverDay": { - "device_class": None, - "icon": "mdi:weather-cloudy", - "label": "Cloud Cover Day", - "unit_metric": PERCENTAGE, - "unit_imperial": PERCENTAGE, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-cloudy", + ATTR_LABEL: "Cloud Cover Day", + ATTR_UNIT_METRIC: PERCENTAGE, + ATTR_UNIT_IMPERIAL: PERCENTAGE, + ATTR_ENABLED: False, }, "CloudCoverNight": { - "device_class": None, - "icon": "mdi:weather-cloudy", - "label": "Cloud Cover Night", - "unit_metric": PERCENTAGE, - "unit_imperial": PERCENTAGE, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-cloudy", + ATTR_LABEL: "Cloud Cover Night", + ATTR_UNIT_METRIC: PERCENTAGE, + ATTR_UNIT_IMPERIAL: PERCENTAGE, + ATTR_ENABLED: False, }, "Grass": { - "device_class": None, - "icon": "mdi:grass", - "label": "Grass Pollen", - "unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, - "unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:grass", + ATTR_LABEL: "Grass Pollen", + ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_ENABLED: False, }, "HoursOfSun": { - "device_class": None, - "icon": "mdi:weather-partly-cloudy", - "label": "Hours Of Sun", - "unit_metric": TIME_HOURS, - "unit_imperial": TIME_HOURS, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-partly-cloudy", + ATTR_LABEL: "Hours Of Sun", + ATTR_UNIT_METRIC: TIME_HOURS, + ATTR_UNIT_IMPERIAL: TIME_HOURS, + ATTR_ENABLED: True, }, "Mold": { - "device_class": None, - "icon": "mdi:blur", - "label": "Mold Pollen", - "unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, - "unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:blur", + ATTR_LABEL: "Mold Pollen", + ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_ENABLED: False, }, "Ozone": { - "device_class": None, - "icon": "mdi:vector-triangle", - "label": "Ozone", - "unit_metric": None, - "unit_imperial": None, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:vector-triangle", + ATTR_LABEL: "Ozone", + ATTR_UNIT_METRIC: None, + ATTR_UNIT_IMPERIAL: None, + ATTR_ENABLED: False, }, "Ragweed": { - "device_class": None, - "icon": "mdi:sprout", - "label": "Ragweed Pollen", - "unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, - "unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:sprout", + ATTR_LABEL: "Ragweed Pollen", + ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_ENABLED: False, }, "RealFeelTemperatureMax": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature Max", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": True, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature Max", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: True, }, "RealFeelTemperatureMin": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature Min", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": True, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature Min", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: True, }, "RealFeelTemperatureShadeMax": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature Shade Max", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature Shade Max", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "RealFeelTemperatureShadeMin": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature Shade Min", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature Shade Min", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "ThunderstormProbabilityDay": { - "device_class": None, - "icon": "mdi:weather-lightning", - "label": "Thunderstorm Probability Day", - "unit_metric": PERCENTAGE, - "unit_imperial": PERCENTAGE, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-lightning", + ATTR_LABEL: "Thunderstorm Probability Day", + ATTR_UNIT_METRIC: PERCENTAGE, + ATTR_UNIT_IMPERIAL: PERCENTAGE, + ATTR_ENABLED: True, }, "ThunderstormProbabilityNight": { - "device_class": None, - "icon": "mdi:weather-lightning", - "label": "Thunderstorm Probability Night", - "unit_metric": PERCENTAGE, - "unit_imperial": PERCENTAGE, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-lightning", + ATTR_LABEL: "Thunderstorm Probability Night", + ATTR_UNIT_METRIC: PERCENTAGE, + ATTR_UNIT_IMPERIAL: PERCENTAGE, + ATTR_ENABLED: True, }, "Tree": { - "device_class": None, - "icon": "mdi:tree-outline", - "label": "Tree Pollen", - "unit_metric": CONCENTRATION_PARTS_PER_CUBIC_METER, - "unit_imperial": CONCENTRATION_PARTS_PER_CUBIC_METER, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:tree-outline", + ATTR_LABEL: "Tree Pollen", + ATTR_UNIT_METRIC: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_UNIT_IMPERIAL: CONCENTRATION_PARTS_PER_CUBIC_METER, + ATTR_ENABLED: False, }, "UVIndex": { - "device_class": None, - "icon": "mdi:weather-sunny", - "label": "UV Index", - "unit_metric": UV_INDEX, - "unit_imperial": UV_INDEX, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-sunny", + ATTR_LABEL: "UV Index", + ATTR_UNIT_METRIC: UV_INDEX, + ATTR_UNIT_IMPERIAL: UV_INDEX, + ATTR_ENABLED: True, }, "WindGustDay": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind Gust Day", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Gust Day", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: False, }, "WindGustNight": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind Gust Night", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Gust Night", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: False, }, "WindDay": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind Day", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Day", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: True, }, "WindNight": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind Night", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Night", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: True, }, } SENSOR_TYPES: Final[dict[str, SensorDescription]] = { "ApparentTemperature": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "Apparent Temperature", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "Apparent Temperature", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "Ceiling": { - "device_class": None, - "icon": "mdi:weather-fog", - "label": "Cloud Ceiling", - "unit_metric": LENGTH_METERS, - "unit_imperial": LENGTH_FEET, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-fog", + ATTR_LABEL: "Cloud Ceiling", + ATTR_UNIT_METRIC: LENGTH_METERS, + ATTR_UNIT_IMPERIAL: LENGTH_FEET, + ATTR_ENABLED: True, }, "CloudCover": { - "device_class": None, - "icon": "mdi:weather-cloudy", - "label": "Cloud Cover", - "unit_metric": PERCENTAGE, - "unit_imperial": PERCENTAGE, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-cloudy", + ATTR_LABEL: "Cloud Cover", + ATTR_UNIT_METRIC: PERCENTAGE, + ATTR_UNIT_IMPERIAL: PERCENTAGE, + ATTR_ENABLED: False, }, "DewPoint": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "Dew Point", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "Dew Point", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "RealFeelTemperature": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": True, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: True, }, "RealFeelTemperatureShade": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "RealFeel Temperature Shade", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "RealFeel Temperature Shade", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "Precipitation": { - "device_class": None, - "icon": "mdi:weather-rainy", - "label": "Precipitation", - "unit_metric": LENGTH_MILLIMETERS, - "unit_imperial": LENGTH_INCHES, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-rainy", + ATTR_LABEL: "Precipitation", + ATTR_UNIT_METRIC: LENGTH_MILLIMETERS, + ATTR_UNIT_IMPERIAL: LENGTH_INCHES, + ATTR_ENABLED: True, }, "PressureTendency": { - "device_class": "accuweather__pressure_tendency", - "icon": "mdi:gauge", - "label": "Pressure Tendency", - "unit_metric": None, - "unit_imperial": None, - "enabled": True, + ATTR_DEVICE_CLASS: "accuweather__pressure_tendency", + ATTR_ICON: "mdi:gauge", + ATTR_LABEL: "Pressure Tendency", + ATTR_UNIT_METRIC: None, + ATTR_UNIT_IMPERIAL: None, + ATTR_ENABLED: True, }, "UVIndex": { - "device_class": None, - "icon": "mdi:weather-sunny", - "label": "UV Index", - "unit_metric": UV_INDEX, - "unit_imperial": UV_INDEX, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-sunny", + ATTR_LABEL: "UV Index", + ATTR_UNIT_METRIC: UV_INDEX, + ATTR_UNIT_IMPERIAL: UV_INDEX, + ATTR_ENABLED: True, }, "WetBulbTemperature": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "Wet Bulb Temperature", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "Wet Bulb Temperature", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "WindChillTemperature": { - "device_class": DEVICE_CLASS_TEMPERATURE, - "icon": None, - "label": "Wind Chill Temperature", - "unit_metric": TEMP_CELSIUS, - "unit_imperial": TEMP_FAHRENHEIT, - "enabled": False, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, + ATTR_ICON: None, + ATTR_LABEL: "Wind Chill Temperature", + ATTR_UNIT_METRIC: TEMP_CELSIUS, + ATTR_UNIT_IMPERIAL: TEMP_FAHRENHEIT, + ATTR_ENABLED: False, }, "Wind": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": True, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: True, }, "WindGust": { - "device_class": None, - "icon": "mdi:weather-windy", - "label": "Wind Gust", - "unit_metric": SPEED_KILOMETERS_PER_HOUR, - "unit_imperial": SPEED_MILES_PER_HOUR, - "enabled": False, + ATTR_DEVICE_CLASS: None, + ATTR_ICON: "mdi:weather-windy", + ATTR_LABEL: "Wind Gust", + ATTR_UNIT_METRIC: SPEED_KILOMETERS_PER_HOUR, + ATTR_UNIT_IMPERIAL: SPEED_MILES_PER_HOUR, + ATTR_ENABLED: False, }, } diff --git a/homeassistant/components/accuweather/sensor.py b/homeassistant/components/accuweather/sensor.py index 9f2d9ed78bd..09e9cda30ad 100644 --- a/homeassistant/components/accuweather/sensor.py +++ b/homeassistant/components/accuweather/sensor.py @@ -5,7 +5,13 @@ 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, 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.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -14,7 +20,13 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity from . import AccuWeatherDataUpdateCoordinator from .const import ( + API_IMPERIAL, + API_METRIC, + ATTR_ENABLED, ATTR_FORECAST, + ATTR_LABEL, + ATTR_UNIT_IMPERIAL, + ATTR_UNIT_METRIC, ATTRIBUTION, COORDINATOR, DOMAIN, @@ -79,7 +91,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): else: self._description = FORECAST_SENSOR_TYPES[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.kind = kind self._device_class = None @@ -90,8 +102,8 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): def name(self) -> str: """Return the name.""" if self.forecast_day is not None: - return f"{self._name} {self._description['label']} {self.forecast_day}d" - return f"{self._name} {self._description['label']}" + return f"{self._name} {self._description[ATTR_LABEL]} {self.forecast_day}d" + return f"{self._name} {self._description[ATTR_LABEL]}" @property def unique_id(self) -> str: @@ -137,19 +149,19 @@ class AccuWeatherSensor(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 unit_of_measurement(self) -> str | None: """Return the unit the value is expressed in.""" if self.coordinator.is_metric: - return self._description["unit_metric"] - return self._description["unit_imperial"] + return self._description[ATTR_UNIT_METRIC] + return self._description[ATTR_UNIT_IMPERIAL] @property def extra_state_attributes(self) -> dict[str, Any]: @@ -169,4 +181,4 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity): @property def entity_registry_enabled_default(self) -> bool: """Return if the entity should be enabled when first added to the entity registry.""" - return self._description["enabled"] + return self._description[ATTR_ENABLED] diff --git a/homeassistant/components/accuweather/weather.py b/homeassistant/components/accuweather/weather.py index e4745537c4f..0dc4c7e270c 100644 --- a/homeassistant/components/accuweather/weather.py +++ b/homeassistant/components/accuweather/weather.py @@ -25,6 +25,8 @@ from homeassistant.util.dt import utc_from_timestamp from . import AccuWeatherDataUpdateCoordinator from .const import ( + API_IMPERIAL, + API_METRIC, ATTR_FORECAST, ATTRIBUTION, CONDITION_CLASSES, @@ -61,7 +63,7 @@ class AccuWeatherEntity(CoordinatorEntity, WeatherEntity): """Initialize.""" super().__init__(coordinator) 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 def name(self) -> str: