@homebridge-plugins/homebridge-august 2.2.8-beta.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 (64) hide show
  1. package/.eslintrc.json +86 -0
  2. package/.github/FUNDING.yml +4 -0
  3. package/.github/ISSUE_TEMPLATE/bug-report.yml +97 -0
  4. package/.github/ISSUE_TEMPLATE/config.yml +8 -0
  5. package/.github/ISSUE_TEMPLATE/feature-request.yml +38 -0
  6. package/.github/ISSUE_TEMPLATE/support-request.yml +85 -0
  7. package/.github/ISSUE_TEMPLATE.md +48 -0
  8. package/.github/PULL_REQUEST_TEMPLATE/pull_request.md +27 -0
  9. package/.github/dependabot.yml +17 -0
  10. package/.github/labeler.yml +38 -0
  11. package/.github/npm-version-script-esm.js +85 -0
  12. package/.github/workflows/beta-release.yml +55 -0
  13. package/.github/workflows/build.yml +18 -0
  14. package/.github/workflows/changerelease.yml +11 -0
  15. package/.github/workflows/labeler.yml +9 -0
  16. package/.github/workflows/release-drafter.yml +14 -0
  17. package/.github/workflows/release.yml +35 -0
  18. package/.github/workflows/stale.yml +12 -0
  19. package/CHANGELOG.md +197 -0
  20. package/LICENSE +14 -0
  21. package/README.md +45 -0
  22. package/SECURITY.md +19 -0
  23. package/branding/Homebridge_x_August.svg +32 -0
  24. package/branding/icon.png +0 -0
  25. package/config.schema.json +489 -0
  26. package/dist/devices/device.d.ts +55 -0
  27. package/dist/devices/device.d.ts.map +1 -0
  28. package/dist/devices/device.js +219 -0
  29. package/dist/devices/device.js.map +1 -0
  30. package/dist/devices/lock.d.ts +44 -0
  31. package/dist/devices/lock.d.ts.map +1 -0
  32. package/dist/devices/lock.js +353 -0
  33. package/dist/devices/lock.js.map +1 -0
  34. package/dist/homebridge-ui/public/index.html +203 -0
  35. package/dist/homebridge-ui/server.d.ts +2 -0
  36. package/dist/homebridge-ui/server.d.ts.map +1 -0
  37. package/dist/homebridge-ui/server.js +47 -0
  38. package/dist/homebridge-ui/server.js.map +1 -0
  39. package/dist/index.d.ts +4 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +11 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/platform.d.ts +91 -0
  44. package/dist/platform.d.ts.map +1 -0
  45. package/dist/platform.js +481 -0
  46. package/dist/platform.js.map +1 -0
  47. package/dist/settings.d.ts +177 -0
  48. package/dist/settings.d.ts.map +1 -0
  49. package/dist/settings.js +9 -0
  50. package/dist/settings.js.map +1 -0
  51. package/docs/.nojekyll +1 -0
  52. package/docs/assets/highlight.css +22 -0
  53. package/docs/assets/icons.js +18 -0
  54. package/docs/assets/icons.svg +1 -0
  55. package/docs/assets/main.js +60 -0
  56. package/docs/assets/navigation.js +1 -0
  57. package/docs/assets/search.js +1 -0
  58. package/docs/assets/style.css +1493 -0
  59. package/docs/functions/default.html +1 -0
  60. package/docs/index.html +39 -0
  61. package/docs/modules.html +2 -0
  62. package/eslint.config.js +50 -0
  63. package/package.json +92 -0
  64. package/typedoc.json +17 -0
@@ -0,0 +1,219 @@
1
+ export class deviceBase {
2
+ platform;
3
+ accessory;
4
+ device;
5
+ api;
6
+ log;
7
+ config;
8
+ hap;
9
+ // Config
10
+ deviceLogging;
11
+ deviceRefreshRate;
12
+ deviceUpdateRate;
13
+ devicePushRate;
14
+ constructor(platform, accessory, device) {
15
+ this.platform = platform;
16
+ this.accessory = accessory;
17
+ this.device = device;
18
+ this.api = this.platform.api;
19
+ this.log = this.platform.log;
20
+ this.config = this.platform.config;
21
+ this.hap = this.api.hap;
22
+ this.getDeviceLogSettings(accessory, device);
23
+ this.getDeviceRateSettings(accessory, device);
24
+ this.getDeviceConfigSettings(accessory, device);
25
+ this.getDeviceContext(accessory, device);
26
+ // Set accessory information
27
+ accessory
28
+ .getService(this.hap.Service.AccessoryInformation)
29
+ .setCharacteristic(this.hap.Characteristic.Manufacturer, 'August Home Inc.')
30
+ .setCharacteristic(this.hap.Characteristic.AppMatchingIdentifier, 'id648730592')
31
+ .setCharacteristic(this.hap.Characteristic.Name, accessory.displayName)
32
+ .setCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName)
33
+ .setCharacteristic(this.hap.Characteristic.Model, device.skuNumber)
34
+ .setCharacteristic(this.hap.Characteristic.ProductData, device.lockId)
35
+ .setCharacteristic(this.hap.Characteristic.SerialNumber, device.SerialNumber);
36
+ }
37
+ async getDeviceLogSettings(accessory, device) {
38
+ this.deviceLogging = this.platform.debugMode ? 'debugMode' : device.logging ?? this.platform.platformLogging ?? 'standard';
39
+ const logging = this.platform.debugMode
40
+ ? 'debugMode'
41
+ : device.logging
42
+ ? 'Device Config'
43
+ : this.platform.platformLogging
44
+ ? 'Platform Confg'
45
+ : 'Default';
46
+ accessory.context.logging = this.deviceLogging;
47
+ await this.debugLog(`Using ${logging} Logging: ${this.deviceLogging}`);
48
+ }
49
+ async getDeviceRateSettings(accessory, device) {
50
+ // refreshRate
51
+ this.deviceRefreshRate = device.refreshRate === 0 ? 0 : device.refreshRate ?? this.platform.platformRefreshRate ?? 30;
52
+ const refreshRate = device.refreshRate === 0
53
+ ? 'Disabled'
54
+ : device.refreshRate
55
+ ? 'Device Config'
56
+ : this.platform.platformRefreshRate
57
+ ? 'Platform Config'
58
+ : 'Default';
59
+ accessory.context.deviceRefreshRate = this.deviceRefreshRate;
60
+ await this.debugLog(`Using ${refreshRate} refreshRate`);
61
+ // updateRate
62
+ this.deviceUpdateRate = device.updateRate ?? this.platform.platformUpdateRate ?? 5;
63
+ const updateRate = device.updateRate ? 'Device Config' : this.platform.platformUpdateRate ? 'Platform Config' : 'Default';
64
+ accessory.context.deviceUpdateRate = this.deviceUpdateRate;
65
+ await this.debugLog(`Using ${updateRate} updateRate`);
66
+ // pushRate
67
+ this.devicePushRate = device.pushRate ?? this.platform.platformPushRate ?? 1;
68
+ const pushRate = device.pushRate ? 'Device Config' : this.platform.platformPushRate ? 'Platform Config' : 'Default';
69
+ accessory.context.devicePushRate = this.devicePushRate;
70
+ await this.debugLog(`Using ${pushRate} pushRate`);
71
+ }
72
+ async getDeviceConfigSettings(accessory, device) {
73
+ const deviceConfig = {
74
+ ...(device.logging && device.logging !== 'standard' && { logging: device.logging }),
75
+ ...(device.refreshRate !== undefined && { refreshRate: device.refreshRate }),
76
+ ...(device.overrideHomeKitEnabled === true && { overrideHomeKitEnabled: device.overrideHomeKitEnabled }),
77
+ ...(device.updateRate !== undefined && { updateRate: device.updateRate }),
78
+ ...(device.pushRate !== undefined && { pushRate: device.pushRate }),
79
+ ...(device.lock?.hide_contactsensor === true && { hide_contactsensor: device.lock.hide_contactsensor }),
80
+ ...(device.lock?.hide_lock === true && { hide_lock: device.lock.hide_lock }),
81
+ };
82
+ if (Object.keys(deviceConfig).length) {
83
+ await this.debugSuccessLog(`Config: ${JSON.stringify(deviceConfig)}`);
84
+ }
85
+ }
86
+ async getDeviceContext(accessory, device) {
87
+ // Firmware Version
88
+ const deviceFirmwareVersion = device.firmware ?? device.currentFirmwareVersion ?? this.platform.version ?? '0.0.0';
89
+ const version = deviceFirmwareVersion.toString();
90
+ await this.debugLog(`${this.device.Type}: ${accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
91
+ let deviceVersion;
92
+ if (version?.includes('.') === false) {
93
+ const replace = version?.replace(/^V|-.*$/g, '');
94
+ const match = replace?.match(/./g);
95
+ const validVersion = match?.join('.');
96
+ deviceVersion = validVersion ?? '0.0.0';
97
+ }
98
+ else {
99
+ deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
100
+ }
101
+ accessory
102
+ .getService(this.hap.Service.AccessoryInformation)
103
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
104
+ .setCharacteristic(this.hap.Characteristic.SoftwareRevision, deviceVersion)
105
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
106
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
107
+ .updateValue(deviceVersion);
108
+ accessory.context.deviceVersion = deviceVersion;
109
+ await this.debugSuccessLog(`deviceVersion: ${accessory.context.deviceVersion}`);
110
+ }
111
+ /**
112
+ * Updates the value of a HomeKit characteristic and logs the change.
113
+ *
114
+ * This function updates the specified characteristic of a given service with a new value.
115
+ * It also logs the updated value and the context before and after the update for debugging purposes.
116
+ *
117
+ * @param Service - The HomeKit service that contains the characteristic to be updated.
118
+ * @param ServiceName - The name of the service being updated.
119
+ * @param Characteristic - The specific characteristic to be updated.
120
+ * @param CharacteristicValue - The new value to set for the characteristic. If undefined, the function logs the value and returns without updating.
121
+ * @param CharacteristicName - The name of the characteristic being updated, used for logging purposes.
122
+ * @param Value - The value to compare against to determine the status.
123
+ * @param StatusMatch - The status message to log if the characteristic value matches the provided value.
124
+ * @param StatusDoesNotMatch - The status message to log if the chxaracteristic value does not match the provided value.
125
+ * @return void
126
+ */
127
+ async updateCharacteristic(Service, ServiceName, Characteristic, CharacteristicValue, CharacteristicName, Value, StatusMatch, StatusDoesNotMatch) {
128
+ if (CharacteristicValue === undefined) {
129
+ await this.debugLog(`${CharacteristicName}: ${CharacteristicValue}`);
130
+ }
131
+ else {
132
+ Service.updateCharacteristic(Characteristic, CharacteristicValue);
133
+ await this.debugLog(`updateCharacteristic ${CharacteristicName}: ${CharacteristicValue} (${CharacteristicValue === Value ? StatusMatch : StatusDoesNotMatch})`);
134
+ await this.debugWarnLog(`context before: ${this.accessory.context[ServiceName[CharacteristicName]]}`);
135
+ const contextBefore = this.accessory.context[ServiceName[CharacteristicName]];
136
+ this.accessory.context[ServiceName[CharacteristicName]] = CharacteristicValue;
137
+ await this.debugWarnLog(`context after: ${this.accessory.context[ServiceName[CharacteristicName]]}`);
138
+ if ((contextBefore !== this.accessory.context[ServiceName[CharacteristicName]]) && StatusMatch && StatusDoesNotMatch) {
139
+ await this.infoLog(`was ${CharacteristicValue === Value ? StatusMatch : StatusDoesNotMatch}`);
140
+ }
141
+ }
142
+ }
143
+ async statusCode(action, error) {
144
+ const statusCodeString = error.message; // Convert statusCode to a string
145
+ const logMap = {
146
+ 100: `Command successfully sent, statusCode: ${statusCodeString}`,
147
+ 200: `Request successful, statusCode: ${statusCodeString}`,
148
+ 400: `Bad Request, statusCode: ${statusCodeString}`,
149
+ 429: `Too Many Requests, exceeded the number of requests allowed for a given time window, statusCode: ${statusCodeString}`,
150
+ };
151
+ const logMessage = logMap[statusCodeString.slice(0, 3)]
152
+ ?? `Unknown statusCode: ${statusCodeString}, Submit Bugs Here: https://tinyurl.com/AugustYaleBug`;
153
+ await this.debugLog(logMessage);
154
+ if (!logMap[statusCodeString.slice(0, 3)]) {
155
+ await this.debugErrorLog(`failed ${action}, Error: ${error}`);
156
+ }
157
+ }
158
+ /**
159
+ * Logging for Device
160
+ */
161
+ async infoLog(...log) {
162
+ if (await this.enablingDeviceLogging()) {
163
+ this.log.info(`Lock: ${this.accessory.displayName}`, String(...log));
164
+ }
165
+ }
166
+ async successLog(...log) {
167
+ if (await this.enablingDeviceLogging()) {
168
+ this.log.success(`Lock: ${this.accessory.displayName}`, String(...log));
169
+ }
170
+ }
171
+ async debugSuccessLog(...log) {
172
+ if (await this.enablingDeviceLogging()) {
173
+ if (await this.loggingIsDebug()) {
174
+ this.log.success(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
175
+ }
176
+ }
177
+ }
178
+ async warnLog(...log) {
179
+ if (await this.enablingDeviceLogging()) {
180
+ this.log.warn(`Lock: ${this.accessory.displayName}`, String(...log));
181
+ }
182
+ }
183
+ async debugWarnLog(...log) {
184
+ if (await this.enablingDeviceLogging()) {
185
+ if (await this.loggingIsDebug()) {
186
+ this.log.warn(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
187
+ }
188
+ }
189
+ }
190
+ async errorLog(...log) {
191
+ if (await this.enablingDeviceLogging()) {
192
+ this.log.error(`Lock: ${this.accessory.displayName}`, String(...log));
193
+ }
194
+ }
195
+ async debugErrorLog(...log) {
196
+ if (await this.enablingDeviceLogging()) {
197
+ if (await this.loggingIsDebug()) {
198
+ this.log.error(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
199
+ }
200
+ }
201
+ }
202
+ async debugLog(...log) {
203
+ if (await this.enablingDeviceLogging()) {
204
+ if (this.deviceLogging === 'debug') {
205
+ this.log.info(`[DEBUG] Lock: ${this.accessory.displayName}`, String(...log));
206
+ }
207
+ else if (this.deviceLogging === 'debugMode') {
208
+ this.log.debug(`Lock: ${this.accessory.displayName}`, String(...log));
209
+ }
210
+ }
211
+ }
212
+ async loggingIsDebug() {
213
+ return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug';
214
+ }
215
+ async enablingDeviceLogging() {
216
+ return this.deviceLogging === 'debugMode' || this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
217
+ }
218
+ }
219
+ //# sourceMappingURL=device.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device.js","sourceRoot":"","sources":["../../src/devices/device.ts"],"names":[],"mappings":"AASA,MAAM,OAAgB,UAAU;IAaT;IACT;IACA;IAdI,GAAG,CAAK;IACR,GAAG,CAAS;IACZ,MAAM,CAAuB;IAC1B,GAAG,CAAK;IAE3B,SAAS;IACC,aAAa,CAAS;IACtB,iBAAiB,CAAS;IAC1B,gBAAgB,CAAS;IACzB,cAAc,CAAS;IAEjC,YACqB,QAAwB,EACjC,SAA4B,EAC5B,MAA8B;QAFrB,aAAQ,GAAR,QAAQ,CAAgB;QACjC,cAAS,GAAT,SAAS,CAAmB;QAC5B,WAAM,GAAN,MAAM,CAAwB;QAExC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAA;QAC5B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAA;QAClC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,CAAA;QAEvB,IAAI,CAAC,oBAAoB,CAAC,SAAS,EAAE,M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,CAAC;gBACnC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;YAC9E,CAAC;iBAAM,IAAI,IAAI,CAAC,aAAa,KAAK,WAAW,EAAE,CAAC;gBAC9C,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;YACvE,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,cAAc;QAClB,OAAO,IAAI,CAAC,aAAa,KAAK,WAAW,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,CAAA;IAC7E,CAAC;IAED,KAAK,CAAC,qBAAqB;QACzB,OAAO,IAAI,CAAC,aAAa,KAAK,WAAW,IAAI,IAAI,CAAC,aAAa,KAAK,OAAO,IAAI,IAAI,CAAC,aAAa,KAAK,UAAU,CAAA;IAClH,CAAC;CACF"}
@@ -0,0 +1,44 @@
1
+ import type { CharacteristicValue, PlatformAccessory } from 'homebridge';
2
+ import type { AugustPlatform } from '../platform.js';
3
+ import type { device, devicesConfig, lockDetails, lockEvent, lockStatus } from '../settings.js';
4
+ import { deviceBase } from './device.js';
5
+ /**
6
+ * Platform Accessory
7
+ * An instance of this class is created for each accessory your platform registers
8
+ * Each accessory may expose multiple services of different service types.
9
+ */
10
+ export declare class LockMechanism extends deviceBase {
11
+ readonly platform: AugustPlatform;
12
+ private LockMechanism?;
13
+ private Battery;
14
+ private ContactSensor?;
15
+ lockEvent: lockEvent;
16
+ lockStatus: lockStatus;
17
+ lockDetails: lockDetails;
18
+ lockUpdateInProgress: boolean;
19
+ doLockUpdate: any;
20
+ constructor(platform: AugustPlatform, accessory: PlatformAccessory, device: device & devicesConfig);
21
+ /**
22
+ * Parse the device status from the August api
23
+ */
24
+ parseStatus(): Promise<void>;
25
+ /**
26
+ * Parse the device status from the August api
27
+ */
28
+ parseEventStatus(): Promise<void>;
29
+ /**
30
+ * Asks the August Home API for the latest device information
31
+ */
32
+ refreshStatus(): Promise<void>;
33
+ /**
34
+ * Pushes the requested changes to the August API
35
+ */
36
+ pushChanges(): Promise<void>;
37
+ /**
38
+ * Updates the status for each of the HomeKit Characteristics
39
+ */
40
+ updateHomeKitCharacteristics(): Promise<void>;
41
+ setLockTargetState(value: CharacteristicValue): Promise<void>;
42
+ subscribeAugust(): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../src/devices/lock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAW,MAAM,YAAY,CAAA;AAEjF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAU/F,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,UAAU;IAiCzC,QAAQ,CAAC,QAAQ,EAAE,cAAc;IA/BnC,OAAO,CAAC,aAAa,CAAC,CAKrB;IAED,OAAO,CAAC,OAAO,CAMd;IAED,OAAO,CAAC,aAAa,CAAC,CAIrB;IAGD,SAAS,EAAG,SAAS,CAAA;IACrB,UAAU,EAAG,UAAU,CAAA;IACvB,WAAW,EAAG,WAAW,CAAA;IAGzB,oBAAoB,EAAE,OAAO,CAAA;IAC7B,YAAY,EAAE,GAAG,CAAA;gBAGN,QAAQ,EAAE,cAAc,EACjC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GAAG,aAAa;IAuHhC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA4DlC;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IAyCvC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBpC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BlC;;OAEG;IACG,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC;IAqB7C,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAc7D,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;CAevC"}
@@ -0,0 +1,353 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * lock.ts: homebridge-august.
4
+ */
5
+ import August from 'august-yale';
6
+ import { interval, Subject } from 'rxjs';
7
+ import { debounceTime, skipWhile, tap } from 'rxjs/operators';
8
+ import { deviceBase } from './device.js';
9
+ /**
10
+ * Platform Accessory
11
+ * An instance of this class is created for each accessory your platform registers
12
+ * Each accessory may expose multiple services of different service types.
13
+ */
14
+ export class LockMechanism extends deviceBase {
15
+ platform;
16
+ // Service
17
+ LockMechanism;
18
+ Battery;
19
+ ContactSensor;
20
+ // Lock Mechanism
21
+ lockEvent;
22
+ lockStatus;
23
+ lockDetails;
24
+ // Lock Updates
25
+ lockUpdateInProgress;
26
+ doLockUpdate;
27
+ constructor(platform, accessory, device) {
28
+ super(platform, accessory, device);
29
+ this.platform = platform;
30
+ // this is subject we use to track when we need to POST changes to the August API
31
+ this.doLockUpdate = new Subject();
32
+ this.lockUpdateInProgress = false;
33
+ // Initialize Lock Mechanism Service
34
+ if (device.lock?.hide_lock) {
35
+ if (this.LockMechanism?.Service) {
36
+ this.debugLog('Removing Lock Mechanism Service');
37
+ this.LockMechanism.Service = accessory.getService(this.hap.Service.LockMechanism);
38
+ accessory.removeService(this.LockMechanism.Service);
39
+ accessory.context.LockMechanism = {};
40
+ }
41
+ }
42
+ else {
43
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
44
+ this.LockMechanism = {
45
+ Name: accessory.displayName,
46
+ Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism),
47
+ LockTargetState: accessory.context.LockTargetState ?? this.hap.Characteristic.LockTargetState.SECURED,
48
+ LockCurrentState: accessory.context.LockCurrentState ?? this.hap.Characteristic.LockCurrentState.SECURED,
49
+ };
50
+ accessory.context.LockMechanism = this.LockMechanism;
51
+ // Initialize Lock Mechanism Characteristics
52
+ this.LockMechanism.Service
53
+ .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
54
+ .getCharacteristic(this.hap.Characteristic.LockTargetState)
55
+ .onGet(() => {
56
+ return this.LockMechanism.LockTargetState;
57
+ })
58
+ .onSet(this.setLockTargetState.bind(this));
59
+ }
60
+ // Initialize Contact Sensor Service
61
+ if (device.lock?.hide_contactsensor) {
62
+ if (this.ContactSensor?.Service) {
63
+ this.debugLog('Removing Conact Sensor Service');
64
+ this.ContactSensor.Service = accessory.getService(this.hap.Service.ContactSensor);
65
+ accessory.removeService(this.ContactSensor.Service);
66
+ accessory.context.ContactSensor = {};
67
+ }
68
+ }
69
+ else {
70
+ accessory.context.ContactSensor = accessory.context.ContactSensor ?? {};
71
+ this.ContactSensor = {
72
+ Name: `${accessory.displayName} Contact Sensor`,
73
+ Service: accessory.getService(this.hap.Service.ContactSensor) ?? accessory.addService(this.hap.Service.ContactSensor),
74
+ ContactSensorState: accessory.context.ContactSensorState ?? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED,
75
+ };
76
+ accessory.context.ContactSensor = this.ContactSensor;
77
+ // Initialize Conact Sensor Characteristics
78
+ this.ContactSensor.Service
79
+ .setCharacteristic(this.hap.Characteristic.Name, this.ContactSensor.Name)
80
+ .getCharacteristic(this.hap.Characteristic.ContactSensorState)
81
+ .onGet(() => {
82
+ return this.ContactSensor.ContactSensorState;
83
+ });
84
+ }
85
+ // Initialize Battery Service
86
+ accessory.context.Battery = accessory.context.Battery ?? {};
87
+ this.Battery = {
88
+ Name: `${accessory.displayName} Battery`,
89
+ Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
90
+ BatteryLevel: accessory.context.BatteryLevel ?? 100,
91
+ StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
92
+ ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGING,
93
+ };
94
+ accessory.context.Battery = this.Battery;
95
+ // Initialize Battery Characteristics
96
+ this.Battery.Service
97
+ .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
98
+ .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
99
+ .getCharacteristic(this.hap.Characteristic.BatteryLevel)
100
+ .onGet(() => {
101
+ return this.Battery.BatteryLevel;
102
+ });
103
+ this.Battery.Service
104
+ .getCharacteristic(this.hap.Characteristic.StatusLowBattery)
105
+ .onGet(() => {
106
+ return this.Battery.StatusLowBattery;
107
+ });
108
+ // Initial Device Refresh
109
+ this.refreshStatus();
110
+ // Subscribe to august changes
111
+ this.subscribeAugust();
112
+ // Start an update interval
113
+ interval(this.deviceRefreshRate * 1000)
114
+ .pipe(skipWhile(() => this.lockUpdateInProgress))
115
+ .subscribe(async () => {
116
+ await this.refreshStatus();
117
+ });
118
+ // Watch for Lock change events
119
+ // We put in a debounce of 100ms so we don't make duplicate calls
120
+ if (!device.lock?.hide_lock) {
121
+ this.doLockUpdate
122
+ .pipe(tap(() => {
123
+ this.lockUpdateInProgress = true;
124
+ }), debounceTime(this.devicePushRate * 1000))
125
+ .subscribe(async () => {
126
+ try {
127
+ await this.pushChanges();
128
+ }
129
+ catch (e) {
130
+ await this.statusCode('pushChanges', e);
131
+ await this.errorLog(`doLockUpdate pushChanges: ${e}`);
132
+ }
133
+ this.lockUpdateInProgress = false;
134
+ });
135
+ }
136
+ }
137
+ /**
138
+ * Parse the device status from the August api
139
+ */
140
+ async parseStatus() {
141
+ await this.debugLog('parseStatus');
142
+ const retryCount = 1;
143
+ if (this.lockStatus) {
144
+ // Lock Mechanism
145
+ this.platform.augustConfig.addSimpleProps(this.lockStatus);
146
+ if (this.LockMechanism && (this.lockStatus.state.unlocking || this.lockStatus.state.locking)) {
147
+ await this.warnLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}, locking/unlocking parseStatus`
148
+ + ` lockEvent: ${JSON.stringify(this.lockEvent)}`);
149
+ }
150
+ if (!this.device.lock?.hide_lock && this.LockMechanism?.Service && (this.lockEvent.state.locked !== this.lockEvent.state.unlocked)) {
151
+ this.LockMechanism.LockCurrentState = this.lockStatus.state.locked
152
+ ? this.hap.Characteristic.LockCurrentState.SECURED
153
+ : this.lockStatus.state.unlocked
154
+ ? this.hap.Characteristic.LockCurrentState.UNSECURED
155
+ : retryCount > 1 ? this.hap.Characteristic.LockCurrentState.JAMMED : this.hap.Characteristic.LockCurrentState.UNKNOWN;
156
+ if (this.LockMechanism.LockCurrentState === this.hap.Characteristic.LockCurrentState.UNKNOWN) {
157
+ await this.warnLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}, (UNKNOWN) parseStatus`
158
+ + ` lockEvent: ${JSON.stringify(this.lockEvent)}`);
159
+ }
160
+ await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
161
+ }
162
+ // Contact Sensor
163
+ if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
164
+ // ContactSensorState
165
+ this.ContactSensor.ContactSensorState = this.lockStatus.state.open
166
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
167
+ : this.lockStatus.state.closed
168
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
169
+ : this.lockStatus.doorState.includes('open')
170
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
171
+ : this.lockStatus.doorState.includes('closed')
172
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
173
+ : this.ContactSensor.ContactSensorState;
174
+ await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
175
+ }
176
+ }
177
+ if (this.lockDetails) {
178
+ // BatteryLevel
179
+ this.Battery.BatteryLevel = Number((this.lockDetails.battery * 100).toFixed());
180
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
181
+ // StatusLowBattery
182
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 15
183
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
184
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
185
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
186
+ // Firmware Version
187
+ if (this.accessory.context.currentFirmwareVersion !== this.lockDetails.currentFirmwareVersion) {
188
+ await this.warnLog(`Firmware Version changed to Current Firmware Version: ${this.lockDetails.currentFirmwareVersion}`);
189
+ this.accessory
190
+ .getService(this.hap.Service.AccessoryInformation)
191
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, this.lockDetails.currentFirmwareVersion)
192
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.lockDetails.currentFirmwareVersion)
193
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
194
+ .updateValue(this.lockDetails.currentFirmwareVersion);
195
+ this.accessory.context.currentFirmwareVersion = this.lockDetails.currentFirmwareVersion;
196
+ }
197
+ }
198
+ }
199
+ /**
200
+ * Parse the device status from the August api
201
+ */
202
+ async parseEventStatus() {
203
+ await this.debugLog('parseEventStatus');
204
+ const retryCount = 1;
205
+ if (this.lockEvent) {
206
+ this.debugLog(`lockEvent: ${JSON.stringify(this.lockEvent)}`);
207
+ // Lock Mechanism
208
+ this.platform.augustConfig.addSimpleProps(this.lockEvent);
209
+ if (this.LockMechanism && (this.lockEvent.state.unlocking || this.lockEvent.state.locking)) {
210
+ await this.debugLog(`is ${this.lockEvent.state.unlocking ? 'Unlocking' : this.lockEvent.state.locking ? 'Locking' : ''}, parseEventStatus`
211
+ + ` lockEventState: ${JSON.stringify(this.lockEvent.state)}`);
212
+ return;
213
+ }
214
+ if (!this.device.lock?.hide_lock && this.LockMechanism?.Service && (this.lockEvent.state.locked !== this.lockEvent.state.unlocked)) {
215
+ this.LockMechanism.LockCurrentState = this.lockEvent.state.locked
216
+ ? this.hap.Characteristic.LockCurrentState.SECURED
217
+ : this.lockEvent.state.unlocked
218
+ ? this.hap.Characteristic.LockCurrentState.UNSECURED
219
+ : retryCount > 1 ? this.hap.Characteristic.LockCurrentState.JAMMED : this.hap.Characteristic.LockCurrentState.UNKNOWN;
220
+ if (this.LockMechanism.LockCurrentState === this.hap.Characteristic.LockCurrentState.UNKNOWN) {
221
+ await this.warnLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}, (UNKNOWN) parseEventStatus`
222
+ + ` lockEvent: ${JSON.stringify(this.lockEvent)}`);
223
+ }
224
+ await this.debugLog(`LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
225
+ }
226
+ // Contact Sensor
227
+ if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
228
+ // ContactSensorState
229
+ this.ContactSensor.ContactSensorState = this.lockEvent.state.open
230
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
231
+ : this.lockEvent.state.closed
232
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
233
+ : this.lockEvent.doorState === 'open'
234
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
235
+ : this.lockEvent.doorState === 'closed'
236
+ ? this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
237
+ : this.ContactSensor.ContactSensorState;
238
+ await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`);
239
+ }
240
+ }
241
+ }
242
+ /**
243
+ * Asks the August Home API for the latest device information
244
+ */
245
+ async refreshStatus() {
246
+ if (this.deviceRefreshRate !== 0) {
247
+ try {
248
+ // Update Lock Details
249
+ const lockDetails = await this.platform.augustConfig.details(this.device.lockId);
250
+ await this.debugSuccessLog(`(refreshStatus) lockDetails: ${JSON.stringify(lockDetails)}`);
251
+ // Update HomeKit
252
+ this.lockDetails = lockDetails;
253
+ this.lockStatus = lockDetails.LockStatus;
254
+ await this.parseStatus();
255
+ await this.updateHomeKitCharacteristics();
256
+ }
257
+ catch (e) {
258
+ await this.statusCode('(refreshStatus) lockDetails', e);
259
+ await this.errorLog(`pushChanges: ${e.message}`);
260
+ }
261
+ }
262
+ else {
263
+ await this.debugLog();
264
+ }
265
+ }
266
+ /**
267
+ * Pushes the requested changes to the August API
268
+ */
269
+ async pushChanges() {
270
+ try {
271
+ // await this.platform.augustCredentials();
272
+ if (this.LockMechanism) {
273
+ if (this.LockMechanism.LockTargetState !== this.LockMechanism.LockCurrentState) {
274
+ if (this.LockMechanism.LockTargetState === this.hap.Characteristic.LockTargetState.UNSECURED) {
275
+ await this.platform.augustConfig.unlock(this.device.lockId);
276
+ }
277
+ else {
278
+ await this.platform.augustConfig.lock(this.device.lockId);
279
+ }
280
+ await this.successLog(`Sending request to August API: ${this.LockMechanism.LockTargetState === 1 ? 'Locked' : 'Unlocked'}`);
281
+ }
282
+ else {
283
+ await this.debugLog(`No changes, LockTargetState: ${this.LockMechanism.LockTargetState},`
284
+ + ` LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
285
+ this.LockMechanism.LockTargetState = this.LockMechanism.LockCurrentState === this.hap.Characteristic.LockCurrentState.SECURED
286
+ ? this.hap.Characteristic.LockTargetState.SECURED
287
+ : this.hap.Characteristic.LockTargetState.UNSECURED;
288
+ }
289
+ await this.updateHomeKitCharacteristics();
290
+ }
291
+ else {
292
+ await this.errorLog(`lockTargetState: ${JSON.stringify(this.LockMechanism)}`);
293
+ }
294
+ }
295
+ catch (e) {
296
+ await this.statusCode('pushChanges', e);
297
+ await this.debugLog(`pushChanges: ${e}`);
298
+ }
299
+ }
300
+ /**
301
+ * Updates the status for each of the HomeKit Characteristics
302
+ */
303
+ async updateHomeKitCharacteristics() {
304
+ await this.debugLog('updateHomeKitCharacteristics');
305
+ // Lock Mechanism
306
+ if (!this.device.lock?.hide_lock && this.LockMechanism?.Service) {
307
+ // LockTargetState
308
+ await this.updateCharacteristic(this.LockMechanism.Service, 'LockMechanism', this.hap.Characteristic.LockTargetState, this.LockMechanism.LockTargetState, 'LockTargetState');
309
+ // LockCurrentState
310
+ await this.updateCharacteristic(this.LockMechanism.Service, 'LockMechanism', this.hap.Characteristic.LockCurrentState, this.LockMechanism.LockCurrentState, 'LockCurrentState', 1, 'Locked', 'Unlocked');
311
+ }
312
+ // Battery
313
+ // BatteryLevel
314
+ await this.updateCharacteristic(this.Battery.Service, 'Battery', this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel');
315
+ // StatusLowBattery
316
+ await this.updateCharacteristic(this.Battery.Service, 'Battery', this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery');
317
+ // Contact Sensor
318
+ if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
319
+ // ContactSensorState
320
+ await this.updateCharacteristic(this.ContactSensor.Service, 'ContactSensor', this.hap.Characteristic.ContactSensorState, this.ContactSensor.ContactSensorState, 'ContactSensorState', 1, 'Opened', 'Closed');
321
+ }
322
+ }
323
+ async setLockTargetState(value) {
324
+ if (this.LockMechanism) {
325
+ if (this.LockMechanism.LockTargetState !== this.LockMechanism.LockCurrentState) {
326
+ await this.debugLog(`Set LockTargetState: ${value}`);
327
+ }
328
+ else {
329
+ await this.debugLog(`No changes, LockTargetState: ${this.LockMechanism.LockTargetState},`
330
+ + ` LockCurrentState: ${this.LockMechanism.LockCurrentState}`);
331
+ }
332
+ this.accessory.context.LockTargetState = this.LockMechanism.LockTargetState = value;
333
+ this.doLockUpdate.next();
334
+ }
335
+ }
336
+ async subscribeAugust() {
337
+ await this.debugLog('subscribeAugust');
338
+ await this.platform.augustCredentials();
339
+ if (this.config.credentials) {
340
+ await August.subscribe(this.config.credentials, this.device.lockId, async (AugustEvent, timestamp) => {
341
+ await this.debugLog(`AugustEvent: ${JSON.stringify(AugustEvent)}, ${JSON.stringify(timestamp)}`);
342
+ // Update HomeKit
343
+ this.lockEvent = AugustEvent;
344
+ await this.parseEventStatus();
345
+ await this.updateHomeKitCharacteristics();
346
+ });
347
+ }
348
+ else {
349
+ await this.errorLog('subscribeAugust: No credentials');
350
+ }
351
+ }
352
+ }
353
+ //# sourceMappingURL=lock.js.map