mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add Renson button entity (#99494)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
ab060b86d1
commit
e57156dd9c
@ -1020,6 +1020,7 @@ omit =
|
|||||||
homeassistant/components/renson/coordinator.py
|
homeassistant/components/renson/coordinator.py
|
||||||
homeassistant/components/renson/entity.py
|
homeassistant/components/renson/entity.py
|
||||||
homeassistant/components/renson/sensor.py
|
homeassistant/components/renson/sensor.py
|
||||||
|
homeassistant/components/renson/button.py
|
||||||
homeassistant/components/renson/fan.py
|
homeassistant/components/renson/fan.py
|
||||||
homeassistant/components/renson/binary_sensor.py
|
homeassistant/components/renson/binary_sensor.py
|
||||||
homeassistant/components/renson/number.py
|
homeassistant/components/renson/number.py
|
||||||
|
@ -15,6 +15,7 @@ from .coordinator import RensonCoordinator
|
|||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
|
Platform.BUTTON,
|
||||||
Platform.FAN,
|
Platform.FAN,
|
||||||
Platform.NUMBER,
|
Platform.NUMBER,
|
||||||
Platform.SENSOR,
|
Platform.SENSOR,
|
||||||
|
90
homeassistant/components/renson/button.py
Normal file
90
homeassistant/components/renson/button.py
Normal file
@ -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)
|
@ -5,5 +5,5 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/renson",
|
"documentation": "https://www.home-assistant.io/integrations/renson",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"requirements": ["renson-endura-delta==1.5.0"]
|
"requirements": ["renson-endura-delta==1.6.0"]
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
"button": {
|
||||||
|
"sync_time": {
|
||||||
|
"name": "Sync time with device"
|
||||||
|
}
|
||||||
|
},
|
||||||
"number": {
|
"number": {
|
||||||
"filter_change": {
|
"filter_change": {
|
||||||
"name": "Filter clean/replacement"
|
"name": "Filter clean/replacement"
|
||||||
|
@ -2301,7 +2301,7 @@ regenmaschine==2023.06.0
|
|||||||
renault-api==0.2.0
|
renault-api==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.renson
|
# homeassistant.components.renson
|
||||||
renson-endura-delta==1.5.0
|
renson-endura-delta==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.reolink
|
# homeassistant.components.reolink
|
||||||
reolink-aio==0.7.10
|
reolink-aio==0.7.10
|
||||||
|
@ -1703,7 +1703,7 @@ regenmaschine==2023.06.0
|
|||||||
renault-api==0.2.0
|
renault-api==0.2.0
|
||||||
|
|
||||||
# homeassistant.components.renson
|
# homeassistant.components.renson
|
||||||
renson-endura-delta==1.5.0
|
renson-endura-delta==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.reolink
|
# homeassistant.components.reolink
|
||||||
reolink-aio==0.7.10
|
reolink-aio==0.7.10
|
||||||
|
Loading…
x
Reference in New Issue
Block a user