diff --git a/wallmote.py b/wallmote.py index 0929c6d..b96ee0e 100644 --- a/wallmote.py +++ b/wallmote.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 import hassapi as hass +import inspect from threading import Timer ############### @@ -9,16 +10,16 @@ from threading import Timer """ 1: States 1: Lights - 1: Kitchen Lights + 1: Kitchen Lights (Toggle) 1: Off 2: 10% 3: 55% 4: 100% - 2: Main Room Lights + 2: Main Room Lights (Toggle) [...] - 3: Living Room Lights + 3: Living Room Lights (Toggle) [...] - 4: Bedroom Lights + 4: Bedroom Lights (Toggle) [...] 2: A/C 2: Main Room AC @@ -55,206 +56,447 @@ from threading import Timer [...] 4: Bedroom Fan [...] -2: Miscellaneous - 1: Effects - 1: Clear light RGB strip notifications - 2: Music - 1: Join/unjoin speakers - 1. Unjoin speakers - # Select master - 3. Living Room Sonos - 4. Bedroom Sonos - 2: Play Music - 3: Play on Living Room Sonos - 1: Spotify: Liked Songs - 2: Spotify: Getting Things Done - 4: Play on Bedroom Sonos - 1: Spotify: Liked Songs - 2: Spotify: Chill Sleep - 3: Media Controls - 3: Living Room Sonos - 1. Play - 2. Pause - 3. Previous - 4. Next - 4: Bedroom Sonos - [...] - 4. Volume: TODO - 3: Living Room Sonos - 4: Bedroom Sonos -3: Reserved -4: Configuration +2: Music + 1: Join/unjoin speakers + 1. Unjoin speakers + # Select master + 3. Living Room Sonos + 4. Bedroom Sonos + 2: Play Music + 3: Play on Living Room Sonos + 1: Spotify: Liked Songs + 2: Spotify: Getting Things Done + 4: Play on Bedroom Sonos + 1: Spotify: Liked Songs + 2: Spotify: Chill Sleep + 3: Media Controls + 3: Living Room Sonos + 1. Pause + 2. Play + 3. Previous + 4. Next + 4: Bedroom Sonos + [...] + 4. Options: + 3: Living Room Sonos + 2: Crossfade + 1: Off + 2: On + 3: Shuffle + 1: Off + 2: On + 4: Repeat + 1: Off + 2: On + 4: Bedroom Sonos + [...] """ tree = { - 1: { # States + 1: { # State 1: { # Lights 1: { # Kitchen - 1: { "function": lambda hass: set_brightness(hass,"light.kitchen_lights",0) }, - 2: { "function": lambda hass: set_brightness(hass,"light.kitchen_lights",10) }, - 3: { "function": lambda hass: set_brightness(hass,"light.kitchen_lights",55) }, - 4: { "function": lambda hass: set_brightness(hass,"light.kitchen_lights",100) } + "function": lambda hass: hass.call_service("light/toggle",entity_id="light.kitchen_lights"), + "description": "Kitchen Lights: Toggle", + 1: { + "function": lambda hass: set_brightness(hass,"light.kitchen_lights",0), + "description": "Kitchen Lights: 0%" + }, + 2: { + "function": lambda hass: set_brightness(hass,"light.kitchen_lights",10), + "description": "Kitchen Lights: 10%" + }, + 3: { + "function": lambda hass: set_brightness(hass,"light.kitchen_lights",55), + "description": "Kitchen Lights: 55%" + }, + 4: { + "function": lambda hass: set_brightness(hass,"light.kitchen_lights",100), + "description": "Kitchen Lights: 100%" + } }, 2: { # Main Room - 1: { "function": lambda hass: set_brightness(hass,"light.mainroom_lights",0) }, - 2: { "function": lambda hass: set_brightness(hass,"light.mainroom_lights",10) }, - 3: { "function": lambda hass: set_brightness(hass,"light.mainroom_lights",55) }, - 4: { "function": lambda hass: set_brightness(hass,"light.mainroom_lights",100) } + "function": lambda hass: hass.call_service("light/toggle",entity_id="light.mainroom_lights"), + "description": "Main Room Lights: Toggle", + 1: { + "function": lambda hass: set_brightness(hass,"light.mainroom_lights",0), + "description": "Main Room Lights: 0%" + }, + 2: { + "function": lambda hass: set_brightness(hass,"light.mainroom_lights",10), + "description": "Main Room Lights: 10%" + }, + 3: { + "function": lambda hass: set_brightness(hass,"light.mainroom_lights",55), + "description": "Main Room Lights: 55%" + }, + 4: { + "function": lambda hass: set_brightness(hass,"light.mainroom_lights",100), + "description": "Main Room Lights: 100%" + } }, 3: { # Living Room - 1: { "function": lambda hass: set_brightness(hass,"light.livingroom_lights",0) }, - 2: { "function": lambda hass: set_brightness(hass,"light.livingroom_lights",10) }, - 3: { "function": lambda hass: set_brightness(hass,"light.livingroom_lights",55) }, - 4: { "function": lambda hass: set_brightness(hass,"light.livingroom_lights",100) } + "function": lambda hass: hass.call_service("light/toggle",entity_id="light.livingroom_lights"), + "description": "Living Room Lights: Toggle", + 1: { + "function": lambda hass: set_brightness(hass,"light.livingroom_lights",0), + "description": "Living Room Lights: 0%" + }, + 2: { + "function": lambda hass: set_brightness(hass,"light.livingroom_lights",10), + "description": "Living Room Lights: 10%" + }, + 3: { + "function": lambda hass: set_brightness(hass,"light.livingroom_lights",55), + "description": "Living Room Lights: 55%" + }, + 4: { + "function": lambda hass: set_brightness(hass,"light.livingroom_lights",100), + "description": "Living Room Lights: 100%" + } }, 4: { # Bedroom - 1: { "function": lambda hass: set_brightness(hass,"light.bedroom_lights",0) }, - 2: { "function": lambda hass: set_brightness(hass,"light.bedroom_lights",10) }, - 3: { "function": lambda hass: set_brightness(hass,"light.bedroom_lights",55) }, - 4: { "function": lambda hass: set_brightness(hass,"light.bedroom_lights",100) } + "function": lambda hass: hass.call_service("light/toggle",entity_id="light.bedroom_lights"), + "description": "Bedroom Lights: Toggle", + 1: { + "function": lambda hass: set_brightness(hass,"light.bedroom_lights",0), + "description": "Bedroom Lights: 0%" + }, + 2: { + "function": lambda hass: set_brightness(hass,"light.bedroom_lights",10), + "description": "Bedroom Lights: 10%" + }, + 3: { + "function": lambda hass: set_brightness(hass,"light.bedroom_lights",55), + "description": "Bedroom Lights: 55%" + }, + 4: { + "function": lambda hass: set_brightness(hass,"light.bedroom_lights",100), + "description": "Bedroom Lights: 100%" + } } }, 2: { # A/C 2: { # Main Room 1: { # Power - 1: { "function": lambda hass: hass.turn_on("climate.mainroom_ac") }, - 2: { "function": lambda hass: hass.turn_on("climate.mainroom_ac") }, - 3: { "function": lambda hass: hass.turn_off("climate.mainroom_ac") }, - 4: { "function": lambda hass: hass.turn_off("climate.mainroom_ac") }, + 1: { + "function": lambda hass: hass.turn_on("climate.mainroom_ac"), + "description": "Main Room A/C Power: On" + }, + 2: { + "function": lambda hass: hass.turn_on("climate.mainroom_ac"), + "description": "Main Room A/C Power: On" + }, + 3: { + "function": lambda hass: hass.turn_off("climate.mainroom_ac"), + "description": "Main Room A/C Power: Off" + }, + 4: { + "function": lambda hass: hass.turn_off("climate.mainroom_ac"), + "description": "Main Room A/C Power: Off" + }, }, 2: { # Mode - 1: { "function": lambda hass: gree_set_mode(hass,"mainroom_ac","cool") }, - 2: { "function": lambda hass: gree_set_mode(hass,"mainroom_ac","heat") }, - 3: { "function": lambda hass: gree_set_mode(hass,"mainroom_ac","fan_only") } + 1: { + "function": lambda hass: gree_set_mode(hass,"mainroom_ac","cool"), + "description": "Main Room A/C Mode: Cool" + }, + 2: { + "function": lambda hass: gree_set_mode(hass,"mainroom_ac","heat"), + "description": "Main Room A/C Mode: Heat" + }, + 3: { + "function": lambda hass: gree_set_mode(hass,"mainroom_ac","fan_only"), + "description": "Main Room A/C Mode: Fan" + } }, 3: { # Fan Level - 1: { "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","auto") }, - 2: { "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","quiet") }, - 3: { "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","medium") }, - 4: { "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","high") } + 1: { + "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","auto"), + "description": "Main Room A/C Fan Level: Auto" + }, + 2: { + "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","quiet"), + "description": "Main Room A/C Fan Level: Quiet" + }, + 3: { + "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","medium"), + "description": "Main Room A/C Fan Level: Medium" + }, + 4: { + "function": lambda hass: gree_set_fan_level(hass,"mainroom_ac","high"), + "description": "Main Room A/C Fan Level: High" + } }, 4: { # Temperature - 1: { "function": lambda hass: set_temperature(hass,"mainroom_ac",72) }, - 2: { "function": lambda hass: set_temperature(hass,"mainroom_ac",74) }, - 3: { "function": lambda hass: set_temperature(hass,"mainroom_ac",76) }, - 4: { "function": lambda hass: set_temperature(hass,"mainroom_ac",78) } + 1: { + "function": lambda hass: set_temperature(hass,"mainroom_ac",72), + "description": "Main Room A/C Temperature: 72" + }, + 2: { + "function": lambda hass: set_temperature(hass,"mainroom_ac",74), + "description": "Main Room A/C Temperature: 74" + }, + 3: { + "function": lambda hass: set_temperature(hass,"mainroom_ac",76), + "description": "Main Room A/C Temperature: 76" + }, + 4: { + "function": lambda hass: set_temperature(hass,"mainroom_ac",78), + "description": "Main Room A/C Temperature: 78" + } } }, 3: { # Living Room 1: { # Power - 1: { "function": lambda hass: hass.turn_on("climate.livingroom_ac") }, - 2: { "function": lambda hass: hass.turn_on("climate.livingroom_ac") }, - 3: { "function": lambda hass: hass.turn_off("climate.livingroom_ac") }, - 4: { "function": lambda hass: hass.turn_off("climate.livingroom_ac") }, + 1: { + "function": lambda hass: hass.turn_on("climate.livingroom_ac"), + "description": "Living Room A/C Power: On" + }, + 2: { + "function": lambda hass: hass.turn_on("climate.livingroom_ac"), + "description": "Living Room A/C Power: On" + }, + 3: { + "function": lambda hass: hass.turn_off("climate.livingroom_ac"), + "description": "Living Room A/C Power: Off" + }, + 4: { + "function": lambda hass: hass.turn_off("climate.livingroom_ac"), + "description": "Living Room A/C Power: Off" + }, }, 2: { # Mode - 1: { "function": lambda hass: gree_set_mode(hass,"livingroom_ac","cool") }, - 2: { "function": lambda hass: gree_set_mode(hass,"livingroom_ac","heat") }, - 3: { "function": lambda hass: gree_set_mode(hass,"livingroom_ac","fan_only") } + 1: { + "function": lambda hass: gree_set_mode(hass,"livingroom_ac","cool"), + "description": "Living Room A/C Mode: Cool" + }, + 2: { + "function": lambda hass: gree_set_mode(hass,"livingroom_ac","heat"), + "description": "Living Room A/C Mode: Heat" + }, + 3: { + "function": lambda hass: gree_set_mode(hass,"livingroom_ac","fan_only"), + "description": "Living Room A/C Mode: Fan" + } }, 3: { # Fan Level - 1: { "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","auto") }, - 2: { "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","quiet") }, - 3: { "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","medium") }, - 4: { "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","high") } + 1: { + "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","auto"), + "description": "Living Room A/C Fan Level: Auto" + }, + 2: { + "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","quiet"), + "description": "Living Room A/C Fan Level: Quiet" + }, + 3: { + "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","medium"), + "description": "Living Room A/C Fan Level: Medium" + }, + 4: { + "function": lambda hass: gree_set_fan_level(hass,"livingroom_ac","high"), + "description": "Living Room A/C Fan Level: High" + } }, 4: { # Temperature - 1: { "function": lambda hass: set_temperature(hass,"livingroom_ac",72) }, - 2: { "function": lambda hass: set_temperature(hass,"livingroom_ac",74) }, - 3: { "function": lambda hass: set_temperature(hass,"livingroom_ac",76) }, - 4: { "function": lambda hass: set_temperature(hass,"livingroom_ac",78) } + 1: { + "function": lambda hass: set_temperature(hass,"livingroom_ac",72), + "description": "Living Room A/C Temperature: 72" + }, + 2: { + "function": lambda hass: set_temperature(hass,"livingroom_ac",74), + "description": "Living Room A/C Temperature: 74" + }, + 3: { + "function": lambda hass: set_temperature(hass,"livingroom_ac",76), + "description": "Living Room A/C Temperature: 76" + }, + 4: { + "function": lambda hass: set_temperature(hass,"livingroom_ac",78), + "description": "Living Room A/C Temperature: 78" + } } }, 4: { # Bedroom 1: { # Power - 1: { "function": lambda hass: hass.turn_on("climate.bedroom_ac") }, - 2: { "function": lambda hass: hass.turn_on("climate.bedroom_ac") }, - 3: { "function": lambda hass: hass.turn_off("climate.bedroom_ac") }, - 4: { "function": lambda hass: hass.turn_off("climate.bedroom_ac") }, + 1: { + "function": lambda hass: hass.turn_on("climate.bedroom_ac"), + "description": "Bedroom A/C Power: On" + }, + 2: { + "function": lambda hass: hass.turn_on("climate.bedroom_ac"), + "description": "Bedroom A/C Power: On" + }, + 3: { + "function": lambda hass: hass.turn_off("climate.bedroom_ac"), + "description": "Bedroom A/C Power: Off" + }, + 4: { + "function": lambda hass: hass.turn_off("climate.bedroom_ac"), + "description": "Bedroom A/C Power: Off" + }, }, 2: { # Mode - 1: { "function": lambda hass: gree_set_mode(hass,"bedroom_ac","cool") }, - 2: { "function": lambda hass: gree_set_mode(hass,"bedroom_ac","heat") }, - 3: { "function": lambda hass: gree_set_mode(hass,"bedroom_ac","fan_only") } + 1: { + "function": lambda hass: gree_set_mode(hass,"bedroom_ac","cool"), + "description": "Bedroom A/C Mode: Cool" + }, + 2: { + "function": lambda hass: gree_set_mode(hass,"bedroom_ac","heat"), + "description": "Bedroom A/C Mode: Heat" + }, + 3: { + "function": lambda hass: gree_set_mode(hass,"bedroom_ac","fan_only"), + "description": "Bedroom A/C Mode: Fan" + } }, 3: { # Fan Level - 1: { "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","auto") }, - 2: { "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","quiet") }, - 3: { "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","medium") }, - 4: { "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","high") } + 1: { + "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","auto"), + "description": "Bedroom A/C Fan Level: Auto" + }, + 2: { + "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","quiet"), + "description": "Bedroom A/C Fan Level: Quiet" + }, + 3: { + "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","medium"), + "description": "Bedroom A/C Fan Level: Medium" + }, + 4: { + "function": lambda hass: gree_set_fan_level(hass,"bedroom_ac","high"), + "description": "Bedroom A/C Fan Level: High" + } }, 4: { # Temperature - 1: { "function": lambda hass: set_temperature(hass,"bedroom_ac",72) }, - 2: { "function": lambda hass: set_temperature(hass,"bedroom_ac",74) }, - 3: { "function": lambda hass: set_temperature(hass,"bedroom_ac",76) }, - 4: { "function": lambda hass: set_temperature(hass,"bedroom_ac",78) } + 1: { + "function": lambda hass: set_temperature(hass,"bedroom_ac",72), + "description": "Bedroom A/C Temperature: 72" + }, + 2: { + "function": lambda hass: set_temperature(hass,"bedroom_ac",74), + "description": "Bedroom A/C Temperature: 74" + }, + 3: { + "function": lambda hass: set_temperature(hass,"bedroom_ac",76), + "description": "Bedroom A/C Temperature: 76" + }, + 4: { + "function": lambda hass: set_temperature(hass,"bedroom_ac",78), + "description": "Bedroom A/C Temperature: 78" + } } } }, 3: { # Fans 1: { # Kitchen - 1: { "function": lambda hass: hass.set_value("input_number.kitchen_fan",0) }, - 2: { "function": lambda hass: hass.set_value("input_number.kitchen_fan",1) }, - 3: { "function": lambda hass: hass.set_value("input_number.kitchen_fan",2) }, - 4: { "function": lambda hass: hass.set_value("input_number.kitchen_fan",3) } + 1: {"function": lambda hass: hass.set_value("input_number.kitchen_fan",0)}, + 2: {"function": lambda hass: hass.set_value("input_number.kitchen_fan",1)}, + 3: {"function": lambda hass: hass.set_value("input_number.kitchen_fan",2)}, + 4: {"function": lambda hass: hass.set_value("input_number.kitchen_fan",3)} }, 3: { # Living Room - 1: { "function": lambda hass: hass.set_value("input_number.livingroom_fan",0) }, - 2: { "function": lambda hass: hass.set_value("input_number.livingroom_fan",1) }, - 3: { "function": lambda hass: hass.set_value("input_number.livingroom_fan",2) }, - 4: { "function": lambda hass: hass.set_value("input_number.livingroom_fan",3) } + 1: {"function": lambda hass: hass.set_value("input_number.livingroom_fan",0)}, + 2: {"function": lambda hass: hass.set_value("input_number.livingroom_fan",1)}, + 3: {"function": lambda hass: hass.set_value("input_number.livingroom_fan",2)}, + 4: {"function": lambda hass: hass.set_value("input_number.livingroom_fan",3)} }, 4: { # Bedroom - 1: { "function": lambda hass: hass.set_value("input_number.bedroom_fan",0) }, - 2: { "function": lambda hass: hass.set_value("input_number.bedroom_fan",1) }, - 3: { "function": lambda hass: hass.set_value("input_number.bedroom_fan",2) }, - 4: { "function": lambda hass: hass.set_value("input_number.bedroom_fan",3) } + 1: {"function": lambda hass: hass.set_value("input_number.bedroom_fan",0)}, + 2: {"function": lambda hass: hass.set_value("input_number.bedroom_fan",1)}, + 3: {"function": lambda hass: hass.set_value("input_number.bedroom_fan",2)}, + 4: {"function": lambda hass: hass.set_value("input_number.bedroom_fan",3)} } } }, - 2: { # Miscellaneous - 1: { # Effects - 1: { "service": "script/clear_lightswitch_leds" } + 2: { # Music + 1: { # Join/unjoin + 1: {"function": lambda hass: hass.call_service("sonos/unjoin", + entity_id=["media_player.livingroom_sonos","media_player.bedroom_sonos"])}, + 3: {"function": lambda hass: hass.call_service("sonos/join", + master="media_player.livingroom_sonos",entity_id="media_player.bedroom_sonos")}, + 4: {"function": lambda hass: hass.call_service("sonos/join", + master="media_player.livingroom_sonos",entity_id="media_player.bedroom_sonos")}, }, - 2: { # Music - 1: { # Join/unjoin - 1: { "function": lambda hass: hass.call_service("sonos/unjoin", - entity_id=["media_player.livingroom_sonos","media_player.bedroom_sonos"]) }, - 3: { "function": lambda hass: hass.call_service("sonos/join", - master="media_player.livingroom_sonos",entity_id="media_player.bedroom_sonos")}, - 4: { "function": lambda hass: hass.call_service("sonos/join", - master="media_player.livingroom_sonos",entity_id="media_player.bedroom_sonos")}, + 2: { # Play Music + 3: { # Living Room Sonos + 1: {"function": lambda hass: select_source(hass,"media_player.livingroom_sonos","Songs")}, + 2: {"function": lambda hass: select_source(hass,"media_player.livingroom_sonos","Getting Things Done")} }, - 2: { # Play Music - 3: { # Living Room Sonos - 1: { "function": lambda hass: select_source(hass,"media_player.livingroom_sonos","Songs") }, - 2: { "function": lambda hass: select_source(hass,"media_player.livingroom_sonos","Getting Things Done") } + 4: { # Bedroom Sonos + 1: {"function": lambda hass: select_source(hass,"media_player.bedroom_sonos","Songs")}, + 2: {"function": lambda hass: select_source(hass,"media_player.bedroom_sonos","Chill sleep")} + } + }, + 3: { # Media Controls + 3: { # Living Room Sonos + 1: {"function": lambda hass: hass.call_service("media_player/media_pause", + entity_id="media_player.livingroom_sonos")}, + 2: {"function": lambda hass: hass.call_service("media_player/media_play", + entity_id="media_player.livingroom_sonos")}, + 3: {"function": lambda hass: hass.call_service("media_player/media_previous_track", + entity_id="media_player.livingroom_sonos")}, + 4: {"function": lambda hass: hass.call_service("media_player/media_next_track", + entity_id="media_player.livingroom_sonos")} + }, + 4: { # Bedroom Sonos + 1: {"function": lambda hass: hass.call_service("media_player/media_pause", + entity_id="media_player.bedroom_sonos")}, + 2: {"function": lambda hass: hass.call_service("media_player/media_play", + entity_id="media_player.bedroom_sonos")}, + 3: {"function": lambda hass: hass.call_service("media_player/media_previous_track", + entity_id="media_player.bedroom_sonos")}, + 4: {"function": lambda hass: hass.call_service("media_player/media_next_track", + entity_id="media_player.bedroom_sonos")} + } + }, + 4: { # Options + 3: { # Living Room Sonos + 2: { # Crossfade + 1: {"function": lambda hass: hass.turn_off("switch.livingroom_sonos_crossfade"), + "description": "Living Room Sonos: Crossfade: Off"}, + 2: {"function": lambda hass: hass.turn_on("switch.livingroom_sonos_crossfade"), + "description": "Living Room Sonos: Crossfade: On"} }, - 4: { # Bedroom Sonos - 1: { "function": lambda hass: select_source(hass,"media_player.bedroom_sonos","Songs") }, - 2: { "function": lambda hass: select_source(hass,"media_player.bedroom_sonos","Chill sleep") } + 3: { # Shuffle + 1: {"function": lambda hass: hass.call_service("media_player/shuffle_set", + entity_id="media_player.livingroom_sonos",shuffle=False), + "description": "Living Room Sonos: Shuffle: Off"}, + 2: {"function": lambda hass: hass.call_service("media_player/shuffle_set", + entity_id="media_player.livingroom_sonos",shuffle=True), + "description": "Living Room Sonos: Shuffle: On"}, + }, + 4: { # Repeat + 1: {"function": lambda hass: hass.call_service("media_player/repeat_set", + entity_id="media_player.livingroom_sonos",repeat="off"), + "description": "Living Room Sonos: Repeat: Off"}, + 2: {"function": lambda hass: hass.call_service("media_player/repeat_set", + entity_id="media_player.livingroom_sonos",repeat="all"), + "description": "Living Room Sonos: Repeat: On"}, } }, - 3: { # Media Controls - 3: { # Living Room Sonos - 1: { "function": lambda hass: hass.call_service("media_player/media_pause", - entity_id="media_player.livingroom_sonos")}, - 2: { "function": lambda hass: hass.call_service("media_player/media_play", - entity_id="media_player.livingroom_sonos")}, - 3: { "function": lambda hass: hass.call_service("media_player/media_previous_track", - entity_id="media_player.livingroom_sonos")}, - 4: { "function": lambda hass: hass.call_service("media_player/media_next_track", - entity_id="media_player.livingroom_sonos")} + 4: { # Bedroom Sonos + 2: { # Crossfade + 1: {"function": lambda hass: hass.turn_off("switch.bedroom_sonos_crossfade"), + "description": "Bedroom Sonos: Crossfade: Off"}, + 2: {"function": lambda hass: hass.turn_on("switch.bedroom_sonos_crossfade"), + "description": "Bedroom Sonos: Crossfade: On"} }, - 4: { # Bedroom Sonos - 1: { "function": lambda hass: hass.call_service("media_player/media_pause", - entity_id="media_player.bedroom_sonos")}, - 2: { "function": lambda hass: hass.call_service("media_player/media_play", - entity_id="media_player.bedroom_sonos")}, - 3: { "function": lambda hass: hass.call_service("media_player/media_previous_track", - entity_id="media_player.bedroom_sonos")}, - 4: { "function": lambda hass: hass.call_service("media_player/media_next_track", - entity_id="media_player.bedroom_sonos")} + 3: { # Shuffle + 1: {"function": lambda hass: hass.call_service("media_player/shuffle_set", + entity_id="media_player.bedroom_sonos",shuffle=False), + "description": "Bedroom Sonos: Shuffle: Off"}, + 2: {"function": lambda hass: hass.call_service("media_player/shuffle_set", + entity_id="media_player.bedroom_sonos",shuffle=True), + "description": "Bedroom Sonos: Shuffle: On"}, + }, + 4: { # Repeat + 1: {"function": lambda hass: hass.call_service("media_player/repeat_set", + entity_id="media_player.bedroom_sonos",repeat="off"), + "description": "Bedroom Sonos: Repeat: Off"}, + 2: {"function": lambda hass: hass.call_service("media_player/repeat_set", + entity_id="media_player.bedroom_sonos",repeat="all"), + "description": "Bedroom Sonos: Repeat: On"}, } } } @@ -290,21 +532,19 @@ def select_source(hass, device, source): # Sequence Logic # ################## -# Long press cancels any existing sequence and begins a new one. The first element in a -# sequence is always a long press, and all others are always short presses. -# While a sequence is being entered, normal actions from short presses in hass are -# disabled. A sequence can be ended either immediately by recognizing a full sequence -# or by TIMEOUT seconds passing. +# Short presses will be recorded into a sequence array. Long presses are reserved for +# actions directly in hass for now; use KeyReleased event to capture them. A sequence +# can be ended either immediately by recognizing a full sequence or by TIMEOUT seconds +# passing. (The former is NYI but the code is capable as is.) # - self.currentSequence contains an array of keys representing a sequence that is # actively being entered. # - self.tot contains a timer for the process_sequence function, ending sequence entry. -TIMEOUT=2 +TIMEOUT=1 class WallmotePlumbing(hass.Hass): def initialize(self): - self.turn_on("automation.wallmote"); self.currentSequence = []; self.listen_event(self.onevent, "zwave_js_value_notification"); @@ -314,22 +554,12 @@ class WallmotePlumbing(hass.Hass): key = int(event.get('property_key')); # We don't get a KeyPressed event at all for long presses evt = event.get('value'); - if (evt == "KeyPressed"): - self.shortpress(key); - elif (evt == "KeyReleased"): - self.longpress(key); + if (evt == "KeyPressed"): self.shortpress(key); def shortpress(self, key): - # Single presses are handled in hass; sequences must start with a long press - if (len(self.currentSequence) == 0): return; self.currentSequence.append(key); self.reset_tot(); - def longpress(self, key): - self.turn_off("automation.wallmote"); - self.currentSequence = [key]; - self.reset_tot(); - def reset_tot(self): if (hasattr(self,"tot")): self.tot.cancel(); self.tot = Timer(TIMEOUT,self.process_sequence); @@ -337,9 +567,6 @@ class WallmotePlumbing(hass.Hass): def process_sequence(self): self.tot.cancel(); # So process_sequence can be called directly - self.turn_on("automation.wallmote"); - # Clear self.currentSequence so future shortpresses are not - # treated as part of a sequence sequence = self.currentSequence; self.currentSequence = []; self.log(sequence); @@ -350,7 +577,13 @@ class WallmotePlumbing(hass.Hass): # Deeper into the rabbit hole category = sequence.pop(0); if (category in tree): self.run_action(sequence,tree[category]); + else: self.log("No match"); else: - # Perform an action from here + # Perform an action from here and log the description if ("function" in tree): tree["function"](self); elif ("service" in tree): self.call_service(tree["service"]); + else: + self.log("No match"); + return; + if ("description" in tree): self.log(tree["description"]); + else: self.log(inspect.getsource(tree["function"]).strip());