from .filter import RulesFilter
from .lightgroup import LightGroupBehavior
[docs]class RuleActivationContext(dict):
def __init__(self, loop, configurator, rules_filter=RulesFilter.ALL):
super().__init__()
self.loop = loop
self.configurator = configurator
self.cleanup_subscribers = set()
self.rules_filter = rules_filter
@property
def lookup(self):
return self.configurator.lookup
[docs] def on_cleanup(self, func):
self.cleanup_subscribers.add(func)
@property
def lightgroup_behaviors(self):
if 'lightgroup_behaviors' not in self:
self['lightgroup_behaviors'] = {}
return self['lightgroup_behaviors']
[docs] def get_lightgroup_behavior(self, group_light, create=True):
if group_light.name in self.lightgroup_behaviors:
return self.lightgroup_behaviors[group_light.name]
elif create:
behavior = LightGroupBehavior(group_light, self)
self.lightgroup_behaviors[group_light.name] = behavior
return behavior
return None
[docs] async def cleanup(self):
for subscriber in self.cleanup_subscribers:
await subscriber()