Add start_application service to fully_kiosk integration (#80226)
This commit is contained in:
parent
e3af2cb6b8
commit
a68bd8df6f
4 changed files with 61 additions and 1 deletions
|
@ -24,5 +24,7 @@ MEDIA_SUPPORT_FULLYKIOSK = (
|
|||
)
|
||||
|
||||
SERVICE_LOAD_URL = "load_url"
|
||||
SERVICE_START_APPLICATION = "start_application"
|
||||
|
||||
ATTR_URL = "url"
|
||||
ATTR_APPLICATION = "application"
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
)
|
||||
),
|
||||
)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue