Use UnitOfTime in integrations (h-s) (#84289)

This commit is contained in:
epenet 2022-12-20 13:21:14 +01:00 committed by GitHub
parent 6a8d9a91cb
commit 55a5e17cf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 64 additions and 75 deletions

View File

@ -18,8 +18,8 @@ from homeassistant.const import (
ATTR_LONGITUDE, ATTR_LONGITUDE,
CONF_MODE, CONF_MODE,
CONF_NAME, CONF_NAME,
TIME_MINUTES,
UnitOfLength, UnitOfLength,
UnitOfTime,
) )
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
@ -56,14 +56,14 @@ def sensor_descriptions(travel_mode: str) -> tuple[SensorEntityDescription, ...]
icon=ICONS.get(travel_mode, ICON_CAR), icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION, key=ATTR_DURATION,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
), ),
SensorEntityDescription( SensorEntityDescription(
name="Duration in traffic", name="Duration in traffic",
icon=ICONS.get(travel_mode, ICON_CAR), icon=ICONS.get(travel_mode, ICON_CAR),
key=ATTR_DURATION_IN_TRAFFIC, key=ATTR_DURATION_IN_TRAFFIC,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
), ),
SensorEntityDescription( SensorEntityDescription(
name="Distance", name="Distance",

View File

@ -18,7 +18,7 @@ from homeassistant.const import (
CONF_STATE, CONF_STATE,
CONF_TYPE, CONF_TYPE,
PERCENTAGE, PERCENTAGE,
TIME_HOURS, UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
@ -46,7 +46,7 @@ CONF_TYPE_KEYS = [CONF_TYPE_TIME, CONF_TYPE_RATIO, CONF_TYPE_COUNT]
DEFAULT_NAME = "unnamed statistics" DEFAULT_NAME = "unnamed statistics"
UNITS: dict[str, str] = { UNITS: dict[str, str] = {
CONF_TYPE_TIME: TIME_HOURS, CONF_TYPE_TIME: UnitOfTime.HOURS,
CONF_TYPE_RATIO: PERCENTAGE, CONF_TYPE_RATIO: PERCENTAGE,
CONF_TYPE_COUNT: "", CONF_TYPE_COUNT: "",
} }

View File

@ -15,7 +15,7 @@ from homeassistant.const import (
CONF_DEVICE, CONF_DEVICE,
CONF_ENTITIES, CONF_ENTITIES,
PERCENTAGE, PERCENTAGE,
TIME_SECONDS, UnitOfTime,
) )
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from homeassistant.helpers.dispatcher import dispatcher_send from homeassistant.helpers.dispatcher import dispatcher_send
@ -167,7 +167,7 @@ class DeviceWithPrograms(HomeConnectDevice):
""" """
sensors = { sensors = {
"Remaining Program Time": (None, None, SensorDeviceClass.TIMESTAMP, 1), "Remaining Program Time": (None, None, SensorDeviceClass.TIMESTAMP, 1),
"Duration": (TIME_SECONDS, "mdi:update", None, 1), "Duration": (UnitOfTime.SECONDS, "mdi:update", None, 1),
"Program Progress": (PERCENTAGE, "mdi:progress-clock", None, 1), "Program Progress": (PERCENTAGE, "mdi:progress-clock", None, 1),
} }
return [ return [

View File

@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.const import CONF_MONITORED_CONDITIONS, TIME_MINUTES from homeassistant.const import CONF_MONITORED_CONDITIONS, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -32,7 +32,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
key="watering_time", key="watering_time",
name="Watering Time", name="Watering Time",
icon="mdi:water-pump", icon="mdi:water-pump",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
), ),
) )

View File

@ -7,14 +7,7 @@ from typing import Any, cast
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.const import ( from homeassistant.const import CONF_METHOD, CONF_NAME, UnitOfTime
CONF_METHOD,
CONF_NAME,
TIME_DAYS,
TIME_HOURS,
TIME_MINUTES,
TIME_SECONDS,
)
from homeassistant.helpers import selector from homeassistant.helpers import selector
from homeassistant.helpers.schema_config_entry_flow import ( from homeassistant.helpers.schema_config_entry_flow import (
SchemaConfigFlowHandler, SchemaConfigFlowHandler,
@ -40,10 +33,10 @@ UNIT_PREFIXES = [
selector.SelectOptionDict(value="T", label="T (tera)"), selector.SelectOptionDict(value="T", label="T (tera)"),
] ]
TIME_UNITS = [ TIME_UNITS = [
selector.SelectOptionDict(value=TIME_SECONDS, label="s (seconds)"), selector.SelectOptionDict(value=UnitOfTime.SECONDS, label="s (seconds)"),
selector.SelectOptionDict(value=TIME_MINUTES, label="min (minutes)"), selector.SelectOptionDict(value=UnitOfTime.MINUTES, label="min (minutes)"),
selector.SelectOptionDict(value=TIME_HOURS, label="h (hours)"), selector.SelectOptionDict(value=UnitOfTime.HOURS, label="h (hours)"),
selector.SelectOptionDict(value=TIME_DAYS, label="d (days)"), selector.SelectOptionDict(value=UnitOfTime.DAYS, label="d (days)"),
] ]
INTEGRATION_METHODS = [ INTEGRATION_METHODS = [
selector.SelectOptionDict(value=METHOD_TRAPEZOIDAL, label="Trapezoidal rule"), selector.SelectOptionDict(value=METHOD_TRAPEZOIDAL, label="Trapezoidal rule"),
@ -81,7 +74,7 @@ CONFIG_SCHEMA = vol.Schema(
vol.Required(CONF_UNIT_PREFIX, default="none"): selector.SelectSelector( vol.Required(CONF_UNIT_PREFIX, default="none"): selector.SelectSelector(
selector.SelectSelectorConfig(options=UNIT_PREFIXES), selector.SelectSelectorConfig(options=UNIT_PREFIXES),
), ),
vol.Required(CONF_UNIT_TIME, default=TIME_HOURS): selector.SelectSelector( vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector(
selector.SelectSelectorConfig( selector.SelectSelectorConfig(
options=TIME_UNITS, mode=selector.SelectSelectorMode.DROPDOWN options=TIME_UNITS, mode=selector.SelectSelectorMode.DROPDOWN
), ),

View File

@ -22,10 +22,7 @@ from homeassistant.const import (
CONF_UNIQUE_ID, CONF_UNIQUE_ID,
STATE_UNAVAILABLE, STATE_UNAVAILABLE,
STATE_UNKNOWN, STATE_UNKNOWN,
TIME_DAYS, UnitOfTime,
TIME_HOURS,
TIME_MINUTES,
TIME_SECONDS,
) )
from homeassistant.core import Event, HomeAssistant, State, callback from homeassistant.core import Event, HomeAssistant, State, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er from homeassistant.helpers import config_validation as cv, entity_registry as er
@ -55,10 +52,10 @@ UNIT_PREFIXES = {None: 1, "k": 10**3, "M": 10**6, "G": 10**9, "T": 10**12}
# SI Time prefixes # SI Time prefixes
UNIT_TIME = { UNIT_TIME = {
TIME_SECONDS: 1, UnitOfTime.SECONDS: 1,
TIME_MINUTES: 60, UnitOfTime.MINUTES: 60,
TIME_HOURS: 60 * 60, UnitOfTime.HOURS: 60 * 60,
TIME_DAYS: 24 * 60 * 60, UnitOfTime.DAYS: 24 * 60 * 60,
} }
DEFAULT_ROUND = 3 DEFAULT_ROUND = 3
@ -72,7 +69,7 @@ PLATFORM_SCHEMA = vol.All(
vol.Required(CONF_SOURCE_SENSOR): cv.entity_id, vol.Required(CONF_SOURCE_SENSOR): cv.entity_id,
vol.Optional(CONF_ROUND_DIGITS, default=DEFAULT_ROUND): vol.Coerce(int), vol.Optional(CONF_ROUND_DIGITS, default=DEFAULT_ROUND): vol.Coerce(int),
vol.Optional(CONF_UNIT_PREFIX, default=None): vol.In(UNIT_PREFIXES), vol.Optional(CONF_UNIT_PREFIX, default=None): vol.In(UNIT_PREFIXES),
vol.Optional(CONF_UNIT_TIME, default=TIME_HOURS): vol.In(UNIT_TIME), vol.Optional(CONF_UNIT_TIME, default=UnitOfTime.HOURS): vol.In(UNIT_TIME),
vol.Remove(CONF_UNIT_OF_MEASUREMENT): cv.string, vol.Remove(CONF_UNIT_OF_MEASUREMENT): cv.string,
vol.Optional(CONF_METHOD, default=METHOD_TRAPEZOIDAL): vol.In( vol.Optional(CONF_METHOD, default=METHOD_TRAPEZOIDAL): vol.In(
INTEGRATION_METHODS INTEGRATION_METHODS
@ -146,7 +143,7 @@ class IntegrationSensor(RestoreEntity, SensorEntity):
source_entity: str, source_entity: str,
unique_id: str | None, unique_id: str | None,
unit_prefix: str | None, unit_prefix: str | None,
unit_time: str, unit_time: UnitOfTime,
) -> None: ) -> None:
"""Initialize the integration sensor.""" """Initialize the integration sensor."""
self._attr_unique_id = unique_id self._attr_unique_id = unique_id

View File

@ -7,7 +7,7 @@ from pyirishrail.pyirishrail import IrishRailRTPI
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME, TIME_MINUTES from homeassistant.const import CONF_NAME, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -126,7 +126,7 @@ class IrishRailTransportSensor(SensorEntity):
@property @property
def native_unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return UnitOfTime.MINUTES
@property @property
def icon(self): def icon(self):

View File

@ -10,11 +10,11 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_SECONDS,
UnitOfElectricCurrent, UnitOfElectricCurrent,
UnitOfElectricPotential, UnitOfElectricPotential,
UnitOfEnergy, UnitOfEnergy,
UnitOfPower, UnitOfPower,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -57,7 +57,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="charge_time", key="charge_time",
name="Charge time", name="Charge time",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
icon="mdi:timer-outline", icon="mdi:timer-outline",
), ),
SensorEntityDescription( SensorEntityDescription(

View File

@ -15,8 +15,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONF_CLIENT_ID, CONF_CLIENT_ID,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_HOURS,
UnitOfPressure, UnitOfPressure,
UnitOfTime,
UnitOfVolume, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -84,7 +84,7 @@ SENSOR_TYPES = (
name="Pump hours", name="Pump hours",
icon="mdi:clock", icon="mdi:clock",
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
native_unit_of_measurement=TIME_HOURS, native_unit_of_measurement=UnitOfTime.HOURS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda coordinator: coordinator.data.pump_hours, value_fn=lambda coordinator: coordinator.data.pump_hours,

View File

@ -14,7 +14,7 @@ from homeassistant.components.select import (
SelectEntityDescription, SelectEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TIME_MINUTES from homeassistant.const import UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -48,7 +48,7 @@ LITTER_ROBOT_SELECT = RobotSelectEntityDescription[LitterRobot, int](
key="cycle_delay", key="cycle_delay",
name="Clean Cycle Wait Time Minutes", name="Clean Cycle Wait Time Minutes",
icon="mdi:timer-outline", icon="mdi:timer-outline",
unit_of_measurement=TIME_MINUTES, unit_of_measurement=UnitOfTime.MINUTES,
current_fn=lambda robot: robot.clean_cycle_wait_time_minutes, current_fn=lambda robot: robot.clean_cycle_wait_time_minutes,
options_fn=lambda robot: robot.VALID_WAIT_TIMES, options_fn=lambda robot: robot.VALID_WAIT_TIMES,
select_fn=lambda robot, option: robot.set_wait_time(int(option)), select_fn=lambda robot, option: robot.set_wait_time(int(option)),

View File

@ -3,7 +3,7 @@ from __future__ import annotations
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 TIME_MILLISECONDS from homeassistant.const import UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -114,7 +114,7 @@ class MinecraftServerLatencyTimeSensor(MinecraftServerSensorEntity):
server=server, server=server,
type_name=NAME_LATENCY_TIME, type_name=NAME_LATENCY_TIME,
icon=ICON_LATENCY_TIME, icon=ICON_LATENCY_TIME,
unit=TIME_MILLISECONDS, unit=UnitOfTime.MILLISECONDS,
) )
async def async_update(self) -> None: async def async_update(self) -> None:

View File

@ -9,7 +9,7 @@ import MVGLive
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME, TIME_MINUTES from homeassistant.const import CONF_NAME, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -141,7 +141,7 @@ class MVGLiveSensor(SensorEntity):
@property @property
def native_unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return UnitOfTime.MINUTES
def update(self) -> None: def update(self) -> None:
"""Get the latest data and update the state.""" """Get the latest data and update the state."""

View File

@ -17,9 +17,9 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TIME_MILLISECONDS,
UnitOfDataRate, UnitOfDataRate,
UnitOfInformation, UnitOfInformation,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -260,7 +260,7 @@ SENSOR_SPEED_TYPES = [
key="AveragePing", key="AveragePing",
name="Average Ping", name="Average Ping",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
native_unit_of_measurement=TIME_MILLISECONDS, native_unit_of_measurement=UnitOfTime.MILLISECONDS,
icon="mdi:wan", icon="mdi:wan",
), ),
] ]

View File

@ -12,7 +12,7 @@ from homeassistant.const import (
ATTR_LONGITUDE, ATTR_LONGITUDE,
CONF_NAME, CONF_NAME,
CONF_SHOW_ON_MAP, CONF_SHOW_ON_MAP,
TIME_MINUTES, UnitOfTime,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -177,7 +177,7 @@ class NMBSSensor(SensorEntity):
"""Get the total travel time for a given connection.""" """Get the total travel time for a given connection."""
_attr_attribution = "https://api.irail.be/" _attr_attribution = "https://api.irail.be/"
_attr_native_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = UnitOfTime.MINUTES
def __init__( def __init__(
self, api_client, name, show_on_map, station_from, station_to, excl_vias self, api_client, name, show_on_map, station_from, station_to, excl_vias

View File

@ -18,8 +18,8 @@ from homeassistant.const import (
CONF_HOST, CONF_HOST,
CONF_MONITORED_VARIABLES, CONF_MONITORED_VARIABLES,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_MINUTES,
UnitOfEnergy, UnitOfEnergy,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -36,7 +36,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="charge_time", key="charge_time",
name="Charge Time Elapsed", name="Charge Time Elapsed",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),

View File

@ -8,7 +8,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TIME_MINUTES, UV_INDEX from homeassistant.const import UV_INDEX, UnitOfTime
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
@ -78,42 +78,42 @@ SENSOR_DESCRIPTIONS = (
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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.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=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )

View File

@ -18,7 +18,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
SensorStateClass, SensorStateClass,
) )
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TIME_SECONDS from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -32,7 +32,7 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
key=OralBSensor.TIME, key=OralBSensor.TIME,
device_class=SensorDeviceClass.DURATION, device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
), ),
OralBSensor.SECTOR: SensorEntityDescription( OralBSensor.SECTOR: SensorEntityDescription(
key=OralBSensor.SECTOR, key=OralBSensor.SECTOR,

View File

@ -33,9 +33,9 @@ from homeassistant.components.sensor import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_SECONDS,
UnitOfDataRate, UnitOfDataRate,
UnitOfInformation, UnitOfInformation,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -146,7 +146,7 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = (
key=QSD_SYSTEM_TIME, key=QSD_SYSTEM_TIME,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
name="Uptime", name="Uptime",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
subkey=QSD_UPTIME, subkey=QSD_UPTIME,
), ),

View File

@ -12,8 +12,7 @@ from homeassistant.const import (
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
CONF_USERNAME, CONF_USERNAME,
PERCENTAGE, PERCENTAGE,
TIME_DAYS, UnitOfTime,
TIME_MINUTES,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -63,9 +62,9 @@ UNIT_OF_MEASUREMENT_MAP = {
"is_watering": "", "is_watering": "",
"manual_watering": "", "manual_watering": "",
"next_cycle": "", "next_cycle": "",
"rain_delay": TIME_DAYS, "rain_delay": UnitOfTime.DAYS,
"status": "", "status": "",
"watering_time": TIME_MINUTES, "watering_time": UnitOfTime.MINUTES,
} }
BINARY_SENSORS = ["is_watering", "status"] BINARY_SENSORS = ["is_watering", "status"]

View File

@ -15,7 +15,7 @@ import rjpl
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME, TIME_MINUTES from homeassistant.const import CONF_NAME, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -142,7 +142,7 @@ class RejseplanenTransportSensor(SensorEntity):
@property @property
def native_unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return UnitOfTime.MINUTES
@property @property
def icon(self): def icon(self):

View File

@ -25,10 +25,10 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_MINUTES,
UnitOfEnergy, UnitOfEnergy,
UnitOfLength, UnitOfLength,
UnitOfPower, UnitOfPower,
UnitOfTime,
UnitOfVolume, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -195,7 +195,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = (
entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], entity_class=RenaultSensor[KamereonVehicleBatteryStatusData],
icon="mdi:timer", icon="mdi:timer",
name="Charging remaining time", name="Charging remaining time",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
RenaultSensorEntityDescription( RenaultSensorEntityDescription(

View File

@ -13,7 +13,7 @@ from RMVtransport.rmvtransport import (
import voluptuous as vol import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import CONF_NAME, CONF_TIMEOUT, TIME_MINUTES from homeassistant.const import CONF_NAME, CONF_TIMEOUT, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -184,7 +184,7 @@ class RMVDepartureSensor(SensorEntity):
@property @property
def native_unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit this state is expressed in.""" """Return the unit this state is expressed in."""
return TIME_MINUTES return UnitOfTime.MINUTES
async def async_update(self) -> None: async def async_update(self) -> None:
"""Get the latest data and update the state.""" """Get the latest data and update the state."""

View File

@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TIME_MILLISECONDS, UnitOfDataRate from homeassistant.const import UnitOfDataRate, UnitOfTime
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
@ -45,7 +45,7 @@ SENSOR_TYPES: tuple[SpeedtestSensorEntityDescription, ...] = (
SpeedtestSensorEntityDescription( SpeedtestSensorEntityDescription(
key="ping", key="ping",
name="Ping", name="Ping",
native_unit_of_measurement=TIME_MILLISECONDS, native_unit_of_measurement=UnitOfTime.MILLISECONDS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SpeedtestSensorEntityDescription( SpeedtestSensorEntityDescription(

View File

@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
SensorStateClass, SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, TIME_MINUTES from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT, UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -48,7 +48,7 @@ SENSORS: tuple[SteamistSensorEntityDescription, ...] = (
SteamistSensorEntityDescription( SteamistSensorEntityDescription(
key=_KEY_MINUTES_REMAIN, key=_KEY_MINUTES_REMAIN,
name="Steam Minutes Remain", name="Steam Minutes Remain",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
value_fn=lambda status: status.minutes_remain, value_fn=lambda status: status.minutes_remain,
), ),
SteamistSensorEntityDescription( SteamistSensorEntityDescription(