mirror of
https://github.com/home-assistant/core.git
synced 2025-04-30 12:17:52 +00:00
Add load_url service to fully_kiosk integration (#79969)
This commit is contained in:
parent
8fe504356a
commit
ffb6434776
@ -5,6 +5,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import FullyKioskDataUpdateCoordinator
|
from .coordinator import FullyKioskDataUpdateCoordinator
|
||||||
|
from .services import async_setup_services
|
||||||
|
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
Platform.BINARY_SENSOR,
|
Platform.BINARY_SENSOR,
|
||||||
@ -26,6 +27,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
|
await async_setup_services(hass)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,3 +22,7 @@ MEDIA_SUPPORT_FULLYKIOSK = (
|
|||||||
| MediaPlayerEntityFeature.VOLUME_SET
|
| MediaPlayerEntityFeature.VOLUME_SET
|
||||||
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
| MediaPlayerEntityFeature.BROWSE_MEDIA
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SERVICE_LOAD_URL = "load_url"
|
||||||
|
|
||||||
|
ATTR_URL = "url"
|
||||||
|
41
homeassistant/components/fully_kiosk/services.py
Normal file
41
homeassistant/components/fully_kiosk/services.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
"""Services for the Fully Kiosk Browser integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.const import ATTR_DEVICE_ID
|
||||||
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
import homeassistant.helpers.device_registry as dr
|
||||||
|
|
||||||
|
from .const import ATTR_URL, DOMAIN, SERVICE_LOAD_URL
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_services(hass: HomeAssistant) -> None:
|
||||||
|
"""Set up the services for the Fully Kiosk Browser integration."""
|
||||||
|
|
||||||
|
async def async_load_url(call: ServiceCall) -> None:
|
||||||
|
"""Load a URL on the Fully Kiosk Browser."""
|
||||||
|
registry = dr.async_get(hass)
|
||||||
|
for target in call.data[ATTR_DEVICE_ID]:
|
||||||
|
|
||||||
|
device = registry.async_get(target)
|
||||||
|
if device:
|
||||||
|
coordinator = hass.data[DOMAIN][list(device.config_entries)[0]]
|
||||||
|
await coordinator.fully.loadUrl(call.data[ATTR_URL])
|
||||||
|
|
||||||
|
hass.services.async_register(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_LOAD_URL,
|
||||||
|
async_load_url,
|
||||||
|
schema=vol.Schema(
|
||||||
|
vol.All(
|
||||||
|
{
|
||||||
|
vol.Required(ATTR_DEVICE_ID): cv.ensure_list,
|
||||||
|
vol.Required(
|
||||||
|
ATTR_URL,
|
||||||
|
): cv.string,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
14
homeassistant/components/fully_kiosk/services.yaml
Normal file
14
homeassistant/components/fully_kiosk/services.yaml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
load_url:
|
||||||
|
name: Load URL
|
||||||
|
description: Load a URL on Fully Kiosk Browser
|
||||||
|
target:
|
||||||
|
device:
|
||||||
|
integration: fully_kiosk
|
||||||
|
fields:
|
||||||
|
url:
|
||||||
|
name: URL
|
||||||
|
description: URL to load.
|
||||||
|
example: "https://home-assistant.io"
|
||||||
|
required: true
|
||||||
|
selector:
|
||||||
|
text:
|
36
tests/components/fully_kiosk/test_services.py
Normal file
36
tests/components/fully_kiosk/test_services.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
"""Test Fully Kiosk Browser services."""
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from homeassistant.components.fully_kiosk.const import (
|
||||||
|
ATTR_URL,
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_LOAD_URL,
|
||||||
|
)
|
||||||
|
from homeassistant.const import ATTR_DEVICE_ID
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import device_registry as dr
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
|
|
||||||
|
async def test_services(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_fully_kiosk: MagicMock,
|
||||||
|
init_integration: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test the Fully Kiosk Browser services."""
|
||||||
|
device_registry = dr.async_get(hass)
|
||||||
|
device_entry = device_registry.async_get_device(
|
||||||
|
identifiers={(DOMAIN, "abcdef-123456")}
|
||||||
|
)
|
||||||
|
|
||||||
|
assert device_entry
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
DOMAIN,
|
||||||
|
SERVICE_LOAD_URL,
|
||||||
|
{ATTR_DEVICE_ID: [device_entry.id], ATTR_URL: "https://example.com"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(mock_fully_kiosk.loadUrl.mock_calls) == 1
|
Loading…
x
Reference in New Issue
Block a user