From 0ee6712579a71a93204c6496a1a21412451b799d Mon Sep 17 00:00:00 2001 From: RenierM26 <66512715+RenierM26@users.noreply.github.com> Date: Thu, 18 Feb 2021 20:29:11 +0200 Subject: [PATCH] Improve switch error correction. --- custom_components/ezviz_cloud/switch.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/ezviz_cloud/switch.py b/custom_components/ezviz_cloud/switch.py index 49428c1..0834c3c 100644 --- a/custom_components/ezviz_cloud/switch.py +++ b/custom_components/ezviz_cloud/switch.py @@ -34,10 +34,12 @@ async def async_setup_entry( supported_switches = set(supported_switches) for idx, camera in enumerate(coordinator.data): - if camera.get("switches"): - for switch in camera.get("switches"): - if switch in supported_switches: - switch_entities.append(EzvizSwitch(coordinator, idx, switch)) + if not camera.get("switches"): + continue + for switch in camera["switches"]: + if switch not in supported_switches: + continue + switch_entities.append(EzvizSwitch(coordinator, idx, switch)) async_add_entities(switch_entities)