broke out door function
This commit is contained in:
11
door.py
Normal file
11
door.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from appdaemon.plugins.hass.hassapi import Hass
|
||||||
|
from room_control import RoomController
|
||||||
|
|
||||||
|
|
||||||
|
class DoorControl(Hass):
|
||||||
|
def initialize(self):
|
||||||
|
self.listen_state(self.door_open, entity_id=self.args['door'], new='on')
|
||||||
|
|
||||||
|
def door_open(self, entity, attribute, old, new, kwargs):
|
||||||
|
app: RoomController = self.get_app(self.args['app'])
|
||||||
|
app.activate_all_off()
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
|
import json
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import time, timedelta
|
from datetime import time, timedelta
|
||||||
from gc import callbacks
|
|
||||||
from telnetlib import KERMIT
|
|
||||||
from typing import List
|
from typing import List
|
||||||
import json
|
|
||||||
import astral
|
import astral
|
||||||
from appdaemon.plugins.hass.hassapi import Hass
|
from appdaemon.plugins.hass.hassapi import Hass
|
||||||
from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
from appdaemon.plugins.mqtt.mqttapi import Mqtt
|
||||||
|
|
||||||
|
|
||||||
class RoomController(Hass, Mqtt):
|
class RoomController(Hass, Mqtt):
|
||||||
"""Class for linking an light with a motion sensor.
|
"""Class for linking an light with a motion sensor.
|
||||||
|
|
||||||
@@ -42,16 +42,6 @@ class RoomController(Hass, Mqtt):
|
|||||||
self.mqtt_subscribe(topic, namespace='mqtt')
|
self.mqtt_subscribe(topic, namespace='mqtt')
|
||||||
self.listen_event(self.handle_button, "MQTT_MESSAGE", topic=topic, namespace='mqtt', button=button)
|
self.listen_event(self.handle_button, "MQTT_MESSAGE", topic=topic, namespace='mqtt', button=button)
|
||||||
|
|
||||||
|
|
||||||
if (door := self.args.get('door')):
|
|
||||||
door_entity = self.get_entity(door)
|
|
||||||
self.log(f'Setting up door: {door_entity.friendly_name}')
|
|
||||||
self.listen_state(
|
|
||||||
callback=self.activate_all_off,
|
|
||||||
entity_id=door,
|
|
||||||
new='on'
|
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sensor(self) -> str:
|
def sensor(self) -> str:
|
||||||
return self.args['sensor']
|
return self.args['sensor']
|
||||||
@@ -315,12 +305,16 @@ class RoomController(Hass, Mqtt):
|
|||||||
self.log(f'ERROR: unknown scene: {scene}')
|
self.log(f'ERROR: unknown scene: {scene}')
|
||||||
|
|
||||||
def activate_all_off(self, *args, **kwargs):
|
def activate_all_off(self, *args, **kwargs):
|
||||||
|
"""Activate if all of the entities are on
|
||||||
|
"""
|
||||||
if self.all_off:
|
if self.all_off:
|
||||||
self.activate(*args, **kwargs)
|
self.activate(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
self.log(f'Skipped activating - everything is not off')
|
self.log(f'Skipped activating - everything is not off')
|
||||||
|
|
||||||
def activate_any_on(self, *args, **kwargs):
|
def activate_any_on(self, *args, **kwargs):
|
||||||
|
"""Activate if any of the entities are on
|
||||||
|
"""
|
||||||
if self.any_on:
|
if self.any_on:
|
||||||
self.activate(*args, **kwargs)
|
self.activate(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
@@ -362,29 +356,15 @@ class RoomController(Hass, Mqtt):
|
|||||||
# self.log(f'No action in: {payload}')
|
# self.log(f'No action in: {payload}')
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if action == 'single':
|
if action == '':
|
||||||
|
# self.log(f'{topic}: {payload}')
|
||||||
|
pass
|
||||||
|
elif action == 'single':
|
||||||
self.button_single_click(kwargs['button'])
|
self.button_single_click(kwargs['button'])
|
||||||
elif action != '':
|
else:
|
||||||
self.log(f'{topic}: {payload}')
|
self.log(f'Unhandled button event: {event_name}')
|
||||||
finally:
|
finally:
|
||||||
return
|
return
|
||||||
elif event_name == 'deconz_event':
|
|
||||||
# event 1002 is a single button press
|
|
||||||
if data['event'] == 1002:
|
|
||||||
self.button_single_click(kwargs['button'])
|
|
||||||
|
|
||||||
# event 1001 is a long press start
|
|
||||||
elif data['event'] == 1001:
|
|
||||||
self.log(f'{data["id"]} long press down')
|
|
||||||
if 'delay' in self.args and self.entity_state:
|
|
||||||
self.cancel_motion_callback(new='off')
|
|
||||||
self.listen_motion_off(self.delay)
|
|
||||||
self.turn_on(self.entity, brightness_pct=100)
|
|
||||||
|
|
||||||
# event 1004 is a double click
|
|
||||||
elif data['event'] == 1004:
|
|
||||||
self.log(f'{data["id"]} double click')
|
|
||||||
self.button_double_click()
|
|
||||||
else:
|
else:
|
||||||
self.log(f'Unhandled button event: {event_name}')
|
self.log(f'Unhandled button event: {event_name}')
|
||||||
|
|
||||||
@@ -396,11 +376,6 @@ class RoomController(Hass, Mqtt):
|
|||||||
else:
|
else:
|
||||||
self.activate(cause=cause)
|
self.activate(cause=cause)
|
||||||
|
|
||||||
def button_double_click(self):
|
|
||||||
if 'sleep' in self.args:
|
|
||||||
self.sleep_bool = not self.sleep_bool
|
|
||||||
self.activate(cause='button double click')
|
|
||||||
|
|
||||||
def get_app_callbacks(self, name: str = None):
|
def get_app_callbacks(self, name: str = None):
|
||||||
name = name or self.name
|
name = name or self.name
|
||||||
for app_name, callbacks in self.get_callback_entries().items():
|
for app_name, callbacks in self.get_callback_entries().items():
|
||||||
|
|||||||
Reference in New Issue
Block a user