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
 
23
 
24
     def cast(self):
24
     def cast(self):
25
         # Function to convert numbers > 2**15 to negative numbers (issue #30)
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
         if self.type == 'bool':
29
         if self.type == 'bool':
29
             # returns a boolean
30
             # returns a boolean
69
         values = Variable.getall_values_of_type(self)
70
         values = Variable.getall_values_of_type(self)
70
         res = {}
71
         res = {}
71
         for address, variable in values.items():
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
                 address, self.start_address, address - self.start_address + 1)
74
                 address, self.start_address, address - self.start_address + 1)
74
             res[str(address - self.start_address + 1)] = variable
75
             res[str(address - self.start_address + 1)] = variable
75
         return res
76
         return res

+ 3
- 3
tests/test_variable_values.py View File

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

Loading…
Cancel
Save