Add number device class support to ESPHome (#82277)

This commit is contained in:
Franck Nijhof 2022-11-17 21:12:45 +01:00 committed by GitHub
parent b717da879f
commit a07117470e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 4 deletions

View File

@ -3,7 +3,7 @@
"name": "ESPHome", "name": "ESPHome",
"config_flow": true, "config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/esphome", "documentation": "https://www.home-assistant.io/integrations/esphome",
"requirements": ["aioesphomeapi==11.4.3"], "requirements": ["aioesphomeapi==11.5.0"],
"zeroconf": ["_esphomelib._tcp.local."], "zeroconf": ["_esphomelib._tcp.local."],
"dhcp": [{ "registered_devices": true }], "dhcp": [{ "registered_devices": true }],
"codeowners": ["@OttoWinter", "@jesserockz"], "codeowners": ["@OttoWinter", "@jesserockz"],

View File

@ -1,11 +1,12 @@
"""Support for esphome numbers.""" """Support for esphome numbers."""
from __future__ import annotations from __future__ import annotations
from contextlib import suppress
import math import math
from aioesphomeapi import NumberInfo, NumberMode as EsphomeNumberMode, NumberState from aioesphomeapi import NumberInfo, NumberMode as EsphomeNumberMode, NumberState
from homeassistant.components.number import NumberEntity, NumberMode from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -47,6 +48,13 @@ NUMBER_MODES: EsphomeEnumMapper[EsphomeNumberMode, NumberMode] = EsphomeEnumMapp
class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity): class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
"""A number implementation for esphome.""" """A number implementation for esphome."""
@property
def device_class(self) -> NumberDeviceClass | None:
"""Return the class of this entity."""
with suppress(ValueError):
return NumberDeviceClass(self._static_info.device_class)
return None
@property @property
def native_min_value(self) -> float: def native_min_value(self) -> float:
"""Return the minimum value.""" """Return the minimum value."""

View File

@ -156,7 +156,7 @@ aioecowitt==2022.09.3
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==11.4.3 aioesphomeapi==11.5.0
# homeassistant.components.flo # homeassistant.components.flo
aioflo==2021.11.0 aioflo==2021.11.0

View File

@ -143,7 +143,7 @@ aioecowitt==2022.09.3
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==11.4.3 aioesphomeapi==11.5.0
# homeassistant.components.flo # homeassistant.components.flo
aioflo==2021.11.0 aioflo==2021.11.0