mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Make multi-switches device a single device with 2 switches (#39689)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
df8daf561e
commit
f298281ec4
@ -20,22 +20,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
if not relay_blocks:
|
if not relay_blocks:
|
||||||
return
|
return
|
||||||
|
|
||||||
multiple_blocks = len(relay_blocks) > 1
|
async_add_entities(RelaySwitch(wrapper, block) for block in relay_blocks)
|
||||||
async_add_entities(
|
|
||||||
RelaySwitch(wrapper, block, multiple_blocks=multiple_blocks)
|
|
||||||
for block in relay_blocks
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RelaySwitch(ShellyBlockEntity, SwitchEntity):
|
class RelaySwitch(ShellyBlockEntity, SwitchEntity):
|
||||||
"""Switch that controls a relay block on Shelly devices."""
|
"""Switch that controls a relay block on Shelly devices."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, wrapper: ShellyDeviceWrapper, block: RelayBlock) -> None:
|
||||||
self, wrapper: ShellyDeviceWrapper, block: RelayBlock, multiple_blocks
|
|
||||||
) -> None:
|
|
||||||
"""Initialize relay switch."""
|
"""Initialize relay switch."""
|
||||||
super().__init__(wrapper, block)
|
super().__init__(wrapper, block)
|
||||||
self.multiple_blocks = multiple_blocks
|
|
||||||
self.control_result = None
|
self.control_result = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -46,19 +39,6 @@ class RelaySwitch(ShellyBlockEntity, SwitchEntity):
|
|||||||
|
|
||||||
return self.block.output
|
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):
|
async def async_turn_on(self, **kwargs):
|
||||||
"""Turn on relay."""
|
"""Turn on relay."""
|
||||||
self.control_result = await self.block.set_state(turn="on")
|
self.control_result = await self.block.set_state(turn="on")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user