Explorar o código

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 %!s(int64=4) %!d(string=hai) anos
pai
achega
0b29ddc094
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  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
         if e.config_id != e.entity:
-            newopts.pop(e.entity)
+            newopts.pop(e.entity, None)
             newopts[e.config_id] = opts[e.entity]
 
         for e in devcfg.secondary_entities():
             if e.config_id != e.entity:
-                newopts.pop(e.entity)
+                newopts.pop(e.entity, None)
                 newopts[e.config_id] = opts[e.entity]
 
         entry.options = {**newopts}