Skip to content

Commit

Permalink
Renson number entity (#99358)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jimmyd-be authored Sep 10, 2023
1 parent 73a695d commit 6c45f43
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/renson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.FAN,
Platform.NUMBER,
Platform.SENSOR,
]

Expand Down
84 changes: 84 additions & 0 deletions homeassistant/components/renson/number.py
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions homeassistant/components/renson/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
}
},
"entity": {
"number": {
"filter_change": {
"name": "Filter clean/replacement"
}
},
"binary_sensor": {
"frost_protection_active": {
"name": "Frost protection active"
Expand Down

0 comments on commit 6c45f43

Please sign in to comment.