small formatting

This commit is contained in:
John Lancaster
2023-04-26 22:39:22 -05:00
parent 5c8fa5e586
commit ad2eda75cc

View File

@@ -2,11 +2,11 @@ from copy import deepcopy
from datetime import time, timedelta
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
class MotionLight(hass.Hass):
class MotionLight(Hass):
"""Class for linking an light with a motion sensor.
- Separate the turning on and turning off functions.
@@ -22,15 +22,16 @@ class MotionLight(hass.Hass):
self.schedule_transitions()
self.run_daily(callback=self.schedule_transitions, start='00:00:00')
if (b := self.args.get('button')):
if not isinstance(b, list):
b = [b]
for button in b:
if (button := self.args.get('button')):
if not isinstance(button, list):
button = [button]
for button in button:
self.log(f'Setting up button: {button}')
self.listen_event(self.handle_button, event='deconz_event', id=button)
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(
callback=self.activate_all_off,
entity_id=door,
@@ -239,8 +240,7 @@ class MotionLight(hass.Hass):
self.callback_light_off()
def listen_motion_on(self):
self.log(
f'Waiting for motion on {self.friendly_name(self.sensor)} to turn on {self.friendly_name(self.entity)}')
self.log(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(
callback=self.activate,
entity_id=self.sensor,
@@ -249,8 +249,7 @@ class MotionLight(hass.Hass):
)
def listen_motion_off(self, duration: timedelta):
self.log(
f'Waiting for motion to stop on {self.friendly_name(self.sensor)} for {duration} to turn off {self.friendly_name(self.entity)}')
self.log(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(
callback=self.deactivate,
entity_id=self.sensor,
@@ -282,7 +281,7 @@ class MotionLight(hass.Hass):
elif new == 'off':
self.callback_light_off(entity, attribute, old, new, kwargs)
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):
"""Called when the light turns on
@@ -328,7 +327,7 @@ class MotionLight(hass.Hass):
self.call_service('scene/apply', entities=scene, transition=0)
self.log(f'Applied scene: {scene}')
elif scene is None:
self.log(f'No scene, ignoring...')
# Need to act as if the light had just turned off to reset the motion (and maybe other things?)