Added missing files
This commit is contained in:
parent
7b3ac37a0f
commit
bfec9a0524
3 changed files with 90 additions and 0 deletions
32
ddc-mqtt/devices.py
Normal file
32
ddc-mqtt/devices.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
device = {
|
||||
"identifiers": ["Kikkei Labs Display KVM"],
|
||||
"name": "Display KVM",
|
||||
"model": "Kikkei-display-kvm-0",
|
||||
"manufacturer": "Kikkei Labs",
|
||||
}
|
||||
|
||||
|
||||
display_device = {
|
||||
"identifiers": ["Kid"],
|
||||
"name": "Display # KVM",
|
||||
"model": "Kikkei-display-kvm",
|
||||
"manufacturer": "Kikkei Labs",
|
||||
}
|
||||
|
||||
display_input_entity = {
|
||||
"generic_switch": 'homeassistant/switch/display-kvm-#/?-switch/config',
|
||||
"generic_switch_config": {
|
||||
"availability_topic": "kikkei/display-kvm/garbage",
|
||||
"state_topic": "kikkei/display-kvm/kids/#/?/state",
|
||||
"name": "",
|
||||
"unique_id": "",
|
||||
"object_id": "",
|
||||
"payload_available": "ON",
|
||||
"payload_not_available": "OFF",
|
||||
#"json_attributes_topic": "kikkei/household/#/%/attributes",
|
||||
"state_on": "true",
|
||||
"state_off": "false",
|
||||
"command_topic": "kikkei/display-kvm/#/?/command",
|
||||
"device": display_device
|
||||
}
|
||||
}
|
||||
38
ddc-mqtt/mqtt_client.py
Normal file
38
ddc-mqtt/mqtt_client.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from devices import garbage_config
|
||||
import paho.mqtt.client as mqtt
|
||||
import json
|
||||
from timer import Timer
|
||||
|
||||
class MQTTClient:
|
||||
def on_connect(self, client, userdata, flags, rc):
|
||||
print("Connected with result code " + str(rc))
|
||||
|
||||
def on_disconnect(self, client, userdata, rc):
|
||||
self.timer.reset()
|
||||
self.timer.active = True
|
||||
|
||||
def on_message(self, client, userdata, msg):
|
||||
if self.delegate != None:
|
||||
self.delegate.on_message(msg.topic, msg.payload)
|
||||
|
||||
def __init__(self, username, password, host, port):
|
||||
self.client = mqtt.Client()
|
||||
|
||||
self.client.username_pw_set(username, password)
|
||||
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.client.on_connect = self.on_connect
|
||||
self.client.on_message = self.on_message
|
||||
self.client.on_disconnect = self.on_disconnect
|
||||
self.client.connect(host, port, 60)
|
||||
self.delegate = None
|
||||
self.timer = Timer(60, self)
|
||||
self.timer.active = False
|
||||
|
||||
def on_timer(self, timer, elapsed):
|
||||
self.client.connect(self.host, self.port, 60)
|
||||
|
||||
def step(self, dt):
|
||||
self.client.loop()
|
||||
self.timer.step(dt)
|
||||
20
ddc-mqtt/timer.py
Normal file
20
ddc-mqtt/timer.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
class Timer:
|
||||
def __init__(self, time, delegate):
|
||||
self.delegate = delegate
|
||||
self.time = time
|
||||
self.elapsed = 0
|
||||
self.active = True
|
||||
self.payload = None
|
||||
self.name = ""
|
||||
|
||||
def step(self, dt):
|
||||
if not self.active:
|
||||
return
|
||||
self.elapsed += dt
|
||||
if self.elapsed >= self.time:
|
||||
self.active = False
|
||||
self.delegate.on_timer(self, self.elapsed)
|
||||
self.elapsed = 0
|
||||
|
||||
def reset(self):
|
||||
self.elapsed = 0
|
||||
Loading…
Reference in a new issue