#!/usr/bin/env python # -*- coding: utf-8 -*- # """ devices (DEVICES) ================= **Author:** * Dirk Alders **Description:** This Module supports smarthome devices **Submodules:** * :mod:`shelly` * :mod:`silvercrest_powerplug` **Unittest:** See also the :download:`unittest ` documentation. **Module Documentation:** """ try: from config import APP_NAME as ROOT_LOGGER_NAME except ImportError: ROOT_LOGGER_NAME = 'root' from devices.shelly import shelly as shelly_sw1 from devices.tradfri import tradfri_light as tradfri_sw from devices.tradfri import tradfri_light as tradfri_sw_br from devices.tradfri import tradfri_light as tradfri_sw_br_ct from devices.tradfri import tradfri_button as tradfri_button from devices.tradfri import tradfri_light as livarno_sw_br_ct from devices.brennenstuhl import brennenstuhl_heatingvalve from devices.silvercrest import silvercrest_powerplug from devices.silvercrest import silvercrest_motion_sensor from devices.mydevices import powerplug as my_powerplug from devices.mydevices import audio_status from devices.mydevices import remote class group(object): def __init__(self, *args): super().__init__() self._members = args self._iter_counter = 0 # self.methods = [] self.variables = [] for name in [m for m in args[0].__class__.__dict__.keys()]: if not name.startswith('_') and callable(getattr(args[0], name)): # add all public callable attributes to the list self.methods.append(name) if not name.startswith('_') and not callable(getattr(args[0], name)): # add all public callable attributes to the list self.variables.append(name) # for member in self: methods = [m for m in member.__class__.__dict__.keys() if not m.startswith( '_') if not m.startswith('_') and callable(getattr(args[0], m))] if self.methods != methods: raise ValueError("All given instances needs to have same methods:", self.methods, methods) # variables = [v for v in member.__class__.__dict__.keys() if not v.startswith( '_') if not v.startswith('_') and not callable(getattr(args[0], v))] if self.variables != variables: raise ValueError("All given instances needs to have same variables:", self.variables, variables) def __iter__(self): return self def __next__(self): if self._iter_counter < len(self): self._iter_counter += 1 return self._members[self._iter_counter - 1] self._iter_counter = 0 raise StopIteration def __getitem__(self, i): return self._members[i] def __len__(self): return len(self._members) def __getattribute__(self, name): def group_execution(*args, **kwargs): for member in self[:]: m = getattr(member, name) m(*args, **kwargs) try: rv = super().__getattribute__(name) except AttributeError: if callable(getattr(self[0], name)): return group_execution else: return getattr(self[0], name) else: return rv