Introduce mqttMessage object
This commit is contained in:
+3
-4
@@ -1,5 +1,7 @@
|
||||
import time
|
||||
|
||||
from mqtt import MqttMessage
|
||||
|
||||
REQUIREMENTS = ['bluepy', 'interruptingcow']
|
||||
|
||||
# Bluepy might need special settings
|
||||
@@ -10,10 +12,7 @@ class MiscaleWorker():
|
||||
self._mac = mac
|
||||
|
||||
def status_update(self):
|
||||
return [{
|
||||
'topic': 'weight/kg',
|
||||
'payload': self._get_weight(),
|
||||
}]
|
||||
return [MqttMessage(topic='weight/kg', payload= self._get_weight())]
|
||||
|
||||
def _get_weight(self):
|
||||
from bluepy import btle
|
||||
|
||||
+5
-13
@@ -1,3 +1,5 @@
|
||||
from mqtt import MqttMessage
|
||||
|
||||
REQUIREMENTS = ['python-eq3bt']
|
||||
|
||||
monitoredAttrs = ["low_battery", "valve_state", "target_temperature"]
|
||||
@@ -24,20 +26,10 @@ class ThermostatWorker:
|
||||
thermostat.update()
|
||||
|
||||
for attr in monitoredAttrs:
|
||||
ret.append({
|
||||
'topic': self.format_topic(name, attr),
|
||||
'payload': getattr(thermostat, attr),
|
||||
})
|
||||
ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=getattr(thermostat, attr)))
|
||||
|
||||
ret.append({
|
||||
'topic': self.format_topic(name, 'mode'),
|
||||
'payload': haModesMapping[thermostat.mode],
|
||||
})
|
||||
|
||||
ret.append({
|
||||
'topic': self.format_topic(name, 'away'),
|
||||
'payload': 'ON' if thermostat.mode == Mode.Away else 'OFF'
|
||||
})
|
||||
ret.append(MqttMessage(topic=self.format_topic(name, 'mode'), payload=haModesMapping[thermostat.mode]))
|
||||
ret.append(MqttMessage(topic=self.format_topic(name, 'away'), payload='ON' if thermostat.mode == Mode.Away else 'OFF'))
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
Reference in New Issue
Block a user