small formatting
This commit is contained in:
@@ -2,11 +2,11 @@ from copy import deepcopy
|
|||||||
from datetime import time, timedelta
|
from datetime import time, timedelta
|
||||||
from typing import Dict, List, Tuple, Union
|
from typing import Dict, List, Tuple, Union
|
||||||
|
|
||||||
from appdaemon.plugins.hass import hassapi as hass
|
from appdaemon.plugins.hass.hassapi import Hass
|
||||||
from continuous import Continuous
|
from continuous import Continuous
|
||||||
|
|
||||||
|
|
||||||
class MotionLight(hass.Hass):
|
class MotionLight(Hass):
|
||||||
"""Class for linking an light with a motion sensor.
|
"""Class for linking an light with a motion sensor.
|
||||||
|
|
||||||
- Separate the turning on and turning off functions.
|
- Separate the turning on and turning off functions.
|
||||||
@@ -22,15 +22,16 @@ class MotionLight(hass.Hass):
|
|||||||
self.schedule_transitions()
|
self.schedule_transitions()
|
||||||
self.run_daily(callback=self.schedule_transitions, start='00:00:00')
|
self.run_daily(callback=self.schedule_transitions, start='00:00:00')
|
||||||
|
|
||||||
if (b := self.args.get('button')):
|
if (button := self.args.get('button')):
|
||||||
if not isinstance(b, list):
|
if not isinstance(button, list):
|
||||||
b = [b]
|
button = [button]
|
||||||
for button in b:
|
for button in button:
|
||||||
self.log(f'Setting up button: {button}')
|
self.log(f'Setting up button: {button}')
|
||||||
self.listen_event(self.handle_button, event='deconz_event', id=button)
|
self.listen_event(self.handle_button, event='deconz_event', id=button)
|
||||||
|
|
||||||
if (door := self.args.get('door')):
|
if (door := self.args.get('door')):
|
||||||
self.log(f'Setting up door: {self.friendly_name(door)}')
|
self.door_entity = self.get_entity(door)
|
||||||
|
self.log(f'Setting up door: {self.door_entity.friendly_name}')
|
||||||
self.listen_state(
|
self.listen_state(
|
||||||
callback=self.activate_all_off,
|
callback=self.activate_all_off,
|
||||||
entity_id=door,
|
entity_id=door,
|
||||||
@@ -239,8 +240,7 @@ class MotionLight(hass.Hass):
|
|||||||
self.callback_light_off()
|
self.callback_light_off()
|
||||||
|
|
||||||
def listen_motion_on(self):
|
def listen_motion_on(self):
|
||||||
self.log(
|
self.log(f'Waiting for motion on {self.friendly_name(self.sensor)} to turn on {self.friendly_name(self.entity)}')
|
||||||
f'Waiting for motion on {self.friendly_name(self.sensor)} to turn on {self.friendly_name(self.entity)}')
|
|
||||||
self.motion_on_handle = self.listen_state(
|
self.motion_on_handle = self.listen_state(
|
||||||
callback=self.activate,
|
callback=self.activate,
|
||||||
entity_id=self.sensor,
|
entity_id=self.sensor,
|
||||||
@@ -249,8 +249,7 @@ class MotionLight(hass.Hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def listen_motion_off(self, duration: timedelta):
|
def listen_motion_off(self, duration: timedelta):
|
||||||
self.log(
|
self.log(f'Waiting for motion to stop on {self.friendly_name(self.sensor)} for {duration} to turn off {self.friendly_name(self.entity)}')
|
||||||
f'Waiting for motion to stop on {self.friendly_name(self.sensor)} for {duration} to turn off {self.friendly_name(self.entity)}')
|
|
||||||
self.motion_off_handle = self.listen_state(
|
self.motion_off_handle = self.listen_state(
|
||||||
callback=self.deactivate,
|
callback=self.deactivate,
|
||||||
entity_id=self.sensor,
|
entity_id=self.sensor,
|
||||||
@@ -282,7 +281,7 @@ class MotionLight(hass.Hass):
|
|||||||
elif new == 'off':
|
elif new == 'off':
|
||||||
self.callback_light_off(entity, attribute, old, new, kwargs)
|
self.callback_light_off(entity, attribute, old, new, kwargs)
|
||||||
else:
|
else:
|
||||||
self.log(f'Uknown state: {new}')
|
self.log(f'Unknown state: {new}')
|
||||||
|
|
||||||
def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
def callback_light_on(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
"""Called when the light turns on
|
"""Called when the light turns on
|
||||||
|
|||||||
Reference in New Issue
Block a user