Files
bt-mqtt-gateway/workers/thermostat.py
T
2017-11-23 22:16:29 +01:00

42 lines
1.1 KiB
Python

from mqtt import MqttMessage
REQUIREMENTS = ['python-eq3bt']
monitoredAttrs = ["low_battery", "valve_state", "target_temperature"]
class ThermostatWorker:
def __init__(self, devices=None):
self._devices = devices
def status_update(self):
from eq3bt import Thermostat, Mode
haModesMapping = {
Mode.Closed: 'off',
Mode.Open: 'on',
Mode.Auto: 'auto',
Mode.Manual: 'manual',
Mode.Away: 'away',
Mode.Boost: 'boost',
}
ret = []
for name, mac in self.devices.items():
thermostat = Thermostat(mac)
thermostat.update()
for attr in monitoredAttrs:
ret.append(MqttMessage(topic=self.format_topic(name, attr), payload=getattr(thermostat, attr)))
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
@property
def devices(self):
return self._devices
def format_topic(self, device, attr):
return '/'.join([device, attr])