Add support for Broadlink SP4 series and the latest SP mini 3 devices (#41522)

* Add support for Broadlink SP4 series

* Bump python-broadlink to 0.16

* Fix stale docstring
pull/43019/head
Felipe Martins Diel 2020-11-08 14:19:28 -03:00 committed by GitHub
parent 30e0d14499
commit e5fe0c40ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 38 additions and 4 deletions

View File

@ -8,7 +8,7 @@ DOMAIN = "broadlink"
DOMAINS_AND_TYPES = ( DOMAINS_AND_TYPES = (
(REMOTE_DOMAIN, ("RM2", "RM4")), (REMOTE_DOMAIN, ("RM2", "RM4")),
(SENSOR_DOMAIN, ("A1", "RM2", "RM4")), (SENSOR_DOMAIN, ("A1", "RM2", "RM4")),
(SWITCH_DOMAIN, ("MP1", "RM2", "RM4", "SP1", "SP2")), (SWITCH_DOMAIN, ("MP1", "RM2", "RM4", "SP1", "SP2", "SP4", "SP4B")),
) )
DEFAULT_PORT = 80 DEFAULT_PORT = 80

View File

@ -2,7 +2,7 @@
"domain": "broadlink", "domain": "broadlink",
"name": "Broadlink", "name": "Broadlink",
"documentation": "https://www.home-assistant.io/integrations/broadlink", "documentation": "https://www.home-assistant.io/integrations/broadlink",
"requirements": ["broadlink==0.15.0"], "requirements": ["broadlink==0.16.0"],
"codeowners": ["@danielhiversen", "@felipediel"], "codeowners": ["@danielhiversen", "@felipediel"],
"config_flow": true "config_flow": true
} }

View File

@ -121,6 +121,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
elif device.api.type == "SP2": elif device.api.type == "SP2":
switches = [BroadlinkSP2Switch(device)] switches = [BroadlinkSP2Switch(device)]
elif device.api.type in {"SP4", "SP4B"}:
switches = [BroadlinkSP4Switch(device)]
elif device.api.type == "MP1": elif device.api.type == "MP1":
switches = [BroadlinkMP1Slot(device, slot) for slot in range(1, 5)] switches = [BroadlinkMP1Slot(device, slot) for slot in range(1, 5)]
@ -294,6 +297,27 @@ class BroadlinkSP2Switch(BroadlinkSP1Switch):
self.async_write_ha_state() self.async_write_ha_state()
class BroadlinkSP4Switch(BroadlinkSP1Switch):
"""Representation of a Broadlink SP4 switch."""
def __init__(self, device, *args, **kwargs):
"""Initialize the switch."""
super().__init__(device, *args, **kwargs)
self._state = self._coordinator.data["pwr"]
@property
def assumed_state(self):
"""Return True if unable to access real state of the switch."""
return False
@callback
def update_data(self):
"""Update data."""
if self._coordinator.last_update_success:
self._state = self._coordinator.data["pwr"]
self.async_write_ha_state()
class BroadlinkMP1Slot(BroadlinkSwitch): class BroadlinkMP1Slot(BroadlinkSwitch):
"""Representation of a Broadlink MP1 slot.""" """Representation of a Broadlink MP1 slot."""

View File

@ -31,6 +31,8 @@ def get_update_manager(device):
"RM4": BroadlinkRMUpdateManager, "RM4": BroadlinkRMUpdateManager,
"SP1": BroadlinkSP1UpdateManager, "SP1": BroadlinkSP1UpdateManager,
"SP2": BroadlinkSP2UpdateManager, "SP2": BroadlinkSP2UpdateManager,
"SP4": BroadlinkSP4UpdateManager,
"SP4B": BroadlinkSP4UpdateManager,
} }
return update_managers[device.api.type](device) return update_managers[device.api.type](device)
@ -153,3 +155,11 @@ class BroadlinkSP2UpdateManager(BroadlinkUpdateManager):
except (CommandNotSupportedError, StorageError): except (CommandNotSupportedError, StorageError):
data["load_power"] = None data["load_power"] = None
return data return data
class BroadlinkSP4UpdateManager(BroadlinkUpdateManager):
"""Manages updates for Broadlink SP4 devices."""
async def async_fetch_data(self):
"""Fetch data from the device."""
return await self.device.async_request(self.device.api.get_state)

View File

@ -380,7 +380,7 @@ boto3==1.9.252
bravia-tv==1.0.6 bravia-tv==1.0.6
# homeassistant.components.broadlink # homeassistant.components.broadlink
broadlink==0.15.0 broadlink==0.16.0
# homeassistant.components.brother # homeassistant.components.brother
brother==0.1.18 brother==0.1.18

View File

@ -204,7 +204,7 @@ bond-api==0.1.8
bravia-tv==1.0.6 bravia-tv==1.0.6
# homeassistant.components.broadlink # homeassistant.components.broadlink
broadlink==0.15.0 broadlink==0.16.0
# homeassistant.components.brother # homeassistant.components.brother
brother==0.1.18 brother==0.1.18