Tiny cleanup in Number base entity (#87339)
parent
fc38b4327f
commit
9ead071202
|
@ -8,15 +8,14 @@ from datetime import timedelta
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
from math import ceil, floor
|
from math import ceil, floor
|
||||||
from typing import Any, Final, final
|
from typing import Any, final
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.backports.enum import StrEnum
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import ATTR_MODE, CONF_UNIT_OF_MEASUREMENT, UnitOfTemperature
|
from homeassistant.const import ATTR_MODE, CONF_UNIT_OF_MEASUREMENT, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers.config_validation import ( # noqa: F401
|
from homeassistant.helpers.config_validation import (
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
PLATFORM_SCHEMA_BASE,
|
PLATFORM_SCHEMA_BASE,
|
||||||
)
|
)
|
||||||
|
@ -37,27 +36,36 @@ from .const import (
|
||||||
SERVICE_SET_VALUE,
|
SERVICE_SET_VALUE,
|
||||||
UNIT_CONVERTERS,
|
UNIT_CONVERTERS,
|
||||||
NumberDeviceClass,
|
NumberDeviceClass,
|
||||||
|
NumberMode,
|
||||||
)
|
)
|
||||||
from .websocket_api import async_setup as async_setup_ws_api
|
from .websocket_api import async_setup as async_setup_ws_api
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(seconds=30)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
ENTITY_ID_FORMAT = DOMAIN + ".{}"
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
DEVICE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(NumberDeviceClass))
|
|
||||||
|
|
||||||
|
|
||||||
class NumberMode(StrEnum):
|
|
||||||
"""Modes for number entities."""
|
|
||||||
|
|
||||||
AUTO = "auto"
|
|
||||||
BOX = "box"
|
|
||||||
SLIDER = "slider"
|
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"ATTR_MAX",
|
||||||
|
"ATTR_MIN",
|
||||||
|
"ATTR_STEP",
|
||||||
|
"ATTR_VALUE",
|
||||||
|
"DEFAULT_MAX_VALUE",
|
||||||
|
"DEFAULT_MIN_VALUE",
|
||||||
|
"DEFAULT_STEP",
|
||||||
|
"DOMAIN",
|
||||||
|
"PLATFORM_SCHEMA_BASE",
|
||||||
|
"PLATFORM_SCHEMA",
|
||||||
|
"NumberDeviceClass",
|
||||||
|
"NumberEntity",
|
||||||
|
"NumberEntityDescription",
|
||||||
|
"NumberExtraStoredData",
|
||||||
|
"NumberMode",
|
||||||
|
"RestoreNumber",
|
||||||
|
]
|
||||||
|
|
||||||
# mypy: disallow-any-generics
|
# mypy: disallow-any-generics
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
from typing import Final
|
from typing import Final
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.backports.enum import StrEnum
|
from homeassistant.backports.enum import StrEnum
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
@ -342,6 +344,15 @@ class NumberDeviceClass(StrEnum):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class NumberMode(StrEnum):
|
||||||
|
"""Modes for number entities."""
|
||||||
|
|
||||||
|
AUTO = "auto"
|
||||||
|
BOX = "box"
|
||||||
|
SLIDER = "slider"
|
||||||
|
|
||||||
|
|
||||||
|
DEVICE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(NumberDeviceClass))
|
||||||
DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
|
DEVICE_CLASS_UNITS: dict[NumberDeviceClass, set[type[StrEnum] | str | None]] = {
|
||||||
NumberDeviceClass.APPARENT_POWER: set(UnitOfApparentPower),
|
NumberDeviceClass.APPARENT_POWER: set(UnitOfApparentPower),
|
||||||
NumberDeviceClass.AQI: {None},
|
NumberDeviceClass.AQI: {None},
|
||||||
|
|
Loading…
Reference in New Issue