1 """Entity representing a Sonos player."""
3 from __future__
import annotations
5 from abc
import abstractmethod
9 from soco.core
import SoCo
16 from .const
import DATA_SONOS, DOMAIN, SONOS_FALLBACK_POLL, SONOS_STATE_UPDATED
17 from .exception
import SonosUpdateError
18 from .speaker
import SonosSpeaker
20 _LOGGER = logging.getLogger(__name__)
24 """Representation of a Sonos entity."""
26 _attr_should_poll =
False
27 _attr_has_entity_name =
True
29 def __init__(self, speaker: SonosSpeaker) ->
None:
30 """Initialize a SonosEntity."""
34 """Handle common setup when added to hass."""
39 f
"{SONOS_FALLBACK_POLL}-{self.soco.uid}",
46 f
"{SONOS_STATE_UPDATED}-{self.soco.uid}",
52 """Clean up when entity is removed."""
53 del self.
hasshass.data[DATA_SONOS].entity_id_mappings[self.
entity_identity_id]
56 """Poll the entity if subscriptions fail."""
57 if not self.
speakerspeaker.subscriptions_failed:
58 self.
speakerspeaker.subscriptions_failed =
True
59 await self.
speakerspeaker.async_unsubscribe()
62 except SonosUpdateError
as err:
63 _LOGGER.debug(
"Could not fallback poll: %s", err)
67 """Poll the specific functionality if subscriptions fail.
69 Should be implemented by platforms if needed.
74 """Return the speaker SoCo instance."""
79 """Return information about the device."""
80 suggested_area: str |
None =
None
81 if not self.
speakerspeaker.battery_info:
83 suggested_area = self.
speakerspeaker.zone_name
85 identifiers={(DOMAIN, self.
socosoco.uid)},
86 name=self.
speakerspeaker.zone_name,
87 model=self.
speakerspeaker.model_name.replace(
"Sonos ",
""),
88 model_id=self.
speakerspeaker.model_number,
89 sw_version=self.
speakerspeaker.version,
91 (dr.CONNECTION_NETWORK_MAC, self.
speakerspeaker.mac_address),
92 (dr.CONNECTION_UPNP, f
"uuid:{self.speaker.uid}"),
95 suggested_area=suggested_area,
96 configuration_url=f
"http://{self.soco.ip_address}:1400/support/review",
101 """Return whether this device is available."""
102 return self.
speakerspeaker.available
106 """Representation of a Sonos entity which may not support updating by subscriptions."""
110 """Poll the device for the current state."""
113 """Update the state using the built-in entity poller."""
114 if not self.available:
118 except SonosUpdateError
as err:
119 _LOGGER.debug(
"Could not poll: %s", err)
None _async_fallback_poll(self)
None __init__(self, SonosSpeaker speaker)
None async_fallback_poll(self, datetime.datetime now)
None async_will_remove_from_hass(self)
DeviceInfo device_info(self)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)