From b376d311e8955eccfff980925c99bc7a08124203 Mon Sep 17 00:00:00 2001 From: Marc Date: Sat, 22 Jul 2023 09:02:03 +0200 Subject: [PATCH] Implement new service to set room volume without knowing its speaker group --- custom_components/teufel_raumfeld/__init__.py | 28 +++++++++++++------ custom_components/teufel_raumfeld/const.py | 8 +++--- .../teufel_raumfeld/services.yaml | 12 +++++++- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/custom_components/teufel_raumfeld/__init__.py b/custom_components/teufel_raumfeld/__init__.py index cb2c56a..d118d45 100644 --- a/custom_components/teufel_raumfeld/__init__.py +++ b/custom_components/teufel_raumfeld/__init__.py @@ -46,12 +46,12 @@ POSINF_ELEM_TRACK_DATA, POSINF_ELEM_URI, SERVICE_ADD_ROOM, - SERVICE_ADD_ROOM_PAR_MEMBER, - SERVICE_ADD_ROOM_PAR_ROOM, SERVICE_DROP_ROOM, - SERVICE_DROP_ROOM_PAR_MEMBER, - SERVICE_DROP_ROOM_PAR_ROOM, SERVICE_GROUP, + SERVICE_PAR_MEMBER, + SERVICE_PAR_ROOM, + SERVICE_PAR_VOLUME, + SERVICE_SET_ROOM_VOLUME, TIMEOUT_HOST_VALIDATION, TITLE_UNKNOWN, TRACKINF_ALBUM, @@ -206,16 +206,16 @@ async def async_handle_group(call): await raumfeld.async_create_group(room_lst) async def async_handle_add_room(call): - room = call.data.get(SERVICE_ADD_ROOM_PAR_ROOM) - room_of_group = call.data.get(SERVICE_ADD_ROOM_PAR_MEMBER) + room = call.data.get(SERVICE_PAR_ROOM) + room_of_group = call.data.get(SERVICE_PAR_MEMBER) room_groups = raumfeld.get_groups() for group in room_groups: if room_of_group in group: await raumfeld.async_add_room_to_group(room, group) async def async_handle_drop_room(call): - room = call.data.get(SERVICE_DROP_ROOM_PAR_ROOM) - room_of_group = call.data.get(SERVICE_DROP_ROOM_PAR_MEMBER) + room = call.data.get(SERVICE_PAR_ROOM) + room_of_group = call.data.get(SERVICE_PAR_MEMBER) if room_of_group is None: await raumfeld.async_drop_room_from_group(room) else: @@ -224,9 +224,21 @@ async def async_handle_drop_room(call): if room_of_group in group: await raumfeld.async_drop_room_from_group(room, group) + async def async_handle_set_room_volume(call): + room = call.data.get(SERVICE_PAR_ROOM) + volume = call.data.get(SERVICE_PAR_VOLUME) + room_groups = raumfeld.get_groups() + for group in room_groups: + if room in group: + rooms = [room] + await raumfeld.async_set_group_room_volume(group, volume, rooms) + hass.services.async_register(DOMAIN, SERVICE_GROUP, async_handle_group) hass.services.async_register(DOMAIN, SERVICE_ADD_ROOM, async_handle_add_room) hass.services.async_register(DOMAIN, SERVICE_DROP_ROOM, async_handle_drop_room) + hass.services.async_register( + DOMAIN, SERVICE_SET_ROOM_VOLUME, async_handle_set_room_volume + ) return True diff --git a/custom_components/teufel_raumfeld/const.py b/custom_components/teufel_raumfeld/const.py index f8f9c94..e47da2a 100644 --- a/custom_components/teufel_raumfeld/const.py +++ b/custom_components/teufel_raumfeld/const.py @@ -41,11 +41,11 @@ ROOM_PREFIX = "Room: " SERVICE_GROUP = "group" SERVICE_ADD_ROOM = "add_room" -SERVICE_ADD_ROOM_PAR_ROOM = "room" -SERVICE_ADD_ROOM_PAR_MEMBER = "room_of_group" +SERVICE_SET_ROOM_VOLUME = "set_room_volume" +SERVICE_PAR_ROOM = "room" +SERVICE_PAR_VOLUME = "volume" +SERVICE_PAR_MEMBER = "room_of_group" SERVICE_DROP_ROOM = "drop_room" -SERVICE_DROP_ROOM_PAR_ROOM = "room" -SERVICE_DROP_ROOM_PAR_MEMBER = "room_of_group" SERVICE_PLAY_SYSTEM_SOUND = "play_sound" SERVICE_RESTORE = "restore" SERVICE_SNAPSHOT = "snapshot" diff --git a/custom_components/teufel_raumfeld/services.yaml b/custom_components/teufel_raumfeld/services.yaml index ddc18bb..17f8afa 100644 --- a/custom_components/teufel_raumfeld/services.yaml +++ b/custom_components/teufel_raumfeld/services.yaml @@ -62,9 +62,19 @@ add_room: drop_room: description: Remove a room from a speaker group. fields: - room_name: + room: description: Name of the room to remove from a speaker group. example: "Movie room" room_of_group: description: Name of one room member of the speaker group. If provided, the room must be member of that group. example: "Movie room" + +set_room_volume: + description: Set volume of a room. + fields: + room: + description: Name of the room to remove from a speaker group. + example: "Movie room" + volume: + description: Name of one room member of the speaker group. If provided, the room must be member of that group. + example: "20"