mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Fix minor async issues in Plex (#33785)
* Fix minor async context issues * Annotate callback
This commit is contained in:
parent
81569f10c0
commit
3873b23704
@ -2,7 +2,10 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||
from homeassistant.helpers.dispatcher import (
|
||||
async_dispatcher_connect,
|
||||
async_dispatcher_send,
|
||||
)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
@ -58,7 +61,7 @@ class PlexSensor(Entity):
|
||||
|
||||
@callback
|
||||
def update_plex(_):
|
||||
dispatcher_send(
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
PLEX_UPDATE_PLATFORMS_SIGNAL.format(self._server.machine_identifier),
|
||||
)
|
||||
|
@ -12,7 +12,8 @@ import requests.exceptions
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send, dispatcher_send
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
|
||||
from .const import (
|
||||
@ -175,11 +176,12 @@ class PlexServer:
|
||||
if config_entry_update_needed:
|
||||
raise ShouldUpdateConfigEntry
|
||||
|
||||
def refresh_entity(self, machine_identifier, device, session):
|
||||
@callback
|
||||
def async_refresh_entity(self, machine_identifier, device, session):
|
||||
"""Forward refresh dispatch to media_player."""
|
||||
unique_id = f"{self.machine_identifier}:{machine_identifier}"
|
||||
_LOGGER.debug("Refreshing %s", unique_id)
|
||||
dispatcher_send(
|
||||
async_dispatcher_send(
|
||||
self.hass,
|
||||
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(unique_id),
|
||||
device,
|
||||
@ -262,7 +264,7 @@ class PlexServer:
|
||||
if client_id in new_clients:
|
||||
new_entity_configs.append(client_data)
|
||||
else:
|
||||
self.refresh_entity(
|
||||
self.async_refresh_entity(
|
||||
client_id, client_data["device"], client_data.get("session")
|
||||
)
|
||||
|
||||
@ -272,7 +274,7 @@ class PlexServer:
|
||||
self._known_clients - self._known_idle - ignored_clients
|
||||
).difference(available_clients)
|
||||
for client_id in idle_clients:
|
||||
self.refresh_entity(client_id, None, None)
|
||||
self.async_refresh_entity(client_id, None, None)
|
||||
self._known_idle.add(client_id)
|
||||
|
||||
if new_entity_configs:
|
||||
|
Loading…
x
Reference in New Issue
Block a user