def __event_handler(self, event): if event._opcode == Event.PROV_UNPROVISIONED_RECEIVED: uuid = event._data["uuid"] rssi = event._data["rssi"] if uuid not in self.unprov_list: self.logger.info("Received UUID {} with RSSI: {} dB".format( uuid.hex(), rssi)) self.unprov_list.append(uuid) elif event._opcode == Event.PROV_CAPS_RECEIVED: element_count = event._data["num_elements"] self.logger.info("Received capabilities") self.logger.info("Number of elements: {}".format(element_count)) self.iaci.send( cmd.OobUse(event._data["context_id"], OOBMethod.NONE, 0, 0)) self.__session_data["elements"] = [ mt.Element(i) for i in range(element_count) ] elif event._opcode == Event.PROV_COMPLETE: num_elements = len(self.__session_data["elements"]) address_range = "{}-{}".format( hex(event._data["address"]), hex(event._data["address"] + num_elements - 1)) self.logger.info("Provisioning complete") self.logger.info("\tAddress(es): " + address_range) self.logger.info("\tDevice key: {}".format( event._data["device_key"].hex())) self.logger.info("\tNetwork key: {}".format( event._data["net_key"].hex())) self.logger.info("Adding device key to subnet %d", event._data["net_key_index"]) # Devkey added to subnet 0. self.iaci.send( cmd.DevkeyAdd(event._data["address"], 0, event._data["device_key"])) self.logger.info("Adding publication address of root element") self.iaci.send(cmd.AddrPublicationAdd(event._data["address"])) self.__session_data["device_key"] = event._data["device_key"] self.store(self.__session_data) # Update address to the next in range self.__next_free_address += num_elements else: self.default_handler(event)
def __event_handler(self, event): if event._opcode == Event.PROV_UNPROVISIONED_RECEIVED: if event._data not in self.__unprov_list: uuid_fmt = str(hexlify(event._data["uuid"]), 'ascii').upper() self.logger.info("Received UUID {} with RSSI: -{} dB".format( uuid_fmt, event._data["rssi"])) self.__unprov_list.add(event._data) elif event._opcode == Event.PROV_CAPS_RECEIVED: self.logger.info("Received capabilities") self.logger.info("Number of elements: {}".format( str(event._data["num_elements"]))) self.__caps[event._data["context_id"]] = event._data self.iaci.send( cmd.OobUse(event._data["context_id"], OOBMethod.NONE, 0)) elif event._opcode == Event.PROV_COMPLETE: caps = self.__caps[event._data["context_id"]] num_elements = caps["num_elements"] address_range = "{}-{}".format( hex(event._data["address"]), hex(event._data["address"] + num_elements - 1)) self.logger.info("Provisioning complete") self.logger.info("\tAddress(es): " + address_range) self.logger.info("\tDevice key: {}".format( str(hexlify(event._data["device_key"]), "ascii").upper())) self.logger.info("\tNetwork key: {}".format( str(hexlify(event._data["net_key"]), "ascii").upper())) self.logger.info("Adding device key to subnet 0") # Devkey added to subnet 0. self.iaci.send( cmd.DevkeyAdd(event._data["address"], 0, event._data["device_key"])) self.logger.info("Adding publication address(es)") for i in range(0, num_elements): self.iaci.send( cmd.AddrPublicationAdd(event._data["address"] + i)) # Update address to the next in range self.__prov_data["address"] += num_elements else: self.default_handler(event)