Skip to content

Commit

Permalink
fix #107449, handle deep standby gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
autinerd committed Jan 7, 2024
1 parent e1dd582 commit 0512f86
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions homeassistant/components/enigma2/media_player.py
@@ -1,9 +1,10 @@
"""Support for Enigma2 media players."""
from __future__ import annotations

from logging import getLogger
from typing import Any

from aiohttp.client_exceptions import ClientConnectorError
from aiohttp.client_exceptions import ClientConnectorError, ServerDisconnectedError
from openwebif.api import OpenWebIfDevice
from openwebif.enums import RemoteControlCodes, SetVolumeOption
import voluptuous as vol
Expand Down Expand Up @@ -50,6 +51,8 @@
ATTR_MEDIA_END_TIME = "media_end_time"
ATTR_MEDIA_START_TIME = "media_start_time"

_LOGGER = getLogger(__name__)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_HOST): cv.string,
Expand Down Expand Up @@ -140,7 +143,15 @@ def __init__(self, name: str, device: OpenWebIfDevice, about: dict) -> None:

async def async_turn_off(self) -> None:
"""Turn off media player."""
await self._device.turn_off()
try:
await self._device.turn_off()
except ServerDisconnectedError as err:
_LOGGER.warning(
"%s went into deep standby. Error: %s",
self._device.base.host,
str(err),
)
self._attr_available = False

async def async_turn_on(self) -> None:
"""Turn the media player on."""
Expand Down Expand Up @@ -188,9 +199,20 @@ async def async_select_source(self, source: str) -> None:

async def async_update(self) -> None:
"""Update state of the media_player."""
await self._device.update()
try:
await self._device.update()
if not self._attr_available:
_LOGGER.debug("%s is available", self._device.base.host)
self._attr_available = True
except ClientConnectorError as err:
if self._attr_available:
_LOGGER.warning(
"%s is unavailable. Error: %s", self._device.base.host, str(err)
)
self._attr_available = False
return

self._data = self._device.status_info
self._attr_available = not self._device.is_offline

if self._data.get("inStandby") == "false":
self._attr_extra_state_attributes = {
Expand Down

0 comments on commit 0512f86

Please sign in to comment.