Use UnitOfTime in integrations (a-g) (#84288)
parent
55a5e17cf2
commit
68857dc272
|
@ -15,12 +15,12 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import (
|
||||
CONCENTRATION_PARTS_PER_CUBIC_METER,
|
||||
PERCENTAGE,
|
||||
TIME_HOURS,
|
||||
UV_INDEX,
|
||||
UnitOfLength,
|
||||
UnitOfPrecipitationDepth,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -95,7 +95,7 @@ FORECAST_SENSOR_TYPES: tuple[AccuWeatherSensorDescription, ...] = (
|
|||
key="HoursOfSun",
|
||||
icon="mdi:weather-partly-cloudy",
|
||||
name="Hours of sun",
|
||||
native_unit_of_measurement=TIME_HOURS,
|
||||
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||
value_fn=lambda data, _: cast(float, data),
|
||||
),
|
||||
AccuWeatherSensorDescription(
|
||||
|
|
|
@ -10,7 +10,7 @@ from adguardhome import AdGuardHome, AdGuardHomeConnectionError
|
|||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE, TIME_MILLISECONDS
|
||||
from homeassistant.const import PERCENTAGE, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -83,7 +83,7 @@ SENSORS: tuple[AdGuardHomeEntityDescription, ...] = (
|
|||
key="average_speed",
|
||||
name="Average processing speed",
|
||||
icon="mdi:speedometer",
|
||||
native_unit_of_measurement=TIME_MILLISECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.MILLISECONDS,
|
||||
value_fn=lambda adguard: adguard.stats.avg_processing_time(),
|
||||
),
|
||||
AdGuardHomeEntityDescription(
|
||||
|
|
|
@ -26,8 +26,8 @@ from homeassistant.const import (
|
|||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
TIME_SECONDS,
|
||||
UnitOfPressure,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -75,7 +75,7 @@ SENSOR_DESCRIPTIONS = {
|
|||
key="update_interval",
|
||||
name="Update Interval",
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
# The interval setting is not a generally useful entity for most users.
|
||||
entity_registry_enabled_default=False,
|
||||
|
|
|
@ -5,8 +5,8 @@ from homeassistant.const import (
|
|||
PERCENTAGE,
|
||||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
TIME_HOURS,
|
||||
UnitOfPressure,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -52,7 +52,7 @@ class AtagSensor(AtagEntity, SensorEntity):
|
|||
TEMP_CELSIUS,
|
||||
TEMP_FAHRENHEIT,
|
||||
PERCENTAGE,
|
||||
TIME_HOURS,
|
||||
UnitOfTime.HOURS,
|
||||
):
|
||||
self._attr_native_unit_of_measurement = coordinator.data.report[
|
||||
self._id
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TIME_DAYS, UnitOfInformation
|
||||
from homeassistant.const import UnitOfInformation, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
|
@ -113,13 +113,13 @@ SENSOR_DESCRIPTIONS: tuple[SensorValueEntityDescription, ...] = (
|
|||
SensorValueEntityDescription(
|
||||
key="daysTotal",
|
||||
name="Billing cycle length",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
icon="mdi:calendar-range",
|
||||
),
|
||||
SensorValueEntityDescription(
|
||||
key="daysRemaining",
|
||||
name="Billing cycle remaining",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
icon="mdi:calendar-clock",
|
||||
),
|
||||
)
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.components.number import (
|
|||
NumberEntityDescription,
|
||||
NumberMode,
|
||||
)
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import UnitOfTime
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -73,7 +73,7 @@ FAN_NUMBER_DESCRIPTIONS = (
|
|||
native_min_value=ONE_MIN_SECS,
|
||||
native_max_value=HALF_DAY_SECS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
value_fn=lambda device: cast(Optional[int], device.return_to_auto_timeout),
|
||||
mode=NumberMode.SLIDER,
|
||||
),
|
||||
|
@ -83,7 +83,7 @@ FAN_NUMBER_DESCRIPTIONS = (
|
|||
native_min_value=ONE_MIN_SECS,
|
||||
native_max_value=ONE_DAY_SECS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
value_fn=lambda device: cast(Optional[int], device.motion_sense_timeout),
|
||||
mode=NumberMode.SLIDER,
|
||||
),
|
||||
|
@ -96,7 +96,7 @@ LIGHT_NUMBER_DESCRIPTIONS = (
|
|||
native_min_value=ONE_MIN_SECS,
|
||||
native_max_value=HALF_DAY_SECS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
value_fn=lambda device: cast(
|
||||
Optional[int], device.light_return_to_auto_timeout
|
||||
),
|
||||
|
@ -108,7 +108,7 @@ LIGHT_NUMBER_DESCRIPTIONS = (
|
|||
native_min_value=ONE_MIN_SECS,
|
||||
native_max_value=ONE_DAY_SECS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
value_fn=lambda device: cast(Optional[int], device.light_auto_motion_timeout),
|
||||
mode=NumberMode.SLIDER,
|
||||
),
|
||||
|
|
|
@ -12,12 +12,7 @@ from homeassistant.components.sensor import (
|
|||
SensorEntity,
|
||||
SensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_CURRENCY,
|
||||
CONF_DISPLAY_OPTIONS,
|
||||
TIME_MINUTES,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
from homeassistant.const import CONF_CURRENCY, CONF_DISPLAY_OPTIONS, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -65,7 +60,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="minutes_between_blocks",
|
||||
name="Time between Blocks",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="number_of_transactions",
|
||||
|
@ -74,7 +69,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="hash_rate",
|
||||
name="Hash rate",
|
||||
native_unit_of_measurement=f"PH/{TIME_SECONDS}",
|
||||
native_unit_of_measurement=f"PH/{UnitOfTime.SECONDS}",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="timestamp",
|
||||
|
|
|
@ -7,7 +7,7 @@ from bizkaibus.bizkaibus import BizkaibusData
|
|||
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
|
||||
|
@ -47,7 +47,7 @@ def setup_platform(
|
|||
class BizkaibusSensor(SensorEntity):
|
||||
"""The class for handling the data."""
|
||||
|
||||
_attr_native_unit_of_measurement = TIME_MINUTES
|
||||
_attr_native_unit_of_measurement = UnitOfTime.MINUTES
|
||||
|
||||
def __init__(self, data, name):
|
||||
"""Initialize the sensor."""
|
||||
|
|
|
@ -25,7 +25,6 @@ from homeassistant.const import (
|
|||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TIME_SECONDS,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
|
@ -35,6 +34,7 @@ from homeassistant.const import (
|
|||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
UnitOfTemperature,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -207,7 +207,7 @@ SENSOR_DESCRIPTIONS = {
|
|||
(BTHomeSensorDeviceClass.DURATION, Units.TIME_SECONDS): SensorEntityDescription(
|
||||
key=f"{BTHomeSensorDeviceClass.DURATION}_{Units.TIME_SECONDS}",
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
# Used for current sensor
|
||||
|
|
|
@ -41,10 +41,10 @@ from homeassistant.const import (
|
|||
PERCENTAGE,
|
||||
REVOLUTIONS_PER_MINUTE,
|
||||
TEMP_CELSIUS,
|
||||
TIME_DAYS,
|
||||
VOLUME_FLOW_RATE_CUBIC_METERS_PER_HOUR,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -232,7 +232,7 @@ SENSOR_TYPES = (
|
|||
ComfoconnectSensorEntityDescription(
|
||||
key=ATTR_DAYS_TO_REPLACE_FILTER,
|
||||
name="Days to replace filter",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
icon="mdi:calendar",
|
||||
sensor_id=SENSOR_DAYS_TO_REPLACE_FILTER,
|
||||
),
|
||||
|
|
|
@ -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_NAME,
|
||||
CONF_SOURCE,
|
||||
TIME_DAYS,
|
||||
TIME_HOURS,
|
||||
TIME_MINUTES,
|
||||
TIME_SECONDS,
|
||||
)
|
||||
from homeassistant.const import CONF_NAME, CONF_SOURCE, UnitOfTime
|
||||
from homeassistant.helpers import selector
|
||||
from homeassistant.helpers.schema_config_entry_flow import (
|
||||
SchemaConfigFlowHandler,
|
||||
|
@ -41,10 +34,10 @@ UNIT_PREFIXES = [
|
|||
selector.SelectOptionDict(value="P", label="P (peta)"),
|
||||
]
|
||||
TIME_UNITS = [
|
||||
selector.SelectOptionDict(value=TIME_SECONDS, label="Seconds"),
|
||||
selector.SelectOptionDict(value=TIME_MINUTES, label="Minutes"),
|
||||
selector.SelectOptionDict(value=TIME_HOURS, label="Hours"),
|
||||
selector.SelectOptionDict(value=TIME_DAYS, label="Days"),
|
||||
selector.SelectOptionDict(value=UnitOfTime.SECONDS, label="Seconds"),
|
||||
selector.SelectOptionDict(value=UnitOfTime.MINUTES, label="Minutes"),
|
||||
selector.SelectOptionDict(value=UnitOfTime.HOURS, label="Hours"),
|
||||
selector.SelectOptionDict(value=UnitOfTime.DAYS, label="Days"),
|
||||
]
|
||||
|
||||
OPTIONS_SCHEMA = vol.Schema(
|
||||
|
@ -61,7 +54,7 @@ OPTIONS_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),
|
||||
),
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@ from homeassistant.const import (
|
|||
CONF_SOURCE,
|
||||
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
|
||||
|
@ -54,10 +51,10 @@ UNIT_PREFIXES = {
|
|||
|
||||
# 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,
|
||||
}
|
||||
|
||||
ICON = "mdi:chart-line"
|
||||
|
@ -71,7 +68,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|||
vol.Required(CONF_SOURCE): 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.Optional(CONF_UNIT): cv.string,
|
||||
vol.Optional(CONF_TIME_WINDOW, default=DEFAULT_TIME_WINDOW): cv.time_period,
|
||||
}
|
||||
|
@ -144,7 +141,7 @@ class DerivativeSensor(RestoreEntity, SensorEntity):
|
|||
time_window: timedelta,
|
||||
unit_of_measurement: str | None,
|
||||
unit_prefix: str | None,
|
||||
unit_time: str,
|
||||
unit_time: UnitOfTime,
|
||||
unique_id: str | None,
|
||||
) -> None:
|
||||
"""Initialize the derivative sensor."""
|
||||
|
|
|
@ -14,7 +14,7 @@ import requests
|
|||
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
|
||||
|
@ -117,7 +117,7 @@ class DublinPublicTransportSensor(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):
|
||||
|
|
|
@ -24,8 +24,8 @@ from homeassistant.const import (
|
|||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
PERCENTAGE,
|
||||
TIME_DAYS,
|
||||
UnitOfInformation,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
|
@ -69,7 +69,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="days_left",
|
||||
name="Days left",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
icon="mdi:calendar-today",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.const import (
|
|||
CONF_LONGITUDE,
|
||||
CONF_NAME,
|
||||
CONF_SHOW_ON_MAP,
|
||||
TIME_MINUTES,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -190,7 +190,7 @@ class EnturPublicTransportSensor(SensorEntity):
|
|||
@property
|
||||
def native_unit_of_measurement(self) -> str:
|
||||
"""Return the unit this state is expressed in."""
|
||||
return TIME_MINUTES
|
||||
return UnitOfTime.MINUTES
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
|
|
|
@ -24,8 +24,8 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_PASSWORD,
|
||||
CONF_USERNAME,
|
||||
TIME_MINUTES,
|
||||
UnitOfInformation,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
@ -135,37 +135,37 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="talk_used",
|
||||
name="Talk used",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="talk_limit",
|
||||
name="Talk limit",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="talk_remaining",
|
||||
name="Talk remaining",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="other_talk_used",
|
||||
name="Other Talk used",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="other_talk_limit",
|
||||
name="Other Talk limit",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="other_talk_remaining",
|
||||
name="Other Talk remaining",
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
icon="mdi:cellphone",
|
||||
),
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from homeassistant.components.number import NumberEntity
|
||||
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 DeviceInfo, Entity, EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -36,7 +36,7 @@ class PeriodicVentingTime(CoordinatorEntity[Coordinator], NumberEntity):
|
|||
_attr_native_min_value: float = 0
|
||||
_attr_native_step: float = 1
|
||||
_attr_entity_category = EntityCategory.CONFIG
|
||||
_attr_native_unit_of_measurement = TIME_MINUTES
|
||||
_attr_native_unit_of_measurement = UnitOfTime.MINUTES
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
|
@ -5,7 +5,7 @@ from contextlib import suppress
|
|||
|
||||
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import UnitOfTime
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -21,7 +21,7 @@ ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
|
|||
native_max_value=9999,
|
||||
native_step=1,
|
||||
native_min_value=0,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
NumberEntityDescription(
|
||||
|
@ -38,7 +38,7 @@ ENTITY_TYPES: tuple[NumberEntityDescription, ...] = (
|
|||
native_max_value=9999,
|
||||
native_step=1,
|
||||
native_min_value=0,
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
),
|
||||
NumberEntityDescription(
|
||||
|
|
|
@ -14,12 +14,11 @@ from homeassistant.const import (
|
|||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
TEMP_CELSIUS,
|
||||
TIME_MINUTES,
|
||||
TIME_SECONDS,
|
||||
UnitOfElectricCurrent,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -92,7 +91,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
key="timeToEmptyFull",
|
||||
name="Time to empty/full",
|
||||
device_class=SensorDeviceClass.DURATION,
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key="temperature",
|
||||
|
@ -112,7 +111,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||
SensorEntityDescription(
|
||||
key="timestamp",
|
||||
name="Total run time",
|
||||
native_unit_of_measurement=TIME_SECONDS,
|
||||
native_unit_of_measurement=UnitOfTime.SECONDS,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
|||
CONF_API_KEY,
|
||||
CONF_NAME,
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
TIME_MINUTES,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import CoreState, HomeAssistant
|
||||
from homeassistant.helpers.device_registry import DeviceEntryType
|
||||
|
@ -76,7 +76,7 @@ class GoogleTravelTimeSensor(SensorEntity):
|
|||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
self._config_entry = config_entry
|
||||
self._unit_of_measurement = TIME_MINUTES
|
||||
self._unit_of_measurement = UnitOfTime.MINUTES
|
||||
self._matrix = None
|
||||
self._api_key = api_key
|
||||
self._unique_id = config_entry.entry_id
|
||||
|
|
|
@ -18,7 +18,7 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
STATE_UNKNOWN,
|
||||
TIME_DAYS,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -75,7 +75,7 @@ SENSOR_TYPES: tuple[GoogleWifiSensorEntityDescription, ...] = (
|
|||
key=ATTR_UPTIME,
|
||||
primary_key="system",
|
||||
sensor_key="uptime",
|
||||
native_unit_of_measurement=TIME_DAYS,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
icon="mdi:timelapse",
|
||||
),
|
||||
GoogleWifiSensorEntityDescription(
|
||||
|
|
|
@ -12,10 +12,8 @@ from homeassistant.const import (
|
|||
CONF_SENSORS,
|
||||
CONF_TEMPERATURE_UNIT,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
TIME_HOURS,
|
||||
TIME_MINUTES,
|
||||
TIME_SECONDS,
|
||||
Platform,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -66,8 +64,8 @@ PULSE_COUNTER_SCHEMA = vol.Schema(
|
|||
vol.Required(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_COUNTED_QUANTITY): cv.string,
|
||||
vol.Optional(CONF_COUNTED_QUANTITY_PER_PULSE, default=1.0): vol.Coerce(float),
|
||||
vol.Optional(CONF_TIME_UNIT, default=TIME_SECONDS): vol.Any(
|
||||
TIME_SECONDS, TIME_MINUTES, TIME_HOURS
|
||||
vol.Optional(CONF_TIME_UNIT, default=UnitOfTime.SECONDS): vol.Any(
|
||||
UnitOfTime.SECONDS.value, UnitOfTime.MINUTES.value, UnitOfTime.HOURS.value
|
||||
),
|
||||
}
|
||||
)
|
||||
|
|
|
@ -10,11 +10,9 @@ from homeassistant.const import (
|
|||
CONF_NAME,
|
||||
CONF_SENSORS,
|
||||
CONF_TEMPERATURE_UNIT,
|
||||
TIME_HOURS,
|
||||
TIME_MINUTES,
|
||||
TIME_SECONDS,
|
||||
UnitOfElectricPotential,
|
||||
UnitOfPower,
|
||||
UnitOfTime,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -233,16 +231,16 @@ class PulseCounter(GEMSensor):
|
|||
@property
|
||||
def _seconds_per_time_unit(self) -> int:
|
||||
"""Return the number of seconds in the given display time unit."""
|
||||
if self._time_unit == TIME_SECONDS:
|
||||
if self._time_unit == UnitOfTime.SECONDS:
|
||||
return 1
|
||||
if self._time_unit == TIME_MINUTES:
|
||||
if self._time_unit == UnitOfTime.MINUTES:
|
||||
return 60
|
||||
if self._time_unit == TIME_HOURS:
|
||||
if self._time_unit == UnitOfTime.HOURS:
|
||||
return 3600
|
||||
|
||||
# Config schema should have ensured it is one of the above values
|
||||
raise Exception(
|
||||
f"Invalid value for time unit: {self._time_unit}. Expected one of {TIME_SECONDS}, {TIME_MINUTES}, or {TIME_HOURS}"
|
||||
f"Invalid value for time unit: {self._time_unit}. Expected one of {UnitOfTime.SECONDS}, {UnitOfTime.MINUTES}, or {UnitOfTime.HOURS}"
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import TEMP_FAHRENHEIT, TIME_MINUTES, UnitOfElectricPotential
|
||||
from homeassistant.const import TEMP_FAHRENHEIT, UnitOfElectricPotential, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
@ -72,7 +72,7 @@ VALVE_CONTROLLER_DESCRIPTIONS = (
|
|||
name="Uptime",
|
||||
icon="mdi:timer",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
native_unit_of_measurement=TIME_MINUTES,
|
||||
native_unit_of_measurement=UnitOfTime.MINUTES,
|
||||
api_category=API_SYSTEM_DIAGNOSTICS,
|
||||
),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue