From 9ea23bbeedec5a3375ce157318fd4929fabaf792 Mon Sep 17 00:00:00 2001
From: johannes walcher <johannes.walcher@stusta.de>
Date: Thu, 26 Jul 2018 17:01:07 +0200
Subject: [PATCH] fixed configs, linting

---
 babel/babel.py               | 26 +++++++++++++++-----------
 hauptbahnhof/hauptbahnhof.py | 17 +++++++++--------
 2 files changed, 24 insertions(+), 19 deletions(-)

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