Still iterating on the home cinema configuration

This commit is contained in:
Pierre committed 2026-09-26 16:43:24 +02:00
1 parent ed6f218968
commit ed59a72c3f
6 files changed
+232 -35

No files matched your search

+41
View File
@@ -1,6 +1,7 @@
import appdaemon.plugins.hass.hassapi as hass
import ad_toolbox.smartcondition as SmartCondition
from ad_toolbox.smartobject import SmartObject
from ad_toolbox.eventhandler import EventHandler
import time
class SmartShutter(SmartObject):
@@ -75,12 +76,52 @@ class SmartShutter(SmartObject):
self.ready = True
self.on_update()
# toggle_events uses the same event filters as SmartSwitch.
self.event_handlers = []
if "toggle_events" in self.args:
self.event_handlers.append(EventHandler(self, self.args["toggle_events"], self.on_toggle_event))
def terminate(self):
self.event_handlers = []
self.emergency_close_conditions = None
self.close_conditions = None
self.open_conditions = None
super().terminate()
def on_toggle_event(self, event_name, data, event_context):
if not self.ready:
return
current_position = self.get_state(self.entity_id, attribute='current_position')
try:
current_position = float(current_position)
except (TypeError, ValueError):
self.log("Toggle ignored: current position is unavailable", level="WARNING")
return
# Reverse the requested movement when another press arrives in transit.
if self.target_position is not None:
should_close = self.target_position == self.open_position
else:
midpoint = (self.open_position + self.close_position) / 2
should_close = current_position >= midpoint
if not should_close and self.emergency_close_conditions and self.emergency_close_conditions.evaluate(False) == SmartCondition.Result.Succeeded:
self.on_update()
return
self.stop_slow_transition()
if self.auto_switch:
self.set_state(self.auto_switch, state='off')
self.target_position = self.close_position if should_close else self.open_position
self.log(f"Toggle shutter to {self.target_position} (previous position was {current_position})")
if self.target_position == 0:
self.call_service("cover/close_cover", entity_id=self.entity_id)
elif self.target_position == 100:
self.call_service("cover/open_cover", entity_id=self.entity_id)
else:
self.call_service("cover/set_cover_position", entity_id=self.entity_id, position=self.target_position)
def on_state_change(self, entity, attribute, old, new, kwargs):
if self.ready == False:
self.log(f"on_state_change called before the app is ready",level = "WARNING")