def run(self): """ Thread that will load interfaces and drivers and contact the odoo server with the updates """ helpers.check_git_branch() helpers.check_certificate() # We first add the IoT Box to the connected DB because IoT handlers cannot be downloaded if # the identifier of the Box is not found in the DB. So add the Box to the DB. self.send_alldevices() helpers.download_iot_handlers() helpers.load_iot_handlers() # Start the interfaces for interface in interfaces.values(): i = interface() i.daemon = True i.start() # Check every 3 secondes if the list of connected devices has changed and send the updated # list to the connected DB. self.previous_iot_devices = [] while 1: try: if iot_devices != self.previous_iot_devices: self.send_alldevices() self.previous_iot_devices = iot_devices.copy() time.sleep(3) except: # No matter what goes wrong, the Manager loop needs to keep running _logger.error(format_exc())
def run(self): """ Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates """ helpers.check_git_branch() helpers.check_certificate() updated_devices = {} self.send_alldevices() self.load_drivers() # The list of devices doesn't change after the Raspberry has booted display_devices = self.get_connected_displays() cpt = 0 while 1: try: updated_devices = self.usb_loop() updated_devices.update(self.video_loop()) updated_devices.update(mpdm.devices) updated_devices.update(display_devices) updated_devices.update(bt_devices) updated_devices.update(socket_devices) updated_devices.update(self.serial_loop()) if cpt % 40 == 0: printer_devices = self.printer_loop() cpt = 0 updated_devices.update(printer_devices) cpt += 1 added = updated_devices.keys() - self.devices.keys() removed = self.devices.keys() - updated_devices.keys() self.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 == self.devices[path].connection_type]: if driverclass.supported(device = updated_devices[path].dev): _logger.info('Device %s is now connected', path) d = driverclass(device = updated_devices[path].dev) d.daemon = True iot_devices[path] = d # Start the thread after creating the iot_devices entry so the # thread can assume the iot_devices entry will exist while it's # running, at least until the `disconnect` above gets triggered # when `removed` is not empty. Threads are currently not # explicitly terminated when that happens, so the results can # be undefined. d.start() send_devices = True break if send_devices: self.send_alldevices() time.sleep(3) except: # No matter what goes wrong, the Manager loop needs to keep running _logger.error(format_exc())
def run(self): """ Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates """ helpers.check_git_branch() helpers.check_certificate() updated_devices = {} self.send_alldevices() self.load_drivers() # The list of devices doesn't change after the Raspberry has booted display_devices = self.get_connected_displays() cpt = 0 while 1: updated_devices = self.usb_loop() updated_devices.update(self.video_loop()) updated_devices.update(mpdm.devices) updated_devices.update(display_devices) updated_devices.update(bt_devices) updated_devices.update(socket_devices) updated_devices.update(self.serial_loop()) if cpt % 40 == 0: printer_devices = self.printer_loop() cpt = 0 updated_devices.update(printer_devices) cpt += 1 added = updated_devices.keys() - self.devices.keys() removed = self.devices.keys() - updated_devices.keys() self.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 == self.devices[path].connection_type ]: if driverclass.supported(device=updated_devices[path].dev): _logger.info('Device %s is now connected', path) d = driverclass(device=updated_devices[path].dev) d.daemon = True d.start() iot_devices[path] = d send_devices = True break if send_devices: self.send_alldevices() time.sleep(3)
def run(self): """ Thread that will check connected/disconnected device, load drivers if needed and contact the odoo server with the updates """ helpers.check_git_branch() helpers.check_certificate() self.send_alldevices() self.load_iot_handlers() self.previous_iot_devices = [] for interface in interfaces.values(): i = interface() i.daemon = True i.start() while 1: if iot_devices != self.previous_iot_devices: self.send_alldevices() self.previous_iot_devices = iot_devices.copy() time.sleep(3)