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
This commit is contained in:
Shay Levy 2020-11-12 11:12:56 +02:00 committed by GitHub
parent be93060e99
commit 22a0464dce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 21 deletions

View File

@ -30,18 +30,18 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
for block in wrapper.device.blocks: for block in wrapper.device.blocks:
if block.type == "light": if block.type == "light":
blocks.append(block) blocks.append(block)
elif ( elif block.type == "relay":
block.type == "relay" appliance_type = wrapper.device.settings["relays"][int(block.channel)].get(
and wrapper.device.settings["relays"][int(block.channel)].get(
"appliance_type" "appliance_type"
) )
== "light" if appliance_type and appliance_type.lower() == "light":
): blocks.append(block)
blocks.append(block) unique_id = (
unique_id = f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}' f'{wrapper.device.shelly["mac"]}-{block.type}_{block.channel}'
await async_remove_entity_by_domain( )
hass, "switch", unique_id, config_entry.entry_id await async_remove_entity_by_domain(
) hass, "switch", unique_id, config_entry.entry_id
)
if not blocks: if not blocks:
return return

View File

@ -23,18 +23,21 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
relay_blocks = [] relay_blocks = []
for block in wrapper.device.blocks: for block in wrapper.device.blocks:
if block.type == "relay" and ( if block.type == "relay":
wrapper.device.settings["relays"][int(block.channel)].get("appliance_type") appliance_type = wrapper.device.settings["relays"][int(block.channel)].get(
!= "light" "appliance_type"
):
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 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: if not relay_blocks:
return return