homebridge-blocky-control 0.0.0-stage → 1.2.1
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.
- package/LICENSE +176 -0
- package/README.md +107 -2
- package/config.schema.json +146 -0
- package/dist/blockyClient.js +99 -0
- package/dist/blockyClient.js.map +1 -0
- package/dist/blockyController.js +253 -0
- package/dist/blockyController.js.map +1 -0
- package/dist/config.js +43 -0
- package/dist/config.js.map +1 -0
- package/dist/controls.js +49 -0
- package/dist/controls.js.map +1 -0
- package/dist/hapAccessory.js +127 -0
- package/dist/hapAccessory.js.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/matterAccessories.js +199 -0
- package/dist/matterAccessories.js.map +1 -0
- package/dist/matterDeviceTypes.js +22 -0
- package/dist/matterDeviceTypes.js.map +1 -0
- package/dist/platform.js +151 -0
- package/dist/platform.js.map +1 -0
- package/dist/settings.js +20 -0
- package/dist/settings.js.map +1 -0
- package/package.json +48 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
#
|
|
1
|
+
# homebridge-blocky-control
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A [Homebridge](https://homebridge.io) plugin that controls [blocky](https://0xerr0r.github.io/blocky/) DNS blocking. It works over HomeKit (HAP), Matter, or both.
|
|
4
|
+
|
|
5
|
+
It adds these controls:
|
|
6
|
+
|
|
7
|
+
| Control | Type | On / Open | Off / Closed |
|
|
8
|
+
| --- | --- | --- | --- |
|
|
9
|
+
| **Blocky** | Switch | Blocking is on | Blocking is off until you turn it back on |
|
|
10
|
+
| **Pause Blocky 5 Minutes** | Timer (valve) | Blocking is off for 5 minutes, with a countdown | Blocking turns back on now |
|
|
11
|
+
| **Pause Blocky 10 Minutes** | Timer (valve) | Blocking is off for 10 minutes, with a countdown | Blocking turns back on now |
|
|
12
|
+
| **Pause Blocky 1 Hour** | Timer (valve) | Blocking is off for 60 minutes, with a countdown | Blocking turns back on now |
|
|
13
|
+
|
|
14
|
+
HomeKit and Matter have no "timer" accessory. The closest is a valve, which carries a duration and shows a remaining-time countdown in the Home app.
|
|
15
|
+
So by default each pause is a generic Valve (HAP) or Water Valve (Matter) with a fixed duration. Set `pauseStyle` to `switch` to use plain switches instead.
|
|
16
|
+
|
|
17
|
+
> **Matter controllers:** controllers differ in how they handle the Water Valve type. Some may show it
|
|
18
|
+
> as a water valve (Alexa, for example, may ask for confirmation or a PIN to open one) or not
|
|
19
|
+
> support it at all. If pauses look wrong or don't appear, set `pauseStyle` to `switch`.
|
|
20
|
+
|
|
21
|
+
- You choose the pause durations (`pauseMinutes`). Use an empty list to get only the main switch.
|
|
22
|
+
- Only one pause can run at a time. Turning on another pause switch restarts the timer with its duration.
|
|
23
|
+
- When blocky's timer ends, the pause turns off and **Blocky** turns back on.
|
|
24
|
+
- The plugin polls blocky's status, so changes made elsewhere also show up: blocky's CLI or API, other clients, or a restart.
|
|
25
|
+
If something else started a timed disable, the plugin turns on the shortest pause that covers the time left.
|
|
26
|
+
- In HomeKit, all switches belong to one accessory. In Matter, each control is a separate accessory. Switches use the **On/Off Switch** type by default. Set `matterDeviceType` to `outlet` or `light` if your controller shows them as unsupported.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Homebridge 1.8+ for HAP. Matter needs Homebridge 2.x with Matter turned on for the bridge or child bridge.
|
|
31
|
+
- blocky's HTTP API must be reachable from Homebridge (`ports.http` in blocky's config).
|
|
32
|
+
|
|
33
|
+
## Configuration
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
{
|
|
37
|
+
"platform": "BlockyControl",
|
|
38
|
+
"name": "Blocky",
|
|
39
|
+
"url": "http://192.168.1.2:4000",
|
|
40
|
+
"pauseMinutes": [5, 10, 60],
|
|
41
|
+
"pauseStyle": "valve",
|
|
42
|
+
"groups": [],
|
|
43
|
+
"pollInterval": 15,
|
|
44
|
+
"timeout": 5
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
| Key | Default | Description |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `url` | *(required)* | Base URL of blocky's HTTP listener (`http://` or `https://`). Leave off `/api`. |
|
|
51
|
+
| `name` | `Blocky` | Name of the main switch. Pause switches are named `Pause <name> …`. |
|
|
52
|
+
| `pauseMinutes` | `[5, 10, 60]` | One pause control is created for each entry (1 to 1440). |
|
|
53
|
+
| `pauseStyle` | `valve` | `valve` (timer with countdown) or `switch`. |
|
|
54
|
+
| `groups` | all | Only disable these blocky groups (passed to blocky as `groups=`). |
|
|
55
|
+
| `pollInterval` | `15` | Seconds between status checks (5 to 3600). `0` turns polling off. |
|
|
56
|
+
| `timeout` | `5` | HTTP request timeout, in seconds (1 to 10). |
|
|
57
|
+
| `matterDeviceType` | `switch` | Matter only: `switch`, `outlet`, or `light`. Changing it re-creates the Matter accessories. |
|
|
58
|
+
|
|
59
|
+
### HAP vs Matter
|
|
60
|
+
|
|
61
|
+
The plugin publishes over whichever transports the bridge has turned on.
|
|
62
|
+
If you pair the same bridge to Apple Home over both HAP and Matter, every switch appears twice.
|
|
63
|
+
Use a child bridge with only the transport you want.
|
|
64
|
+
|
|
65
|
+
## Security
|
|
66
|
+
|
|
67
|
+
**Anyone who can control your Home can turn DNS blocking off.** That includes every person you've
|
|
68
|
+
added to the Home in Apple Home (or every user and admin on a Matter fabric), Siri, and automations.
|
|
69
|
+
With a home hub it also works away from home. The main **Blocky** switch disables blocking with no
|
|
70
|
+
time limit, so if you rely on blocky for content filtering (kids, guests), keep that in mind:
|
|
71
|
+
|
|
72
|
+
- Apple Home can't limit control of a single accessory: everyone you share the Home with can operate it
|
|
73
|
+
("Allow Editing" only covers changing the setup). Don't share the Home with people who shouldn't turn it off.
|
|
74
|
+
- Use `pauseMinutes` and avoid the main switch in shared rooms, so blocking always comes back on by itself.
|
|
75
|
+
- Run the plugin on its own child bridge, and pair that bridge only to the controllers that need it.
|
|
76
|
+
|
|
77
|
+
blocky's API has no login, so anyone on your network who can reach `ports.http` could do the same
|
|
78
|
+
thing with `curl`. This plugin widens that to everyone with access to your Home. Consider limiting
|
|
79
|
+
blocky's HTTP port to the Homebridge host with a firewall rule.
|
|
80
|
+
|
|
81
|
+
The plugin only talks to the configured blocky URL. It doesn't follow redirects, and it rejects
|
|
82
|
+
URLs containing a user name or password.
|
|
83
|
+
|
|
84
|
+
## blocky API used
|
|
85
|
+
|
|
86
|
+
- `GET /api/blocking/status`
|
|
87
|
+
- `GET /api/blocking/enable`
|
|
88
|
+
- `GET /api/blocking/disable?duration=<n>m[&groups=a,b]` (with no `duration`, blocking stays off until re-enabled)
|
|
89
|
+
|
|
90
|
+
## Development
|
|
91
|
+
|
|
92
|
+
```shell
|
|
93
|
+
npm install
|
|
94
|
+
npm test # build + unit tests against an in-process fake blocky
|
|
95
|
+
npm run fake-blocky # fake blocky API on http://127.0.0.1:4000
|
|
96
|
+
npm run watch # build, link, run Homebridge with test/hbConfig (HAP + Matter)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Code layout:
|
|
100
|
+
|
|
101
|
+
- `src/blockyClient.ts`: HTTP client for blocky's REST API
|
|
102
|
+
- `src/blockyController.ts`: state, polling, actions, and the "change" event. Shared by both transports.
|
|
103
|
+
- `src/config.ts`: startup checks for the URL and numeric settings
|
|
104
|
+
- `src/controls.ts`: definitions of the main switch and the pause switches
|
|
105
|
+
- `src/hapAccessory.ts`: HAP accessory with one `Switch` service per control
|
|
106
|
+
- `src/matterAccessories.ts`: one Matter on/off accessory per control
|
|
107
|
+
- `src/matterDeviceTypes.ts`: maps `matterDeviceType` to a Homebridge Matter device type
|
|
108
|
+
- `src/platform.ts`: picks the transports, restores the cache, removes stale accessories
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "BlockyControl",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"strictValidation": false,
|
|
6
|
+
"headerDisplay": "Control [blocky](https://0xerr0r.github.io/blocky/) DNS blocking from HomeKit or Matter. You get a switch that turns blocking on and off, plus one \"pause\" switch for each duration listed below.",
|
|
7
|
+
"schema": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"required": [
|
|
10
|
+
"name",
|
|
11
|
+
"url"
|
|
12
|
+
],
|
|
13
|
+
"properties": {
|
|
14
|
+
"name": {
|
|
15
|
+
"title": "Name",
|
|
16
|
+
"type": "string",
|
|
17
|
+
"default": "Blocky",
|
|
18
|
+
"description": "Name of the main switch. Pause switches are named \"Pause <Name> 5 Minutes\" and so on."
|
|
19
|
+
},
|
|
20
|
+
"url": {
|
|
21
|
+
"title": "Blocky URL",
|
|
22
|
+
"type": "string",
|
|
23
|
+
"format": "uri",
|
|
24
|
+
"placeholder": "http://192.168.1.2:4000",
|
|
25
|
+
"description": "Base URL of blocky's HTTP listener (ports.http in blocky's config). Leave off the /api path.",
|
|
26
|
+
"pattern": "^https?://"
|
|
27
|
+
},
|
|
28
|
+
"pauseMinutes": {
|
|
29
|
+
"title": "Pause durations (minutes)",
|
|
30
|
+
"type": "array",
|
|
31
|
+
"default": [
|
|
32
|
+
5,
|
|
33
|
+
10,
|
|
34
|
+
60
|
|
35
|
+
],
|
|
36
|
+
"description": "Each entry adds a switch that pauses blocking for that many minutes. Leave empty to show only the on/off switch.",
|
|
37
|
+
"items": {
|
|
38
|
+
"type": "integer",
|
|
39
|
+
"minimum": 1,
|
|
40
|
+
"maximum": 1440
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"pauseStyle": {
|
|
44
|
+
"title": "Pause control style",
|
|
45
|
+
"type": "string",
|
|
46
|
+
"default": "valve",
|
|
47
|
+
"oneOf": [
|
|
48
|
+
{
|
|
49
|
+
"title": "Timer (valve with countdown)",
|
|
50
|
+
"enum": [
|
|
51
|
+
"valve"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"title": "Switch",
|
|
56
|
+
"enum": [
|
|
57
|
+
"switch"
|
|
58
|
+
]
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"description": "Timer shows each pause as a valve with its duration and a live countdown in the Home app. Switch shows a plain on/off switch."
|
|
62
|
+
},
|
|
63
|
+
"groups": {
|
|
64
|
+
"title": "Blocking groups",
|
|
65
|
+
"type": "array",
|
|
66
|
+
"description": "Only disable these blocky groups (as named under blocking.denylists in blocky's config). Leave empty to disable all groups.",
|
|
67
|
+
"items": {
|
|
68
|
+
"type": "string"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"pollInterval": {
|
|
72
|
+
"title": "Poll interval (seconds)",
|
|
73
|
+
"type": "integer",
|
|
74
|
+
"default": 15,
|
|
75
|
+
"minimum": 0,
|
|
76
|
+
"description": "How often to check blocky's status, so changes made elsewhere show up. Set to 0 to turn polling off; otherwise at least 5.",
|
|
77
|
+
"maximum": 3600
|
|
78
|
+
},
|
|
79
|
+
"timeout": {
|
|
80
|
+
"title": "Request timeout (seconds)",
|
|
81
|
+
"type": "number",
|
|
82
|
+
"default": 5,
|
|
83
|
+
"minimum": 1,
|
|
84
|
+
"maximum": 10,
|
|
85
|
+
"description": "How long to wait for blocky to answer (1 to 10 seconds). HomeKit gives up on a switch after about 10 seconds."
|
|
86
|
+
},
|
|
87
|
+
"matterDeviceType": {
|
|
88
|
+
"title": "Matter device type",
|
|
89
|
+
"type": "string",
|
|
90
|
+
"default": "switch",
|
|
91
|
+
"oneOf": [
|
|
92
|
+
{
|
|
93
|
+
"title": "Switch (On/Off Switch)",
|
|
94
|
+
"enum": [
|
|
95
|
+
"switch"
|
|
96
|
+
]
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"title": "Outlet (On/Off Plug-in Unit)",
|
|
100
|
+
"enum": [
|
|
101
|
+
"outlet"
|
|
102
|
+
]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"title": "Light (On/Off Light)",
|
|
106
|
+
"enum": [
|
|
107
|
+
"light"
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
"description": "How the switches look to Matter controllers. Only applies when Matter is on for this bridge. If your controller doesn't support Switch, use Outlet. Changing this re-creates the Matter accessories."
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"layout": [
|
|
116
|
+
"name",
|
|
117
|
+
"url",
|
|
118
|
+
{
|
|
119
|
+
"key": "pauseMinutes",
|
|
120
|
+
"type": "array",
|
|
121
|
+
"buttonText": "Add duration",
|
|
122
|
+
"items": [
|
|
123
|
+
"pauseMinutes[]"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"pauseStyle",
|
|
127
|
+
{
|
|
128
|
+
"type": "fieldset",
|
|
129
|
+
"title": "Advanced",
|
|
130
|
+
"expandable": true,
|
|
131
|
+
"items": [
|
|
132
|
+
"matterDeviceType",
|
|
133
|
+
{
|
|
134
|
+
"key": "groups",
|
|
135
|
+
"type": "array",
|
|
136
|
+
"buttonText": "Add group",
|
|
137
|
+
"items": [
|
|
138
|
+
"groups[]"
|
|
139
|
+
]
|
|
140
|
+
},
|
|
141
|
+
"pollInterval",
|
|
142
|
+
"timeout"
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
]
|
|
146
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal client for blocky's REST API.
|
|
3
|
+
* https://0xerr0r.github.io/blocky/latest/rest-api/
|
|
4
|
+
*/
|
|
5
|
+
const MAX_RESPONSE_BYTES = 64 * 1024;
|
|
6
|
+
export class BlockyApiError extends Error {
|
|
7
|
+
status;
|
|
8
|
+
constructor(message, status) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.name = 'BlockyApiError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** Read the body as text, giving up once it passes MAX_RESPONSE_BYTES (blocky's responses are tiny). */
|
|
15
|
+
async function readLimited(response, path) {
|
|
16
|
+
const tooLarge = () => new BlockyApiError(`blocky's response to ${path} was unexpectedly large`, response.status);
|
|
17
|
+
if (Number(response.headers.get('content-length') ?? 0) > MAX_RESPONSE_BYTES) {
|
|
18
|
+
await response.body?.cancel();
|
|
19
|
+
throw tooLarge();
|
|
20
|
+
}
|
|
21
|
+
if (!response.body) {
|
|
22
|
+
return '';
|
|
23
|
+
}
|
|
24
|
+
const chunks = [];
|
|
25
|
+
let size = 0;
|
|
26
|
+
for await (const chunk of response.body) {
|
|
27
|
+
size += chunk.byteLength;
|
|
28
|
+
if (size > MAX_RESPONSE_BYTES) {
|
|
29
|
+
await response.body.cancel().catch(() => undefined);
|
|
30
|
+
throw tooLarge();
|
|
31
|
+
}
|
|
32
|
+
chunks.push(chunk);
|
|
33
|
+
}
|
|
34
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
35
|
+
}
|
|
36
|
+
export class BlockyClient {
|
|
37
|
+
options;
|
|
38
|
+
baseUrl;
|
|
39
|
+
constructor(options) {
|
|
40
|
+
this.options = options;
|
|
41
|
+
// tolerate a trailing slash or an explicit /api suffix in the config
|
|
42
|
+
this.baseUrl = options.url.trim().replace(/\/+$/, '').replace(/\/api$/, '');
|
|
43
|
+
}
|
|
44
|
+
async status() {
|
|
45
|
+
const body = await this.request('/api/blocking/status');
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = JSON.parse(body);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new BlockyApiError(`Unexpected status response from blocky: ${body.slice(0, 200)}`);
|
|
52
|
+
}
|
|
53
|
+
if (typeof parsed !== 'object' || parsed === null || typeof parsed.enabled !== 'boolean') {
|
|
54
|
+
throw new BlockyApiError(`Unexpected status response from blocky: ${body.slice(0, 200)}`);
|
|
55
|
+
}
|
|
56
|
+
return parsed;
|
|
57
|
+
}
|
|
58
|
+
async enable() {
|
|
59
|
+
await this.request('/api/blocking/enable');
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Disable blocking.
|
|
63
|
+
* @param minutes how long to disable for; omit (or 0) to disable until re-enabled
|
|
64
|
+
*/
|
|
65
|
+
async disable(minutes) {
|
|
66
|
+
const params = new URLSearchParams();
|
|
67
|
+
if (minutes && minutes > 0) {
|
|
68
|
+
params.set('duration', `${minutes}m`);
|
|
69
|
+
}
|
|
70
|
+
if (this.options.groups && this.options.groups.length > 0) {
|
|
71
|
+
params.set('groups', this.options.groups.join(','));
|
|
72
|
+
}
|
|
73
|
+
const query = params.toString();
|
|
74
|
+
await this.request(`/api/blocking/disable${query ? `?${query}` : ''}`);
|
|
75
|
+
}
|
|
76
|
+
async request(path) {
|
|
77
|
+
const url = `${this.baseUrl}${path}`;
|
|
78
|
+
let response;
|
|
79
|
+
try {
|
|
80
|
+
response = await fetch(url, {
|
|
81
|
+
method: 'GET',
|
|
82
|
+
headers: { Accept: 'application/json' },
|
|
83
|
+
// blocky never redirects; following one could send requests somewhere unexpected.
|
|
84
|
+
redirect: 'error',
|
|
85
|
+
signal: AbortSignal.timeout(this.options.timeoutMs),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
90
|
+
throw new BlockyApiError(`Could not reach blocky at ${url}: ${reason}`);
|
|
91
|
+
}
|
|
92
|
+
const body = await readLimited(response, path);
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new BlockyApiError(`blocky returned HTTP ${response.status} for ${path}: ${body.trim().slice(0, 200)}`, response.status);
|
|
95
|
+
}
|
|
96
|
+
return body;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=blockyClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockyClient.js","sourceRoot":"","sources":["../src/blockyClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAC;AAErC,MAAM,OAAO,cAAe,SAAQ,KAAK;IACM;IAA7C,YAAY,OAAe,EAAkB,MAAe;QAC1D,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,WAAM,GAAN,MAAM,CAAS;QAE1D,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED,wGAAwG;AACxG,KAAK,UAAU,WAAW,CAAC,QAAkB,EAAE,IAAY;IACzD,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,IAAI,cAAc,CAAC,wBAAwB,IAAI,yBAAyB,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClH,IAAI,MAAM,CAAC,QAAQ,CAAC,OAA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