From 00a7fd5048d4b5ed4a76f9f31b2607a06db89d9e Mon Sep 17 00:00:00 2001 From: John Lancaster <32917998+jsl12@users.noreply.github.com> Date: Sat, 25 Nov 2023 22:06:43 -0600 Subject: [PATCH] toggle stuff --- apps/cubes/cube.py | 18 ++++++++---------- apps/room_control | 2 +- apps/rooms/bathroom.yaml | 2 +- apps/rooms/bedroom.yaml | 1 + apps/rooms/kitchen.yaml | 2 +- apps/rooms/living_room.yaml | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/cubes/cube.py b/apps/cubes/cube.py index 13b8e06..536b8e2 100644 --- a/apps/cubes/cube.py +++ b/apps/cubes/cube.py @@ -1,15 +1,16 @@ import json from copy import deepcopy +from appdaemon.plugins.hass.hassapi import Hass from appdaemon.plugins.mqtt.mqttapi import Mqtt +# from ..room_control.room_control import RoomController -class AqaraCube(Mqtt): +class AqaraCube(Hass, Mqtt): def initialize(self): - self.set_namespace('mqtt') topic = f'zigbee2mqtt/{self.args["cube"]}' - self.mqtt_subscribe(topic) - self.listen_event(self.handle_event, "MQTT_MESSAGE", topic=topic) + self.mqtt_subscribe(topic, namespace='mqtt') + self.listen_event(self.handle_event, "MQTT_MESSAGE", topic=topic, namespace='mqtt') self.log(f'Listening for cube events on: {topic}') self.app = self.get_app(self.args['app']) @@ -39,12 +40,9 @@ class AqaraCube(Mqtt): self.call_service('scene/turn_on', entity_id=description, namespace='default') self.log(f'Turned on {description}') - elif description == 'toggle': - cause = f'{action} from {self.args["cube"]}' - if self.app.entity_state: - self.app.deactivate(cause=cause) - else: - self.app.activate(cause=cause) + elif description.startswith('toggle'): + cause = f'{self.args["cube"]} {action}' + self.app.toggle(kwargs={'cause': cause}) # def handle_rotate_right(self, payload): # self.log(f'{self.args["cube"]}: Rotate right') diff --git a/apps/room_control b/apps/room_control index afc5e45..1486450 160000 --- a/apps/room_control +++ b/apps/room_control @@ -1 +1 @@ -Subproject commit afc5e456425ae7c1ba1e64d05bcf8405edc67296 +Subproject commit 148645094abd9ad253699aaf1d1b05d7c85ed4f3 diff --git a/apps/rooms/bathroom.yaml b/apps/rooms/bathroom.yaml index df8c701..d46566a 100644 --- a/apps/rooms/bathroom.yaml +++ b/apps/rooms/bathroom.yaml @@ -1,6 +1,7 @@ bathroom: module: room_control class: RoomController + ref_entity: light.bathroom off_duration: '00:05:00' states: - time: '05:00:00' @@ -35,7 +36,6 @@ bathroom_button: module: button class: Button app: bathroom - ref_entity: light.bathroom button: Bathroom Button bathroom_motion: diff --git a/apps/rooms/bedroom.yaml b/apps/rooms/bedroom.yaml index 19ea792..41b2b33 100644 --- a/apps/rooms/bedroom.yaml +++ b/apps/rooms/bedroom.yaml @@ -1,6 +1,7 @@ bedroom: module: room_control class: RoomController + ref_entity: light.bedroom off_duration: '00:05:00' states: - time: 'sunrise - 03:00:00' diff --git a/apps/rooms/kitchen.yaml b/apps/rooms/kitchen.yaml index 91063d9..74ec1f4 100755 --- a/apps/rooms/kitchen.yaml +++ b/apps/rooms/kitchen.yaml @@ -1,6 +1,7 @@ kitchen: module: room_control class: RoomController + ref_entity: light.kitchen off_duration: '00:10:00' ha_button: input_button.activate_kitchen states: @@ -40,7 +41,6 @@ kitchen_button: module: button class: Button app: kitchen - ref_entity: light.kitchen button: Kitchen Button kitchen_motion: diff --git a/apps/rooms/living_room.yaml b/apps/rooms/living_room.yaml index 867eddd..911ee33 100644 --- a/apps/rooms/living_room.yaml +++ b/apps/rooms/living_room.yaml @@ -1,6 +1,7 @@ living_room: module: room_control class: RoomController + ref_entity: light.living_room off_duration: 00:30:00 states: - time: sunrise @@ -76,7 +77,6 @@ living_room_button: class: Button app: living_room button: Living Room Button - ref_entity: light.living_room living_room_motion: module: motion