def render_DELETE(self, request): logger.info("RD: DELETE to /rd from {host}:{port}".format( host=request.source[0], port=request.source[1])) DB.DB.remove_endpoint() device = device_translator.convert_to_device_instance(informations) Client.delete(device) return True
def _evaluate(self, unknown_devices): missing_devices, new_devices = self._diff(device_pool.DevicePool.devices(), unknown_devices) if missing_devices: logger.info(str(len(new_devices)) + " devices were deleted on OpenHAB") for device in missing_devices: Client.delete(device) if new_devices: for device in new_devices: try: logger.info("Found device: '{}'".format(device.get("label"))) self.add_device(device) except Exception as e: logger.error(e)
def _evaluate(self, unknown_devices): missing_devices, new_devices, changed_devices = self._diff(__class__._known_devices, unknown_devices) if missing_devices: for missing_device_id in missing_devices: logger.info("can't find '{}' with id '{}'".format(__class__._known_devices[missing_device_id].get('label'), missing_device_id)) try: Client.delete(missing_device_id) except AttributeError: DevicePool.remove(missing_device_id) if new_devices: for new_device_id in new_devices: name = unknown_devices[new_device_id].get('label') logger.info("found '{}' with id '{}'".format(name, new_device_id)) device = Device(new_device_id, SEPL_DEVICE_TYPE, name) product = unknown_devices[new_device_id].get('product') device.addTag('type', 'Extended color light') device.addTag('product', product.get('name')) device.addTag('manufacturer', product.get('company')) try: Client.add(device) except AttributeError: DevicePool.add(device) if changed_devices: for changed_device_id in changed_devices: seconds_since_seen = unknown_devices[changed_device_id].get('seconds_since_seen') if seconds_since_seen >= 60: try: Client.disconnect(changed_device_id) except AttributeError: DevicePool.remove(changed_device_id) del unknown_devices[changed_device_id] else: device = DevicePool.get(changed_device_id) name = unknown_devices[changed_device_id].get('label') if not name == device.name: device.name = name try: Client.update(device) except AttributeError: DevicePool.update(device) logger.info("name of '{}' changed to {}".format(changed_device_id, name)) __class__._known_devices = unknown_devices
def _evaluate(self, unknown_devices): missing_devices, new_devices = self._diff(self._know_devices, unknown_devices) if missing_devices: for missing_device_id in missing_devices: logger.info("can't find '{}'".format(missing_device_id)) try: Client.delete(missing_device_id) except AttributeError: DevicePool.remove(missing_device_id) SessionManager.delRemoteDevice(missing_device_id) if new_devices: for new_device_id in new_devices: try: dyson_data = dyson_map[unknown_devices[new_device_id] ['ProductType']] dyson_device = DysonDevice( new_device_id, dyson_data['type'], dyson_data['name'], decrypt_password(unknown_devices[new_device_id] ['LocalCredentials']), unknown_devices[new_device_id]['ProductType'], unknown_devices[new_device_id]['ScaleUnit']) dyson_device.addTag('manufacturer', 'Dyson') count = '' for tag in dyson_data['tags']: dyson_device.addTag('type{}'.format(count), tag) if not count: count = 0 count = count + 1 logger.info("found '{}' with id '{}'".format( dyson_device.name, dyson_device.id)) SessionManager.addRemoteDevice(dyson_device) except KeyError: logger.error( "missing device data or malformed message - '{}'". format(unknown_devices[new_device_id])) self._know_devices = unknown_devices.keys()
if 4 in tests: time.sleep(0.5) logger.info('------ change name of existing device ------') device = device_manager.get(id_3) device.name = 'Dummy Smart Bulb' Client.update(device) if 5 in tests: time.sleep(0.5) logger.info('------ disconnect existing device ------') Client.disconnect(id_1) if 6 in tests: time.sleep(0.5) logger.info('------ delete existing device ------') Client.delete(id_3) if 7 in tests: time.sleep(0.5) logger.info('------ add new device ------') new_device = Device(id_4, 'iot#1740e97f-1ae1-4547-a757-a62018083d3f', 'Dummy Device 4') Client.add(new_device) if 8 in tests: time.sleep(0.5) logger.info('------ push 5 events ------') for event in range(5): data = json.dumps({'str_field': 'dummy event', 'int_field': event}) response = Client.event(id_4, 'dummy-event', data, 'dummy metadata {}'.format(event))