From eba1ac000197b3ade824622ecec0c6643b54256b Mon Sep 17 00:00:00 2001 From: RoaringSon Date: Mon, 6 Nov 2023 19:50:22 +0100 Subject: [PATCH] Update switch.py Workaround for "TypeError: 'NoneType' object is not iterable" bug when UNMANAGED rigs are present in NH. --- custom_components/nicehash/switch.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/custom_components/nicehash/switch.py b/custom_components/nicehash/switch.py index c47ea8e..bbf3fa6 100644 --- a/custom_components/nicehash/switch.py +++ b/custom_components/nicehash/switch.py @@ -67,18 +67,20 @@ def _update_entities(): new_dev.append(rig_switch) _update_entities.dev.append(rig_switch.unique_id) - for dev in rig.get("devices"): - device_id = dev.get("id") - device_switch = NiceHashDeviceSwitch( - hass.data[DOMAIN][config_entry.entry_id][API], - coordinator, - config_entry, - rig_id, - device_id, - ) - if device_switch.unique_id not in _update_entities.dev: - new_dev.append(device_switch) - _update_entities.dev.append(device_switch.unique_id) + rig_devices = rig.get("devices") + if rig_devices: + for dev in rig_devices: + device_id = dev.get("id") + device_switch = NiceHashDeviceSwitch( + hass.data[DOMAIN][config_entry.entry_id][API], + coordinator, + config_entry, + rig_id, + device_id, + ) + if device_switch.unique_id not in _update_entities.dev: + new_dev.append(device_switch) + _update_entities.dev.append(device_switch.unique_id) async_add_entities(new_dev)