mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add number platform to ecoforest (#100694)
* add power number entity to ecoforest integration * fix number.py header * minor fixes * change power to power level * update comment for native value prop Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * exclude number.py from coverage --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
parent
5cf5f5b4cf
commit
cd30286913
@ -262,6 +262,7 @@ omit =
|
|||||||
homeassistant/components/ecoforest/__init__.py
|
homeassistant/components/ecoforest/__init__.py
|
||||||
homeassistant/components/ecoforest/coordinator.py
|
homeassistant/components/ecoforest/coordinator.py
|
||||||
homeassistant/components/ecoforest/entity.py
|
homeassistant/components/ecoforest/entity.py
|
||||||
|
homeassistant/components/ecoforest/number.py
|
||||||
homeassistant/components/ecoforest/sensor.py
|
homeassistant/components/ecoforest/sensor.py
|
||||||
homeassistant/components/econet/__init__.py
|
homeassistant/components/econet/__init__.py
|
||||||
homeassistant/components/econet/binary_sensor.py
|
homeassistant/components/econet/binary_sensor.py
|
||||||
|
@ -18,7 +18,7 @@ from homeassistant.exceptions import ConfigEntryNotReady
|
|||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import EcoforestCoordinator
|
from .coordinator import EcoforestCoordinator
|
||||||
|
|
||||||
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
PLATFORMS: list[Platform] = [Platform.SENSOR, Platform.NUMBER]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
74
homeassistant/components/ecoforest/number.py
Normal file
74
homeassistant/components/ecoforest/number.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
"""Support for Ecoforest number platform."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
from pyecoforest.models.device import Device
|
||||||
|
|
||||||
|
from homeassistant.components.number import NumberEntity, NumberEntityDescription
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
|
from .const import DOMAIN
|
||||||
|
from .coordinator import EcoforestCoordinator
|
||||||
|
from .entity import EcoforestEntity
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EcoforestRequiredKeysMixin:
|
||||||
|
"""Mixin for required keys."""
|
||||||
|
|
||||||
|
value_fn: Callable[[Device], float | None]
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class EcoforestNumberEntityDescription(
|
||||||
|
NumberEntityDescription, EcoforestRequiredKeysMixin
|
||||||
|
):
|
||||||
|
"""Describes an ecoforest number entity."""
|
||||||
|
|
||||||
|
|
||||||
|
NUMBER_ENTITIES = (
|
||||||
|
EcoforestNumberEntityDescription(
|
||||||
|
key="power_level",
|
||||||
|
translation_key="power_level",
|
||||||
|
native_min_value=1,
|
||||||
|
native_max_value=9,
|
||||||
|
native_step=1,
|
||||||
|
value_fn=lambda data: data.power,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: ConfigEntry,
|
||||||
|
async_add_entities: AddEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up Ecoforest number platform."""
|
||||||
|
coordinator: EcoforestCoordinator = hass.data[DOMAIN][config_entry.entry_id]
|
||||||
|
|
||||||
|
entities = [
|
||||||
|
EcoforestNumberEntity(coordinator, description)
|
||||||
|
for description in NUMBER_ENTITIES
|
||||||
|
]
|
||||||
|
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class EcoforestNumberEntity(EcoforestEntity, NumberEntity):
|
||||||
|
"""Representation of an Ecoforest number entity."""
|
||||||
|
|
||||||
|
entity_description: EcoforestNumberEntityDescription
|
||||||
|
|
||||||
|
@property
|
||||||
|
def native_value(self) -> float | None:
|
||||||
|
"""Return the state of the entity."""
|
||||||
|
return self.entity_description.value_fn(self.data)
|
||||||
|
|
||||||
|
async def async_set_native_value(self, value: float) -> None:
|
||||||
|
"""Update the native value."""
|
||||||
|
await self.coordinator.api.set_power(int(value))
|
||||||
|
await self.coordinator.async_request_refresh()
|
@ -17,5 +17,12 @@
|
|||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"number": {
|
||||||
|
"power_level": {
|
||||||
|
"name": "Power level"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user