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.
Files changed (45) hide show
  1. package/README.md +21 -6
  2. package/config.schema.json +2 -33
  3. package/dist/accessoryInformation.d.ts +1 -1
  4. package/dist/accessoryInformation.js +14 -18
  5. package/dist/accessoryInformation.js.map +1 -1
  6. package/dist/categoriesParse.d.ts +8 -0
  7. package/dist/categoriesParse.js +44 -0
  8. package/dist/categoriesParse.js.map +1 -0
  9. package/dist/config.d.ts +12 -155
  10. package/dist/config.js +52 -100
  11. package/dist/config.js.map +1 -1
  12. package/dist/devices/create.d.ts +3 -9
  13. package/dist/devices/create.js +6 -7
  14. package/dist/devices/create.js.map +1 -1
  15. package/dist/devices/deviceManager.d.ts +6 -8
  16. package/dist/devices/deviceManager.js +47 -126
  17. package/dist/devices/deviceManager.js.map +1 -1
  18. package/dist/devices/homekitPlug.d.ts +10 -16
  19. package/dist/devices/homekitPlug.js +93 -74
  20. package/dist/devices/homekitPlug.js.map +1 -1
  21. package/dist/devices/homekitPowerstrip.d.ts +11 -17
  22. package/dist/devices/homekitPowerstrip.js +106 -73
  23. package/dist/devices/homekitPowerstrip.js.map +1 -1
  24. package/dist/devices/index.d.ts +12 -19
  25. package/dist/devices/index.js +44 -71
  26. package/dist/devices/index.js.map +1 -1
  27. package/dist/devices/kasaDevices.d.ts +4 -5
  28. package/dist/platform.d.ts +22 -29
  29. package/dist/platform.js +127 -131
  30. package/dist/platform.js.map +1 -1
  31. package/dist/python/kasaApi.py +109 -0
  32. package/dist/python/pythonChecker.d.ts +2 -2
  33. package/dist/python/pythonChecker.js +24 -89
  34. package/dist/python/pythonChecker.js.map +1 -1
  35. package/dist/utils.d.ts +3 -18
  36. package/dist/utils.js +72 -116
  37. package/dist/utils.js.map +1 -1
  38. package/package.json +20 -19
  39. package/requirements.txt +4 -1
  40. package/dist/python/discover.py +0 -38
  41. package/dist/python/getSysInfo.py +0 -39
  42. package/dist/python/turnOff.py +0 -20
  43. package/dist/python/turnOffChild.py +0 -22
  44. package/dist/python/turnOn.py +0 -20
  45. 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 { KasaPythonAccessoryContext } from '../platform.js';
7
- import type { DeviceConfig, Powerstrip } from './kasaDevices.js';
3
+ import type { Powerstrip } from './kasaDevices.js';
8
4
  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
- */
5
+ protected kasaDevice: Powerstrip;
18
6
  private getSysInfo;
19
- private addAndConfigureOutletService;
20
- private addOnCharacteristic;
21
- private addOutletInUseCharacteristic;
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
- deviceConfig;
7
- constructor(platform, config, homebridgeAccessory, kasaDevice, deviceConfig, deviceManager) {
8
- super(platform, config, homebridgeAccessory, kasaDevice, 7 /* Categories.OUTLET */, deviceConfig, deviceManager);
9
- this.config = config;
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.addAndConfigureOutletService(child, index);
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
- return Promise.resolve(await this.deviceManager.getSysInfo(this));
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.addOnCharacteristic(outletService, child);
31
- this.addOutletInUseCharacteristic(outletService, child);
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
- 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;
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
- 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;
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 if (typeof value === 'boolean' && value === false) {
54
- this.deviceManager.turnOffChild(this, childNumber).catch(this.logRejection.bind(this));
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
- 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;
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
- 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;
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
- }, this.config.discoveryOptions.pollingInterval);
97
- return outletService;
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;AAKvC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAItE,MAAM,CAAC,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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,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,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"}
@@ -1,36 +1,29 @@
1
- import type { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service, WithUUID } from 'homebridge';
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
- readonly config: KasaPythonConfig;
11
- readonly kasaDevice: KasaDevice;
8
+ protected kasaDevice: KasaDevice;
12
9
  readonly category: Categories;
13
10
  readonly log: Logger;
14
- protected deviceManager: DeviceManager;
15
- homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
11
+ readonly categoryName: string;
16
12
  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);
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
- 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;
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
  }
@@ -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
- deviceConfig;
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 = 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);
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 = 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]);
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)(this.homebridgeAccessory, this);
47
- if (accInfo === null) {
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
- // 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
- });
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} ${this.kasaDevice.sys_info.deviceId}`;
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
- 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}`);
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,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,YAAY,CAAe;IAE5B,GAAG,CAGC;IAEZ;;OAEG;IACH,YACW,QAA4B,EAC5B,MAAwB,EACjC,mBAEa,EACJ,UAAsB,EACtB,QAAoB,EAC7B,YAA0B,EAC1B,aAA6B;QARpB,aAAQ,GAAR,QAAQ,CAAoB;QAC5B,WAAM,GAAN,MAAM,CAAkB;QAIxB,eAAU,GAAV,UAAU,CAAY;QACtB,aAAQ,GAAR,QAAQ,CAAY;QAI7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjF,IAAI,CAAC,GAAG,GAAG,YAAY,CACrB,QAAQ,CAAC,GAAG,EACZ,GAAG,EAAE,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,CACxC,CAAC;QAEF,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,C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Q,CAAC,MAAM,CAAC;IACzC,CAAC;IAID,WAAW,CACT,OAAgB,EAChB,cAA8B,EAC9B,KAA6D,EAC7D,gBAAyB;QAEzB,MAAM,UAAU,GAAG,YAAY,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,EAAE;YACzE,GAAG,gBAAgB,CAAC,CAAC,CAAC,OAAO,gBAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,KAAK,EAAE,CAAC;QACrE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC3B,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,kBAAuD,EAAE,IAAY,EAAE,OAAgB;QAChG,MAAM,WAAW,GAAG,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;QACrE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,WAAW,eAAe,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClG,OAAO,IAAI,CAAC,mBAAmB,CAAC,UAAU,CAAC,kBAAkB,EAAE,IAAI,EAAE,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: false;
34
+ uses_http: boolean;
36
35
  }
37
36
  export interface Plug extends DeviceCommonInfo {
38
- children: ChildPlug[];
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 {};