Skip to content

Commit

Permalink
Add Renson button entity (home-assistant#99494)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Resch <robert@resch.dev>
  • Loading branch information
jimmyd-be and edenhaus committed Sep 21, 2023
1 parent ab060b8 commit e57156d
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ omit =
homeassistant/components/renson/coordinator.py
homeassistant/components/renson/entity.py
homeassistant/components/renson/sensor.py
homeassistant/components/renson/button.py
homeassistant/components/renson/fan.py
homeassistant/components/renson/binary_sensor.py
homeassistant/components/renson/number.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 @@ -15,6 +15,7 @@

PLATFORMS = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.FAN,
Platform.NUMBER,
Platform.SENSOR,
Expand Down
90 changes: 90 additions & 0 deletions homeassistant/components/renson/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Renson ventilation unit buttons."""
from __future__ import annotations

from dataclasses import dataclass

from _collections_abc import Callable
from renson_endura_delta.renson import RensonVentilation

from homeassistant.components.button import (
ButtonDeviceClass,
ButtonEntity,
ButtonEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import EntityCategory
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import RensonCoordinator, RensonData
from .const import DOMAIN
from .entity import RensonEntity


@dataclass
class RensonButtonEntityDescriptionMixin:
"""Action function called on press."""

action_fn: Callable[[RensonVentilation], None]


@dataclass
class RensonButtonEntityDescription(
ButtonEntityDescription, RensonButtonEntityDescriptionMixin
):
"""Class describing Renson button entity."""


ENTITY_DESCRIPTIONS: tuple[RensonButtonEntityDescription, ...] = (
RensonButtonEntityDescription(
key="sync_time",
entity_category=EntityCategory.CONFIG,
translation_key="sync_time",
action_fn=lambda api: api.sync_time(),
),
RensonButtonEntityDescription(
key="restart",
device_class=ButtonDeviceClass.RESTART,
entity_category=EntityCategory.CONFIG,
action_fn=lambda api: api.restart_device(),
),
)


async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Renson button platform."""

data: RensonData = hass.data[DOMAIN][config_entry.entry_id]

entities = [
RensonButton(description, data.api, data.coordinator)
for description in ENTITY_DESCRIPTIONS
]

async_add_entities(entities)


class RensonButton(RensonEntity, ButtonEntity):
"""Representation of a Renson actions."""

_attr_has_entity_name = True
entity_description: RensonButtonEntityDescription

def __init__(
self,
description: RensonButtonEntityDescription,
api: RensonVentilation,
coordinator: RensonCoordinator,
) -> None:
"""Initialize class."""
super().__init__(description.key, api, coordinator)

self.entity_description = description

def press(self) -> None:
"""Triggers the action."""
self.entity_description.action_fn(self.api)
2 changes: 1 addition & 1 deletion homeassistant/components/renson/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/renson",
"iot_class": "local_polling",
"requirements": ["renson-endura-delta==1.5.0"]
"requirements": ["renson-endura-delta==1.6.0"]
}
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": {
"button": {
"sync_time": {
"name": "Sync time with device"
}
},
"number": {
"filter_change": {
"name": "Filter clean/replacement"
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ regenmaschine==2023.06.0
renault-api==0.2.0

# homeassistant.components.renson
renson-endura-delta==1.5.0
renson-endura-delta==1.6.0

# homeassistant.components.reolink
reolink-aio==0.7.10
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@ regenmaschine==2023.06.0
renault-api==0.2.0

# homeassistant.components.renson
renson-endura-delta==1.5.0
renson-endura-delta==1.6.0

# homeassistant.components.reolink
reolink-aio==0.7.10
Expand Down

0 comments on commit e57156d

Please sign in to comment.