Smarthome Functionen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smart_brain.py 3.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import config
  2. import devices
  3. import function
  4. import inspect
  5. import logging
  6. import mqtt
  7. import os
  8. import report
  9. import time
  10. logger = logging.getLogger(config.APP_NAME)
  11. class shellies(object):
  12. def __init__(self, mc):
  13. self.dinigroom = devices.shelly(mc, topic="shellies/diningroom") # http://shelly1l-84CCA8ADD055
  14. self.sleep_madi = devices.shelly(mc, topic="shellies/sleep_madi") # http://shelly1l-E8DB84A254C7
  15. # self._ = devices.shelly(mc, topic="") # http://
  16. # self._ = devices.shelly(mc, topic="") # http://
  17. # self._ = devices.shelly(mc, topic="") # http://
  18. # self._ = devices.shelly(mc, topic="") # http://
  19. # self._ = devices.shelly(mc, topic="") # http://
  20. # self._ = devices.shelly(mc, topic="") # http://
  21. # self._ = devices.shelly(mc, topic="") # http://
  22. class powerplugs(object):
  23. def __init__(self, mc):
  24. self.dining_floorlamp = devices.silvercrest_powerplug(mc, "zigbee_og_e/powerplug/dining_floorlamp")
  25. self.aux = devices.silvercrest_powerplug(mc, topic="zigbee_og_e/powerplug/aux")
  26. self.dirk = devices.my_powerplug(mc, "powerplug/dirk")
  27. class lights(object):
  28. def __init__(self, mc):
  29. self.sleep_madi = devices.tradfri_light(mc, topic="zigbee_og_e/light/sleep_madi")
  30. self.sleep_bed_di = devices.tradfri_light(mc, topic="zigbee_og_e/light/sleep_bed_di")
  31. # self._ = devices.tradfri_light(mc, topic="")
  32. # self._ = devices.tradfri_light(mc, topic="")
  33. # self._ = devices.tradfri_light(mc, topic="")
  34. # self._ = devices.tradfri_light(mc, topic="")
  35. # self._ = devices.tradfri_light(mc, topic="")
  36. # self._ = devices.tradfri_light(mc, topic="")
  37. # self._ = devices.tradfri_light(mc, topic="")
  38. # self._ = devices.tradfri_light(mc, topic="")
  39. # self._ = devices.tradfri_light(mc, topic="")
  40. class input_devices(object):
  41. def __init__(self, mc):
  42. self.og_east = devices.tradfri_button(mc, topic="zigbee_og_e/input_device/og_east")
  43. class all_devices(object):
  44. def __init__(self, mc):
  45. self.shellies = shellies(mc)
  46. self.powerplugs = powerplugs(mc)
  47. self.lights = lights(mc)
  48. self.input_devices = input_devices(mc)
  49. def devicelist(self):
  50. rv = []
  51. for name, obj in inspect.getmembers(self):
  52. if not name.startswith('_') and name != inspect.stack()[0][3]:
  53. for devicename, deviceobj in inspect.getmembers(obj):
  54. if not devicename.startswith('_'):
  55. rv.append(deviceobj)
  56. return rv
  57. if __name__ == "__main__":
  58. if config.DEBUG:
  59. report.stdoutLoggingConfigure(([config.APP_NAME, config.DEBUGLEVEL], ), report.LONG_FMT)
  60. else:
  61. report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO),
  62. (config.APP_NAME+'.devices', logging.WARNING)), report.SHORT_FMT)
  63. #
  64. mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT,
  65. username=config.MQTT_USER, password=config.MQTT_PASSWORD, name=config.APP_NAME)
  66. ad = all_devices(mc)
  67. func = function.all_functions(ad)
  68. # def wcb(device, txt):
  69. # logger.warning("%s: %s", device.topic, txt)
  70. # for device in ad.devicelist():
  71. # device.add_warning_callback(wcb)
  72. # def cb(device, key, data):
  73. # print("Callback: %s::%s" % (key, str(data)))
  74. # ad.shellies.dinigroom.add_callback(devices.shelly.KEY_OUTPUT_0, None, cb)
  75. while (True):
  76. time.sleep(1)