1
0
mirror of https://github.com/mjg59/python-broadlink.git synced 2024-11-13 03:00:11 +01:00

Make the type a class attribute (#530)

This commit is contained in:
Felipe Martins Diel 2021-01-28 19:16:25 -03:00 committed by Felipe Martins Diel
parent 586d44493e
commit e12fd6f115
8 changed files with 19 additions and 56 deletions

View File

@ -6,17 +6,14 @@ from .exceptions import check_error
class S1C(device): class S1C(device):
"""Controls a Broadlink S1C.""" """Controls a Broadlink S1C."""
TYPE = "S1C"
_SENSORS_TYPES = { _SENSORS_TYPES = {
0x31: "Door Sensor", # 49 as hex 0x31: "Door Sensor", # 49 as hex
0x91: "Key Fob", # 145 as hex, as serial on fob corpse 0x91: "Key Fob", # 145 as hex, as serial on fob corpse
0x21: "Motion Sensor", # 33 as hex 0x21: "Motion Sensor", # 33 as hex
} }
def __init__(self, *args, **kwargs) -> None:
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "S1C"
def get_sensors_status(self) -> dict: def get_sensors_status(self) -> dict:
"""Return the state of the sensors.""" """Return the state of the sensors."""
packet = bytearray(16) packet = bytearray(16)

View File

@ -9,10 +9,7 @@ from .helpers import calculate_crc16
class hysen(device): class hysen(device):
"""Controls a Hysen HVAC.""" """Controls a Hysen HVAC."""
def __init__(self, *args, **kwargs) -> None: TYPE = "Hysen heating controller"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "Hysen heating controller"
# Send a request # Send a request
# input_payload should be a bytearray, usually 6 bytes, e.g. bytearray([0x01,0x06,0x00,0x02,0x10,0x00]) # input_payload should be a bytearray, usually 6 bytes, e.g. bytearray([0x01,0x06,0x00,0x02,0x10,0x00])

View File

@ -8,10 +8,7 @@ from .exceptions import check_error
class dooya(device): class dooya(device):
"""Controls a Dooya curtain motor.""" """Controls a Dooya curtain motor."""
def __init__(self, *args, **kwargs) -> None: TYPE = "Dooya DT360E"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "Dooya DT360E"
def _send(self, magic1: int, magic2: int) -> int: def _send(self, magic1: int, magic2: int) -> int:
"""Send a packet to the device.""" """Send a packet to the device."""

View File

@ -87,6 +87,8 @@ def ping(address: str, port: int = 80) -> None:
class device: class device:
"""Controls a Broadlink device.""" """Controls a Broadlink device."""
TYPE = "Unknown"
def __init__( def __init__(
self, self,
host: Tuple[str, int], host: Tuple[str, int],
@ -110,7 +112,7 @@ class device:
self.count = random.randint(0x8000, 0xFFFF) self.count = random.randint(0x8000, 0xFFFF)
self.iv = bytes.fromhex("562e17996d093d28ddb3ba695a2e6f58") self.iv = bytes.fromhex("562e17996d093d28ddb3ba695a2e6f58")
self.id = 0 self.id = 0
self.type = "Unknown" self.type = self.TYPE # For backwards compatibility.
self.lock = threading.Lock() self.lock = threading.Lock()
self.aes = None self.aes = None

View File

@ -11,6 +11,8 @@ from .exceptions import check_error
class lb1(device): class lb1(device):
"""Controls a Broadlink LB1.""" """Controls a Broadlink LB1."""
TYPE = "LB1"
@enum.unique @enum.unique
class ColorMode(enum.IntEnum): class ColorMode(enum.IntEnum):
"""Enumerates color modes.""" """Enumerates color modes."""
@ -18,11 +20,6 @@ class lb1(device):
WHITE = 1 WHITE = 1
SCENE = 2 SCENE = 2
def __init__(self, *args, **kwargs) -> None:
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "LB1"
def get_state(self) -> dict: def get_state(self) -> dict:
"""Return the power state of the device. """Return the power state of the device.

View File

@ -8,10 +8,7 @@ from .exceptions import check_error
class rm(device): class rm(device):
"""Controls a Broadlink RM.""" """Controls a Broadlink RM."""
def __init__(self, *args, **kwargs) -> None: TYPE = "RM2"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "RM2"
def _send(self, command: int, data: bytes = b'') -> bytes: def _send(self, command: int, data: bytes = b'') -> bytes:
"""Send a packet to the device.""" """Send a packet to the device."""
@ -65,10 +62,7 @@ class rm(device):
class rm4(rm): class rm4(rm):
"""Controls a Broadlink RM4.""" """Controls a Broadlink RM4."""
def __init__(self, *args, **kwargs) -> None: TYPE = "RM4"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "RM4"
def _send(self, command: int, data: bytes = b'') -> bytes: def _send(self, command: int, data: bytes = b'') -> bytes:
"""Send a packet to the device.""" """Send a packet to the device."""

View File

@ -8,17 +8,14 @@ from .exceptions import check_error
class a1(device): class a1(device):
"""Controls a Broadlink A1.""" """Controls a Broadlink A1."""
TYPE = "A1"
_SENSORS_AND_LEVELS = ( _SENSORS_AND_LEVELS = (
("light", ("dark", "dim", "normal", "bright")), ("light", ("dark", "dim", "normal", "bright")),
("air_quality", ("excellent", "good", "normal", "bad")), ("air_quality", ("excellent", "good", "normal", "bad")),
("noise", ("quiet", "normal", "noisy")), ("noise", ("quiet", "normal", "noisy")),
) )
def __init__(self, *args, **kwargs) -> None:
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "A1"
def check_sensors(self) -> dict: def check_sensors(self) -> dict:
"""Return the state of the sensors.""" """Return the state of the sensors."""
data = self.check_sensors_raw() data = self.check_sensors_raw()

View File

@ -9,10 +9,7 @@ from .exceptions import check_error
class mp1(device): class mp1(device):
"""Controls a Broadlink MP1.""" """Controls a Broadlink MP1."""
def __init__(self, *args, **kwargs) -> None: TYPE = "MP1"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "MP1"
def set_power_mask(self, sid_mask: int, state: bool) -> None: def set_power_mask(self, sid_mask: int, state: bool) -> None:
"""Set the power state of the device.""" """Set the power state of the device."""
@ -70,10 +67,7 @@ class mp1(device):
class bg1(device): class bg1(device):
"""Controls a BG Electrical smart outlet.""" """Controls a BG Electrical smart outlet."""
def __init__(self, *args, **kwargs) -> None: TYPE = "BG1"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "BG1"
def get_state(self) -> dict: def get_state(self) -> dict:
"""Return the power state of the device. """Return the power state of the device.
@ -151,10 +145,7 @@ class bg1(device):
class sp1(device): class sp1(device):
"""Controls a Broadlink SP1.""" """Controls a Broadlink SP1."""
def __init__(self, *args, **kwargs) -> None: TYPE = "SP1"
"""Initialize the device."""
device.__init__(self, *args, **kwargs)
self.type = "SP1"
def set_power(self, state: bool) -> None: def set_power(self, state: bool) -> None:
"""Set the power state of the device.""" """Set the power state of the device."""
@ -167,10 +158,7 @@ class sp1(device):
class sp2(device): class sp2(device):
"""Controls a Broadlink SP2.""" """Controls a Broadlink SP2."""
def __init__(self, *args, **kwargs) -> None: TYPE = "SP2"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "SP2"
def set_power(self, state: bool) -> None: def set_power(self, state: bool) -> None:
"""Set the power state of the device.""" """Set the power state of the device."""
@ -225,10 +213,7 @@ class sp2(device):
class sp4(device): class sp4(device):
"""Controls a Broadlink SP4.""" """Controls a Broadlink SP4."""
def __init__(self, *args, **kwargs) -> None: TYPE = "SP4"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "SP4"
def set_power(self, state: bool) -> None: def set_power(self, state: bool) -> None:
"""Set the power state of the device.""" """Set the power state of the device."""
@ -307,10 +292,7 @@ class sp4(device):
class sp4b(sp4): class sp4b(sp4):
"""Controls a Broadlink SP4 (type B).""" """Controls a Broadlink SP4 (type B)."""
def __init__(self, *args, **kwargs) -> None: TYPE = "SP4B"
"""Initialize the controller."""
device.__init__(self, *args, **kwargs)
self.type = "SP4B"
def get_state(self) -> dict: def get_state(self) -> dict:
"""Get full state of device.""" """Get full state of device."""