Suppress 404 in Bravia TV (#77288)

pull/77968/head
Artem Draft 2022-09-01 05:42:23 +03:00 committed by Paulus Schoutsen
parent 8b8db998df
commit 37acd3e3f2
1 changed files with 10 additions and 1 deletions

View File

@ -7,7 +7,7 @@ from functools import wraps
import logging import logging
from typing import Any, Final, TypeVar from typing import Any, Final, TypeVar
from pybravia import BraviaTV, BraviaTVError from pybravia import BraviaTV, BraviaTVError, BraviaTVNotFound
from typing_extensions import Concatenate, ParamSpec from typing_extensions import Concatenate, ParamSpec
from homeassistant.components.media_player.const import ( from homeassistant.components.media_player.const import (
@ -79,6 +79,7 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
self.connected = False self.connected = False
# Assume that the TV is in Play mode # Assume that the TV is in Play mode
self.playing = True self.playing = True
self.skipped_updates = 0
super().__init__( super().__init__(
hass, hass,
@ -113,6 +114,7 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
power_status = await self.client.get_power_status() power_status = await self.client.get_power_status()
self.is_on = power_status == "active" self.is_on = power_status == "active"
self.skipped_updates = 0
if self.is_on is False: if self.is_on is False:
return return
@ -121,6 +123,13 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
await self.async_update_sources() await self.async_update_sources()
await self.async_update_volume() await self.async_update_volume()
await self.async_update_playing() await self.async_update_playing()
except BraviaTVNotFound as err:
if self.skipped_updates < 10:
self.connected = False
self.skipped_updates += 1
_LOGGER.debug("Update skipped, Bravia API service is reloading")
return
raise UpdateFailed("Error communicating with device") from err
except BraviaTVError as err: except BraviaTVError as err:
self.is_on = False self.is_on = False
self.connected = False self.connected = False