homebridge-zonetouch3 0.1.0 → 0.3.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/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # homebridge-zonetouch3
2
2
 
3
3
  A Homebridge plugin for the Polyaire **ZoneTouch 3**. Each configured zone
4
- shows up in HomeKit as a Switch.
4
+ shows up in HomeKit as a Fan with an adjustable speed percentage mapped to the
5
+ zone damper opening.
5
6
 
6
7
  ## Status: real, working protocol
7
8
 
@@ -12,12 +13,11 @@ the Home Assistant community (see the "ZoneTouch 3 by Polyaire" thread on
12
13
  community.home-assistant.io); this plugin ports that protocol directly.
13
14
 
14
15
  Supported:
15
- - Turning a zone on (to a configurable open %, default 100) or off
16
+ - Turning each zone on or off from its HomeKit fan control
17
+ - Setting each zone damper from 0% (closed) to 100% (fully open) using fan speed
16
18
  - Polling zone state and temperature every `pollIntervalSeconds` (default 30s)
17
19
 
18
- Not implemented yet (the protocol has no obvious blocker, just not wired
19
- up): exposing zone open-percentage as a HomeKit dimmer instead of a plain
20
- switch, and exposing the temperature sensor as a HomeKit accessory.
20
+ The temperature sensor is not exposed as a HomeKit accessory.
21
21
 
22
22
  ## Install
23
23
 
@@ -37,8 +37,8 @@ built-in `net` module).
37
37
  "port": 7030,
38
38
  "pollIntervalSeconds": 30,
39
39
  "zones": [
40
- { "id": 0, "name": "Living Room", "onPercent": 100 },
41
- { "id": 1, "name": "Bedroom", "onPercent": 80 }
40
+ { "id": 0, "name": "Living Room" },
41
+ { "id": 1, "name": "Bedroom" }
42
42
  ]
43
43
  }
44
44
  ]
@@ -51,8 +51,8 @@ built-in `net` module).
51
51
  doesn't respond, this is the first thing worth double-checking.
52
52
  - `zones[].id`: zone index starting at 0, in the same order they appear in
53
53
  the ZoneTouch app.
54
- - `zones[].onPercent`: how far open the zone damper goes when switched on
55
- in HomeKit (the app calls this separately from "on/off").
54
+ - Each zone's HomeKit fan speed sets the damper opening percentage. Turning a
55
+ zone off closes its damper; turning it on restores the last non-zero speed.
56
56
 
57
57
  ## A couple of protocol quirks worth knowing
58
58
 
@@ -66,6 +66,6 @@ built-in `net` module).
66
66
 
67
67
  - `index.js` — registers the platform with Homebridge.
68
68
  - `lib/platform.js` — reads config, creates one accessory per zone.
69
- - `lib/zoneAccessory.js` — exposes a zone as a HomeKit Switch.
69
+ - `lib/zoneAccessory.js` — exposes a zone as a HomeKit Fan with percentage speed.
70
70
  - `lib/zonetouchClient.js` — the TCP connection and the actual ZoneTouch
71
71
  3 binary protocol (message building, CRC16, response parsing).
@@ -34,12 +34,7 @@
34
34
  "type": "object",
35
35
  "properties": {
36
36
  "id": { "title": "Zone index (0-based)", "type": "integer" },
37
- "name": { "title": "Zone name", "type": "string" },
38
- "onPercent": {
39
- "title": "Open percentage when switched on",
40
- "type": "integer",
41
- "default": 100
42
- }
37
+ "name": { "title": "Zone name", "type": "string" }
43
38
  }
44
39
  }
45
40
  }
@@ -3,32 +3,81 @@ class ZoneAccessory {
3
3
  this.platform = platform;
4
4
  this.accessory = accessory;
5
5
  this.zoneConfig = zoneConfig;
6
+ const initialState = platform.client.getZoneState(zoneConfig.id);
7
+ this.lastNonZeroSpeed = initialState.isOn && initialState.percent > 0
8
+ ? initialState.percent
9
+ : 100;
6
10
  const { Service, Characteristic } = platform.api.hap;
7
11
 
12
+ const oldSwitchService = accessory.getService(Service.Switch);
13
+ if (oldSwitchService) accessory.removeService(oldSwitchService);
14
+ const oldWindowCovering = accessory.getService(Service.WindowCovering);
15
+ if (oldWindowCovering) accessory.removeService(oldWindowCovering);
16
+
17
+ accessory.displayName = zoneConfig.name;
8
18
  this.service =
9
- accessory.getService(Service.Switch) || accessory.addService(Service.Switch);
19
+ accessory.getService(Service.Fanv2) || accessory.addService(Service.Fanv2);
10
20
 
11
21
  this.service.setCharacteristic(Characteristic.Name, zoneConfig.name);
12
22
 
13
23
  this.service
14
- .getCharacteristic(Characteristic.On)
15
- .onGet(() => this._getOn())
16
- .onSet((value) => this._setOn(value));
24
+ .getCharacteristic(Characteristic.Active)
25
+ .onGet(() => this._getActive())
26
+ .onSet((value) => this._setActive(value));
27
+
28
+ this.service
29
+ .getCharacteristic(Characteristic.RotationSpeed)
30
+ .onGet(() => this._getSpeed())
31
+ .onSet((value) => this._setSpeed(value));
32
+
33
+ this.service
34
+ .getCharacteristic(Characteristic.CurrentFanState)
35
+ .onGet(() => this._getFanState());
17
36
 
18
- // Once client.js emits real zone updates, push them into HomeKit:
19
37
  platform.client.on('zoneUpdate', (update) => {
20
38
  if (update.zoneId === zoneConfig.id) {
21
- this.service.updateCharacteristic(Characteristic.On, update.isOn);
39
+ if (update.isOn && update.percent > 0) this.lastNonZeroSpeed = update.percent;
40
+ this.service.updateCharacteristic(Characteristic.Active, update.isOn
41
+ ? Characteristic.Active.ACTIVE
42
+ : Characteristic.Active.INACTIVE);
43
+ this.service.updateCharacteristic(Characteristic.RotationSpeed, update.isOn ? update.percent : 0);
44
+ this.service.updateCharacteristic(Characteristic.CurrentFanState, this._getFanState());
22
45
  }
23
46
  });
24
47
  }
25
48
 
26
- _getOn() {
27
- return this.platform.client.getZoneState(this.zoneConfig.id).isOn;
49
+ _getActive() {
50
+ const state = this.platform.client.getZoneState(this.zoneConfig.id);
51
+ return state.isOn
52
+ ? this.platform.api.hap.Characteristic.Active.ACTIVE
53
+ : this.platform.api.hap.Characteristic.Active.INACTIVE;
54
+ }
55
+
56
+ _getSpeed() {
57
+ const state = this.platform.client.getZoneState(this.zoneConfig.id);
58
+ return state.isOn ? state.percent : 0;
59
+ }
60
+
61
+ _getFanState() {
62
+ const { Characteristic } = this.platform.api.hap;
63
+ const state = this.platform.client.getZoneState(this.zoneConfig.id);
64
+ return state.isOn
65
+ ? Characteristic.CurrentFanState.BLOWING_AIR
66
+ : Characteristic.CurrentFanState.INACTIVE;
67
+ }
68
+
69
+ _setActive(value) {
70
+ const { Characteristic } = this.platform.api.hap;
71
+ const isActive = value === Characteristic.Active.ACTIVE;
72
+ const state = this.platform.client.getZoneState(this.zoneConfig.id);
73
+ const speed = state.isOn && state.percent > 0 ? state.percent : this.lastNonZeroSpeed;
74
+ this.platform.client.setZoneOn(this.zoneConfig.id, isActive, speed);
28
75
  }
29
76
 
30
- _setOn(value) {
31
- this.platform.client.setZoneOn(this.zoneConfig.id, value, this.zoneConfig.onPercent || 100);
77
+ _setSpeed(value) {
78
+ const speed = Math.max(0, Math.min(100, Math.round(value)));
79
+ if (speed > 0) this.lastNonZeroSpeed = speed;
80
+ this.platform.client.setZoneOn(this.zoneConfig.id, speed > 0, speed);
32
81
  }
33
82
  }
34
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-zonetouch3",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "description": "Homebridge plugin for Polyaire ZoneTouch 3 AC zone control",
5
5
  "repository": {
6
6
  "type": "git",