diff --git a/homeassistant/components/fully_kiosk/__init__.py b/homeassistant/components/fully_kiosk/__init__.py index 86ab769e0ec..e417d7c0bcb 100644 --- a/homeassistant/components/fully_kiosk/__init__.py +++ b/homeassistant/components/fully_kiosk/__init__.py @@ -5,6 +5,7 @@ from homeassistant.core import HomeAssistant from .const import DOMAIN from .coordinator import FullyKioskDataUpdateCoordinator +from .services import async_setup_services PLATFORMS = [ 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 async_setup_services(hass) + return True diff --git a/homeassistant/components/fully_kiosk/const.py b/homeassistant/components/fully_kiosk/const.py index 4af7628ed63..b722d7fb4ca 100644 --- a/homeassistant/components/fully_kiosk/const.py +++ b/homeassistant/components/fully_kiosk/const.py @@ -22,3 +22,7 @@ MEDIA_SUPPORT_FULLYKIOSK = ( | MediaPlayerEntityFeature.VOLUME_SET | MediaPlayerEntityFeature.BROWSE_MEDIA ) + +SERVICE_LOAD_URL = "load_url" + +ATTR_URL = "url" diff --git a/homeassistant/components/fully_kiosk/services.py b/homeassistant/components/fully_kiosk/services.py new file mode 100644 index 00000000000..3d7d564f0b2 --- /dev/null +++ b/homeassistant/components/fully_kiosk/services.py @@ -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, + }, + ) + ), + ) diff --git a/homeassistant/components/fully_kiosk/services.yaml b/homeassistant/components/fully_kiosk/services.yaml new file mode 100644 index 00000000000..53ce0a8aec8 --- /dev/null +++ b/homeassistant/components/fully_kiosk/services.yaml @@ -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: diff --git a/tests/components/fully_kiosk/test_services.py b/tests/components/fully_kiosk/test_services.py new file mode 100644 index 00000000000..e3b63dad341 --- /dev/null +++ b/tests/components/fully_kiosk/test_services.py @@ -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