Use hass.add_job in samsungtv (#66976)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
865159781f
commit
3b146d8e9b
2 changed files with 3 additions and 3 deletions
|
@ -24,7 +24,6 @@ from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.async_ import run_callback_threadsafe
|
|
||||||
|
|
||||||
from .bridge import (
|
from .bridge import (
|
||||||
SamsungTVBridge,
|
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)
|
bridge = await _async_create_bridge_with_updated_data(hass, entry)
|
||||||
|
|
||||||
# Ensure new token gets saved against the config_entry
|
# Ensure new token gets saved against the config_entry
|
||||||
|
@callback
|
||||||
def _update_token() -> None:
|
def _update_token() -> None:
|
||||||
"""Update config entry with the new token."""
|
"""Update config entry with the new token."""
|
||||||
hass.config_entries.async_update_entry(
|
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:
|
def new_token_callback() -> None:
|
||||||
"""Update config entry with the new token."""
|
"""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)
|
bridge.register_new_token_callback(new_token_callback)
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
||||||
|
|
||||||
if self._attr_state == STATE_ON and self._app_list is None:
|
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._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:
|
def _update_app_list(self) -> None:
|
||||||
self._app_list = self._bridge.get_app_list()
|
self._app_list = self._bridge.get_app_list()
|
||||||
|
|
Loading…
Add table
Reference in a new issue