Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit c022025

Browse files
committed
fix to support HA 2021.5
1 parent 8cada67 commit c022025

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

custom_components/sonos_crossfade/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@ def get_soco_from_entity_id(self, entity_id):
3131
"""Returns the SoCo object of the entity that corresponds to the given entity_id"""
3232
data_sonos = self.hass.data[sonos.media_player.DATA_SONOS]
3333

34-
for entity in data_sonos.entities:
35-
if entity.entity_id == entity_id:
36-
break
34+
if hasattr(data_sonos, 'media_player_entities'):
35+
"""HA 2021.5 Support"""
36+
for entity in data_sonos.media_player_entities.items():
37+
if entity[1].entity_id == entity_id:
38+
return entity[1].soco
39+
3740
else:
38-
entity = None
39-
40-
if entity is None:
41-
_LOGGER.error("No entity found for entity_id: %s", entity_id)
42-
return None
43-
44-
return entity.soco
41+
"""Legacy Support"""
42+
for entity in data_sonos.entities:
43+
if entity.entity_id == entity_id:
44+
return entity.soco
45+
46+
_LOGGER.error("No entity found for entity_id: %s", entity_id)
47+
return None
4548

4649
def update(self, call):
4750
"""Handle the service call."""

0 commit comments

Comments
 (0)