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:
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

View file

@ -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