2022-12-19 10:35:20 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
"""
|
|
|
|
devices (DEVICES)
|
2022-12-20 19:38:57 +01:00
|
|
|
=================
|
2022-12-19 10:35:20 +01:00
|
|
|
|
|
|
|
**Author:**
|
|
|
|
|
|
|
|
* Dirk Alders <sudo-dirk@mount-mockery.de>
|
|
|
|
|
|
|
|
**Description:**
|
|
|
|
|
|
|
|
This Module supports smarthome devices
|
|
|
|
|
|
|
|
**Submodules:**
|
|
|
|
|
|
|
|
* :mod:`shelly`
|
|
|
|
* :mod:`silvercrest_powerplug`
|
|
|
|
|
|
|
|
**Unittest:**
|
|
|
|
|
|
|
|
See also the :download:`unittest <devices/_testresults_/unittest.pdf>` documentation.
|
|
|
|
|
|
|
|
**Module Documentation:**
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
from config import APP_NAME as ROOT_LOGGER_NAME
|
|
|
|
except ImportError:
|
|
|
|
ROOT_LOGGER_NAME = 'root'
|
|
|
|
|
2023-10-29 15:10:06 +01:00
|
|
|
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
|
2024-09-01 12:49:42 +02:00
|
|
|
my_ambient = None
|
2022-12-19 10:35:20 +01:00
|
|
|
|
|
|
|
|
2023-01-25 07:40:33 +01:00
|
|
|
class group(object):
|
|
|
|
def __init__(self, *args):
|
|
|
|
super().__init__()
|
|
|
|
self._members = args
|
|
|
|
self._iter_counter = 0
|
|
|
|
#
|
|
|
|
self.methods = []
|
2023-10-29 15:10:06 +01:00
|
|
|
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)
|
2023-01-25 07:40:33 +01:00
|
|
|
#
|
|
|
|
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:
|
2023-10-29 15:10:06 +01:00
|
|
|
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)
|
2023-01-25 07:40:33 +01:00
|
|
|
|
|
|
|
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:
|
2023-10-29 15:10:06 +01:00
|
|
|
if callable(getattr(self[0], name)):
|
|
|
|
return group_execution
|
2022-12-19 10:35:20 +01:00
|
|
|
else:
|
2023-10-29 15:10:06 +01:00
|
|
|
return getattr(self[0], name)
|
2022-12-19 10:35:20 +01:00
|
|
|
else:
|
2023-10-29 15:10:06 +01:00
|
|
|
return rv
|