Ejemplo n.º 1
0
async def viewer_fixture(
    hass: HomeAssistant,
    mock_entry: MockEntityFixture,
    mock_viewer: Viewer,
    mock_liveview: Liveview,
):
    """Fixture for a single viewport for testing the select platform."""

    # disable pydantic validation so mocking can happen
    Viewer.__config__.validate_assignment = False

    viewer_obj = mock_viewer.copy(deep=True)
    viewer_obj._api = mock_entry.api
    viewer_obj.name = "Test Viewer"
    viewer_obj.liveview_id = mock_liveview.id

    mock_entry.api.bootstrap.reset_objects()
    mock_entry.api.bootstrap.viewers = {
        viewer_obj.id: viewer_obj,
    }
    mock_entry.api.bootstrap.liveviews = {mock_liveview.id: mock_liveview}

    await hass.config_entries.async_setup(mock_entry.entry.entry_id)
    await hass.async_block_till_done()

    assert_entity_counts(hass, Platform.SELECT, 1, 1)

    yield viewer_obj

    Viewer.__config__.validate_assignment = True
Ejemplo n.º 2
0
async def test_select_set_option_viewer(
    hass: HomeAssistant,
    viewer: Viewer,
):
    """Test Liveview select."""
    _, entity_id = ids_from_device_description(
        Platform.SELECT, viewer, VIEWER_SELECTS[0]
    )

    viewer.__fields__["set_liveview"] = Mock()
    viewer.set_liveview = AsyncMock()

    liveview = list(viewer.api.bootstrap.liveviews.values())[0]

    await hass.services.async_call(
        "select",
        "select_option",
        {ATTR_ENTITY_ID: entity_id, ATTR_OPTION: liveview.name},
        blocking=True,
    )

    viewer.set_liveview.assert_called_once_with(liveview)
Ejemplo n.º 3
0
def mock_viewer():
    """Mock UniFi Protect Viewport device."""

    data = json.loads(load_fixture("sample_viewport.json", integration=DOMAIN))
    return Viewer.from_unifi_dict(**data)