1234567891011121314151617181920212223242526272829 |
- import logging
-
-
- class base(dict):
- """A base device for all devicetypes
-
- Args:
- mqtt_client (mqtt.mqtt_client): A MQTT Client instance
- topic (str): the base topic for this device
- """
- PROPERTIES = []
-
- def __init__(self, mqtt_client, topic, **kwargs):
- super().__init__()
- self.mqtt_client = mqtt_client
- self.topic = topic
- for key in kwargs:
- setattr(self, key, kwargs[key])
- #
- self.logger = logging.getLogger('devices')
- for entry in self.topic.split('/'):
- self.logger = self.logger.getChild(entry)
-
- def __set__(self, key, data):
- if key in self.PROPERTIES:
- self.logger.debug("Setting new property %s to %s", key, repr(data))
- self[key] = data
- else:
- self.logger.warning("Ignoring unsupported property %s", key)
|