homebridge-kasa-python 1.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +398 -0
  3. package/config.schema.json +214 -0
  4. package/dist/accessoryInformation.d.ts +3 -0
  5. package/dist/accessoryInformation.js +24 -0
  6. package/dist/accessoryInformation.js.map +1 -0
  7. package/dist/config.d.ts +186 -0
  8. package/dist/config.js +154 -0
  9. package/dist/config.js.map +1 -0
  10. package/dist/devices/create.d.ts +10 -0
  11. package/dist/devices/create.js +20 -0
  12. package/dist/devices/create.js.map +1 -0
  13. package/dist/devices/deviceManager.d.ts +15 -0
  14. package/dist/devices/deviceManager.js +157 -0
  15. package/dist/devices/deviceManager.js.map +1 -0
  16. package/dist/devices/homekitPlug.d.ts +23 -0
  17. package/dist/devices/homekitPlug.js +101 -0
  18. package/dist/devices/homekitPlug.js.map +1 -0
  19. package/dist/devices/homekitPowerstrip.d.ts +23 -0
  20. package/dist/devices/homekitPowerstrip.js +103 -0
  21. package/dist/devices/homekitPowerstrip.js.map +1 -0
  22. package/dist/devices/index.d.ts +36 -0
  23. package/dist/devices/index.js +118 -0
  24. package/dist/devices/index.js.map +1 -0
  25. package/dist/devices/kasaDevices.d.ts +48 -0
  26. package/dist/devices/kasaDevices.js +2 -0
  27. package/dist/devices/kasaDevices.js.map +1 -0
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +6 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/platform.d.ts +57 -0
  32. package/dist/platform.js +182 -0
  33. package/dist/platform.js.map +1 -0
  34. package/dist/python/discover.py +38 -0
  35. package/dist/python/getSysInfo.py +39 -0
  36. package/dist/python/pythonChecker.d.ts +31 -0
  37. package/dist/python/pythonChecker.js +195 -0
  38. package/dist/python/pythonChecker.js.map +1 -0
  39. package/dist/python/pythonHome.py +3 -0
  40. package/dist/python/turnOff.py +20 -0
  41. package/dist/python/turnOffChild.py +22 -0
  42. package/dist/python/turnOn.py +20 -0
  43. package/dist/python/turnOnChild.py +22 -0
  44. package/dist/settings.d.ts +2 -0
  45. package/dist/settings.js +3 -0
  46. package/dist/settings.js.map +1 -0
  47. package/dist/utils.d.ts +30 -0
  48. package/dist/utils.js +172 -0
  49. package/dist/utils.js.map +1 -0
  50. package/package.json +79 -0
  51. package/requirements.txt +1 -0
@@ -0,0 +1,101 @@
1
+ import HomekitDevice from './index.js';
2
+ import { deferAndCombine, getOrAddCharacteristic } from '../utils.js';
3
+ export default class HomeKitDevicePlug extends HomekitDevice {
4
+ config;
5
+ kasaDevice;
6
+ deviceConfig;
7
+ constructor(platform, config, homebridgeAccessory, kasaDevice, deviceConfig, deviceManager) {
8
+ super(platform, config, homebridgeAccessory, kasaDevice, 7 /* Categories.OUTLET */, deviceConfig, deviceManager);
9
+ this.config = config;
10
+ this.kasaDevice = kasaDevice;
11
+ this.deviceConfig = deviceConfig;
12
+ this.addOutletService();
13
+ this.getSysInfo = deferAndCombine(async (requestCount) => {
14
+ this.log.debug(`executing deferred getSysInfo count: ${requestCount}`);
15
+ return Promise.resolve(await this.deviceManager.getSysInfo(this));
16
+ }, platform.config.waitTimeUpdate);
17
+ }
18
+ /**
19
+ * Aggregates getSysInfo requests
20
+ *
21
+ * @private
22
+ */
23
+ getSysInfo;
24
+ addOutletService() {
25
+ const { Outlet } = this.platform.Service;
26
+ const outletService = this.homebridgeAccessory.getService(Outlet) ??
27
+ this.addService(Outlet, this.name);
28
+ this.addOnCharacteristic(outletService);
29
+ this.addOutletInUseCharacteristic(outletService);
30
+ return outletService;
31
+ }
32
+ addOnCharacteristic(service) {
33
+ const onCharacteristic = getOrAddCharacteristic(service, this.platform.Characteristic.On);
34
+ onCharacteristic
35
+ .onGet(async () => {
36
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
37
+ if (device) {
38
+ const state = device.sys_info.relay_state;
39
+ this.log.debug(`Current State of On is: ${state === 1 ? true : false} for ${this.name}`);
40
+ return state ?? 0;
41
+ }
42
+ return 0;
43
+ })
44
+ .onSet(async (value) => {
45
+ this.log.info(`Setting On to: ${value} for ${this.name}`);
46
+ if (typeof value === 'boolean' && value === true) {
47
+ this.deviceManager.turnOn(this).catch(this.logRejection.bind(this));
48
+ return;
49
+ }
50
+ else if (typeof value === 'boolean' && value === false) {
51
+ this.deviceManager.turnOff(this).catch(this.logRejection.bind(this));
52
+ return;
53
+ }
54
+ this.log.warn('setValue: Invalid On:', value);
55
+ throw new Error(`setValue: Invalid On: ${value}`);
56
+ });
57
+ let oldState = this.kasaDevice.sys_info.relay_state;
58
+ setInterval(async () => {
59
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
60
+ let newState;
61
+ if (device) {
62
+ newState = device.sys_info.relay_state;
63
+ }
64
+ if (newState !== undefined && newState !== oldState) {
65
+ this.updateValue(service, onCharacteristic, newState);
66
+ oldState = newState;
67
+ }
68
+ }, this.config.discoveryOptions.pollingInterval);
69
+ return service;
70
+ }
71
+ addOutletInUseCharacteristic(service) {
72
+ const outletInUseCharacteristic = getOrAddCharacteristic(service, this.platform.Characteristic.OutletInUse);
73
+ outletInUseCharacteristic
74
+ .onGet(async () => {
75
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
76
+ if (device) {
77
+ const state = device.sys_info.relay_state;
78
+ this.log.debug(`Current State of On is: ${state === 1 ? true : false} for ${this.name}`);
79
+ return state ?? 0;
80
+ }
81
+ return 0;
82
+ });
83
+ let oldState = this.kasaDevice.sys_info.relay_state;
84
+ setInterval(async () => {
85
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
86
+ let newState;
87
+ if (device) {
88
+ newState = device.sys_info.relay_state;
89
+ }
90
+ if (newState !== undefined && newState !== oldState) {
91
+ this.updateValue(service, outletInUseCharacteristic, newState);
92
+ oldState = newState;
93
+ }
94
+ }, this.config.discoveryOptions.pollingInterval);
95
+ return service;
96
+ }
97
+ identify() {
98
+ this.log.info('identify');
99
+ }
100
+ }
101
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} from 'homebridge';
2
+ import HomekitDevice from './index.js';
3
+ import { KasaPythonConfig } from '../config.js';
4
+ import DeviceManager from './deviceManager.js';
5
+ import type KasaPythonPlatform from '../platform.js';
6
+ import type { KasaPythonAccessoryContext } from '../platform.js';
7
+ import type { DeviceConfig, Powerstrip } from './kasaDevices.js';
8
+ export default class HomeKitDevicePowerStrip extends HomekitDevice {
9
+ readonly config: KasaPythonConfig;
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
+ */
18
+ private getSysInfo;
19
+ private addAndConfigureOutletService;
20
+ private addOnCharacteristic;
21
+ private addOutletInUseCharacteristic;
22
+ identify(): void;
23
+ }
@@ -0,0 +1,103 @@
1
+ import HomekitDevice from './index.js';
2
+ import { deferAndCombine, getOrAddCharacteristic } from '../utils.js';
3
+ export default class HomeKitDevicePowerStrip extends HomekitDevice {
4
+ config;
5
+ kasaDevice;
6
+ deviceConfig;
7
+ constructor(platform, config, homebridgeAccessory, kasaDevice, deviceConfig, deviceManager) {
8
+ super(platform, config, homebridgeAccessory, kasaDevice, 7 /* Categories.OUTLET */, deviceConfig, deviceManager);
9
+ this.config = config;
10
+ this.kasaDevice = kasaDevice;
11
+ this.deviceConfig = deviceConfig;
12
+ this.kasaDevice.sys_info.children.forEach((child, index) => {
13
+ this.addAndConfigureOutletService(child, index);
14
+ });
15
+ this.getSysInfo = deferAndCombine(async (requestCount) => {
16
+ this.log.debug(`executing deferred getSysInfo count: ${requestCount}`);
17
+ return Promise.resolve(await this.deviceManager.getSysInfo(this));
18
+ }, platform.config.waitTimeUpdate);
19
+ }
20
+ /**
21
+ * Aggregates getSysInfo requests
22
+ *
23
+ * @private
24
+ */
25
+ getSysInfo;
26
+ addAndConfigureOutletService(child, index) {
27
+ const { Outlet } = this.platform.Service;
28
+ const outletService = this.homebridgeAccessory.getServiceById(Outlet, `outlet-${index + 1}`) ??
29
+ this.addService(Outlet, child.alias, `outlet-${index + 1}`);
30
+ this.addOnCharacteristic(outletService, child);
31
+ this.addOutletInUseCharacteristic(outletService, child);
32
+ return outletService;
33
+ }
34
+ addOnCharacteristic(outletService, childDevice) {
35
+ const onCharacteristic = getOrAddCharacteristic(outletService, this.platform.Characteristic.On);
36
+ onCharacteristic
37
+ .onGet(async () => {
38
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
39
+ if (device) {
40
+ const childState = device.sys_info.children?.find((child) => child.id === childDevice.id)?.state;
41
+ this.log.debug(`Current State of On is: ${childState === 1 ? true : false} for ${childDevice.alias}`);
42
+ return childState ?? 0;
43
+ }
44
+ return 0;
45
+ })
46
+ .onSet(async (value) => {
47
+ this.log.info(`Setting On to: ${value} for ${childDevice.alias}`);
48
+ const childNumber = (parseInt(childDevice.id.replace(this.id, ''), 10));
49
+ if (typeof value === 'boolean' && value === true) {
50
+ this.deviceManager.turnOnChild(this, childNumber).catch(this.logRejection.bind(this));
51
+ return;
52
+ }
53
+ else if (typeof value === 'boolean' && value === false) {
54
+ this.deviceManager.turnOffChild(this, childNumber).catch(this.logRejection.bind(this));
55
+ return;
56
+ }
57
+ this.log.warn('setValue: Invalid On:', value);
58
+ 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;
73
+ }
74
+ addOutletInUseCharacteristic(outletService, childDevice) {
75
+ const outletInUseCharacteristic = getOrAddCharacteristic(outletService, this.platform.Characteristic.OutletInUse);
76
+ outletInUseCharacteristic.onGet(async () => {
77
+ const device = await this.getSysInfo().catch(this.logRejection.bind(this));
78
+ if (device) {
79
+ const childState = device.sys_info.children?.find((child) => child.id === childDevice.id)?.state;
80
+ this.log.debug(`Current State of Outlet In Use is: ${childState === 1 ? true : false} for ${childDevice.alias}`);
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;
89
+ if (device) {
90
+ newChildState = device.sys_info.children?.find((child) => child.id === childDevice.id)?.state;
91
+ }
92
+ if (newChildState !== undefined && newChildState !== oldChildState) {
93
+ this.updateChildValue(outletService, outletInUseCharacteristic, newChildState, childDevice.alias);
94
+ oldChildState = newChildState;
95
+ }
96
+ }, this.config.discoveryOptions.pollingInterval);
97
+ return outletService;
98
+ }
99
+ identify() {
100
+ this.log.info('identify');
101
+ }
102
+ }
103
+ //# sourceMappingURL=homekitPowerstrip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"homekitPowerstrip.js","sourceRoot":"","sources":["../../src/devices/homekitPowerstrip.ts"],"names":[],"mappings":"AAGA,OAAO,aAAa,MAAM,YAAY,CAAC;AAKvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAItE,MAAM,CAAC,OAAO,OAAO,uBAAwB,SAAQ,aAAa;IAGrD;IAIA;IACA;IAPX,YACE,QAA4B,EACnB,MAAwB,EACjC,mBAEa,EACJ,UAAsB,EACtB,YAA0B,EACnC,aAA6B;QAE7B,KAAK,CACH,QAAQ,EACR,MAAM,EACN,mBAAmB,EACnB,UAAU,6BAEV,YAAY,EACZ,aAAa,CACd,CAAC;QAhBO,WAAM,GAAN,MAAM,CAAk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AAC;gBACnE,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,yBAAyB,EAAE,aAAa,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC;gBAClG,aAAa,GAAG,aAAa,CAAC;YAChC,CAAC;QACH,CAAC,EAAE,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;QAGjD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import type { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service, WithUUID } from 'homebridge';
2
+ import type { KasaPythonConfig } from '../config.js';
3
+ import DeviceManager from './deviceManager.js';
4
+ import type KasaPythonPlatform from '../platform.js';
5
+ import type { KasaPythonAccessoryContext } from '../platform.js';
6
+ import type { KasaDevice } from '../utils.js';
7
+ import type { DeviceConfig } from './kasaDevices.js';
8
+ export default abstract class HomekitDevice {
9
+ readonly platform: KasaPythonPlatform;
10
+ readonly config: KasaPythonConfig;
11
+ readonly kasaDevice: KasaDevice;
12
+ readonly category: Categories;
13
+ readonly log: Logger;
14
+ protected deviceManager: DeviceManager;
15
+ homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
16
+ readonly deviceConfig: DeviceConfig;
17
+ private lsc;
18
+ /**
19
+ * Creates an instance of HomeKitDevice.
20
+ */
21
+ constructor(platform: KasaPythonPlatform, config: KasaPythonConfig, homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext> | undefined, kasaDevice: KasaDevice, category: Categories, deviceConfig: DeviceConfig, deviceManager?: DeviceManager);
22
+ get id(): string;
23
+ get name(): string;
24
+ get manufacturer(): string;
25
+ get model(): string;
26
+ get serialNumber(): string;
27
+ get firmwareRevision(): string;
28
+ get hardwareRevision(): string;
29
+ abstract identify(): void;
30
+ updateValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError): void;
31
+ updateChildValue(service: Service, characteristic: Characteristic, value: Nullable<CharacteristicValue> | Error | HapStatusError, childDeviceAlias: string): void;
32
+ addService(serviceConstructor: typeof this.platform.Service.Outlet | typeof this.platform.Service.Lightbulb, name: string, subType?: string): Service;
33
+ protected logRejection(reason: unknown): void;
34
+ protected removeServiceIfExists(service: WithUUID<typeof Service>): void;
35
+ protected removeCharacteristicIfExists(service: Service, characteristic: WithUUID<new () => Characteristic>): void;
36
+ }
@@ -0,0 +1,118 @@
1
+ import chalk from 'chalk';
2
+ import AccessoryInformation from '../accessoryInformation.js';
3
+ import DeviceManager from './deviceManager.js';
4
+ import { prefixLogger } from '../utils.js';
5
+ export default class HomekitDevice {
6
+ platform;
7
+ config;
8
+ kasaDevice;
9
+ category;
10
+ log;
11
+ deviceManager;
12
+ homebridgeAccessory;
13
+ deviceConfig;
14
+ lsc;
15
+ /**
16
+ * Creates an instance of HomeKitDevice.
17
+ */
18
+ constructor(platform, config, homebridgeAccessory, kasaDevice, category, deviceConfig, deviceManager) {
19
+ this.platform = platform;
20
+ this.config = config;
21
+ this.kasaDevice = kasaDevice;
22
+ this.category = category;
23
+ this.deviceConfig = deviceConfig;
24
+ this.deviceManager = deviceManager ? deviceManager : new DeviceManager(platform);
25
+ this.log = prefixLogger(platform.log, () => `${chalk.blue(`[${this.name}]`)}`);
26
+ this.lsc = this.platform.lsc.bind(this.platform);
27
+ const categoryName = platform.getCategoryName(category) ?? '';
28
+ if (homebridgeAccessory === null || homebridgeAccessory === undefined) {
29
+ const uuid = platform.api.hap.uuid.generate(this.id);
30
+ this.log.debug(`Creating new Accessory [${this.id}] [${uuid}] category: ${categoryName}`);
31
+ this.homebridgeAccessory = new platform.api.platformAccessory(this.name, uuid, category);
32
+ this.homebridgeAccessory.context.deviceId = this.id;
33
+ this.platform.registerPlatformAccessory(this.homebridgeAccessory);
34
+ }
35
+ else {
36
+ this.homebridgeAccessory = homebridgeAccessory;
37
+ this.log.debug(`Existing Accessory found [${homebridgeAccessory.context.deviceId}] [${homebridgeAccessory.UUID}] category: ${categoryName}`);
38
+ this.homebridgeAccessory.displayName = this.name;
39
+ if (this.homebridgeAccessory.category !== category) {
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]);
45
+ }
46
+ const accInfo = AccessoryInformation(platform.api.hap)(this.homebridgeAccessory, this);
47
+ if (accInfo === null) {
48
+ this.log.error('Could not retrieve default AccessoryInformation');
49
+ }
50
+ // Remove Old Services
51
+ this.homebridgeAccessory.services.forEach((service) => {
52
+ if (service instanceof platform.Service.AccessoryInformation) {
53
+ return;
54
+ }
55
+ if (service instanceof platform.Service.Outlet) {
56
+ return;
57
+ }
58
+ this.log.warn(`Removing stale Service: ${this.lsc(service)} uuid:[%s] subtype:[%s]`, service.UUID, service.subtype || '');
59
+ this.homebridgeAccessory.removeService(service);
60
+ });
61
+ this.homebridgeAccessory.on("identify" /* PlatformAccessoryEvent.IDENTIFY */, () => {
62
+ this.identify();
63
+ });
64
+ }
65
+ get id() {
66
+ return this.kasaDevice.sys_info.deviceId;
67
+ }
68
+ get name() {
69
+ return this.kasaDevice.alias;
70
+ }
71
+ get manufacturer() {
72
+ return 'TP-Link';
73
+ }
74
+ get model() {
75
+ return this.kasaDevice.sys_info.model;
76
+ }
77
+ get serialNumber() {
78
+ return `${this.kasaDevice.sys_info.mac} ${this.kasaDevice.sys_info.deviceId}`;
79
+ }
80
+ get firmwareRevision() {
81
+ return this.kasaDevice.sys_info.sw_ver;
82
+ }
83
+ get hardwareRevision() {
84
+ return this.kasaDevice.sys_info.hw_ver;
85
+ }
86
+ updateValue(service, characteristic, value) {
87
+ this.log.debug(`Updating ${this.lsc(service, characteristic)} ${value}`);
88
+ characteristic.updateValue(value);
89
+ }
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
+ addService(serviceConstructor, name, subType) {
96
+ const serviceName = this.platform.getServiceName(serviceConstructor);
97
+ this.log.debug(`Creating new ${serviceName} Service on ${name}${subType ? ` [${subType}]` : ''}`);
98
+ return this.homebridgeAccessory.addService(serviceConstructor, name, subType);
99
+ }
100
+ logRejection(reason) {
101
+ this.log.error(JSON.stringify(reason));
102
+ }
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
+ }
118
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/devices/index.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,oBAAoB,MAAM,4BAA4B,CAAC;AAE9D,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C,MAAM,CAAC,OAAO,OAAgB,aAAa;IAkB9B;IACA;IAIA;IACA;IAvBF,GAAG,CAAS;IAEX,aAAa,CAAgB;IAEvC,mBAAmB,CAAgD;IAE1D,YA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,OAAO,CAAC,CAAC;QAClE,IAAI,YAAY,KAAK,IAAI,IAAI,YAAY,KAAK,SAAS,EAAE,CAAC;YACxD,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,2BAA2B,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,YAAY,EACtE,YAAY,CAAC,IAAI,CAClB,CAAC;YAEF,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAES,4BAA4B,CACpC,OAAgB,EAChB,cAAkD;QAElD,IACE,OAAO,CAAC,kBAAkB,CACxB,cAA4D,CAC7D,EACD,CAAC;YACD,MAAM,sBAAsB,GAAG,OAAO,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;YACzE,IAAI,CAAC,GAAG,CAAC,IAAI,CACX,kCAAkC,IAAI,CAAC,GAAG,CACxC,OAAO,EACP,sBAAsB,CACvB,YAAY,EACb,sBAAsB,CAAC,IAAI,CAC5B,CAAC;YAEF,OAAO,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ interface DeviceCommonInfo {
2
+ alias: string;
3
+ children?: ChildPlug[];
4
+ device_id: string;
5
+ host: string;
6
+ is_off: boolean;
7
+ is_on: boolean;
8
+ sys_info: SysInfo;
9
+ }
10
+ export interface SysInfo {
11
+ sw_ver: string;
12
+ hw_ver: string;
13
+ model: string;
14
+ deviceId: string;
15
+ mic_type: string;
16
+ mac: string;
17
+ led_off: number;
18
+ relay_state: number;
19
+ err_code: number;
20
+ children?: ChildPlug[];
21
+ child_num?: number;
22
+ }
23
+ export interface ChildPlug {
24
+ id: string;
25
+ state: number;
26
+ alias: string;
27
+ }
28
+ export interface DeviceConfig {
29
+ host: string;
30
+ timeout: number;
31
+ connection_type: {
32
+ device_family: string;
33
+ encryption_type: string;
34
+ };
35
+ uses_http: false;
36
+ }
37
+ export interface Plug extends DeviceCommonInfo {
38
+ children: ChildPlug[];
39
+ device_config: DeviceConfig;
40
+ }
41
+ export interface Powerstrip extends DeviceCommonInfo {
42
+ device_config: DeviceConfig;
43
+ sys_info: SysInfo & {
44
+ children: ChildPlug[];
45
+ child_num: number;
46
+ };
47
+ }
48
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kasaDevices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kasaDevices.js","sourceRoot":"","sources":["../../src/devices/kasaDevices.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { API } from 'homebridge';
2
+ declare const _default: (api: API) => void;
3
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { PLATFORM_NAME } from './settings.js';
2
+ import KasaPythonPlatform from './platform.js';
3
+ export default (api) => {
4
+ api.registerPlatform(PLATFORM_NAME, KasaPythonPlatform);
5
+ };
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,kBAAkB,MAAM,eAAe,CAAC;AAE/C,eAAe,CAAC,GAAQ,EAAQ,EAAE;IAChC,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC;AAC1D,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { Categories } from 'homebridge';
2
+ import type { API, Characteristic, DynamicPlatformPlugin, Logging, PlatformAccessory, PlatformConfig, Service, WithUUID } from 'homebridge';
3
+ import type { KasaPythonConfig } from './config.js';
4
+ import type { KasaDevice } from './utils.js';
5
+ export type KasaPythonAccessoryContext = {
6
+ deviceId?: string;
7
+ };
8
+ export default class KasaPythonPlatform implements DynamicPlatformPlugin {
9
+ readonly log: Logging;
10
+ readonly api: API;
11
+ readonly Service: typeof Service;
12
+ readonly Characteristic: typeof Characteristic;
13
+ config: KasaPythonConfig;
14
+ private readonly configuredAccessories;
15
+ private readonly homekitDevicesById;
16
+ readonly storagePath: string;
17
+ readonly venvPythonExecutable: string;
18
+ private deviceManager;
19
+ constructor(log: Logging, config: PlatformConfig, api: API);
20
+ /**
21
+ * Function invoked when checking python environment.
22
+ */
23
+ private checkPython;
24
+ /**
25
+ * Return string representation of Service/Characteristic for logging
26
+ *
27
+ * @internal
28
+ */
29
+ lsc(serviceOrCharacteristic: Service | Characteristic | {
30
+ UUID: string;
31
+ }, characteristic?: Characteristic | {
32
+ UUID: string;
33
+ }): string;
34
+ private createHomekitDevice;
35
+ getCategoryName(category: Categories): string | undefined;
36
+ getServiceName(service: {
37
+ UUID: string;
38
+ }): string | undefined;
39
+ getCharacteristicName(characteristic: WithUUID<{
40
+ name?: string;
41
+ displayName?: string;
42
+ }>): string | undefined;
43
+ /**
44
+ * Registers a Homebridge PlatformAccessory.
45
+ *
46
+ * Calls {@link external:homebridge.API#registerPlatformAccessories}
47
+ */
48
+ registerPlatformAccessory(platformAccessory: PlatformAccessory<KasaPythonAccessoryContext>): void;
49
+ /**
50
+ * Function invoked when homebridge tries to restore cached accessory
51
+ */
52
+ configureAccessory(accessory: PlatformAccessory<KasaPythonAccessoryContext>): void;
53
+ /**
54
+ * Adds a new device.
55
+ */
56
+ foundDevice(device: KasaDevice): void;
57
+ }