forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Renson button entity (home-assistant#99494)
Co-authored-by: Robert Resch <robert@resch.dev>
- Loading branch information
Showing
7 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters