homebridge-smartgrade 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.en.md +141 -0
- package/README.md +83 -2
- package/config.schema.json +130 -0
- package/dist/homebridge-ui/handlers.js +91 -0
- package/dist/homebridge-ui/handlers.js.map +1 -0
- package/dist/homebridge-ui/public/index.html +199 -0
- package/dist/homebridge-ui/server.js +29 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/src/api/client.js +293 -0
- package/dist/src/api/client.js.map +1 -0
- package/dist/src/api/errors.js +27 -0
- package/dist/src/api/errors.js.map +1 -0
- package/dist/src/api/index.js +4 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/api/jwt.js +46 -0
- package/dist/src/api/jwt.js.map +1 -0
- package/dist/src/api/types.js +2 -0
- package/dist/src/api/types.js.map +1 -0
- package/dist/src/deviceInfo.js +95 -0
- package/dist/src/deviceInfo.js.map +1 -0
- package/dist/src/eve.js +34 -0
- package/dist/src/eve.js.map +1 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/platform.js +204 -0
- package/dist/src/platform.js.map +1 -0
- package/dist/src/platformAccessory.js +176 -0
- package/dist/src/platformAccessory.js.map +1 -0
- package/dist/src/products.js +128 -0
- package/dist/src/products.js.map +1 -0
- package/dist/src/settings.js +9 -0
- package/dist/src/settings.js.map +1 -0
- package/package.json +62 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sobelman
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# homebridge-smartgrade
|
|
4
|
+
|
|
5
|
+
**Control SmartGrade Secure (IoTech Verticals / Dealor · דילאור) Wi‑Fi smart switches from Apple Home via Homebridge.**
|
|
6
|
+
|
|
7
|
+
**English** | [עברית](README.md)
|
|
8
|
+
|
|
9
|
+
[](https://github.com/sobelman/homebridge-smartgrade/actions/workflows/ci.yaml) [](LICENSE) [](https://homebridge.io) [](https://github.com/sobelman/ha-smartgrade)
|
|
10
|
+
|
|
11
|
+
<img src="images/smartgrade-product.jpg" alt="SmartGrade boiler switch" width="380">
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
> [!WARNING]
|
|
16
|
+
> This is an **unofficial**, community-built plugin. It is not affiliated with, endorsed or supported by IoTech Verticals or Dealor. The vendor cloud API is undocumented and may change at any time.
|
|
17
|
+
|
|
18
|
+
## What it does
|
|
19
|
+
|
|
20
|
+
SmartGrade Secure is the app for the cloud‑connected smart switches made by **IoTech Verticals** and sold in Israel by **Dealor** – best known for the glass‑panel **boiler (water heater) switch**. The devices only talk to the vendor cloud, so this plugin uses the same cloud as the app.
|
|
21
|
+
|
|
22
|
+
- 🔐 **Log in from the Homebridge UI** – enter your phone number, press **Send SMS**, type the code. No config.json editing.
|
|
23
|
+
- 🎛️ **Choose the HomeKit accessory type per device (or per relay)** – **Switch**, **Outlet** or **Valve** (generic valve or water faucet icon). Valve is suggested for boilers, Outlet for sockets.
|
|
24
|
+
- 🔀 **Multi‑relay devices** – each relay (`switch_1`…`switch_3`) becomes its own accessory, named after the relay names set in the app.
|
|
25
|
+
- ⚡ **Optional power readings** – power (W), current (A) and voltage (V) as read‑only Eve characteristics.
|
|
26
|
+
- 📋 **Device details in the settings screen** – model (English + Hebrew), MAC, firmware and pending update, online state, relays, max‑on time, signal strength, the **timers configured in the app** and the **next scheduled action** (all read‑only).
|
|
27
|
+
- 📴 Offline devices and an expired login show as **No Response** in Home instead of a wrong state.
|
|
28
|
+
|
|
29
|
+
The sibling **Home Assistant** integration lives at [sobelman/ha-smartgrade](https://github.com/sobelman/ha-smartgrade).
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
1. In the Homebridge UI open **Plugins**, search for **`homebridge-smartgrade`** and install it
|
|
34
|
+
(or `npm install -g homebridge-smartgrade`).
|
|
35
|
+
2. Open the plugin's **Settings**. Running it as a **child bridge** is recommended.
|
|
36
|
+
3. Log in (below), press **Save**, and restart Homebridge.
|
|
37
|
+
|
|
38
|
+
Requirements: Homebridge 1.8+ or 2.x, Node.js 20, 22 or 24, and a SmartGrade / Dealor account with at least one device.
|
|
39
|
+
|
|
40
|
+
## Logging in (SMS code)
|
|
41
|
+
|
|
42
|
+
The vendor has no username/password – the app logs in with a one‑time SMS code. The plugin's custom settings screen does the same:
|
|
43
|
+
|
|
44
|
+
1. Enter the mobile number registered in the Dealor app (`05XXXXXXXX`; `+972…` is accepted too) and press **Send SMS**.
|
|
45
|
+
2. Enter the code from the SMS and press **Log in**.
|
|
46
|
+
3. The settings screen saves the resulting **login token (JWT)** and your user id into the plugin config. Restart Homebridge (or just the child bridge).
|
|
47
|
+
|
|
48
|
+
The status badge at the top of the settings screen always shows whether you are logged in and how many days the token has left.
|
|
49
|
+
|
|
50
|
+
> ### ⚠️ **Monthly re‑login required**
|
|
51
|
+
> **The vendor's login token is valid for exactly 30 days and the cloud has no refresh endpoint.** When it expires the devices show **No Response** and the Homebridge log says so. About once a month, open the plugin settings, press **Send SMS**, enter the new code, save and restart. The settings screen and the log start warning **5 days before** expiry. This is a limitation of the vendor cloud, not of the plugin; the official app asks for a new SMS code too.
|
|
52
|
+
|
|
53
|
+
## Accessory type per device
|
|
54
|
+
|
|
55
|
+
Every relay is exposed as a **Switch** unless you choose otherwise. In the settings screen press **Load devices** and then **Add as …** to add a device with its suggested type, or edit the **Per‑device settings** list:
|
|
56
|
+
|
|
57
|
+
| Setting | Meaning |
|
|
58
|
+
|---|---|
|
|
59
|
+
| `id` | Device id (12 hex digits, shown in the device list). |
|
|
60
|
+
| `relay` | Optional. 1–3 to configure a single relay; empty = all relays of the device. A relay entry wins over a device entry. |
|
|
61
|
+
| `name` | HomeKit name. |
|
|
62
|
+
| `accessoryType` | `switch` (default), `outlet` or `valve`. |
|
|
63
|
+
| `valveType` | For valves: `generic` (default) or `faucet` (water faucet icon). |
|
|
64
|
+
| `hidden` | Do not expose this device/relay. |
|
|
65
|
+
|
|
66
|
+
| Type | HomeKit service | Characteristics |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| Switch | `Switch` | `On` |
|
|
69
|
+
| Outlet | `Outlet` | `On`, `OutletInUse` (from the power reading when available, otherwise follows `On`) |
|
|
70
|
+
| Valve | `Valve` (`GENERIC_VALVE` or `WATER_FAUCET`) | `Active`, `InUse`, `ValveType` |
|
|
71
|
+
|
|
72
|
+
Changing the type keeps the same accessory (the old service is replaced), so the room assignment survives.
|
|
73
|
+
|
|
74
|
+
Example `config.json` (normally written by the settings screen):
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"platform": "SmartGrade",
|
|
79
|
+
"name": "SmartGrade",
|
|
80
|
+
"pollInterval": 30,
|
|
81
|
+
"exposePower": false,
|
|
82
|
+
"devices": [
|
|
83
|
+
{ "id": "aabbccddeeff", "name": "Boiler", "accessoryType": "valve", "valveType": "generic" },
|
|
84
|
+
{ "id": "112233445566", "relay": 2, "accessoryType": "outlet" },
|
|
85
|
+
{ "id": "112233445566", "relay": 3, "hidden": true }
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`jwt` and `userId` are added by the login screen. Do not share them.
|
|
91
|
+
|
|
92
|
+
### Other options
|
|
93
|
+
|
|
94
|
+
| Option | Default | Meaning |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `pollInterval` | `30` | Seconds between state refreshes (min 15). After a command the state is re‑read after ~3 s. |
|
|
97
|
+
| `exposePower` | `false` | Adds read‑only Eve **Consumption (W)**, **Electric Current (A)** and **Voltage (V)** characteristics from the device's last reading (updated by the device about once a minute). Visible in Eve and similar apps, not in Apple Home. |
|
|
98
|
+
|
|
99
|
+
## Supported devices
|
|
100
|
+
|
|
101
|
+
| Products (product id) | Exposed as |
|
|
102
|
+
|---|---|
|
|
103
|
+
| Boiler switches (6, **8**) | Relay → Switch / Outlet / Valve (Valve suggested) |
|
|
104
|
+
| Sockets and plug adapters (2, 5, 16, 17) | Relay → Switch / Outlet / Valve (Outlet suggested) |
|
|
105
|
+
| Wi‑Fi switch (7), light switches 1–3 gangs (9–13), DIN rail switches (14, 15, 22) | One accessory per relay |
|
|
106
|
+
| Shutters (18, 19, 36) | Hidden by default; add them to the device list to expose their relays as plain switches (state mapping unverified) |
|
|
107
|
+
| AC panels, IR, gateway, power meter, sensors | Not exposed (no on/off relay) – still listed with details in the settings screen |
|
|
108
|
+
|
|
109
|
+
> **Only product 8 (Gewiss 3‑module boiler switch, single relay) has been tested on a live account.** Everything else follows the official app's models and is untested – reports and fixes are welcome.
|
|
110
|
+
|
|
111
|
+
## Timers
|
|
112
|
+
|
|
113
|
+
Timers created in the Dealor app are stored and run **in the vendor cloud**, so they keep working whether or not Homebridge is running. HomeKit has no way to represent them, so the plugin **does not change them**; the settings screen lists them (name, enabled, kind, days, on/off times or on/off minutes, date range) together with the next scheduled action.
|
|
114
|
+
|
|
115
|
+
## Not exposed
|
|
116
|
+
|
|
117
|
+
- **IP address and Wi‑Fi network (SSID)** – the vendor API does not return them.
|
|
118
|
+
- **Account details** (name, e‑mail, phone) – deliberately not shown.
|
|
119
|
+
- **Energy (kWh)** – the API's kWh history uses unverified units, so it is not exposed.
|
|
120
|
+
- **Live push (MQTT)** – the vendor broker ties the connection to the user id and would disconnect the phone app, so the plugin polls.
|
|
121
|
+
|
|
122
|
+
## Privacy and security
|
|
123
|
+
|
|
124
|
+
- The plugin talks only to `https://api.iotechv.com` (the vendor cloud), using the app‑level credentials that ship inside the official app plus your own login token.
|
|
125
|
+
- Your token is stored in Homebridge's `config.json`. Anyone with it can control your devices for up to 30 days – keep backups private.
|
|
126
|
+
- There is no automatic SMS forwarding or token renewal, by design.
|
|
127
|
+
|
|
128
|
+
## Development
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
npm install
|
|
132
|
+
npm run lint # eslint + type-check (including tests)
|
|
133
|
+
npm test # node:test with a mocked fetch – never touches the real cloud
|
|
134
|
+
npm run build # tsc -> dist/, copies the settings UI
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Layout: `src/api/` (cloud client, ported from the Home Assistant integration), `src/platform.ts` (discovery, polling), `src/platformAccessory.ts` (Switch / Outlet / Valve), `homebridge-ui/` (custom settings screen: `server.ts`, `handlers.ts`, `public/index.html`).
|
|
138
|
+
|
|
139
|
+
## Disclaimer
|
|
140
|
+
|
|
141
|
+
SmartGrade, IoTech Verticals and Dealor are trademarks of their respective owners. This project is provided as‑is under the [MIT license](LICENSE); use it at your own risk, especially with high‑power loads such as a water heater.
|
package/README.md
CHANGED
|
@@ -1,3 +1,84 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center" dir="rtl">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# homebridge-smartgrade
|
|
4
|
+
|
|
5
|
+
**שליטה במתגים החכמים של SmartGrade Secure (IoTech Verticals / דילאור) מתוך אפליקציית הבית של אפל, דרך Homebridge.**
|
|
6
|
+
|
|
7
|
+
[English](README.en.md) | **עברית**
|
|
8
|
+
|
|
9
|
+
<div dir="ltr" align="center">
|
|
10
|
+
|
|
11
|
+
[](https://github.com/sobelman/homebridge-smartgrade/actions/workflows/ci.yaml) [](LICENSE) [](https://homebridge.io) [](https://github.com/sobelman/ha-smartgrade)
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<img src="images/smartgrade-product.jpg" alt="מתג חכם לדוד של SmartGrade" width="380">
|
|
16
|
+
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
> [!WARNING]
|
|
20
|
+
> זהו פלאגין **לא‑רשמי** שנבנה על ידי הקהילה. הוא אינו קשור ל‑IoTech Verticals או לדילאור, ואינו נתמך או מאושר על ידן.
|
|
21
|
+
|
|
22
|
+
<div dir="rtl" align="right">
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## מה הפלאגין עושה
|
|
26
|
+
|
|
27
|
+
- 🔐 **התחברות מתוך ממשק Homebridge** – מזינים מספר טלפון, לוחצים **שלח SMS**, ומקלידים את הקוד. בלי לערוך את config.json.
|
|
28
|
+
- 🎛️ **בחירת סוג האביזר ב‑HomeKit לכל מכשיר (או לכל ממסר)** – **מתג (Switch)**, **שקע (Outlet)** או **ברז/מגוף (Valve)**. לדוד מומלץ Valve, לשקעים Outlet.
|
|
29
|
+
- 🔀 **מכשירים עם כמה ממסרים** – כל ממסר מופיע כאביזר נפרד, עם השם שהוגדר באפליקציה.
|
|
30
|
+
- ⚡ **קריאת חשמל (אופציונלי)** – הספק (W), זרם (A) ומתח (V) כמאפייני Eve לקריאה בלבד.
|
|
31
|
+
- 📋 **פרטי המכשיר במסך ההגדרות** – דגם (עברית ואנגלית), כתובת MAC, גרסת קושחה ועדכון ממתין, מחובר/מנותק, ממסרים, זמן הדלקה מקסימלי, עוצמת אות, **הטיימרים שהוגדרו באפליקציה** ו**הפעולה המתוזמנת הבאה** (הכל לקריאה בלבד).
|
|
32
|
+
- 📴 מכשיר מנותק או התחברות שפגה מוצגים כ"אין תגובה" באפליקציית הבית, ולא כמצב שגוי.
|
|
33
|
+
|
|
34
|
+
גרסת **Home Assistant**: [sobelman/ha-smartgrade](https://github.com/sobelman/ha-smartgrade).
|
|
35
|
+
|
|
36
|
+
## התקנה
|
|
37
|
+
|
|
38
|
+
1. בממשק Homebridge פותחים **Plugins**, מחפשים **`homebridge-smartgrade`** ומתקינים.
|
|
39
|
+
2. פותחים את **Settings** של הפלאגין (מומלץ להריץ כ‑child bridge).
|
|
40
|
+
3. מתחברים (ראו למטה), לוחצים **Save** ומפעילים מחדש את Homebridge.
|
|
41
|
+
|
|
42
|
+
## התחברות עם קוד SMS
|
|
43
|
+
|
|
44
|
+
1. מזינים את מספר הנייד הרשום באפליקציית דילאור (`05XXXXXXXX`) ולוחצים **שלח SMS**.
|
|
45
|
+
2. מזינים את הקוד שהתקבל ולוחצים **התחבר**.
|
|
46
|
+
3. מסך ההגדרות שומר את **טוקן ההתחברות (JWT)** ואת מזהה המשתמש בהגדרות הפלאגין. מפעילים מחדש את Homebridge.
|
|
47
|
+
|
|
48
|
+
> ### ⚠️ **נדרשת התחברות מחדש פעם בחודש**
|
|
49
|
+
> **הטוקן של היצרן תקף ל‑30 יום בדיוק, ואין בענן שלהם אפשרות לחדש אותו.** כשהוא פג, המכשירים מוצגים כ"אין תגובה" והלוג של Homebridge מודיע על כך. פעם בחודש בערך נכנסים להגדרות הפלאגין, לוחצים **שלח SMS**, מזינים את הקוד החדש, שומרים ומפעילים מחדש. מסך ההגדרות והלוג מתחילים להזהיר **5 ימים לפני** שהטוקן פג. זו מגבלה של הענן של היצרן – גם האפליקציה הרשמית מבקשת קוד SMS חדש.
|
|
50
|
+
|
|
51
|
+
## סוג אביזר לכל מכשיר
|
|
52
|
+
|
|
53
|
+
כברירת מחדל כל ממסר מופיע כ**מתג**. במסך ההגדרות לוחצים **טען מכשירים** ואז **Add as …** כדי להוסיף מכשיר עם הסוג המומלץ, או עורכים את רשימת **Per‑device settings**:
|
|
54
|
+
|
|
55
|
+
- `id` – מזהה המכשיר (12 תווים, מופיע ברשימת המכשירים).
|
|
56
|
+
- `relay` – אופציונלי: 1–3 לממסר בודד; ריק = כל הממסרים.
|
|
57
|
+
- `name` – השם ב‑HomeKit.
|
|
58
|
+
- `accessoryType` – `switch` (ברירת מחדל), `outlet` או `valve`.
|
|
59
|
+
- `valveType` – לברז: `generic` (מגוף כללי) או `faucet` (ברז מים).
|
|
60
|
+
- `hidden` – הסתרה מ‑HomeKit.
|
|
61
|
+
|
|
62
|
+
## מכשירים נתמכים
|
|
63
|
+
|
|
64
|
+
- מתגי דוד (6, **8**), שקעים ומתאמים (2, 5, 16, 17), מתג WIFI (7), מתגי תאורה 1–3 (9–13), מתגי פס דין (14, 15, 22) – אביזר לכל ממסר.
|
|
65
|
+
- תריסים (18, 19, 36) – מוסתרים כברירת מחדל; אפשר להוסיף אותם לרשימה (כמתגים פשוטים, לא נבדק).
|
|
66
|
+
- מזגנים, IR, גייטווי, מונה חשמל וחיישנים – לא מוצגים ב‑HomeKit (אין להם ממסר), אבל מופיעים עם פרטים במסך ההגדרות.
|
|
67
|
+
|
|
68
|
+
> **רק מוצר 8 (מתג חכם לדוד לגוויס 3 מקומות) נבדק בפועל על חשבון אמיתי.** כל השאר מבוססים על המודלים של האפליקציה הרשמית ולא נבדקו.
|
|
69
|
+
|
|
70
|
+
## טיימרים
|
|
71
|
+
|
|
72
|
+
הטיימרים שמגדירים באפליקציית דילאור נשמרים ורצים **בענן של היצרן**, ולכן ממשיכים לעבוד גם כש‑Homebridge כבוי. הפלאגין **לא משנה אותם** – רק מציג אותם במסך ההגדרות (שם, פעיל, סוג, ימים, שעות) יחד עם הפעולה המתוזמנת הבאה.
|
|
73
|
+
|
|
74
|
+
## מה לא נחשף
|
|
75
|
+
|
|
76
|
+
- **כתובת IP ושם הרשת האלחוטית (SSID)** – ה‑API של היצרן לא מחזיר אותם.
|
|
77
|
+
- **פרטי החשבון** (שם, אימייל, טלפון) – לא מוצגים בכוונה.
|
|
78
|
+
- **צריכת אנרגיה (kWh)** – היחידות לא מאומתות.
|
|
79
|
+
|
|
80
|
+
## הסתייגות
|
|
81
|
+
|
|
82
|
+
SmartGrade, IoTech Verticals ודילאור הם סימנים מסחריים של בעליהם. הפרויקט מסופק כמות שהוא תחת [רישיון MIT](LICENSE); השימוש באחריותכם, במיוחד עם עומסים גבוהים כמו דוד חשמל.
|
|
83
|
+
|
|
84
|
+
</div>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
{
|
|
2
|
+
"pluginAlias": "SmartGrade",
|
|
3
|
+
"pluginType": "platform",
|
|
4
|
+
"singular": true,
|
|
5
|
+
"customUi": true,
|
|
6
|
+
"customUiPath": "./dist/homebridge-ui",
|
|
7
|
+
"headerDisplay": "SmartGrade Secure / Dealor (דילאור) cloud smart switches. Log in with the SMS code using the form above. ⚠️ The vendor login lasts 30 days and cannot be refreshed: log in again here about once a month.",
|
|
8
|
+
"footerDisplay": "Each device (or a single relay of it) can be exposed to HomeKit as a Switch, an Outlet or a Valve. Valve suits a boiler (water heater).",
|
|
9
|
+
"schema": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"name": {
|
|
13
|
+
"title": "Name",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"default": "SmartGrade",
|
|
16
|
+
"required": true
|
|
17
|
+
},
|
|
18
|
+
"jwt": {
|
|
19
|
+
"title": "Login token (set by the login form above)",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"description": "Filled in automatically after the SMS login. Valid for 30 days. Do not share it."
|
|
22
|
+
},
|
|
23
|
+
"userId": {
|
|
24
|
+
"title": "User id (set by the login form above)",
|
|
25
|
+
"type": "string"
|
|
26
|
+
},
|
|
27
|
+
"mobile": {
|
|
28
|
+
"title": "Mobile number (used to prefill the next login)",
|
|
29
|
+
"type": "string",
|
|
30
|
+
"pattern": "^(05\\d{8})?$"
|
|
31
|
+
},
|
|
32
|
+
"pollInterval": {
|
|
33
|
+
"title": "Polling interval (seconds)",
|
|
34
|
+
"type": "integer",
|
|
35
|
+
"default": 30,
|
|
36
|
+
"minimum": 15,
|
|
37
|
+
"maximum": 3600
|
|
38
|
+
},
|
|
39
|
+
"exposePower": {
|
|
40
|
+
"title": "Show power / current / voltage (Eve app)",
|
|
41
|
+
"type": "boolean",
|
|
42
|
+
"default": false,
|
|
43
|
+
"description": "Adds read-only Eve characteristics (W, A, V) from the device's last power reading. Visible in the Eve app and other apps that show custom characteristics, not in Apple Home."
|
|
44
|
+
},
|
|
45
|
+
"devices": {
|
|
46
|
+
"title": "Per-device settings",
|
|
47
|
+
"type": "array",
|
|
48
|
+
"items": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"properties": {
|
|
51
|
+
"id": {
|
|
52
|
+
"title": "Device id",
|
|
53
|
+
"type": "string",
|
|
54
|
+
"required": true,
|
|
55
|
+
"description": "12 hex digits, shown in the device list above."
|
|
56
|
+
},
|
|
57
|
+
"relay": {
|
|
58
|
+
"title": "Relay (leave empty for all relays)",
|
|
59
|
+
"type": "integer",
|
|
60
|
+
"minimum": 1,
|
|
61
|
+
"maximum": 3
|
|
62
|
+
},
|
|
63
|
+
"name": {
|
|
64
|
+
"title": "HomeKit name",
|
|
65
|
+
"type": "string"
|
|
66
|
+
},
|
|
67
|
+
"accessoryType": {
|
|
68
|
+
"title": "HomeKit accessory type",
|
|
69
|
+
"type": "string",
|
|
70
|
+
"default": "switch",
|
|
71
|
+
"oneOf": [
|
|
72
|
+
{ "title": "Switch", "enum": ["switch"] },
|
|
73
|
+
{ "title": "Outlet", "enum": ["outlet"] },
|
|
74
|
+
{ "title": "Valve (suggested for boilers)", "enum": ["valve"] }
|
|
75
|
+
]
|
|
76
|
+
},
|
|
77
|
+
"valveType": {
|
|
78
|
+
"title": "Valve icon",
|
|
79
|
+
"type": "string",
|
|
80
|
+
"default": "generic",
|
|
81
|
+
"oneOf": [
|
|
82
|
+
{ "title": "Generic valve", "enum": ["generic"] },
|
|
83
|
+
{ "title": "Water faucet", "enum": ["faucet"] }
|
|
84
|
+
],
|
|
85
|
+
"condition": {
|
|
86
|
+
"functionBody": "return model.devices && model.devices[arrayIndices] && model.devices[arrayIndices].accessoryType === 'valve';"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"hidden": {
|
|
90
|
+
"title": "Hide from HomeKit",
|
|
91
|
+
"type": "boolean",
|
|
92
|
+
"default": false
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"layout": [
|
|
100
|
+
"name",
|
|
101
|
+
{
|
|
102
|
+
"type": "fieldset",
|
|
103
|
+
"title": "Devices",
|
|
104
|
+
"expandable": true,
|
|
105
|
+
"expanded": true,
|
|
106
|
+
"items": [
|
|
107
|
+
{
|
|
108
|
+
"key": "devices",
|
|
109
|
+
"type": "array",
|
|
110
|
+
"buttonText": "Add device",
|
|
111
|
+
"items": [
|
|
112
|
+
"devices[].id",
|
|
113
|
+
"devices[].relay",
|
|
114
|
+
"devices[].name",
|
|
115
|
+
"devices[].accessoryType",
|
|
116
|
+
"devices[].valveType",
|
|
117
|
+
"devices[].hidden"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
"type": "fieldset",
|
|
124
|
+
"title": "Advanced",
|
|
125
|
+
"expandable": true,
|
|
126
|
+
"expanded": false,
|
|
127
|
+
"items": ["pollInterval", "exposePower", "mobile", "userId", "jwt"]
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request handlers of the custom settings UI, kept separate from the
|
|
3
|
+
* HomebridgePluginUiServer wiring so they can be unit-tested with a mocked
|
|
4
|
+
* fetch. These are the only code paths that talk to the vendor cloud for the
|
|
5
|
+
* login, and only when the user presses the buttons in the Homebridge UI.
|
|
6
|
+
*/
|
|
7
|
+
import { SmartGradeApi, isValidMobile, normalizeMobile } from '../src/api/client.js';
|
|
8
|
+
import { SmartGradeAuthError, SmartGradeError } from '../src/api/errors.js';
|
|
9
|
+
import { tokenStatus } from '../src/api/jwt.js';
|
|
10
|
+
import { summarizeDevice } from '../src/deviceInfo.js';
|
|
11
|
+
/** Error with a message that is safe to show in the UI. */
|
|
12
|
+
export class UiError extends Error {
|
|
13
|
+
}
|
|
14
|
+
function friendly(err, fallback) {
|
|
15
|
+
if (err instanceof UiError) {
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
if (err instanceof SmartGradeAuthError) {
|
|
19
|
+
throw new UiError('The code was rejected or has expired. Request a new SMS and try again.');
|
|
20
|
+
}
|
|
21
|
+
if (err instanceof SmartGradeError) {
|
|
22
|
+
throw new UiError(`${fallback}: ${err.message}`);
|
|
23
|
+
}
|
|
24
|
+
throw new UiError(fallback);
|
|
25
|
+
}
|
|
26
|
+
export function createUiHandlers(fetchImpl) {
|
|
27
|
+
// One client for the whole login, so the SMS request and the code submit
|
|
28
|
+
// share the same app token, exactly like the official app.
|
|
29
|
+
const loginClient = new SmartGradeApi({ fetch: fetchImpl });
|
|
30
|
+
return {
|
|
31
|
+
status({ jwt }) {
|
|
32
|
+
return tokenStatus(jwt);
|
|
33
|
+
},
|
|
34
|
+
async sendSms({ mobile }) {
|
|
35
|
+
const normalized = normalizeMobile(mobile ?? '');
|
|
36
|
+
if (!isValidMobile(normalized)) {
|
|
37
|
+
throw new UiError('Enter an Israeli mobile number, e.g. 05XXXXXXXX.');
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
if (!(await loginClient.requestSms(normalized))) {
|
|
41
|
+
throw new UiError('The SmartGrade cloud did not accept this number. Is it the number registered in the Dealor app?');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
friendly(err, 'Could not request the SMS');
|
|
46
|
+
}
|
|
47
|
+
return { sent: true, mobile: normalized };
|
|
48
|
+
},
|
|
49
|
+
async submitCode({ code }) {
|
|
50
|
+
const clean = String(code ?? '').trim();
|
|
51
|
+
if (!/^\d{3,8}$/.test(clean)) {
|
|
52
|
+
throw new UiError('Enter the numeric code from the SMS.');
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const result = await loginClient.submitCode(clean);
|
|
56
|
+
return { jwt: result.jwt, userId: result.userId, status: tokenStatus(result.jwt) };
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
friendly(err, 'Login failed');
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
async devices({ jwt, userId }) {
|
|
63
|
+
if (!jwt) {
|
|
64
|
+
throw new UiError('Log in first.');
|
|
65
|
+
}
|
|
66
|
+
const client = new SmartGradeApi({ jwt, userId: userId ?? null, fetch: fetchImpl });
|
|
67
|
+
let devices;
|
|
68
|
+
try {
|
|
69
|
+
devices = await client.getAllDevices();
|
|
70
|
+
}
|
|
71
|
+
catch (err) {
|
|
72
|
+
if (err instanceof SmartGradeAuthError) {
|
|
73
|
+
throw new UiError('The saved login is no longer valid. Log in again with a new SMS code.');
|
|
74
|
+
}
|
|
75
|
+
friendly(err, 'Could not load devices');
|
|
76
|
+
}
|
|
77
|
+
// Read-only extras; a failure here never hides the device.
|
|
78
|
+
const summaries = await Promise.all([...devices.values()].map(async (device) => {
|
|
79
|
+
const [stats, timers, next, future] = await Promise.all([
|
|
80
|
+
client.getLastUsageStats(device.id).catch(() => null),
|
|
81
|
+
Array.isArray(device.timers) ? Promise.resolve(device.timers) : client.getTimers(device.id).catch(() => []),
|
|
82
|
+
client.getNextAction(device.id).catch(() => null),
|
|
83
|
+
client.getFutureActions(device.id).catch(() => []),
|
|
84
|
+
]);
|
|
85
|
+
return summarizeDevice(device, { stats, timers, next, future });
|
|
86
|
+
}));
|
|
87
|
+
return { devices: summaries };
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../homebridge-ui/handlers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAoB,MAAM,mBAAmB,CAAC;AAElE,OAAO,EAAE,eAAe,EAAsB,MAAM,sBAAsB,CAAC;AAE3E,2DAA2D;AAC3D,MAAM,OAAO,OAAQ,SAAQ,KAAK;CAAG;AASrC,SAAS,QAAQ,CAAC,GAAY,EAAE,QAAgB;IAC9C,IAAI,GAAG,YAAY,OAAO,EAAE,CAAC;QAC3B,MAAM,GAAG,CAAC;IACZ,CAAC;IACD,IAAI,GAAG,YAAY,mBAAmB,EAAE,CAAC;QACvC,MAAM,IAAI,OAAO,CAAC,wEAAwE,CAAC,CAAC;IAC9F,CAAC;IACD,IAAI,GAAG,YAAY,eAAe,EAAE,CAAC;QACnC,MAAM,IAAI,OAAO,CAAC,GAAG,QAAQ,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAqB;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