@toharush/homebridge-redalert 1.0.0
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/.github/workflows/build.yml +28 -0
- package/.github/workflows/publish.yml +25 -0
- package/LICENSE +176 -0
- package/README.md +74 -0
- package/config.schema.json +65 -0
- package/dist/RedAlertPlatform.d.ts +21 -0
- package/dist/RedAlertPlatform.d.ts.map +1 -0
- package/dist/RedAlertPlatform.js +104 -0
- package/dist/RedAlertPlatform.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/oref/alertHandler.d.ts +11 -0
- package/dist/oref/alertHandler.d.ts.map +1 -0
- package/dist/oref/alertHandler.js +33 -0
- package/dist/oref/alertHandler.js.map +1 -0
- package/dist/oref/orefClient.d.ts +15 -0
- package/dist/oref/orefClient.d.ts.map +1 -0
- package/dist/oref/orefClient.js +77 -0
- package/dist/oref/orefClient.js.map +1 -0
- package/dist/settings.d.ts +9 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/settings.js +12 -0
- package/dist/settings.js.map +1 -0
- package/dist/types.d.ts +36 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +55 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/configValidator.d.ts +4 -0
- package/dist/utils/configValidator.d.ts.map +1 -0
- package/dist/utils/configValidator.js +17 -0
- package/dist/utils/configValidator.js.map +1 -0
- package/dist/utils/debugLogger.d.ts +6 -0
- package/dist/utils/debugLogger.d.ts.map +1 -0
- package/dist/utils/debugLogger.js +19 -0
- package/dist/utils/debugLogger.js.map +1 -0
- package/eslint.config.js +42 -0
- package/nodemon.json +12 -0
- package/package.json +45 -0
- package/src/RedAlertPlatform.ts +128 -0
- package/src/index.ts +8 -0
- package/src/oref/alertHandler.spec.ts +174 -0
- package/src/oref/alertHandler.ts +34 -0
- package/src/oref/orefClient.ts +77 -0
- package/src/settings.ts +11 -0
- package/src/types.ts +73 -0
- package/src/utils/configValidator.spec.ts +46 -0
- package/src/utils/configValidator.ts +20 -0
- package/src/utils/debugLogger.spec.ts +50 -0
- package/src/utils/debugLogger.ts +18 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
name: Build & Test
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
node-version: [20, 22]
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v5
|
|
19
|
+
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v5
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
|
|
25
|
+
- run: npm install
|
|
26
|
+
- run: npm run lint
|
|
27
|
+
- run: npm run build
|
|
28
|
+
- run: npm test
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v5
|
|
13
|
+
|
|
14
|
+
- uses: actions/setup-node@v5
|
|
15
|
+
with:
|
|
16
|
+
node-version: 20
|
|
17
|
+
registry-url: https://registry.npmjs.org/
|
|
18
|
+
|
|
19
|
+
- run: npm install
|
|
20
|
+
- run: npm run lint
|
|
21
|
+
- run: npm run build
|
|
22
|
+
- run: npm test
|
|
23
|
+
- run: npm publish --access public
|
|
24
|
+
env:
|
|
25
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
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
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# homebridge-redalert
|
|
2
|
+
|
|
3
|
+
Homebridge plugin for Israeli Red Alert (Pikud HaOref) notifications via HomeKit motion sensor.
|
|
4
|
+
|
|
5
|
+
The plugin polls the official Pikud HaOref API directly — no Telegram, no middleman, no authentication required.
|
|
6
|
+
|
|
7
|
+
## Disclaimer
|
|
8
|
+
|
|
9
|
+
**חשוב מאוד לקרוא!**
|
|
10
|
+
|
|
11
|
+
התוסף איננו תוסף רשמי של פיקוד העורף או מערכת הבטחון.
|
|
12
|
+
התוסף משתמש ב-API של פיקוד העורף לקבלת התרעות ולכן יתכנו שיבושים.
|
|
13
|
+
בכל מקרה יש להמשיך להשתמש באמצעיים הרשמיים של מערכת הבטחון.
|
|
14
|
+
|
|
15
|
+
1. This plugin is not an official Home Front Command product.
|
|
16
|
+
2. The plugin uses the Pikud HaOref public API for alerts. There may be delays or disruptions.
|
|
17
|
+
3. Always use the official alert systems alongside this plugin.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Search for `redalert` in the Homebridge plugin search, or install manually:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
npm install -g homebridge-redalert
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Configuration
|
|
28
|
+
|
|
29
|
+
Configure via the Homebridge UI or manually in `config.json`:
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"platform": "RedAlert",
|
|
34
|
+
"cities": "תל אביב, חיפה",
|
|
35
|
+
"categories": ["rockets", "uav", "earthquake", "terror"],
|
|
36
|
+
"polling_interval": 1000,
|
|
37
|
+
"debug": false
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Options
|
|
42
|
+
|
|
43
|
+
| Option | Required | Default | Description |
|
|
44
|
+
|--------|----------|---------|-------------|
|
|
45
|
+
| `cities` | Yes | — | City names in Hebrew, comma-separated. Must match Pikud HaOref naming exactly. |
|
|
46
|
+
| `categories` | No | All | Alert types to monitor. If empty, all categories are enabled. |
|
|
47
|
+
| `polling_interval` | No | 1000 | How often to poll the API in milliseconds (500–5000). |
|
|
48
|
+
| `debug` | No | false | Enable extra debug logging. |
|
|
49
|
+
|
|
50
|
+
### Available Categories
|
|
51
|
+
|
|
52
|
+
| Key | Description |
|
|
53
|
+
|-----|-------------|
|
|
54
|
+
| `rockets` | Rockets & Missiles (ירי רקטות וטילים) |
|
|
55
|
+
| `uav` | UAV Intrusion (חדירת כלי טיס) |
|
|
56
|
+
| `nonconventional` | Non-conventional Threat |
|
|
57
|
+
| `warning` | Heads-up Notice (התראה מוקדמת) |
|
|
58
|
+
| `earthquake` | Earthquake (רעידת אדמה) |
|
|
59
|
+
| `cbrne` | Chemical/Bio/Nuclear |
|
|
60
|
+
| `terror` | Terrorist Infiltration (חדירת מחבלים) |
|
|
61
|
+
| `tsunami` | Tsunami (צונאמי) |
|
|
62
|
+
| `hazmat` | Hazardous Materials (חומרים מסוכנים) |
|
|
63
|
+
|
|
64
|
+
## How It Works
|
|
65
|
+
|
|
66
|
+
- The plugin creates a single **motion sensor** in HomeKit.
|
|
67
|
+
- It polls the Pikud HaOref API every second (configurable).
|
|
68
|
+
- When an alert matches your cities and selected categories, the motion sensor turns **ON**.
|
|
69
|
+
- When the alert clears from the API, the motion sensor turns **OFF**.
|
|
70
|
+
- You can create HomeKit automations based on the motion sensor (e.g. flash lights, play a sound, send a notification).
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
Apache-2.0
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "RedAlert",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"headerDisplay": "חשוב מאוד לקרוא את תנאי השימוש!\n\nהתוסף איננו תוסף רשמי של פיקוד העורף או מערכת הבטחון.\n\nהתוסף משתמש ב-API של פיקוד העורף לקבלת התרעות ולכן יתכנו שיבושים.\n\nבכל מקרה יש להמשיך להשתמש באמצעיים הרשמיים של מערכת הבטחון.\n\nDisclaimer:\n\n1. This plugin is not an official Home Front Command product.\n\n2. The plugin uses the Pikud HaOref public API for alerts. There may be delays or disruptions.\n\n3. Always use the official alert systems alongside this plugin.",
|
|
6
|
+
"schema": {
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"cities": {
|
|
10
|
+
"title": "Cities (separate by comma, written in Hebrew)",
|
|
11
|
+
"description": "City names must match Pikud HaOref naming exactly (in Hebrew)",
|
|
12
|
+
"type": "string",
|
|
13
|
+
"required": true,
|
|
14
|
+
"default": "אזור_פיקוד_העורף_בעברית"
|
|
15
|
+
},
|
|
16
|
+
"categories": {
|
|
17
|
+
"title": "Alert Categories",
|
|
18
|
+
"description": "Select which alert types to be notified about. If none selected, all categories are enabled.",
|
|
19
|
+
"type": "array",
|
|
20
|
+
"uniqueItems": true,
|
|
21
|
+
"items": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"enum": [
|
|
24
|
+
"rockets",
|
|
25
|
+
"uav",
|
|
26
|
+
"nonconventional",
|
|
27
|
+
"warning",
|
|
28
|
+
"earthquake",
|
|
29
|
+
"cbrne",
|
|
30
|
+
"terror",
|
|
31
|
+
"tsunami",
|
|
32
|
+
"hazmat"
|
|
33
|
+
],
|
|
34
|
+
"titleMap": {
|
|
35
|
+
"rockets": "Rockets & Missiles (ירי רקטות וטילים)",
|
|
36
|
+
"uav": "UAV Intrusion (חדירת כלי טיס)",
|
|
37
|
+
"nonconventional": "Non-conventional Threat",
|
|
38
|
+
"warning": "Heads-up Notice (התראה מוקדמת)",
|
|
39
|
+
"earthquake": "Earthquake (רעידת אדמה)",
|
|
40
|
+
"cbrne": "Chemical/Bio/Nuclear (איום כימי/ביולוגי/גרעיני)",
|
|
41
|
+
"terror": "Terrorist Infiltration (חדירת מחבלים)",
|
|
42
|
+
"tsunami": "Tsunami (צונאמי)",
|
|
43
|
+
"hazmat": "Hazardous Materials (חומרים מסוכנים)"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"polling_interval": {
|
|
48
|
+
"title": "Polling interval in milliseconds",
|
|
49
|
+
"description": "How often to check for new alerts. Default is 1000ms (1 second). Lower values are faster but use more bandwidth.",
|
|
50
|
+
"type": "number",
|
|
51
|
+
"required": false,
|
|
52
|
+
"default": 1000,
|
|
53
|
+
"minimum": 500,
|
|
54
|
+
"maximum": 5000
|
|
55
|
+
},
|
|
56
|
+
"debug": {
|
|
57
|
+
"title": "Enable Debug Logs",
|
|
58
|
+
"description": "When checked, the plugin will produce extra logs for debugging purposes",
|
|
59
|
+
"type": "boolean",
|
|
60
|
+
"default": false,
|
|
61
|
+
"required": false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig, Service, Characteristic } from 'homebridge';
|
|
2
|
+
export declare class RedAlertPlatform implements DynamicPlatformPlugin {
|
|
3
|
+
readonly config: PlatformConfig;
|
|
4
|
+
readonly api: API;
|
|
5
|
+
readonly Service: typeof Service;
|
|
6
|
+
readonly Characteristic: typeof Characteristic;
|
|
7
|
+
readonly accessories: PlatformAccessory[];
|
|
8
|
+
private readonly log;
|
|
9
|
+
private readonly cities;
|
|
10
|
+
private readonly pollingInterval;
|
|
11
|
+
private readonly allowedCategories;
|
|
12
|
+
private readonly accessoryUUID;
|
|
13
|
+
private accessory;
|
|
14
|
+
private orefClient;
|
|
15
|
+
private alertHandler;
|
|
16
|
+
constructor(log: Logger, config: PlatformConfig, api: API);
|
|
17
|
+
configureAccessory(accessory: PlatformAccessory): void;
|
|
18
|
+
discoverDevices(): void;
|
|
19
|
+
private startMonitoring;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=RedAlertPlatform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedAlertPlatform.d.ts","sourceRoot":"","sources":["../src/RedAlertPlatform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAS5H,qBAAa,gBAAiB,YAAW,qBAAqB;aAiB1C,MAAM,EAAE,cAAc;aACtB,GAAG,EAAE,GAAG;IAjB1B,SAAgB,OAAO,EAAE,OAAO,OAAO,CAAwB;IAC/D,SAAgB,cAAc,EAAE,OAAO,cAAc,CAA+B;IACpF,SAAgB,WAAW,EAAE,iBAAiB,EAAE,CAAM;IAEtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAc;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgB;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAc;IAChD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAEvC,OAAO,CAAC,SAAS,CAAkC;IACnD,OAAO,CAAC,UAAU,CAA2B;IAC7C,OAAO,CAAC,YAAY,CAA6B;gBAG/C,GAAG,EAAE,MAAM,EACK,MAAM,EAAE,cAAc,EACtB,GAAG,EAAE,GAAG;IA8B1B,kBAAkB,CAAC,SAAS,EAAE,iBAAiB;IAkB/C,eAAe;IAwBf,OAAO,CAAC,eAAe;CA4BxB"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.RedAlertPlatform = void 0;
|
|
7
|
+
const settings_1 = require("./settings");
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
const configValidator_1 = require("./utils/configValidator");
|
|
11
|
+
const debugLogger_1 = require("./utils/debugLogger");
|
|
12
|
+
const orefClient_1 = require("./oref/orefClient");
|
|
13
|
+
const alertHandler_1 = require("./oref/alertHandler");
|
|
14
|
+
class RedAlertPlatform {
|
|
15
|
+
constructor(log, config, api) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
this.api = api;
|
|
18
|
+
this.Service = this.api.hap.Service;
|
|
19
|
+
this.Characteristic = this.api.hap.Characteristic;
|
|
20
|
+
this.accessories = [];
|
|
21
|
+
this.cities = [];
|
|
22
|
+
this.accessory = null;
|
|
23
|
+
this.orefClient = null;
|
|
24
|
+
this.alertHandler = null;
|
|
25
|
+
this.pollingInterval = lodash_1.default.get(config, 'polling_interval', settings_1.DEFAULT_POLLING_INTERVAL);
|
|
26
|
+
this.log = (0, debugLogger_1.createDebugLogger)(log, lodash_1.default.get(config, 'debug', false));
|
|
27
|
+
this.accessoryUUID = this.api.hap.uuid.generate(settings_1.PLATFORM_NAME);
|
|
28
|
+
const selectedKeys = !lodash_1.default.isEmpty(config.categories)
|
|
29
|
+
? config.categories
|
|
30
|
+
: types_1.ALL_CATEGORY_KEYS;
|
|
31
|
+
this.allowedCategories = new Set(lodash_1.default.flatMap(selectedKeys, (key) => types_1.CATEGORY_MAP[key] || []));
|
|
32
|
+
process.on('unhandledRejection', (reason) => {
|
|
33
|
+
this.log.error(`${reason}`);
|
|
34
|
+
});
|
|
35
|
+
const validated = (0, configValidator_1.validateConfig)(config, this.log);
|
|
36
|
+
if (!validated) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.cities = (0, lodash_1.default)(validated.cities).split(',').map(lodash_1.default.trim).compact().value();
|
|
40
|
+
this.log.easyDebug(`Finished initializing platform: ${settings_1.PLATFORM_NAME}`);
|
|
41
|
+
this.log.info(`Monitoring ${this.cities.length} cities, ${this.allowedCategories.size} category IDs enabled`);
|
|
42
|
+
this.api.on('didFinishLaunching', () => {
|
|
43
|
+
this.log.easyDebug('Executed didFinishLaunching callback');
|
|
44
|
+
this.discoverDevices();
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
configureAccessory(accessory) {
|
|
48
|
+
try {
|
|
49
|
+
this.log.easyDebug(`Loading accessory from cache: ${accessory.displayName}`);
|
|
50
|
+
const service = accessory.getService('alerts');
|
|
51
|
+
if (service) {
|
|
52
|
+
service.setCharacteristic(this.Characteristic.MotionDetected, false);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
accessory.addService(this.api.hap.Service.MotionSensor, 'Red Alert', 'alerts');
|
|
56
|
+
}
|
|
57
|
+
this.accessories.push(accessory);
|
|
58
|
+
this.log.easyDebug('Accessory configured successfully');
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
this.log.error(`${error}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
discoverDevices() {
|
|
65
|
+
const existing = lodash_1.default.find(this.accessories, (acc) => acc.UUID === this.accessoryUUID);
|
|
66
|
+
if (existing) {
|
|
67
|
+
this.accessory = existing;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
this.accessory = new this.api.platformAccessory('Red Alert', this.accessoryUUID);
|
|
71
|
+
this.api.registerPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, [this.accessory]);
|
|
72
|
+
this.configureAccessory(this.accessory);
|
|
73
|
+
}
|
|
74
|
+
// Remove stale accessories (e.g. old per-city ones from previous versions)
|
|
75
|
+
const stale = lodash_1.default.filter(this.accessories, (acc) => acc.UUID !== this.accessoryUUID);
|
|
76
|
+
if (!lodash_1.default.isEmpty(stale)) {
|
|
77
|
+
this.log.info(`Removing ${stale.length} stale accessory(ies)`);
|
|
78
|
+
this.api.unregisterPlatformAccessories(settings_1.PLUGIN_NAME, settings_1.PLATFORM_NAME, stale);
|
|
79
|
+
this.accessories.length = 0;
|
|
80
|
+
if (this.accessory) {
|
|
81
|
+
this.accessories.push(this.accessory);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
this.startMonitoring();
|
|
85
|
+
}
|
|
86
|
+
startMonitoring() {
|
|
87
|
+
var _a;
|
|
88
|
+
const service = (_a = this.accessory) === null || _a === void 0 ? void 0 : _a.getService('alerts');
|
|
89
|
+
if (!service) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const motionChar = service.getCharacteristic(this.Characteristic.MotionDetected);
|
|
93
|
+
this.alertHandler = new alertHandler_1.AlertHandler(this.log, this.cities, this.allowedCategories, {
|
|
94
|
+
getMotionDetected: () => motionChar.value,
|
|
95
|
+
setMotionDetected: (on) => {
|
|
96
|
+
service.updateCharacteristic(this.Characteristic.MotionDetected, on);
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
this.orefClient = new orefClient_1.OrefClient(this.log, this.pollingInterval, (alerts) => this.alertHandler.handleAlerts(alerts));
|
|
100
|
+
this.orefClient.start();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
exports.RedAlertPlatform = RedAlertPlatform;
|
|
104
|
+
//# sourceMappingURL=RedAlertPlatform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedAlertPlatform.js","sourceRoot":"","sources":["../src/RedAlertPlatform.ts"],"names":[],"mappings":";;;;;;AACA,yCAAkF;AAClF,oDAAuB;AACvB,mCAA0D;AAC1D,6DAAyD;AACzD,qDAAqE;AACrE,kDAA+C;AAC/C,sDAAmD;AAEnD,MAAa,gBAAgB;IAe3B,YACE,GAAW,EACK,MAAsB,EACtB,GAAQ;QADR,WAAM,GAAN,MAAM,CAAgB;QACtB,QAAG,GAAH,GAAG,CAAK;QAjBV,YAAO,GAAmB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC;QAC/C,mBAAc,GAA0B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC;QACpE,gBAAW,GAAwB,EAAE,CAAC;QAGrC,WAAM,GAAa,EAAE,CAAC;QAK/B,cAAS,GAA6B,IAAI,CAAC;QAC3C,eAAU,GAAsB,IAAI,CAAC;QACrC,iBAAY,GAAwB,IAAI,CAAC;QAO/C,IAAI,CAAC,eAAe,GAAG,gBAAC,CAAC,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,mCAAwB,CAAC,CAAC;QACnF,IAAI,CAAC,GAAG,GAAG,IAAA,+BAAiB,EAAC,GAAG,EAAE,gBAAC,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,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BAAiB,EACtB;YACE,iBAAiB,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAuB;YAC3D,iBAAiB,EAAE,CAAC,EAAE,EAAE,EAAE;gBACxB,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YACvE,CAAC;SACF,CACF,CAAC;QAEF,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAC9B,IAAI,CAAC,GAAG,EACR,IAAI,CAAC,eAAe,EACpB,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,YAAa,CAAC,YAAY,CAAC,MAAM,CAAC,CACpD,CAAC;QAEF,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC;CACF;AAtHD,4CAsHC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;yBAKvB,KAAK,GAAG;AAAlB,kBAEE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const settings_1 = require("./settings");
|
|
3
|
+
const RedAlertPlatform_1 = require("./RedAlertPlatform");
|
|
4
|
+
module.exports = (api) => {
|
|
5
|
+
api.registerPlatform(settings_1.PLATFORM_NAME, RedAlertPlatform_1.RedAlertPlatform);
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,yCAA2C;AAC3C,yDAAsD;AAEtD,iBAAS,CAAC,GAAQ,EAAE,EAAE;IACpB,GAAG,CAAC,gBAAgB,CAAC,wBAAa,EAAE,mCAAgB,CAAC,CAAC;AACxD,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CachedService, OrefAlert } from '../types';
|
|
2
|
+
import { DebugLogger } from '../utils/debugLogger';
|
|
3
|
+
export declare class AlertHandler {
|
|
4
|
+
private readonly log;
|
|
5
|
+
private readonly allowedCategories;
|
|
6
|
+
private readonly sensor;
|
|
7
|
+
private readonly citySet;
|
|
8
|
+
constructor(log: DebugLogger, cities: string[], allowedCategories: Set<number>, sensor: CachedService);
|
|
9
|
+
handleAlerts(alerts: OrefAlert[]): void;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=alertHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alertHandler.d.ts","sourceRoot":"","sources":["../../src/oref/alertHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAgB,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,qBAAa,YAAY;IAIrB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAEpB,OAAO,CAAC,QAAQ,CAAC,iBAAiB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;gBAGnB,GAAG,EAAE,WAAW,EACjC,MAAM,EAAE,MAAM,EAAE,EACC,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,EAC9B,MAAM,EAAE,aAAa;IAKxC,YAAY,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI;CAiBxC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AlertHandler = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
class AlertHandler {
|
|
10
|
+
constructor(log, cities, allowedCategories, sensor) {
|
|
11
|
+
this.log = log;
|
|
12
|
+
this.allowedCategories = allowedCategories;
|
|
13
|
+
this.sensor = sensor;
|
|
14
|
+
this.citySet = new Set(cities);
|
|
15
|
+
}
|
|
16
|
+
handleAlerts(alerts) {
|
|
17
|
+
const hasActive = lodash_1.default.some(alerts, (alert) => alert.category !== types_1.OrefCategory.EventEnded
|
|
18
|
+
&& this.allowedCategories.has(alert.category)
|
|
19
|
+
&& this.citySet.has(alert.data));
|
|
20
|
+
if (hasActive) {
|
|
21
|
+
if (!this.sensor.getMotionDetected()) {
|
|
22
|
+
this.sensor.setMotionDetected(true);
|
|
23
|
+
this.log.info('ALERT: Red Alert triggered');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else if (this.sensor.getMotionDetected()) {
|
|
27
|
+
this.sensor.setMotionDetected(false);
|
|
28
|
+
this.log.info('Alert ended');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.AlertHandler = AlertHandler;
|
|
33
|
+
//# sourceMappingURL=alertHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alertHandler.js","sourceRoot":"","sources":["../../src/oref/alertHandler.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,oCAAkE;AAGlE,MAAa,YAAY;IAGvB,YACmB,GAAgB,EACjC,MAAgB,EACC,iBAA8B,EAC9B,MAAqB;QAHrB,QAAG,GAAH,GAAG,CAAa;QAEhB,sBAAiB,GAAjB,iBAAiB,CAAa;QAC9B,WAAM,GAAN,MAAM,CAAe;QAEtC,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAED,YAAY,CAAC,MAAmB;QAC9B,MAAM,SAAS,GAAG,gBAAC,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CACzC,KAAK,CAAC,QAAQ,KAAK,oBAAY,CAAC,UAAU;eACvC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC;eAC1C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAChC,CAAC;QAEF,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;gBACpC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;YAC9C,CAAC;QACH,CAAC;aAAM,IAAI,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC;YAC3C,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;YACrC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF;AA7BD,oCA6BC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { OrefAlert } from '../types';
|
|
2
|
+
import { DebugLogger } from '../utils/debugLogger';
|
|
3
|
+
export declare class OrefClient {
|
|
4
|
+
private readonly log;
|
|
5
|
+
private readonly pollingInterval;
|
|
6
|
+
private readonly onAlerts;
|
|
7
|
+
private polling;
|
|
8
|
+
private pollTimer;
|
|
9
|
+
constructor(log: DebugLogger, pollingInterval: number, onAlerts: (alerts: OrefAlert[]) => void);
|
|
10
|
+
start(): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
private poll;
|
|
13
|
+
private fetchAlerts;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=orefClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orefClient.d.ts","sourceRoot":"","sources":["../../src/oref/orefClient.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,qBAAa,UAAU;IAKnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,eAAe;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAN3B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAA8C;gBAG5C,GAAG,EAAE,WAAW,EAChB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,IAAI;IAG1D,KAAK;IAML,IAAI;IAQJ,OAAO,CAAC,IAAI;IAmBZ,OAAO,CAAC,WAAW;CA2BpB"}
|