95 lines
3.6 KiB
Python
95 lines
3.6 KiB
Python
|
import config
|
||
|
import devices
|
||
|
import function
|
||
|
import inspect
|
||
|
import logging
|
||
|
import mqtt
|
||
|
import os
|
||
|
import report
|
||
|
import time
|
||
|
|
||
|
logger = logging.getLogger(config.APP_NAME)
|
||
|
|
||
|
|
||
|
class shellies(object):
|
||
|
def __init__(self, mc):
|
||
|
self.dinigroom = devices.shelly(mc, topic="shellies/diningroom") # http://shelly1l-84CCA8ADD055
|
||
|
self.sleep_madi = devices.shelly(mc, topic="shellies/sleep_madi") # http://shelly1l-E8DB84A254C7
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
# self._ = devices.shelly(mc, topic="") # http://
|
||
|
|
||
|
|
||
|
class powerplugs(object):
|
||
|
def __init__(self, mc):
|
||
|
self.dining_floorlamp = devices.silvercrest_powerplug(mc, "zigbee_og_e/powerplug/dining_floorlamp")
|
||
|
self.aux = devices.silvercrest_powerplug(mc, topic="zigbee_og_e/powerplug/aux")
|
||
|
self.dirk = devices.my_powerplug(mc, "powerplug/dirk")
|
||
|
|
||
|
|
||
|
class lights(object):
|
||
|
def __init__(self, mc):
|
||
|
self.sleep_madi = devices.tradfri_light(mc, topic="zigbee_og_e/light/sleep_madi")
|
||
|
self.sleep_bed_di = devices.tradfri_light(mc, topic="zigbee_og_e/light/sleep_bed_di")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
# self._ = devices.tradfri_light(mc, topic="")
|
||
|
|
||
|
|
||
|
class input_devices(object):
|
||
|
def __init__(self, mc):
|
||
|
self.og_east = devices.tradfri_button(mc, topic="zigbee_og_e/input_device/og_east")
|
||
|
|
||
|
|
||
|
class all_devices(object):
|
||
|
def __init__(self, mc):
|
||
|
self.shellies = shellies(mc)
|
||
|
self.powerplugs = powerplugs(mc)
|
||
|
self.lights = lights(mc)
|
||
|
self.input_devices = input_devices(mc)
|
||
|
|
||
|
def devicelist(self):
|
||
|
rv = []
|
||
|
for name, obj in inspect.getmembers(self):
|
||
|
if not name.startswith('_') and name != inspect.stack()[0][3]:
|
||
|
for devicename, deviceobj in inspect.getmembers(obj):
|
||
|
if not devicename.startswith('_'):
|
||
|
rv.append(deviceobj)
|
||
|
return rv
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
if config.DEBUG:
|
||
|
report.stdoutLoggingConfigure(([config.APP_NAME, config.DEBUGLEVEL], ), report.LONG_FMT)
|
||
|
else:
|
||
|
report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO),
|
||
|
(config.APP_NAME+'.devices', logging.WARNING)), report.SHORT_FMT)
|
||
|
#
|
||
|
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT,
|
||
|
username=config.MQTT_USER, password=config.MQTT_PASSWORD, name=config.APP_NAME)
|
||
|
|
||
|
ad = all_devices(mc)
|
||
|
func = function.all_functions(ad)
|
||
|
|
||
|
# def wcb(device, txt):
|
||
|
# logger.warning("%s: %s", device.topic, txt)
|
||
|
# for device in ad.devicelist():
|
||
|
# device.add_warning_callback(wcb)
|
||
|
|
||
|
# def cb(device, key, data):
|
||
|
# print("Callback: %s::%s" % (key, str(data)))
|
||
|
# ad.shellies.dinigroom.add_callback(devices.shelly.KEY_OUTPUT_0, None, cb)
|
||
|
|
||
|
while (True):
|
||
|
time.sleep(1)
|