diff --git a/__test__/devices/test_my_powerplug.py b/__test__/devices/test_my_powerplug.py index e08dd94..4a289e7 100644 --- a/__test__/devices/test_my_powerplug.py +++ b/__test__/devices/test_my_powerplug.py @@ -1,6 +1,6 @@ from module import mqtt_test_client, init_state, state_change_by_mqtt from devices import my_powerplug as test_device -from devices import warning +from devices.base import warning from mqtt import mqtt_client import pytest import time diff --git a/__test__/devices/test_shelly.py b/__test__/devices/test_shelly.py index e345ed3..ed83bea 100644 --- a/__test__/devices/test_shelly.py +++ b/__test__/devices/test_shelly.py @@ -1,6 +1,6 @@ from module import mqtt_test_client, init_state, state_change_by_mqtt -from devices import shelly as test_device -from devices import warning +from devices import shelly_sw1 as test_device +from devices.base import warning from mqtt import mqtt_client import pytest import time diff --git a/__test__/devices/test_silvercrest_motion_sensor.py b/__test__/devices/test_silvercrest_motion_sensor.py index 4251d37..ca0f5cc 100644 --- a/__test__/devices/test_silvercrest_motion_sensor.py +++ b/__test__/devices/test_silvercrest_motion_sensor.py @@ -1,6 +1,6 @@ from module import mqtt_test_client, init_state, state_change_by_mqtt from devices import silvercrest_motion_sensor as test_device -from devices import warning +from devices.base import warning from mqtt import mqtt_client import pytest import time diff --git a/__test__/devices/test_silvercrest_powerplug.py b/__test__/devices/test_silvercrest_powerplug.py index 5925ea9..55e1229 100644 --- a/__test__/devices/test_silvercrest_powerplug.py +++ b/__test__/devices/test_silvercrest_powerplug.py @@ -1,6 +1,6 @@ from module import mqtt_test_client, init_state, state_change_by_mqtt from devices import silvercrest_powerplug as test_device -from devices import warning +from devices.base import warning from mqtt import mqtt_client import pytest import time diff --git a/devices/__init__.py b/devices/__init__.py index e0bd89c..9e7491b 100644 --- a/devices/__init__.py +++ b/devices/__init__.py @@ -100,24 +100,3 @@ class group(object): return getattr(self[0], name) else: return rv - - -class warning(dict): - TYPE_BATTERY_LOW = 1 - TYPE_OVERTEMPERATURE = 2 - # - KEY_ID = 'id' - KEY_TYPE = 'type' - KEY_TEXT = 'text' - KEY_TM = 'tm' - - def __init__(self, identification, type, text, args): - super().__init__({ - self.KEY_ID: identification, - self.KEY_TYPE: type, - self.KEY_TEXT: text % args, - self.KEY_TM: time.localtime(), - }) - - def __str__(self): - return time.asctime(self.get(self.KEY_TM)) + ": " + self[self.KEY_TEXT] + " - " + self[self.KEY_ID] diff --git a/devices/base.py b/devices/base.py index 6107e0a..5fc9c6e 100644 --- a/devices/base.py +++ b/devices/base.py @@ -4,6 +4,7 @@ from base import mqtt_base from base import videv_base import json +import time BATTERY_WARN_LEVEL = 10 @@ -102,3 +103,24 @@ class base(mqtt_base): self.mqtt_client.send('/'.join([self.topic, key, self.TX_TOPIC] if len(self.TX_TOPIC) > 0 else [self.topic, key]), data) else: self.logger.error("Unknown tx toptic. Set TX_TOPIC of class to a known value") + + +class warning(dict): + TYPE_BATTERY_LOW = 1 + TYPE_OVERTEMPERATURE = 2 + # + KEY_ID = 'id' + KEY_TYPE = 'type' + KEY_TEXT = 'text' + KEY_TM = 'tm' + + def __init__(self, identification, type, text, args): + super().__init__({ + self.KEY_ID: identification, + self.KEY_TYPE: type, + self.KEY_TEXT: text % args, + self.KEY_TM: time.localtime(), + }) + + def __str__(self): + return time.asctime(self.get(self.KEY_TM)) + ": " + self[self.KEY_TEXT] + " - " + self[self.KEY_ID] diff --git a/devices/brennenstuhl.py b/devices/brennenstuhl.py index 48ebb70..c76b8b8 100644 --- a/devices/brennenstuhl.py +++ b/devices/brennenstuhl.py @@ -3,6 +3,7 @@ # from devices.base import base from devices.base import BATTERY_WARN_LEVEL +from devices.base import warning import json diff --git a/devices/shelly.py b/devices/shelly.py index 8870ad3..03117fb 100644 --- a/devices/shelly.py +++ b/devices/shelly.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # from devices.base import base +from devices.base import warning import logging import task diff --git a/devices/silvercrest.py b/devices/silvercrest.py index db931f5..593fa13 100644 --- a/devices/silvercrest.py +++ b/devices/silvercrest.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- # from devices.base import base +from devices.base import warning import logging diff --git a/devices/tradfri.py b/devices/tradfri.py index 6b4453b..05045ce 100644 --- a/devices/tradfri.py +++ b/devices/tradfri.py @@ -3,6 +3,7 @@ # from devices.base import base from devices.base import BATTERY_WARN_LEVEL +from devices.base import warning import logging