From 3ffcbc5222dda43fc392ce238fb8f11c438ddec2 Mon Sep 17 00:00:00 2001 From: xZetsubou Date: Sun, 11 Aug 2024 16:14:07 +0300 Subject: [PATCH] Fix if device entry doesn't exists #314 --- custom_components/localtuya/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/localtuya/__init__.py b/custom_components/localtuya/__init__.py index 7feffd65a..0ff4117cc 100644 --- a/custom_components/localtuya/__init__.py +++ b/custom_components/localtuya/__init__.py @@ -419,7 +419,7 @@ async def async_remove_orphan_entities(hass, entry): @callback def check_if_device_disabled(hass: HomeAssistant, entry: ConfigEntry, dev_id): - """Return whether if the device disbaled or not""" + """Return whether if the device disbaled or not.""" ent_reg = er.async_get(hass) entries = er.async_entries_for_config_entry(ent_reg, entry.entry_id) ha_device_id: str = None @@ -429,8 +429,8 @@ def check_if_device_disabled(hass: HomeAssistant, entry: ConfigEntry, dev_id): ha_device_id = entitiy.device_id break - if ha_device_id: - return dr.async_get(hass).async_get(ha_device_id).disabled + if ha_device_id and (device := dr.async_get(hass).async_get(ha_device_id)): + return device.disabled @callback