diff --git a/homeassistant/components/here_travel_time/sensor.py b/homeassistant/components/here_travel_time/sensor.py index 310484907ad..445efb92dcf 100644 --- a/homeassistant/components/here_travel_time/sensor.py +++ b/homeassistant/components/here_travel_time/sensor.py @@ -18,8 +18,8 @@ from homeassistant.const import ( ATTR_LONGITUDE, CONF_MODE, CONF_NAME, - TIME_MINUTES, UnitOfLength, + UnitOfTime, ) from homeassistant.core import HomeAssistant, callback 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), key=ATTR_DURATION, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, ), SensorEntityDescription( name="Duration in traffic", icon=ICONS.get(travel_mode, ICON_CAR), key=ATTR_DURATION_IN_TRAFFIC, state_class=SensorStateClass.MEASUREMENT, - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, ), SensorEntityDescription( name="Distance", diff --git a/homeassistant/components/history_stats/sensor.py b/homeassistant/components/history_stats/sensor.py index 642c327e29d..fc3aedfde24 100644 --- a/homeassistant/components/history_stats/sensor.py +++ b/homeassistant/components/history_stats/sensor.py @@ -18,7 +18,7 @@ from homeassistant.const import ( CONF_STATE, CONF_TYPE, PERCENTAGE, - TIME_HOURS, + UnitOfTime, ) from homeassistant.core import HomeAssistant, callback 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" UNITS: dict[str, str] = { - CONF_TYPE_TIME: TIME_HOURS, + CONF_TYPE_TIME: UnitOfTime.HOURS, CONF_TYPE_RATIO: PERCENTAGE, CONF_TYPE_COUNT: "", } diff --git a/homeassistant/components/home_connect/api.py b/homeassistant/components/home_connect/api.py index f3c98e618b8..f50ab711550 100644 --- a/homeassistant/components/home_connect/api.py +++ b/homeassistant/components/home_connect/api.py @@ -15,7 +15,7 @@ from homeassistant.const import ( CONF_DEVICE, CONF_ENTITIES, PERCENTAGE, - TIME_SECONDS, + UnitOfTime, ) from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers.dispatcher import dispatcher_send @@ -167,7 +167,7 @@ class DeviceWithPrograms(HomeConnectDevice): """ sensors = { "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), } return [ diff --git a/homeassistant/components/hydrawise/sensor.py b/homeassistant/components/hydrawise/sensor.py index f9201cc0420..3114a50673f 100644 --- a/homeassistant/components/hydrawise/sensor.py +++ b/homeassistant/components/hydrawise/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorEntity, SensorEntityDescription, ) -from homeassistant.const import CONF_MONITORED_CONDITIONS, TIME_MINUTES +from homeassistant.const import CONF_MONITORED_CONDITIONS, UnitOfTime from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -32,7 +32,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( key="watering_time", name="Watering Time", icon="mdi:water-pump", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, ), ) diff --git a/homeassistant/components/integration/config_flow.py b/homeassistant/components/integration/config_flow.py index 446132ece7c..147c4262319 100644 --- a/homeassistant/components/integration/config_flow.py +++ b/homeassistant/components/integration/config_flow.py @@ -7,14 +7,7 @@ from typing import Any, cast import voluptuous as vol from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN -from homeassistant.const import ( - CONF_METHOD, - CONF_NAME, - TIME_DAYS, - TIME_HOURS, - TIME_MINUTES, - TIME_SECONDS, -) +from homeassistant.const import CONF_METHOD, CONF_NAME, UnitOfTime from homeassistant.helpers import selector from homeassistant.helpers.schema_config_entry_flow import ( SchemaConfigFlowHandler, @@ -40,10 +33,10 @@ UNIT_PREFIXES = [ selector.SelectOptionDict(value="T", label="T (tera)"), ] TIME_UNITS = [ - selector.SelectOptionDict(value=TIME_SECONDS, label="s (seconds)"), - selector.SelectOptionDict(value=TIME_MINUTES, label="min (minutes)"), - selector.SelectOptionDict(value=TIME_HOURS, label="h (hours)"), - selector.SelectOptionDict(value=TIME_DAYS, label="d (days)"), + selector.SelectOptionDict(value=UnitOfTime.SECONDS, label="s (seconds)"), + selector.SelectOptionDict(value=UnitOfTime.MINUTES, label="min (minutes)"), + selector.SelectOptionDict(value=UnitOfTime.HOURS, label="h (hours)"), + selector.SelectOptionDict(value=UnitOfTime.DAYS, label="d (days)"), ] INTEGRATION_METHODS = [ 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( 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( options=TIME_UNITS, mode=selector.SelectSelectorMode.DROPDOWN ), diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index d08d04e094d..54e50b7b1de 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -22,10 +22,7 @@ from homeassistant.const import ( CONF_UNIQUE_ID, STATE_UNAVAILABLE, STATE_UNKNOWN, - TIME_DAYS, - TIME_HOURS, - TIME_MINUTES, - TIME_SECONDS, + UnitOfTime, ) from homeassistant.core import Event, HomeAssistant, State, callback 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 UNIT_TIME = { - TIME_SECONDS: 1, - TIME_MINUTES: 60, - TIME_HOURS: 60 * 60, - TIME_DAYS: 24 * 60 * 60, + UnitOfTime.SECONDS: 1, + UnitOfTime.MINUTES: 60, + UnitOfTime.HOURS: 60 * 60, + UnitOfTime.DAYS: 24 * 60 * 60, } DEFAULT_ROUND = 3 @@ -72,7 +69,7 @@ PLATFORM_SCHEMA = vol.All( vol.Required(CONF_SOURCE_SENSOR): cv.entity_id, 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_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.Optional(CONF_METHOD, default=METHOD_TRAPEZOIDAL): vol.In( INTEGRATION_METHODS @@ -146,7 +143,7 @@ class IntegrationSensor(RestoreEntity, SensorEntity): source_entity: str, unique_id: str | None, unit_prefix: str | None, - unit_time: str, + unit_time: UnitOfTime, ) -> None: """Initialize the integration sensor.""" self._attr_unique_id = unique_id diff --git a/homeassistant/components/irish_rail_transport/sensor.py b/homeassistant/components/irish_rail_transport/sensor.py index d11a0b31809..7ac30cc5a23 100644 --- a/homeassistant/components/irish_rail_transport/sensor.py +++ b/homeassistant/components/irish_rail_transport/sensor.py @@ -7,7 +7,7 @@ from pyirishrail.pyirishrail import IrishRailRTPI import voluptuous as vol 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 import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -126,7 +126,7 @@ class IrishRailTransportSensor(SensorEntity): @property def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" - return TIME_MINUTES + return UnitOfTime.MINUTES @property def icon(self): diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index b18d11c94f1..415f5de0720 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -10,11 +10,11 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( TEMP_CELSIUS, - TIME_SECONDS, UnitOfElectricCurrent, UnitOfElectricPotential, UnitOfEnergy, UnitOfPower, + UnitOfTime, ) from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -57,7 +57,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="charge_time", name="Charge time", - native_unit_of_measurement=TIME_SECONDS, + native_unit_of_measurement=UnitOfTime.SECONDS, icon="mdi:timer-outline", ), SensorEntityDescription( diff --git a/homeassistant/components/justnimbus/sensor.py b/homeassistant/components/justnimbus/sensor.py index 6f31b9789b6..754fa66ae51 100644 --- a/homeassistant/components/justnimbus/sensor.py +++ b/homeassistant/components/justnimbus/sensor.py @@ -15,8 +15,8 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( CONF_CLIENT_ID, TEMP_CELSIUS, - TIME_HOURS, UnitOfPressure, + UnitOfTime, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -84,7 +84,7 @@ SENSOR_TYPES = ( name="Pump hours", icon="mdi:clock", device_class=SensorDeviceClass.DURATION, - native_unit_of_measurement=TIME_HOURS, + native_unit_of_measurement=UnitOfTime.HOURS, state_class=SensorStateClass.MEASUREMENT, entity_category=EntityCategory.DIAGNOSTIC, value_fn=lambda coordinator: coordinator.data.pump_hours, diff --git a/homeassistant/components/litterrobot/select.py b/homeassistant/components/litterrobot/select.py index d384e94a092..0edfd5b0646 100644 --- a/homeassistant/components/litterrobot/select.py +++ b/homeassistant/components/litterrobot/select.py @@ -14,7 +14,7 @@ from homeassistant.components.select import ( SelectEntityDescription, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TIME_MINUTES +from homeassistant.const import UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -48,7 +48,7 @@ LITTER_ROBOT_SELECT = RobotSelectEntityDescription[LitterRobot, int]( key="cycle_delay", name="Clean Cycle Wait Time Minutes", icon="mdi:timer-outline", - unit_of_measurement=TIME_MINUTES, + unit_of_measurement=UnitOfTime.MINUTES, current_fn=lambda robot: robot.clean_cycle_wait_time_minutes, options_fn=lambda robot: robot.VALID_WAIT_TIMES, select_fn=lambda robot, option: robot.set_wait_time(int(option)), diff --git a/homeassistant/components/minecraft_server/sensor.py b/homeassistant/components/minecraft_server/sensor.py index f10a359eca0..36d78520565 100644 --- a/homeassistant/components/minecraft_server/sensor.py +++ b/homeassistant/components/minecraft_server/sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import TIME_MILLISECONDS +from homeassistant.const import UnitOfTime from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -114,7 +114,7 @@ class MinecraftServerLatencyTimeSensor(MinecraftServerSensorEntity): server=server, type_name=NAME_LATENCY_TIME, icon=ICON_LATENCY_TIME, - unit=TIME_MILLISECONDS, + unit=UnitOfTime.MILLISECONDS, ) async def async_update(self) -> None: diff --git a/homeassistant/components/mvglive/sensor.py b/homeassistant/components/mvglive/sensor.py index 0f0d32908ef..2f8467a0333 100644 --- a/homeassistant/components/mvglive/sensor.py +++ b/homeassistant/components/mvglive/sensor.py @@ -9,7 +9,7 @@ import MVGLive import voluptuous as vol 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 import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -141,7 +141,7 @@ class MVGLiveSensor(SensorEntity): @property def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" - return TIME_MINUTES + return UnitOfTime.MINUTES def update(self) -> None: """Get the latest data and update the state.""" diff --git a/homeassistant/components/netgear/sensor.py b/homeassistant/components/netgear/sensor.py index 3a1d03499cd..510b97c37e3 100644 --- a/homeassistant/components/netgear/sensor.py +++ b/homeassistant/components/netgear/sensor.py @@ -17,9 +17,9 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, - TIME_MILLISECONDS, UnitOfDataRate, UnitOfInformation, + UnitOfTime, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory @@ -260,7 +260,7 @@ SENSOR_SPEED_TYPES = [ key="AveragePing", name="Average Ping", entity_category=EntityCategory.DIAGNOSTIC, - native_unit_of_measurement=TIME_MILLISECONDS, + native_unit_of_measurement=UnitOfTime.MILLISECONDS, icon="mdi:wan", ), ] diff --git a/homeassistant/components/nmbs/sensor.py b/homeassistant/components/nmbs/sensor.py index 1d5bb3ef30b..0ce898e27a0 100644 --- a/homeassistant/components/nmbs/sensor.py +++ b/homeassistant/components/nmbs/sensor.py @@ -12,7 +12,7 @@ from homeassistant.const import ( ATTR_LONGITUDE, CONF_NAME, CONF_SHOW_ON_MAP, - TIME_MINUTES, + UnitOfTime, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -177,7 +177,7 @@ class NMBSSensor(SensorEntity): """Get the total travel time for a given connection.""" _attr_attribution = "https://api.irail.be/" - _attr_native_unit_of_measurement = TIME_MINUTES + _attr_native_unit_of_measurement = UnitOfTime.MINUTES def __init__( self, api_client, name, show_on_map, station_from, station_to, excl_vias diff --git a/homeassistant/components/openevse/sensor.py b/homeassistant/components/openevse/sensor.py index 9fecb141058..409425982b4 100644 --- a/homeassistant/components/openevse/sensor.py +++ b/homeassistant/components/openevse/sensor.py @@ -18,8 +18,8 @@ from homeassistant.const import ( CONF_HOST, CONF_MONITORED_VARIABLES, TEMP_CELSIUS, - TIME_MINUTES, UnitOfEnergy, + UnitOfTime, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -36,7 +36,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = ( SensorEntityDescription( key="charge_time", name="Charge Time Elapsed", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, ), diff --git a/homeassistant/components/openuv/sensor.py b/homeassistant/components/openuv/sensor.py index dd8d1587f49..4f02f01a93c 100644 --- a/homeassistant/components/openuv/sensor.py +++ b/homeassistant/components/openuv/sensor.py @@ -8,7 +8,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) 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.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.dt import as_local, parse_datetime @@ -78,42 +78,42 @@ SENSOR_DESCRIPTIONS = ( key=TYPE_SAFE_EXPOSURE_TIME_1, name="Skin type 1 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key=TYPE_SAFE_EXPOSURE_TIME_2, name="Skin type 2 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key=TYPE_SAFE_EXPOSURE_TIME_3, name="Skin type 3 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key=TYPE_SAFE_EXPOSURE_TIME_4, name="Skin type 4 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key=TYPE_SAFE_EXPOSURE_TIME_5, name="Skin type 5 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), SensorEntityDescription( key=TYPE_SAFE_EXPOSURE_TIME_6, name="Skin type 6 safe exposure time", icon="mdi:timer-outline", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), ) diff --git a/homeassistant/components/oralb/sensor.py b/homeassistant/components/oralb/sensor.py index af1edd582f9..124138d7e36 100644 --- a/homeassistant/components/oralb/sensor.py +++ b/homeassistant/components/oralb/sensor.py @@ -18,7 +18,7 @@ from homeassistant.components.sensor import ( SensorEntityDescription, 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.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -32,7 +32,7 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = { key=OralBSensor.TIME, device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.TOTAL_INCREASING, - native_unit_of_measurement=TIME_SECONDS, + native_unit_of_measurement=UnitOfTime.SECONDS, ), OralBSensor.SECTOR: SensorEntityDescription( key=OralBSensor.SECTOR, diff --git a/homeassistant/components/qnap_qsw/sensor.py b/homeassistant/components/qnap_qsw/sensor.py index 6e82bbd4fed..f86a4d3aa74 100644 --- a/homeassistant/components/qnap_qsw/sensor.py +++ b/homeassistant/components/qnap_qsw/sensor.py @@ -33,9 +33,9 @@ from homeassistant.components.sensor import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( TEMP_CELSIUS, - TIME_SECONDS, UnitOfDataRate, UnitOfInformation, + UnitOfTime, ) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity import EntityCategory @@ -146,7 +146,7 @@ SENSOR_TYPES: Final[tuple[QswSensorEntityDescription, ...]] = ( key=QSD_SYSTEM_TIME, entity_category=EntityCategory.DIAGNOSTIC, name="Uptime", - native_unit_of_measurement=TIME_SECONDS, + native_unit_of_measurement=UnitOfTime.SECONDS, state_class=SensorStateClass.TOTAL_INCREASING, subkey=QSD_UPTIME, ), diff --git a/homeassistant/components/raincloud/__init__.py b/homeassistant/components/raincloud/__init__.py index 40a9514e1d7..59019cf833d 100644 --- a/homeassistant/components/raincloud/__init__.py +++ b/homeassistant/components/raincloud/__init__.py @@ -12,8 +12,7 @@ from homeassistant.const import ( CONF_SCAN_INTERVAL, CONF_USERNAME, PERCENTAGE, - TIME_DAYS, - TIME_MINUTES, + UnitOfTime, ) from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv @@ -63,9 +62,9 @@ UNIT_OF_MEASUREMENT_MAP = { "is_watering": "", "manual_watering": "", "next_cycle": "", - "rain_delay": TIME_DAYS, + "rain_delay": UnitOfTime.DAYS, "status": "", - "watering_time": TIME_MINUTES, + "watering_time": UnitOfTime.MINUTES, } BINARY_SENSORS = ["is_watering", "status"] diff --git a/homeassistant/components/rejseplanen/sensor.py b/homeassistant/components/rejseplanen/sensor.py index fa1f9cc0b24..9ef8b5dc370 100644 --- a/homeassistant/components/rejseplanen/sensor.py +++ b/homeassistant/components/rejseplanen/sensor.py @@ -15,7 +15,7 @@ import rjpl import voluptuous as vol 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 import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -142,7 +142,7 @@ class RejseplanenTransportSensor(SensorEntity): @property def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" - return TIME_MINUTES + return UnitOfTime.MINUTES @property def icon(self): diff --git a/homeassistant/components/renault/sensor.py b/homeassistant/components/renault/sensor.py index 21f9dacb46b..257f0564ef1 100644 --- a/homeassistant/components/renault/sensor.py +++ b/homeassistant/components/renault/sensor.py @@ -25,10 +25,10 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( PERCENTAGE, TEMP_CELSIUS, - TIME_MINUTES, UnitOfEnergy, UnitOfLength, UnitOfPower, + UnitOfTime, UnitOfVolume, ) from homeassistant.core import HomeAssistant @@ -195,7 +195,7 @@ SENSOR_TYPES: tuple[RenaultSensorEntityDescription[Any], ...] = ( entity_class=RenaultSensor[KamereonVehicleBatteryStatusData], icon="mdi:timer", name="Charging remaining time", - native_unit_of_measurement=TIME_MINUTES, + native_unit_of_measurement=UnitOfTime.MINUTES, state_class=SensorStateClass.MEASUREMENT, ), RenaultSensorEntityDescription( diff --git a/homeassistant/components/rmvtransport/sensor.py b/homeassistant/components/rmvtransport/sensor.py index 25f14ae6df3..d3ee722af94 100644 --- a/homeassistant/components/rmvtransport/sensor.py +++ b/homeassistant/components/rmvtransport/sensor.py @@ -13,7 +13,7 @@ from RMVtransport.rmvtransport import ( import voluptuous as vol 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.exceptions import PlatformNotReady import homeassistant.helpers.config_validation as cv @@ -184,7 +184,7 @@ class RMVDepartureSensor(SensorEntity): @property def native_unit_of_measurement(self): """Return the unit this state is expressed in.""" - return TIME_MINUTES + return UnitOfTime.MINUTES async def async_update(self) -> None: """Get the latest data and update the state.""" diff --git a/homeassistant/components/speedtestdotnet/sensor.py b/homeassistant/components/speedtestdotnet/sensor.py index 66cf1bb5810..c3773802650 100644 --- a/homeassistant/components/speedtestdotnet/sensor.py +++ b/homeassistant/components/speedtestdotnet/sensor.py @@ -11,7 +11,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) 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.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -45,7 +45,7 @@ SENSOR_TYPES: tuple[SpeedtestSensorEntityDescription, ...] = ( SpeedtestSensorEntityDescription( key="ping", name="Ping", - native_unit_of_measurement=TIME_MILLISECONDS, + native_unit_of_measurement=UnitOfTime.MILLISECONDS, state_class=SensorStateClass.MEASUREMENT, ), SpeedtestSensorEntityDescription( diff --git a/homeassistant/components/steamist/sensor.py b/homeassistant/components/steamist/sensor.py index 0f9008e63dd..702feda580f 100644 --- a/homeassistant/components/steamist/sensor.py +++ b/homeassistant/components/steamist/sensor.py @@ -13,7 +13,7 @@ from homeassistant.components.sensor import ( SensorStateClass, ) 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.helpers.entity_platform import AddEntitiesCallback @@ -48,7 +48,7 @@ SENSORS: tuple[SteamistSensorEntityDescription, ...] = ( SteamistSensorEntityDescription( key=_KEY_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, ), SteamistSensorEntityDescription(