mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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
|
import logging
|
||||||
|
|
||||||
from homeassistant.core import callback
|
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.entity import Entity
|
||||||
from homeassistant.helpers.event import async_call_later
|
from homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
@ -58,7 +61,7 @@ class PlexSensor(Entity):
|
|||||||
|
|
||||||
@callback
|
@callback
|
||||||
def update_plex(_):
|
def update_plex(_):
|
||||||
dispatcher_send(
|
async_dispatcher_send(
|
||||||
self.hass,
|
self.hass,
|
||||||
PLEX_UPDATE_PLATFORMS_SIGNAL.format(self._server.machine_identifier),
|
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.components.media_player import DOMAIN as MP_DOMAIN
|
||||||
from homeassistant.const import CONF_TOKEN, CONF_URL, CONF_VERIFY_SSL
|
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 homeassistant.helpers.event import async_call_later
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -175,11 +176,12 @@ class PlexServer:
|
|||||||
if config_entry_update_needed:
|
if config_entry_update_needed:
|
||||||
raise ShouldUpdateConfigEntry
|
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."""
|
"""Forward refresh dispatch to media_player."""
|
||||||
unique_id = f"{self.machine_identifier}:{machine_identifier}"
|
unique_id = f"{self.machine_identifier}:{machine_identifier}"
|
||||||
_LOGGER.debug("Refreshing %s", unique_id)
|
_LOGGER.debug("Refreshing %s", unique_id)
|
||||||
dispatcher_send(
|
async_dispatcher_send(
|
||||||
self.hass,
|
self.hass,
|
||||||
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(unique_id),
|
PLEX_UPDATE_MEDIA_PLAYER_SIGNAL.format(unique_id),
|
||||||
device,
|
device,
|
||||||
@ -262,7 +264,7 @@ class PlexServer:
|
|||||||
if client_id in new_clients:
|
if client_id in new_clients:
|
||||||
new_entity_configs.append(client_data)
|
new_entity_configs.append(client_data)
|
||||||
else:
|
else:
|
||||||
self.refresh_entity(
|
self.async_refresh_entity(
|
||||||
client_id, client_data["device"], client_data.get("session")
|
client_id, client_data["device"], client_data.get("session")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -272,7 +274,7 @@ class PlexServer:
|
|||||||
self._known_clients - self._known_idle - ignored_clients
|
self._known_clients - self._known_idle - ignored_clients
|
||||||
).difference(available_clients)
|
).difference(available_clients)
|
||||||
for client_id in idle_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)
|
self._known_idle.add(client_id)
|
||||||
|
|
||||||
if new_entity_configs:
|
if new_entity_configs:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user