Use new device class in meteoclimatic (#83327)
This commit is contained in:
parent
eb13f2b724
commit
069c1f35ca
2 changed files with 96 additions and 92 deletions
|
@ -5,7 +5,6 @@ from datetime import timedelta
|
||||||
|
|
||||||
from meteoclimatic import Condition
|
from meteoclimatic import Condition
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntityDescription
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_CONDITION_CLEAR_NIGHT,
|
ATTR_CONDITION_CLEAR_NIGHT,
|
||||||
ATTR_CONDITION_CLOUDY,
|
ATTR_CONDITION_CLOUDY,
|
||||||
|
@ -23,15 +22,7 @@ from homeassistant.components.weather import (
|
||||||
ATTR_CONDITION_WINDY,
|
ATTR_CONDITION_WINDY,
|
||||||
ATTR_CONDITION_WINDY_VARIANT,
|
ATTR_CONDITION_WINDY_VARIANT,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import Platform
|
||||||
DEGREE,
|
|
||||||
LENGTH_MILLIMETERS,
|
|
||||||
PERCENTAGE,
|
|
||||||
PRESSURE_HPA,
|
|
||||||
SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
|
||||||
)
|
|
||||||
|
|
||||||
DOMAIN = "meteoclimatic"
|
DOMAIN = "meteoclimatic"
|
||||||
PLATFORMS = [Platform.SENSOR, Platform.WEATHER]
|
PLATFORMS = [Platform.SENSOR, Platform.WEATHER]
|
||||||
|
@ -45,86 +36,6 @@ CONF_STATION_CODE = "station_code"
|
||||||
|
|
||||||
DEFAULT_WEATHER_CARD = True
|
DEFAULT_WEATHER_CARD = True
|
||||||
|
|
||||||
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="temp_current",
|
|
||||||
name="Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="temp_max",
|
|
||||||
name="Daily Max Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="temp_min",
|
|
||||||
name="Daily Min Temperature",
|
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="humidity_current",
|
|
||||||
name="Humidity",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="humidity_max",
|
|
||||||
name="Daily Max Humidity",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="humidity_min",
|
|
||||||
name="Daily Min Humidity",
|
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
|
||||||
device_class=SensorDeviceClass.HUMIDITY,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="pressure_current",
|
|
||||||
name="Pressure",
|
|
||||||
native_unit_of_measurement=PRESSURE_HPA,
|
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="pressure_max",
|
|
||||||
name="Daily Max Pressure",
|
|
||||||
native_unit_of_measurement=PRESSURE_HPA,
|
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="pressure_min",
|
|
||||||
name="Daily Min Pressure",
|
|
||||||
native_unit_of_measurement=PRESSURE_HPA,
|
|
||||||
device_class=SensorDeviceClass.PRESSURE,
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="wind_current",
|
|
||||||
name="Wind Speed",
|
|
||||||
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
device_class="mdi:weather-windy",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="wind_max",
|
|
||||||
name="Daily Max Wind Speed",
|
|
||||||
native_unit_of_measurement=SPEED_KILOMETERS_PER_HOUR,
|
|
||||||
device_class="mdi:weather-windy",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="wind_bearing",
|
|
||||||
name="Wind Bearing",
|
|
||||||
native_unit_of_measurement=DEGREE,
|
|
||||||
device_class="mdi:weather-windy",
|
|
||||||
),
|
|
||||||
SensorEntityDescription(
|
|
||||||
key="rain",
|
|
||||||
name="Daily Precipitation",
|
|
||||||
native_unit_of_measurement=LENGTH_MILLIMETERS,
|
|
||||||
device_class="mdi:cup-water",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
CONDITION_CLASSES = {
|
CONDITION_CLASSES = {
|
||||||
ATTR_CONDITION_CLEAR_NIGHT: [Condition.moon, Condition.hazemoon],
|
ATTR_CONDITION_CLEAR_NIGHT: [Condition.moon, Condition.hazemoon],
|
||||||
|
|
|
@ -1,6 +1,18 @@
|
||||||
"""Support for Meteoclimatic sensor."""
|
"""Support for Meteoclimatic sensor."""
|
||||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
from homeassistant.components.sensor import (
|
||||||
|
SensorDeviceClass,
|
||||||
|
SensorEntity,
|
||||||
|
SensorEntityDescription,
|
||||||
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import (
|
||||||
|
DEGREE,
|
||||||
|
PERCENTAGE,
|
||||||
|
UnitOfPrecipitationDepth,
|
||||||
|
UnitOfPressure,
|
||||||
|
UnitOfSpeed,
|
||||||
|
UnitOfTemperature,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
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
|
||||||
|
@ -10,7 +22,88 @@ from homeassistant.helpers.update_coordinator import (
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .const import ATTRIBUTION, DOMAIN, MANUFACTURER, MODEL, SENSOR_TYPES
|
from .const import ATTRIBUTION, DOMAIN, MANUFACTURER, MODEL
|
||||||
|
|
||||||
|
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="temp_current",
|
||||||
|
name="Temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="temp_max",
|
||||||
|
name="Daily Max Temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="temp_min",
|
||||||
|
name="Daily Min Temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="humidity_current",
|
||||||
|
name="Humidity",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="humidity_max",
|
||||||
|
name="Daily Max Humidity",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="humidity_min",
|
||||||
|
name="Daily Min Humidity",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="pressure_current",
|
||||||
|
name="Pressure",
|
||||||
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="pressure_max",
|
||||||
|
name="Daily Max Pressure",
|
||||||
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="pressure_min",
|
||||||
|
name="Daily Min Pressure",
|
||||||
|
native_unit_of_measurement=UnitOfPressure.HPA,
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="wind_current",
|
||||||
|
name="Wind Speed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="wind_max",
|
||||||
|
name="Daily Max Wind Speed",
|
||||||
|
native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
|
||||||
|
device_class=SensorDeviceClass.WIND_SPEED,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="wind_bearing",
|
||||||
|
name="Wind Bearing",
|
||||||
|
native_unit_of_measurement=DEGREE,
|
||||||
|
device_class="mdi:weather-windy",
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="rain",
|
||||||
|
name="Daily Precipitation",
|
||||||
|
native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
|
||||||
|
device_class=SensorDeviceClass.PRECIPITATION,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue