Browse Source

[lint] clean errors

Maxime Alves LIRMM@home 3 years ago
parent
commit
13cd4273b9
5 changed files with 26 additions and 12 deletions
  1. 6
    3
      pyheatpump/cli.py
  2. 2
    0
      pyheatpump/config.py
  3. 3
    3
      pyheatpump/db.py
  4. 11
    2
      pyheatpump/models/heatpump.py
  5. 4
    4
      pyheatpump/models/variable_type.py

+ 6
- 3
pyheatpump/cli.py View File

@@ -25,9 +25,12 @@ CONTEXT_SETTINGS={
25 25
 @click.option('--version', is_flag=True)
26 26
 @click.pass_context
27 27
 def cli(ctx, version):
28
+    """
28 29
     if version:
29 30
         from pyheatpump import version
30 31
         return click.echo(pyheatpump.version())
32
+    """
33
+    pass
31 34
 
32 35
 
33 36
 @click.option('--host', default=None)
@@ -174,9 +177,9 @@ def supervise(since):
174 177
         last_update = get_last_update()
175 178
     
176 179
     post_packets = [
177
-        Heatpump(mac_address, last_update, ['Analog']).__dict__(),
178
-        Heatpump(mac_address, last_update, ['Digital']).__dict__(),
179
-        Heatpump(mac_address, last_update, ['Integer']).__dict__()
180
+        Heatpump(mac_address, last_update, ['Analog']).packet,
181
+        Heatpump(mac_address, last_update, ['Digital']).packet,
182
+        Heatpump(mac_address, last_update, ['Integer']).packet
180 183
     ]
181 184
 
182 185
     base_url = {

+ 2
- 0
pyheatpump/config.py View File

@@ -1,11 +1,13 @@
1 1
 #!/usr/bin/env python3
2 2
 import os
3 3
 import re
4
+import sys
4 5
 from datetime import datetime
5 6
 from configparser import ConfigParser
6 7
 from starlette.requests import Request
7 8
 from starlette.routing import Route, Router
8 9
 from starlette.responses import PlainTextResponse, JSONResponse
10
+from starlette.exceptions import HTTPException
9 11
 from pprint import pprint
10 12
 import uvicorn
11 13
 import json

+ 3
- 3
pyheatpump/db.py View File

@@ -34,7 +34,7 @@ class DB():
34 34
         return True
35 35
 
36 36
 
37
-    def commit():
37
+    def commit(self):
38 38
         """
39 39
             Default mode of connecting is autocommit
40 40
         """
@@ -78,7 +78,7 @@ class DB():
78 78
                 print(e)
79 79
                 return []
80 80
             except sqlite3.OperationalError as e:
81
-                raise Exception('Can\'t find DB file %s'.format(filename)) from e
81
+                raise Exception(f'Can\'t find DB file {filename}') from e
82 82
 
83 83
 
84 84
 
@@ -93,7 +93,7 @@ class RowClass(object):
93 93
         if type(attr) == str:
94 94
             q = ("SELECT * FROM {tablename} WHERE ? LIKE '?'", (key, attr))
95 95
         elif type(attr) == int:
96
-            q = ("SELECT * FROM {tablename} WHERE ? LIKE ?", (key, attr))
96
+            q = ("SELECT * FROM {tablename} WHERE ? = ?", (key, attr))
97 97
 
98 98
         res = []
99 99
         for row in DB.sql(*q):

+ 11
- 2
pyheatpump/models/heatpump.py View File

@@ -27,9 +27,18 @@ class Heatpump:
27 27
             self.var_types = VariableType.getall()
28 28
 
29 29
     def __str__(self):
30
-        return str(self.__dict__())
30
+        res = f'{self.mac_address} ['
31
+        res += ', '.join([
32
+            var_type.slabel
33
+            for var_type in self.var_types
34
+        ])
35
+        res += ']'
31 36
 
32
-    def __dict__(self):
37
+    @property
38
+    def packet(self):
39
+        """
40
+        Returns an object containing all values and the current macAddress
41
+        """
33 42
         r = {'macAddress': self.macformat}
34 43
         if not self.last_update:
35 44
             # Since beginning

+ 4
- 4
pyheatpump/models/variable_type.py View File

@@ -2,9 +2,9 @@ from pyheatpump.db import DB, RowClass
2 2
 
3 3
 
4 4
 class VariableType(RowClass):
5
-    slabel: str = None
6
-    label: str = None
7
-    type: str = None
5
+    slabel: str = '' 
6
+    label: str = '' 
7
+    type: str = '' 
8 8
     start_address: int = None
9 9
     end_address: int = None
10 10
 
@@ -28,7 +28,7 @@ class VariableType(RowClass):
28 28
             return bool
29 29
 
30 30
 
31
-    def select():
31
+    def select(self):
32 32
         try:
33 33
             elt = next(super().select('slabel', 'var_type'))
34 34
         except StopIteration:

Loading…
Cancel
Save