homebridge-plugin-klares4 1.1.1-beta.5 → 1.1.1-beta.6
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/CHANGELOG.md +30 -6
- package/README.md +34 -34
- package/dist/accessories/cover-accessory.d.ts +8 -4
- package/dist/accessories/cover-accessory.d.ts.map +1 -1
- package/dist/accessories/cover-accessory.js +36 -37
- package/dist/accessories/cover-accessory.js.map +1 -1
- package/dist/accessories/light-accessory.d.ts +7 -3
- package/dist/accessories/light-accessory.d.ts.map +1 -1
- package/dist/accessories/light-accessory.js +27 -24
- package/dist/accessories/light-accessory.js.map +1 -1
- package/dist/accessories/scenario-accessory.d.ts +8 -4
- package/dist/accessories/scenario-accessory.d.ts.map +1 -1
- package/dist/accessories/scenario-accessory.js +23 -19
- package/dist/accessories/scenario-accessory.js.map +1 -1
- package/dist/accessories/sensor-accessory.d.ts +5 -1
- package/dist/accessories/sensor-accessory.d.ts.map +1 -1
- package/dist/accessories/sensor-accessory.js +49 -36
- package/dist/accessories/sensor-accessory.js.map +1 -1
- package/dist/accessories/thermostat-accessory.d.ts +5 -1
- package/dist/accessories/thermostat-accessory.d.ts.map +1 -1
- package/dist/accessories/thermostat-accessory.js +68 -55
- package/dist/accessories/thermostat-accessory.js.map +1 -1
- package/dist/accessories/zone-accessory.d.ts +5 -1
- package/dist/accessories/zone-accessory.d.ts.map +1 -1
- package/dist/accessories/zone-accessory.js +32 -32
- package/dist/accessories/zone-accessory.js.map +1 -1
- package/dist/mqtt-bridge.d.ts +6 -12
- package/dist/mqtt-bridge.d.ts.map +1 -1
- package/dist/mqtt-bridge.js +148 -104
- package/dist/mqtt-bridge.js.map +1 -1
- package/dist/platform.d.ts +26 -37
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +177 -132
- package/dist/platform.js.map +1 -1
- package/dist/types.d.ts +203 -21
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +78 -0
- package/dist/types.js.map +1 -1
- package/dist/websocket-client.d.ts +6 -5
- package/dist/websocket-client.d.ts.map +1 -1
- package/dist/websocket-client.js +257 -313
- package/dist/websocket-client.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.1.1-beta.6] - 2025-12-28
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **Strict TypeScript Refactoring**: Complete codebase rewrite for strict type compliance
|
|
15
|
+
- Replaced all `any` types with proper interfaces and discriminated unions
|
|
16
|
+
- Added explicit return types to all functions and methods
|
|
17
|
+
- Implemented type guards for MQTT command validation
|
|
18
|
+
- Improved error handling: clean messages without stack traces in production logs
|
|
19
|
+
- Removed all emojis from source code, comments, and log messages
|
|
20
|
+
|
|
21
|
+
### Technical
|
|
22
|
+
|
|
23
|
+
- New discriminated union types for device status (`KseniaLight`, `KseniaCover`, etc.)
|
|
24
|
+
- `AccessoryHandler` union type for typed accessory management
|
|
25
|
+
- Raw API response interfaces (`KseniaOutputStatusRaw`, `KseniaSensorStatusRaw`, etc.)
|
|
26
|
+
- Type guard functions (`isMqttLightCommand`, `isMqttCoverCommand`, etc.)
|
|
27
|
+
- Removed duplicate `MqttConfig` definition
|
|
28
|
+
|
|
29
|
+
### Documentation
|
|
30
|
+
|
|
31
|
+
- Removed all emojis from README.md, CHANGELOG.md, and CONTEXT.md
|
|
32
|
+
- Updated code style to match strict TypeScript standards
|
|
33
|
+
|
|
10
34
|
## [1.1.1-beta.5] - 2025-09-18
|
|
11
35
|
|
|
12
36
|
### Fixed
|
|
@@ -80,12 +104,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
80
104
|
|
|
81
105
|
- Complete plugin rewrite for Ksenia Lares4 systems
|
|
82
106
|
- Support for multiple device types:
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
-
|
|
87
|
-
-
|
|
88
|
-
-
|
|
107
|
+
- Security zones (contact sensors)
|
|
108
|
+
- Lights with on/off control
|
|
109
|
+
- Window coverings with position control
|
|
110
|
+
- Thermostats with temperature and mode control
|
|
111
|
+
- Environmental sensors (temperature, humidity, light)
|
|
112
|
+
- Scenario automation triggers
|
|
89
113
|
- Real-time WebSocket communication with Lares4 system
|
|
90
114
|
- Configurable device exclusion system
|
|
91
115
|
- Custom device naming support
|
package/README.md
CHANGED
|
@@ -5,25 +5,25 @@
|
|
|
5
5
|
|
|
6
6
|
Plugin completo per sistemi Ksenia Lares4 che integra zone di sicurezza, luci, tapparelle, termostati e sensori ambientali in un'unica soluzione per Homebridge.
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Caratteristiche
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
10
|
+
- **Zone di Sicurezza**: Sensori di contatto per porte e finestre
|
|
11
|
+
- **Controllo Luci**: Accensione/spegnimento di tutte le luci del sistema
|
|
12
|
+
- **Tapparelle Intelligenti**: Controllo percentuale con timing configurabile
|
|
13
|
+
- **Termostati**: Controllo temperatura e modalita riscaldamento/raffreddamento
|
|
14
|
+
- **Sensori Ambientali**: Temperatura, umidita e luminosita in tempo reale
|
|
15
|
+
- **Aggiornamenti Real-time**: Connessione WebSocket con riconnessione automatica
|
|
16
|
+
- **Configurazione UI**: Interfaccia grafica completa in Homebridge UI
|
|
17
|
+
- **Personalizzazione**: Nomi personalizzati ed esclusione selettiva di entita
|
|
18
|
+
- **Bridge MQTT**: Pubblicazione stati e ricezione comandi via MQTT (opzionale)
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Prerequisiti
|
|
21
21
|
|
|
22
22
|
- Homebridge >= 1.6.0
|
|
23
23
|
- Node.js >= 14.18.1
|
|
24
24
|
- Sistema Ksenia Lares4 con accesso WebSocket abilitato
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## Installazione
|
|
27
27
|
|
|
28
28
|
### Tramite Homebridge UI (Consigliato)
|
|
29
29
|
|
|
@@ -39,13 +39,13 @@ Plugin completo per sistemi Ksenia Lares4 che integra zone di sicurezza, luci, t
|
|
|
39
39
|
npm install -g homebridge-plugin-klares4
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
##
|
|
42
|
+
## Configurazione
|
|
43
43
|
|
|
44
44
|
### Configurazione Base
|
|
45
45
|
|
|
46
|
-
Il plugin
|
|
46
|
+
Il plugin puo essere configurato completamente tramite l'interfaccia grafica di Homebridge UI. I parametri obbligatori sono:
|
|
47
47
|
|
|
48
|
-
- **Nome Plugin**: Nome che
|
|
48
|
+
- **Nome Plugin**: Nome che apparira nei log
|
|
49
49
|
- **Indirizzo IP**: IP del sistema Ksenia Lares4
|
|
50
50
|
- **Sender ID**: Identificativo univoco per la connessione WebSocket
|
|
51
51
|
- **PIN Sistema**: PIN di accesso al sistema Lares4
|
|
@@ -103,7 +103,7 @@ Il plugin può essere configurato completamente tramite l'interfaccia grafica di
|
|
|
103
103
|
| `excludeSensors` | string[] | [] | Sensori da escludere |
|
|
104
104
|
| `customNames` | object | {} | Nomi personalizzati |
|
|
105
105
|
|
|
106
|
-
##
|
|
106
|
+
## Tipi di Accessori Supportati
|
|
107
107
|
|
|
108
108
|
### Zone di Sicurezza
|
|
109
109
|
|
|
@@ -121,27 +121,27 @@ Il plugin può essere configurato completamente tramite l'interfaccia grafica di
|
|
|
121
121
|
|
|
122
122
|
- **Tipo HomeKit**: Window Covering
|
|
123
123
|
- **Controllo**: Percentuale (0-100%)
|
|
124
|
-
- **Comandi**: Su/
|
|
124
|
+
- **Comandi**: Su/Giu/Stop
|
|
125
125
|
- **Timing**: Configurabile tramite `maxSeconds`
|
|
126
126
|
|
|
127
127
|
### Termostati
|
|
128
128
|
|
|
129
129
|
- **Tipo HomeKit**: Thermostat
|
|
130
|
-
- **
|
|
130
|
+
- **Modalita**: Off/Heat/Cool
|
|
131
131
|
- **Controllo**: Temperatura target
|
|
132
132
|
- **Sensori**: Temperatura corrente
|
|
133
133
|
|
|
134
134
|
### Sensori Ambientali
|
|
135
135
|
|
|
136
136
|
- **Tipi HomeKit**: Temperature/Humidity/Light Sensor
|
|
137
|
-
- **Dati**: Temperatura,
|
|
137
|
+
- **Dati**: Temperatura, Umidita, Luminosita
|
|
138
138
|
- **Aggiornamenti**: Real-time
|
|
139
139
|
|
|
140
|
-
##
|
|
140
|
+
## Bridge MQTT (Opzionale)
|
|
141
141
|
|
|
142
142
|
Il plugin include un bridge MQTT che permette di pubblicare gli stati degli accessori e ricevere comandi via MQTT.
|
|
143
143
|
|
|
144
|
-
###
|
|
144
|
+
### Configurazione MQTT
|
|
145
145
|
|
|
146
146
|
Abilita il bridge MQTT nella sezione "MQTT Bridge" della configurazione:
|
|
147
147
|
|
|
@@ -160,7 +160,7 @@ Abilita il bridge MQTT nella sezione "MQTT Bridge" della configurazione:
|
|
|
160
160
|
}
|
|
161
161
|
```
|
|
162
162
|
|
|
163
|
-
###
|
|
163
|
+
### Pubblicazione Stati
|
|
164
164
|
|
|
165
165
|
Gli stati degli accessori vengono pubblicati sui seguenti topic:
|
|
166
166
|
|
|
@@ -171,7 +171,7 @@ Gli stati degli accessori vengono pubblicati sui seguenti topic:
|
|
|
171
171
|
- **Zone**: `homebridge/klares4/zone/{id}/state`
|
|
172
172
|
- **Scenari**: `homebridge/klares4/scenario/{id}/state`
|
|
173
173
|
|
|
174
|
-
###
|
|
174
|
+
### Ricezione Comandi
|
|
175
175
|
|
|
176
176
|
Invia comandi agli accessori sui seguenti topic:
|
|
177
177
|
|
|
@@ -180,7 +180,7 @@ Invia comandi agli accessori sui seguenti topic:
|
|
|
180
180
|
- **Termostati**: `homebridge/klares4/thermostat/{id}/set`
|
|
181
181
|
- **Scenari**: `homebridge/klares4/scenario/{id}/set`
|
|
182
182
|
|
|
183
|
-
###
|
|
183
|
+
### Esempi di Utilizzo
|
|
184
184
|
|
|
185
185
|
#### Accendere una luce:
|
|
186
186
|
|
|
@@ -206,7 +206,7 @@ mosquitto_pub -h 192.168.1.100 -t "homebridge/klares4/thermostat/3/set" -m '{"ta
|
|
|
206
206
|
mosquitto_pub -h 192.168.1.100 -t "homebridge/klares4/scenario/4/set" -m '{"active": true}'
|
|
207
207
|
```
|
|
208
208
|
|
|
209
|
-
###
|
|
209
|
+
### Formato Payload Stati
|
|
210
210
|
|
|
211
211
|
```json
|
|
212
212
|
{
|
|
@@ -219,7 +219,7 @@ mosquitto_pub -h 192.168.1.100 -t "homebridge/klares4/scenario/4/set" -m '{"acti
|
|
|
219
219
|
}
|
|
220
220
|
```
|
|
221
221
|
|
|
222
|
-
##
|
|
222
|
+
## Risoluzione Problemi
|
|
223
223
|
|
|
224
224
|
### Connessione WebSocket
|
|
225
225
|
|
|
@@ -242,7 +242,7 @@ Abilita il debug logging per diagnosi dettagliate:
|
|
|
242
242
|
|
|
243
243
|
### Serial Number Warning
|
|
244
244
|
|
|
245
|
-
Il warning "Serial Number characteristic must have a length of more than 1 character"
|
|
245
|
+
Il warning "Serial Number characteristic must have a length of more than 1 character" e stato risolto nelle versioni recenti. Assicurati di avere l'ultima versione del plugin.
|
|
246
246
|
|
|
247
247
|
### Tapparelle non Responsive
|
|
248
248
|
|
|
@@ -252,16 +252,16 @@ Se le tapparelle non rispondono correttamente:
|
|
|
252
252
|
2. Controlla che i comandi up, down, alt siano supportati dal sistema
|
|
253
253
|
3. Testa prima con movimenti completi (0% o 100%)
|
|
254
254
|
|
|
255
|
-
##
|
|
255
|
+
## Monitoraggio
|
|
256
256
|
|
|
257
257
|
Il plugin fornisce log dettagliati per monitorare:
|
|
258
258
|
|
|
259
259
|
- Stato connessione WebSocket
|
|
260
260
|
- Comandi inviati e ricevuti
|
|
261
|
-
- Aggiornamenti
|
|
261
|
+
- Aggiornamenti entita
|
|
262
262
|
- Errori e riconnessioni
|
|
263
263
|
|
|
264
|
-
##
|
|
264
|
+
## Contributi
|
|
265
265
|
|
|
266
266
|
I contributi sono benvenuti! Per contribuire:
|
|
267
267
|
|
|
@@ -271,11 +271,11 @@ I contributi sono benvenuti! Per contribuire:
|
|
|
271
271
|
4. Push al branch
|
|
272
272
|
5. Apri una Pull Request
|
|
273
273
|
|
|
274
|
-
##
|
|
274
|
+
## Licenza
|
|
275
275
|
|
|
276
|
-
Questo progetto
|
|
276
|
+
Questo progetto e rilasciato sotto licenza MIT.
|
|
277
277
|
|
|
278
|
-
##
|
|
278
|
+
## Link Utili
|
|
279
279
|
|
|
280
280
|
- [Homebridge](https://homebridge.io/)
|
|
281
281
|
- [Homebridge UI](https://github.com/homebridge/homebridge-config-ui-x)
|
|
@@ -283,4 +283,4 @@ Questo progetto è rilasciato sotto licenza MIT.
|
|
|
283
283
|
|
|
284
284
|
---
|
|
285
285
|
|
|
286
|
-
**Nota**: Questo progetto non
|
|
286
|
+
**Nota**: Questo progetto non e affiliato con Ksenia Security S.p.A. E un progetto open source sviluppato dalla comunita.
|
|
@@ -1,21 +1,25 @@
|
|
|
1
1
|
import type { CharacteristicValue, PlatformAccessory } from 'homebridge';
|
|
2
2
|
import type { Lares4Platform } from '../platform';
|
|
3
|
-
import type {
|
|
3
|
+
import type { KseniaCover } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Cover Accessory Handler
|
|
6
|
+
* Handles HomeKit WindowCovering service for Ksenia Lares4 covers/shutters
|
|
7
|
+
*/
|
|
4
8
|
export declare class CoverAccessory {
|
|
5
9
|
private readonly platform;
|
|
6
10
|
private readonly accessory;
|
|
7
11
|
private service;
|
|
8
|
-
|
|
12
|
+
device: KseniaCover;
|
|
9
13
|
private targetPosition;
|
|
10
14
|
private currentPosition;
|
|
11
15
|
private positionState;
|
|
12
|
-
private maxSeconds;
|
|
16
|
+
private readonly maxSeconds;
|
|
13
17
|
constructor(platform: Lares4Platform, accessory: PlatformAccessory);
|
|
14
18
|
setTargetPosition(value: CharacteristicValue): Promise<void>;
|
|
15
19
|
getTargetPosition(): Promise<CharacteristicValue>;
|
|
16
20
|
getCurrentPosition(): Promise<CharacteristicValue>;
|
|
17
21
|
getPositionState(): Promise<CharacteristicValue>;
|
|
18
22
|
private simulateMovement;
|
|
19
|
-
updateStatus(newDevice:
|
|
23
|
+
updateStatus(newDevice: KseniaCover): void;
|
|
20
24
|
}
|
|
21
25
|
//# sourceMappingURL=cover-accessory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cover-accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/cover-accessory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"cover-accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/cover-accessory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,UAAU,CAAC;AAEzD;;;GAGG;AACH,qBAAa,cAAc;IASnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAT9B,OAAO,CAAC,OAAO,CAAU;IAClB,MAAM,EAAE,WAAW,CAAC;IAC3B,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,eAAe,CAAa;IACpC,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;gBAGf,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,iBAAiB;IAsDpC,iBAAiB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAoC5D,iBAAiB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIjD,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIlD,gBAAgB,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAI7D,OAAO,CAAC,gBAAgB;IA4CjB,YAAY,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;CAmCpD"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CoverAccessory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Cover Accessory Handler
|
|
6
|
+
* Handles HomeKit WindowCovering service for Ksenia Lares4 covers/shutters
|
|
7
|
+
*/
|
|
4
8
|
class CoverAccessory {
|
|
5
9
|
constructor(platform, accessory) {
|
|
6
10
|
this.platform = platform;
|
|
@@ -9,28 +13,31 @@ class CoverAccessory {
|
|
|
9
13
|
this.currentPosition = 0;
|
|
10
14
|
this.positionState = 2; // 2 = stopped
|
|
11
15
|
this.device = accessory.context.device;
|
|
12
|
-
this.currentPosition = this.device.status?.position
|
|
13
|
-
this.targetPosition = this.device.status?.position
|
|
14
|
-
this.maxSeconds = this.platform.config.maxSeconds
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
this.currentPosition = this.device.status?.position ?? 0;
|
|
17
|
+
this.targetPosition = this.device.status?.position ?? 0;
|
|
18
|
+
this.maxSeconds = this.platform.config.maxSeconds ?? 30;
|
|
19
|
+
const accessoryInfoService = this.accessory.getService(this.platform.Service.AccessoryInformation);
|
|
20
|
+
if (accessoryInfoService) {
|
|
21
|
+
accessoryInfoService
|
|
22
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Ksenia')
|
|
23
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'Lares4 Cover')
|
|
24
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.device.id)
|
|
25
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, '2.0.0');
|
|
26
|
+
}
|
|
27
|
+
this.service =
|
|
28
|
+
this.accessory.getService(this.platform.Service.WindowCovering) ??
|
|
29
|
+
this.accessory.addService(this.platform.Service.WindowCovering);
|
|
24
30
|
this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
this.service
|
|
32
|
+
.getCharacteristic(this.platform.Characteristic.CurrentPosition)
|
|
27
33
|
.onGet(this.getCurrentPosition.bind(this));
|
|
28
|
-
this.service
|
|
34
|
+
this.service
|
|
35
|
+
.getCharacteristic(this.platform.Characteristic.PositionState)
|
|
29
36
|
.onGet(this.getPositionState.bind(this));
|
|
30
|
-
this.service
|
|
37
|
+
this.service
|
|
38
|
+
.getCharacteristic(this.platform.Characteristic.TargetPosition)
|
|
31
39
|
.onSet(this.setTargetPosition.bind(this))
|
|
32
40
|
.onGet(this.getTargetPosition.bind(this));
|
|
33
|
-
// Inizializza i valori delle caratteristiche con valori sicuri
|
|
34
41
|
const safeCurrentPosition = isNaN(this.currentPosition) ? 0 : this.currentPosition;
|
|
35
42
|
const safeTargetPosition = isNaN(this.targetPosition) ? 0 : this.targetPosition;
|
|
36
43
|
this.service.setCharacteristic(this.platform.Characteristic.CurrentPosition, safeCurrentPosition);
|
|
@@ -40,26 +47,23 @@ class CoverAccessory {
|
|
|
40
47
|
async setTargetPosition(value) {
|
|
41
48
|
const targetPosition = value;
|
|
42
49
|
if (targetPosition === this.currentPosition) {
|
|
43
|
-
return;
|
|
50
|
+
return;
|
|
44
51
|
}
|
|
45
52
|
this.targetPosition = targetPosition;
|
|
46
53
|
try {
|
|
47
|
-
// Determina lo stato del movimento
|
|
48
54
|
if (targetPosition > this.currentPosition) {
|
|
49
55
|
this.positionState = 1; // Opening
|
|
50
56
|
}
|
|
51
57
|
else {
|
|
52
|
-
this.positionState = 0; // Closing
|
|
58
|
+
this.positionState = 0; // Closing
|
|
53
59
|
}
|
|
54
|
-
// Aggiorna lo stato del movimento
|
|
55
60
|
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.positionState);
|
|
56
61
|
await this.platform.wsClient?.moveCover(this.device.id, targetPosition);
|
|
57
|
-
this.platform.log.info(
|
|
58
|
-
// Simula il movimento graduale
|
|
62
|
+
this.platform.log.info(`${this.device.name}: Moving to ${targetPosition}%`);
|
|
59
63
|
this.simulateMovement(targetPosition);
|
|
60
64
|
}
|
|
61
65
|
catch (error) {
|
|
62
|
-
this.platform.log.error(
|
|
66
|
+
this.platform.log.error(`Cover control error ${this.device.name}:`, error instanceof Error ? error.message : String(error));
|
|
63
67
|
throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
64
68
|
}
|
|
65
69
|
}
|
|
@@ -76,40 +80,35 @@ class CoverAccessory {
|
|
|
76
80
|
const startPosition = this.currentPosition;
|
|
77
81
|
const distance = Math.abs(targetPosition - startPosition);
|
|
78
82
|
const direction = targetPosition > startPosition ? 1 : -1;
|
|
79
|
-
const stepSize = this.platform.config.coverStepSize
|
|
80
|
-
const totalTime = (distance / 100) * (this.maxSeconds * 1000);
|
|
81
|
-
const stepTime = totalTime / (distance / stepSize);
|
|
83
|
+
const stepSize = this.platform.config.coverStepSize ?? 5;
|
|
84
|
+
const totalTime = (distance / 100) * (this.maxSeconds * 1000);
|
|
85
|
+
const stepTime = totalTime / (distance / stepSize);
|
|
82
86
|
let currentStep = 0;
|
|
83
87
|
const totalSteps = Math.ceil(distance / stepSize);
|
|
84
88
|
const moveInterval = setInterval(() => {
|
|
85
89
|
currentStep++;
|
|
86
90
|
if (currentStep >= totalSteps) {
|
|
87
|
-
// Movimento completato
|
|
88
91
|
this.currentPosition = targetPosition;
|
|
89
92
|
this.positionState = 2; // Stopped
|
|
90
93
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
|
|
91
94
|
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.positionState);
|
|
92
|
-
this.platform.log.debug(
|
|
95
|
+
this.platform.log.debug(`${this.device.name}: Movement completed to ${targetPosition}%`);
|
|
93
96
|
clearInterval(moveInterval);
|
|
94
97
|
}
|
|
95
98
|
else {
|
|
96
|
-
|
|
97
|
-
this.currentPosition = Math.min(100, Math.max(0, startPosition + (direction * stepSize * currentStep)));
|
|
99
|
+
this.currentPosition = Math.min(100, Math.max(0, startPosition + direction * stepSize * currentStep));
|
|
98
100
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
|
|
99
101
|
}
|
|
100
102
|
}, stepTime);
|
|
101
103
|
}
|
|
102
|
-
// Metodo per aggiornare lo stato dall'esterno (aggiornamenti real-time)
|
|
103
104
|
updateStatus(newDevice) {
|
|
104
105
|
this.device = newDevice;
|
|
105
106
|
if (this.device.status?.position !== this.currentPosition) {
|
|
106
|
-
this.currentPosition = this.device.status?.position
|
|
107
|
-
this.targetPosition = this.device.status?.position
|
|
108
|
-
// Aggiorna le caratteristiche
|
|
107
|
+
this.currentPosition = this.device.status?.position ?? 0;
|
|
108
|
+
this.targetPosition = this.device.status?.position ?? 0;
|
|
109
109
|
this.service.updateCharacteristic(this.platform.Characteristic.CurrentPosition, this.currentPosition);
|
|
110
110
|
this.service.updateCharacteristic(this.platform.Characteristic.TargetPosition, this.targetPosition);
|
|
111
111
|
}
|
|
112
|
-
// Aggiorna lo stato del movimento
|
|
113
112
|
switch (this.device.status?.state) {
|
|
114
113
|
case 'opening':
|
|
115
114
|
this.positionState = 1;
|
|
@@ -121,7 +120,7 @@ class CoverAccessory {
|
|
|
121
120
|
this.positionState = 2; // stopped
|
|
122
121
|
}
|
|
123
122
|
this.service.updateCharacteristic(this.platform.Characteristic.PositionState, this.positionState);
|
|
124
|
-
this.platform.log.debug(
|
|
123
|
+
this.platform.log.debug(`Updated cover state ${this.device.name}: ${this.currentPosition}%`);
|
|
125
124
|
}
|
|
126
125
|
}
|
|
127
126
|
exports.CoverAccessory = CoverAccessory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cover-accessory.js","sourceRoot":"","sources":["../../src/accessories/cover-accessory.ts"],"names":[],"mappings":";;;AAIA,MAAa,cAAc;IAQvB,YACqB,QAAwB,EACxB,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAmB;QAPzC,mBAAc,GAAW,CAAC,CAAC;QAC3B,oBAAe,GAAW,CAAC,CAAC;QAC5B,kBAAa,GAAW,CAAC,CAAC,CAAC,cAAc;QAO7C,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"cover-accessory.js","sourceRoot":"","sources":["../../src/accessories/cover-accessory.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,cAAc;IAQvB,YACqB,QAAwB,EACxB,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAmB;QAPzC,mBAAc,GAAW,CAAC,CAAC;QAC3B,oBAAe,GAAW,CAAC,CAAC;QAC5B,kBAAa,GAAW,CAAC,CAAC,CAAC,cAAc;QAO7C,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,MAAqB,CAAC;QACtD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC;QACzD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,UAAU,GAAI,IAAI,CAAC,QAAQ,CAAC,MAAuB,CAAC,UAAU,IAAI,EAAE,CAAC;QAE1E,MAAM,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,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GAAG,CAAC,CAAC,CAAC,UAAU;QAC1C,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAC7B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,aAAa,EAC1C,IAAI,CAAC,aAAa,CACrB,CAAC;QAEF,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,uBAAuB,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC;IACjG,CAAC;CACJ;AA/LD,wCA+LC"}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import type { CharacteristicValue, PlatformAccessory } from 'homebridge';
|
|
2
2
|
import type { Lares4Platform } from '../platform';
|
|
3
|
-
import type {
|
|
3
|
+
import type { KseniaLight } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Light Accessory Handler
|
|
6
|
+
* Handles HomeKit Lightbulb service for Ksenia Lares4 lights
|
|
7
|
+
*/
|
|
4
8
|
export declare class LightAccessory {
|
|
5
9
|
private readonly platform;
|
|
6
10
|
private readonly accessory;
|
|
7
11
|
private service;
|
|
8
|
-
|
|
12
|
+
device: KseniaLight;
|
|
9
13
|
constructor(platform: Lares4Platform, accessory: PlatformAccessory);
|
|
10
14
|
setOn(value: CharacteristicValue): Promise<void>;
|
|
11
15
|
getOn(): Promise<CharacteristicValue>;
|
|
12
16
|
setBrightness(value: CharacteristicValue): Promise<void>;
|
|
13
17
|
getBrightness(): Promise<CharacteristicValue>;
|
|
14
|
-
updateStatus(newDevice:
|
|
18
|
+
updateStatus(newDevice: KseniaLight): void;
|
|
15
19
|
}
|
|
16
20
|
//# sourceMappingURL=light-accessory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"light-accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/light-accessory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"light-accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/light-accessory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAe,MAAM,UAAU,CAAC;AAEzD;;;GAGG;AACH,qBAAa,cAAc;IAKnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL9B,OAAO,CAAC,OAAO,CAAU;IAClB,MAAM,EAAE,WAAW,CAAC;gBAGN,QAAQ,EAAE,cAAc,EACxB,SAAS,EAAE,iBAAiB;IAkCpC,KAAK,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBhD,KAAK,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAIrC,aAAa,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BxD,aAAa,IAAI,OAAO,CAAC,mBAAmB,CAAC;IAInD,YAAY,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;CAmBpD"}
|
|
@@ -1,28 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LightAccessory = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Light Accessory Handler
|
|
6
|
+
* Handles HomeKit Lightbulb service for Ksenia Lares4 lights
|
|
7
|
+
*/
|
|
4
8
|
class LightAccessory {
|
|
5
9
|
constructor(platform, accessory) {
|
|
6
10
|
this.platform = platform;
|
|
7
11
|
this.accessory = accessory;
|
|
8
12
|
this.device = accessory.context.device;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const accessoryInfoService = this.accessory.getService(this.platform.Service.AccessoryInformation);
|
|
14
|
+
if (accessoryInfoService) {
|
|
15
|
+
accessoryInfoService
|
|
16
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'Ksenia')
|
|
17
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'Lares4 Light')
|
|
18
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, this.device.id)
|
|
19
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, '2.0.0');
|
|
20
|
+
}
|
|
21
|
+
this.service =
|
|
22
|
+
this.accessory.getService(this.platform.Service.Lightbulb) ??
|
|
23
|
+
this.accessory.addService(this.platform.Service.Lightbulb);
|
|
18
24
|
this.service.setCharacteristic(this.platform.Characteristic.Name, this.device.name);
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
this.service
|
|
26
|
+
.getCharacteristic(this.platform.Characteristic.On)
|
|
21
27
|
.onSet(this.setOn.bind(this))
|
|
22
28
|
.onGet(this.getOn.bind(this));
|
|
23
|
-
// Se la luce è dimmerabile, aggiungi la caratteristica Brightness
|
|
24
29
|
if (this.device.status?.dimmable) {
|
|
25
|
-
this.service
|
|
30
|
+
this.service
|
|
31
|
+
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
26
32
|
.onSet(this.setBrightness.bind(this))
|
|
27
33
|
.onGet(this.getBrightness.bind(this));
|
|
28
34
|
}
|
|
@@ -32,15 +38,15 @@ class LightAccessory {
|
|
|
32
38
|
try {
|
|
33
39
|
await this.platform.wsClient?.switchLight(this.device.id, on);
|
|
34
40
|
this.device.status.on = on;
|
|
35
|
-
this.platform.log.info(
|
|
41
|
+
this.platform.log.info(`${this.device.name}: ${on ? 'On' : 'Off'}`);
|
|
36
42
|
}
|
|
37
43
|
catch (error) {
|
|
38
|
-
this.platform.log.error(
|
|
44
|
+
this.platform.log.error(`Light control error ${this.device.name}:`, error instanceof Error ? error.message : String(error));
|
|
39
45
|
throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
async getOn() {
|
|
43
|
-
return this.device.status?.on
|
|
49
|
+
return this.device.status?.on ?? false;
|
|
44
50
|
}
|
|
45
51
|
async setBrightness(value) {
|
|
46
52
|
const brightness = value;
|
|
@@ -51,27 +57,24 @@ class LightAccessory {
|
|
|
51
57
|
await this.platform.wsClient?.dimLight(this.device.id, brightness);
|
|
52
58
|
this.device.status.brightness = brightness;
|
|
53
59
|
this.device.status.on = brightness > 0;
|
|
54
|
-
// Aggiorna anche la caratteristica On
|
|
55
60
|
this.service.updateCharacteristic(this.platform.Characteristic.On, this.device.status.on);
|
|
56
|
-
this.platform.log.info(
|
|
61
|
+
this.platform.log.info(`${this.device.name}: Brightness ${brightness}%`);
|
|
57
62
|
}
|
|
58
63
|
catch (error) {
|
|
59
|
-
this.platform.log.error(
|
|
64
|
+
this.platform.log.error(`Dimmer error ${this.device.name}:`, error instanceof Error ? error.message : String(error));
|
|
60
65
|
throw new this.platform.api.hap.HapStatusError(-70402 /* this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE */);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
async getBrightness() {
|
|
64
|
-
return this.device.status?.brightness
|
|
69
|
+
return this.device.status?.brightness ?? (this.device.status?.on ? 100 : 0);
|
|
65
70
|
}
|
|
66
|
-
// Metodo per aggiornare lo stato dall'esterno (aggiornamenti real-time)
|
|
67
71
|
updateStatus(newDevice) {
|
|
68
72
|
this.device = newDevice;
|
|
69
|
-
|
|
70
|
-
this.service.updateCharacteristic(this.platform.Characteristic.On, this.device.status?.on || false);
|
|
73
|
+
this.service.updateCharacteristic(this.platform.Characteristic.On, this.device.status?.on ?? false);
|
|
71
74
|
if (this.device.status?.dimmable && this.device.status?.brightness !== undefined) {
|
|
72
75
|
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.device.status.brightness);
|
|
73
76
|
}
|
|
74
|
-
this.platform.log.debug(
|
|
77
|
+
this.platform.log.debug(`Updated light state ${this.device.name}: ${this.device.status?.on ? 'ON' : 'OFF'}`);
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
exports.LightAccessory = LightAccessory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"light-accessory.js","sourceRoot":"","sources":["../../src/accessories/light-accessory.ts"],"names":[],"mappings":";;;AAIA,MAAa,cAAc;IAIvB,YACqB,QAAwB,EACxB,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAmB;QAE7C,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"light-accessory.js","sourceRoot":"","sources":["../../src/accessories/light-accessory.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACH,MAAa,cAAc;IAIvB,YACqB,QAAwB,EACxB,SAA4B;QAD5B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,cAAS,GAAT,SAAS,CAAmB;QAE7C,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,MAAqB,CAAC;QAEtD,MAAM,oBAAoB,GAAG,IAAI,CAAC,SAAS,CAAC,UAAU,CAClD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,oBAAoB,CAC7C,CAAC;QACF,IAAI,oBAAoB,EAAE,CAAC;YACvB,oBAAoB;iBACf,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,YAAY,EAAE,QAAQ,CAAC;iBACtE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC;iBACrE,iBAAiB,CAAC,IAAI,CAAC,QAAQ,CAAC,cAAc,C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AC,oBAAoB,CAC7B,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,EACvC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAChC,CAAC;QACN,CAAC;QAED,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CACnB,uBAAuB,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,CACtF,CAAC;IACN,CAAC;CACJ;AAlHD,wCAkHC"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
2
|
-
import { Lares4Platform } from '../platform';
|
|
3
|
-
import {
|
|
2
|
+
import type { Lares4Platform } from '../platform';
|
|
3
|
+
import type { KseniaScenario } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Scenario Accessory Handler
|
|
6
|
+
* Handles HomeKit Switch service for Ksenia Lares4 scenarios
|
|
7
|
+
*/
|
|
4
8
|
export declare class ScenarioAccessory {
|
|
5
9
|
private readonly platform;
|
|
6
10
|
private readonly accessory;
|
|
7
|
-
private readonly device;
|
|
8
11
|
private service;
|
|
9
|
-
|
|
12
|
+
readonly device: KseniaScenario;
|
|
13
|
+
constructor(platform: Lares4Platform, accessory: PlatformAccessory, device: KseniaScenario);
|
|
10
14
|
setOn(value: CharacteristicValue): Promise<void>;
|
|
11
15
|
getOn(): Promise<CharacteristicValue>;
|
|
12
16
|
}
|