Esempio n. 1
0
    def subscribe(self, callback, mode=None, granularity=1):
        self.hub.send(
            MsgHubProperties(MsgHubProperties.BUTTON,
                             MsgHubProperties.UPD_ENABLE))

        if callback:
            self._subscribers.add(callback)
Esempio n. 2
0
    def unsubscribe(self, callback=None):
        if callback in self._subscribers:
            self._subscribers.remove(callback)

        if not self._subscribers:
            self.hub.send(
                MsgHubProperties(MsgHubProperties.BUTTON,
                                 MsgHubProperties.UPD_DISABLE))
Esempio n. 3
0
    def test_hub_properties(self):
        conn = ConnectionMock().connect()
        hub = Hub(conn)

        conn.notification_delayed('060001060600', 0.1)
        msg = MsgHubProperties(MsgHubProperties.VOLTAGE_PERC,
                               MsgHubProperties.UPD_REQUEST)
        resp = hub.send(msg)
        assert isinstance(resp, MsgHubProperties)
        self.assertEqual(1, len(resp.parameters))
        self.assertEqual(0, usbyte(resp.parameters, 0))

        conn.notification_delayed('12000101064c45474f204d6f766520487562', 0.1)
        msg = MsgHubProperties(MsgHubProperties.ADVERTISE_NAME,
                               MsgHubProperties.UPD_REQUEST)
        resp = hub.send(msg)
        assert isinstance(resp, MsgHubProperties)
        self.assertEqual(b"LEGO Move Hub", resp.parameters)

        conn.wait_notifications_handled()