added enable feature
This commit is contained in:
@@ -22,6 +22,7 @@ bathroom_button:
|
|||||||
bathroom_daylight:
|
bathroom_daylight:
|
||||||
module: controller
|
module: controller
|
||||||
class: ControllerDaylight
|
class: ControllerDaylight
|
||||||
|
enable: input_boolean.enable_bathroom
|
||||||
room: bathroom
|
room: bathroom
|
||||||
entities:
|
entities:
|
||||||
- light.bathroom
|
- light.bathroom
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ bedroom_button:
|
|||||||
bedroom_daylight:
|
bedroom_daylight:
|
||||||
module: controller
|
module: controller
|
||||||
class: ControllerDaylight
|
class: ControllerDaylight
|
||||||
|
enable: input_boolean.enable_bedroom
|
||||||
room: bedroom
|
room: bedroom
|
||||||
entities:
|
entities:
|
||||||
- light.bedroom
|
- light.bedroom
|
||||||
|
|||||||
@@ -203,6 +203,14 @@ class ControllerDaylight(Hass):
|
|||||||
if entity.get_state() == 'on':
|
if entity.get_state() == 'on':
|
||||||
self.start_adjustments(entity.entity_id)
|
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):
|
def handle_state_change(self, entity=None, attribute=None, old=None, new=None, kwargs=None):
|
||||||
self.log(f'{entity}: {old} -> {new}')
|
self.log(f'{entity}: {old} -> {new}')
|
||||||
if new == 'on':
|
if new == 'on':
|
||||||
@@ -245,7 +253,14 @@ class ControllerDaylight(Hass):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self) -> bool:
|
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):
|
def start_adjustments(self, entity: str):
|
||||||
self.adjustment_handle = self.run_every(
|
self.adjustment_handle = self.run_every(
|
||||||
@@ -263,12 +278,15 @@ class ControllerDaylight(Hass):
|
|||||||
self.log(f'Cancelled adjustments')
|
self.log(f'Cancelled adjustments')
|
||||||
|
|
||||||
def ongoing_adjustment(self, kwargs):
|
def ongoing_adjustment(self, kwargs):
|
||||||
self.log(f'Ongoing adjustment')
|
if self.enabled:
|
||||||
settings = self.adjuster.current_settings
|
self.log(f'Ongoing adjustment')
|
||||||
matching = self.matching_state(entity_id=kwargs['entity'])
|
settings = self.adjuster.current_settings
|
||||||
if not matching and not self.room.is_sleeping:
|
matching = self.matching_state(entity_id=kwargs['entity'])
|
||||||
self.turn_on(entity_id=kwargs['entity'], **settings)
|
if not matching and not self.room.is_sleeping:
|
||||||
self.log(f'Adjusted {self.friendly_name(kwargs["entity"])} with {settings}')
|
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):
|
def update_sensors(self, kwargs):
|
||||||
for key, val in self.adjuster.current_settings.items():
|
for key, val in self.adjuster.current_settings.items():
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ kitchen_button:
|
|||||||
kitchen_daylight:
|
kitchen_daylight:
|
||||||
module: controller
|
module: controller
|
||||||
class: ControllerDaylight
|
class: ControllerDaylight
|
||||||
|
enable: input_boolean.enable_kitchen
|
||||||
room: kitchen
|
room: kitchen
|
||||||
entities:
|
entities:
|
||||||
- light.kitchen
|
- light.kitchen
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ living_room_button:
|
|||||||
living_room_daylight:
|
living_room_daylight:
|
||||||
module: controller
|
module: controller
|
||||||
class: ControllerDaylight
|
class: ControllerDaylight
|
||||||
|
enable: input_boolean.enable_living_room
|
||||||
room: living_room
|
room: living_room
|
||||||
entities:
|
entities:
|
||||||
- light.living_room
|
- light.living_room
|
||||||
@@ -59,7 +60,7 @@ living_room_daylight:
|
|||||||
brightness: 200
|
brightness: 200
|
||||||
color_temp: 350
|
color_temp: 350
|
||||||
|
|
||||||
- time: '10:30:00pm'
|
- time: '11:00:00pm'
|
||||||
brightness: 75
|
brightness: 75
|
||||||
color_temp: 375
|
color_temp: 375
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user