Exemple #1
0
    def __init__(self, switch_callback=_NOOP, motion_callback=_NOOP,
                 with_discovery=True, with_subscribers=True, with_cache=None,
                 bind=None, config_filename=None):
        """
        Create a WeMo environment.

        @param switch_callback: A function to be called when a new switch is
                                discovered.
        @type switch_callback:  function
        @param motion_callback: A function to be called when a new motion is
                                discovered.
        @type motion_callback:  function
        @param with_subscribers: Whether to register for events with discovered
                                devices.
        @type with_subscribers: bool
        @param bind: ip:port to which to bind the response server.
        @type bind: str
        """
        self._config = WemoConfiguration(filename=config_filename)
        self.upnp = UPnP(self._found_device, bind=bind or self._config.bind)
        self.registry = SubscriptionRegistry()
        if with_cache is None:
            with_cache = (self._config.cache if self._config.cache is not None else True)
        self._with_cache = with_cache
        self._with_discovery = with_discovery
        self._with_subscribers = with_subscribers
        self._switch_callback = switch_callback
        self._motion_callback = motion_callback
        self._switches = {}
        self._motions = {}
Exemple #2
0
    def __init__(self, switch_callback=_NOOP, motion_callback=_NOOP, bridge_callback=_NOOP,
                 maker_callback=_NOOP, with_discovery=True, with_subscribers=True, with_cache=_MARKER, 
                 bind=None, config_filename=None):
        """
        Create a WeMo environment.

        @param switch_callback: A function to be called when a new switch is
                                discovered.
        @type switch_callback:  function
        @param motion_callback: A function to be called when a new motion is
                                discovered.
        @type motion_callback:  function
        @param with_subscribers: Whether to register for events with discovered
                                devices.
        @type with_subscribers: bool
        @param bind: ip:port to which to bind the response server.
        @type bind: str
        """
        if with_cache is not _MARKER:
            log.warn("with_cache argument is deprecated (and nonfunctional)")
        self._config = WemoConfiguration(filename=config_filename)
        self.upnp = UPnP(bind=bind or self._config.bind)
        discovered.connect(self._found_device, self.upnp)
        self.registry = SubscriptionRegistry()
        self._with_discovery = with_discovery
        self._with_subscribers = with_subscribers
        self._switch_callback = switch_callback
        self._motion_callback = motion_callback
        self._bridge_callback = bridge_callback
        self._maker_callback = maker_callback
        self._switches = {}
        self._motions = {}
        self._bridges = {}
        self._makers = {}
        self.devices = {}