Skip to content

Commit

Permalink
Implement new service to set room volume without knowing its speaker …
Browse files Browse the repository at this point in the history
…group
  • Loading branch information
Marc committed Jul 22, 2023
1 parent a3ce258 commit b376d31
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
28 changes: 20 additions & 8 deletions custom_components/teufel_raumfeld/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions custom_components/teufel_raumfeld/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion custom_components/teufel_raumfeld/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit b376d31

Please sign in to comment.