Use UnitOfTime in integrations (t-z) (#84291)

This commit is contained in:
epenet 2022-12-20 12:30:14 +01:00 committed by GitHub
parent 1f3da9cf1a
commit fba13dcc90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 50 additions and 56 deletions

View File

@ -9,7 +9,7 @@ from tmb import IBus
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
@ -81,7 +81,7 @@ class TMBSensor(SensorEntity):
self._stop = stop self._stop = stop
self._line = line.upper() self._line = line.upper()
self._name = name self._name = name
self._unit = TIME_MINUTES self._unit = UnitOfTime.MINUTES
self._state = None self._state = None
@property @property

View File

@ -10,7 +10,7 @@ from tololib.message_info import SettingsInfo
from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.components.number import NumberEntity, NumberEntityDescription
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
@ -43,7 +43,7 @@ NUMBERS = (
key="power_timer", key="power_timer",
icon="mdi:power-settings", icon="mdi:power-settings",
name="Power Timer", name="Power Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
native_max_value=POWER_TIMER_MAX, native_max_value=POWER_TIMER_MAX,
getter=lambda settings: settings.power_timer, getter=lambda settings: settings.power_timer,
setter=lambda client, value: client.set_power_timer(value), setter=lambda client, value: client.set_power_timer(value),
@ -52,7 +52,7 @@ NUMBERS = (
key="salt_bath_timer", key="salt_bath_timer",
icon="mdi:shaker-outline", icon="mdi:shaker-outline",
name="Salt Bath Timer", name="Salt Bath Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
native_max_value=SALT_BATH_TIMER_MAX, native_max_value=SALT_BATH_TIMER_MAX,
getter=lambda settings: settings.salt_bath_timer, getter=lambda settings: settings.salt_bath_timer,
setter=lambda client, value: client.set_salt_bath_timer(value), setter=lambda client, value: client.set_salt_bath_timer(value),
@ -61,7 +61,7 @@ NUMBERS = (
key="fan_timer", key="fan_timer",
icon="mdi:fan-auto", icon="mdi:fan-auto",
name="Fan Timer", name="Fan Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
native_max_value=FAN_TIMER_MAX, native_max_value=FAN_TIMER_MAX,
getter=lambda settings: settings.fan_timer, getter=lambda settings: settings.fan_timer,
setter=lambda client, value: client.set_fan_timer(value), setter=lambda client, value: client.set_fan_timer(value),

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 PERCENTAGE, TEMP_CELSIUS, TIME_MINUTES from homeassistant.const import PERCENTAGE, TEMP_CELSIUS, 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
@ -63,7 +63,7 @@ SENSORS = (
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:power-settings", icon="mdi:power-settings",
name="Power Timer", name="Power Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
getter=lambda status: status.power_timer, getter=lambda status: status.power_timer,
availability_checker=lambda settings, status: status.power_on availability_checker=lambda settings, status: status.power_on
and settings.power_timer is not None, and settings.power_timer is not None,
@ -73,7 +73,7 @@ SENSORS = (
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:shaker-outline", icon="mdi:shaker-outline",
name="Salt Bath Timer", name="Salt Bath Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
getter=lambda status: status.salt_bath_timer, getter=lambda status: status.salt_bath_timer,
availability_checker=lambda settings, status: status.salt_bath_on availability_checker=lambda settings, status: status.salt_bath_on
and settings.salt_bath_timer is not None, and settings.salt_bath_timer is not None,
@ -83,7 +83,7 @@ SENSORS = (
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
icon="mdi:fan-auto", icon="mdi:fan-auto",
name="Fan Timer", name="Fan Timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
getter=lambda status: status.fan_timer, getter=lambda status: status.fan_timer,
availability_checker=lambda settings, status: status.fan_on availability_checker=lambda settings, status: status.fan_on
and settings.fan_timer is not None, and settings.fan_timer is not None,

View File

@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_BATTERY_LEVEL, PERCENTAGE, TIME_MINUTES from homeassistant.const import ATTR_BATTERY_LEVEL, PERCENTAGE, UnitOfTime
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -152,14 +152,14 @@ SENSOR_TYPES: tuple[TractiveSensorEntityDescription, ...] = (
key=ATTR_MINUTES_ACTIVE, key=ATTR_MINUTES_ACTIVE,
name="Minutes active", name="Minutes active",
icon="mdi:clock-time-eight-outline", icon="mdi:clock-time-eight-outline",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
entity_class=TractiveActivitySensor, entity_class=TractiveActivitySensor,
), ),
TractiveSensorEntityDescription( TractiveSensorEntityDescription(
key=ATTR_DAILY_GOAL, key=ATTR_DAILY_GOAL,
name="Daily goal", name="Daily goal",
icon="mdi:flag-checkered", icon="mdi:flag-checkered",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
entity_class=TractiveActivitySensor, entity_class=TractiveActivitySensor,
), ),
) )

View File

@ -18,8 +18,8 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
PERCENTAGE, PERCENTAGE,
TIME_HOURS,
Platform, Platform,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry from homeassistant.helpers import entity_registry
@ -98,7 +98,7 @@ SENSOR_DESCRIPTIONS_FAN: tuple[TradfriSensorEntityDescription, ...] = (
key="filter_life_remaining", key="filter_life_remaining",
name="filter time left", name="filter time left",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TIME_HOURS, native_unit_of_measurement=UnitOfTime.HOURS,
icon="mdi:clock-outline", icon="mdi:clock-outline",
value=_get_filter_time_left, value=_get_filter_time_left,
), ),

View File

@ -7,7 +7,7 @@ from TransportNSW import TransportNSW
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 ATTR_MODE, CONF_API_KEY, CONF_NAME, TIME_MINUTES from homeassistant.const import ATTR_MODE, CONF_API_KEY, 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
@ -106,7 +106,7 @@ class TransportNSWSensor(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

@ -18,7 +18,7 @@ from homeassistant.const import (
CONF_API_KEY, CONF_API_KEY,
CONF_MONITORED_CONDITIONS, CONF_MONITORED_CONDITIONS,
CONF_SCAN_INTERVAL, CONF_SCAN_INTERVAL,
TIME_SECONDS, 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
@ -43,7 +43,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( SensorEntityDescription(
key="last_build_duration", key="last_build_duration",
name="Last Build Duration", name="Last Build Duration",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
icon="mdi:timelapse", icon="mdi:timelapse",
), ),
SensorEntityDescription( SensorEntityDescription(

View File

@ -9,7 +9,7 @@ from homeassistant.components.number import (
NumberEntityDescription, NumberEntityDescription,
) )
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, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -146,7 +146,7 @@ NUMBERS: dict[str, tuple[NumberEntityDescription, ...]] = {
key=DPCode.COOK_TIME, key=DPCode.COOK_TIME,
name="Cook time", name="Cook time",
icon="mdi:timer", icon="mdi:timer",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
), ),
NumberEntityDescription( NumberEntityDescription(

View File

@ -15,10 +15,10 @@ 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_MINUTES,
UnitOfElectricCurrent, UnitOfElectricCurrent,
UnitOfElectricPotential, UnitOfElectricPotential,
UnitOfPower, UnitOfPower,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -437,7 +437,7 @@ SENSORS: dict[str, tuple[TuyaSensorEntityDescription, ...]] = {
TuyaSensorEntityDescription( TuyaSensorEntityDescription(
key=DPCode.REMAIN_TIME, key=DPCode.REMAIN_TIME,
name="Remaining time", name="Remaining time",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
icon="mdi:timer", icon="mdi:timer",
), ),
), ),

View File

@ -10,7 +10,7 @@ import requests
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_MODE, TIME_MINUTES from homeassistant.const import CONF_MODE, 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
@ -107,7 +107,7 @@ class UkTransportSensor(SensorEntity):
TRANSPORT_API_URL_BASE = "https://transportapi.com/v3/uk/" TRANSPORT_API_URL_BASE = "https://transportapi.com/v3/uk/"
_attr_icon = "mdi:train" _attr_icon = "mdi:train"
_attr_native_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = UnitOfTime.MINUTES
def __init__(self, name, api_app_id, api_app_key, url): def __init__(self, name, api_app_id, api_app_key, url):
"""Initialize the sensor.""" """Initialize the sensor."""

View File

@ -14,7 +14,7 @@ from pyunifiprotect.data import (
from homeassistant.components.number import NumberEntity, NumberEntityDescription from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import PERCENTAGE, TIME_SECONDS from homeassistant.const import PERCENTAGE, UnitOfTime
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -124,7 +124,7 @@ LIGHT_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
name="Auto-shutoff Duration", name="Auto-shutoff Duration",
icon="mdi:camera-timer", icon="mdi:camera-timer",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
ufp_min=15, ufp_min=15,
ufp_max=900, ufp_max=900,
ufp_step=15, ufp_step=15,
@ -158,7 +158,7 @@ DOORLOCK_NUMBERS: tuple[ProtectNumberEntityDescription, ...] = (
name="Auto-lock Timeout", name="Auto-lock Timeout",
icon="mdi:walk", icon="mdi:walk",
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
ufp_min=0, ufp_min=0,
ufp_max=3600, ufp_max=3600,
ufp_step=15, ufp_step=15,

View File

@ -30,10 +30,10 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TEMP_CELSIUS, TEMP_CELSIUS,
TIME_SECONDS,
UnitOfDataRate, UnitOfDataRate,
UnitOfElectricPotential, UnitOfElectricPotential,
UnitOfInformation, UnitOfInformation,
UnitOfTime,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
@ -482,7 +482,7 @@ NVR_SENSORS: tuple[ProtectSensorEntityDescription, ...] = (
ProtectSensorEntityDescription[NVR]( ProtectSensorEntityDescription[NVR](
key="record_capacity", key="record_capacity",
name="Recording Capacity", name="Recording Capacity",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
icon="mdi:record-rec", icon="mdi:record-rec",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,

View File

@ -2,7 +2,7 @@
from datetime import timedelta from datetime import timedelta
import logging import logging
from homeassistant.const import TIME_SECONDS from homeassistant.const import UnitOfTime
LOGGER = logging.getLogger(__package__) LOGGER = logging.getLogger(__package__)
@ -18,7 +18,7 @@ PACKETS_PER_SEC_RECEIVED = "packets_per_sec_received"
PACKETS_PER_SEC_SENT = "packets_per_sec_sent" PACKETS_PER_SEC_SENT = "packets_per_sec_sent"
TIMESTAMP = "timestamp" TIMESTAMP = "timestamp"
DATA_PACKETS = "packets" DATA_PACKETS = "packets"
DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{TIME_SECONDS}" DATA_RATE_PACKETS_PER_SECOND = f"{DATA_PACKETS}/{UnitOfTime.SECONDS}"
WAN_STATUS = "wan_status" WAN_STATUS = "wan_status"
ROUTER_IP = "ip" ROUTER_IP = "ip"
ROUTER_UPTIME = "uptime" ROUTER_UPTIME = "uptime"

View File

@ -10,7 +10,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_SECONDS, UnitOfDataRate, UnitOfInformation from homeassistant.const import UnitOfDataRate, UnitOfInformation, 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
@ -90,7 +90,7 @@ SENSOR_DESCRIPTIONS: tuple[UpnpSensorEntityDescription, ...] = (
key=ROUTER_UPTIME, key=ROUTER_UPTIME,
name="Uptime", name="Uptime",
icon="mdi:server-network", icon="mdi:server-network",
native_unit_of_measurement=TIME_SECONDS, native_unit_of_measurement=UnitOfTime.SECONDS,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
format="d", format="d",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,

View File

@ -17,7 +17,7 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT, TEMP_FAHRENHEIT,
TIME_MINUTES, UnitOfTime,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -207,7 +207,7 @@ SENSOR_ENTITIES: tuple[VenstarSensorEntityDescription, ...] = (
RUNTIME_ENTITY = VenstarSensorEntityDescription( RUNTIME_ENTITY = VenstarSensorEntityDescription(
key="runtime", key="runtime",
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
uom_fn=lambda _: TIME_MINUTES, uom_fn=lambda _: UnitOfTime.MINUTES,
value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name], value_fn=lambda coordinator, sensor_name: coordinator.runtimes[-1][sensor_name],
name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime", name_fn=lambda coordinator, sensor_name: f"{coordinator.client.name} {RUNTIME_ATTRIBUTES[sensor_name]} Runtime",
) )

View File

@ -11,7 +11,7 @@ import async_timeout
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 TIME_MINUTES from homeassistant.const import UnitOfTime
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -187,5 +187,5 @@ class ViaggiaTrenoSensor(SensorEntity):
self._unit = "" self._unit = ""
else: else:
self._state = res.get("ritardo") self._state = res.get("ritardo")
self._unit = TIME_MINUTES self._unit = UnitOfTime.MINUTES
self._icon = ICON self._icon = ICON

View File

@ -16,8 +16,8 @@ from homeassistant.const import (
CONF_NAME, CONF_NAME,
CONF_REGION, CONF_REGION,
EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STARTED,
TIME_MINUTES,
UnitOfLength, UnitOfLength,
UnitOfTime,
) )
from homeassistant.core import CoreState, HomeAssistant from homeassistant.core import CoreState, HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.device_registry import DeviceEntryType
@ -74,7 +74,7 @@ class WazeTravelTime(SensorEntity):
"""Representation of a Waze travel time sensor.""" """Representation of a Waze travel time sensor."""
_attr_attribution = "Powered by Waze" _attr_attribution = "Powered by Waze"
_attr_native_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = UnitOfTime.MINUTES
_attr_device_class = SensorDeviceClass.DURATION _attr_device_class = SensorDeviceClass.DURATION
_attr_state_class = SensorStateClass.MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT
_attr_device_info = DeviceInfo( _attr_device_info = DeviceInfo(

View File

@ -14,7 +14,7 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DOMAIN, TIME_DAYS from homeassistant.const import CONF_DOMAIN, 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, EntityCategory from homeassistant.helpers.entity import DeviceInfo, EntityCategory
@ -81,7 +81,7 @@ SENSORS: tuple[WhoisSensorEntityDescription, ...] = (
key="days_until_expiration", key="days_until_expiration",
name="Days until expiration", name="Days until expiration",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
native_unit_of_measurement=TIME_DAYS, native_unit_of_measurement=UnitOfTime.DAYS,
value_fn=_days_until_expiration, value_fn=_days_until_expiration,
), ),
WhoisSensorEntityDescription( WhoisSensorEntityDescription(

View File

@ -13,7 +13,7 @@ from wolf_smartset.models import (
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import TEMP_CELSIUS, TIME_HOURS, UnitOfPressure from homeassistant.const import TEMP_CELSIUS, UnitOfPressure, 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
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -100,7 +100,7 @@ class WolfLinkHours(WolfLinkSensor):
@property @property
def native_unit_of_measurement(self): def native_unit_of_measurement(self):
"""Return the unit the value is expressed in.""" """Return the unit the value is expressed in."""
return TIME_HOURS return UnitOfTime.HOURS
class WolfLinkTemperature(WolfLinkSensor): class WolfLinkTemperature(WolfLinkSensor):

View File

@ -10,13 +10,7 @@ import requests
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 ( from homeassistant.const import ATTR_NAME, CONF_API_KEY, CONF_ID, CONF_NAME, UnitOfTime
ATTR_NAME,
CONF_API_KEY,
CONF_ID,
CONF_NAME,
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
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -106,7 +100,7 @@ class WashingtonStateTravelTimeSensor(WashingtonStateTransportSensor):
"""Travel time sensor from WSDOT.""" """Travel time sensor from WSDOT."""
_attr_attribution = ATTRIBUTION _attr_attribution = ATTRIBUTION
_attr_native_unit_of_measurement = TIME_MINUTES _attr_native_unit_of_measurement = UnitOfTime.MINUTES
def __init__(self, name, access_code, travel_time_id): def __init__(self, name, access_code, travel_time_id):
"""Construct a travel time sensor.""" """Construct a travel time sensor."""

View File

@ -12,7 +12,7 @@ from homeassistant.components.number import (
NumberEntityDescription, NumberEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_MODEL, DEGREE, REVOLUTIONS_PER_MINUTE, TIME_MINUTES from homeassistant.const import CONF_MODEL, DEGREE, REVOLUTIONS_PER_MINUTE, UnitOfTime
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import entity_registry as er from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity import EntityCategory
@ -193,7 +193,7 @@ NUMBER_TYPES = {
key=ATTR_DELAY_OFF_COUNTDOWN, key=ATTR_DELAY_OFF_COUNTDOWN,
name="Delay off countdown", name="Delay off countdown",
icon="mdi:fan-off", icon="mdi:fan-off",
native_unit_of_measurement=TIME_MINUTES, native_unit_of_measurement=UnitOfTime.MINUTES,
native_min_value=0, native_min_value=0,
native_max_value=480, native_max_value=480,
native_step=1, native_step=1,

View File

@ -96,7 +96,6 @@ from homeassistant.const import (
PERCENTAGE, PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS, SIGNAL_STRENGTH_DECIBELS,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT, SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
TIME_SECONDS,
VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE, VOLUME_FLOW_RATE_CUBIC_FEET_PER_MINUTE,
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR, VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
UnitOfElectricCurrent, UnitOfElectricCurrent,
@ -110,6 +109,7 @@ from homeassistant.const import (
UnitOfPressure, UnitOfPressure,
UnitOfSpeed, UnitOfSpeed,
UnitOfTemperature, UnitOfTemperature,
UnitOfTime,
UnitOfVolume, UnitOfVolume,
UnitOfVolumetricFlux, UnitOfVolumetricFlux,
) )
@ -202,7 +202,7 @@ MULTILEVEL_SENSOR_UNIT_MAP: dict[str, set[MultilevelSensorScaleType]] = {
UnitOfMass.POUNDS: UNIT_POUNDS, UnitOfMass.POUNDS: UNIT_POUNDS,
UnitOfPressure.PSI: UNIT_POUND_PER_SQUARE_INCH, UnitOfPressure.PSI: UNIT_POUND_PER_SQUARE_INCH,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT: UNIT_POWER_LEVEL, SIGNAL_STRENGTH_DECIBELS_MILLIWATT: UNIT_POWER_LEVEL,
TIME_SECONDS: UNIT_SECOND, UnitOfTime.SECONDS: UNIT_SECOND,
UnitOfPressure.MMHG: UNIT_SYSTOLIC, UnitOfPressure.MMHG: UNIT_SYSTOLIC,
UnitOfElectricPotential.VOLT: SENSOR_UNIT_VOLT, UnitOfElectricPotential.VOLT: SENSOR_UNIT_VOLT,
UnitOfPower.WATT: SENSOR_UNIT_WATT, UnitOfPower.WATT: SENSOR_UNIT_WATT,