Просмотр исходного кода

maint: raise exceptions on migration errors

Issue #6477
Jason Rumney 1 день назад
Родитель
Сommit
38d250151d
1 измененных файлов с 28 добавлено и 116 удалено
  1. 28 116
      custom_components/tuya_local/__init__.py

+ 28 - 116
custom_components/tuya_local/__init__.py

@@ -104,11 +104,10 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             )
             config[CONF_TYPE] = await device.async_inferred_type()
             if config[CONF_TYPE] is None:
-                _LOGGER.error(
-                    "Unable to determine type for device %s",
-                    config[CONF_DEVICE_ID],
+                raise KeyError(
+                    f"Unable to determine type for device {config[CONF_DEVICE_ID]}"
                 )
-                return False
+
         hass.config_entries.async_update_entry(
             entry,
             data={
@@ -134,11 +133,10 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             )
             config[CONF_TYPE] = await device.async_inferred_type()
             if config[CONF_TYPE] is None:
-                _LOGGER.error(
-                    "Unable to determine type for device %s",
-                    config[CONF_DEVICE_ID],
+                raise KeyError(
+                    f"Unable to determine type for device {config[CONF_DEVICE_ID]}"
                 )
-                return False
+
         opts.pop(CONF_TYPE, None)
         hass.config_entries.async_update_entry(
             entry,
@@ -191,8 +189,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(NOT_FOUND, entry.data[CONF_TYPE])
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id(entity_entry):
@@ -275,11 +272,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id12(entity_entry):
@@ -322,11 +315,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13(entity_entry):
@@ -382,11 +371,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_2(entity_entry):
@@ -430,11 +415,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_3(entity_entry):
@@ -496,12 +477,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             get_config,
             entry.data[CONF_TYPE],
         )
-        if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_5(entity_entry):
@@ -527,11 +503,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_6(entity_entry):
@@ -568,11 +540,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_7(entity_entry):
@@ -595,11 +563,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_8(entity_entry):
@@ -646,11 +610,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_9(entity_entry):
@@ -673,11 +633,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_10(entity_entry):
@@ -734,11 +690,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_13(entity_entry):
@@ -765,11 +717,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_15(entity_entry):
@@ -811,11 +759,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_16(entity_entry):
@@ -842,11 +786,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_17(entity_entry):
@@ -876,11 +816,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_18(entity_entry):
@@ -904,11 +840,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_19(entity_entry):
@@ -938,11 +870,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_20(entity_entry):
@@ -970,11 +898,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_21(entity_entry):
@@ -1030,11 +954,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_23(entity_entry):
@@ -1063,11 +983,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_24(entity_entry):
@@ -1093,11 +1009,7 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
             entry.data[CONF_TYPE],
         )
         if conf_file is None:
-            _LOGGER.error(
-                NOT_FOUND,
-                entry.data[CONF_TYPE],
-            )
-            return False
+            raise FileNotFoundError(errno.ENOENT, NOT_FOUND, entry.data[CONF_TYPE])
 
         @callback
         def update_unique_id13_25(entity_entry):