homebridge-tsvesync 1.0.0 → 1.0.2

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.
Files changed (99) hide show
  1. package/config.schema.json +77 -0
  2. package/dist/platform.d.ts +7 -1
  3. package/dist/platform.d.ts.map +1 -1
  4. package/dist/platform.js +69 -21
  5. package/dist/platform.js.map +1 -1
  6. package/dist/platformAccessory.d.ts +8 -15
  7. package/dist/platformAccessory.d.ts.map +1 -1
  8. package/dist/platformAccessory.js +82 -50
  9. package/dist/platformAccessory.js.map +1 -1
  10. package/package/LICENSE +21 -0
  11. package/package/README.md +227 -0
  12. package/package/api/vesync/VeSync.yaml +33 -0
  13. package/package/api/vesyncbulb/ESL100.yaml +74 -0
  14. package/package/api/vesyncbulb/ESL100CW.yaml +123 -0
  15. package/package/api/vesyncbulb/ESL100MC.yaml +169 -0
  16. package/package/api/vesyncbulb/XYD0001.yaml +193 -0
  17. package/package/api/vesyncfan/Classic200S.yaml +280 -0
  18. package/package/api/vesyncfan/Classic300S.yaml +278 -0
  19. package/package/api/vesyncfan/Core200S.yaml +256 -0
  20. package/package/api/vesyncfan/Core300S.yaml +281 -0
  21. package/package/api/vesyncfan/Core400S.yaml +281 -0
  22. package/package/api/vesyncfan/Core600S.yaml +281 -0
  23. package/package/api/vesyncfan/Dual200S.yaml +278 -0
  24. package/package/api/vesyncfan/LAP-C201S-AUSR.yaml +256 -0
  25. package/package/api/vesyncfan/LAP-C202S-WUSR.yaml +256 -0
  26. package/package/api/vesyncfan/LAP-C301S-WAAA.yaml +281 -0
  27. package/package/api/vesyncfan/LAP-C301S-WJP.yaml +281 -0
  28. package/package/api/vesyncfan/LAP-C302S-WUSB.yaml +281 -0
  29. package/package/api/vesyncfan/LAP-C401S-WAAA.yaml +281 -0
  30. package/package/api/vesyncfan/LAP-C401S-WJP.yaml +281 -0
  31. package/package/api/vesyncfan/LAP-C401S-WUSR.yaml +281 -0
  32. package/package/api/vesyncfan/LAP-C601S-WEU.yaml +281 -0
  33. package/package/api/vesyncfan/LAP-C601S-WUS.yaml +281 -0
  34. package/package/api/vesyncfan/LAP-C601S-WUSR.yaml +281 -0
  35. package/package/api/vesyncfan/LAP-EL551S-AEUR.yaml +167 -0
  36. package/package/api/vesyncfan/LAP-EL551S-AUS.yaml +167 -0
  37. package/package/api/vesyncfan/LAP-EL551S-WEU.yaml +167 -0
  38. package/package/api/vesyncfan/LAP-EL551S-WUS.yaml +167 -0
  39. package/package/api/vesyncfan/LAP-V102S-AASR.yaml +167 -0
  40. package/package/api/vesyncfan/LAP-V102S-AUSR.yaml +167 -0
  41. package/package/api/vesyncfan/LAP-V102S-WEU.yaml +167 -0
  42. package/package/api/vesyncfan/LAP-V102S-WJP.yaml +167 -0
  43. package/package/api/vesyncfan/LAP-V102S-WUS.yaml +167 -0
  44. package/package/api/vesyncfan/LAP-V201-AUSR.yaml +167 -0
  45. package/package/api/vesyncfan/LAP-V201S-AASR.yaml +167 -0
  46. package/package/api/vesyncfan/LAP-V201S-AEUR.yaml +167 -0
  47. package/package/api/vesyncfan/LAP-V201S-AUSR.yaml +167 -0
  48. package/package/api/vesyncfan/LAP-V201S-WEU.yaml +167 -0
  49. package/package/api/vesyncfan/LAP-V201S-WJP.yaml +167 -0
  50. package/package/api/vesyncfan/LAP-V201S-WUS.yaml +167 -0
  51. package/package/api/vesyncfan/LEH-S601S-WUS.yaml +303 -0
  52. package/package/api/vesyncfan/LEH-S601S-WUSR.yaml +82 -0
  53. package/package/api/vesyncfan/LTF-F422S-KEU.yaml +165 -0
  54. package/package/api/vesyncfan/LTF-F422S-WUS.yaml +165 -0
  55. package/package/api/vesyncfan/LTF-F422S-WUSR.yaml +167 -0
  56. package/package/api/vesyncfan/LTF-F422_WJP.yaml +165 -0
  57. package/package/api/vesyncfan/LUH-A601S-AUSW.yaml +82 -0
  58. package/package/api/vesyncfan/LUH-A601S-WUSB.yaml +305 -0
  59. package/package/api/vesyncfan/LUH-A602S-WEU.yaml +305 -0
  60. package/package/api/vesyncfan/LUH-A602S-WEUR.yaml +305 -0
  61. package/package/api/vesyncfan/LUH-A602S-WJP.yaml +305 -0
  62. package/package/api/vesyncfan/LUH-A602S-WUS.yaml +305 -0
  63. package/package/api/vesyncfan/LUH-A602S-WUSC.yaml +305 -0
  64. package/package/api/vesyncfan/LUH-A602S-WUSR.yaml +305 -0
  65. package/package/api/vesyncfan/LUH-D301S-WEU.yaml +305 -0
  66. package/package/api/vesyncfan/LUH-D301S-WJP.yaml +305 -0
  67. package/package/api/vesyncfan/LUH-D301S-WUSR.yaml +305 -0
  68. package/package/api/vesyncfan/LUH-M101S-WUS.yaml +278 -0
  69. package/package/api/vesyncfan/LUH-O451S-WEU.yaml +278 -0
  70. package/package/api/vesyncfan/LUH-O451S-WUS.yaml +278 -0
  71. package/package/api/vesyncfan/LUH-O451S-WUSR.yaml +305 -0
  72. package/package/api/vesyncfan/LUH-O601S-KUS.yaml +305 -0
  73. package/package/api/vesyncfan/LUH-O601S-WUS.yaml +305 -0
  74. package/package/api/vesyncfan/LV-PUR131S.yaml +108 -0
  75. package/package/api/vesyncfan/LV-RH131S.yaml +108 -0
  76. package/package/api/vesyncoutlet/ESO15-TB.yaml +124 -0
  77. package/package/api/vesyncoutlet/ESW01-EU.yaml +122 -0
  78. package/package/api/vesyncoutlet/ESW03-USA.yaml +122 -0
  79. package/package/api/vesyncoutlet/ESW15-USA.yaml +156 -0
  80. package/package/api/vesyncoutlet/wifi-switch-1.3.yaml +60 -0
  81. package/package/api/vesyncswitch/ESWD16.yaml +128 -0
  82. package/package/api/vesyncswitch/ESWL01.yaml +56 -0
  83. package/package/api/vesyncswitch/ESWL03.yaml +56 -0
  84. package/package/package.json +53 -0
  85. package/package/src/lib/helpers.ts +290 -0
  86. package/package/src/lib/vesync.ts +530 -0
  87. package/package/src/lib/vesyncBaseDevice.ts +114 -0
  88. package/package/src/lib/vesyncBulb.ts +252 -0
  89. package/package/src/lib/vesyncBulbImpl.ts +215 -0
  90. package/package/src/lib/vesyncFan.ts +447 -0
  91. package/package/src/lib/vesyncFanImpl.ts +848 -0
  92. package/package/src/lib/vesyncOutlet.ts +148 -0
  93. package/package/src/lib/vesyncOutletImpl.ts +284 -0
  94. package/package/src/lib/vesyncSwitch.ts +546 -0
  95. package/package/src/lib/vesyncSwitchImpl.ts +408 -0
  96. package/package.json +34 -10
  97. package/src/platform.ts +87 -22
  98. package/src/platformAccessory.ts +104 -51
  99. package/tsvesync-1.0.11.tgz +0 -0
@@ -1,6 +1,23 @@
1
1
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
2
2
  import { TSVESyncPlatform } from './platform';
3
- import { TSVESync, Device } from 'tsvesync';
3
+ import { VeSyncBaseDevice } from 'tsvesync/dist/src/lib/vesyncBaseDevice';
4
+
5
+ interface VeSyncDeviceWithPower extends VeSyncBaseDevice {
6
+ deviceStatus: string;
7
+ turnOn(): Promise<boolean>;
8
+ turnOff(): Promise<boolean>;
9
+ }
10
+
11
+ interface VeSyncDeviceWithBrightness extends VeSyncDeviceWithPower {
12
+ brightness: number;
13
+ setBrightness(value: number): Promise<boolean>;
14
+ }
15
+
16
+ interface VeSyncDeviceWithSpeed extends VeSyncDeviceWithPower {
17
+ speed: number;
18
+ maxSpeed: number;
19
+ setSpeed(value: number): Promise<boolean>;
20
+ }
4
21
 
5
22
  export class TSVESyncAccessory {
6
23
  private service!: Service;
@@ -8,51 +25,81 @@ export class TSVESyncAccessory {
8
25
  constructor(
9
26
  private readonly platform: TSVESyncPlatform,
10
27
  private readonly accessory: PlatformAccessory,
11
- private readonly client: TSVESync,
28
+ private readonly device: VeSyncBaseDevice,
12
29
  ) {
13
- // Get the device from context
14
- const device = accessory.context.device as Device;
15
-
16
30
  // set accessory information
17
31
  this.accessory.getService(this.platform.Service.AccessoryInformation)!
18
- .setCharacteristic(this.platform.Characteristic.Manufacturer, 'TSVESync')
19
- .setCharacteristic(this.platform.Characteristic.Model, device.model || 'Unknown')
20
- .setCharacteristic(this.platform.Characteristic.SerialNumber, device.id);
32
+ .setCharacteristic(this.platform.Characteristic.Manufacturer, 'VeSync')
33
+ .setCharacteristic(this.platform.Characteristic.Model, device.deviceType)
34
+ .setCharacteristic(this.platform.Characteristic.SerialNumber, device.cid);
21
35
 
22
36
  // Set up the appropriate service based on device type
23
- this.setupService(device);
37
+ this.setupService();
38
+ }
39
+
40
+ private setupService() {
41
+ const deviceType = this.device.deviceType;
42
+
43
+ if (deviceType.includes('BULB')) {
44
+ this.setupBulb();
45
+ } else if (deviceType.includes('FAN') || deviceType.includes('AIR')) {
46
+ this.setupFan();
47
+ } else {
48
+ this.setupSwitch();
49
+ }
24
50
  }
25
51
 
26
- private setupService(device: Device) {
27
- // Determine the appropriate service type based on device capabilities
28
- if (device.supportsBrightness) {
29
- // Set up as a lightbulb if it supports brightness
30
- this.service = this.accessory.getService(this.platform.Service.Lightbulb)
31
- || this.accessory.addService(this.platform.Service.Lightbulb);
52
+ private setupBulb() {
53
+ this.service = this.accessory.getService(this.platform.Service.Lightbulb)
54
+ || this.accessory.addService(this.platform.Service.Lightbulb);
32
55
 
33
- // Add brightness characteristic
56
+ // Add brightness characteristic if device supports it
57
+ const bulb = this.device as VeSyncDeviceWithBrightness;
58
+ if ('setBrightness' in bulb) {
34
59
  this.service.getCharacteristic(this.platform.Characteristic.Brightness)
35
60
  .onSet(this.setBrightness.bind(this))
36
61
  .onGet(this.getBrightness.bind(this));
37
- } else {
38
- // Set up as a switch for basic on/off functionality
39
- this.service = this.accessory.getService(this.platform.Service.Switch)
40
- || this.accessory.addService(this.platform.Service.Switch);
41
62
  }
42
63
 
43
- // Add on/off characteristic (common to both switch and lightbulb)
44
64
  this.service.getCharacteristic(this.platform.Characteristic.On)
45
65
  .onSet(this.setOn.bind(this))
46
66
  .onGet(this.getOn.bind(this));
47
67
  }
48
68
 
49
- /**
50
- * Handle "SET" requests from HomeKit for power state
51
- */
69
+ private setupFan() {
70
+ this.service = this.accessory.getService(this.platform.Service.Fan)
71
+ || this.accessory.addService(this.platform.Service.Fan);
72
+
73
+ this.service.getCharacteristic(this.platform.Characteristic.On)
74
+ .onSet(this.setOn.bind(this))
75
+ .onGet(this.getOn.bind(this));
76
+
77
+ const fan = this.device as VeSyncDeviceWithSpeed;
78
+ if ('setSpeed' in fan) {
79
+ this.service.getCharacteristic(this.platform.Characteristic.RotationSpeed)
80
+ .onSet(this.setFanSpeed.bind(this))
81
+ .onGet(this.getFanSpeed.bind(this));
82
+ }
83
+ }
84
+
85
+ private setupSwitch() {
86
+ this.service = this.accessory.getService(this.platform.Service.Switch)
87
+ || this.accessory.addService(this.platform.Service.Switch);
88
+
89
+ this.service.getCharacteristic(this.platform.Characteristic.On)
90
+ .onSet(this.setOn.bind(this))
91
+ .onGet(this.getOn.bind(this));
92
+ }
93
+
52
94
  async setOn(value: CharacteristicValue) {
53
95
  try {
54
- const device = this.accessory.context.device as Device;
55
- await this.client.setPowerState(device.id, value as boolean);
96
+ const device = this.device as VeSyncDeviceWithPower;
97
+ const newState = value as boolean;
98
+ if (newState) {
99
+ await device.turnOn();
100
+ } else {
101
+ await device.turnOff();
102
+ }
56
103
  this.platform.log.debug('Set power state ->', value);
57
104
  } catch (error) {
58
105
  this.platform.log.error('Failed to set power state:', error);
@@ -60,52 +107,58 @@ export class TSVESyncAccessory {
60
107
  }
61
108
  }
62
109
 
63
- /**
64
- * Handle "GET" requests from HomeKit for power state
65
- */
66
110
  async getOn(): Promise<CharacteristicValue> {
67
111
  try {
68
- const device = this.accessory.context.device as Device;
69
- const state = await this.client.getPowerState(device.id);
70
- this.platform.log.debug('Get power state ->', state);
71
- return state;
112
+ const device = this.device as VeSyncDeviceWithPower;
113
+ return device.deviceStatus === 'on';
72
114
  } catch (error) {
73
115
  this.platform.log.error('Failed to get power state:', error);
74
116
  throw error;
75
117
  }
76
118
  }
77
119
 
78
- /**
79
- * Handle "SET" requests from HomeKit for brightness
80
- */
81
120
  async setBrightness(value: CharacteristicValue) {
82
121
  try {
83
- const device = this.accessory.context.device as Device;
84
- if (device.supportsBrightness) {
85
- await this.client.setBrightness(device.id, value as number);
86
- this.platform.log.debug('Set brightness ->', value);
87
- }
122
+ const device = this.device as VeSyncDeviceWithBrightness;
123
+ await device.setBrightness(value as number);
124
+ this.platform.log.debug('Set brightness ->', value);
88
125
  } catch (error) {
89
126
  this.platform.log.error('Failed to set brightness:', error);
90
127
  throw error;
91
128
  }
92
129
  }
93
130
 
94
- /**
95
- * Handle "GET" requests from HomeKit for brightness
96
- */
97
131
  async getBrightness(): Promise<CharacteristicValue> {
98
132
  try {
99
- const device = this.accessory.context.device as Device;
100
- if (device.supportsBrightness) {
101
- const brightness = await this.client.getBrightness(device.id);
102
- this.platform.log.debug('Get brightness ->', brightness);
103
- return brightness;
104
- }
105
- return 100;
133
+ const device = this.device as VeSyncDeviceWithBrightness;
134
+ return device.brightness || 100;
106
135
  } catch (error) {
107
136
  this.platform.log.error('Failed to get brightness:', error);
108
137
  throw error;
109
138
  }
110
139
  }
140
+
141
+ async setFanSpeed(value: CharacteristicValue) {
142
+ try {
143
+ const device = this.device as VeSyncDeviceWithSpeed;
144
+ // Convert HomeKit 0-100 to device speed levels
145
+ const speed = Math.ceil((value as number) / (100 / device.maxSpeed));
146
+ await device.setSpeed(speed);
147
+ this.platform.log.debug('Set fan speed ->', speed);
148
+ } catch (error) {
149
+ this.platform.log.error('Failed to set fan speed:', error);
150
+ throw error;
151
+ }
152
+ }
153
+
154
+ async getFanSpeed(): Promise<CharacteristicValue> {
155
+ try {
156
+ const device = this.device as VeSyncDeviceWithSpeed;
157
+ // Convert device speed levels to HomeKit 0-100
158
+ return (device.speed || 0) * (100 / device.maxSpeed);
159
+ } catch (error) {
160
+ this.platform.log.error('Failed to get fan speed:', error);
161
+ throw error;
162
+ }
163
+ }
111
164
  }
Binary file