Return cached device_info if refresh fails in SamsungTV (#68844)

This commit is contained in:
epenet 2022-03-30 10:16:26 +02:00 committed by GitHub
parent 7a9a0c0c91
commit 8fb645e1d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -465,7 +465,7 @@ class SamsungTVWSBridge(
if self._get_device_spec("PowerState") is not None: if self._get_device_spec("PowerState") is not None:
LOGGER.debug("Checking if TV %s is on using device info", self.host) LOGGER.debug("Checking if TV %s is on using device info", self.host)
# Ensure we get an updated value # Ensure we get an updated value
info = await self.async_device_info() info = await self.async_device_info(force=True)
return info is not None and info["device"]["PowerState"] == "on" return info is not None and info["device"]["PowerState"] == "on"
return await super().async_is_on() return await super().async_is_on()
@ -522,7 +522,7 @@ class SamsungTVWSBridge(
return RESULT_CANNOT_CONNECT return RESULT_CANNOT_CONNECT
async def async_device_info(self) -> dict[str, Any] | None: async def async_device_info(self, force: bool = False) -> dict[str, Any] | None:
"""Try to gather infos of this TV.""" """Try to gather infos of this TV."""
if self._rest_api is None: if self._rest_api is None:
assert self.port assert self.port
@ -539,7 +539,7 @@ class SamsungTVWSBridge(
self._device_info = device_info self._device_info = device_info
return device_info return device_info
return None return None if force else self._device_info
async def async_launch_app(self, app_id: str) -> None: async def async_launch_app(self, app_id: str) -> None:
"""Send the launch_app command using websocket protocol.""" """Send the launch_app command using websocket protocol."""
@ -721,18 +721,18 @@ class SamsungTVEncryptedBridge(
rest_api = SamsungTVAsyncRest( rest_api = SamsungTVAsyncRest(
host=self.host, host=self.host,
session=async_get_clientsession(self.hass), session=async_get_clientsession(self.hass),
port=self.port, port=rest_api_port,
timeout=TIMEOUT_WEBSOCKET, timeout=TIMEOUT_WEBSOCKET,
) )
with contextlib.suppress(*REST_EXCEPTIONS): with contextlib.suppress(*REST_EXCEPTIONS):
device_info: dict[str, Any] = await rest_api.rest_device_info() device_info: dict[str, Any] = await rest_api.rest_device_info()
LOGGER.debug("Device info on %s is: %s", self.host, device_info) LOGGER.debug("Device info on %s is: %s", self.host, device_info)
self._device_info = device_info self._device_info = device_info
self._rest_api_port = rest_api_port self._rest_api_port = rest_api_port
return device_info return device_info
return None return self._device_info
async def async_send_keys(self, keys: list[str]) -> None: async def async_send_keys(self, keys: list[str]) -> None:
"""Send a list of keys using websocket protocol.""" """Send a list of keys using websocket protocol."""