From eabe8b9f1ff4a21b70cf0bbe163e0e5b824889f3 Mon Sep 17 00:00:00 2001 From: bj00rn Date: Tue, 3 Dec 2024 23:10:17 +0100 Subject: [PATCH 1/2] feat: add select for system state --- README.md | 10 +++++++-- custom_components/saleryd_hrv/__init__.py | 2 +- custom_components/saleryd_hrv/bridge.py | 9 ++++++-- custom_components/saleryd_hrv/const.py | 5 +++-- custom_components/saleryd_hrv/number.py | 6 ++--- custom_components/saleryd_hrv/select.py | 27 ++++++++++++++++++++++- 6 files changed, 48 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 93c6ac7..e9378a2 100644 --- a/README.md +++ b/README.md @@ -71,8 +71,9 @@ Name | Description Name | Description -- | -- -`ventilation_mode` | set ventilation mode normal/away/boost -`temperature_mode` | set temperature mode cool/normal/economy +`ventilation_mode` | set ventilation mode Normal/Away/Boost +`temperature_mode` | set temperature mode Cool/Normal/Economy +`system state` | set control system state on/off ### Number Name | Description @@ -81,6 +82,11 @@ Name | Description `economy temperature` | Economy temperature installer setting `normal temperature` | Normal temperature installer setting +### Button +Name | Description +-- | -- +`system reset` | Reset system warnings + ## Experimental features ### Sensors diff --git a/custom_components/saleryd_hrv/__init__.py b/custom_components/saleryd_hrv/__init__.py index b3d4c27..0293baa 100644 --- a/custom_components/saleryd_hrv/__init__.py +++ b/custom_components/saleryd_hrv/__init__.py @@ -113,7 +113,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: "SalerydLokeConfigEntry" raise ConfigEntryNotReady(f"Timeout while connecting to {url}:{port}") from ex else: coordinator = SalerydLokeDataUpdateCoordinator(hass, LOGGER) - bridge = SalerydLokeBridge(client, coordinator, LOGGER) + bridge = SalerydLokeBridge(entry, client, coordinator, LOGGER) entry.runtime_data = SalerydLokeData( client=client, coordinator=coordinator, diff --git a/custom_components/saleryd_hrv/bridge.py b/custom_components/saleryd_hrv/bridge.py index 3af9466..8c2868b 100644 --- a/custom_components/saleryd_hrv/bridge.py +++ b/custom_components/saleryd_hrv/bridge.py @@ -15,11 +15,16 @@ class SalerydLokeBridge: """Representation of bridge between client and coordinator""" def __init__( - self, client: "Client", coordinator: "SalerydLokeDataUpdateCoordinator", logger + self, + entry: "SalerydLokeConfigEntry", + client: "Client", + coordinator: "SalerydLokeDataUpdateCoordinator", + logger, ): self.client = client self.coordinator = coordinator self.logger = logger + self.entry = entry self.client.add_handler(self.update_data_callback) @@ -43,6 +48,6 @@ async def send(key, data): await self.client.send_command(key, data) if auth: - installer_password = self._entry.data.get(CONF_INSTALLER_PASSWORD) + installer_password = self.entry.data.get(CONF_INSTALLER_PASSWORD) await send(DataKeyEnum.INSTALLER_PASSWORD, installer_password) await send(key, data) diff --git a/custom_components/saleryd_hrv/const.py b/custom_components/saleryd_hrv/const.py index f5d80a9..cce6156 100644 --- a/custom_components/saleryd_hrv/const.py +++ b/custom_components/saleryd_hrv/const.py @@ -22,7 +22,8 @@ CLIMATE = "climate" SELECT = "select" NUMBER = "number" -PLATFORMS = [SENSOR, SWITCH, SELECT, NUMBER] +BUTTON = "button" +PLATFORMS = [SENSOR, SWITCH, SELECT, NUMBER, BUTTON] # Configuration and options @@ -81,8 +82,8 @@ class SystemActiveModeEnum(IntEnum): class ModeEnum(IntEnum): - On = 1 Off = 0 + On = 1 LOGGER: Logger = getLogger(__package__) diff --git a/custom_components/saleryd_hrv/number.py b/custom_components/saleryd_hrv/number.py index 163ad5c..5808d53 100644 --- a/custom_components/saleryd_hrv/number.py +++ b/custom_components/saleryd_hrv/number.py @@ -61,9 +61,9 @@ async def async_setup_entry( entry: "SalerydLokeConfigEntry", async_add_entities: "AddEntitiesCallback", ): + coordinator = entry.runtime_data.coordinator if entry.data.get(CONF_ENABLE_INSTALLER_SETTINGS): - coordinator = entry.runtime_data.coordinator - entities = [ + config_entities = [ SalerydLokeNumber( coordinator, entry, @@ -108,4 +108,4 @@ async def async_setup_entry( ), ] - async_add_entities(entities) + async_add_entities(config_entities) diff --git a/custom_components/saleryd_hrv/select.py b/custom_components/saleryd_hrv/select.py index 18d8c8c..bdedf14 100644 --- a/custom_components/saleryd_hrv/select.py +++ b/custom_components/saleryd_hrv/select.py @@ -2,11 +2,17 @@ from typing import TYPE_CHECKING from homeassistant.components.select import SelectEntity, SelectEntityDescription +from homeassistant.helpers.entity import EntityCategory from homeassistant.util import slugify from pysaleryd.const import DataKeyEnum from pysaleryd.utils import SystemProperty -from .const import TemperatureModeEnum, VentilationModeEnum +from .const import ( + CONF_ENABLE_INSTALLER_SETTINGS, + ModeEnum, + TemperatureModeEnum, + VentilationModeEnum, +) from .coordinator import SalerydLokeDataUpdateCoordinator from .entity import SalerydLokeEntity @@ -57,6 +63,10 @@ class SalerydLokeTemperatureModeSelect(SalerydLokeSelect): OPTION_ENUM = TemperatureModeEnum +class SalerydLokeSystemActiveModeSelect(SalerydLokeSelect): + OPTION_ENUM = ModeEnum + + async def async_setup_entry( hass: "HomeAssistant", entry: "SalerydLokeConfigEntry", @@ -82,3 +92,18 @@ async def async_setup_entry( ), ] async_add_entities(entites) + + if entry.data.get(CONF_ENABLE_INSTALLER_SETTINGS): + config_entities = [ + SalerydLokeSystemActiveModeSelect( + coordinator, + entry, + SelectEntityDescription( + key=DataKeyEnum.CONTROL_SYSTEM_STATE, + name="System active", + entity_category=EntityCategory.CONFIG, + icon="mdi:power", + ), + ) + ] + async_add_entities(config_entities) From 30ac5dd1b0c9a4e7383ed25e1e5db6611324e9e0 Mon Sep 17 00:00:00 2001 From: bj00rn Date: Tue, 3 Dec 2024 23:10:56 +0100 Subject: [PATCH 2/2] feat: add button to reset system warnings --- custom_components/saleryd_hrv/button.py | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 custom_components/saleryd_hrv/button.py diff --git a/custom_components/saleryd_hrv/button.py b/custom_components/saleryd_hrv/button.py new file mode 100644 index 0000000..8712380 --- /dev/null +++ b/custom_components/saleryd_hrv/button.py @@ -0,0 +1,49 @@ +from typing import TYPE_CHECKING + +from homeassistant.components.button import ButtonEntity, ButtonEntityDescription +from homeassistant.helpers.entity import EntityCategory +from homeassistant.util import slugify +from pysaleryd.const import DataKeyEnum + +from .const import CONF_ENABLE_INSTALLER_SETTINGS, SystemActiveModeEnum +from .entity import SaleryLokeVirtualEntity + +if TYPE_CHECKING: + from homeassistant.core import HomeAssistant + from homeassistant.helpers.entity_platform import AddEntitiesCallback + + from .data import SalerydLokeConfigEntry + + +class SalerydLokeButton(SaleryLokeVirtualEntity, ButtonEntity): + def __init__(self, entry: "SalerydLokeConfigEntry", entity_description): + self._entry = entry + self.entity_id = f"button.{entry.unique_id}_{slugify(entity_description.name)}" + super().__init__(entry, entity_description) + + +class SalerydLokeSystemResetButton(SalerydLokeButton): + async def async_press(self): + await self._entry.runtime_data.bridge.send_command( + DataKeyEnum.CONTROL_SYSTEM_STATE, SystemActiveModeEnum.Reset, True + ) + + +async def async_setup_entry( + hass: "HomeAssistant", + entry: "SalerydLokeConfigEntry", + async_add_entities: "AddEntitiesCallback", +): + if entry.data.get(CONF_ENABLE_INSTALLER_SETTINGS): + config_entities = [ + SalerydLokeSystemResetButton( + entry, + ButtonEntityDescription( + key=DataKeyEnum.CONTROL_SYSTEM_STATE, + name="System reset", + entity_category=EntityCategory.CONFIG, + icon="mdi:restart", + ), + ) + ] + async_add_entities(config_entities)