瀏覽代碼

Use get with default of False when migrating options.

Issue #61
Some configs are missing entries for the entity altogether, so ensure they
do not raise an error during migration by assuming False.
This is maybe only happening for configs that have had entities added since
the user first installed.
Jason Rumney 4 年之前
父節點
當前提交
4651a348eb
共有 1 個文件被更改,包括 2 次插入2 次删除
  1. 2 2
      custom_components/tuya_local/__init__.py

+ 2 - 2
custom_components/tuya_local/__init__.py

@@ -124,12 +124,12 @@ async def async_migrate_entry(hass, entry: ConfigEntry):
         e = devcfg.primary_entity
         if e.config_id != e.entity:
             newopts.pop(e.entity, None)
-            newopts[e.config_id] = opts[e.entity]
+            newopts[e.config_id] = opts.get(e.entity, False)
 
         for e in devcfg.secondary_entities():
             if e.config_id != e.entity:
                 newopts.pop(e.entity, None)
-                newopts[e.config_id] = opts[e.entity]
+                newopts[e.config_id] = opts.get(e.entity, False)
 
         entry.options = {**newopts}
         entry.version = 5