Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 0c3a1c0

Browse files
authored
Add additional services (#22)
* LoadStartURL and LoadURL services * Additional services * Add play_audio service, support boolean config
1 parent 9902ed6 commit 0c3a1c0

File tree

4 files changed

+200
-27
lines changed

4 files changed

+200
-27
lines changed

custom_components/fullykiosk/const.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
COORDINATOR = "coordinator"
55
CONTROLLER = "controller"
66

7+
ATTR_APPLICATION = "application"
8+
ATTR_CONFIG_TYPE = "config_type"
9+
ATTR_KEY = "key"
710
ATTR_STREAM = "stream"
11+
ATTR_URL = "url"
12+
ATTR_VALUE = "value"
813

914
AUDIOMANAGER_STREAM_MUSIC = 3
15+
16+
SERVICE_LOAD_START_URL = "load_start_url"
17+
SERVICE_LOAD_URL = "load_url"
18+
SERVICE_PLAY_AUDIO = "play_audio"
19+
SERVICE_RESTART_APP = "restart"
20+
SERVICE_SET_CONFIG = "set_config"
21+
SERVICE_START_APPLICATION = "start_application"
22+
SERVICE_TO_FOREGROUND = "to_foreground"

custom_components/fullykiosk/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"config_flow": true,
55
"documentation": "https://www.home-assistant.io/integrations/fullykiosk",
66
"requirements": [
7-
"python-fullykiosk==0.0.5"
7+
"python-fullykiosk==0.0.6"
88
],
99
"ssdp": [],
1010
"zeroconf": [],

custom_components/fullykiosk/media_player.py

Lines changed: 115 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
"""Fully Kiosk Browser media_player entity."""
22
import logging
3-
import voluptuous as vol
4-
5-
from homeassistant.helpers import config_validation as cv, entity_platform, service
63

4+
import voluptuous as vol
75
from homeassistant.components.media_player import (
86
ATTR_MEDIA_VOLUME_LEVEL,
97
SERVICE_VOLUME_SET,
108
SUPPORT_PLAY_MEDIA,
119
SUPPORT_VOLUME_SET,
1210
MediaPlayerEntity,
1311
)
14-
15-
SUPPORT_FULLYKIOSK = SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET
12+
from homeassistant.helpers import config_validation as cv
13+
from homeassistant.helpers import entity_platform
1614

1715
from .const import (
18-
DOMAIN,
19-
COORDINATOR,
20-
CONTROLLER,
16+
ATTR_APPLICATION,
17+
ATTR_CONFIG_TYPE,
18+
ATTR_KEY,
2119
ATTR_STREAM,
22-
AUDIOMANAGER_STREAM_MUSIC
20+
ATTR_URL,
21+
ATTR_VALUE,
22+
AUDIOMANAGER_STREAM_MUSIC,
23+
CONTROLLER,
24+
COORDINATOR,
25+
DOMAIN,
26+
SERVICE_LOAD_START_URL,
27+
SERVICE_LOAD_URL,
28+
SERVICE_PLAY_AUDIO,
29+
SERVICE_RESTART_APP,
30+
SERVICE_SET_CONFIG,
31+
SERVICE_START_APPLICATION,
32+
SERVICE_TO_FOREGROUND,
2333
)
2434

35+
SUPPORT_FULLYKIOSK = SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET
36+
37+
2538
_LOGGER = logging.getLogger(__name__)
2639

2740

@@ -32,17 +45,54 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
3245

3346
platform = entity_platform.current_platform.get()
3447

35-
# This will call Entity.set_fullykiosk_volume_level(volume_level=VALUE, stream=VALUE)
48+
platform.async_register_entity_service(
49+
SERVICE_LOAD_START_URL, {}, "async_fullykiosk_load_start_url"
50+
)
51+
52+
platform.async_register_entity_service(
53+
SERVICE_LOAD_URL, {vol.Required(ATTR_URL): cv.url}, "async_fullykiosk_load_url"
54+
)
55+
56+
platform.async_register_entity_service(
57+
SERVICE_PLAY_AUDIO,
58+
{
59+
vol.Required(ATTR_URL): cv.string,
60+
vol.Required(ATTR_STREAM): vol.All(vol.Number(scale=0), vol.Range(1, 10)),
61+
},
62+
"async_fullykiosk_play_audio",
63+
)
64+
65+
platform.async_register_entity_service(
66+
SERVICE_RESTART_APP, {}, "async_fullykiosk_restart"
67+
)
68+
69+
platform.async_register_entity_service(
70+
SERVICE_SET_CONFIG,
71+
{
72+
vol.Required(ATTR_CONFIG_TYPE): vol.In(["string", "bool"]),
73+
vol.Required(ATTR_KEY): cv.string,
74+
vol.Required(ATTR_VALUE): vol.Any(cv.string, cv.boolean),
75+
},
76+
"async_fullykiosk_set_config",
77+
)
78+
3679
platform.async_register_entity_service(
3780
SERVICE_VOLUME_SET,
3881
{
3982
vol.Required(ATTR_MEDIA_VOLUME_LEVEL): cv.small_float,
40-
vol.Required(ATTR_STREAM): vol.All(
41-
vol.Number(scale=0),
42-
vol.Range(1, 10),
43-
),
83+
vol.Required(ATTR_STREAM): vol.All(vol.Number(scale=0), vol.Range(1, 10)),
4484
},
45-
"async_set_fullykiosk_volume_level",
85+
"async_fullykiosk_set_volume_level",
86+
)
87+
88+
platform.async_register_entity_service(
89+
SERVICE_START_APPLICATION,
90+
{vol.Required(ATTR_APPLICATION): cv.string},
91+
"async_fullykiosk_start_app",
92+
)
93+
94+
platform.async_register_entity_service(
95+
SERVICE_TO_FOREGROUND, {}, "async_fullykiosk_to_foreground"
4696
)
4797

4898
async_add_entities([FullyMediaPlayer(coordinator, controller)], False)
@@ -79,24 +129,64 @@ def device_info(self):
79129
def unique_id(self):
80130
return self._unique_id
81131

132+
def fullykiosk_set_volume_level(self, volume_level, stream):
133+
"""Set volume level for a stream, range 0..1."""
134+
self.controller.setAudioVolume(int(volume_level * 100), stream)
135+
136+
def fullykiosk_play_audio(self, url, stream):
137+
"""Play a piece of audio on a specific stream."""
138+
self.controller.playSound(url, stream)
139+
82140
def play_media(self, media_type, media_id, **kwargs):
83-
self.controller.playSound(media_id)
141+
"""Play a piece of media."""
142+
self.fullykiosk_play_audio(media_id, AUDIOMANAGER_STREAM_MUSIC)
84143

85-
def set_fullykiosk_volume_level(self, volume_level, stream):
144+
def set_volume_level(self, volume_level):
145+
"""Set volume level, range 0..1."""
146+
self.fullykiosk_set_volume_level(volume_level, AUDIOMANAGER_STREAM_MUSIC)
147+
148+
async def async_fullykiosk_load_start_url(self):
149+
"""Load the start URL on a fullykiosk browser."""
150+
await self.hass.async_add_executor_job(self.controller.loadStartUrl)
151+
152+
async def async_fullykiosk_load_url(self, url):
153+
"""Load URL on a fullykiosk browser."""
154+
await self.hass.async_add_executor_job(self.controller.loadUrl, url)
155+
156+
async def async_fullykiosk_play_audio(self, url, stream):
157+
"""Play a piece of audio on a specific stream."""
158+
await self.hass.async_add_executor_job(self.fullykiosk_play_audio, url, stream)
159+
160+
async def async_fullykiosk_restart(self):
161+
"""Restart the fullykiosk browser app."""
162+
await self.hass.async_add_executor_job(self.controller.restartApp)
163+
164+
async def async_fullykiosk_set_config(self, config_type, key, value):
165+
"""Set fullykiosk configuration value."""
166+
if config_type == "string":
167+
await self.hass.async_add_executor_job(
168+
self.controller.setConfigurationString, key, value
169+
)
170+
elif config_type == "bool":
171+
await self.hass.async_add_executor_job(
172+
self.controller.setConfigurationBool, key, value
173+
)
174+
175+
async def async_fullykiosk_set_volume_level(self, volume_level, stream):
86176
"""Set volume level for a stream, range 0..1."""
87-
self.controller.sendCommand(
88-
cmd="setAudioVolume", level=str(int(volume_level * 100)), stream=str(stream)
177+
await self.hass.async_add_executor_job(
178+
self.fullykiosk_set_volume_level, volume_level, stream
89179
)
90180

91-
async def async_set_fullykiosk_volume_level(self, volume_level, stream):
92-
"""Set volume level for a stream, range 0..1."""
181+
async def async_fullykiosk_start_app(self, application):
182+
"""Start an application on the device running the fullykiosk browser app."""
93183
await self.hass.async_add_executor_job(
94-
self.set_fullykiosk_volume_level, volume_level, stream
184+
self.controller.startApplication, application
95185
)
96186

97-
def set_volume_level(self, volume_level):
98-
"""Set volume level, range 0..1."""
99-
self.set_fullykiosk_volume_level(volume_level=volume_level, stream=AUDIOMANAGER_STREAM_MUSIC)
187+
async def async_fullykiosk_to_foreground(self):
188+
"""Bring the fullykiosk browser app back to the foreground."""
189+
await self.hass.async_add_executor_job(self.controller.toForeground)
100190

101191
async def async_added_to_hass(self):
102192
"""Connect to dispatcher listening for entity data notifications."""

custom_components/fullykiosk/services.yaml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,77 @@
11
# Describes the format for available fullykiosk services
22

3+
load_start_url:
4+
description: Load Fully Kiosk Browser start URL.
5+
fields:
6+
entity_id:
7+
description: Name(s) of entities to load the start URL on.
8+
example: "media_player.amazon_fire_media_player"
9+
10+
load_url:
11+
description: Load URL on Fully Kiosk Browser.
12+
fields:
13+
entity_id:
14+
description: Name(s) of entities to load the start URL on.
15+
example: "media_player.amazon_fire_media_player"
16+
url:
17+
description: URL to be loaded.
18+
example: "https://www.fully-kiosk.com"
19+
20+
play_audio:
21+
description: Play audio on a Fully Kiosk Browser.
22+
fields:
23+
entity_id:
24+
description: Name(s) of entities to play media on
25+
example: "media_player.amazon_fire_media_player"
26+
url:
27+
description: The URL of the audio to play.
28+
example: "https://home-assistant.io/audio/test.mp3"
29+
stream:
30+
description: Stream on which to play the audio
31+
example: 3
32+
33+
restart:
34+
description: Restart the Fully Kiosk Browser app.
35+
fields:
36+
entity_id:
37+
description: Name(s) of entities to restart the app on.
38+
example: "media_player.amazon_fire_media_player"
39+
40+
set_config:
41+
description: Modify a setting in Fully Kiosk Browser.
42+
fields:
43+
entity_id:
44+
description: Name(s) of entities to modify the setting on.
45+
example: "media_player.amazon_fire_media_player"
46+
config_type:
47+
description: Type of setting (either 'string' or 'bool')
48+
example: "string"
49+
key:
50+
description: Key of the setting to change
51+
example: "startURL"
52+
value:
53+
description: New value of the setting
54+
example: "https://www.fully-kiosk.com"
55+
56+
start_application:
57+
description: Restart the Fully Kiosk Browser app.
58+
fields:
59+
entity_id:
60+
description: Name(s) of entities to restart the app on.
61+
example: "media_player.amazon_fire_media_player"
62+
application:
63+
description: Package name of the application to start.
64+
example: "de.ozerov.fully"
65+
66+
to_foreground:
67+
description: Bring the Fully Kiosk Browser app to the foreground.
68+
fields:
69+
entity_id:
70+
description: Name(s) of entities on which to bring the app to the foreground.
71+
example: "media_player.amazon_fire_media_player"
72+
373
volume_set:
4-
description: Set a fullykiosk volume level.
74+
description: Set a Fully Kiosk Browser volume level.
575
fields:
676
entity_id:
777
description: Name(s) of entities to set volume level on.

0 commit comments

Comments
 (0)