about summary refs log tree commit diff
path: root/broadlink
diff options
context:
space:
mode:
authorMayeul Cantan <mayeul.cantan@gmail.com>2018-04-30T21·06+0200
committerMayeul Cantan <mayeul.cantan@gmail.com>2018-04-30T21·06+0200
commit56b2ac36e5a2359272f4af8a49cfaf3e1891733a (patch)
tree01da77a7aad80dbde5e8d01010a188fe4329b090 /broadlink
parent766b7b00fb1cec868e3d5fca66f1aada208959ce (diff)
Refactor the device list
It is now more readable, which should make it easier to parse the code
and add new devices.
Diffstat (limited to 'broadlink')
-rw-r--r--broadlink/__init__.py103
1 files changed, 42 insertions, 61 deletions
diff --git a/broadlink/__init__.py b/broadlink/__init__.py
index a5415c23dc7a..9dccc8d4b2d0 100644
--- a/broadlink/__init__.py
+++ b/broadlink/__init__.py
@@ -13,69 +13,50 @@ import sys
 import threading
 import codecs
 
+
 def gendevice(devtype, host, mac):
-  if devtype == 0: # SP1
-    return sp1(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2711: # SP2
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2719 or devtype == 0x7919 or devtype == 0x271a or devtype == 0x791a: # Honeywell SP2
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2720: # SPMini
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x753e: # SP3
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x7D00: # OEM branded SP3
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x947a or devtype == 0x9479: # SP3S
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2728: # SPMini2
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2733 or devtype == 0x273e: # OEM branded SPMini
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype >= 0x7530 and devtype <= 0x7918: # OEM branded SPMini2
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2736: # SPMiniPlus
-    return sp2(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2712: # RM2
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2737: # RM Mini
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x273d: # RM Pro Phicomm
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2783: # RM2 Home Plus
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x277c: # RM2 Home Plus GDT
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x272a: # RM2 Pro Plus
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2787: # RM2 Pro Plus2
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x279d: # RM2 Pro Plus3
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x27a9: # RM2 Pro Plus_300
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x278b: # RM2 Pro Plus BL
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2797: # RM2 Pro Plus HYC
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x27a1: # RM2 Pro Plus R1
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x27a6: # RM2 Pro PP
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x278f: # RM Mini Shate
-    return rm(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2714: # A1
-    return a1(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x4EB5 or devtype == 0x4EF7: # MP1: 0x4eb5, honyar oem mp1: 0x4ef7
-    return mp1(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x4EAD: # Hysen controller
-    return hysen(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x2722: # S1 (SmartOne Alarm Kit)
-    return S1C(host=host, mac=mac, devtype=devtype)
-  elif devtype == 0x4E4D: # Dooya DT360E (DOOYA_CURTAIN_V2)
-    return dooya(host=host, mac=mac, devtype=devtype)
-  else:
+  devices = {
+          sp1: [0],
+          sp2: [0x2711,                          # SP2
+                0x2719, 0x7919, 0x271a, 0x791a,  # Honeywell SP2
+                0x2720,                          # SPMini
+                0x753e,                          # SP3
+                0x7D00,                          # OEM branded SP3
+                0x947a, 0x9479,                  # SP3S
+                0x2728,                          # SPMini2
+                0x2733, 0x273e,                  # OEM branded SPMini
+                0x7530, 0x7918,                  # OEM branded SPMini2
+                0x2736                           # SPMiniPlus
+                ],
+          rm: [0x2712,  # RM2
+               0x2737,  # RM Mini
+               0x273d,  # RM Pro Phicomm
+               0x2783,  # RM2 Home Plus
+               0x277c,  # RM2 Home Plus GDT
+               0x272a,  # RM2 Pro Plus
+               0x2787,  # RM2 Pro Plus2
+               0x279d,  # RM2 Pro Plus3
+               0x27a9,  # RM2 Pro Plus_300
+               0x278b,  # RM2 Pro Plus BL
+               0x2797,  # RM2 Pro Plus HYC
+               0x27a1,  # RM2 Pro Plus R1
+               0x27a6,  # RM2 Pro PP
+               0x278f   # RM Mini Shate
+               ],
+          a1: [0x2714],  # A1
+          mp1: [0x4EB5,  # MP1
+                0x4EF7   # Honyar oem mp1
+                ],
+          hysen: [0x4EAD],  # Hysen controller
+          S1C: [0x2722],  # S1 (SmartOne Alarm Kit)
+          dooya: [0x4E4D]  # Dooya DT360E (DOOYA_CURTAIN_V2)
+          }
+
+  # Look for the class associated to devtype in devices
+  [deviceClass] = [dev for dev in devices if devtype in devices[dev]] or [None]
+  if deviceClass is None:
     return device(host=host, mac=mac, devtype=devtype)
+  return deviceClass(host=host, mac=mac, devtype=devtype)
 
 def discover(timeout=None, local_ip_address=None):
   if local_ip_address is None: