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 load_iot_handlers(self): """ This method loads local files: 'odoo/addons/hw_drivers/iot_handlers/drivers' and 'odoo/addons/hw_drivers/iot_handlers/interfaces' And execute these python drivers and interfaces """ helpers.download_iot_handlers() for directory in ['interfaces', 'drivers']: path = get_resource_path('hw_drivers', 'iot_handlers', directory) filesList = os.listdir(path) for file in filesList: path_file = os.path.join(path, file) spec = util.spec_from_file_location(file, path_file) if spec: module = util.module_from_spec(spec) spec.loader.exec_module(module) http.addons_manifest = {} http.root = http.Root()
def load_iot_handlers(self): helpers.download_iot_handlers(False) subprocess.check_call(["sudo", "service", "odoo", "restart"]) return "<meta http-equiv='refresh' content='20; url=http://" + helpers.get_ip() + ":8069/list_handlers'>"