Skip to content
Snippets Groups Projects
Commit 45249e47 authored by Johannes Walcher's avatar Johannes Walcher
Browse files

added /haspa/power/status message

parent 512b4a41
No related branches found
No related tags found
No related merge requests found
...@@ -65,6 +65,10 @@ Response for requestinfo ...@@ -65,6 +65,10 @@ Response for requestinfo
DATA: {'light':{'desc':'a light'}} DATA: {'light':{'desc':'a light'}}
## /haspa/power/status
Request to issue a full power status message to update all clients
DATA: {}
## /haspa/status ## /haspa/status
Message that the haspa status has changed, please somebody decide what to do. Message that the haspa status has changed, please somebody decide what to do.
......
...@@ -14,6 +14,7 @@ class Babel: ...@@ -14,6 +14,7 @@ class Babel:
self.hbf = Hauptbahnhof(loop) self.hbf = Hauptbahnhof(loop)
self.hbf.subscribe('/haspa/power', self.command_translate) self.hbf.subscribe('/haspa/power', self.command_translate)
self.hbf.subscribe('/haspa/power/requestinfo', self.command_requestinfo) self.hbf.subscribe('/haspa/power/requestinfo', self.command_requestinfo)
self.hbf.subscribe('/haspa/power/status', self.command_requeststatus)
self.ledstrip_states = [[0, 0, 0, 0], [0, 0, 0, 0]] self.ledstrip_states = [[0, 0, 0, 0], [0, 0, 0, 0]]
self.espids = ['a9495a00', 'c14e5a00'] self.espids = ['a9495a00', 'c14e5a00']
...@@ -33,9 +34,9 @@ class Babel: ...@@ -33,9 +34,9 @@ class Babel:
} }
self.rupprecht_map = { self.rupprecht_map = {
'table': 'rupprecht-table', 'table': ('rupprecht-table', 0),
'alarm': 'rupprecht-alarm', 'alarm': ('rupprecht-alarm', 0),
'fan': 'rupprecht-fan', 'fan': ('rupprecht-fan', 0),
} }
async def teardown(self): async def teardown(self):
...@@ -50,10 +51,11 @@ class Babel: ...@@ -50,10 +51,11 @@ class Babel:
del client del client
group_changed = False group_changed = False
msg = {} msg = {}
for lamp, value in message.items(): for lamp, value in sorted(message.items()):
## The lamp is managed by rupprecht ## The lamp is managed by rupprecht
if lamp in self.rupprecht_map: if lamp in self.rupprecht_map:
msg[self.rupprecht_map[lamp]] = int(value) msg[self.rupprecht_map[lamp][0]] = int(value)
self.rupprecht_map[lamp][1] = int(value)
## The lamp is a led strip and needs to be aggregated ## The lamp is a led strip and needs to be aggregated
if lamp.startswith('ledstrip'): if lamp.startswith('ledstrip'):
...@@ -75,13 +77,12 @@ class Babel: ...@@ -75,13 +77,12 @@ class Babel:
group_changed |= self.ledstrip_states[idx[0]][idx[1]] != int(value) group_changed |= self.ledstrip_states[idx[0]][idx[1]] != int(value)
self.ledstrip_states[idx[0]][idx[1]] = int(value) self.ledstrip_states[idx[0]][idx[1]] = int(value)
self.hbf.log.info("Done mapping: ")
self.hbf.log.info(self.ledstrip_states) self.hbf.log.info(self.ledstrip_states)
if group_changed: if group_changed:
for idx, ledidx in enumerate(self.espids): for idx, ledidx in enumerate(self.espids):
msg[ledidx] = self.ledstrip_states[idx] msg[ledidx] = self.ledstrip_states[idx]
await self.hbf.publish('/haspa/led', msg) await self.hbf.publish('/haspa/led', msg)
print("MSG: ", msg) print("Mapped Reduced Message: ", msg)
async def command_requestinfo(self, client, msg, _): async def command_requestinfo(self, client, msg, _):
""" """
...@@ -91,3 +92,14 @@ class Babel: ...@@ -91,3 +92,14 @@ class Babel:
await self.hbf.publish('/haspa/power/info', { await self.hbf.publish('/haspa/power/info', {
'documentation':'too lazy to implement' 'documentation':'too lazy to implement'
}) })
async def command_requeststatus(self, client, msg, _):
msg = {}
for idx, espid in enumerate(self.espids):
msg[espid] = self.ledstrip_states[idx]
for rupid, value in self.rupprecht_map.values():
msg[rupid] = value
print("Full message: ", msg)
await self.hbf.publish('/haspa/led', msg)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment