mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Renson number entity (#99358)
* Starting number sensor * Filter change config * Add translation to number entity * add number entity to .coveragerc * Moved has_entity_name to description + changed name of entity * Add self.coordinator.async_request_refresh() after changing value * Add device calss and unit of measurement to number entity
This commit is contained in:
parent
73a695d857
commit
6c45f43c5d
@ -1011,6 +1011,7 @@ omit =
|
||||
homeassistant/components/renson/sensor.py
|
||||
homeassistant/components/renson/fan.py
|
||||
homeassistant/components/renson/binary_sensor.py
|
||||
homeassistant/components/renson/number.py
|
||||
homeassistant/components/raspyrfm/*
|
||||
homeassistant/components/recollect_waste/sensor.py
|
||||
homeassistant/components/recorder/repack.py
|
||||
|
@ -22,6 +22,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.FAN,
|
||||
Platform.NUMBER,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
|
84
homeassistant/components/renson/number.py
Normal file
84
homeassistant/components/renson/number.py
Normal file
@ -0,0 +1,84 @@
|
||||
"""Platform to control a Renson ventilation unit."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
from renson_endura_delta.field_enum import FILTER_PRESET_FIELD, DataType
|
||||
from renson_endura_delta.renson import RensonVentilation
|
||||
|
||||
from homeassistant.components.number import (
|
||||
NumberDeviceClass,
|
||||
NumberEntity,
|
||||
NumberEntityDescription,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import EntityCategory, UnitOfTime
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import RensonCoordinator
|
||||
from .const import DOMAIN
|
||||
from .entity import RensonEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
RENSON_NUMBER_DESCRIPTION = NumberEntityDescription(
|
||||
key="filter_change",
|
||||
translation_key="filter_change",
|
||||
icon="mdi:filter",
|
||||
native_step=1,
|
||||
native_min_value=0,
|
||||
native_max_value=360,
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
has_entity_name=True,
|
||||
device_class=NumberDeviceClass.DURATION,
|
||||
native_unit_of_measurement=UnitOfTime.DAYS,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the Renson number platform."""
|
||||
|
||||
api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api
|
||||
coordinator: RensonCoordinator = hass.data[DOMAIN][
|
||||
config_entry.entry_id
|
||||
].coordinator
|
||||
|
||||
async_add_entities([RensonNumber(RENSON_NUMBER_DESCRIPTION, api, coordinator)])
|
||||
|
||||
|
||||
class RensonNumber(RensonEntity, NumberEntity):
|
||||
"""Representation of the Renson number platform."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
description: NumberEntityDescription,
|
||||
api: RensonVentilation,
|
||||
coordinator: RensonCoordinator,
|
||||
) -> None:
|
||||
"""Initialize the Renson number."""
|
||||
super().__init__(description.key, api, coordinator)
|
||||
|
||||
self.entity_description = description
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self) -> None:
|
||||
"""Handle updated data from the coordinator."""
|
||||
self._attr_native_value = self.api.parse_value(
|
||||
self.api.get_field_value(self.coordinator.data, FILTER_PRESET_FIELD.name),
|
||||
DataType.NUMERIC,
|
||||
)
|
||||
|
||||
super()._handle_coordinator_update()
|
||||
|
||||
async def async_set_native_value(self, value: float) -> None:
|
||||
"""Update the current value."""
|
||||
|
||||
await self.hass.async_add_executor_job(self.api.set_filter_days, value)
|
||||
|
||||
await self.coordinator.async_request_refresh()
|
@ -13,6 +13,11 @@
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"number": {
|
||||
"filter_change": {
|
||||
"name": "Filter clean/replacement"
|
||||
}
|
||||
},
|
||||
"binary_sensor": {
|
||||
"frost_protection_active": {
|
||||
"name": "Frost protection active"
|
||||
|
Loading…
x
Reference in New Issue
Block a user