Use hass.add_job in samsungtv (#66976)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/66990/head
epenet 2022-02-21 09:11:29 +01:00 committed by GitHub
parent 865159781f
commit 3b146d8e9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -24,7 +24,6 @@ from homeassistant.core import Event, HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
from homeassistant.util.async_ import run_callback_threadsafe
from .bridge import (
SamsungTVBridge,
@ -119,6 +118,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
bridge = await _async_create_bridge_with_updated_data(hass, entry)
# Ensure new token gets saved against the config_entry
@callback
def _update_token() -> None:
"""Update config entry with the new token."""
hass.config_entries.async_update_entry(
@ -127,7 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
def new_token_callback() -> None:
"""Update config entry with the new token."""
run_callback_threadsafe(hass.loop, _update_token)
hass.add_job(_update_token)
bridge.register_new_token_callback(new_token_callback)

View File

@ -164,7 +164,7 @@ class SamsungTVDevice(MediaPlayerEntity):
if self._attr_state == STATE_ON and self._app_list is None:
self._app_list = {} # Ensure that we don't update it twice in parallel
self.hass.async_add_job(self._update_app_list)
self._update_app_list()
def _update_app_list(self) -> None:
self._app_list = self._bridge.get_app_list()