homebridge-kasa-python 2.7.0-beta.2 → 2.7.0-beta.3
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/dist/devices/deviceManager.d.ts +3 -4
- package/dist/devices/deviceManager.js +7 -7
- package/dist/devices/deviceManager.js.map +1 -1
- package/dist/devices/homekitLightBulb.d.ts +10 -0
- package/dist/devices/homekitLightBulb.js +175 -3
- package/dist/devices/homekitLightBulb.js.map +1 -1
- package/dist/devices/homekitPlug.d.ts +9 -0
- package/dist/devices/homekitPlug.js +130 -0
- package/dist/devices/homekitPlug.js.map +1 -1
- package/dist/devices/homekitPowerStrip.d.ts +9 -0
- package/dist/devices/homekitPowerStrip.js +139 -0
- package/dist/devices/homekitPowerStrip.js.map +1 -1
- package/dist/devices/homekitSwitch.d.ts +10 -0
- package/dist/devices/homekitSwitch.js +143 -0
- package/dist/devices/homekitSwitch.js.map +1 -1
- package/dist/devices/index.d.ts +4 -14
- package/dist/devices/index.js +6 -213
- package/dist/devices/index.js.map +1 -1
- package/dist/devices/kasaDevices.d.ts +4 -4
- package/dist/python/kasaApi.py +0 -12
- package/package.json +1 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import HomekitDevice from './index.js';
|
|
2
|
+
import { deferAndCombine, getOrAddCharacteristic } from '../utils.js';
|
|
2
3
|
export default class HomeKitDevicePowerStrip extends HomekitDevice {
|
|
3
4
|
kasaDevice;
|
|
5
|
+
isUpdating = false;
|
|
6
|
+
previousKasaDevice;
|
|
7
|
+
getSysInfo;
|
|
4
8
|
constructor(platform, kasaDevice) {
|
|
5
9
|
super(platform, kasaDevice, 7 /* Categories.OUTLET */, 'OUTLET');
|
|
6
10
|
this.kasaDevice = kasaDevice;
|
|
@@ -9,6 +13,19 @@ export default class HomeKitDevicePowerStrip extends HomekitDevice {
|
|
|
9
13
|
this.log.debug(`Adding outlet service for child device: ${child.alias}`);
|
|
10
14
|
this.addOutletService(child, index);
|
|
11
15
|
});
|
|
16
|
+
this.getSysInfo = deferAndCombine(async (requestCount) => {
|
|
17
|
+
this.log.debug(`Executing deferred getSysInfo count: ${requestCount}`);
|
|
18
|
+
if (this.deviceManager) {
|
|
19
|
+
this.log.debug('Fetching new SysInfo from device manager');
|
|
20
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
21
|
+
this.kasaDevice.sys_info = await this.deviceManager.getSysInfo(this.deviceConfig);
|
|
22
|
+
this.log.debug('Updated SysInfo from device manager');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.log.warn('Device manager is not available');
|
|
26
|
+
}
|
|
27
|
+
}, platform.config.waitTimeUpdate);
|
|
28
|
+
this.startPolling();
|
|
12
29
|
}
|
|
13
30
|
addOutletService(child, index) {
|
|
14
31
|
const { Outlet } = this.platform.Service;
|
|
@@ -22,5 +39,127 @@ export default class HomeKitDevicePowerStrip extends HomekitDevice {
|
|
|
22
39
|
identify() {
|
|
23
40
|
this.log.info('identify');
|
|
24
41
|
}
|
|
42
|
+
addCharacteristic(service, characteristicType, child) {
|
|
43
|
+
const alias = child.alias;
|
|
44
|
+
this.log.debug(`Adding characteristic ${this.platform.getCharacteristicName(characteristicType)} for device: ${alias}`);
|
|
45
|
+
const characteristic = getOrAddCharacteristic(service, characteristicType);
|
|
46
|
+
characteristic.onGet(this.handleOnGet.bind(this, characteristicType, child));
|
|
47
|
+
if (characteristicType === this.platform.Characteristic.On) {
|
|
48
|
+
characteristic.onSet(this.handleOnSet.bind(this, service, characteristicType, child));
|
|
49
|
+
}
|
|
50
|
+
return service;
|
|
51
|
+
}
|
|
52
|
+
async handleOnGet(characteristicType, child) {
|
|
53
|
+
const characteristicName = this.platform.getCharacteristicName(characteristicType);
|
|
54
|
+
if (!characteristicName) {
|
|
55
|
+
throw new Error('Characteristic name is undefined');
|
|
56
|
+
}
|
|
57
|
+
this.log.debug(`Getting current value for characteristic ${characteristicName} for device: ${child.alias}`);
|
|
58
|
+
try {
|
|
59
|
+
const characteristicValue = this.getCharacteristicValue(characteristicType, child);
|
|
60
|
+
this.log.debug(`Current Value of ${characteristicName} is: ${characteristicValue} for ${child.alias}`);
|
|
61
|
+
return characteristicValue ?? false;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
this.log.error(`Error getting current value for characteristic ${characteristicName} for device: ${child.alias}:`, error);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
getCharacteristicValue(characteristicType, child) {
|
|
69
|
+
const characteristicMap = {
|
|
70
|
+
On: 'state',
|
|
71
|
+
OutletInUse: 'state',
|
|
72
|
+
};
|
|
73
|
+
const characteristicKey = characteristicMap[characteristicType.name];
|
|
74
|
+
const childDevice = this.kasaDevice.sys_info.children?.find(c => c.id === child.id);
|
|
75
|
+
const value = childDevice ? childDevice[characteristicKey] : undefined;
|
|
76
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || value === null) {
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
async handleOnSet(service, characteristicType, child, value) {
|
|
82
|
+
const characteristicName = this.platform.getCharacteristicName(characteristicType);
|
|
83
|
+
if (!characteristicName) {
|
|
84
|
+
throw new Error('Characteristic name is undefined');
|
|
85
|
+
}
|
|
86
|
+
this.log.info(`Setting ${characteristicName} to: ${value} for ${child.alias}`);
|
|
87
|
+
if (this.deviceManager) {
|
|
88
|
+
try {
|
|
89
|
+
this.isUpdating = true;
|
|
90
|
+
const characteristicMap = {
|
|
91
|
+
On: 'state',
|
|
92
|
+
};
|
|
93
|
+
const characteristicKey = characteristicMap[characteristicName];
|
|
94
|
+
if (!characteristicKey) {
|
|
95
|
+
throw new Error(`Characteristic key not found for ${characteristicName}`);
|
|
96
|
+
}
|
|
97
|
+
const childNumber = parseInt(child.id.slice(-1), 10);
|
|
98
|
+
await this.deviceManager.controlDevice(this.deviceConfig, characteristicKey, value, childNumber);
|
|
99
|
+
const kasaChild = this.kasaDevice.sys_info.children?.find(c => c.id === child.id);
|
|
100
|
+
if (kasaChild) {
|
|
101
|
+
kasaChild[characteristicKey] = value;
|
|
102
|
+
}
|
|
103
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
104
|
+
this.updateValue(service, service.getCharacteristic(characteristicType), value);
|
|
105
|
+
this.updateValue(service, service.getCharacteristic(this.platform.Characteristic.OutletInUse), value);
|
|
106
|
+
this.log.debug(`Successfully set ${characteristicName} to ${value} for ${child.alias}`);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
this.logRejection(error);
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
this.isUpdating = false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new Error('Device manager is undefined.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async updateState() {
|
|
121
|
+
if (this.isUpdating) {
|
|
122
|
+
this.log.debug('Update already in progress, skipping updateState');
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.isUpdating = true;
|
|
126
|
+
try {
|
|
127
|
+
this.log.debug('Updating device state');
|
|
128
|
+
await this.getSysInfo();
|
|
129
|
+
this.log.debug('Device found, updating state');
|
|
130
|
+
this.kasaDevice.sys_info.children?.forEach(async (child) => {
|
|
131
|
+
const childNumber = parseInt(child.id.slice(-1), 10);
|
|
132
|
+
this.log.debug(`Processing child device: ${child.alias} with child number: ${childNumber}`);
|
|
133
|
+
const service = this.homebridgeAccessory.getServiceById(this.platform.Service.Outlet, `outlet-${childNumber + 1}`);
|
|
134
|
+
if (service && this.previousKasaDevice) {
|
|
135
|
+
this.log.debug(`Service found for child device: ${child.alias}`);
|
|
136
|
+
const previousChild = this.previousKasaDevice.sys_info.children?.find(c => c.id === child.id);
|
|
137
|
+
if (previousChild && previousChild.state !== child.state) {
|
|
138
|
+
this.log.debug('Updating child devicestate');
|
|
139
|
+
this.updateValue(service, service.getCharacteristic(this.platform.Characteristic.On), child.state);
|
|
140
|
+
this.updateValue(service, service.getCharacteristic(this.platform.Characteristic.OutletInUse), child.state);
|
|
141
|
+
this.log.debug(`Updated state for child device: ${child.alias} to ${child.state}`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
this.log.debug(`State unchanged for child device: ${child.alias}`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
this.log.warn(`Service not found for child device: ${child.alias} or previous Kasa device is undefined`);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
this.log.debug('Device state updated successfully');
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
this.log.error('Error updating device state:', error);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
this.isUpdating = false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
startPolling() {
|
|
161
|
+
this.log.debug('Starting polling for device state updates');
|
|
162
|
+
setInterval(this.updateState.bind(this), this.platform.config.discoveryOptions.pollingInterval);
|
|
163
|
+
}
|
|
25
164
|
}
|
|
26
165
|
//# sourceMappingURL=homekitPowerStrip.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homekitPowerStrip.js","sourceRoot":"","sources":["../../src/devices/homekitPowerStrip.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"homekitPowerStrip.js","sourceRoot":"","sources":["../../src/devices/homekitPowerStrip.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAItE,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,aAAa;IAOpD;IANJ,UAAU,GAAY,KAAK,CAAC;IAC5B,kBAAkB,CAAyB;IAC3C,UAAU,CAAsB;IAExC,YACE,QAA4B,EAClB,UAAsB;QA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
|
|
3
3
|
import type { Switch } from './kasaDevices.js';
|
|
4
4
|
export default class HomeKitDeviceSwitch extends HomekitDevice {
|
|
5
5
|
protected kasaDevice: Switch;
|
|
6
|
+
private isUpdating;
|
|
7
|
+
private previousKasaDevice;
|
|
8
|
+
private getSysInfo;
|
|
6
9
|
private hasBrightness;
|
|
7
10
|
constructor(platform: KasaPythonPlatform, kasaDevice: Switch);
|
|
8
11
|
private addSwitchService;
|
|
9
12
|
identify(): void;
|
|
13
|
+
private addCharacteristic;
|
|
14
|
+
private handleOnGet;
|
|
15
|
+
private getCharacteristicValue;
|
|
16
|
+
private getDefaultValue;
|
|
17
|
+
private handleOnSet;
|
|
18
|
+
private updateState;
|
|
19
|
+
private startPolling;
|
|
10
20
|
}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import HomekitDevice from './index.js';
|
|
2
|
+
import { deferAndCombine, getOrAddCharacteristic } from '../utils.js';
|
|
2
3
|
export default class HomeKitDeviceSwitch extends HomekitDevice {
|
|
3
4
|
kasaDevice;
|
|
5
|
+
isUpdating = false;
|
|
6
|
+
previousKasaDevice;
|
|
7
|
+
getSysInfo;
|
|
4
8
|
hasBrightness;
|
|
5
9
|
constructor(platform, kasaDevice) {
|
|
6
10
|
super(platform, kasaDevice, 8 /* Categories.SWITCH */, 'SWITCH');
|
|
@@ -8,6 +12,19 @@ export default class HomeKitDeviceSwitch extends HomekitDevice {
|
|
|
8
12
|
this.log.debug(`Initializing HomeKitDeviceSwitch for device: ${kasaDevice.sys_info.alias}`);
|
|
9
13
|
this.hasBrightness = !!this.kasaDevice.feature_info.brightness;
|
|
10
14
|
this.addSwitchService();
|
|
15
|
+
this.getSysInfo = deferAndCombine(async (requestCount) => {
|
|
16
|
+
this.log.debug(`Executing deferred getSysInfo count: ${requestCount}`);
|
|
17
|
+
if (this.deviceManager) {
|
|
18
|
+
this.log.debug('Fetching new SysInfo from device manager');
|
|
19
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
20
|
+
this.kasaDevice.sys_info = await this.deviceManager.getSysInfo(this.deviceConfig);
|
|
21
|
+
this.log.debug('Updated SysInfo from device manager');
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.log.warn('Device manager is not available');
|
|
25
|
+
}
|
|
26
|
+
}, platform.config.waitTimeUpdate);
|
|
27
|
+
this.startPolling();
|
|
11
28
|
}
|
|
12
29
|
addSwitchService() {
|
|
13
30
|
const { Switch, Lightbulb } = this.platform.Service;
|
|
@@ -23,5 +40,131 @@ export default class HomeKitDeviceSwitch extends HomekitDevice {
|
|
|
23
40
|
identify() {
|
|
24
41
|
this.log.info('identify');
|
|
25
42
|
}
|
|
43
|
+
addCharacteristic(service, characteristicType) {
|
|
44
|
+
this.log.debug(`Adding characteristic ${this.platform.getCharacteristicName(characteristicType)} for device: ${this.name}`);
|
|
45
|
+
const characteristic = getOrAddCharacteristic(service, characteristicType);
|
|
46
|
+
characteristic.onGet(this.handleOnGet.bind(this, characteristicType));
|
|
47
|
+
characteristic.onSet(this.handleOnSet.bind(this, service, characteristicType));
|
|
48
|
+
return service;
|
|
49
|
+
}
|
|
50
|
+
async handleOnGet(characteristicType) {
|
|
51
|
+
const characteristicName = this.platform.getCharacteristicName(characteristicType);
|
|
52
|
+
if (!characteristicName) {
|
|
53
|
+
throw new Error('Characteristic name is undefined');
|
|
54
|
+
}
|
|
55
|
+
this.log.debug(`Getting current value for characteristic ${characteristicName} for device: ${this.name}`);
|
|
56
|
+
try {
|
|
57
|
+
const characteristicValue = this.getCharacteristicValue(characteristicType);
|
|
58
|
+
this.log.debug(`Current Value of ${characteristicName} is: ${characteristicValue} for ${this.name}`);
|
|
59
|
+
return characteristicValue ?? this.getDefaultValue(characteristicType);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
this.log.error(`Error getting current value for characteristic ${characteristicName} for device: ${this.name}:`, error);
|
|
63
|
+
}
|
|
64
|
+
return this.getDefaultValue(characteristicType);
|
|
65
|
+
}
|
|
66
|
+
getCharacteristicValue(characteristicType) {
|
|
67
|
+
const characteristicMap = {
|
|
68
|
+
Brightness: 'brightness',
|
|
69
|
+
On: 'state',
|
|
70
|
+
};
|
|
71
|
+
const characteristicKey = characteristicMap[characteristicType.name];
|
|
72
|
+
if (!characteristicKey) {
|
|
73
|
+
this.log.warn(`Characteristic ${characteristicType.name} is not supported`);
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const value = this.kasaDevice.sys_info[characteristicKey];
|
|
77
|
+
if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean' || value === null) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
getDefaultValue(characteristicType) {
|
|
83
|
+
if (characteristicType === this.platform.Characteristic.Brightness) {
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
async handleOnSet(service, characteristicType, value) {
|
|
89
|
+
const characteristicName = this.platform.getCharacteristicName(characteristicType);
|
|
90
|
+
if (!characteristicName) {
|
|
91
|
+
throw new Error('Characteristic name is undefined');
|
|
92
|
+
}
|
|
93
|
+
this.log.info(`Setting ${characteristicName} to: ${value} for ${this.name}`);
|
|
94
|
+
if (this.deviceManager) {
|
|
95
|
+
try {
|
|
96
|
+
this.isUpdating = true;
|
|
97
|
+
const characteristicMap = {
|
|
98
|
+
Brightness: 'brightness',
|
|
99
|
+
On: 'state',
|
|
100
|
+
};
|
|
101
|
+
const characteristicKey = characteristicMap[characteristicName];
|
|
102
|
+
if (!characteristicKey) {
|
|
103
|
+
throw new Error(`Characteristic key not found for ${characteristicName}`);
|
|
104
|
+
}
|
|
105
|
+
await this.deviceManager.controlDevice(this.deviceConfig, characteristicKey, value);
|
|
106
|
+
this.kasaDevice.sys_info[characteristicKey] = value;
|
|
107
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
108
|
+
this.updateValue(service, service.getCharacteristic(characteristicType), value);
|
|
109
|
+
this.log.debug(`Successfully set ${characteristicName} to ${value} for ${this.name}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
this.logRejection(error);
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
this.isUpdating = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
throw new Error('Device manager is undefined.');
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async updateState() {
|
|
124
|
+
if (this.isUpdating) {
|
|
125
|
+
this.log.debug('Update already in progress, skipping updateState');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this.isUpdating = true;
|
|
129
|
+
try {
|
|
130
|
+
this.log.debug('Updating device state');
|
|
131
|
+
await this.getSysInfo();
|
|
132
|
+
this.log.debug('Device found, updating state');
|
|
133
|
+
const service = this.homebridgeAccessory.getService(this.platform.Service.Switch) ||
|
|
134
|
+
this.homebridgeAccessory.getService(this.platform.Service.Lightbulb);
|
|
135
|
+
if (service && this.previousKasaDevice) {
|
|
136
|
+
if (this.previousKasaDevice.sys_info.state !== this.kasaDevice.sys_info.state) {
|
|
137
|
+
this.updateValue(service, service.getCharacteristic(this.platform.Characteristic.On), this.kasaDevice.sys_info.state ?? false);
|
|
138
|
+
this.log.debug(`Updated state for device: ${this.name} to ${this.kasaDevice.sys_info.state}`);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
this.log.debug(`State unchanged for device: ${this.name}`);
|
|
142
|
+
}
|
|
143
|
+
if (service.testCharacteristic(this.platform.Characteristic.Brightness)) {
|
|
144
|
+
if (this.previousKasaDevice.sys_info.brightness !== this.kasaDevice.sys_info.brightness) {
|
|
145
|
+
this.updateValue(service, service.getCharacteristic(this.platform.Characteristic.Brightness), this.kasaDevice.sys_info.brightness ?? 0);
|
|
146
|
+
this.log.debug(`Updated brightness for device: ${this.name} to ${this.kasaDevice.sys_info.brightness}`);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.log.debug(`Brightness unchanged for device: ${this.name}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
this.log.warn(`Service not found for device: ${this.name} or previous Kasa device is undefined`);
|
|
155
|
+
}
|
|
156
|
+
this.log.debug('Device state updated successfully');
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
this.log.error('Error updating device state:', error);
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
this.isUpdating = false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
startPolling() {
|
|
166
|
+
this.log.debug('Starting polling for device state updates');
|
|
167
|
+
setInterval(this.updateState.bind(this), this.platform.config.discoveryOptions.pollingInterval);
|
|
168
|
+
}
|
|
26
169
|
}
|
|
27
170
|
//# sourceMappingURL=homekitSwitch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"homekitSwitch.js","sourceRoot":"","sources":["../../src/devices/homekitSwitch.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"homekitSwitch.js","sourceRoot":"","sources":["../../src/devices/homekitSwitch.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAItE,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,aAAa;IAQhD;IAPJ,UAAU,GAAY,KAAK,CAAC;IAC5B,kBAAkB,CAAyB;IAC3C,UAAU,CAAsB;IAChC,aAAa,CAAU;IAE/B,YACE,QAA4B,EAClB,UAAkB;QAE5B,KAAK,CACH,QAAQ,EACR,UAAU,6BAEV,QAAQ,CACT,CAAC;QAPQ,eAAU,GAAV,UAAU,CAAQ;QAQ5B,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,gDAAgD,UAAU,CAAC,QAA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AAC,GAAG,CAAC,IAAI,CAAC,iCAAiC,IAAI,CAAC,IAAI,uCAAuC,CAAC,CAAC;YACnG,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACtD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,8BAA8B,EAAE,KAAK,CAAC,CAAC;QACxD,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC;IAEO,YAAY;QAClB,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC5D,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAClG,CAAC;CACF"}
|
package/dist/devices/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service
|
|
1
|
+
import { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service } from 'homebridge';
|
|
2
2
|
import DeviceManager from './deviceManager.js';
|
|
3
3
|
import type KasaPythonPlatform from '../platform.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { DeviceConfig, KasaDevice } from './kasaDevices.js';
|
|
5
5
|
import type { KasaPythonAccessoryContext } from '../platform.js';
|
|
6
6
|
export default abstract class HomekitDevice {
|
|
7
7
|
readonly platform: KasaPythonPlatform;
|
|
@@ -12,9 +12,6 @@ export default abstract class HomekitDevice {
|
|
|
12
12
|
readonly deviceConfig: DeviceConfig;
|
|
13
13
|
protected deviceManager: DeviceManager | undefined;
|
|
14
14
|
homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
|
|
15
|
-
private isUpdating;
|
|
16
|
-
private previousKasaDevice;
|
|
17
|
-
private getSysInfo;
|
|
18
15
|
constructor(platform: KasaPythonPlatform, kasaDevice: KasaDevice, category: Categories, categoryName: string);
|
|
19
16
|
private initializeAccessory;
|
|
20
17
|
private updateAccessory;
|
|
@@ -26,14 +23,7 @@ export default abstract class HomekitDevice {
|
|
|
26
23
|
get serialNumber(): string;
|
|
27
24
|
get firmwareRevision(): string;
|
|
28
25
|
abstract identify(): void;
|
|
29
|
-
updateValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError, childDeviceAlias?: string): void;
|
|
30
26
|
addService(serviceConstructor: typeof this.platform.Service.Outlet, name: string, subType?: string): Service;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
private handleOnGet;
|
|
34
|
-
private getCharacteristicValue;
|
|
35
|
-
private getDefaultValue;
|
|
36
|
-
private handleOnSet;
|
|
37
|
-
protected updateState(): Promise<void>;
|
|
38
|
-
private startPolling;
|
|
27
|
+
updateValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError, childDeviceAlias?: string): void;
|
|
28
|
+
logRejection(reason: unknown): void;
|
|
39
29
|
}
|