From f5676fabea8a09f5702d00e75f3cf55f01ed5b22 Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Wed, 3 Apr 2019 14:21:54 +0000 Subject: [PATCH] [IMP] hw_driver: inform the odoo instance of connected and disconnected devices Before this commit, we only sent the list of connected devices to the odoo instance (thanks to `self.send_alldevices`) when a device is newly connected. Now, we also send this list when a device is disconnected. We also try to call this method once if multiple devices are connected/disconnected during an iteration. task-id 1939338 closes odoo/odoo#32678 Signed-off-by: Quentin Lejeune (qle) --- addons/hw_drivers/controllers/driver.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/hw_drivers/controllers/driver.py b/addons/hw_drivers/controllers/driver.py index 9d238227a38..4ed79871083 100755 --- a/addons/hw_drivers/controllers/driver.py +++ b/addons/hw_drivers/controllers/driver.py @@ -359,18 +359,23 @@ class Manager(Thread): added = updated_devices.keys() - devices.keys() removed = devices.keys() - updated_devices.keys() devices = updated_devices + send_devices = False for path in [device_rm for device_rm in removed if device_rm in iot_devices]: iot_devices[path].disconnect() + _logger.info('Device %s is now disconnected', path) + send_devices = True for path in [device_add for device_add in added if device_add not in iot_devices]: for driverclass in [d for d in drivers if d.connection_type == devices[path].connection_type]: if driverclass.supported(device = updated_devices[path].dev): - _logger.info('For device %s will be driven', path) + _logger.info('Device %s is now connected', path) d = driverclass(device = updated_devices[path].dev) d.daemon = True d.start() iot_devices[path] = d - self.send_alldevices() + send_devices = True break + if send_devices: + self.send_alldevices() time.sleep(3) class GattBtManager(Gatt_DeviceManager):