def _notify(self, data):
     """Notify this channel of inbound data"""
     payload = tlv.decode(payload=data.get('payload'),
                          content_type=data.get('ct'),
                          decode_b64=True)
     super(CurrentResourceValue, self)._notify(payload)
     # after one response, close the channel
     self.ensure_stopped()
Пример #2
0
 def _notify(self, data):
     decoded = {}
     decoded.update(data)
     decoded['payload'] = tlv.decode(payload=data.get('payload'),
                                     content_type=data.get('ct'),
                                     decode_b64=True)
     for k, v in dict(ep='device_id', path='resource_path').items():
         if k in decoded:
             decoded[v] = decoded.pop(k, None)
     super(ResourceValues, self)._notify(decoded)
def handle_channel_message(db, queues, b64decode, notification_object):
    """Handler for notification channels

    Given a NotificationMessage object, update internal state, notify
    any subscribers and resolve async deferred tasks.

    :param db:
    :param queues:
    :param b64decode:
    :param notification_object:
    :return:
    """
    for notification in getattr(notification_object, 'notifications') or []:
        # Ensure we have subscribed for the path we received a notification for
        subscriber_queue = queues[notification.ep].get(notification.path)
        if subscriber_queue is None:
            LOG.warning(
                "Ignoring notification on %s (%s) as no subscription is registered",
                notification.ep,
                notification.path
            )
            break

        payload = tlv.decode(
            payload=notification.payload,
            content_type=notification.ct,
            decode_b64=b64decode
        )
        subscriber_queue.put(payload)

    for response in getattr(notification_object, 'async_responses') or []:
        payload = tlv.decode(
            payload=response.payload,
            content_type=response.ct,
            decode_b64=b64decode
        )
        db.update({response.id: dict(
            payload=payload,
            error=response.error,
            status_code=response.status
        )})