MQTT Home Emulation
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

silvercrest.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from devices.base import base
  2. from devices.tradfri import sw as tradfri_sw
  3. from devices.tradfri import sw_br_ct as tradfri_sw_br_ct
  4. import json
  5. class sw(tradfri_sw):
  6. pass
  7. class sw_br_ct(tradfri_sw_br_ct):
  8. def set_state(self, value):
  9. self.__set__("state", "on" if value else "off")
  10. def power_on_action(self):
  11. self["state"] = "on"
  12. class motion_sensor(base):
  13. """ Communication (MQTT)
  14. silvercrest_motion_sensor {
  15. battery: [0...100] %
  16. battery_low: [True, False]
  17. linkquality: [0...255] lqi
  18. occupancy: [True, False]
  19. tamper: [True, False]
  20. voltage: [0...] mV
  21. }
  22. """
  23. KEY_BATTERY = "battery"
  24. KEY_BATTERY_LOW = "battery_low"
  25. KEY_LINKQUALITY = "linkquality"
  26. KEY_OCCUPANCY = "occupancy"
  27. KEY_UNMOUNTED = "tamper"
  28. KEY_VOLTAGE = "voltage"
  29. #
  30. PROPERTIES = [KEY_OCCUPANCY, KEY_UNMOUNTED]
  31. def __init__(self, mqtt_client, topic, **kwargs):
  32. super().__init__(mqtt_client, topic, **kwargs)
  33. #
  34. self[self.KEY_OCCUPANCY] = False
  35. #
  36. cmd_base = self.topic.replace('/', '.') + '.'
  37. self.user_cmds = {
  38. cmd_base + 'toggle_occupancy': self.__ui_toggle_occupancy__,
  39. }
  40. def send_device_status(self):
  41. self.logger.info("Sending status: %s", repr(self))
  42. self.mqtt_client.send(self.topic, json.dumps(self))
  43. def __ui_toggle_occupancy__(self, *args):
  44. self.__set__(self.KEY_OCCUPANCY, not self.get(self.KEY_OCCUPANCY))
  45. self.send_device_status()