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

fixed configs, linting

parent 116e64c7
No related branches found
No related tags found
No related merge requests found
...@@ -15,20 +15,22 @@ class Babel: ...@@ -15,20 +15,22 @@ class Babel:
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.ledstrip_states = [[0,0,0,0], [0,0,0,0]] self.ledstrip_states = [[0, 0, 0, 0], [0, 0, 0, 0]]
self.espids = ['a9495a00','024c5a00'] self.espids = ['a9495a00', 'c14e5a00']
# TODO create this mapping: # TODO create this mapping:
# mapps from (color, id) ==> (self.ledstrip indexes) # mapps from (color, id) ==> (self.ledstrip indexes)
self.idxpair = { self.idxpair = {
('c',1):(0,0), # The first one has cold and warm swapped...
('w',1):(0,1), ('c', 1):(0, 1),
('c',2):(0,2), ('w', 1):(0, 0),
('w',2):(0,3), ('c', 2):(0, 3),
('c',3):(1,0), ('w', 2):(0, 2),
('w',3):(1,1), # This one has cold and warm right
('c',4):(1,2), ('c', 3):(1, 0),
('w',4):(1,3), ('w', 3):(1, 1),
('c', 4):(1, 2),
('w', 4):(1, 3),
} }
self.rupprecht_map = { self.rupprecht_map = {
...@@ -38,6 +40,7 @@ class Babel: ...@@ -38,6 +40,7 @@ class Babel:
} }
async def teardown(self): async def teardown(self):
""" clean up after yourself """
await self.hbf.teardown() await self.hbf.teardown()
async def command_translate(self, client, message, _): async def command_translate(self, client, message, _):
...@@ -45,6 +48,7 @@ class Babel: ...@@ -45,6 +48,7 @@ class Babel:
space.get_number_of_network_devices() -> int space.get_number_of_network_devices() -> int
Return the number of non-stationary, connected network devices. Return the number of non-stationary, connected network devices.
""" """
del client
group_changed = False group_changed = False
msg = {} msg = {}
for lamp, value in message.items(): for lamp, value in message.items():
...@@ -60,7 +64,7 @@ class Babel: ...@@ -60,7 +64,7 @@ class Babel:
group_changed |= self.ledstrip_states[a][b] != int(value) group_changed |= self.ledstrip_states[a][b] != int(value)
self.ledstrip_states[a][b] = int(value) self.ledstrip_states[a][b] = int(value)
elif len(tmp) == 2 and tmp[1] in ('c','w'): elif len(tmp) == 2 and tmp[1] in ('c', 'w'):
for color, position in self.idxpair: for color, position in self.idxpair:
if color == tmp[1]: if color == tmp[1]:
idx = self.idxpair[(color, position)] idx = self.idxpair[(color, position)]
......
...@@ -27,6 +27,8 @@ class Hauptbahnhof: ...@@ -27,6 +27,8 @@ class Hauptbahnhof:
# find master config # find master config
self._config = self.config("hauptbahnhof") self._config = self.config("hauptbahnhof")
self._host = self._config['host']
self._subscriptions = {} self._subscriptions = {}
self._mqtt = None self._mqtt = None
self._mqtt_queue = [] self._mqtt_queue = []
...@@ -65,27 +67,26 @@ class Hauptbahnhof: ...@@ -65,27 +67,26 @@ class Hauptbahnhof:
mqtt.loop_start() mqtt.loop_start()
mqtt.on_message = self.on_message mqtt.on_message = self.on_message
mqtt.on_connect = lambda client, userdata, flags, rc: self.connected.set() mqtt.on_connect = lambda client, userdata, flags, rc: self.connected.set()
try: try:
await mqtt.connect(self._config['host']) await mqtt.connect(self._host)
except KeyError: except:
self.log.error("Could not connect to %s"%self._config['host']) self.log.error("Could not connect to %s", self._host)
self.loop.cancel() self.loop.cancel()
raise
await self.connected.wait() await self.connected.wait()
self.log.info("Connected to %s" % self._config['host']) self.log.info("Successfully connected to %s", self._config['host'])
for topic in self._subscriptions: for topic in self._subscriptions:
mqtt.subscribe(topic) mqtt.subscribe(topic)
while self._mqtt_queue: while self._mqtt_queue:
topic, msg = self._mqtt_queue.pop(0) topic, msg = self._mqtt_queue.pop(0)
self.log.debug("Topic: %s"%topic) self.log.debug("Topic: %s", topic)
await self._mqtt.publish(topic, msg) await self._mqtt.publish(topic, msg)
# Now we have mqtt available! # Now we have mqtt available!
self._mqtt = mqtt self._mqtt = mqtt
self.log.info("Startup done")
async def message_processing(self): async def message_processing(self):
while True: while True:
...@@ -104,7 +105,7 @@ class Hauptbahnhof: ...@@ -104,7 +105,7 @@ class Hauptbahnhof:
await asyncio.gather(*[fut(client, payloadobj, msg) for fut in futures]) await asyncio.gather(*[fut(client, payloadobj, msg) for fut in futures])
except json.JSONDecodeError: except json.JSONDecodeError:
self.log("Invalid json received: %s"%payload) self.log("Invalid json received: %s"%payload)
except Exception as e: except Exception:
traceback.print_exc() traceback.print_exc()
def on_message(self, client, userdata, msg): def on_message(self, client, userdata, 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