Add mode to ESPHome numbers (#60653)

pull/60660/head
Jesse Hills 2021-12-01 08:19:14 +13:00 committed by GitHub
parent 11b81ef88b
commit 8630022e92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 6 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==10.5.0"], "requirements": ["aioesphomeapi==10.6.0"],
"zeroconf": ["_esphomelib._tcp.local."], "zeroconf": ["_esphomelib._tcp.local."],
"codeowners": ["@OttoWinter", "@jesserockz"], "codeowners": ["@OttoWinter", "@jesserockz"],
"after_dependencies": ["zeroconf", "tag"], "after_dependencies": ["zeroconf", "tag"],

View File

@ -3,14 +3,19 @@ from __future__ import annotations
import math import math
from aioesphomeapi import NumberInfo, NumberState from aioesphomeapi import NumberInfo, NumberMode as EsphomeNumberMode, NumberState
from homeassistant.components.number import NumberEntity from homeassistant.components.number import 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
from . import EsphomeEntity, esphome_state_property, platform_async_setup_entry from . import (
EsphomeEntity,
EsphomeEnumMapper,
esphome_state_property,
platform_async_setup_entry,
)
async def async_setup_entry( async def async_setup_entry(
@ -30,6 +35,15 @@ async def async_setup_entry(
) )
NUMBER_MODES: EsphomeEnumMapper[EsphomeNumberMode, NumberMode] = EsphomeEnumMapper(
{
EsphomeNumberMode.AUTO: NumberMode.AUTO,
EsphomeNumberMode.BOX: NumberMode.BOX,
EsphomeNumberMode.SLIDER: NumberMode.SLIDER,
}
)
# https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property # https://github.com/PyCQA/pylint/issues/3150 for all @esphome_state_property
# pylint: disable=invalid-overridden-method # pylint: disable=invalid-overridden-method
@ -57,6 +71,13 @@ class EsphomeNumber(EsphomeEntity[NumberInfo, NumberState], NumberEntity):
"""Return the unit of measurement.""" """Return the unit of measurement."""
return super()._static_info.unit_of_measurement return super()._static_info.unit_of_measurement
@property
def mode(self) -> NumberMode:
"""Return the mode of the entity."""
if self._static_info.mode:
return NUMBER_MODES.from_esphome(self._static_info.mode)
return NumberMode.AUTO
@esphome_state_property @esphome_state_property
def value(self) -> float | None: def value(self) -> float | None:
"""Return the state of the entity.""" """Return the state of the entity."""

View File

@ -161,7 +161,7 @@ aioeagle==1.1.0
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==10.5.0 aioesphomeapi==10.6.0
# homeassistant.components.flo # homeassistant.components.flo
aioflo==2021.11.0 aioflo==2021.11.0

View File

@ -112,7 +112,7 @@ aioeagle==1.1.0
aioemonitor==1.0.5 aioemonitor==1.0.5
# homeassistant.components.esphome # homeassistant.components.esphome
aioesphomeapi==10.5.0 aioesphomeapi==10.6.0
# homeassistant.components.flo # homeassistant.components.flo
aioflo==2021.11.0 aioflo==2021.11.0