From 22a0464dce3ad4192d82236d30856dedf95761df Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Thu, 12 Nov 2020 11:12:56 +0200 Subject: [PATCH] Make Appliance Type Case-insensitive (#43114) "appliance_type" is a free text parameter in the device settings, this fix will make the comparison case-insensitive --- homeassistant/components/shelly/light.py | 20 +++++++++--------- homeassistant/components/shelly/switch.py | 25 +++++++++++++---------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/shelly/light.py b/homeassistant/components/shelly/light.py index b62b5ee5e8c..83c7f3cf177 100644 --- a/homeassistant/components/shelly/light.py +++ b/homeassistant/components/shelly/light.py @@ -30,18 +30,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities): for block in wrapper.device.blocks: if block.type == "light": blocks.append(block) - elif ( - block.type == "relay" - and wrapper.device.settings["relays"][int(block.channel)].get( + elif block.type == "relay": + appliance_type = wrapper.device.settings["relays"][int(block.channel)].get( "appliance_type" ) - == "light" - ): - blocks.append(block) - unique_id = f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}' - await async_remove_entity_by_domain( - hass, "switch", unique_id, config_entry.entry_id - ) + if appliance_type and appliance_type.lower() == "light": + blocks.append(block) + unique_id = ( + f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}' + ) + await async_remove_entity_by_domain( + hass, "switch", unique_id, config_entry.entry_id + ) if not blocks: return diff --git a/homeassistant/components/shelly/switch.py b/homeassistant/components/shelly/switch.py index ee5ecc5d8f8..653f090bf4e 100644 --- a/homeassistant/components/shelly/switch.py +++ b/homeassistant/components/shelly/switch.py @@ -23,18 +23,21 @@ async def async_setup_entry(hass, config_entry, async_add_entities): relay_blocks = [] for block in wrapper.device.blocks: - if block.type == "relay" and ( - wrapper.device.settings["relays"][int(block.channel)].get("appliance_type") - != "light" - ): - relay_blocks.append(block) - unique_id = f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}' - await async_remove_entity_by_domain( - hass, - "light", - unique_id, - config_entry.entry_id, + if block.type == "relay": + appliance_type = wrapper.device.settings["relays"][int(block.channel)].get( + "appliance_type" ) + if not appliance_type or appliance_type.lower() != "light": + relay_blocks.append(block) + unique_id = ( + f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}' + ) + await async_remove_entity_by_domain( + hass, + "light", + unique_id, + config_entry.entry_id, + ) if not relay_blocks: return