def _onAppStatus(self, client, userdata, pahoMessage): """ Internal callback for application command messages, parses source application from topic string and passes the information on to the registerd applicaion status callback """ try: status = Status(pahoMessage) self.logger.debug("Received %s action from %s" % (status.action, status.clientId)) if self.appStatusCallback: self.appStatusCallback(status) except InvalidEventException as e: self.logger.critical(str(e))
def __init__(self, config, logHandlers=None): self._config = ApplicationClientConfig(**config) # Call parent constructor AbstractClient.__init__( self, domain=self._config.domain, organization=self._config.orgId, clientId=self._config.clientId, username=self._config.username, password=self._config.password, logHandlers=logHandlers, cleanStart=self._config.cleanStart, port=self._config.port, transport=self._config.transport, ) # Add handlers for events and status self.client.message_callback_add("iot-2/type/+/id/+/evt/+/fmt/+", self._onDeviceEvent) self.client.message_callback_add("iot-2/type/+/id/+/mon", self._onDeviceStatus) self.client.message_callback_add("iot-2/app/+/mon", self._onAppStatus) # Add handler for commands if not connected to QuickStart if not self._config.isQuickstart(): self.client.message_callback_add("iot-2/type/+/id/+/cmd/+/fmt/+", self._onDeviceCommand) # Attach fallback handler self.client.on_message = self._onUnsupportedMessage # Initialize user supplied callbacks self.deviceEventCallback = None self.deviceCommandCallback = None self.deviceStatusCallback = None self.appStatusCallback = None # Create an api client if not connected in QuickStart mode if not self._config.isQuickstart(): apiClient = ApiClient(self._config, self.logger) self.registry = Registry(apiClient) self.status = Status(apiClient) self.usage = Usage(apiClient) self.dsc = DSC(apiClient) self.lec = LEC(apiClient) self.mgmt = Mgmt(apiClient) self.serviceBindings = ServiceBindings(apiClient) self.actions = Actions(apiClient) self.state = StateMgr(apiClient)