async def resolve_devices(self, info, pattern="*"): """ This method fetches all the devices using the pattern. :param pattern: Pattern for filtering the result. Returns only properties that matches the pattern. :type pattern: str :return: List of devices. :rtype: List of Device """ device_names = db.get_device_exported(pattern) return [Device(name=name) for name in device_names]
def resolve_classes(self, info, pattern="*"): devs_clss = db.get_device_class_list(f"{self.server}/{self.name}") mapping = defaultdict(list) rule = re.compile(fnmatch.translate(pattern), re.IGNORECASE) for device, clss in zip(devs_clss[::2], devs_clss[1::2]): mapping[clss].append(Device(name=device)) return [DeviceClass(name=clss, server=self.server, instance=self.name, devices=devices) for clss, devices in mapping.items() if rule.match(clss)]
async def resolve_device(self, info, name=None): """ This method fetches the device using the name. :param name: Name of the device. :type name: str :return: Device. :rtype: Device """ device_names = db.get_device_exported(name) if len(device_names) == 1: return Device(name=device_names[0]) else: return None