1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Use Plex websocket payloads to reduce overhead (#42332)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
jjlawren
2020-12-02 12:00:13 -06:00
committed by GitHub
parent 6e8efe2b67
commit f2f935506e
15 changed files with 516 additions and 464 deletions

View File

@@ -1,8 +1,39 @@
"""Helper methods for Plex tests."""
from plexwebsocket import SIGNAL_DATA
from datetime import timedelta
from plexwebsocket import SIGNAL_CONNECTION_STATE, SIGNAL_DATA, STATE_CONNECTED
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed
UPDATE_PAYLOAD = {
"PlaySessionStateNotification": [
{
"sessionKey": "999",
"ratingKey": "12345",
"viewOffset": 5050,
"playQueueItemID": 54321,
"state": "playing",
}
]
}
def trigger_plex_update(mock_websocket):
"""Call the websocket callback method."""
def websocket_connected(mock_websocket):
"""Call the websocket callback method to signal successful connection."""
callback = mock_websocket.call_args[0][1]
callback(SIGNAL_DATA, None, None)
callback(SIGNAL_CONNECTION_STATE, STATE_CONNECTED, None)
def trigger_plex_update(mock_websocket, payload=UPDATE_PAYLOAD):
"""Call the websocket callback method with a Plex update."""
callback = mock_websocket.call_args[0][1]
callback(SIGNAL_DATA, payload, None)
async def wait_for_debouncer(hass):
"""Move time forward to wait for sensor debouncer."""
next_update = dt_util.utcnow() + timedelta(seconds=3)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()