def __init__( self, device_id=None, name=None, homie_settings={}, mqtt_settings={}, extensions=["stats", "firmware", "meta"], ): global instance_count instance_count = instance_count + 1 self.instance_number = instance_count self._mqtt_connected = False # mqtt connection status, true = connected if device_id is None: device_id = self.generate_device_id() assert validate_id(device_id), "Invalid device id {}".format(device_id) self.device_id = device_id assert name self.name = name for extension in extensions: assert extension in EXTENSIONS self.extensions = extensions self._state = "init" self.homie_settings = self._homie_validate_settings(homie_settings) self.topic = "/".join((self.homie_settings["topic"], self.device_id)) # may need a way to set these self.retained = True self.qos = 1 self.nodes = {} self.start_time = None self.nodes_published = False self.mqtt_client = connect_mqtt_client(self, mqtt_settings) self.mqtt_subscription_handlers = {} global devices devices.append(self)
def __init__(self, device_id=None, name=None, homie_settings={}, mqtt_settings={}): global instance_count instance_count = instance_count + 1 self.instance_number = instance_count if device_id is None: device_id = self.generate_device_id() assert validate_id(device_id), 'Invalid device id {}'.format(device_id) self.device_id = device_id assert name self.name = name self._state = "init" self.homie_settings = self._homie_validate_settings(homie_settings) self.topic = "/".join((self.homie_settings['topic'], self.device_id)) #may need a way to set these self.retained = True self.qos = 1 self.nodes = {} self.start_time = None self.nodes_published = False self.mqtt_connected = False self.mqtt_client = connect_mqtt_client(self, mqtt_settings) self.using_shared_mqtt_client = mqtt_settings['MQTT_SHARE_CLIENT']