MQTT Home Emulation
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

base.py 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import logging
  2. class base(dict):
  3. """A base device for all devicetypes
  4. Args:
  5. mqtt_client (mqtt.mqtt_client): A MQTT Client instance
  6. topic (str): the base topic for this device
  7. """
  8. PROPERTIES = []
  9. def __init__(self, mqtt_client, topic):
  10. super().__init__()
  11. self.mqtt_client = mqtt_client
  12. self.topic = topic
  13. #
  14. self.logger = logging.getLogger('devices')
  15. for entry in self.topic.split('/'):
  16. self.logger = self.logger.getChild(entry)
  17. #
  18. self.__power_on_inst__ = []
  19. def __set__(self, key, data):
  20. if key in self.PROPERTIES:
  21. self.logger.debug("Setting new property %s to %s", key, repr(data))
  22. self[key] = data
  23. else:
  24. self.logger.warning("Ignoring unsupported property %s", key)
  25. def power_on(self):
  26. for i in self.__power_on_inst__:
  27. i.power_on_action()
  28. def register_power_on_instance(self, inst):
  29. if inst not in self.__power_on_inst__:
  30. self.__power_on_inst__.append(inst)
  31. def power_on_action(self):
  32. pass