ovos-phal-plugin-browser 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ovos_phal_plugin_browser-0.1.0a1/LICENSE +202 -0
- ovos_phal_plugin_browser-0.1.0a1/PKG-INFO +76 -0
- ovos_phal_plugin_browser-0.1.0a1/README.md +52 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser/__init__.py +252 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser/device.py +169 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser/system.py +162 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/PKG-INFO +76 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/SOURCES.txt +12 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/dependency_links.txt +1 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/entry_points.txt +2 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/requires.txt +5 -0
- ovos_phal_plugin_browser-0.1.0a1/ovos_phal_plugin_browser.egg-info/top_level.txt +1 -0
- ovos_phal_plugin_browser-0.1.0a1/pyproject.toml +37 -0
- ovos_phal_plugin_browser-0.1.0a1/setup.cfg +4 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ovos-phal-plugin-browser
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: OpenVoiceOS PHAL plugin: the browser tab as the device (volume, location, power, sensors, camera)
|
|
5
|
+
Author: Andreas Lorensen
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/emkay-voice/ovos-phal-plugin-browser
|
|
8
|
+
Project-URL: Issues, https://github.com/emkay-voice/ovos-phal-plugin-browser/issues
|
|
9
|
+
Project-URL: Emkay, https://github.com/emkay-voice/emkay
|
|
10
|
+
Keywords: ovos,openvoiceos,plugin,phal,browser,volume,geolocation,pyodide,emkay
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Environment :: WebAssembly :: Emscripten
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: ovos-plugin-manager>=0.0.26
|
|
19
|
+
Requires-Dist: ovos-utils>=0.0.38
|
|
20
|
+
Requires-Dist: ovos-bus-client>=0.0.8
|
|
21
|
+
Requires-Dist: ovos-config>=0.0.12
|
|
22
|
+
Requires-Dist: json-database>=0.7.0
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# ovos-phal-plugin-browser
|
|
26
|
+
|
|
27
|
+
An [OpenVoiceOS](https://openvoiceos.org) PHAL plugin whose hardware is a
|
|
28
|
+
**browser tab**: volume, location, power, connectivity, sensors and the
|
|
29
|
+
camera, answered on the bus exactly as the device plugins answer them, with
|
|
30
|
+
the actual work done by the web page OVOS runs in.
|
|
31
|
+
|
|
32
|
+
It was made for [Emkay](https://github.com/emkay-voice/emkay), OpenVoiceOS in
|
|
33
|
+
the browser (Pyodide), and is what Emkay uses. Any host that runs OVOS in a
|
|
34
|
+
page can use it the same way.
|
|
35
|
+
|
|
36
|
+
## What it answers
|
|
37
|
+
|
|
38
|
+
| Bus messages | Behaves like | The page does |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `mycroft.volume.get/set/increase/decrease/mute/unmute/mute.toggle` | ovos-PHAL-plugin-alsa: `percent` 0..1, `{percent, muted}` answers and change reports, level kept in the plugin's settings | sets the gain of the one audio node everything plays through |
|
|
41
|
+
| `ovos.ipgeo.update` | ovos-phal-plugin-ipgeo: fills the *assistant* config layer (below the user layer, so a location the user set always wins) | asks the browser's geolocation (the user is asked first); OVOS' `get_reverse_geolocation` turns it into city, country and time zone. Until then, the browser's time zone |
|
|
42
|
+
| `system.reboot`, `system.shutdown`, `system.mycroft.service.restart`, `system.factory.reset`, `system.configure.language`, `system.ssh.*` | ovos-PHAL-plugin-system | reloads the page, blanks the screen until tapped, wipes the saved data; ssh is reported as not available |
|
|
43
|
+
| `ovos.PHAL.internet_check` | ovos-PHAL-plugin-connectivity-events | reports `navigator.onLine` and its changes |
|
|
44
|
+
| `ovos.phal.camera.ping/open/close/get` | ovos-PHAL-plugin-camera: `b64_frame` JPEG answers | opens the browser camera (the user is asked first) and takes a picture |
|
|
45
|
+
| `ovos.phal.sensor`, `ovos.phal.binary_sensor` (emitted) | ovos-PHAL-sensors | sends what the browser knows: battery, network, screen on and orientation, moving or still, how the phone lies, compass, storage, memory and CPU cores |
|
|
46
|
+
|
|
47
|
+
## How a host uses it
|
|
48
|
+
|
|
49
|
+
The plugin talks to the page through one callable, given when it is made:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from ovos_phal_plugin_browser import BrowserPHAL
|
|
53
|
+
|
|
54
|
+
plugin = BrowserPHAL(bus=bus, config=config, post=send_to_page)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`post(change: dict)` gets what the page should do: `{"volume": 0.6, "muted":
|
|
58
|
+
false}`, or `{"request": "location" | "camera_check" | "camera_open" |
|
|
59
|
+
"camera_close" | "picture" | "reload" | "off" | "forget_welcome"}`. The page
|
|
60
|
+
answers through the plugin's methods: `on_position(lat, lon, error)`,
|
|
61
|
+
`on_picture(id, jpeg_b64, error)` and `on_page_event(event, data)` for
|
|
62
|
+
`"online"`, `"sensor"`, `"camera"` and `"picture"`.
|
|
63
|
+
|
|
64
|
+
Emkay's page side is [`web/device.js`](https://github.com/emkay-voice/emkay/blob/main/web/device.js),
|
|
65
|
+
and the wiring is in [`worker_main.py`](https://github.com/emkay-voice/emkay/blob/main/py/emkay_mobile/worker_main.py).
|
|
66
|
+
|
|
67
|
+
On an ordinary device, with real hardware, use the device plugins instead.
|
|
68
|
+
|
|
69
|
+
## Config
|
|
70
|
+
|
|
71
|
+
`PHAL.ovos-phal-plugin-browser` in `mycroft.conf`; nothing needs setting. The
|
|
72
|
+
volume is kept in `~/.config/OpenVoiceOS/ovos-phal-plugin-browser.json`.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Apache-2.0
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# ovos-phal-plugin-browser
|
|
2
|
+
|
|
3
|
+
An [OpenVoiceOS](https://openvoiceos.org) PHAL plugin whose hardware is a
|
|
4
|
+
**browser tab**: volume, location, power, connectivity, sensors and the
|
|
5
|
+
camera, answered on the bus exactly as the device plugins answer them, with
|
|
6
|
+
the actual work done by the web page OVOS runs in.
|
|
7
|
+
|
|
8
|
+
It was made for [Emkay](https://github.com/emkay-voice/emkay), OpenVoiceOS in
|
|
9
|
+
the browser (Pyodide), and is what Emkay uses. Any host that runs OVOS in a
|
|
10
|
+
page can use it the same way.
|
|
11
|
+
|
|
12
|
+
## What it answers
|
|
13
|
+
|
|
14
|
+
| Bus messages | Behaves like | The page does |
|
|
15
|
+
|---|---|---|
|
|
16
|
+
| `mycroft.volume.get/set/increase/decrease/mute/unmute/mute.toggle` | ovos-PHAL-plugin-alsa: `percent` 0..1, `{percent, muted}` answers and change reports, level kept in the plugin's settings | sets the gain of the one audio node everything plays through |
|
|
17
|
+
| `ovos.ipgeo.update` | ovos-phal-plugin-ipgeo: fills the *assistant* config layer (below the user layer, so a location the user set always wins) | asks the browser's geolocation (the user is asked first); OVOS' `get_reverse_geolocation` turns it into city, country and time zone. Until then, the browser's time zone |
|
|
18
|
+
| `system.reboot`, `system.shutdown`, `system.mycroft.service.restart`, `system.factory.reset`, `system.configure.language`, `system.ssh.*` | ovos-PHAL-plugin-system | reloads the page, blanks the screen until tapped, wipes the saved data; ssh is reported as not available |
|
|
19
|
+
| `ovos.PHAL.internet_check` | ovos-PHAL-plugin-connectivity-events | reports `navigator.onLine` and its changes |
|
|
20
|
+
| `ovos.phal.camera.ping/open/close/get` | ovos-PHAL-plugin-camera: `b64_frame` JPEG answers | opens the browser camera (the user is asked first) and takes a picture |
|
|
21
|
+
| `ovos.phal.sensor`, `ovos.phal.binary_sensor` (emitted) | ovos-PHAL-sensors | sends what the browser knows: battery, network, screen on and orientation, moving or still, how the phone lies, compass, storage, memory and CPU cores |
|
|
22
|
+
|
|
23
|
+
## How a host uses it
|
|
24
|
+
|
|
25
|
+
The plugin talks to the page through one callable, given when it is made:
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from ovos_phal_plugin_browser import BrowserPHAL
|
|
29
|
+
|
|
30
|
+
plugin = BrowserPHAL(bus=bus, config=config, post=send_to_page)
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`post(change: dict)` gets what the page should do: `{"volume": 0.6, "muted":
|
|
34
|
+
false}`, or `{"request": "location" | "camera_check" | "camera_open" |
|
|
35
|
+
"camera_close" | "picture" | "reload" | "off" | "forget_welcome"}`. The page
|
|
36
|
+
answers through the plugin's methods: `on_position(lat, lon, error)`,
|
|
37
|
+
`on_picture(id, jpeg_b64, error)` and `on_page_event(event, data)` for
|
|
38
|
+
`"online"`, `"sensor"`, `"camera"` and `"picture"`.
|
|
39
|
+
|
|
40
|
+
Emkay's page side is [`web/device.js`](https://github.com/emkay-voice/emkay/blob/main/web/device.js),
|
|
41
|
+
and the wiring is in [`worker_main.py`](https://github.com/emkay-voice/emkay/blob/main/py/emkay_mobile/worker_main.py).
|
|
42
|
+
|
|
43
|
+
On an ordinary device, with real hardware, use the device plugins instead.
|
|
44
|
+
|
|
45
|
+
## Config
|
|
46
|
+
|
|
47
|
+
`PHAL.ovos-phal-plugin-browser` in `mycroft.conf`; nothing needs setting. The
|
|
48
|
+
volume is kept in `~/.config/OpenVoiceOS/ovos-phal-plugin-browser.json`.
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
Apache-2.0
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"""The phone's "hardware" for OVOS: a PHAL plugin whose device is the browser.
|
|
2
|
+
|
|
3
|
+
On a device, PHAL plugins answer OVOS' hardware messages: ovos-PHAL-plugin-
|
|
4
|
+
alsa turns `mycroft.volume.*` into mixer changes, ipgeo finds the location,
|
|
5
|
+
and so on. Here the hardware is the page, so this plugin answers the same
|
|
6
|
+
messages, with the same data, and hands the actual change to the page.
|
|
7
|
+
|
|
8
|
+
Volume follows ovos-PHAL-plugin-alsa exactly: `percent` is 0..1 on the bus,
|
|
9
|
+
`mycroft.volume.get` is answered with {"percent", "muted"}, every change is
|
|
10
|
+
reported the same way, and the level is kept in the plugin's own settings
|
|
11
|
+
file (~/.config/OpenVoiceOS/ovos-phal-plugin-browser.json, which lives in
|
|
12
|
+
IndexedDB like the rest of ~/.config). The page plays everything through
|
|
13
|
+
one gain node, which is this plugin's "mixer".
|
|
14
|
+
|
|
15
|
+
Location follows ovos-phal-plugin-ipgeo, which a device uses on first boot:
|
|
16
|
+
it fills the *assistant* config layer (below the user layer, so a location
|
|
17
|
+
the user sets always wins), only when that layer has none, and again on
|
|
18
|
+
`ovos.ipgeo.update` (with "overwrite"). ipgeo asks http://ip-api.com, which
|
|
19
|
+
an https page may not call, so the position comes from the browser's own
|
|
20
|
+
geolocation instead (it asks the user first) and OVOS' own
|
|
21
|
+
`get_reverse_geolocation` turns it into city, country and time zone. Until
|
|
22
|
+
then, or if the user says no, the layer gets the browser's time zone, so
|
|
23
|
+
clocks and timers are right from the start.
|
|
24
|
+
|
|
25
|
+
Power, factory reset and language (ovos-PHAL-plugin-system) are in
|
|
26
|
+
phal_system.py; connectivity, sensors and the camera in phal_device.py.
|
|
27
|
+
"""
|
|
28
|
+
import os
|
|
29
|
+
import json
|
|
30
|
+
|
|
31
|
+
from ovos_bus_client.message import Message
|
|
32
|
+
from ovos_bus_client.session import SessionManager
|
|
33
|
+
from ovos_bus_client.util import get_message_lang
|
|
34
|
+
from ovos_config import Configuration
|
|
35
|
+
from ovos_config.models import AssistantConfig
|
|
36
|
+
from ovos_plugin_manager.phal import PHALPlugin
|
|
37
|
+
from ovos_utils.log import LOG
|
|
38
|
+
|
|
39
|
+
from .device import DeviceMixin
|
|
40
|
+
from .system import SystemMixin
|
|
41
|
+
|
|
42
|
+
try:
|
|
43
|
+
from json_database import JsonConfigXDG
|
|
44
|
+
except ImportError: # pragma: no cover
|
|
45
|
+
JsonConfigXDG = None
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class BrowserPHAL(SystemMixin, DeviceMixin, PHALPlugin):
|
|
49
|
+
"""PHAL for a browser tab: volume, location, power, connectivity,
|
|
50
|
+
sensors and camera, each with the bus contract of the plugin a device
|
|
51
|
+
uses for it."""
|
|
52
|
+
|
|
53
|
+
def __init__(self, bus=None, config=None, post=None):
|
|
54
|
+
"""
|
|
55
|
+
Args:
|
|
56
|
+
bus: the OVOS bus
|
|
57
|
+
config: the plugin's PHAL config section (default_volume)
|
|
58
|
+
post: callable(dict) that hands a state change to the page
|
|
59
|
+
"""
|
|
60
|
+
super().__init__(bus=bus, name="ovos-phal-plugin-browser", config=config or {})
|
|
61
|
+
self._post = post or (lambda change: None)
|
|
62
|
+
self.settings = (JsonConfigXDG(self.name, subfolder="OpenVoiceOS")
|
|
63
|
+
if JsonConfigXDG else {})
|
|
64
|
+
if self.settings.get("first_boot", True):
|
|
65
|
+
self.settings["volume"] = int(self.config.get("default_volume", 75))
|
|
66
|
+
self.settings["muted"] = False
|
|
67
|
+
self.settings["first_boot"] = False
|
|
68
|
+
self._store()
|
|
69
|
+
self._system_start()
|
|
70
|
+
self._device_start()
|
|
71
|
+
for topic, handler in self._handlers().items():
|
|
72
|
+
self.bus.on(topic, handler)
|
|
73
|
+
self._report() # the page starts at the stored level
|
|
74
|
+
self.assistant_config = AssistantConfig()
|
|
75
|
+
self._location_request = None # the ovos.ipgeo.update waiting for an answer
|
|
76
|
+
self.on_location_update() # first boot: as ipgeo does
|
|
77
|
+
|
|
78
|
+
def _handlers(self):
|
|
79
|
+
return {
|
|
80
|
+
"mycroft.volume.get": self.handle_volume_request,
|
|
81
|
+
"mycroft.volume.set": self.handle_volume_change,
|
|
82
|
+
"mycroft.volume.increase": self.handle_volume_increase,
|
|
83
|
+
"mycroft.volume.decrease": self.handle_volume_decrease,
|
|
84
|
+
"mycroft.volume.mute": self.handle_mute_request,
|
|
85
|
+
"mycroft.volume.unmute": self.handle_unmute_request,
|
|
86
|
+
"mycroft.volume.mute.toggle": self.handle_mute_toggle_request,
|
|
87
|
+
"ovos.ipgeo.update": self.on_location_update,
|
|
88
|
+
**self._system_handlers(),
|
|
89
|
+
**self._device_handlers(),
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# --- the "mixer" ----------------------------------------------------
|
|
93
|
+
@property
|
|
94
|
+
def volume(self) -> int:
|
|
95
|
+
"""Current level, 0..100."""
|
|
96
|
+
return int(self.settings.get("volume", 75))
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def muted(self) -> bool:
|
|
100
|
+
return bool(self.settings.get("muted", False))
|
|
101
|
+
|
|
102
|
+
def _store(self):
|
|
103
|
+
if hasattr(self.settings, "store"):
|
|
104
|
+
self.settings.store()
|
|
105
|
+
|
|
106
|
+
def _report(self):
|
|
107
|
+
"""Tell the page the level to play at."""
|
|
108
|
+
self._post({"volume": self.volume / 100, "muted": self.muted})
|
|
109
|
+
|
|
110
|
+
def set_volume(self, percent, play_sound=True):
|
|
111
|
+
"""Set the level (0..100), clamped, as the alsa plugin does."""
|
|
112
|
+
self.settings["volume"] = max(0, min(100, int(percent)))
|
|
113
|
+
self._store()
|
|
114
|
+
self._report()
|
|
115
|
+
if play_sound:
|
|
116
|
+
self.bus.emit(Message("mycroft.audio.play_sound",
|
|
117
|
+
{"uri": "snd/blop-mark-diangelo.wav"}))
|
|
118
|
+
self.handle_volume_request(Message("mycroft.volume.get"))
|
|
119
|
+
|
|
120
|
+
def set_muted(self, muted: bool):
|
|
121
|
+
self.settings["muted"] = bool(muted)
|
|
122
|
+
self._store()
|
|
123
|
+
self._report()
|
|
124
|
+
self.handle_volume_request(Message("mycroft.volume.get"))
|
|
125
|
+
|
|
126
|
+
# --- location (same contract as ovos-phal-plugin-ipgeo) -------------
|
|
127
|
+
def _has_location(self) -> bool:
|
|
128
|
+
"""True once the assistant layer holds a real location (a city), not
|
|
129
|
+
just the time-zone stand-in written below."""
|
|
130
|
+
loc = self.assistant_config.get("location") or {}
|
|
131
|
+
return bool(loc.get("city"))
|
|
132
|
+
|
|
133
|
+
def on_location_update(self, message=None):
|
|
134
|
+
"""Ask the page for the phone's position, unless a location is known
|
|
135
|
+
and the request does not ask to overwrite it (as ipgeo's on_reset)."""
|
|
136
|
+
if self._has_location() and (message is None or not message.data.get("overwrite")):
|
|
137
|
+
LOG.debug("Skipping overwrite of existing location")
|
|
138
|
+
return
|
|
139
|
+
if not self.assistant_config.get("location"):
|
|
140
|
+
self._store_location({"timezone": self._browser_timezone()})
|
|
141
|
+
self._location_request = message
|
|
142
|
+
self._post({"request": "location"})
|
|
143
|
+
|
|
144
|
+
@staticmethod
|
|
145
|
+
def _browser_timezone() -> dict:
|
|
146
|
+
tz = os.environ.get("EMKAY_TZ") or "UTC" # set by worker.js
|
|
147
|
+
return {"code": tz, "name": tz.replace("/", " ")}
|
|
148
|
+
|
|
149
|
+
def on_position(self, lat=None, lon=None, error=None):
|
|
150
|
+
"""The page's answer: coordinates, or why there are none."""
|
|
151
|
+
message, self._location_request = self._location_request, None
|
|
152
|
+
if error or lat is None or lon is None:
|
|
153
|
+
LOG.info(f"No position from the browser: {error}")
|
|
154
|
+
if message:
|
|
155
|
+
self.bus.emit(message.response(data={"error": True}))
|
|
156
|
+
return
|
|
157
|
+
try:
|
|
158
|
+
from ovos_utils.geolocation import get_reverse_geolocation
|
|
159
|
+
lang = get_message_lang(message) or Configuration().get("lang", "en")
|
|
160
|
+
location = get_reverse_geolocation(float(lat), float(lon), lang=lang)
|
|
161
|
+
except Exception as e: # offline, service refused: keep what we have
|
|
162
|
+
LOG.error(f"Reverse geolocation failed: {e}")
|
|
163
|
+
if message:
|
|
164
|
+
self.bus.emit(message.response(data={"error": True}))
|
|
165
|
+
return
|
|
166
|
+
LOG.info(f"Browser geolocation: {location.get('address')}")
|
|
167
|
+
self._store_location(location)
|
|
168
|
+
if message:
|
|
169
|
+
self.bus.emit(message.response(data={"location": location}))
|
|
170
|
+
|
|
171
|
+
def _store_location(self, location: dict):
|
|
172
|
+
"""Write the assistant layer and tell OVOS, as ipgeo does.
|
|
173
|
+
|
|
174
|
+
The device's default session carries its own copy of the location
|
|
175
|
+
(OVOS-SESSION-1 stamps lat/lon/tz into it when it is created), and
|
|
176
|
+
skills read the time zone from there. On a device ipgeo has usually
|
|
177
|
+
run before the first question; here the position may come minutes
|
|
178
|
+
later, when the user allows it, so the default session is created
|
|
179
|
+
anew from the updated configuration.
|
|
180
|
+
"""
|
|
181
|
+
self.assistant_config["location"] = location
|
|
182
|
+
self.assistant_config.store()
|
|
183
|
+
self.bus.emit(Message("configuration.updated"))
|
|
184
|
+
SessionManager.reset_default_session()
|
|
185
|
+
|
|
186
|
+
# --- bus handlers (same contract as ovos-PHAL-plugin-alsa) -----------
|
|
187
|
+
def validate_message_context(self, message) -> bool:
|
|
188
|
+
"""Only the device's own session controls its volume (as alsa)."""
|
|
189
|
+
sid = SessionManager.get(message).session_id
|
|
190
|
+
native = getattr(self.bus, "session_id", "default")
|
|
191
|
+
return sid == native
|
|
192
|
+
|
|
193
|
+
def handle_volume_request(self, message):
|
|
194
|
+
if not self.validate_message_context(message):
|
|
195
|
+
return
|
|
196
|
+
self.bus.emit(message.response({"percent": self.volume / 100,
|
|
197
|
+
"muted": self.muted}))
|
|
198
|
+
|
|
199
|
+
def handle_volume_change(self, message):
|
|
200
|
+
if not self.validate_message_context(message):
|
|
201
|
+
return
|
|
202
|
+
self.set_volume(message.data["percent"] * 100,
|
|
203
|
+
play_sound=message.data.get("play_sound", True))
|
|
204
|
+
|
|
205
|
+
def handle_volume_increase(self, message):
|
|
206
|
+
if not self.validate_message_context(message):
|
|
207
|
+
return
|
|
208
|
+
change = message.data.get("percent", .10) * 100 or 15
|
|
209
|
+
self.set_volume(self.volume + abs(change),
|
|
210
|
+
play_sound=message.data.get("play_sound", True))
|
|
211
|
+
|
|
212
|
+
def handle_volume_decrease(self, message):
|
|
213
|
+
if not self.validate_message_context(message):
|
|
214
|
+
return
|
|
215
|
+
change = message.data.get("percent", -.10) * 100 or 15
|
|
216
|
+
self.set_volume(self.volume - abs(change),
|
|
217
|
+
play_sound=message.data.get("play_sound", True))
|
|
218
|
+
|
|
219
|
+
def handle_mute_request(self, message):
|
|
220
|
+
if self.validate_message_context(message):
|
|
221
|
+
LOG.info("User muted audio.")
|
|
222
|
+
self.set_muted(True)
|
|
223
|
+
|
|
224
|
+
def handle_unmute_request(self, message):
|
|
225
|
+
if self.validate_message_context(message):
|
|
226
|
+
LOG.info("User unmuted audio.")
|
|
227
|
+
self.set_muted(False)
|
|
228
|
+
|
|
229
|
+
def handle_mute_toggle_request(self, message):
|
|
230
|
+
if self.validate_message_context(message):
|
|
231
|
+
self.set_muted(not self.muted)
|
|
232
|
+
|
|
233
|
+
def shutdown(self):
|
|
234
|
+
for topic, handler in self._handlers().items():
|
|
235
|
+
self.bus.remove(topic, handler)
|
|
236
|
+
super().shutdown()
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
_plugin = None
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def start(bus, post):
|
|
243
|
+
"""Load the plugin on the bus; `post(str)` sends JSON to the page."""
|
|
244
|
+
global _plugin
|
|
245
|
+
conf = Configuration().get("PHAL", {}).get("ovos-phal-plugin-browser", {})
|
|
246
|
+
_plugin = BrowserPHAL(bus=bus, config=conf, post=lambda change: post(json.dumps(change)))
|
|
247
|
+
return _plugin
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def plugin():
|
|
251
|
+
"""The loaded plugin (None before start())."""
|
|
252
|
+
return _plugin
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"""Connectivity, sensors and camera for the browser PHAL plugin.
|
|
2
|
+
|
|
3
|
+
Each follows the PHAL plugin a device uses for it, with the browser's APIs
|
|
4
|
+
as the hardware (web/device.js reads them and reports changes):
|
|
5
|
+
|
|
6
|
+
Connectivity - ovos-PHAL-plugin-connectivity-events: the same
|
|
7
|
+
mycroft.network/internet.(dis)connected and .state messages on a change,
|
|
8
|
+
and the same answer to `ovos.PHAL.internet_check`. The state comes from
|
|
9
|
+
the browser (navigator.onLine and its online/offline events), since a
|
|
10
|
+
page cannot open the DNS socket that plugin checks with.
|
|
11
|
+
|
|
12
|
+
Sensors - ovos-PHAL-sensors' bus logger: every reading is an
|
|
13
|
+
`ovos.phal.sensor` (a value) or `ovos.phal.binary_sensor` (on/off) with
|
|
14
|
+
state, sensor_id "<device>_<name>", device_name, name and attributes
|
|
15
|
+
(Home Assistant style: unit_of_measurement, device_class, icon). The
|
|
16
|
+
control panel's Sensors page shows them. What a phone browser offers:
|
|
17
|
+
battery level and charging, network type and speed, screen on/off and
|
|
18
|
+
orientation, whether the phone is moving (motion sensor), ambient light.
|
|
19
|
+
|
|
20
|
+
Camera - ovos-PHAL-plugin-camera: ovos.phal.camera.ping/open/close/get.
|
|
21
|
+
`get` answers with {"path"} when a path was given (a JPEG written there)
|
|
22
|
+
or {"b64_frame"}. That plugin sends the raw OpenCV pixel buffer; here
|
|
23
|
+
`b64_frame` is a JPEG, which is what the browser's camera gives and what
|
|
24
|
+
a consumer can decode without knowing the frame size. The browser asks
|
|
25
|
+
the user before the first picture.
|
|
26
|
+
"""
|
|
27
|
+
import base64
|
|
28
|
+
import os
|
|
29
|
+
import string
|
|
30
|
+
|
|
31
|
+
from ovos_bus_client.message import Message
|
|
32
|
+
from ovos_utils.log import LOG
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _norm(s):
|
|
36
|
+
"""ovos-PHAL-sensors' id normalisation (ascii, lower, underscores)."""
|
|
37
|
+
s = str(s).lower().strip().replace(" ", "_").replace("-", "").replace(".", "_")
|
|
38
|
+
return "".join(c for c in s if c in string.ascii_letters + string.digits + "_")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class DeviceMixin:
|
|
42
|
+
"""Connectivity, sensor and camera handlers, for BrowserPHAL."""
|
|
43
|
+
|
|
44
|
+
def _device_handlers(self):
|
|
45
|
+
return {
|
|
46
|
+
"ovos.PHAL.internet_check": self.handle_internet_check,
|
|
47
|
+
"ovos.phal.camera.ping": self.handle_camera_pong,
|
|
48
|
+
"ovos.phal.camera.open": self.handle_camera_open,
|
|
49
|
+
"ovos.phal.camera.close": self.handle_camera_close,
|
|
50
|
+
"ovos.phal.camera.get": self.handle_take_picture,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
def _device_start(self):
|
|
54
|
+
self.online = None # unknown until the page reports
|
|
55
|
+
self.sensors = {} # sensor_id -> last reading sent
|
|
56
|
+
self._pictures = {} # request id -> the camera.get message
|
|
57
|
+
self._picture_id = 0
|
|
58
|
+
self._camera_ping = None # the ovos.phal.camera.ping being answered
|
|
59
|
+
if self.config.get("camera", True):
|
|
60
|
+
self._post({"request": "camera_check"}) # "let the system know"
|
|
61
|
+
|
|
62
|
+
# --- page events (worker_main.phal_event) ------------------------------
|
|
63
|
+
def on_page_event(self, event: str, data: dict):
|
|
64
|
+
"""A change the page saw: "online", "sensor" or "picture"."""
|
|
65
|
+
if event == "online":
|
|
66
|
+
self.set_online(bool(data.get("online")))
|
|
67
|
+
elif event == "sensor":
|
|
68
|
+
self.sensor_reading(**data)
|
|
69
|
+
elif event == "picture":
|
|
70
|
+
self.on_picture(**data)
|
|
71
|
+
elif event == "camera":
|
|
72
|
+
# the page's answer to camera_check; as the plugin: a pong when
|
|
73
|
+
# there is a camera, to the ping that asked (or to all, on load)
|
|
74
|
+
ping, self._camera_ping = self._camera_ping, None
|
|
75
|
+
if data.get("available"):
|
|
76
|
+
self.bus.emit(ping.reply("ovos.phal.camera.pong") if ping
|
|
77
|
+
else Message("ovos.phal.camera.pong"))
|
|
78
|
+
|
|
79
|
+
# --- connectivity (ovos-PHAL-plugin-connectivity-events) ---------------
|
|
80
|
+
def set_online(self, online: bool, message=None):
|
|
81
|
+
"""Emit what connectivity-events emits when the state changes.
|
|
82
|
+
|
|
83
|
+
A browser only knows "has a connection" or not, so the state is
|
|
84
|
+
FULL or NONE (the plugin's LIMITED, network without internet, does
|
|
85
|
+
not occur).
|
|
86
|
+
"""
|
|
87
|
+
if online == self.online:
|
|
88
|
+
return
|
|
89
|
+
was, self.online = self.online, online
|
|
90
|
+
message = message or Message("connectivity_check")
|
|
91
|
+
LOG.info(f"Network state changed to: {'FULL' if online else 'NONE'}")
|
|
92
|
+
if online:
|
|
93
|
+
self.bus.emit(message.reply("mycroft.network.connected"))
|
|
94
|
+
self.bus.emit(message.reply("mycroft.internet.connected"))
|
|
95
|
+
else:
|
|
96
|
+
if was:
|
|
97
|
+
self.bus.emit(message.reply("mycroft.internet.disconnected"))
|
|
98
|
+
self.bus.emit(message.reply("mycroft.network.disconnected"))
|
|
99
|
+
self.bus.emit(message.reply("enclosure.notify.no_internet"))
|
|
100
|
+
state = "connected" if online else "disconnected"
|
|
101
|
+
self.bus.emit(message.reply("mycroft.internet.state", {"state": state}))
|
|
102
|
+
self.bus.emit(message.reply("mycroft.network.state", {"state": state}))
|
|
103
|
+
|
|
104
|
+
def handle_internet_check(self, message):
|
|
105
|
+
online = bool(self.online) if self.online is not None else True
|
|
106
|
+
self.bus.emit(message.response({"internet_connected": online,
|
|
107
|
+
"network_connected": online}))
|
|
108
|
+
|
|
109
|
+
# --- sensors (ovos-PHAL-sensors' MessageBusLogger) -----------------------
|
|
110
|
+
def sensor_reading(self, device, name, state, binary=False, attributes=None):
|
|
111
|
+
"""Emit one reading, when it differs from the last one sent."""
|
|
112
|
+
device, name = _norm(device), _norm(name)
|
|
113
|
+
sensor_id = f"{device}_{name}"
|
|
114
|
+
attributes = dict(attributes or {})
|
|
115
|
+
attributes.setdefault("friendly_name", f"{device} {name}".replace("_", " ").title())
|
|
116
|
+
if self.sensors.get(sensor_id) == (state, attributes):
|
|
117
|
+
return
|
|
118
|
+
self.sensors[sensor_id] = (state, attributes)
|
|
119
|
+
topic = "ovos.phal.binary_sensor" if binary else "ovos.phal.sensor"
|
|
120
|
+
self.bus.emit(Message(topic, {"state": state, "sensor_id": sensor_id,
|
|
121
|
+
"device_name": device, "name": name,
|
|
122
|
+
"attributes": attributes}))
|
|
123
|
+
|
|
124
|
+
# --- camera (ovos-PHAL-plugin-camera) -----------------------------------
|
|
125
|
+
def handle_camera_pong(self, message):
|
|
126
|
+
# the page has a camera when the browser offers one (mediaDevices);
|
|
127
|
+
# whether the user allows it is only known at the first picture
|
|
128
|
+
if self.validate_message_context(message) and self.config.get("camera", True):
|
|
129
|
+
self._camera_ping = message
|
|
130
|
+
self._post({"request": "camera_check"})
|
|
131
|
+
|
|
132
|
+
def handle_camera_open(self, message):
|
|
133
|
+
if self.validate_message_context(message):
|
|
134
|
+
self._post({"request": "camera_open"})
|
|
135
|
+
|
|
136
|
+
def handle_camera_close(self, message):
|
|
137
|
+
if self.validate_message_context(message):
|
|
138
|
+
self._post({"request": "camera_close"})
|
|
139
|
+
|
|
140
|
+
def handle_take_picture(self, message):
|
|
141
|
+
"""Ask the page for a frame; on_picture answers the request."""
|
|
142
|
+
if not self.validate_message_context(message):
|
|
143
|
+
return
|
|
144
|
+
self._picture_id += 1
|
|
145
|
+
self._pictures[self._picture_id] = message
|
|
146
|
+
self._post({"request": "picture", "id": self._picture_id})
|
|
147
|
+
|
|
148
|
+
def on_picture(self, id, jpeg_b64=None, error=None):
|
|
149
|
+
message = self._pictures.pop(int(id), None)
|
|
150
|
+
if message is None:
|
|
151
|
+
return
|
|
152
|
+
if error or not jpeg_b64:
|
|
153
|
+
LOG.error(f"No picture from the browser: {error}")
|
|
154
|
+
self.bus.emit(message.response({"error": str(error)}, False))
|
|
155
|
+
return
|
|
156
|
+
path = message.data.get("path")
|
|
157
|
+
if path:
|
|
158
|
+
try:
|
|
159
|
+
path = os.path.expanduser(path)
|
|
160
|
+
os.makedirs(os.path.dirname(path) or ".", exist_ok=True)
|
|
161
|
+
with open(path, "wb") as f:
|
|
162
|
+
f.write(base64.b64decode(jpeg_b64))
|
|
163
|
+
LOG.info(f"Picture saved: {path}")
|
|
164
|
+
self.bus.emit(message.response({"path": path}))
|
|
165
|
+
except Exception as e:
|
|
166
|
+
LOG.error(f"Error saving image: {e}")
|
|
167
|
+
self.bus.emit(message.response({"error": str(e)}, False))
|
|
168
|
+
else:
|
|
169
|
+
self.bus.emit(message.response({"b64_frame": jpeg_b64}))
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"""Power, factory reset and language for the browser PHAL plugin.
|
|
2
|
+
|
|
3
|
+
Same bus contract as ovos-PHAL-plugin-system, which a device runs: the same
|
|
4
|
+
messages in, the same `.start` / `.complete` messages and GUI animations out.
|
|
5
|
+
What differs is the machine: on a device these end in `systemctl`, here
|
|
6
|
+
OVOS *is* the page, so
|
|
7
|
+
|
|
8
|
+
system.reboot -> the page reloads (after saving to disk)
|
|
9
|
+
system.mycroft.service.restart -> the same: every OVOS service is the page
|
|
10
|
+
system.shutdown -> the page goes dark; a tap starts it again
|
|
11
|
+
system.factory.reset -> the plugin's own wipe (cache, data, logs,
|
|
12
|
+
configs), then a reboot, so Emkay starts
|
|
13
|
+
as on the first day (and offers setup)
|
|
14
|
+
system.ssh.* -> a browser has no SSH: status says off
|
|
15
|
+
|
|
16
|
+
The page part is in web/device.js.
|
|
17
|
+
"""
|
|
18
|
+
import os
|
|
19
|
+
import shutil
|
|
20
|
+
from os.path import expanduser, join
|
|
21
|
+
|
|
22
|
+
from ovos_bus_client.message import Message
|
|
23
|
+
from ovos_utils.log import LOG
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class SystemMixin:
|
|
27
|
+
"""ovos-PHAL-plugin-system's handlers, for BrowserPHAL."""
|
|
28
|
+
|
|
29
|
+
def _system_handlers(self):
|
|
30
|
+
return {
|
|
31
|
+
"system.ssh.status": self.handle_ssh_status,
|
|
32
|
+
"system.ssh.enable": self.handle_ssh_change,
|
|
33
|
+
"system.ssh.disable": self.handle_ssh_change,
|
|
34
|
+
"system.reboot": self.handle_reboot_request,
|
|
35
|
+
"system.reboot.start": self.handle_rebooting,
|
|
36
|
+
"system.shutdown": self.handle_shutdown_request,
|
|
37
|
+
"system.shutdown.start": self.handle_shutting_down,
|
|
38
|
+
"system.factory.reset": self.handle_factory_reset_request,
|
|
39
|
+
"system.factory.reset.register": self.handle_reset_register,
|
|
40
|
+
"system.configure.language": self.handle_configure_language_request,
|
|
41
|
+
"system.mycroft.service.restart": self.handle_mycroft_restart_request,
|
|
42
|
+
"system.mycroft.service.restart.start": self.handle_mycroft_restarting,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
def _system_start(self):
|
|
46
|
+
from ovos_bus_client.apis.gui import GUIInterface
|
|
47
|
+
self.gui = GUIInterface(bus=self.bus, skill_id=self.name)
|
|
48
|
+
self.factory_reset_plugs = []
|
|
49
|
+
# as the system plugin: let PHAL plugins with a reset step register
|
|
50
|
+
self.bus.emit(Message("system.factory.reset.ping"))
|
|
51
|
+
|
|
52
|
+
# --- power -----------------------------------------------------------
|
|
53
|
+
def handle_reboot_request(self, message):
|
|
54
|
+
self.bus.emit(message.forward("system.reboot.start", message.data))
|
|
55
|
+
LOG.info("Reboot requested: reloading the page")
|
|
56
|
+
self._post({"request": "reload"})
|
|
57
|
+
|
|
58
|
+
def handle_rebooting(self, message):
|
|
59
|
+
if message.data.get("display", True):
|
|
60
|
+
self.gui.show_loading_animation("Rebooting", override_animations=True,
|
|
61
|
+
override_idle=True)
|
|
62
|
+
|
|
63
|
+
def handle_mycroft_restart_request(self, message):
|
|
64
|
+
self.bus.emit(message.forward("system.mycroft.service.restart.start", message.data))
|
|
65
|
+
LOG.info("Service restart requested: reloading the page")
|
|
66
|
+
self._post({"request": "reload"})
|
|
67
|
+
|
|
68
|
+
def handle_mycroft_restarting(self, message):
|
|
69
|
+
if message.data.get("display", True):
|
|
70
|
+
self.gui.show_loading_animation("Restarting", override_animations=True,
|
|
71
|
+
override_idle=True)
|
|
72
|
+
|
|
73
|
+
def handle_shutdown_request(self, message):
|
|
74
|
+
self.bus.emit(message.forward("system.shutdown.start", message.data))
|
|
75
|
+
LOG.info("Shutdown requested: the page goes dark")
|
|
76
|
+
self._post({"request": "off"})
|
|
77
|
+
|
|
78
|
+
def handle_shutting_down(self, message):
|
|
79
|
+
if message.data.get("display", True):
|
|
80
|
+
self.gui.show_loading_animation("Shutting Down", override_animations=True,
|
|
81
|
+
override_idle=True)
|
|
82
|
+
|
|
83
|
+
# --- factory reset (ovos-PHAL-plugin-system's steps) ------------------
|
|
84
|
+
def handle_reset_register(self, message):
|
|
85
|
+
sid = message.data.get("skill_id")
|
|
86
|
+
if sid and sid not in self.factory_reset_plugs:
|
|
87
|
+
self.factory_reset_plugs.append(sid)
|
|
88
|
+
|
|
89
|
+
def handle_factory_reset_request(self, message):
|
|
90
|
+
from json_database import JsonDatabaseXDG, JsonStorageXDG
|
|
91
|
+
from ovos_config.locations import ASSISTANT_CONFIG, USER_CONFIG, WEB_CONFIG_CACHE
|
|
92
|
+
from ovos_config.meta import get_config_filename, get_xdg_base
|
|
93
|
+
from ovos_utils.xdg_utils import xdg_cache_home, xdg_data_home, xdg_state_home
|
|
94
|
+
|
|
95
|
+
LOG.debug(f"Factory reset request: {message.data}")
|
|
96
|
+
self.bus.emit(message.forward("system.factory.reset.start"))
|
|
97
|
+
self.bus.emit(message.forward("system.factory.reset.ping"))
|
|
98
|
+
base = get_xdg_base()
|
|
99
|
+
|
|
100
|
+
if message.data.get("wipe_cache", True):
|
|
101
|
+
shutil.rmtree(f"{xdg_cache_home()}/{base}", ignore_errors=True)
|
|
102
|
+
if message.data.get("wipe_data", True):
|
|
103
|
+
shutil.rmtree(f"{xdg_data_home()}/{base}", ignore_errors=True)
|
|
104
|
+
for j in ["ovos_device_info", "ovos_oauth", "ovos_oauth_apps", "ovos_devices",
|
|
105
|
+
"ovos_metrics", "ovos_preferences", "ovos_skills_meta"]:
|
|
106
|
+
p = JsonStorageXDG(j).path
|
|
107
|
+
if os.path.isfile(p):
|
|
108
|
+
os.remove(p)
|
|
109
|
+
for j in ["ovos_metrics", "ovos_utterances", "ovos_wakewords"]:
|
|
110
|
+
p = JsonDatabaseXDG(j).db.path
|
|
111
|
+
if os.path.isfile(p):
|
|
112
|
+
os.remove(p)
|
|
113
|
+
# the pre-trained intents lived in the data folder just wiped;
|
|
114
|
+
# forget that they were downloaded, so the next boot fetches them
|
|
115
|
+
# again instead of training on the phone (worker.js)
|
|
116
|
+
stamp = expanduser("~/.local/share/emkay-mobile/downloads.json")
|
|
117
|
+
if os.path.isfile(stamp):
|
|
118
|
+
os.remove(stamp)
|
|
119
|
+
if message.data.get("wipe_logs", True):
|
|
120
|
+
shutil.rmtree(f"{xdg_state_home()}/{base}", ignore_errors=True)
|
|
121
|
+
if message.data.get("wipe_configs", True):
|
|
122
|
+
old = join(expanduser("~"), "." + base, get_config_filename())
|
|
123
|
+
for p in (old, USER_CONFIG, ASSISTANT_CONFIG, WEB_CONFIG_CACHE):
|
|
124
|
+
if os.path.isfile(p):
|
|
125
|
+
os.remove(p)
|
|
126
|
+
LOG.debug("Data reset completed")
|
|
127
|
+
|
|
128
|
+
if message.data.get("reset_hardware", True) and self.factory_reset_plugs:
|
|
129
|
+
# plugins answer on this same bus while the message is emitted
|
|
130
|
+
done = set()
|
|
131
|
+
on_done = lambda m: done.add(m.data.get("skill_id"))
|
|
132
|
+
self.bus.on("system.factory.reset.phal.complete", on_done)
|
|
133
|
+
self.bus.emit(message.forward("system.factory.reset.phal", message.data))
|
|
134
|
+
self.bus.remove("system.factory.reset.phal.complete", on_done)
|
|
135
|
+
missing = set(self.factory_reset_plugs) - done
|
|
136
|
+
if missing:
|
|
137
|
+
LOG.warning(f"No reset answer from: {sorted(missing)}")
|
|
138
|
+
|
|
139
|
+
# no reset script here (there is no shell); the page also forgets
|
|
140
|
+
# that Emkay was started before, so it offers setup again
|
|
141
|
+
self.bus.emit(message.forward("system.factory.reset.complete"))
|
|
142
|
+
self._post({"request": "forget_welcome"})
|
|
143
|
+
if message.data.get("reboot", True):
|
|
144
|
+
self.bus.emit(message.forward("system.reboot"))
|
|
145
|
+
|
|
146
|
+
# --- language, ssh -----------------------------------------------------
|
|
147
|
+
def handle_configure_language_request(self, message):
|
|
148
|
+
from ovos_config.config import update_mycroft_config
|
|
149
|
+
from ovos_config.locale import set_default_lang
|
|
150
|
+
language_code = message.data.get("language_code", "en_US")
|
|
151
|
+
language_code = language_code.lower().replace("_", "-") # no ~/.bash_profile here
|
|
152
|
+
set_default_lang(language_code)
|
|
153
|
+
update_mycroft_config({"lang": language_code}, bus=self.bus)
|
|
154
|
+
if message.data.get("display", False):
|
|
155
|
+
self.gui.show_status_animation(f"Language changed to {language_code}", True)
|
|
156
|
+
self.bus.emit(Message("system.configure.language.complete", {"lang": language_code}))
|
|
157
|
+
|
|
158
|
+
def handle_ssh_status(self, message):
|
|
159
|
+
self.bus.emit(message.response(data={"enabled": False}))
|
|
160
|
+
|
|
161
|
+
def handle_ssh_change(self, message):
|
|
162
|
+
LOG.warning(f"{message.msg_type}: a browser has no SSH server")
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ovos-phal-plugin-browser
|
|
3
|
+
Version: 0.1.0a1
|
|
4
|
+
Summary: OpenVoiceOS PHAL plugin: the browser tab as the device (volume, location, power, sensors, camera)
|
|
5
|
+
Author: Andreas Lorensen
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/emkay-voice/ovos-phal-plugin-browser
|
|
8
|
+
Project-URL: Issues, https://github.com/emkay-voice/ovos-phal-plugin-browser/issues
|
|
9
|
+
Project-URL: Emkay, https://github.com/emkay-voice/emkay
|
|
10
|
+
Keywords: ovos,openvoiceos,plugin,phal,browser,volume,geolocation,pyodide,emkay
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Environment :: WebAssembly :: Emscripten
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: ovos-plugin-manager>=0.0.26
|
|
19
|
+
Requires-Dist: ovos-utils>=0.0.38
|
|
20
|
+
Requires-Dist: ovos-bus-client>=0.0.8
|
|
21
|
+
Requires-Dist: ovos-config>=0.0.12
|
|
22
|
+
Requires-Dist: json-database>=0.7.0
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
# ovos-phal-plugin-browser
|
|
26
|
+
|
|
27
|
+
An [OpenVoiceOS](https://openvoiceos.org) PHAL plugin whose hardware is a
|
|
28
|
+
**browser tab**: volume, location, power, connectivity, sensors and the
|
|
29
|
+
camera, answered on the bus exactly as the device plugins answer them, with
|
|
30
|
+
the actual work done by the web page OVOS runs in.
|
|
31
|
+
|
|
32
|
+
It was made for [Emkay](https://github.com/emkay-voice/emkay), OpenVoiceOS in
|
|
33
|
+
the browser (Pyodide), and is what Emkay uses. Any host that runs OVOS in a
|
|
34
|
+
page can use it the same way.
|
|
35
|
+
|
|
36
|
+
## What it answers
|
|
37
|
+
|
|
38
|
+
| Bus messages | Behaves like | The page does |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `mycroft.volume.get/set/increase/decrease/mute/unmute/mute.toggle` | ovos-PHAL-plugin-alsa: `percent` 0..1, `{percent, muted}` answers and change reports, level kept in the plugin's settings | sets the gain of the one audio node everything plays through |
|
|
41
|
+
| `ovos.ipgeo.update` | ovos-phal-plugin-ipgeo: fills the *assistant* config layer (below the user layer, so a location the user set always wins) | asks the browser's geolocation (the user is asked first); OVOS' `get_reverse_geolocation` turns it into city, country and time zone. Until then, the browser's time zone |
|
|
42
|
+
| `system.reboot`, `system.shutdown`, `system.mycroft.service.restart`, `system.factory.reset`, `system.configure.language`, `system.ssh.*` | ovos-PHAL-plugin-system | reloads the page, blanks the screen until tapped, wipes the saved data; ssh is reported as not available |
|
|
43
|
+
| `ovos.PHAL.internet_check` | ovos-PHAL-plugin-connectivity-events | reports `navigator.onLine` and its changes |
|
|
44
|
+
| `ovos.phal.camera.ping/open/close/get` | ovos-PHAL-plugin-camera: `b64_frame` JPEG answers | opens the browser camera (the user is asked first) and takes a picture |
|
|
45
|
+
| `ovos.phal.sensor`, `ovos.phal.binary_sensor` (emitted) | ovos-PHAL-sensors | sends what the browser knows: battery, network, screen on and orientation, moving or still, how the phone lies, compass, storage, memory and CPU cores |
|
|
46
|
+
|
|
47
|
+
## How a host uses it
|
|
48
|
+
|
|
49
|
+
The plugin talks to the page through one callable, given when it is made:
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from ovos_phal_plugin_browser import BrowserPHAL
|
|
53
|
+
|
|
54
|
+
plugin = BrowserPHAL(bus=bus, config=config, post=send_to_page)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`post(change: dict)` gets what the page should do: `{"volume": 0.6, "muted":
|
|
58
|
+
false}`, or `{"request": "location" | "camera_check" | "camera_open" |
|
|
59
|
+
"camera_close" | "picture" | "reload" | "off" | "forget_welcome"}`. The page
|
|
60
|
+
answers through the plugin's methods: `on_position(lat, lon, error)`,
|
|
61
|
+
`on_picture(id, jpeg_b64, error)` and `on_page_event(event, data)` for
|
|
62
|
+
`"online"`, `"sensor"`, `"camera"` and `"picture"`.
|
|
63
|
+
|
|
64
|
+
Emkay's page side is [`web/device.js`](https://github.com/emkay-voice/emkay/blob/main/web/device.js),
|
|
65
|
+
and the wiring is in [`worker_main.py`](https://github.com/emkay-voice/emkay/blob/main/py/emkay_mobile/worker_main.py).
|
|
66
|
+
|
|
67
|
+
On an ordinary device, with real hardware, use the device plugins instead.
|
|
68
|
+
|
|
69
|
+
## Config
|
|
70
|
+
|
|
71
|
+
`PHAL.ovos-phal-plugin-browser` in `mycroft.conf`; nothing needs setting. The
|
|
72
|
+
volume is kept in `~/.config/OpenVoiceOS/ovos-phal-plugin-browser.json`.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Apache-2.0
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
ovos_phal_plugin_browser/__init__.py
|
|
5
|
+
ovos_phal_plugin_browser/device.py
|
|
6
|
+
ovos_phal_plugin_browser/system.py
|
|
7
|
+
ovos_phal_plugin_browser.egg-info/PKG-INFO
|
|
8
|
+
ovos_phal_plugin_browser.egg-info/SOURCES.txt
|
|
9
|
+
ovos_phal_plugin_browser.egg-info/dependency_links.txt
|
|
10
|
+
ovos_phal_plugin_browser.egg-info/entry_points.txt
|
|
11
|
+
ovos_phal_plugin_browser.egg-info/requires.txt
|
|
12
|
+
ovos_phal_plugin_browser.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ovos_phal_plugin_browser
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ovos-phal-plugin-browser"
|
|
7
|
+
version = "0.1.0a1"
|
|
8
|
+
description = "OpenVoiceOS PHAL plugin: the browser tab as the device (volume, location, power, sensors, camera)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = {text = "Apache-2.0"}
|
|
11
|
+
authors = [{name = "Andreas Lorensen"}]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["ovos", "openvoiceos", "plugin", "phal", "browser", "volume", "geolocation", "pyodide", "emkay"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"License :: OSI Approved :: Apache Software License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Environment :: WebAssembly :: Emscripten",
|
|
19
|
+
]
|
|
20
|
+
dependencies = [
|
|
21
|
+
"ovos-plugin-manager>=0.0.26",
|
|
22
|
+
"ovos-utils>=0.0.38",
|
|
23
|
+
"ovos-bus-client>=0.0.8",
|
|
24
|
+
"ovos-config>=0.0.12",
|
|
25
|
+
"json-database>=0.7.0",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/emkay-voice/ovos-phal-plugin-browser"
|
|
30
|
+
Issues = "https://github.com/emkay-voice/ovos-phal-plugin-browser/issues"
|
|
31
|
+
Emkay = "https://github.com/emkay-voice/emkay"
|
|
32
|
+
|
|
33
|
+
[project.entry-points."opm.phal"]
|
|
34
|
+
ovos-phal-plugin-browser = "ovos_phal_plugin_browser:BrowserPHAL"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
packages = ["ovos_phal_plugin_browser"]
|