Initial commit
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
config.yaml
|
||||||
|
__pycache__/
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import yaml
|
||||||
|
|
||||||
|
with open("config.yaml", "r") as f:
|
||||||
|
settings = yaml.load(f)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
mqtt:
|
||||||
|
host: 192.168.1.1
|
||||||
|
username: user
|
||||||
|
password: password
|
||||||
|
workers:
|
||||||
|
thermostat:
|
||||||
|
args:
|
||||||
|
devices:
|
||||||
|
bedroom: 00:11:22:33:44:55
|
||||||
|
topic_prefix: thermostats
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
from config import settings
|
||||||
|
from mqtt import MqttClient
|
||||||
|
from workers.thermostat import ThermostatWorker
|
||||||
|
|
||||||
|
print(settings)
|
||||||
|
|
||||||
|
mqtt = MqttClient()
|
||||||
|
|
||||||
|
args = settings['workers']['thermostat']['args']
|
||||||
|
mqtt.publish(ThermostatWorker(**args).status_update())
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
from config import settings
|
||||||
|
import paho.mqtt.publish as publish
|
||||||
|
|
||||||
|
class MqttClient:
|
||||||
|
def __init__(self):
|
||||||
|
self._connected = False
|
||||||
|
self._config = settings['mqtt']
|
||||||
|
|
||||||
|
def publish(self, messages):
|
||||||
|
print(messages)
|
||||||
|
publish.multiple(messages, hostname=self.hostname, auth = {'username':self.username, 'password':self.password})
|
||||||
|
|
||||||
|
@property
|
||||||
|
def hostname(self):
|
||||||
|
return self._config['host']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
return self._config['username']
|
||||||
|
|
||||||
|
@property
|
||||||
|
def password(self):
|
||||||
|
return self._config['password']
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
paho-mqtt
|
||||||
|
python-eq3bt
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
from eq3bt import Thermostat, Mode
|
||||||
|
|
||||||
|
readableModes = {
|
||||||
|
0: 'off',
|
||||||
|
1: 'on',
|
||||||
|
2: 'auto',
|
||||||
|
3: 'manual',
|
||||||
|
4: 'away',
|
||||||
|
5: 'boost',
|
||||||
|
}
|
||||||
|
|
||||||
|
monitoredAttrs = ["low_battery", "valve_state", "target_temperature"]
|
||||||
|
|
||||||
|
class ThermostatWorker:
|
||||||
|
def __init__(self, devices=None, topic_prefix=None):
|
||||||
|
self._devices = devices
|
||||||
|
self._topic_prefix = topic_prefix
|
||||||
|
|
||||||
|
def status_update(self):
|
||||||
|
ret = []
|
||||||
|
for name, mac in self.devices.items():
|
||||||
|
thermostat = Thermostat(mac)
|
||||||
|
thermostat.update()
|
||||||
|
|
||||||
|
for attr in monitoredAttrs:
|
||||||
|
ret.append({
|
||||||
|
'topic': self.format_topic(name, attr),
|
||||||
|
'payload': getattr(thermostat,attr),
|
||||||
|
})
|
||||||
|
return ret
|
||||||
|
|
||||||
|
@property
|
||||||
|
def devices(self):
|
||||||
|
return self._devices
|
||||||
|
|
||||||
|
@property
|
||||||
|
def topic_prefix(self):
|
||||||
|
return self._topic_prefix
|
||||||
|
|
||||||
|
def format_topic(self, device, attr):
|
||||||
|
return '/'.join([self.topic_prefix, device, attr])
|
||||||
Reference in New Issue
Block a user