def _handle_pipeline_event(self, event): """ Pipeline Event handler function to convert incoming MQTT messages into the appropriate DPS events, based on the topic of the message """ if isinstance(event, pipeline_events_mqtt.IncomingMQTTMessageEvent): topic = event.topic if mqtt_topic_provisioning.is_dps_response_topic(topic): logger.debug( "Received payload:{payload} on topic:{topic}".format( payload=event.payload, topic=topic)) key_values = mqtt_topic_provisioning.extract_properties_from_dps_response_topic( topic) retry_after = key_values.get("retry-after", None) status_code = mqtt_topic_provisioning.extract_status_code_from_dps_response_topic( topic) request_id = key_values["rid"] self.send_event_up( pipeline_events_base.ResponseEvent( request_id=request_id, status_code=int(status_code, 10), response_body=event.payload, retry_after=retry_after, )) else: logger.debug( "Unknown topic: {} passing up to next handler".format( topic)) self.send_event_up(event) else: # all other messages get passed up self.send_event_up(event)
def test_is_not_dps_response_topic(self, topic): assert not mqtt_topic_provisioning.is_dps_response_topic(topic)