示例#1
0
 def __init__(self, topic, hardware_device, min_value=None, max_value=None):
     Notifier.__init__(self)
     Observer.__init__(self)
     DigitalDevice.__init__(self)
     MQTTTarget.__init__(self, topic=topic)
     self._hardware_device = hardware_device
     self._min_value = min_value
     self._max_value = max_value
     self._setup_hardware_device()
示例#2
0
 def __init__(self, size: int, hardware_device=None):
     logger.debug(
         'Creating a digital sensor group with {0} sensors'.format(size))
     Notifier.__init__(self)
     Observer.__init__(self)
     self._states = [DigitalSensor.LOW] * size
     self._hardware_device = hardware_device
     self._read_states_from_hardware_device()
     logger.debug(
         'Digital sensor group with {0} sensors is created'.format(size))
示例#3
0
 def __init__(self, topic: str, hardware_device=None, min_alarm=None, max_alarm=None):
     logger.debug(
         'Creating a voltage sensor named {0}'.format(topic))
     Observer.__init__(self)
     AnalogDevice.__init__(self)
     LTC2945Sensor.__init__(self, topic=topic, hardware_device=hardware_device)
     MQTTTarget.__init__(self, topic=topic)
     self._value = 0
     self._read_value_from_hardware_device()
     logger.debug('Voltage sensor named {0} is created'.format(topic))
示例#4
0
 def __init__(self, topic: str, sensor_group, index: int):
     Notifier.__init__(self)
     Observer.__init__(self)
     DigitalDevice.__init__(self)
     MQTTTarget.__init__(self, topic=topic)
     logger.debug(
         'Creating a digital sensor named {0} at position {1} in the sensor group {2}'.format(self.topic, index,
                                                                                              sensor_group))
     # assert that the index exists in the device group
     sensor_group._get_state(index)
     sensor_group.register_observer(self)
     self._sensor_group = sensor_group
     self._index = index
     self._previous_state = None
     logger.debug(
         'Digital sensor named {0} at position {1} in the sensor group {2} is created'.format(self.topic, index,
                                                                                              sensor_group))
示例#5
0
 def __init__(self, id, host, username=None, password=None):
     logger.debug('Creating MQTT client')
     Notifier.__init__(self)
     Observer.__init__(self)
     self._last_known_payload = {}
     self._mutex = Lock()
     self._client_id = id
     self._client = mqtt.Client(client_id=self._client_id, clean_session=True, protocol=mqtt.MQTTv311)
     if username is not None:
         self._client.username_pw_set(username=username, password=password)
     self._client.on_message = self._on_message
     self._client.on_connect = self._on_connect
     self._client.will_set(topic='client/{0}'.format(self._client_id), payload=self.LOST_CONNECTION, qos=1)
     self._connected = False
     self._client.connect(host)
     self._client.loop_start()
     logger.debug('MQTT client is created')
     while not self._connected:
         pass
     logger.debug('MQTT client is connected')
示例#6
0
 def __init__(self, topic):
     Observer.__init__(self)
     MQTTTarget.__init__(self, topic=topic)
示例#7
0
 def __init__(self, topic: str, hardware_device=None):
     Notifier.__init__(self)
     Observer.__init__(self)
     self._hardware_device = hardware_device
     self._setup_hardware_device()
     self.name = topic