Sfoglia il codice sorgente

fix(media_player): iterate a copy of the dps_map so we can pop items off

When collecting metadata, the loop was using pop(), but changing the dict
as it is iterated is an error. Another loop was popping the collected items
off at the end, because I was aware of the issue, but mistakenly used pop
instead of just getting the value in the main loop.

Working on a copy of the dictionary from the start avoids the issue and
the need for a second loop.

Issue #6129
Jason Rumney 20 ore fa
parent
commit
08fbdc0761
1 ha cambiato i file con 1 aggiunte e 4 eliminazioni
  1. 1 4
      custom_components/tuya_local/media_player.py

+ 1 - 4
custom_components/tuya_local/media_player.py

@@ -60,13 +60,10 @@ class TuyaLocalMediaPlayer(TuyaLocalEntity, MediaPlayerEntity):
         self._repeat_dp = dps_map.pop("repeat", None)
         self._sound_mode_dp = dps_map.pop("sound_mode", None)
         self._metadata = {}
-        for n, dp in dps_map.items():
+        for n, dp in dps_map.copy().items():
             if n in PROP_TO_ATTR:
                 self._metadata[dp.id] = dps_map.pop(n)
 
-        for dp in self._metadata.values():
-            dps_map.pop(dp.name, None)
-
         self._init_end(dps_map)
 
         self._support_flags = MediaPlayerEntityFeature(0)