Add long-term statistics for OpenUV sensors (#55417)

This commit is contained in:
Aaron Bach 2021-09-23 08:54:06 -06:00 committed by GitHub
parent b634bd26d0
commit 1a47fcc4e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,13 @@
"""Support for OpenUV sensors.""" """Support for OpenUV sensors."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TIME_MINUTES, UV_INDEX from homeassistant.const import DEVICE_CLASS_OZONE, TIME_MINUTES, UV_INDEX
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import as_local, parse_datetime from homeassistant.util.dt import as_local, parse_datetime
@ -46,14 +50,16 @@ SENSOR_DESCRIPTIONS = (
SensorEntityDescription( SensorEntityDescription(
key=TYPE_CURRENT_OZONE_LEVEL, key=TYPE_CURRENT_OZONE_LEVEL,
name="Current Ozone Level", name="Current Ozone Level",
icon="mdi:vector-triangle", device_class=DEVICE_CLASS_OZONE,
native_unit_of_measurement="du", native_unit_of_measurement="du",
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_CURRENT_UV_INDEX, key=TYPE_CURRENT_UV_INDEX,
name="Current UV Index", name="Current UV Index",
icon="mdi:weather-sunny", icon="mdi:weather-sunny",
native_unit_of_measurement=UV_INDEX, native_unit_of_measurement=UV_INDEX,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_CURRENT_UV_LEVEL, key=TYPE_CURRENT_UV_LEVEL,
@ -65,42 +71,49 @@ SENSOR_DESCRIPTIONS = (
name="Max UV Index", name="Max UV Index",
icon="mdi:weather-sunny", icon="mdi:weather-sunny",
native_unit_of_measurement=UV_INDEX, native_unit_of_measurement=UV_INDEX,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_1, key=TYPE_SAFE_EXPOSURE_TIME_1,
name="Skin Type 1 Safe Exposure Time", name="Skin Type 1 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_2, key=TYPE_SAFE_EXPOSURE_TIME_2,
name="Skin Type 2 Safe Exposure Time", name="Skin Type 2 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_3, key=TYPE_SAFE_EXPOSURE_TIME_3,
name="Skin Type 3 Safe Exposure Time", name="Skin Type 3 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_4, key=TYPE_SAFE_EXPOSURE_TIME_4,
name="Skin Type 4 Safe Exposure Time", name="Skin Type 4 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_5, key=TYPE_SAFE_EXPOSURE_TIME_5,
name="Skin Type 5 Safe Exposure Time", name="Skin Type 5 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_SAFE_EXPOSURE_TIME_6, key=TYPE_SAFE_EXPOSURE_TIME_6,
name="Skin Type 6 Safe Exposure Time", name="Skin Type 6 Safe Exposure Time",
icon="mdi:timer-outline", icon="mdi:timer-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=TIME_MINUTES,
state_class=STATE_CLASS_MEASUREMENT,
), ),
) )