-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add breeze switch to Renson integration (#101641)
* Add breeze switch * Cleanup code * Replace switch entity with new fan entity * Revert "Replace switch entity with new fan entity" This reverts commit 4fc1ac2.
- Loading branch information
jimmyd-be
committed
Feb 16, 2024
1 parent
d449ead
commit 6f74ea9
Showing
6 changed files
with
122 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
Platform.FAN, | ||
Platform.NUMBER, | ||
Platform.SENSOR, | ||
Platform.SWITCH, | ||
Platform.TIME, | ||
] | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
"""Breeze switch of the Renson ventilation unit.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any | ||
|
||
from renson_endura_delta.field_enum import CURRENT_LEVEL_FIELD, DataType | ||
from renson_endura_delta.renson import Level, RensonVentilation | ||
|
||
from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
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__) | ||
|
||
|
||
class RensonBreezeSwitch(RensonEntity, SwitchEntity): | ||
"""Provide the breeze switch.""" | ||
|
||
_attr_icon = "mdi:weather-dust" | ||
_attr_device_class = SwitchDeviceClass.SWITCH | ||
_attr_has_entity_name = True | ||
_attr_translation_key = "breeze" | ||
|
||
def __init__( | ||
self, | ||
api: RensonVentilation, | ||
coordinator: RensonCoordinator, | ||
) -> None: | ||
"""Initialize class.""" | ||
super().__init__("breeze", api, coordinator) | ||
|
||
self._attr_is_on = False | ||
|
||
async def async_turn_on(self, **kwargs: Any) -> None: | ||
"""Turn on the switch.""" | ||
_LOGGER.debug("Enable Breeze") | ||
|
||
await self.hass.async_add_executor_job(self.api.set_manual_level, Level.BREEZE) | ||
await self.coordinator.async_request_refresh() | ||
|
||
async def async_turn_off(self, **kwargs: Any) -> None: | ||
"""Turn off the switch.""" | ||
_LOGGER.debug("Disable Breeze") | ||
|
||
await self.hass.async_add_executor_job(self.api.set_manual_level, Level.OFF) | ||
await self.coordinator.async_request_refresh() | ||
|
||
@callback | ||
def _handle_coordinator_update(self) -> None: | ||
"""Handle updated data from the coordinator.""" | ||
|
||
level = self.api.parse_value( | ||
self.api.get_field_value(self.coordinator.data, CURRENT_LEVEL_FIELD.name), | ||
DataType.LEVEL, | ||
) | ||
|
||
self._attr_is_on = level == Level.BREEZE.value | ||
|
||
self.async_write_ha_state() | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Call the Renson integration to setup.""" | ||
|
||
api: RensonVentilation = hass.data[DOMAIN][config_entry.entry_id].api | ||
coordinator: RensonCoordinator = hass.data[DOMAIN][ | ||
config_entry.entry_id | ||
].coordinator | ||
|
||
async_add_entities([RensonBreezeSwitch(api, coordinator)]) |