Send notification to alert of Sonos networking issues (#65084)

* Send notification to alert of Sonos networking issues

* Add links to documentation
This commit is contained in:
jjlawren 2022-01-31 12:21:21 -06:00 committed by Paulus Schoutsen
parent 3446c95cd3
commit 2eef05eb84

View File

@ -9,6 +9,7 @@ import soco.config as soco_config
from soco.core import SoCo from soco.core import SoCo
from soco.exceptions import SoCoException from soco.exceptions import SoCoException
from homeassistant.components import persistent_notification
import homeassistant.helpers.device_registry as dr import homeassistant.helpers.device_registry as dr
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import DeviceInfo, Entity from homeassistant.helpers.entity import DeviceInfo, Entity
@ -22,6 +23,8 @@ from .const import (
) )
from .speaker import SonosSpeaker from .speaker import SonosSpeaker
SUB_FAIL_URL = "https://www.home-assistant.io/integrations/sonos/#network-requirements"
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -70,10 +73,15 @@ class SonosEntity(Entity):
listener_msg = f"{self.speaker.subscription_address} (advertising as {soco_config.EVENT_ADVERTISE_IP})" listener_msg = f"{self.speaker.subscription_address} (advertising as {soco_config.EVENT_ADVERTISE_IP})"
else: else:
listener_msg = self.speaker.subscription_address listener_msg = self.speaker.subscription_address
_LOGGER.warning( message = f"{self.speaker.zone_name} cannot reach {listener_msg}, falling back to polling, functionality may be limited"
"%s cannot reach %s, falling back to polling, functionality may be limited", log_link_msg = f", see {SUB_FAIL_URL} for more details"
self.speaker.zone_name, notification_link_msg = f'.\n\nSee <a href="{SUB_FAIL_URL}">Sonos documentation</a> for more details.'
listener_msg, _LOGGER.warning(message + log_link_msg)
persistent_notification.async_create(
self.hass,
message + notification_link_msg,
"Sonos networking issue",
"sonos_subscriptions_failed",
) )
self.speaker.subscriptions_failed = True self.speaker.subscriptions_failed = True
await self.speaker.async_unsubscribe() await self.speaker.async_unsubscribe()