all off improved

This commit is contained in:
Dirk Alders 2023-01-26 10:40:56 +01:00
parent 43308d858e
commit d4c5411d47
2 changed files with 11 additions and 32 deletions

View File

@ -98,11 +98,6 @@ class all_functions(object):
rv.append(obj)
return rv
def common_off(self, device=None, key=None, data=None):
logger.info("Switching \"common\" off.")
for common in self.getmembers('common'):
common.all_off()
def gfw_off(self, device=None, key=None, data=None):
logger.info("Switching \"ground floor west\" off.")
for gfw in self.getmembers('gfw'):
@ -124,20 +119,7 @@ class all_functions(object):
stw.all_off()
def all_off(self, device=None, key=None, data=None):
self.common_off(device, key, data)
self.gfw_off(device, key, data)
self.ffw_off(device, key, data)
self.ffe_off(device, key, data)
self.stw_off(device, key, data)
def devicelist(self):
if self.__devices__ is None:
self.__devices__ = []
for name, obj in inspect.getmembers(self):
if obj.__class__.__module__ == "devices":
self.__devices__.append(obj)
elif obj.__class__.__module__.split('.')[0] == 'function':
for devicename, device in inspect.getmembers(obj):
if device.__class__.__module__ == "devices":
self.__devices__.append(device)
return self.__devices__
parent_name = obj.__class__.__base__.__name__
if parent_name == "room":
obj.all_off()

View File

@ -3,7 +3,7 @@
#
import logging
import task
import inspect
try:
from config import APP_NAME as ROOT_LOGGER_NAME
@ -11,11 +11,6 @@ except ImportError:
ROOT_LOGGER_NAME = 'root'
logger = logging.getLogger(ROOT_LOGGER_NAME).getChild(__name__)
# TODO: all_off: getattr and identify switchable devices switch those off (default method of device)
# - all devices are as attributes in the room class
# - implement a all_off blacklist to be initialised while __init__
# TODO: implement all off and user feedback method (all off save)
class room(object):
def __init__(self, mqtt_client):
@ -23,7 +18,9 @@ class room(object):
def all_off(self, device=None, key=None, data=None):
logger.info("Switching all off \"%s\"", type(self).__name__)
for name, obj in inspect.getmembers(self):
try:
self.main_light_shelly.all_off()
if obj.__module__ == 'devices':
obj.all_off()
except AttributeError:
logger.exception("Device self.main_light does not exist!")
pass # not a module or has no method all_off