Skip to content
Snippets Groups Projects
Unverified Commit a08cb2ca authored by David Nielsen's avatar David Nielsen Committed by GitHub
Browse files

Fix braviatv authentication refresh (#37482)

- Bumps bravia-tv lib to 1.0.6 which fixes is_connected() to actually
      return True only when API is connected, instead of just returning whether
      or not cookies are cached (regardless if they actually worked).
    - Wrap is_connected() because it now performs io.
    - Remove unnecessary logic to refresh cookies. Now that
      is_connected() works, the bravia instance only needs to be
      reconnected when is_connected is False and TV is not off.
parent a882cfaf
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,8 @@ class BraviaTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self.braviarc.connect, pin, CLIENTID_PREFIX, NICKNAME
)
if not self.braviarc.is_connected():
connected = await self.hass.async_add_executor_job(self.braviarc.is_connected)
if not connected:
raise CannotConnect()
system_info = await self.hass.async_add_executor_job(
......@@ -161,7 +162,8 @@ class BraviaTVOptionsFlowHandler(config_entries.OptionsFlow):
async def async_step_init(self, user_input=None):
"""Manage the options."""
self.braviarc = self.hass.data[DOMAIN][self.config_entry.entry_id][BRAVIARC]
if not self.braviarc.is_connected():
connected = await self.hass.async_add_executor_job(self.braviarc.is_connected)
if not connected:
await self.hass.async_add_executor_job(
self.braviarc.connect, self.pin, CLIENTID_PREFIX, NICKNAME
)
......
......@@ -2,7 +2,7 @@
"domain": "braviatv",
"name": "Sony Bravia TV",
"documentation": "https://www.home-assistant.io/integrations/braviatv",
"requirements": ["bravia-tv==1.0.5"],
"requirements": ["bravia-tv==1.0.6"],
"codeowners": ["@bieniu"],
"config_flow": true
}
......@@ -148,33 +148,31 @@ class BraviaTVDevice(MediaPlayerEntity):
self._device_info = device_info
self._ignored_sources = ignored_sources
self._state_lock = asyncio.Lock()
self._need_refresh = True
async def async_update(self):
"""Update TV info."""
if self._state_lock.locked():
return
if self._state == STATE_OFF:
self._need_refresh = True
power_status = await self.hass.async_add_executor_job(
self._braviarc.get_power_status
)
if power_status == "active":
if self._need_refresh:
if power_status != "off":
connected = await self.hass.async_add_executor_job(
self._braviarc.is_connected
)
if not connected:
try:
connected = await self.hass.async_add_executor_job(
self._braviarc.connect, self._pin, CLIENTID_PREFIX, NICKNAME
)
except NoIPControl:
_LOGGER.error("IP Control is disabled in the TV settings")
self._need_refresh = False
else:
connected = self._braviarc.is_connected()
if not connected:
return
power_status = "off"
if power_status == "active":
self._state = STATE_ON
if (
await self._async_refresh_volume()
......
......@@ -375,7 +375,7 @@ bomradarloop==0.1.4
boto3==1.9.252
# homeassistant.components.braviatv
bravia-tv==1.0.5
bravia-tv==1.0.6
# homeassistant.components.broadlink
broadlink==0.14.0
......
......@@ -177,7 +177,7 @@ blinkpy==0.15.0
bomradarloop==0.1.4
# homeassistant.components.braviatv
bravia-tv==1.0.5
bravia-tv==1.0.6
# homeassistant.components.broadlink
broadlink==0.14.0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment