From 39ee67bb98978c281225a540e6f3b39fe9058d92 Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:14:11 -0300 Subject: [PATCH] Split the rm and rm4 classes into smaller classes (#529) --- broadlink/__init__.py | 80 +++++++++++++++++++-------------------- broadlink/remote.py | 88 ++++++++++++++++++++++++++++++------------- 2 files changed, 101 insertions(+), 67 deletions(-) diff --git a/broadlink/__init__.py b/broadlink/__init__.py index 0713127..81481f4 100644 --- a/broadlink/__init__.py +++ b/broadlink/__init__.py @@ -9,7 +9,7 @@ from .cover import dooya from .device import device, ping, scan from .exceptions import exception from .light import lb1 -from .remote import rm, rm4 +from .remote import rm, rm4, rm4mini, rm4pro, rmmini, rmminib, rmpro from .sensor import a1 from .switch import bg1, mp1, sp1, sp2, sp2s, sp3, sp3s, sp4, sp4b @@ -54,45 +54,45 @@ SUPPORTED_TYPES = { 0x618B: (sp4b, "SP4L-EU", "Broadlink"), 0x6489: (sp4b, "SP4L-AU", "Broadlink"), 0x648B: (sp4b, "SP4M-US", "Broadlink"), - 0x2712: (rm, "RM pro/pro+", "Broadlink"), - 0x272A: (rm, "RM pro", "Broadlink"), - 0x2737: (rm, "RM mini 3", "Broadlink"), - 0x273D: (rm, "RM pro", "Broadlink"), - 0x277C: (rm, "RM home", "Broadlink"), - 0x2783: (rm, "RM home", "Broadlink"), - 0x2787: (rm, "RM pro", "Broadlink"), - 0x278B: (rm, "RM plus", "Broadlink"), - 0x278F: (rm, "RM mini", "Broadlink"), - 0x2797: (rm, "RM pro+", "Broadlink"), - 0x279D: (rm, "RM pro+", "Broadlink"), - 0x27A1: (rm, "RM plus", "Broadlink"), - 0x27A6: (rm, "RM plus", "Broadlink"), - 0x27A9: (rm, "RM pro+", "Broadlink"), - 0x27C2: (rm, "RM mini 3", "Broadlink"), - 0x27C3: (rm, "RM pro+", "Broadlink"), - 0x27C7: (rm, "RM mini 3", "Broadlink"), - 0x27CC: (rm, "RM mini 3", "Broadlink"), - 0x27CD: (rm, "RM mini 3", "Broadlink"), - 0x27D0: (rm, "RM mini 3", "Broadlink"), - 0x27D1: (rm, "RM mini 3", "Broadlink"), - 0x27D3: (rm, "RM mini 3", "Broadlink"), - 0x27DE: (rm, "RM mini 3", "Broadlink"), - 0x51DA: (rm4, "RM4 mini", "Broadlink"), - 0x5F36: (rm4, "RM mini 3", "Broadlink"), - 0x6026: (rm4, "RM4 pro", "Broadlink"), - 0x6070: (rm4, "RM4C mini", "Broadlink"), - 0x610E: (rm4, "RM4 mini", "Broadlink"), - 0x610F: (rm4, "RM4C mini", "Broadlink"), - 0x61A2: (rm4, "RM4 pro", "Broadlink"), - 0x62BC: (rm4, "RM4 mini", "Broadlink"), - 0x62BE: (rm4, "RM4C mini", "Broadlink"), - 0x6364: (rm4, "RM4S", "Broadlink"), - 0x648D: (rm4, "RM4 mini", "Broadlink"), - 0x649B: (rm4, "RM4 pro", "Broadlink"), - 0x6508: (rm4, "RM mini 3", "Broadlink"), - 0x6539: (rm4, "RM4C mini", "Broadlink"), - 0x653A: (rm4, "RM4 mini", "Broadlink"), - 0x653C: (rm4, "RM4 pro", "Broadlink"), + 0x2737: (rmmini, "RM mini 3", "Broadlink"), + 0x278F: (rmmini, "RM mini", "Broadlink"), + 0x27C2: (rmmini, "RM mini 3", "Broadlink"), + 0x27C7: (rmmini, "RM mini 3", "Broadlink"), + 0x27CC: (rmmini, "RM mini 3", "Broadlink"), + 0x27CD: (rmmini, "RM mini 3", "Broadlink"), + 0x27D0: (rmmini, "RM mini 3", "Broadlink"), + 0x27D1: (rmmini, "RM mini 3", "Broadlink"), + 0x27D3: (rmmini, "RM mini 3", "Broadlink"), + 0x27DE: (rmmini, "RM mini 3", "Broadlink"), + 0x2712: (rmpro, "RM pro/pro+", "Broadlink"), + 0x272A: (rmpro, "RM pro", "Broadlink"), + 0x273D: (rmpro, "RM pro", "Broadlink"), + 0x277C: (rmpro, "RM home", "Broadlink"), + 0x2783: (rmpro, "RM home", "Broadlink"), + 0x2787: (rmpro, "RM pro", "Broadlink"), + 0x278B: (rmpro, "RM plus", "Broadlink"), + 0x2797: (rmpro, "RM pro+", "Broadlink"), + 0x279D: (rmpro, "RM pro+", "Broadlink"), + 0x27A1: (rmpro, "RM plus", "Broadlink"), + 0x27A6: (rmpro, "RM plus", "Broadlink"), + 0x27A9: (rmpro, "RM pro+", "Broadlink"), + 0x27C3: (rmpro, "RM pro+", "Broadlink"), + 0x5F36: (rmminib, "RM mini 3", "Broadlink"), + 0x6508: (rmminib, "RM mini 3", "Broadlink"), + 0x51DA: (rm4mini, "RM4 mini", "Broadlink"), + 0x6070: (rm4mini, "RM4C mini", "Broadlink"), + 0x610E: (rm4mini, "RM4 mini", "Broadlink"), + 0x610F: (rm4mini, "RM4C mini", "Broadlink"), + 0x62BC: (rm4mini, "RM4 mini", "Broadlink"), + 0x62BE: (rm4mini, "RM4C mini", "Broadlink"), + 0x6364: (rm4mini, "RM4S", "Broadlink"), + 0x648D: (rm4mini, "RM4 mini", "Broadlink"), + 0x6539: (rm4mini, "RM4C mini", "Broadlink"), + 0x653A: (rm4mini, "RM4 mini", "Broadlink"), + 0x6026: (rm4pro, "RM4 pro", "Broadlink"), + 0x61A2: (rm4pro, "RM4 pro", "Broadlink"), + 0x649B: (rm4pro, "RM4 pro", "Broadlink"), + 0x653C: (rm4pro, "RM4 pro", "Broadlink"), 0x2714: (a1, "e-Sensor", "Broadlink"), 0x4EB5: (mp1, "MP1-1K4S", "Broadlink"), 0x4EF7: (mp1, "MP1-1K4S", "Broadlink (OEM)"), diff --git a/broadlink/remote.py b/broadlink/remote.py index f97b755..7e4f91e 100644 --- a/broadlink/remote.py +++ b/broadlink/remote.py @@ -5,10 +5,10 @@ from .device import device from .exceptions import check_error -class rm(device): - """Controls a Broadlink RM.""" +class rmmini(device): + """Controls a Broadlink RM mini 3.""" - TYPE = "RM2" + TYPE = "RMMINI" def _send(self, command: int, data: bytes = b'') -> bytes: """Send a packet to the device.""" @@ -18,10 +18,6 @@ class rm(device): payload = self.decrypt(resp[0x38:]) return payload[0x4:] - def check_data(self) -> bytes: - """Return the last captured code.""" - return self._send(0x4) - def send_data(self, data: bytes) -> None: """Send a code to the device.""" self._send(0x2, data) @@ -30,14 +26,20 @@ class rm(device): """Enter infrared learning mode.""" self._send(0x3) + def check_data(self) -> bytes: + """Return the last captured code.""" + return self._send(0x4) + + +class rmpro(rmmini): + """Controls a Broadlink RM pro.""" + + TYPE = "RMPRO" + def sweep_frequency(self) -> None: """Sweep frequency.""" self._send(0x19) - def cancel_sweep_frequency(self) -> None: - """Cancel sweep frequency.""" - self._send(0x1E) - def check_frequency(self) -> bool: """Return True if the frequency was identified successfully.""" resp = self._send(0x1A) @@ -47,22 +49,25 @@ class rm(device): """Enter radiofrequency learning mode.""" self._send(0x1B) - def check_temperature(self) -> float: - """Return the temperature.""" - return self.check_sensors()["temperature"] + def cancel_sweep_frequency(self) -> None: + """Cancel sweep frequency.""" + self._send(0x1E) def check_sensors(self) -> dict: """Return the state of the sensors.""" resp = self._send(0x1) - temperature = struct.unpack(" float: + """Return the temperature.""" + return self.check_sensors()["temperature"] -class rm4(rm): - """Controls a Broadlink RM4.""" +class rmminib(rmmini): + """Controls a Broadlink RM mini 3 (new firmware).""" - TYPE = "RM4" + TYPE = "RMMINIB" def _send(self, command: int, data: bytes = b'') -> bytes: """Send a packet to the device.""" @@ -73,14 +78,43 @@ class rm4(rm): p_len = struct.unpack(" float: - """Return the humidity.""" - return self.check_sensors()["humidity"] + +class rm4mini(rmminib): + """Controls a Broadlink RM4 mini.""" + + TYPE = "RM4MINI" def check_sensors(self) -> dict: """Return the state of the sensors.""" resp = self._send(0x24) - temperature = struct.unpack(" float: + """Return the temperature.""" + return self.check_sensors()["temperature"] + + def check_humidity(self) -> float: + """Return the humidity.""" + return self.check_sensors()["humidity"] + + +class rm4pro(rm4mini, rmpro): + """Controls a Broadlink RM4 pro.""" + + TYPE = "RM4PRO" + + +class rm(rmpro): + """For backwards compatibility.""" + + TYPE = "RM2" + + +class rm4(rm4pro): + """For backwards compatibility.""" + + TYPE = "RM4"