MQTT Home Emulation
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

base.py 874B

1234567891011121314151617181920212223242526272829
  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, **kwargs):
  10. super().__init__()
  11. self.mqtt_client = mqtt_client
  12. self.topic = topic
  13. for key in kwargs:
  14. setattr(self, key, kwargs[key])
  15. #
  16. self.logger = logging.getLogger('devices')
  17. for entry in self.topic.split('/'):
  18. self.logger = self.logger.getChild(entry)
  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)