2020-06-26 06:24:58 +00:00
|
|
|
"""Helper methods for Plex tests."""
|
2020-12-02 18:00:13 +00:00
|
|
|
from datetime import timedelta
|
2020-06-26 06:24:58 +00:00
|
|
|
|
2021-03-25 18:12:12 +00:00
|
|
|
from plexwebsocket import SIGNAL_CONNECTION_STATE, STATE_CONNECTED
|
2020-06-26 06:24:58 +00:00
|
|
|
|
2020-12-02 18:00:13 +00:00
|
|
|
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 websocket_connected(mock_websocket):
|
|
|
|
"""Call the websocket callback method to signal successful connection."""
|
2020-06-27 08:03:51 +00:00
|
|
|
callback = mock_websocket.call_args[0][1]
|
2020-12-02 18:00:13 +00:00
|
|
|
callback(SIGNAL_CONNECTION_STATE, STATE_CONNECTED, None)
|
|
|
|
|
|
|
|
|
2021-03-31 11:57:16 +00:00
|
|
|
def trigger_plex_update(mock_websocket, msgtype="playing", payload=UPDATE_PAYLOAD):
|
2020-12-02 18:00:13 +00:00
|
|
|
"""Call the websocket callback method with a Plex update."""
|
|
|
|
callback = mock_websocket.call_args[0][1]
|
2021-03-31 11:57:16 +00:00
|
|
|
callback(msgtype, payload, None)
|
2020-12-02 18:00:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
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()
|