mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Use UnitOfTime in integrations (h-s) (#84289)
This commit is contained in:
parent
6a8d9a91cb
commit
55a5e17cf2
@ -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",
|
||||
|
@ -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: "",
|
||||
}
|
||||
|
@ -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 [
|
||||
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -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
|
||||
),
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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(
|
||||
|
@ -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,
|
||||
|
@ -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)),
|
||||
|
@ -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:
|
||||
|
@ -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."""
|
||||
|
@ -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",
|
||||
),
|
||||
]
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
),
|
||||
|
@ -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,
|
||||
),
|
||||
)
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
),
|
||||
|
@ -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"]
|
||||
|
@ -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):
|
||||
|
@ -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(
|
||||
|
@ -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."""
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user