Przeglądaj źródła

Avoid errors when migrating multiple entities of the same type.

If a user upgrades after multiple entity configs are available and has already
configured the same device (an earlier version without multiple entities
perhaps), an error will be raised when trying to migrate the second entity
due to the config already being popped off the options.  Give a default when
popping to avoid raising an error.
Jason Rumney 4 lat temu
rodzic
commit
0b29ddc094
1 zmienionych plików z 2 dodań i 2 usunięć
  1. 2 2
      custom_components/tuya_local/__init__.py

+ 2 - 2
custom_components/tuya_local/__init__.py

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