Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions homeassistant/components/enigma2/media_player.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Support for Enigma2 media players."""
from __future__ import annotations

from aiohttp.client_exceptions import ClientConnectorError
from logging import getLogger

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 +52,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 @@ -143,7 +147,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(
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
"%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 @@ -191,8 +203,18 @@ 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()
self._attr_available = not self._device.is_offline
try:
await self._device.update()
if not self._attr_available:
Comment thread
autinerd marked this conversation as resolved.
Outdated
_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)
Comment thread
autinerd marked this conversation as resolved.
Outdated
)
self._attr_available = False
return

if not self._device.status.in_standby:
self._attr_extra_state_attributes = {
Expand Down