Add start_application service to fully_kiosk integration (#80226)

This commit is contained in:
Charles Garwood 2022-10-14 13:21:58 -04:00 committed by GitHub
parent e3af2cb6b8
commit a68bd8df6f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 1 deletions

View file

@ -24,5 +24,7 @@ MEDIA_SUPPORT_FULLYKIOSK = (
)
SERVICE_LOAD_URL = "load_url"
SERVICE_START_APPLICATION = "start_application"
ATTR_URL = "url"
ATTR_APPLICATION = "application"

View file

@ -8,7 +8,13 @@ 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
from .const import (
ATTR_APPLICATION,
ATTR_URL,
DOMAIN,
SERVICE_LOAD_URL,
SERVICE_START_APPLICATION,
)
async def async_setup_services(hass: HomeAssistant) -> None:
@ -24,6 +30,16 @@ async def async_setup_services(hass: HomeAssistant) -> None:
coordinator = hass.data[DOMAIN][list(device.config_entries)[0]]
await coordinator.fully.loadUrl(call.data[ATTR_URL])
async def async_start_app(call: ServiceCall) -> None:
"""Start an app on the device."""
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.startApplication(call.data[ATTR_APPLICATION])
hass.services.async_register(
DOMAIN,
SERVICE_LOAD_URL,
@ -39,3 +55,19 @@ async def async_setup_services(hass: HomeAssistant) -> None:
)
),
)
hass.services.async_register(
DOMAIN,
SERVICE_START_APPLICATION,
async_start_app,
schema=vol.Schema(
vol.All(
{
vol.Required(ATTR_DEVICE_ID): cv.ensure_list,
vol.Required(
ATTR_APPLICATION,
): cv.string,
},
)
),
)

View file

@ -12,3 +12,18 @@ load_url:
required: true
selector:
text:
start_application:
name: Start Application
description: Start an application on the device running Fully Kiosk Browser.
target:
device:
integration: fully_kiosk
fields:
url:
name: Application
description: Package name of the application to start.
example: "de.ozerov.fully"
required: true
selector:
text:

View file

@ -2,9 +2,11 @@
from unittest.mock import MagicMock
from homeassistant.components.fully_kiosk.const import (
ATTR_APPLICATION,
ATTR_URL,
DOMAIN,
SERVICE_LOAD_URL,
SERVICE_START_APPLICATION,
)
from homeassistant.const import ATTR_DEVICE_ID
from homeassistant.core import HomeAssistant
@ -34,3 +36,12 @@ async def test_services(
)
assert len(mock_fully_kiosk.loadUrl.mock_calls) == 1
await hass.services.async_call(
DOMAIN,
SERVICE_START_APPLICATION,
{ATTR_DEVICE_ID: [device_entry.id], ATTR_APPLICATION: "de.ozerov.fully"},
blocking=True,
)
assert len(mock_fully_kiosk.startApplication.mock_calls) == 1