diff --git a/custom_components/healthbox/__init__.py b/custom_components/healthbox/__init__.py index 6a63003..2dbed22 100644 --- a/custom_components/healthbox/__init__.py +++ b/custom_components/healthbox/__init__.py @@ -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, @@ -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"] @@ -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 diff --git a/custom_components/healthbox/const.py b/custom_components/healthbox/const.py index d89c756..0437382 100644 --- a/custom_components/healthbox/const.py +++ b/custom_components/healthbox/const.py @@ -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( { @@ -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: diff --git a/custom_components/healthbox/coordinator.py b/custom_components/healthbox/coordinator.py index 1513bc4..47bf304 100644 --- a/custom_components/healthbox/coordinator.py +++ b/custom_components/healthbox/coordinator.py @@ -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 ): @@ -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 diff --git a/custom_components/healthbox/manifest.json b/custom_components/healthbox/manifest.json index a5e79e5..6ed851a 100644 --- a/custom_components/healthbox/manifest.json +++ b/custom_components/healthbox/manifest.json @@ -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", diff --git a/custom_components/healthbox/services.yaml b/custom_components/healthbox/services.yaml index 6afa1c7..6798110 100644 --- a/custom_components/healthbox/services.yaml +++ b/custom_components/healthbox/services.yaml @@ -43,4 +43,26 @@ stop_room_boost: selector: device: integration: healthbox - model: Healthbox Room \ No newline at end of file + 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" \ No newline at end of file