Added lighting preset recall on backend and frontend, fixed things in other scripts - things should *mostly* be working now
This commit is contained in:
parent
61a8aa8ebc
commit
d00651a66c
14 changed files with 851 additions and 74 deletions
50
lucke/luckeControl.py
Normal file
50
lucke/luckeControl.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
from http import HTTPStatus
|
||||
|
||||
import aiomqtt
|
||||
import asyncio
|
||||
import toml
|
||||
import aiohttp
|
||||
|
||||
lucke_bearer_token = ""
|
||||
room = ""
|
||||
url = ""
|
||||
roomId = 0
|
||||
|
||||
async def sendSceneRequest(client, scene):
|
||||
global roomId
|
||||
endpoint = url.format(roomId=roomId, sceneId=scene)
|
||||
# Content-Type needs to be JSON, but the content itself is ignored
|
||||
async with aiohttp.request("POST", endpoint, headers={"Authorization": "Bearer " + lucke_bearer_token}, json={}) as resp:
|
||||
#if 204 change was made
|
||||
if resp.status != 204:
|
||||
print(resp.status, await resp.text())
|
||||
|
||||
await client.publish(f'{room}/lucke/preset/current', payload=scene, qos=1, retain=True)
|
||||
|
||||
|
||||
async def task_luckeCommand(controlClient):
|
||||
await controlClient.subscribe(f"{room}/lucke/preset/recall")
|
||||
msgs = controlClient.messages
|
||||
async for mesg in msgs:
|
||||
mesg: aiomqtt.Message
|
||||
msgTopicArr = mesg.topic.value.split('/')
|
||||
sceneNum = mesg.payload.decode()
|
||||
print("Received: " + str(msgTopicArr) + " payload: [" + sceneNum + "]")
|
||||
print('sending request to endpoint..')
|
||||
await sendSceneRequest(controlClient, sceneNum)
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
async def main():
|
||||
global room, lucke_bearer_token, url, roomId
|
||||
conf = toml.load('./malinaConfig.toml')
|
||||
room = conf.get("global")['room']
|
||||
url = conf.get("lucke")['url']
|
||||
roomId = conf.get("lucke")['roomId']
|
||||
lucke_bearer_token = conf.get("lucke")['bearer_token']
|
||||
|
||||
async with aiomqtt.Client('localhost', 1883) as client:
|
||||
task_control = asyncio.create_task(task_luckeCommand(client))
|
||||
await asyncio.gather(task_control)
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(main())
|
Loading…
Add table
Add a link
Reference in a new issue