Plex discovery on demand (#35303)
* Allow Plex discovery on demand * Add new discovery source * Add tests
This commit is contained in:
1 parent
ee96ff2846
commit
c12f8bed43
5 files changed
+81
-2
No files matched your search
@@ -8,6 +8,32 @@ from homeassistant.const import CONF_URL
|
||||
|
||||
from .const import DEFAULT_DATA, MOCK_SERVERS, MOCK_USERS
|
||||
|
||||
GDM_PAYLOAD = [
|
||||
{
|
||||
"data": {
|
||||
"Content-Type": "plex/media-server",
|
||||
"Name": "plextest",
|
||||
"Port": "32400",
|
||||
"Resource-Identifier": "1234567890123456789012345678901234567890",
|
||||
"Updated-At": "157762684800",
|
||||
"Version": "1.0",
|
||||
},
|
||||
"from": ("1.2.3.4", 32414),
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
class MockGDM:
|
||||
"""Mock a GDM instance."""
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the object."""
|
||||
self.entries = GDM_PAYLOAD
|
||||
|
||||
def scan(self):
|
||||
"""Mock the scan call."""
|
||||
pass
|
||||
|
||||
|
||||
class MockResource:
|
||||
"""Mock a PlexAccount resource."""
|
||||
|
||||
@@ -22,7 +22,10 @@ from homeassistant.components.plex.const import (
|
||||
SERVERS,
|
||||
)
|
||||
from homeassistant.config import async_process_ha_core_config
|
||||
from homeassistant.config_entries import ENTRY_STATE_LOADED
|
||||
from homeassistant.config_entries import (
|
||||
ENTRY_STATE_LOADED,
|
||||
SOURCE_INTEGRATION_DISCOVERY,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PORT,
|
||||
@@ -34,7 +37,7 @@ from homeassistant.const import (
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
|
||||
from .const import DEFAULT_DATA, DEFAULT_OPTIONS, MOCK_SERVERS, MOCK_TOKEN
|
||||
from .mock_classes import MockPlexAccount, MockPlexServer
|
||||
from .mock_classes import MockGDM, MockPlexAccount, MockPlexServer
|
||||
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
@@ -746,3 +749,25 @@ async def test_setup_with_limited_credentials(hass):
|
||||
|
||||
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
|
||||
assert entry.state == ENTRY_STATE_LOADED
|
||||
|
||||
|
||||
async def test_integration_discovery(hass):
|
||||
"""Test integration self-discovery."""
|
||||
mock_gdm = MockGDM()
|
||||
|
||||
with patch("homeassistant.components.plex.config_flow.GDM", return_value=mock_gdm):
|
||||
await config_flow.async_discover(hass)
|
||||
|
||||
flows = hass.config_entries.flow.async_progress()
|
||||
|
||||
assert len(flows) == 1
|
||||
|
||||
flow = flows[0]
|
||||
|
||||
assert flow["handler"] == DOMAIN
|
||||
assert flow["context"]["source"] == SOURCE_INTEGRATION_DISCOVERY
|
||||
assert (
|
||||
flow["context"]["unique_id"]
|
||||
== mock_gdm.entries[0]["data"]["Resource-Identifier"]
|
||||
)
|
||||
assert flow["step_id"] == "user"
|
||||
Reference in new issue
Block a user