Exemplo n.º 1
0
    def handle_push_notification(self, namespace, payload, from_myself=False):
        # Handle the ONLINE push notification
        # Leave the rest to the specific implementation
        if namespace == ONLINE:
            old_online_status = self.online
            status = payload['online']['status']
            if status == 2:
                with self._state_lock:
                    self.online = False
            elif status == 1:
                with self._state_lock:
                    self.online = True
            else:
                l.error(
                    "Unknown online status has been reported from the device: %d"
                    % status)

            # If the online status changed, fire the corresponding event
            if old_online_status != self.online:
                evt = DeviceOnlineStatusEvent(self, self.online)
                self.fire_event(evt)
        else:
            self._handle_push_notification(namespace,
                                           payload,
                                           from_myself=from_myself)
Exemplo n.º 2
0
    def handle_push_notification(self, namespace, payload, from_myself=False):
        # Handle the ONLINE push notification
        # Leave the rest to the specific implementation
        if namespace == ONLINE:
            old_online_status = self.online
            status = int(payload['online']['status'])
            if status == 2:
                with self._state_lock:
                    self.online = False
            elif status == 1:
                with self._state_lock:
                    self.online = True
            else:
                l.error(
                    "Unknown online status has been reported from the device: %d"
                    % status)

            # If the online status changed, fire the corresponding event
            if old_online_status != self.online:
                evt = DeviceOnlineStatusEvent(self, self.online)
                self.fire_event(evt)
        elif namespace == BIND:
            data = payload['bind']
            evt = DeviceBindEvent(device=self, bind_data=data)
            self.fire_event(evt)
        elif namespace == UNBIND:
            # Let everybody know we are going down before doing anything
            evt = DeviceUnbindEvent(device=self)
            self.fire_event(evt)
            # Let's handle stat clearing and resource release
            self._handle_unbound()
        else:
            self._handle_push_notification(namespace,
                                           payload,
                                           from_myself=from_myself)
Exemplo n.º 3
0
 def get_wifi_list(self):
     if WIFI_LIST in self.get_abilities():
         return self.execute_command("GET",
                                     WIFI_LIST, {},
                                     timeout=LONG_TIMEOUT)
     else:
         l.error("This device does not support the WIFI_LIST ability")
         return None
Exemplo n.º 4
0
 def get_debug(self):
     if DEBUG in self.get_abilities():
         return self.execute_command("GET", DEBUG, {})
     else:
         l.error("This device does not support the DEBUG ability")
         return None
Exemplo n.º 5
0
 def get_trace(self):
     if TRACE in self.get_abilities():
         return self.execute_command("GET", TRACE, {})
     else:
         l.error("This device does not support the TRACE ability")
         return None