homebridge-kasa-python 1.0.2 → 2.0.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 +21 -6
- package/config.schema.json +2 -33
- package/dist/accessoryInformation.d.ts +1 -1
- package/dist/accessoryInformation.js +14 -18
- package/dist/accessoryInformation.js.map +1 -1
- package/dist/categoriesParse.d.ts +8 -0
- package/dist/categoriesParse.js +44 -0
- package/dist/categoriesParse.js.map +1 -0
- package/dist/config.d.ts +12 -155
- package/dist/config.js +52 -100
- package/dist/config.js.map +1 -1
- package/dist/devices/create.d.ts +3 -9
- package/dist/devices/create.js +6 -7
- package/dist/devices/create.js.map +1 -1
- package/dist/devices/deviceManager.d.ts +6 -8
- package/dist/devices/deviceManager.js +47 -126
- package/dist/devices/deviceManager.js.map +1 -1
- package/dist/devices/homekitPlug.d.ts +10 -16
- package/dist/devices/homekitPlug.js +93 -74
- package/dist/devices/homekitPlug.js.map +1 -1
- package/dist/devices/homekitPowerstrip.d.ts +11 -17
- package/dist/devices/homekitPowerstrip.js +106 -73
- package/dist/devices/homekitPowerstrip.js.map +1 -1
- package/dist/devices/index.d.ts +12 -19
- package/dist/devices/index.js +44 -71
- package/dist/devices/index.js.map +1 -1
- package/dist/devices/kasaDevices.d.ts +4 -5
- package/dist/platform.d.ts +22 -29
- package/dist/platform.js +127 -131
- package/dist/platform.js.map +1 -1
- package/dist/python/kasaApi.py +109 -0
- package/dist/python/pythonChecker.d.ts +2 -2
- package/dist/python/pythonChecker.js +24 -89
- package/dist/python/pythonChecker.js.map +1 -1
- package/dist/utils.d.ts +3 -18
- package/dist/utils.js +72 -116
- package/dist/utils.js.map +1 -1
- package/package.json +20 -19
- package/requirements.txt +4 -1
- package/dist/python/discover.py +0 -38
- package/dist/python/getSysInfo.py +0 -39
- package/dist/python/turnOff.py +0 -20
- package/dist/python/turnOffChild.py +0 -22
- package/dist/python/turnOn.py +0 -20
- package/dist/python/turnOnChild.py +0 -22
|
@@ -1,23 +1,17 @@
|
|
|
1
|
-
import type { PlatformAccessory } from 'homebridge';
|
|
2
1
|
import HomekitDevice from './index.js';
|
|
3
|
-
import { KasaPythonConfig } from '../config.js';
|
|
4
|
-
import DeviceManager from './deviceManager.js';
|
|
5
2
|
import type KasaPythonPlatform from '../platform.js';
|
|
6
|
-
import type {
|
|
7
|
-
import type { DeviceConfig, Powerstrip } from './kasaDevices.js';
|
|
3
|
+
import type { Powerstrip } from './kasaDevices.js';
|
|
8
4
|
export default class HomeKitDevicePowerStrip extends HomekitDevice {
|
|
9
|
-
|
|
10
|
-
readonly kasaDevice: Powerstrip;
|
|
11
|
-
readonly deviceConfig: DeviceConfig;
|
|
12
|
-
constructor(platform: KasaPythonPlatform, config: KasaPythonConfig, homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext> | undefined, kasaDevice: Powerstrip, deviceConfig: DeviceConfig, deviceManager?: DeviceManager);
|
|
13
|
-
/**
|
|
14
|
-
* Aggregates getSysInfo requests
|
|
15
|
-
*
|
|
16
|
-
* @private
|
|
17
|
-
*/
|
|
5
|
+
protected kasaDevice: Powerstrip;
|
|
18
6
|
private getSysInfo;
|
|
19
|
-
private
|
|
20
|
-
private
|
|
21
|
-
|
|
7
|
+
private previousKasaDevice;
|
|
8
|
+
private isUpdating;
|
|
9
|
+
constructor(platform: KasaPythonPlatform, kasaDevice: Powerstrip);
|
|
10
|
+
private addOutletService;
|
|
11
|
+
private addCharacteristic;
|
|
12
|
+
private handleOnGet;
|
|
13
|
+
private handleOnSet;
|
|
14
|
+
private updateState;
|
|
15
|
+
private startPolling;
|
|
22
16
|
identify(): void;
|
|
23
17
|
}
|
|
@@ -1,100 +1,133 @@
|
|
|
1
1
|
import HomekitDevice from './index.js';
|
|
2
2
|
import { deferAndCombine, getOrAddCharacteristic } from '../utils.js';
|
|
3
3
|
export default class HomeKitDevicePowerStrip extends HomekitDevice {
|
|
4
|
-
config;
|
|
5
4
|
kasaDevice;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
getSysInfo;
|
|
6
|
+
previousKasaDevice;
|
|
7
|
+
isUpdating = false;
|
|
8
|
+
constructor(platform, kasaDevice) {
|
|
9
|
+
super(platform, kasaDevice, 7 /* Categories.OUTLET */);
|
|
10
10
|
this.kasaDevice = kasaDevice;
|
|
11
|
-
this.deviceConfig = deviceConfig;
|
|
12
11
|
this.kasaDevice.sys_info.children.forEach((child, index) => {
|
|
13
|
-
this.
|
|
12
|
+
this.addOutletService(child, index);
|
|
14
13
|
});
|
|
15
14
|
this.getSysInfo = deferAndCombine(async (requestCount) => {
|
|
16
15
|
this.log.debug(`executing deferred getSysInfo count: ${requestCount}`);
|
|
17
|
-
|
|
16
|
+
if (this.deviceManager) {
|
|
17
|
+
const newKasaDevice = await this.deviceManager.getSysInfo(this);
|
|
18
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
19
|
+
this.kasaDevice = newKasaDevice;
|
|
20
|
+
return this.kasaDevice;
|
|
21
|
+
}
|
|
22
|
+
return undefined;
|
|
18
23
|
}, platform.config.waitTimeUpdate);
|
|
24
|
+
this.startPolling();
|
|
19
25
|
}
|
|
20
|
-
|
|
21
|
-
* Aggregates getSysInfo requests
|
|
22
|
-
*
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
getSysInfo;
|
|
26
|
-
addAndConfigureOutletService(child, index) {
|
|
26
|
+
addOutletService(child, index) {
|
|
27
27
|
const { Outlet } = this.platform.Service;
|
|
28
28
|
const outletService = this.homebridgeAccessory.getServiceById(Outlet, `outlet-${index + 1}`) ??
|
|
29
29
|
this.addService(Outlet, child.alias, `outlet-${index + 1}`);
|
|
30
|
-
this.
|
|
31
|
-
this.
|
|
30
|
+
this.addCharacteristic(outletService, this.platform.Characteristic.On, child);
|
|
31
|
+
this.addCharacteristic(outletService, this.platform.Characteristic.OutletInUse, child);
|
|
32
32
|
return outletService;
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
addCharacteristic(service, characteristicType, child) {
|
|
35
|
+
const characteristic = getOrAddCharacteristic(service, characteristicType);
|
|
36
|
+
characteristic.onGet(this.handleOnGet.bind(this, child, characteristicType));
|
|
37
|
+
if (characteristicType === this.platform.Characteristic.On) {
|
|
38
|
+
characteristic.onSet(this.handleOnSet.bind(this, child));
|
|
39
|
+
}
|
|
40
|
+
return service;
|
|
41
|
+
}
|
|
42
|
+
async handleOnGet(child, characteristicType) {
|
|
43
|
+
try {
|
|
44
|
+
const childInfo = this.kasaDevice.sys_info.children.find((c) => c.id === child.id);
|
|
45
|
+
if (!childInfo) {
|
|
46
|
+
this.log.warn(`Child with id ${child.id} not found`);
|
|
47
|
+
return 0;
|
|
43
48
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
const stateValue = childInfo.state === 1;
|
|
50
|
+
const characteristicName = this.platform.getCharacteristicName(characteristicType);
|
|
51
|
+
this.log.debug(`Current State of ${characteristicName} is: ${stateValue} for ${child.alias}`);
|
|
52
|
+
return childInfo.state ?? 0;
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
this.log.error('Error getting device state:', error);
|
|
56
|
+
}
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
async handleOnSet(child, value) {
|
|
60
|
+
this.log.info(`Setting On to: ${value} for ${child.alias}`);
|
|
61
|
+
if (typeof value === 'boolean') {
|
|
62
|
+
if (this.deviceManager) {
|
|
63
|
+
const childNumber = parseInt(child.id.slice(-1), 10);
|
|
64
|
+
try {
|
|
65
|
+
this.isUpdating = true;
|
|
66
|
+
await this.deviceManager.toggleDevice(this, value, childNumber);
|
|
67
|
+
const kasaChild = this.kasaDevice.sys_info.children.find((c) => c.id === child.id);
|
|
68
|
+
if (kasaChild) {
|
|
69
|
+
kasaChild.state = value ? 1 : 0;
|
|
70
|
+
}
|
|
71
|
+
this.previousKasaDevice = this.kasaDevice;
|
|
72
|
+
const service = this.homebridgeAccessory.getServiceById(this.platform.Service.Outlet, `outlet-${childNumber + 1}`);
|
|
73
|
+
if (service) {
|
|
74
|
+
const onCharacteristic = service.getCharacteristic(this.platform.Characteristic.On);
|
|
75
|
+
const outletInUseCharacteristic = service.getCharacteristic(this.platform.Characteristic.OutletInUse);
|
|
76
|
+
this.updateValue(service, onCharacteristic, value);
|
|
77
|
+
this.updateValue(service, outletInUseCharacteristic, value);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
this.logRejection(error);
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
this.isUpdating = false;
|
|
86
|
+
}
|
|
52
87
|
}
|
|
53
|
-
else
|
|
54
|
-
|
|
55
|
-
return;
|
|
88
|
+
else {
|
|
89
|
+
throw new Error('Device manager is undefined.');
|
|
56
90
|
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
57
93
|
this.log.warn('setValue: Invalid On:', value);
|
|
58
94
|
throw new Error(`setValue: Invalid On: ${value}`);
|
|
59
|
-
}
|
|
60
|
-
let oldChildState = childDevice.state;
|
|
61
|
-
setInterval(async () => {
|
|
62
|
-
const device = await this.getSysInfo().catch(this.logRejection.bind(this));
|
|
63
|
-
let newChildState;
|
|
64
|
-
if (device) {
|
|
65
|
-
newChildState = device.sys_info.children?.find((child) => child.id === childDevice.id)?.state;
|
|
66
|
-
}
|
|
67
|
-
if (newChildState !== undefined && newChildState !== oldChildState) {
|
|
68
|
-
this.updateChildValue(outletService, onCharacteristic, newChildState, childDevice.alias);
|
|
69
|
-
oldChildState = newChildState;
|
|
70
|
-
}
|
|
71
|
-
}, this.config.discoveryOptions.pollingInterval);
|
|
72
|
-
return outletService;
|
|
95
|
+
}
|
|
73
96
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return childState ?? 0;
|
|
82
|
-
}
|
|
83
|
-
return 0;
|
|
84
|
-
});
|
|
85
|
-
let oldChildState = childDevice.state;
|
|
86
|
-
setInterval(async () => {
|
|
87
|
-
const device = await this.getSysInfo().catch(this.logRejection.bind(this));
|
|
88
|
-
let newChildState;
|
|
97
|
+
async updateState() {
|
|
98
|
+
if (this.isUpdating) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.isUpdating = true;
|
|
102
|
+
try {
|
|
103
|
+
const device = await this.getSysInfo();
|
|
89
104
|
if (device) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
device.sys_info.children.forEach(async (child) => {
|
|
106
|
+
const childNumber = parseInt(child.id.slice(-1), 10);
|
|
107
|
+
const service = this.homebridgeAccessory.getServiceById(this.platform.Service.Outlet, `outlet-${childNumber + 1}`);
|
|
108
|
+
if (service && this.previousKasaDevice) {
|
|
109
|
+
const previousKasaChild = this.previousKasaDevice.sys_info.children.find(c => c.id === child.id);
|
|
110
|
+
const kasaChild = this.kasaDevice.sys_info.children.find(c => c.id === child.id);
|
|
111
|
+
if (previousKasaChild && kasaChild && previousKasaChild.state !== child.state) {
|
|
112
|
+
kasaChild.state = child.state;
|
|
113
|
+
const onCharacteristic = service.getCharacteristic(this.platform.Characteristic.On);
|
|
114
|
+
const outletInUseCharacteristic = service.getCharacteristic(this.platform.Characteristic.OutletInUse);
|
|
115
|
+
this.updateValue(service, onCharacteristic, child.state === 1, child.alias);
|
|
116
|
+
this.updateValue(service, outletInUseCharacteristic, child.state === 1, child.alias);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
95
120
|
}
|
|
96
|
-
}
|
|
97
|
-
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
this.log.error('Error updating device state:', error);
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
this.isUpdating = false;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
startPolling() {
|
|
130
|
+
setInterval(this.updateState.bind(this), this.platform.config.discoveryOptions.pollingInterval);
|
|
98
131
|
}
|
|
99
132
|
identify() {
|
|
100
133
|
this.log.info('identify');
|
|
@@ -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,CAAwC;IAClD,kBAAkB,CAAyB;IAC3C,UAAU,GAAY,KAAK,CAAC;IAEpC,YACE,QAA4B,EAClB,UAAsB;QAEhC,KAAK,CACH,QAAQ,EACR,UAAU,4BAEX,CAAC;QANQ,eAAU,GAAV,UAAU,CAAY;QAOhC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,KAAgB,EAAE,KAAa,EAAE,EAAE;YAC5E,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACtC,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,UAAU,GAAG,eAAe,CAAC,KAAK,EAAE,YAAoB,EAAE,EAAE;YAC/D,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,wCAAwC,YAAY,EAAE,CAAC,CAAC;YACvE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;gBACvB,MAA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AAC,IAAI,CAAC,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;IAClG,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
package/dist/devices/index.d.ts
CHANGED
|
@@ -1,36 +1,29 @@
|
|
|
1
|
-
import type { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service
|
|
2
|
-
import type { KasaPythonConfig } from '../config.js';
|
|
1
|
+
import type { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service } from 'homebridge';
|
|
3
2
|
import DeviceManager from './deviceManager.js';
|
|
4
3
|
import type KasaPythonPlatform from '../platform.js';
|
|
4
|
+
import type { DeviceConfig, KasaDevice } from './kasaDevices.js';
|
|
5
5
|
import type { KasaPythonAccessoryContext } from '../platform.js';
|
|
6
|
-
import type { KasaDevice } from '../utils.js';
|
|
7
|
-
import type { DeviceConfig } from './kasaDevices.js';
|
|
8
6
|
export default abstract class HomekitDevice {
|
|
9
7
|
readonly platform: KasaPythonPlatform;
|
|
10
|
-
|
|
11
|
-
readonly kasaDevice: KasaDevice;
|
|
8
|
+
protected kasaDevice: KasaDevice;
|
|
12
9
|
readonly category: Categories;
|
|
13
10
|
readonly log: Logger;
|
|
14
|
-
|
|
15
|
-
homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
|
|
11
|
+
readonly categoryName: string;
|
|
16
12
|
readonly deviceConfig: DeviceConfig;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
protected deviceManager: DeviceManager | undefined;
|
|
14
|
+
homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
|
|
15
|
+
constructor(platform: KasaPythonPlatform, kasaDevice: KasaDevice, category: Categories);
|
|
16
|
+
private initializeAccessory;
|
|
17
|
+
private updateAccessory;
|
|
18
|
+
private correctAccessoryProperty;
|
|
22
19
|
get id(): string;
|
|
23
20
|
get name(): string;
|
|
24
21
|
get manufacturer(): string;
|
|
25
22
|
get model(): string;
|
|
26
23
|
get serialNumber(): string;
|
|
27
24
|
get firmwareRevision(): string;
|
|
28
|
-
get hardwareRevision(): string;
|
|
29
25
|
abstract identify(): void;
|
|
30
|
-
updateValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError): void;
|
|
31
|
-
|
|
32
|
-
addService(serviceConstructor: typeof this.platform.Service.Outlet | typeof this.platform.Service.Lightbulb, name: string, subType?: string): Service;
|
|
26
|
+
updateValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError, childDeviceAlias?: string): void;
|
|
27
|
+
addService(serviceConstructor: typeof this.platform.Service.Outlet, name: string, subType?: string): Service;
|
|
33
28
|
protected logRejection(reason: unknown): void;
|
|
34
|
-
protected removeServiceIfExists(service: WithUUID<typeof Service>): void;
|
|
35
|
-
protected removeCharacteristicIfExists(service: Service, characteristic: WithUUID<new () => Characteristic>): void;
|
|
36
29
|
}
|
package/dist/devices/index.js
CHANGED
|
@@ -1,66 +1,59 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import AccessoryInformation from '../accessoryInformation.js';
|
|
3
|
-
import DeviceManager from './deviceManager.js';
|
|
4
2
|
import { prefixLogger } from '../utils.js';
|
|
5
3
|
export default class HomekitDevice {
|
|
6
4
|
platform;
|
|
7
|
-
config;
|
|
8
5
|
kasaDevice;
|
|
9
6
|
category;
|
|
10
7
|
log;
|
|
8
|
+
categoryName;
|
|
9
|
+
deviceConfig;
|
|
11
10
|
deviceManager;
|
|
12
11
|
homebridgeAccessory;
|
|
13
|
-
|
|
14
|
-
lsc;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an instance of HomeKitDevice.
|
|
17
|
-
*/
|
|
18
|
-
constructor(platform, config, homebridgeAccessory, kasaDevice, category, deviceConfig, deviceManager) {
|
|
12
|
+
constructor(platform, kasaDevice, category) {
|
|
19
13
|
this.platform = platform;
|
|
20
|
-
this.config = config;
|
|
21
14
|
this.kasaDevice = kasaDevice;
|
|
22
15
|
this.category = category;
|
|
23
|
-
this.deviceConfig =
|
|
24
|
-
this.deviceManager = deviceManager
|
|
25
|
-
this.log = prefixLogger(platform.log,
|
|
26
|
-
this.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
this.deviceConfig = kasaDevice.device_config;
|
|
17
|
+
this.deviceManager = platform.deviceManager;
|
|
18
|
+
this.log = prefixLogger(platform.log, `[${this.name}]`);
|
|
19
|
+
this.categoryName = this.platform.getCategoryName(this.category);
|
|
20
|
+
this.homebridgeAccessory = this.initializeAccessory();
|
|
21
|
+
this.homebridgeAccessory.on("identify" /* PlatformAccessoryEvent.IDENTIFY */, () => this.identify());
|
|
22
|
+
}
|
|
23
|
+
initializeAccessory() {
|
|
24
|
+
const uuid = this.platform.api.hap.uuid.generate(this.id);
|
|
25
|
+
const homebridgeAccessory = this.platform.configuredAccessories.get(uuid);
|
|
26
|
+
let accessory;
|
|
27
|
+
if (!homebridgeAccessory) {
|
|
28
|
+
this.log.debug(`Creating new Accessory [${this.id}] [${uuid}] category: ${this.categoryName}`);
|
|
29
|
+
accessory = new this.platform.api.platformAccessory(this.name, uuid, this.category);
|
|
30
|
+
accessory.context.deviceId = this.id;
|
|
31
|
+
this.platform.registerPlatformAccessory(accessory);
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
36
|
-
this.homebridgeAccessory
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.log.warn(`Correcting Accessory Category from: ${platform.getCategoryName(this.homebridgeAccessory.category)} to: ${categoryName}`);
|
|
41
|
-
this.homebridgeAccessory.category = category;
|
|
42
|
-
}
|
|
43
|
-
this.homebridgeAccessory.context.deviceId = this.id;
|
|
44
|
-
this.platform.api.updatePlatformAccessories([this.homebridgeAccessory]);
|
|
34
|
+
this.log.debug(`Existing Accessory found [${homebridgeAccessory.context.deviceId}] ` +
|
|
35
|
+
`[${homebridgeAccessory.UUID}] category: ${this.platform.getCategoryName(homebridgeAccessory.category)}`);
|
|
36
|
+
accessory = homebridgeAccessory;
|
|
37
|
+
this.updateAccessory(accessory);
|
|
45
38
|
}
|
|
46
|
-
const accInfo = AccessoryInformation(platform.api.hap)(
|
|
47
|
-
if (accInfo
|
|
39
|
+
const accInfo = AccessoryInformation(this.platform.api.hap)(accessory, this);
|
|
40
|
+
if (!accInfo) {
|
|
48
41
|
this.log.error('Could not retrieve default AccessoryInformation');
|
|
49
42
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
43
|
+
return accessory;
|
|
44
|
+
}
|
|
45
|
+
updateAccessory(accessory) {
|
|
46
|
+
this.correctAccessoryProperty(accessory, 'displayName', this.name);
|
|
47
|
+
this.correctAccessoryProperty(accessory, 'category', this.category);
|
|
48
|
+
this.correctAccessoryProperty(accessory.context, 'deviceId', this.id);
|
|
49
|
+
this.platform.configuredAccessories.set(accessory.UUID, accessory);
|
|
50
|
+
this.platform.api.updatePlatformAccessories([accessory]);
|
|
51
|
+
}
|
|
52
|
+
correctAccessoryProperty(obj, key, expectedValue) {
|
|
53
|
+
if (obj[key] !== expectedValue) {
|
|
54
|
+
this.log.warn(`Correcting Accessory ${String(key)} from: ${String(obj[key])} to: ${String(expectedValue)}`);
|
|
55
|
+
obj[key] = expectedValue;
|
|
56
|
+
}
|
|
64
57
|
}
|
|
65
58
|
get id() {
|
|
66
59
|
return this.kasaDevice.sys_info.deviceId;
|
|
@@ -75,23 +68,17 @@ export default class HomekitDevice {
|
|
|
75
68
|
return this.kasaDevice.sys_info.model;
|
|
76
69
|
}
|
|
77
70
|
get serialNumber() {
|
|
78
|
-
return `${this.kasaDevice.sys_info.mac
|
|
71
|
+
return `${this.kasaDevice.sys_info.mac.replace(/:/g, '').slice(-4)}`;
|
|
79
72
|
}
|
|
80
73
|
get firmwareRevision() {
|
|
81
74
|
return this.kasaDevice.sys_info.sw_ver;
|
|
82
75
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
this.log.debug(`Updating ${this.lsc(service, characteristic)} ${value}`);
|
|
76
|
+
updateValue(service, characteristic, value, childDeviceAlias) {
|
|
77
|
+
const logMessage = `Updating ${this.platform.lsc(service, characteristic)}` +
|
|
78
|
+
`${childDeviceAlias ? ` on ${childDeviceAlias}` : ''} to ${value}`;
|
|
79
|
+
this.log.debug(logMessage);
|
|
88
80
|
characteristic.updateValue(value);
|
|
89
81
|
}
|
|
90
|
-
updateChildValue(service, characteristic, value, childDeviceAlias) {
|
|
91
|
-
const homekitState = value === 1 ? true : false;
|
|
92
|
-
this.log.debug(`Updating ${this.lsc(service, characteristic)} on ${childDeviceAlias} to ${homekitState}`);
|
|
93
|
-
characteristic.updateValue(homekitState);
|
|
94
|
-
}
|
|
95
82
|
addService(serviceConstructor, name, subType) {
|
|
96
83
|
const serviceName = this.platform.getServiceName(serviceConstructor);
|
|
97
84
|
this.log.debug(`Creating new ${serviceName} Service on ${name}${subType ? ` [${subType}]` : ''}`);
|
|
@@ -100,19 +87,5 @@ export default class HomekitDevice {
|
|
|
100
87
|
logRejection(reason) {
|
|
101
88
|
this.log.error(JSON.stringify(reason));
|
|
102
89
|
}
|
|
103
|
-
removeServiceIfExists(service) {
|
|
104
|
-
const foundService = this.homebridgeAccessory.getService(service);
|
|
105
|
-
if (foundService !== null && foundService !== undefined) {
|
|
106
|
-
this.log.warn(`Removing stale Service: ${this.lsc(service, foundService)} uuid:[%s]`, foundService.UUID);
|
|
107
|
-
this.homebridgeAccessory.removeService(foundService);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
removeCharacteristicIfExists(service, characteristic) {
|
|
111
|
-
if (service.testCharacteristic(characteristic)) {
|
|
112
|
-
const characteristicToRemove = service.getCharacteristic(characteristic);
|
|
113
|
-
this.log.warn(`Removing stale Characteristic: ${this.lsc(service, characteristicToRemove)} uuid:[%s]`, characteristicToRemove.UUID);
|
|
114
|
-
service.removeCharacteristic(characteristicToRemove);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
90
|
}
|
|
118
91
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAYA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAYA,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,MAAM,CAAC,OAAO,OAAgB,aAAa;IAQ9B;IACC;IACD;IATF,GAAG,CAAS;IACZ,YAAY,CAAS;IACrB,YAAY,CAAe;IAC1B,aAAa,CAA4B;IACnD,mBAAmB,CAAgD;IAEnE,YACW,QAA4B,EAC3B,UAAsB,EACvB,QAAoB;QAFpB,aAAQ,GAAR,QAAQ,CAAoB;QAC3B,eAAU,GAAV,UAAU,CAAY;QACvB,aAAQ,GAAR,QAAQ,CAAY;QAE7B,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,aAAa,CAAC;QAC7C,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC;QAC5C,IAAI,CAAC,GAAG,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC;QACxD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,QAA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AE,OAAO,CAAC,CAAC;IAChF,CAAC;IAES,YAAY,CAAC,MAAe;QACpC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IACzC,CAAC;CACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
export type KasaDevice = Plug | Powerstrip;
|
|
1
2
|
interface DeviceCommonInfo {
|
|
2
3
|
alias: string;
|
|
3
|
-
children?: ChildPlug[];
|
|
4
|
-
device_id: string;
|
|
5
4
|
host: string;
|
|
6
5
|
is_off: boolean;
|
|
7
6
|
is_on: boolean;
|
|
@@ -32,17 +31,17 @@ export interface DeviceConfig {
|
|
|
32
31
|
device_family: string;
|
|
33
32
|
encryption_type: string;
|
|
34
33
|
};
|
|
35
|
-
uses_http:
|
|
34
|
+
uses_http: boolean;
|
|
36
35
|
}
|
|
37
36
|
export interface Plug extends DeviceCommonInfo {
|
|
38
|
-
children
|
|
37
|
+
children?: ChildPlug[];
|
|
39
38
|
device_config: DeviceConfig;
|
|
40
39
|
}
|
|
41
40
|
export interface Powerstrip extends DeviceCommonInfo {
|
|
42
|
-
device_config: DeviceConfig;
|
|
43
41
|
sys_info: SysInfo & {
|
|
44
42
|
children: ChildPlug[];
|
|
45
43
|
child_num: number;
|
|
46
44
|
};
|
|
45
|
+
device_config: DeviceConfig;
|
|
47
46
|
}
|
|
48
47
|
export {};
|