1
1
"""Fully Kiosk Browser media_player entity."""
2
2
import logging
3
- import voluptuous as vol
4
-
5
- from homeassistant .helpers import config_validation as cv , entity_platform , service
6
3
4
+ import voluptuous as vol
7
5
from homeassistant .components .media_player import (
8
6
ATTR_MEDIA_VOLUME_LEVEL ,
9
7
SERVICE_VOLUME_SET ,
10
8
SUPPORT_PLAY_MEDIA ,
11
9
SUPPORT_VOLUME_SET ,
12
10
MediaPlayerEntity ,
13
11
)
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
16
14
17
15
from .const import (
18
- DOMAIN ,
19
- COORDINATOR ,
20
- CONTROLLER ,
16
+ ATTR_APPLICATION ,
17
+ ATTR_CONFIG_TYPE ,
18
+ ATTR_KEY ,
21
19
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 ,
23
33
)
24
34
35
+ SUPPORT_FULLYKIOSK = SUPPORT_PLAY_MEDIA | SUPPORT_VOLUME_SET
36
+
37
+
25
38
_LOGGER = logging .getLogger (__name__ )
26
39
27
40
@@ -32,17 +45,54 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
32
45
33
46
platform = entity_platform .current_platform .get ()
34
47
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
+
36
79
platform .async_register_entity_service (
37
80
SERVICE_VOLUME_SET ,
38
81
{
39
82
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 )),
44
84
},
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"
46
96
)
47
97
48
98
async_add_entities ([FullyMediaPlayer (coordinator , controller )], False )
@@ -79,24 +129,64 @@ def device_info(self):
79
129
def unique_id (self ):
80
130
return self ._unique_id
81
131
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
+
82
140
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 )
84
143
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 ):
86
176
"""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
89
179
)
90
180
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 ."""
93
183
await self .hass .async_add_executor_job (
94
- self .set_fullykiosk_volume_level , volume_level , stream
184
+ self .controller . startApplication , application
95
185
)
96
186
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 )
100
190
101
191
async def async_added_to_hass (self ):
102
192
"""Connect to dispatcher listening for entity data notifications."""
0 commit comments