Tiny cleanup in Number base entity (#87339)

pull/87371/head
Franck Nijhof 2023-02-04 10:04:44 +01:00 committed by GitHub
parent fc38b4327f
commit 9ead071202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 15 deletions

View File

@ -8,15 +8,14 @@ from datetime import timedelta
import inspect
import logging
from math import ceil, floor
from typing import Any, Final, final
from typing import Any, final
import voluptuous as vol
from homeassistant.backports.enum import StrEnum
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_MODE, CONF_UNIT_OF_MEASUREMENT, UnitOfTemperature
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_BASE,
)
@ -37,27 +36,36 @@ from .const import (
SERVICE_SET_VALUE,
UNIT_CONVERTERS,
NumberDeviceClass,
NumberMode,
)
from .websocket_api import async_setup as async_setup_ws_api
SCAN_INTERVAL = timedelta(seconds=30)
_LOGGER = logging.getLogger(__name__)
ENTITY_ID_FORMAT = DOMAIN + ".{}"
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
_LOGGER = logging.getLogger(__name__)
DEVICE_CLASSES_SCHEMA: Final = vol.All(vol.Lower, vol.Coerce(NumberDeviceClass))
class NumberMode(StrEnum):
"""Modes for number entities."""
AUTO = "auto"
BOX = "box"
SLIDER = "slider"
SCAN_INTERVAL = timedelta(seconds=30)
__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

View File

@ -3,6 +3,8 @@ from __future__ import annotations
from typing import Final
import voluptuous as vol
from homeassistant.backports.enum import StrEnum
from homeassistant.const import (
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]] = {
NumberDeviceClass.APPARENT_POWER: set(UnitOfApparentPower),
NumberDeviceClass.AQI: {None},