mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Use new DeviceClass enums in accuweather (#61246)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
d79169ca2e
commit
d03b73eb23
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorStateClass
|
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_CONDITION_CLEAR_NIGHT,
|
ATTR_CONDITION_CLEAR_NIGHT,
|
||||||
ATTR_CONDITION_CLOUDY,
|
ATTR_CONDITION_CLOUDY,
|
||||||
@ -22,7 +22,6 @@ from homeassistant.components.weather import (
|
|||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_PARTS_PER_CUBIC_METER,
|
CONCENTRATION_PARTS_PER_CUBIC_METER,
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
LENGTH_FEET,
|
LENGTH_FEET,
|
||||||
LENGTH_INCHES,
|
LENGTH_INCHES,
|
||||||
LENGTH_METERS,
|
LENGTH_METERS,
|
||||||
@ -123,21 +122,21 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperatureMax",
|
key="RealFeelTemperatureMax",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature Max",
|
name="RealFeel Temperature Max",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperatureMin",
|
key="RealFeelTemperatureMin",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature Min",
|
name="RealFeel Temperature Min",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperatureShadeMax",
|
key="RealFeelTemperatureShadeMax",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature Shade Max",
|
name="RealFeel Temperature Shade Max",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -145,7 +144,7 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperatureShadeMin",
|
key="RealFeelTemperatureShadeMin",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature Shade Min",
|
name="RealFeel Temperature Shade Min",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -215,7 +214,7 @@ FORECAST_SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="ApparentTemperature",
|
key="ApparentTemperature",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="Apparent Temperature",
|
name="Apparent Temperature",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -241,7 +240,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="DewPoint",
|
key="DewPoint",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="Dew Point",
|
name="Dew Point",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -250,7 +249,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperature",
|
key="RealFeelTemperature",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature",
|
name="RealFeel Temperature",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -258,7 +257,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="RealFeelTemperatureShade",
|
key="RealFeelTemperatureShade",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="RealFeel Temperature Shade",
|
name="RealFeel Temperature Shade",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -291,7 +290,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="WetBulbTemperature",
|
key="WetBulbTemperature",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="Wet Bulb Temperature",
|
name="Wet Bulb Temperature",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
@ -300,7 +299,7 @@ SENSOR_TYPES: Final[tuple[AccuWeatherSensorDescription, ...]] = (
|
|||||||
),
|
),
|
||||||
AccuWeatherSensorDescription(
|
AccuWeatherSensorDescription(
|
||||||
key="WindChillTemperature",
|
key="WindChillTemperature",
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
name="Wind Chill Temperature",
|
name="Wind Chill Temperature",
|
||||||
unit_metric=TEMP_CELSIUS,
|
unit_metric=TEMP_CELSIUS,
|
||||||
unit_imperial=TEMP_FAHRENHEIT,
|
unit_imperial=TEMP_FAHRENHEIT,
|
||||||
|
@ -3,9 +3,9 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_NAME, DEVICE_CLASS_TEMPERATURE
|
from homeassistant.const import CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
@ -107,7 +107,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
|
|||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
if self.forecast_day is not None:
|
if self.forecast_day is not None:
|
||||||
if self.entity_description.device_class == DEVICE_CLASS_TEMPERATURE:
|
if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE:
|
||||||
return cast(float, self._sensor_data["Value"])
|
return cast(float, self._sensor_data["Value"])
|
||||||
if self.entity_description.key == "UVIndex":
|
if self.entity_description.key == "UVIndex":
|
||||||
return cast(int, self._sensor_data["Value"])
|
return cast(int, self._sensor_data["Value"])
|
||||||
@ -117,7 +117,7 @@ class AccuWeatherSensor(CoordinatorEntity, SensorEntity):
|
|||||||
return round(self._sensor_data[self._unit_system]["Value"])
|
return round(self._sensor_data[self._unit_system]["Value"])
|
||||||
if self.entity_description.key == "PressureTendency":
|
if self.entity_description.key == "PressureTendency":
|
||||||
return cast(str, self._sensor_data["LocalizedText"].lower())
|
return cast(str, self._sensor_data["LocalizedText"].lower())
|
||||||
if self.entity_description.device_class == DEVICE_CLASS_TEMPERATURE:
|
if self.entity_description.device_class == SensorDeviceClass.TEMPERATURE:
|
||||||
return cast(float, self._sensor_data[self._unit_system]["Value"])
|
return cast(float, self._sensor_data[self._unit_system]["Value"])
|
||||||
if self.entity_description.key == "Precipitation":
|
if self.entity_description.key == "Precipitation":
|
||||||
return cast(float, self._sensor_data[self._unit_system]["Value"])
|
return cast(float, self._sensor_data[self._unit_system]["Value"])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user