def _load_devices(self): #read devices from config #get device from app app = self.application parser = self._get_parser() ds = [] for dev in parser.get_elements('device'): name = dev.text.strip() dname = dev.find('name') if dname is None: self.warning( 'no device name for {}. use a <name> tag'.format(name)) continue dev_name = dname.text.strip() device = None if app: device = app.get_service(ICoreDevice, query='name=="{}"'.format(dev_name)) if device is None: self.warning( 'no device named "{}" available'.format(dev_name)) continue enabled = dev.find('use') if enabled is not None: enabled = to_bool(enabled.text.strip()) d = DashboardDevice(name=name, use=bool(enabled), _device=device) for v in dev.findall('value'): n = v.text.strip() tag = '<{},{}>'.format(name, n) func_name = self._get_xml_value(v, 'func', 'get') period = self._get_xml_value(v, 'period', 60) if not period == 'on_change': try: period = int(period) except ValueError: period = 60 enabled = to_bool(self._get_xml_value(v, 'enabled', False)) timeout = self._get_xml_value(v, 'timeout', 0) d.add_value(n, tag, func_name, period, enabled, timeout) ds.append(d) self.devices = ds
def _load_devices(self): # read devices from config # get device from app app = self.application parser = self._get_parser() ds = [] for dev in parser.get_elements("device"): name = dev.text.strip() dname = dev.find("name") if dname is None: self.warning("no device name for {}. use a <name> tag".format(name)) continue dev_name = dname.text.strip() device = None if app: device = app.get_service(ICoreDevice, query='name=="{}"'.format(dev_name)) if device is None: self.warning('no device named "{}" available'.format(dev_name)) continue enabled = dev.find("use") if enabled is not None: enabled = to_bool(enabled.text.strip()) d = DashboardDevice(name=name, use=bool(enabled), _device=device) for v in dev.findall("value"): n = v.text.strip() tag = "<{},{}>".format(name, n) func_name = self._get_xml_value(v, "func", "get") period = self._get_xml_value(v, "period", 60) if not period == "on_change": try: period = int(period) except ValueError: period = 60 enabled = to_bool(self._get_xml_value(v, "enabled", False)) timeout = self._get_xml_value(v, "timeout", 0) d.add_value(n, tag, func_name, period, enabled, timeout) ds.append(d) self.devices = ds
def _load_devices(self, dev_dicts): app = self.application ds = [] for dd in dev_dicts: name = dd['name'] dev_name = dd['device'] device = app.get_service(ICoreDevice, query='name=="{}"'.format(dev_name)) if device is None: self.warning('no device named "{}" available'.format(dev_name)) if globalv.dashboard_simulation: device = DummyDevice(name=dev_name) else: continue d = DashboardDevice(name=name, use=dd['enabled'], hardware_device=device) for args, cs in dd['values']: pv = d.add_value(**args) self.values.append(pv) for level, kw in cs: d.add_conditional(pv, level, **kw) d.setup_graph() ds.append(d) self.devices = ds