From 1e92e35bfff99e4c65448d1b30572539b41b3ced Mon Sep 17 00:00:00 2001 From: Felipe Martins Diel <41558831+felipediel@users.noreply.github.com> Date: Sun, 31 Oct 2021 07:48:52 -0300 Subject: [PATCH] Improve code quality of the Broadlink switch platform (#58794) --- homeassistant/components/broadlink/switch.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/broadlink/switch.py b/homeassistant/components/broadlink/switch.py index 5ed1e424f53..a06e67defba 100644 --- a/homeassistant/components/broadlink/switch.py +++ b/homeassistant/components/broadlink/switch.py @@ -1,6 +1,5 @@ """Support for Broadlink switches.""" from abc import ABC, abstractmethod -from functools import partial import logging from broadlink.exceptions import BroadlinkException @@ -108,25 +107,26 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Broadlink switch.""" device = hass.data[DOMAIN].devices[config_entry.entry_id] + switches = [] if device.api.type in {"RM4MINI", "RM4PRO", "RMMINI", "RMMINIB", "RMPRO"}: platform_data = hass.data[DOMAIN].platforms.get(SWITCH_DOMAIN, {}) user_defined_switches = platform_data.get(device.api.mac, {}) - switches = [ + switches.extend( BroadlinkRMSwitch(device, config) for config in user_defined_switches - ] + ) elif device.api.type == "SP1": - switches = [BroadlinkSP1Switch(device)] + switches.append(BroadlinkSP1Switch(device)) elif device.api.type in {"SP2", "SP2S", "SP3", "SP3S", "SP4", "SP4B"}: - switches = [BroadlinkSP2Switch(device)] + switches.append(BroadlinkSP2Switch(device)) elif device.api.type == "BG1": - switches = [BroadlinkBG1Slot(device, slot) for slot in range(1, 3)] + switches.extend(BroadlinkBG1Slot(device, slot) for slot in range(1, 3)) elif device.api.type == "MP1": - switches = [BroadlinkMP1Slot(device, slot) for slot in range(1, 5)] + switches.extend(BroadlinkMP1Slot(device, slot) for slot in range(1, 5)) async_add_entities(switches) @@ -273,9 +273,9 @@ class BroadlinkBG1Slot(BroadlinkSwitch): async def _async_send_packet(self, packet): """Send a packet to the device.""" - set_state = partial(self._device.api.set_state, **{f"pwr{self._slot}": packet}) + state = {f"pwr{self._slot}": packet} try: - await self._device.async_request(set_state) + await self._device.async_request(self._device.api.set_state, **state) except (BroadlinkException, OSError) as err: _LOGGER.error("Failed to send packet: %s", err) return False