Skip to content

Commit

Permalink
Merge pull request #103 from rmassch/feat/add-profile-change-action
Browse files Browse the repository at this point in the history
feat: add action to change room profile
  • Loading branch information
rmassch authored Nov 27, 2024
2 parents 8810eb5 + 292c91d commit 9b26050
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
22 changes: 20 additions & 2 deletions custom_components/healthbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .const import (
ALL_SERVICES,
DOMAIN,
SERVICE_CHANGE_ROOM_PROFILE,
SERVICE_CHANGE_ROOM_PROFILE_SCHEMA,
SERVICE_START_ROOM_BOOST,
SERVICE_START_ROOM_BOOST_SCHEMA,
SERVICE_STOP_ROOM_BOOST,
Expand Down Expand Up @@ -40,13 +42,28 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if api_key:
await api.async_enable_advanced_api_features()

coordinator = HealthboxDataUpdateCoordinator(hass=hass, entry=entry, api=api)
coordinator = HealthboxDataUpdateCoordinator(
hass=hass, entry=entry, api=api)
await coordinator.async_config_entry_first_refresh()

hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

# Define Services

async def change_room_profile(call: ServiceCall) -> None:
"""Service to change the HB3 Room Profile."""
device_id = call.data["device_id"]
device_registry = dr.async_get(hass)
device = device_registry.async_get(device_id)
if device:
device_identifier = next(iter(device.identifiers))[1]
room_id: int = int(device_identifier.split("_")[-1])
await coordinator.change_room_profile(
room_id=room_id,
profile_name=call.data["profile_name"]
)

async def start_room_boost(call: ServiceCall) -> None:
"""Service call to start boosting fans in a room."""
device_id = call.data["device_id"]
Expand Down Expand Up @@ -83,7 +100,8 @@ async def stop_room_boost(call: ServiceCall) -> None:
hass.services.async_register(
DOMAIN, SERVICE_STOP_ROOM_BOOST, stop_room_boost, SERVICE_STOP_ROOM_BOOST_SCHEMA
)

hass.services.async_register(DOMAIN, SERVICE_CHANGE_ROOM_PROFILE,
change_room_profile, SERVICE_CHANGE_ROOM_PROFILE_SCHEMA)
entry.async_on_unload(entry.add_update_listener(async_update_options))
return True

Expand Down
14 changes: 13 additions & 1 deletion custom_components/healthbox/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@

PLATFORMS = [Platform.SENSOR, Platform.BINARY_SENSOR]

SERVICE_CHANGE_ROOM_PROFILE = "change_room_profile"
SERVICE_CHANGE_ROOM_PROFILE_SCHEMA = vol.Schema(
{
vol.Required(cv.CONF_DEVICE_ID): cv.string,
vol.Required("profile_name"): cv.string
}
)

SERVICE_START_ROOM_BOOST = "start_room_boost"
SERVICE_START_ROOM_BOOST_SCHEMA = vol.Schema(
{
Expand All @@ -33,7 +41,11 @@
{vol.Required("device_id"): cv.string},
)

ALL_SERVICES = [SERVICE_START_ROOM_BOOST, SERVICE_STOP_ROOM_BOOST]
ALL_SERVICES = [
SERVICE_START_ROOM_BOOST,
SERVICE_STOP_ROOM_BOOST,
SERVICE_CHANGE_ROOM_PROFILE
]


class HealthboxRoomBoost:
Expand Down
15 changes: 8 additions & 7 deletions custom_components/healthbox/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def __init__(
update_interval=SCAN_INTERVAL,
)

async def change_room_profile(
self, room_id: int, profile_name: str
):
"""Start Boosting HB Room."""
await self.api.async_change_room_profile(
room_id=room_id, profile_name=profile_name
)

async def start_room_boost(
self, room_id: int, boost_level: int, boost_timeout: int
):
Expand All @@ -66,13 +74,6 @@ async def _async_update_data(self):
"""Update data via library."""
try:
await self.api.async_get_data()
# hb_data: HealthboxDataObject = HealthboxDataObject(data=data)
# for room in hb_data.rooms:
# boost_data = await self.api.async_get_room_boost_data(room.room_id)

# room.boost = HealthboxRoomBoost(
# boost_data["level"], boost_data["enable"], boost_data["remaining"]
# )

except Healthbox3ApiClientAuthenticationError as exception:
raise ConfigEntryAuthFailed(exception) from exception
Expand Down
2 changes: 1 addition & 1 deletion custom_components/healthbox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/rmassch/healthbox-hacs/issues",
"requirements": [
"pyhealthbox3==0.0.21"
"pyhealthbox3==0.0.22"
],
"ssdp": [],
"version": "0.0.1",
Expand Down
24 changes: 23 additions & 1 deletion custom_components/healthbox/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,26 @@ stop_room_boost:
selector:
device:
integration: healthbox
model: Healthbox Room
model: Healthbox Room
change_room_profile:
name: Change Room Profile
description: Change the Room Profile
fields:
device_id:
name: Room
description: Room
required: true
selector:
device:
integration: healthbox
model: Healthbox Room
profile_name:
name: Profile
description: Healthbox3 Profile
required: true
selector:
select:
options:
- "Eco"
- "Health"
- "Intense"

0 comments on commit 9b26050

Please sign in to comment.