homebridge-zonetouch3 0.2.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,8 +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 an adjustable Window Covering, with its position mapped
5
- to the zone damper percentage.
4
+ shows up in HomeKit as a Fan with an adjustable speed percentage mapped to the
5
+ zone damper opening.
6
6
 
7
7
  ## Status: real, working protocol
8
8
 
@@ -13,7 +13,8 @@ the Home Assistant community (see the "ZoneTouch 3 by Polyaire" thread on
13
13
  community.home-assistant.io); this plugin ports that protocol directly.
14
14
 
15
15
  Supported:
16
- - Setting each zone damper from 0% (closed) to 100% (fully open)
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
17
18
  - Polling zone state and temperature every `pollIntervalSeconds` (default 30s)
18
19
 
19
20
  The temperature sensor is not exposed as a HomeKit accessory.
@@ -50,7 +51,8 @@ built-in `net` module).
50
51
  doesn't respond, this is the first thing worth double-checking.
51
52
  - `zones[].id`: zone index starting at 0, in the same order they appear in
52
53
  the ZoneTouch app.
53
- - Each zone's HomeKit position control sets the damper opening percentage.
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.
54
56
 
55
57
  ## A couple of protocol quirks worth knowing
56
58
 
@@ -64,6 +66,6 @@ built-in `net` module).
64
66
 
65
67
  - `index.js` — registers the platform with Homebridge.
66
68
  - `lib/platform.js` — reads config, creates one accessory per zone.
67
- - `lib/zoneAccessory.js` — exposes a zone as a HomeKit Switch.
69
+ - `lib/zoneAccessory.js` — exposes a zone as a HomeKit Fan with percentage speed.
68
70
  - `lib/zonetouchClient.js` — the TCP connection and the actual ZoneTouch
69
71
  3 binary protocol (message building, CRC16, response parsing).
@@ -3,51 +3,81 @@ class ZoneAccessory {
3
3
  this.platform = platform;
4
4
  this.accessory = accessory;
5
5
  this.zoneConfig = zoneConfig;
6
- this.targetPosition = null;
6
+ const initialState = platform.client.getZoneState(zoneConfig.id);
7
+ this.lastNonZeroSpeed = initialState.isOn && initialState.percent > 0
8
+ ? initialState.percent
9
+ : 100;
7
10
  const { Service, Characteristic } = platform.api.hap;
8
11
 
9
12
  const oldSwitchService = accessory.getService(Service.Switch);
10
13
  if (oldSwitchService) accessory.removeService(oldSwitchService);
14
+ const oldWindowCovering = accessory.getService(Service.WindowCovering);
15
+ if (oldWindowCovering) accessory.removeService(oldWindowCovering);
11
16
 
12
17
  accessory.displayName = zoneConfig.name;
13
18
  this.service =
14
- accessory.getService(Service.WindowCovering) || accessory.addService(Service.WindowCovering);
19
+ accessory.getService(Service.Fanv2) || accessory.addService(Service.Fanv2);
15
20
 
16
21
  this.service.setCharacteristic(Characteristic.Name, zoneConfig.name);
17
22
 
18
23
  this.service
19
- .getCharacteristic(Characteristic.CurrentPosition)
20
- .onGet(() => this._getPosition());
24
+ .getCharacteristic(Characteristic.Active)
25
+ .onGet(() => this._getActive())
26
+ .onSet((value) => this._setActive(value));
21
27
 
22
28
  this.service
23
- .getCharacteristic(Characteristic.TargetPosition)
24
- .onGet(() => this._getTargetPosition())
25
- .onSet((value) => this._setPosition(value));
29
+ .getCharacteristic(Characteristic.RotationSpeed)
30
+ .onGet(() => this._getSpeed())
31
+ .onSet((value) => this._setSpeed(value));
26
32
 
27
33
  this.service
28
- .getCharacteristic(Characteristic.PositionState)
29
- .onGet(() => Characteristic.PositionState.STOPPED);
34
+ .getCharacteristic(Characteristic.CurrentFanState)
35
+ .onGet(() => this._getFanState());
30
36
 
31
37
  platform.client.on('zoneUpdate', (update) => {
32
38
  if (update.zoneId === zoneConfig.id) {
33
- const position = update.isOn ? update.percent : 0;
34
- this.service.updateCharacteristic(Characteristic.CurrentPosition, position);
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());
35
45
  }
36
46
  });
37
47
  }
38
48
 
39
- _getPosition() {
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() {
40
57
  const state = this.platform.client.getZoneState(this.zoneConfig.id);
41
58
  return state.isOn ? state.percent : 0;
42
59
  }
43
60
 
44
- _getTargetPosition() {
45
- return this.targetPosition ?? this._getPosition();
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);
46
75
  }
47
76
 
48
- _setPosition(value) {
49
- this.targetPosition = value;
50
- this.platform.client.setZoneOn(this.zoneConfig.id, value > 0, value);
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);
51
81
  }
52
82
  }
53
83
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "homebridge-zonetouch3",
3
- "version": "0.2.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",