Source code for caspia.pan.builder

from caspia.pan import services as pan_services
from caspia.toolbox.storage.proxy import ProxyStorage


[docs]class Builder: def __init__(self, lookup, *, loop, storage): self.lookup = lookup self.loop = loop self.storage = storage
[docs] def create_lightgroup(self, name, *lights): lightgroup = self.lookup.get('light', name, create=False) if lightgroup and not isinstance(lightgroup, pan_services.LightGroup): msg = '%r already exists and it is not a LightGroup, but %s' raise ValueError(msg % (name, type(lightgroup))) if lightgroup is None: lightgroup = pan_services.LightGroup(name) self.lookup.add(lightgroup) lightgroup.add(*lights) return lightgroup
[docs] def create_switch(self, name): storage = ProxyStorage(self.storage, prefix=name) switch = pan_services.Switch(name, loop=self.loop, storage=storage) self.lookup.add(switch) return switch
[docs] def create_switch_with_action(self, name): import warnings warnings.warn('Please use renamed version of this method: create_switch_with_task(name)', DeprecationWarning) return self.create_switch_with_task(name)
[docs] def create_switch_with_task(self, name): storage = ProxyStorage(self.storage, prefix=name) switch = pan_services.TaskSwitch(name, loop=self.loop, storage=storage) self.lookup.add(switch) return switch