about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhakana <hakan@tarra.se>2020-03-23T20·23+0100
committerGitHub <noreply@github.com>2020-03-23T20·23+0100
commit4a3950a7c50f574530d9085782d2cff1c3df5c4f (patch)
treeab485030d123c980b712d8e812b1d9d59fd8b0a9
parent84e53c8d2b31aa3c31c6e147dd02cf7044bd8765 (diff)
Add temperature and humidity for RM4 mini (0x610e) (#321)
* Add temperature and humidity reading for RM4 Mini

* Change divider for tem and humi (RM4 mini)
-rw-r--r--broadlink/__init__.py27
1 files changed, 20 insertions, 7 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py
index 3a99b03ab72d..627389bd9462 100644
--- a/broadlink/__init__.py
+++ b/broadlink/__init__.py
@@ -635,21 +635,23 @@ class rm(device):
             return True
         return False
 
-    def check_temperature(self):
+    def _read_sensor(self, type, offset, divider):
         packet = bytearray(self._request_header)
-        packet.append(0x01)
+        packet.append(type)
         response = self.send_packet(0x6a, packet)
         err = response[0x22] | (response[0x23] << 8)
         if err != 0:
             return False
         payload = self.decrypt(bytes(response[0x38:]))
-        temp_pos = len(self._request_header) + 4
-        if isinstance(payload[temp_pos], int):
-            temp = (payload[temp_pos] * 10 + payload[temp_pos+1]) / 10.0
+        value_pos = len(self._request_header) + offset
+        if isinstance(payload[value_pos], int):
+            value = (payload[value_pos] + payload[value_pos+1] / divider)
         else:
-            temp = (ord(payload[temp_pos]) * 10 + ord(payload[temp_pos+1])) / 10.0
-        return temp
+            value = (ord(payload[value_pos]) + ord(payload[value_pos+1]) / divider)
+        return value
 
+    def check_temperature(self):
+        return self._read_sensor( 0x01, 4, 10.0 )
 
 class rm4(rm):
     def __init__(self, host, mac, devtype):
@@ -658,6 +660,17 @@ class rm4(rm):
         self._request_header = b'\x04\x00'
         self._code_sending_header = b'\xd0\x00'
 
+    def check_temperature(self):
+        return self._read_sensor( 0x24, 4, 100.0 )
+
+    def check_humidity(self):
+        return self._read_sensor( 0x24, 6, 100.0 )
+
+    def check_sensors(self):
+        return {
+            'temperature': self.check_temperature(),
+            'humidity': self.check_humidity()
+        }
 
 # For legacy compatibility - don't use this
 class rm2(rm):