Control for Window lights
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

__init__.py 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. devices (DEVICES)
  6. =================
  7. **Author:**
  8. * Dirk Alders <sudo-dirk@mount-mockery.de>
  9. **Description:**
  10. This Module supports smarthome devices
  11. **Submodules:**
  12. * :mod:`shelly`
  13. * :mod:`silvercrest_powerplug`
  14. **Unittest:**
  15. See also the :download:`unittest <devices/_testresults_/unittest.pdf>` documentation.
  16. **Module Documentation:**
  17. """
  18. try:
  19. from config import APP_NAME as ROOT_LOGGER_NAME
  20. except ImportError:
  21. ROOT_LOGGER_NAME = 'root'
  22. from devices.shelly import shelly as shelly_sw1
  23. from devices.tradfri import tradfri_light as tradfri_sw
  24. from devices.tradfri import tradfri_light as tradfri_sw_br
  25. from devices.tradfri import tradfri_light as tradfri_sw_br_ct
  26. from devices.tradfri import tradfri_button as tradfri_button
  27. from devices.tradfri import tradfri_light as livarno_sw_br_ct
  28. from devices.brennenstuhl import brennenstuhl_heatingvalve
  29. from devices.silvercrest import silvercrest_powerplug
  30. from devices.silvercrest import silvercrest_motion_sensor
  31. from devices.mydevices import powerplug as my_powerplug
  32. from devices.mydevices import audio_status
  33. from devices.mydevices import remote
  34. my_ambient = None
  35. class group(object):
  36. def __init__(self, *args):
  37. super().__init__()
  38. self._members = args
  39. self._iter_counter = 0
  40. #
  41. self.methods = []
  42. self.variables = []
  43. for name in [m for m in args[0].__class__.__dict__.keys()]:
  44. if not name.startswith('_') and callable(getattr(args[0], name)): # add all public callable attributes to the list
  45. self.methods.append(name)
  46. if not name.startswith('_') and not callable(getattr(args[0], name)): # add all public callable attributes to the list
  47. self.variables.append(name)
  48. #
  49. for member in self:
  50. methods = [m for m in member.__class__.__dict__.keys() if not m.startswith(
  51. '_') if not m.startswith('_') and callable(getattr(args[0], m))]
  52. if self.methods != methods:
  53. raise ValueError("All given instances needs to have same methods:", self.methods, methods)
  54. #
  55. variables = [v for v in member.__class__.__dict__.keys() if not v.startswith(
  56. '_') if not v.startswith('_') and not callable(getattr(args[0], v))]
  57. if self.variables != variables:
  58. raise ValueError("All given instances needs to have same variables:", self.variables, variables)
  59. def __iter__(self):
  60. return self
  61. def __next__(self):
  62. if self._iter_counter < len(self):
  63. self._iter_counter += 1
  64. return self._members[self._iter_counter - 1]
  65. self._iter_counter = 0
  66. raise StopIteration
  67. def __getitem__(self, i):
  68. return self._members[i]
  69. def __len__(self):
  70. return len(self._members)
  71. def __getattribute__(self, name):
  72. def group_execution(*args, **kwargs):
  73. for member in self[:]:
  74. m = getattr(member, name)
  75. m(*args, **kwargs)
  76. try:
  77. rv = super().__getattribute__(name)
  78. except AttributeError:
  79. if callable(getattr(self[0], name)):
  80. return group_execution
  81. else:
  82. return getattr(self[0], name)
  83. else:
  84. return rv