Initial commit
This commit is contained in:
commit
8b4521a447
6 changed files with 2771 additions and 0 deletions
44
oin_ha/__main__.py
Normal file
44
oin_ha/__main__.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
from threading import Timer
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
from .display import Display
|
||||
from .sensors import Sensors
|
||||
|
||||
dt = 10
|
||||
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||
hat_sensors = Sensors(mqttc, "oin", "Oin")
|
||||
hat_display = Display(mqttc, "oin", "Oin")
|
||||
|
||||
|
||||
@mqttc.connect_callback()
|
||||
def on_connect(client, userdata, flags, reason_code, properties):
|
||||
print(f"Connected with result code {reason_code}")
|
||||
|
||||
hat_sensors.publish_discovery()
|
||||
hat_display.publish_discovery()
|
||||
|
||||
hat_sensors.publish_online()
|
||||
hat_display.publish_online()
|
||||
|
||||
timer = Timer(0, send_data)
|
||||
timer.start()
|
||||
|
||||
|
||||
@mqttc.message_callback()
|
||||
def on_message(*args, **kwargs):
|
||||
hat_display.on_message(*args, **kwargs)
|
||||
|
||||
|
||||
mqttc.username_pw_set(username="oin", password="n+Bi58l7LxbH5nEJ")
|
||||
mqttc.connect("homeassistant.local", 1883, 60)
|
||||
|
||||
|
||||
def send_data():
|
||||
timer = Timer(dt, send_data)
|
||||
timer.start()
|
||||
|
||||
hat_sensors.publish_state()
|
||||
|
||||
|
||||
mqttc.loop_forever()
|
Reference in a new issue