send lixie_clock config upon boot
This commit is contained in:
parent
fdb6d65220
commit
84fcb20f49
18
models.py
18
models.py
|
@ -4,11 +4,10 @@ Data models for different device types managed by the Juice IOT hub.
|
||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
import json
|
import json
|
||||||
|
import requests
|
||||||
|
|
||||||
import tools
|
import tools
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
class Network(list):
|
class Network(list):
|
||||||
"""
|
"""
|
||||||
Represents a network of IOT devices.
|
Represents a network of IOT devices.
|
||||||
|
@ -166,7 +165,7 @@ class LightStrip(Device):
|
||||||
animation_rotate_count = 1,
|
animation_rotate_count = 1,
|
||||||
animation_delay = 200,
|
animation_delay = 200,
|
||||||
|
|
||||||
async def mqtt_callback(self, app, msg):
|
def mqtt_callback(self, app, msg):
|
||||||
topic = msg.topic.split('/')
|
topic = msg.topic.split('/')
|
||||||
payload = msg.payload.decode('utf8')
|
payload = msg.payload.decode('utf8')
|
||||||
|
|
||||||
|
@ -236,7 +235,7 @@ class LightStrip(Device):
|
||||||
save_network(network)
|
save_network(network)
|
||||||
|
|
||||||
res = {'event': 'neopixel', 'data': data}
|
res = {'event': 'neopixel', 'data': data}
|
||||||
await app.send_json_all(res)
|
app.loop.create_task(app.send_json_all(res))
|
||||||
|
|
||||||
|
|
||||||
class NeoPixel(SubDevice):
|
class NeoPixel(SubDevice):
|
||||||
|
@ -261,7 +260,7 @@ class LixieClock(Device):
|
||||||
self.time_offset = -5
|
self.time_offset = -5
|
||||||
self.display_number = 0
|
self.display_number = 0
|
||||||
|
|
||||||
async def mqtt_callback(self, app, msg):
|
def mqtt_callback(self, app, msg):
|
||||||
topic = msg.topic.split('/')
|
topic = msg.topic.split('/')
|
||||||
payload = msg.payload.decode('utf8')
|
payload = msg.payload.decode('utf8')
|
||||||
|
|
||||||
|
@ -288,10 +287,17 @@ class LixieClock(Device):
|
||||||
data['change_mode'] = 'time_offset'
|
data['change_mode'] = 'time_offset'
|
||||||
data['time_offset'] = int(payload)
|
data['time_offset'] = int(payload)
|
||||||
self.time_offset = int(payload)
|
self.time_offset = int(payload)
|
||||||
|
elif topic[1] == 'helo':
|
||||||
|
app['mqtt'].publish(topic[0] + '/' + self.display_mode, '')
|
||||||
|
if self.display_mode == 'number':
|
||||||
|
app['mqtt'].publish(topic[0] + '/number', self.display_number)
|
||||||
|
app['mqtt'].publish(topic[0] + '/time_offset', self.time_offset)
|
||||||
|
color = ','.join([str(n) for n in self.color])
|
||||||
|
app['mqtt'].publish(topic[0] + '/color', color)
|
||||||
save_network(network)
|
save_network(network)
|
||||||
|
|
||||||
res = {'event': 'lixie_clock', 'data': data}
|
res = {'event': 'lixie_clock', 'data': data}
|
||||||
await app.send_json_all(res)
|
app.loop.create_task(app.send_json_all(res))
|
||||||
|
|
||||||
|
|
||||||
class LixieDisplay(SubDevice):
|
class LixieDisplay(SubDevice):
|
||||||
|
|
6
mqtt.py
6
mqtt.py
|
@ -2,8 +2,6 @@
|
||||||
"""
|
"""
|
||||||
Contains MQTT funtionality.
|
Contains MQTT funtionality.
|
||||||
"""
|
"""
|
||||||
import asyncio
|
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
|
|
||||||
from models import network
|
from models import network
|
||||||
|
@ -21,9 +19,7 @@ def on_message(client, userdata, msg):
|
||||||
root = msg.topic.partition('/')[0]
|
root = msg.topic.partition('/')[0]
|
||||||
devices = [device for device in network if root == device.mqtt_root]
|
devices = [device for device in network if root == device.mqtt_root]
|
||||||
for device in devices:
|
for device in devices:
|
||||||
coro = device.mqtt_callback(client.app, msg)
|
device.mqtt_callback(client.app, msg)
|
||||||
future = asyncio.run_coroutine_threadsafe(coro, client.app.loop)
|
|
||||||
future.result()
|
|
||||||
|
|
||||||
|
|
||||||
def init_client(app):
|
def init_client(app):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user