added enable feature

This commit is contained in:
John Lancaster
2023-04-23 21:56:35 -05:00
parent 51534fc3ed
commit cf528c5252
5 changed files with 30 additions and 8 deletions

View File

@@ -22,6 +22,7 @@ bathroom_button:
bathroom_daylight:
module: controller
class: ControllerDaylight
enable: input_boolean.enable_bathroom
room: bathroom
entities:
- light.bathroom

View File

@@ -25,6 +25,7 @@ bedroom_button:
bedroom_daylight:
module: controller
class: ControllerDaylight
enable: input_boolean.enable_bedroom
room: bedroom
entities:
- light.bedroom

View File

@@ -203,6 +203,14 @@ class ControllerDaylight(Hass):
if entity.get_state() == 'on':
self.start_adjustments(entity.entity_id)
if (entity_name := self.args.get('enable')) is not None:
self.enable_entity: Entity = self.get_entity(entity_name)
self.log(f'enabled by {self.enable_entity.friendly_name}[{entity_name}]')
# self.listen_state(
# callback=lambda entity, attribute, old, new, kwargs: self.log(f'{self.enable_entity.friendly_name}: {old} -> {new}'),
# entity_id=entity_name
# )
def handle_state_change(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
self.log(f'{entity}: {old} -> {new}')
if new == 'on':
@@ -245,7 +253,14 @@ class ControllerDaylight(Hass):
@property
def enabled(self) -> bool:
return hasattr(self.adjustment_handle)
if hasattr(self, 'enable_entity'):
return self.enable_entity.is_state('on')
else:
return True
@enabled.setter
def enabled(self, new: bool) -> bool:
self.enable_entity.set_state(state='on' if new else 'off')
def start_adjustments(self, entity: str):
self.adjustment_handle = self.run_every(
@@ -263,12 +278,15 @@ class ControllerDaylight(Hass):
self.log(f'Cancelled adjustments')
def ongoing_adjustment(self, kwargs):
self.log(f'Ongoing adjustment')
settings = self.adjuster.current_settings
matching = self.matching_state(entity_id=kwargs['entity'])
if not matching and not self.room.is_sleeping:
self.turn_on(entity_id=kwargs['entity'], **settings)
self.log(f'Adjusted {self.friendly_name(kwargs["entity"])} with {settings}')
if self.enabled:
self.log(f'Ongoing adjustment')
settings = self.adjuster.current_settings
matching = self.matching_state(entity_id=kwargs['entity'])
if not matching and not self.room.is_sleeping:
self.turn_on(entity_id=kwargs['entity'], **settings)
self.log(f'Adjusted {self.friendly_name(kwargs["entity"])} with {settings}')
else:
self.log(f'App disabled by {self.enable_entity.friendly_name}')
def update_sensors(self, kwargs):
for key, val in self.adjuster.current_settings.items():

View File

@@ -22,6 +22,7 @@ kitchen_button:
kitchen_daylight:
module: controller
class: ControllerDaylight
enable: input_boolean.enable_kitchen
room: kitchen
entities:
- light.kitchen

View File

@@ -25,6 +25,7 @@ living_room_button:
living_room_daylight:
module: controller
class: ControllerDaylight
enable: input_boolean.enable_living_room
room: living_room
entities:
- light.living_room
@@ -59,7 +60,7 @@ living_room_daylight:
brightness: 200
color_temp: 350
- time: '10:30:00pm'
- time: '11:00:00pm'
brightness: 75
color_temp: 375