Browse Source

[variable_type] update complement function to a simpler version + tests

Maxime Alves LIRMM@home 3 years ago
parent
commit
f9c2acdcbc
2 changed files with 6 additions and 5 deletions
  1. 3
    2
      pyheatpump/models/variable_type.py
  2. 3
    3
      tests/test_variable_values.py

+ 3
- 2
pyheatpump/models/variable_type.py View File

@@ -23,7 +23,8 @@ class VariableType(RowClass):
23 23
 
24 24
     def cast(self):
25 25
         # Function to convert numbers > 2**15 to negative numbers (issue #30)
26
-        complement = lambda x: x - (1 << 16 if x & (1 << 15) else 0)
26
+        #complement = lambda x: x - (1 << 16 if x & (1 << 15) else 0)
27
+        complement = lambda x: x - (1 << 16) if x >> 15 else x
27 28
 
28 29
         if self.type == 'bool':
29 30
             # returns a boolean
@@ -69,7 +70,7 @@ class VariableType(RowClass):
69 70
         values = Variable.getall_values_of_type(self)
70 71
         res = {}
71 72
         for address, variable in values.items():
72
-            logger.error('address: %s, start_addres: %s, calc: %s',
73
+            logger.debug('address: %s, start_addres: %s, calc: %s',
73 74
                 address, self.start_address, address - self.start_address + 1)
74 75
             res[str(address - self.start_address + 1)] = variable
75 76
         return res

+ 3
- 3
tests/test_variable_values.py View File

@@ -84,15 +84,15 @@ def test_get_type_address(set_test_db):
84 84
 
85 85
         r = c.get('/D/10')
86 86
         d_resp = r.content.decode()
87
-        assert d_resp == 'True'
87
+        assert d_resp == '1'
88 88
 
89 89
         r = c.get('/D/11')
90 90
         d_resp = r.content.decode()
91
-        assert d_resp == 'True'
91
+        assert d_resp == '1'
92 92
 
93 93
         r = c.get('/D/12')
94 94
         d_resp = r.content.decode()
95
-        assert d_resp == 'False'
95
+        assert d_resp == '0'
96 96
     except AssertionError as exc:
97 97
         print(d_resp)
98 98
         raise exc

Loading…
Cancel
Save