more cleanup
This commit is contained in:
@@ -23,6 +23,8 @@ class MotionLight(Hass):
|
||||
self.sync_state()
|
||||
self.run_daily(callback=self.refresh_state_times, start='00:00:00')
|
||||
|
||||
self.app_entities = self.gather_app_entities()
|
||||
|
||||
if (button := self.args.get('button')):
|
||||
if not isinstance(button, list):
|
||||
button = [button]
|
||||
@@ -141,7 +143,7 @@ class MotionLight(Hass):
|
||||
return states
|
||||
|
||||
def current_state(self, time: time = None):
|
||||
if self.sleeping_active:
|
||||
if self.sleep_bool:
|
||||
if (state := self.args.get('sleep_state')):
|
||||
return state
|
||||
else:
|
||||
@@ -155,8 +157,9 @@ class MotionLight(Hass):
|
||||
def current_scene(self, time: time = None):
|
||||
return self.current_state(time=time)['scene']
|
||||
|
||||
@property
|
||||
def app_entities(self):
|
||||
def gather_app_entities(self) -> List[str]:
|
||||
"""Returns a list of all the entities involved in any of the states
|
||||
"""
|
||||
def gen():
|
||||
for settings in deepcopy(self.args['scene']):
|
||||
# dt = self.parse_time(settings.pop('time'))
|
||||
@@ -196,17 +199,13 @@ class MotionLight(Hass):
|
||||
except Exception:
|
||||
return timedelta()
|
||||
|
||||
@property
|
||||
def sleeping_active(self) -> bool:
|
||||
if 'sleep' in self.args:
|
||||
return self.get_state(self.args['sleep']) == 'on'
|
||||
else:
|
||||
return False
|
||||
|
||||
@property
|
||||
def sleep_bool(self) -> bool:
|
||||
if (sleep_var := self.args.get('sleep')):
|
||||
return self.get_state(sleep_var) == 'on'
|
||||
else:
|
||||
# self.log('WARNING')
|
||||
return False
|
||||
|
||||
@sleep_bool.setter
|
||||
def sleep_bool(self, val) -> bool:
|
||||
@@ -284,23 +283,11 @@ class MotionLight(Hass):
|
||||
self.log(f'Turned on scene: {scene}')
|
||||
|
||||
elif isinstance(scene, dict):
|
||||
# makes setting the state to 'on' optional in the yaml definition
|
||||
for entity, settings in scene.items():
|
||||
if 'state' not in settings:
|
||||
scene[entity]['state'] = 'on'
|
||||
|
||||
daylights = [
|
||||
(entity, settings['state'])
|
||||
for entity, settings in scene.items()
|
||||
if isinstance(settings['state'], str) and settings['state'].startswith('daylight')
|
||||
]
|
||||
|
||||
for entity, app_name in daylights:
|
||||
# risky:
|
||||
scene.pop(entity)
|
||||
app: Continuous = self.get_app(app_name)
|
||||
self.log(f'Adjusting with app...')
|
||||
app.adjust()
|
||||
|
||||
self.call_service('scene/apply', entities=scene, transition=0)
|
||||
self.log(f'Applied scene: {scene}')
|
||||
|
||||
@@ -330,6 +317,10 @@ class MotionLight(Hass):
|
||||
self.log(f'Turned off {entity}')
|
||||
|
||||
def refresh_state_times(self, *args, **kwargs):
|
||||
"""Resets the `self.states` attribute to a newly parsed version of the states.
|
||||
|
||||
Parsed states have an absolute time for a certain day.
|
||||
"""
|
||||
# re-parse the state strings into times for the current day
|
||||
self.states = self.parse_states()
|
||||
|
||||
@@ -352,9 +343,6 @@ class MotionLight(Hass):
|
||||
if self.entity_state:
|
||||
self.deactivate()
|
||||
else:
|
||||
# use this instead of self.activate() to avoid it being called again by the state change event
|
||||
# ^ no longer relevant with self.activate() commented out in self.callback_light_on()
|
||||
# self.entity_state = True
|
||||
self.activate()
|
||||
|
||||
# event 1001 is a long press start
|
||||
|
||||
Reference in New Issue
Block a user