Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/system state controls #63

Merged
merged 2 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion custom_components/saleryd_hrv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions custom_components/saleryd_hrv/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
49 changes: 49 additions & 0 deletions custom_components/saleryd_hrv/button.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 3 additions & 2 deletions custom_components/saleryd_hrv/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,8 +82,8 @@ class SystemActiveModeEnum(IntEnum):


class ModeEnum(IntEnum):
On = 1
Off = 0
On = 1


LOGGER: Logger = getLogger(__package__)
Expand Down
6 changes: 3 additions & 3 deletions custom_components/saleryd_hrv/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -108,4 +108,4 @@ async def async_setup_entry(
),
]

async_add_entities(entities)
async_add_entities(config_entities)
27 changes: 26 additions & 1 deletion custom_components/saleryd_hrv/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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)
Loading