From f298281ec468ab7e57385ebbf3c9ac292c3b9700 Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Sun, 6 Sep 2020 16:05:10 +0200 Subject: [PATCH] Make multi-switches device a single device with 2 switches (#39689) Co-authored-by: Paulus Schoutsen --- homeassistant/components/shelly/switch.py | 24 ++--------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/shelly/switch.py b/homeassistant/components/shelly/switch.py index 9bd14c49ab3..7dd57467045 100644 --- a/homeassistant/components/shelly/switch.py +++ b/homeassistant/components/shelly/switch.py @@ -20,22 +20,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if not relay_blocks: return - multiple_blocks = len(relay_blocks) > 1 - async_add_entities( - RelaySwitch(wrapper, block, multiple_blocks=multiple_blocks) - for block in relay_blocks - ) + async_add_entities(RelaySwitch(wrapper, block) for block in relay_blocks) class RelaySwitch(ShellyBlockEntity, SwitchEntity): """Switch that controls a relay block on Shelly devices.""" - def __init__( - self, wrapper: ShellyDeviceWrapper, block: RelayBlock, multiple_blocks - ) -> None: + def __init__(self, wrapper: ShellyDeviceWrapper, block: RelayBlock) -> None: """Initialize relay switch.""" super().__init__(wrapper, block) - self.multiple_blocks = multiple_blocks self.control_result = None @property @@ -46,19 +39,6 @@ class RelaySwitch(ShellyBlockEntity, SwitchEntity): return self.block.output - @property - def device_info(self): - """Device info.""" - if not self.multiple_blocks: - return super().device_info - - # If a device has multiple relays, we want to expose as separate device - return { - "name": self.name, - "identifiers": {(DOMAIN, self.wrapper.mac, self.block.index)}, - "via_device": (DOMAIN, self.wrapper.mac), - } - async def async_turn_on(self, **kwargs): """Turn on relay.""" self.control_result = await self.block.set_state(turn="on")