toggle stuff
This commit is contained in:
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user