示例#1
0
def start_wemo():
    import kodinhenki.wemo.device_tracker as dt
    ip = None
    if is_cer:
        ip = '192.168.44.1'
        # The remote_ip based lookup does not really seem to work with v4.
        # Oh well. So hardcode here for the cer case with N addresses.

    updater.add(dt.get(ip=ip,
                       remote_ip='192.168.44.254',
                       discovery_port=54321,
                       event_port=8989))
示例#2
0
 def probe(self, url):
     _debug('probing new url: %s', url)
     with _prdb_kh.lock:
         o = kodinhenki.wemo.device.from_url(url)
         if not o: return
         if self.event_receiver is not None:
             full_url = urljoin(url, o.services['basicevent'].event_sub_url)
             s = event.Subscription(full_url, self.event_receiver)
             updater.add(s)
             # Even if we reuse the object (and we should
             # have only one device per physical object), re-probing
             # should not duplicate subscriptions. So kill the subscription.
             if o._subscription:
                 updater.remove(o._subscription)
             o._subscription = s
         self._devices[url] = {'o': o}
         return o
示例#3
0
 def probe(self, url):
     _debug('probing new url: %s', url)
     with _prdb_kh.lock:
         o = kodinhenki.wemo.device.from_url(url)
         if not o: return
         if self.event_receiver is not None:
             full_url = urljoin(url, o.services['basicevent'].event_sub_url)
             s = event.Subscription(full_url, self.event_receiver)
             updater.add(s)
             # Even if we reuse the object (and we should
             # have only one device per physical object), re-probing
             # should not duplicate subscriptions. So kill the subscription.
             if o._subscription:
                 updater.remove(o._subscription)
             o._subscription = s
         self._devices[url] = {'o': o}
         return o
示例#4
0
def test_updater():
    m = Mock()
    class ShortWaiter(updater.Updated):
        def next_update_in_seconds(self):
            return DELAY
        def update(self):
            m()
    sw = ShortWaiter()

    updater.add(sw)
    assert not updater.is_empty()
    assert not m.called
    time.sleep(DELAY * 2)
    assert m.called
    updater.remove(sw)
    assert updater.is_empty()

    updater.add(sw)
    updater.remove_all()
    assert updater.is_empty()
示例#5
0
def test_updater():
    m = Mock()

    class ShortWaiter(updater.Updated):
        def next_update_in_seconds(self):
            return DELAY

        def update(self):
            m()

    sw = ShortWaiter()

    updater.add(sw)
    assert not updater.is_empty()
    assert not m.called
    time.sleep(DELAY * 2)
    assert m.called
    updater.remove(sw)
    assert updater.is_empty()

    updater.add(sw)
    updater.remove_all()
    assert updater.is_empty()
示例#6
0
def start():
    import kodinhenki.hue as hue
    import kodinhenki.mpower as mpower
    import kodinhenki.owrt_wifi as _owrt_wifi

    # Start database (implicitly on the hardcoded port + any ip)
    sync.start()

    # Start the devices
    updater.add(hue.get_updater('192.168.44.10'))

    updater.add(mpower.get_updater('192.168.44.21', 'pro'))
    updater.add(mpower.get_updater('192.168.44.20', 'mini'))

    # WeMo is dead, baby!
    # start_wemo()

    if is_cer:
        # We're CER => can check locally wifi state
        _owrt_wifi.start()
示例#7
0
    h.some_object_changed()


if __name__ == '__main__':
    p = khserver.create_shared_argparser('start')
    args = khserver.parse_shared(p)

    _prdb_kh.Home.set_create_owner_instance_callback(Home)
    _debug('creating official database instance')
    db = kh.get_database()
    # Autorotate > megabyte sized ones
    if not os.path.exists(LOGDIR):
        os.mkdir(LOGDIR)
    logger = db.new_logger_to_directory(LOGDIR, autorotate=1000000)
    h = _prdb_kh.Home.new_named().get_owner()
    db.object_added.connect(_object_added)
    db.object_changed.connect(_object_changed)

    # Up to this point we do not have threads really running, so start
    # caring about locking only now..
    _prdb_kh.set_lock_check_enabled(True)

    with _prdb_kh.lock:
        khserver.start()
        if socket.gethostname() == 'poro.lan':
            poroserver.start()

    updater.add(h)

    # threads will implicitly do their stuff ..
示例#8
0
def start(name, **kw):
    u = LightSensor(name, **kw)
    _updater.add(u)
    return u
示例#9
0
def start(d, **kw):
    _debug('starting process %s', repr(d))
    m = ProcessMonitor(d, **kw)
    updater.add(m)
    return m
示例#10
0
    h.some_object_changed()


if __name__ == '__main__':
    p = khserver.create_shared_argparser('start')
    args = khserver.parse_shared(p)

    _prdb_kh.Home.set_create_owner_instance_callback(Home)
    _debug('creating official database instance')
    db = kh.get_database()
    # Autorotate > megabyte sized ones
    if not os.path.exists(LOGDIR):
        os.mkdir(LOGDIR)
    logger = db.new_logger_to_directory(LOGDIR, autorotate=1000000)
    h = _prdb_kh.Home.new_named().get_owner()
    db.object_added.connect(_object_added)
    db.object_changed.connect(_object_changed)

    # Up to this point we do not have threads really running, so start
    # caring about locking only now..
    _prdb_kh.set_lock_check_enabled(True)

    with _prdb_kh.lock:
        khserver.start()
        if socket.gethostname() == 'poro.lan':
            poroserver.start()

    updater.add(h)

    # threads will implicitly do their stuff ..
示例#11
0
def start(**kwargs):
    u = OpenWrtWifiDeviceTracker(**kwargs)
    _updater.add(u)
    return u
示例#12
0
def start(**kwargs):
    u = OpenWrtWifiDeviceTracker(**kwargs)
    _updater.add(u)
    return u