homebridge-dummy 0.9.1 → 1.0.0-alpha.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/CHANGELOG.md +13 -2
- package/README.md +146 -81
- package/config.schema.json +150 -54
- package/dist/accessory/base.d.ts +23 -0
- package/dist/accessory/base.js +69 -0
- package/dist/accessory/base.js.map +1 -0
- package/dist/accessory/lightbulb.d.ts +15 -0
- package/dist/accessory/lightbulb.js +50 -0
- package/dist/accessory/lightbulb.js.map +1 -0
- package/dist/accessory/onoff.d.ts +16 -0
- package/dist/accessory/onoff.js +56 -0
- package/dist/accessory/onoff.js.map +1 -0
- package/dist/accessory/switch.d.ts +8 -0
- package/dist/accessory/switch.js +10 -0
- package/dist/accessory/switch.js.map +1 -0
- package/dist/homebridge/index.d.ts +3 -5
- package/dist/homebridge/index.js +4 -136
- package/dist/homebridge/index.js.map +1 -1
- package/dist/homebridge/platform.d.ts +15 -0
- package/dist/homebridge/platform.js +97 -0
- package/dist/homebridge/platform.js.map +1 -0
- package/dist/homebridge/settings.d.ts +3 -1
- package/dist/homebridge/settings.js +3 -1
- package/dist/homebridge/settings.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +35 -0
- package/dist/homebridge-ui/public/ui.js +1 -0
- package/dist/homebridge-ui/server.d.ts +1 -0
- package/dist/homebridge-ui/server.js +15 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/i18n/en.d.ts +47 -12
- package/dist/i18n/en.js +53 -13
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/i18n.d.ts +47 -12
- package/dist/i18n/template.d.ts +47 -12
- package/dist/i18n/zz.d.ts +47 -12
- package/dist/model/timer.d.ts +12 -0
- package/dist/model/timer.js +64 -0
- package/dist/model/timer.js.map +1 -0
- package/dist/model/types.d.ts +60 -0
- package/dist/model/types.js +13 -0
- package/dist/model/types.js.map +1 -0
- package/dist/tools/configMigration.d.ts +3 -0
- package/dist/tools/configMigration.js +86 -0
- package/dist/tools/configMigration.js.map +1 -0
- package/dist/tools/log.d.ts +14 -0
- package/dist/tools/log.js +25 -0
- package/dist/tools/log.js.map +1 -0
- package/dist/tools/storage.d.ts +4 -2
- package/dist/tools/storage.js +7 -4
- package/dist/tools/storage.js.map +1 -1
- package/dist/tools/validation.d.ts +3 -0
- package/dist/tools/validation.js +13 -0
- package/dist/tools/validation.js.map +1 -0
- package/package.json +33 -24
- package/src/homebridge-ui/public/index.html +35 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { OnOffAccessory } from './onoff.js';
|
|
2
|
+
import { strings } from '../i18n/i18n.js';
|
|
3
|
+
import { STORAGE_KEY_SUFFIX_BRIGHTNESS, storageGet, storageSet } from '../tools/storage.js';
|
|
4
|
+
const DEFAULT_BRIGHTNESS = 0;
|
|
5
|
+
export class LightbulbAccessory extends OnOffAccessory {
|
|
6
|
+
isDimmer;
|
|
7
|
+
brightness = DEFAULT_BRIGHTNESS;
|
|
8
|
+
constructor(Service, Characteristic, accessory, lightbulbConfig, log, persistPath) {
|
|
9
|
+
super(Service, Characteristic, accessory, lightbulbConfig, log, persistPath, LightbulbAccessory.name);
|
|
10
|
+
this.isDimmer = lightbulbConfig.defaultBrightness !== undefined;
|
|
11
|
+
if (this.isDimmer) {
|
|
12
|
+
this.brightness = lightbulbConfig.defaultBrightness;
|
|
13
|
+
this.accessoryService.getCharacteristic(this.Characteristic.Brightness)
|
|
14
|
+
.onGet(this.getBrightness.bind(this))
|
|
15
|
+
.onSet(this.setBrightness.bind(this));
|
|
16
|
+
this.initializeBrightness();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
get brightnessStorageKey() {
|
|
20
|
+
return `${this.identifier}:${STORAGE_KEY_SUFFIX_BRIGHTNESS}`;
|
|
21
|
+
}
|
|
22
|
+
async initializeBrightness() {
|
|
23
|
+
this.brightness = await storageGet(this.persistPath, this.brightnessStorageKey) ?? this.brightness;
|
|
24
|
+
this.accessoryService.updateCharacteristic(this.Characteristic.Brightness, this.brightness);
|
|
25
|
+
}
|
|
26
|
+
getAccessoryService() {
|
|
27
|
+
return this.accessory.getService(this.Service.Lightbulb) || this.accessory.addService(this.Service.Lightbulb);
|
|
28
|
+
}
|
|
29
|
+
logOnState(value) {
|
|
30
|
+
if (this.isDimmer && value) {
|
|
31
|
+
this.logIfDesired(strings.accessory.lightbulb.stateOn, this.config.name, this.brightness.toLocaleString());
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
super.logOnState(value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async getBrightness() {
|
|
38
|
+
return this.brightness;
|
|
39
|
+
}
|
|
40
|
+
async setBrightness(value) {
|
|
41
|
+
if (this.brightness === value) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.brightness = value;
|
|
45
|
+
this.logIfDesired(strings.accessory.lightbulb.brightness, this.config.name, this.brightness.toString());
|
|
46
|
+
await storageSet(this.persistPath, this.brightnessStorageKey, this.brightness);
|
|
47
|
+
this.accessoryService.updateCharacteristic(this.Characteristic.Brightness, this.brightness);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=lightbulb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightbulb.js","sourceRoot":"","sources":["../../src/accessory/lightbulb.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,OAAO,EAAE,6BAA6B,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAE5F,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAE7B,MAAM,OAAO,kBAAmB,SAAQ,cAAc;IAE5C,QAAQ,CAAU;IAElB,UAAU,GAAwB,kBAAkB,CAAC;IAE7D,YACE,OAAoB,EACpB,cAAkC,EAClC,SAA4B,EAC5B,eAAgC,EACh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AI,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAC;YAC3B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC;QAC7G,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAES,KAAK,CAAC,aAAa;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAES,KAAK,CAAC,aAAa,CAAC,KAA0B;QAEtD,IAAI,IAAI,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;QAExB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,UAAU,EAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;QAEzG,MAAM,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,oBAAoB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAE/E,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC9F,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CharacteristicValue, PlatformAccessory } from 'homebridge';
|
|
2
|
+
import { DummyAccessory } from './base.js';
|
|
3
|
+
import { CharacteristicType, OnOffConfig, ServiceType } from '../model/types.js';
|
|
4
|
+
import { Log } from '../tools/log.js';
|
|
5
|
+
export declare abstract class OnOffAccessory extends DummyAccessory {
|
|
6
|
+
private readonly onOffConfig;
|
|
7
|
+
private on;
|
|
8
|
+
constructor(Service: ServiceType, Characteristic: CharacteristicType, accessory: PlatformAccessory, onOffConfig: OnOffConfig, log: Log, persistPath: string, className: string);
|
|
9
|
+
private get isStateful();
|
|
10
|
+
private get onStorageKey();
|
|
11
|
+
private initializeOn;
|
|
12
|
+
protected getOn(): Promise<CharacteristicValue>;
|
|
13
|
+
protected setOn(value: CharacteristicValue): Promise<void>;
|
|
14
|
+
private flip;
|
|
15
|
+
protected logOnState(value: CharacteristicValue): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { DummyAccessory } from './base.js';
|
|
2
|
+
import { strings } from '../i18n/i18n.js';
|
|
3
|
+
import { STORAGE_KEY_SUFFIX_ON, storageGet, storageSet } from '../tools/storage.js';
|
|
4
|
+
export class OnOffAccessory extends DummyAccessory {
|
|
5
|
+
onOffConfig;
|
|
6
|
+
on;
|
|
7
|
+
constructor(Service, Characteristic, accessory, onOffConfig, log, persistPath, className) {
|
|
8
|
+
super(Service, Characteristic, accessory, onOffConfig, log, persistPath, className);
|
|
9
|
+
this.onOffConfig = onOffConfig;
|
|
10
|
+
this.on = onOffConfig.defaultOn ? true : false;
|
|
11
|
+
this.accessoryService.getCharacteristic(Characteristic.On)
|
|
12
|
+
.onGet(this.getOn.bind(this))
|
|
13
|
+
.onSet(this.setOn.bind(this));
|
|
14
|
+
this.initializeOn();
|
|
15
|
+
}
|
|
16
|
+
get isStateful() {
|
|
17
|
+
return this.config.timer?.delay === undefined;
|
|
18
|
+
}
|
|
19
|
+
get onStorageKey() {
|
|
20
|
+
return `${this.identifier}:${STORAGE_KEY_SUFFIX_ON}`;
|
|
21
|
+
}
|
|
22
|
+
async initializeOn() {
|
|
23
|
+
if (this.isStateful) {
|
|
24
|
+
this.on = await storageGet(this.persistPath, this.onStorageKey) ?? this.on;
|
|
25
|
+
}
|
|
26
|
+
this.accessoryService.updateCharacteristic(this.Characteristic.On, this.on);
|
|
27
|
+
}
|
|
28
|
+
async getOn() {
|
|
29
|
+
return this.on;
|
|
30
|
+
}
|
|
31
|
+
async setOn(value) {
|
|
32
|
+
if (this.on !== value) {
|
|
33
|
+
this.logOnState(value);
|
|
34
|
+
}
|
|
35
|
+
this.on = value;
|
|
36
|
+
if (this.isStateful) {
|
|
37
|
+
await storageSet(this.persistPath, this.onStorageKey, this.on);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (this.on === !this.onOffConfig.defaultOn) {
|
|
41
|
+
this.startTimer(this.flip.bind(this));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.cancelTimer();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
this.accessoryService.updateCharacteristic(this.Characteristic.On, this.on);
|
|
48
|
+
}
|
|
49
|
+
async flip() {
|
|
50
|
+
await this.setOn(!this.on);
|
|
51
|
+
}
|
|
52
|
+
logOnState(value) {
|
|
53
|
+
this.logIfDesired(value ? strings.accessory.onOff.stateOn : strings.accessory.onOff.stateOff, this.config.name);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=onoff.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onoff.js","sourceRoot":"","sources":["../../src/accessory/onoff.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK1C,OAAO,EAAE,qBAAqB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEpF,MAAM,OAAgB,cAAe,SAAQ,cAAc;IAQtC;IANX,EAAE,CAAsB;IAEhC,YACE,OAAoB,EACpB,cAAkC,EAClC,SAA4B,EACX,WAAwB,EACzC,GAAQ,EACR,WAAmB,EACnB,SAAiB;QAEjB,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QALnE,gBAAW,GAA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,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,IAAI,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;gBAC5C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YACxC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9E,CAAC;IAEO,KAAK,CAAC,IAAI;QAChB,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAES,UAAU,CAAC,KAA0B;QAC7C,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAClH,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PlatformAccessory, Service } from 'homebridge';
|
|
2
|
+
import { OnOffAccessory } from './onoff.js';
|
|
3
|
+
import { CharacteristicType, ServiceType, SwitchConfig } from '../model/types.js';
|
|
4
|
+
import { Log } from '../tools/log.js';
|
|
5
|
+
export declare class SwitchAccessory extends OnOffAccessory {
|
|
6
|
+
constructor(Service: ServiceType, Characteristic: CharacteristicType, accessory: PlatformAccessory, switchConfig: SwitchConfig, log: Log, persistPath: string);
|
|
7
|
+
protected getAccessoryService(): Service;
|
|
8
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { OnOffAccessory } from './onoff.js';
|
|
2
|
+
export class SwitchAccessory extends OnOffAccessory {
|
|
3
|
+
constructor(Service, Characteristic, accessory, switchConfig, log, persistPath) {
|
|
4
|
+
super(Service, Characteristic, accessory, switchConfig, log, persistPath, SwitchAccessory.name);
|
|
5
|
+
}
|
|
6
|
+
getAccessoryService() {
|
|
7
|
+
return this.accessory.getService(this.Service.Switch) || this.accessory.addService(this.Service.Switch);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=switch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/accessory/switch.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAM5C,MAAM,OAAO,eAAgB,SAAQ,cAAc;IAEjD,YACE,OAAoB,EACpB,cAAkC,EAClC,SAA4B,EAC5B,YAA0B,EAC1B,GAAQ,EACR,WAAmB;QAEnB,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,eAAe,CAAC,IAAI,CAAC,CAAC;IAClG,CAAC;IAES,mBAAmB;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC1G,CAAC;CACF"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { API } from 'homebridge';
|
|
2
|
-
declare const
|
|
3
|
-
export default
|
|
4
|
-
export declare const SUFFIX_BRIGHTNESS = "_brightness";
|
|
5
|
-
export declare const SUFFIX_STATE = "_state";
|
|
1
|
+
import type { API } from 'homebridge';
|
|
2
|
+
declare const _default: (api: API) => void;
|
|
3
|
+
export default _default;
|
package/dist/homebridge/index.js
CHANGED
|
@@ -1,138 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const init = (api) => {
|
|
6
|
-
api.registerAccessory(PLUGIN_NAME, PLUGIN_ALIAS, DummySwitch);
|
|
1
|
+
import { HomebridgeDummyPlatform } from './platform.js';
|
|
2
|
+
import { PLATFORM_NAME } from './settings.js';
|
|
3
|
+
export default (api) => {
|
|
4
|
+
api.registerPlatform(PLATFORM_NAME, HomebridgeDummyPlatform);
|
|
7
5
|
};
|
|
8
|
-
export default init;
|
|
9
|
-
export const SUFFIX_BRIGHTNESS = '_brightness';
|
|
10
|
-
export const SUFFIX_STATE = '_state';
|
|
11
|
-
class DummySwitch {
|
|
12
|
-
log;
|
|
13
|
-
Service;
|
|
14
|
-
Characteristic;
|
|
15
|
-
service;
|
|
16
|
-
infoService;
|
|
17
|
-
persistPath;
|
|
18
|
-
name;
|
|
19
|
-
isDimmer;
|
|
20
|
-
isStateful;
|
|
21
|
-
isReverse;
|
|
22
|
-
isRandom;
|
|
23
|
-
isResettable;
|
|
24
|
-
brightness;
|
|
25
|
-
timeout;
|
|
26
|
-
timer = undefined;
|
|
27
|
-
constructor(log, config, api) {
|
|
28
|
-
this.log = config.disableLogging ? undefined : log;
|
|
29
|
-
this.Service = api.hap.Service;
|
|
30
|
-
this.Characteristic = api.hap.Characteristic;
|
|
31
|
-
this.persistPath = api.user.persistPath();
|
|
32
|
-
this.name = config.name;
|
|
33
|
-
this.isDimmer = config.dimmer ?? false;
|
|
34
|
-
this.isReverse = config.reverse ?? false;
|
|
35
|
-
this.isStateful = config.stateful ?? false;
|
|
36
|
-
this.isRandom = config.random ?? false;
|
|
37
|
-
this.isResettable = config.resettable ?? false;
|
|
38
|
-
this.timeout = config.time;
|
|
39
|
-
this.brightness = config.brightness ?? 0;
|
|
40
|
-
let model;
|
|
41
|
-
if (this.isDimmer) {
|
|
42
|
-
this.service = new this.Service.Lightbulb(this.name);
|
|
43
|
-
model = strings.info.dimmer;
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
this.service = new this.Service.Switch(this.name);
|
|
47
|
-
model = strings.info.switch;
|
|
48
|
-
}
|
|
49
|
-
this.infoService = new this.Service.AccessoryInformation();
|
|
50
|
-
this.infoService
|
|
51
|
-
.setCharacteristic(this.Characteristic.Manufacturer, strings.info.homebridge)
|
|
52
|
-
.setCharacteristic(this.Characteristic.Model, model)
|
|
53
|
-
.setCharacteristic(this.Characteristic.FirmwareRevision, getVersion())
|
|
54
|
-
.setCharacteristic(this.Characteristic.SerialNumber, 'Dummy-' + this.name.replace(/\s/g, '-'));
|
|
55
|
-
this.finishSetup();
|
|
56
|
-
}
|
|
57
|
-
getServices() {
|
|
58
|
-
return [this.infoService, this.service];
|
|
59
|
-
}
|
|
60
|
-
async finishSetup() {
|
|
61
|
-
if (this.isReverse) {
|
|
62
|
-
this.service.setCharacteristic(this.Characteristic.On, true);
|
|
63
|
-
}
|
|
64
|
-
if (this.isStateful) {
|
|
65
|
-
const state = await storageGet(this.persistPath, this.storageKey(SUFFIX_STATE));
|
|
66
|
-
if (!state) {
|
|
67
|
-
this.service.setCharacteristic(this.Characteristic.On, false);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
this.service.setCharacteristic(this.Characteristic.On, true);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (this.isDimmer) {
|
|
74
|
-
const brightness = await storageGet(this.persistPath, this.storageKey(SUFFIX_BRIGHTNESS));
|
|
75
|
-
if (brightness) {
|
|
76
|
-
this.brightness = Number(brightness);
|
|
77
|
-
this.service.setCharacteristic(this.Characteristic.Brightness, Number(this.brightness));
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
this.service.setCharacteristic(this.Characteristic.Brightness, 0);
|
|
81
|
-
}
|
|
82
|
-
this.service.getCharacteristic(this.Characteristic.Brightness)
|
|
83
|
-
.onGet(this._getBrightness.bind(this))
|
|
84
|
-
.onSet(this._setBrightness.bind(this));
|
|
85
|
-
}
|
|
86
|
-
this.service.getCharacteristic(this.Characteristic.On)
|
|
87
|
-
.onSet(this._setOn.bind(this));
|
|
88
|
-
}
|
|
89
|
-
storageKey(suffix) {
|
|
90
|
-
return this.name.replace(/\s/g, '_').toLowerCase() + suffix;
|
|
91
|
-
}
|
|
92
|
-
randomize(timeout) {
|
|
93
|
-
return timeout ? Math.floor(Math.random() * (timeout + 1)) : undefined;
|
|
94
|
-
}
|
|
95
|
-
async _getBrightness() {
|
|
96
|
-
return this.brightness;
|
|
97
|
-
}
|
|
98
|
-
async _setBrightness(brightness) {
|
|
99
|
-
this.log?.(strings.brightness.set, brightness);
|
|
100
|
-
this.brightness = brightness;
|
|
101
|
-
await storageSet(this.persistPath, this.storageKey(SUFFIX_BRIGHTNESS), brightness.toString());
|
|
102
|
-
}
|
|
103
|
-
;
|
|
104
|
-
async _setOn(value) {
|
|
105
|
-
if (this.isDimmer) {
|
|
106
|
-
this.log?.('%s / %s', value ? strings.switch.on : strings.switch.off, this.brightness);
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
this.log?.(value ? strings.switch.on : strings.switch.off);
|
|
110
|
-
}
|
|
111
|
-
if (this.isStateful) {
|
|
112
|
-
await storageSet(this.persistPath, this.storageKey(SUFFIX_STATE), value.toString());
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (value === this.isReverse) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (this.isResettable) {
|
|
119
|
-
clearTimeout(this.timer);
|
|
120
|
-
this.timer = undefined;
|
|
121
|
-
}
|
|
122
|
-
const delay = this.isRandom ? this.randomize(this.timeout) : this.timeout;
|
|
123
|
-
if (!delay) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (delay % 1000 === 0) {
|
|
127
|
-
this.log?.(strings.switch.delay_s, delay / 1000);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
this.log?.(strings.switch.delay_ms, delay);
|
|
131
|
-
}
|
|
132
|
-
this.timer = setTimeout(() => {
|
|
133
|
-
this.service.setCharacteristic(this.Characteristic.On, this.isReverse);
|
|
134
|
-
}, delay);
|
|
135
|
-
}
|
|
136
|
-
;
|
|
137
|
-
}
|
|
138
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/homebridge/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/homebridge/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,eAAe,CAAC,GAAQ,EAAE,EAAE;IAC1B,GAAG,CAAC,gBAAgB,CAAC,aAAa,EAAE,uBAAuB,CAAC,CAAC;AAC/D,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { API, DynamicPlatformPlugin, Logger, PlatformAccessory, PlatformConfig } from 'homebridge';
|
|
2
|
+
export declare class HomebridgeDummyPlatform implements DynamicPlatformPlugin {
|
|
3
|
+
private readonly api;
|
|
4
|
+
private readonly Service;
|
|
5
|
+
private readonly Characteristic;
|
|
6
|
+
private readonly config;
|
|
7
|
+
private readonly log;
|
|
8
|
+
private readonly cachedAccessories;
|
|
9
|
+
private readonly dummyAccessories;
|
|
10
|
+
constructor(logger: Logger, config: PlatformConfig, api: API);
|
|
11
|
+
configureAccessory(accessory: PlatformAccessory): void;
|
|
12
|
+
private teardown;
|
|
13
|
+
private setup;
|
|
14
|
+
private removeCachedAccessory;
|
|
15
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { PLATFORM_NAME, PLUGIN_NAME } from './settings.js';
|
|
2
|
+
import { DummyAccessory } from '../accessory/base.js';
|
|
3
|
+
import { LightbulbAccessory } from '../accessory/lightbulb.js';
|
|
4
|
+
import { SwitchAccessory } from '../accessory/switch.js';
|
|
5
|
+
import { setLanguage, strings } from '../i18n/i18n.js';
|
|
6
|
+
import { AccessoryType } from '../model/types.js';
|
|
7
|
+
import getVersion from '../tools/version.js';
|
|
8
|
+
import { Log } from '../tools/log.js';
|
|
9
|
+
import { migrateAccessories } from '../tools/configMigration.js';
|
|
10
|
+
export class HomebridgeDummyPlatform {
|
|
11
|
+
api;
|
|
12
|
+
Service;
|
|
13
|
+
Characteristic;
|
|
14
|
+
config;
|
|
15
|
+
log;
|
|
16
|
+
cachedAccessories = new Map();
|
|
17
|
+
dummyAccessories = [];
|
|
18
|
+
constructor(logger, config, api) {
|
|
19
|
+
this.api = api;
|
|
20
|
+
this.config = config;
|
|
21
|
+
const userLang = Intl.DateTimeFormat().resolvedOptions().locale.split('-')[0];
|
|
22
|
+
setLanguage(userLang);
|
|
23
|
+
this.Service = api.hap.Service;
|
|
24
|
+
this.Characteristic = api.hap.Characteristic;
|
|
25
|
+
this.log = new Log(logger);
|
|
26
|
+
this.log.always('v%s | System %s | Node %s | HB v%s | HAPNodeJS v%s', getVersion(), process.platform, process.version, api.serverVersion, api.hap.HAPLibraryVersion());
|
|
27
|
+
api.on('didFinishLaunching', () => {
|
|
28
|
+
this.setup();
|
|
29
|
+
});
|
|
30
|
+
api.on('shutdown', () => {
|
|
31
|
+
this.teardown();
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
configureAccessory(accessory) {
|
|
35
|
+
this.log.always(strings.startup.restoringAccessory, accessory.displayName);
|
|
36
|
+
this.cachedAccessories.set(accessory.context.identifier, accessory);
|
|
37
|
+
}
|
|
38
|
+
teardown() {
|
|
39
|
+
this.dummyAccessories.forEach(accessory => {
|
|
40
|
+
accessory.teardown();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
async setup() {
|
|
44
|
+
const keepIdentifiers = new Set();
|
|
45
|
+
const accessories = this.config.accessories || [];
|
|
46
|
+
if (this.config.migrationNeeded) {
|
|
47
|
+
const migratedAccessories = await migrateAccessories(this.log, this.api.user.configPath()) ?? [];
|
|
48
|
+
accessories.push(...migratedAccessories);
|
|
49
|
+
}
|
|
50
|
+
const persistPath = this.api.user.persistPath();
|
|
51
|
+
const newAccessories = [];
|
|
52
|
+
for (const accessoryConfig of accessories) {
|
|
53
|
+
const id = DummyAccessory.identifier(accessoryConfig);
|
|
54
|
+
keepIdentifiers.add(id);
|
|
55
|
+
let accessory = this.cachedAccessories.get(id);
|
|
56
|
+
if (!accessory) {
|
|
57
|
+
const name = accessoryConfig.name;
|
|
58
|
+
this.log.always(strings.startup.newAccessory, name);
|
|
59
|
+
const uuid = this.api.hap.uuid.generate(id);
|
|
60
|
+
accessory = new this.api.platformAccessory(name, uuid);
|
|
61
|
+
accessory.context.identifier = id;
|
|
62
|
+
newAccessories.push(accessory);
|
|
63
|
+
this.cachedAccessories.set(id, accessory);
|
|
64
|
+
}
|
|
65
|
+
let dummyAccessory;
|
|
66
|
+
switch (accessoryConfig.type) {
|
|
67
|
+
case AccessoryType.Lightbulb:
|
|
68
|
+
dummyAccessory = new LightbulbAccessory(this.Service, this.Characteristic, accessory, accessoryConfig, this.log, persistPath);
|
|
69
|
+
break;
|
|
70
|
+
case AccessoryType.Switch:
|
|
71
|
+
dummyAccessory = new SwitchAccessory(this.Service, this.Characteristic, accessory, accessoryConfig, this.log, persistPath);
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
this.log.error(strings.startup.unsupportedType, `'${accessoryConfig.type}'`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
this.dummyAccessories.push(dummyAccessory);
|
|
78
|
+
}
|
|
79
|
+
;
|
|
80
|
+
if (newAccessories.length) {
|
|
81
|
+
this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, newAccessories);
|
|
82
|
+
}
|
|
83
|
+
this.cachedAccessories.forEach(accessory => {
|
|
84
|
+
if (!keepIdentifiers.has(accessory.context.identifier)) {
|
|
85
|
+
this.removeCachedAccessory(accessory);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
const randIndex = Math.floor(Math.random() * strings.startup.welcome.length);
|
|
89
|
+
this.log.always(strings.startup.setupComplete, strings.startup.welcome[randIndex]);
|
|
90
|
+
}
|
|
91
|
+
removeCachedAccessory(accessory) {
|
|
92
|
+
this.log.always(strings.startup.removeAccessory, accessory.displayName);
|
|
93
|
+
this.api.unregisterPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
|
|
94
|
+
this.cachedAccessories.delete(accessory.context.identifier);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/homebridge/platform.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,EAAE,aAAa,EAA4E,MAAM,mBAAmB,CAAC;AAE5H,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE,MAAM,OAAO,uBAAuB;IAcf;IAbF,OAAO,CAAC;IACR,cAAc,CAAC;IAEf,MAAM,CAAsB;IAE5B,GAAG,CAAM;IAET,iBAAiB,GAAmC,IAAI,GAAG,EAAE,CAAC;IAC9D,gBAAgB,GAAuB,EAAE,CAAC;IAE3D,YACE,MAAc,E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AC,SAAS,CAAC,CAAC;YACxC,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7E,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC;IACrF,CAAC;IAEO,qBAAqB,CAAC,SAA4B;QACxD,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,eAAe,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;QACxE,IAAI,CAAC,GAAG,CAAC,6BAA6B,CAAC,WAAW,EAAE,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;QAChF,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;IAC9D,CAAC;CACF"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const PLATFORM_NAME = "HomebridgeDummy";
|
|
2
2
|
export declare const PLUGIN_NAME = "homebridge-dummy";
|
|
3
|
+
export declare const PLUGIN_ALIAS = "Homebridge Dummy";
|
|
4
|
+
export declare const LEGACY_ALIAS = "DummySwitch";
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const PLATFORM_NAME = 'HomebridgeDummy';
|
|
2
2
|
export const PLUGIN_NAME = 'homebridge-dummy';
|
|
3
|
+
export const PLUGIN_ALIAS = 'Homebridge Dummy';
|
|
4
|
+
export const LEGACY_ALIAS = 'DummySwitch';
|
|
3
5
|
//# sourceMappingURL=settings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/homebridge/settings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"settings.js","sourceRoot":"","sources":["../../src/homebridge/settings.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,kBAAkB,CAAC;AAC9C,MAAM,CAAC,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<!-- <p class="text-center">
|
|
2
|
+
<img
|
|
3
|
+
src="https://github.com/mpatfield/homebridge-dummy/blob/latest/img/banner.png?raw=true"
|
|
4
|
+
alt="Homebridge Dummy"
|
|
5
|
+
style="width: 60%;"
|
|
6
|
+
/>
|
|
7
|
+
</p> -->
|
|
8
|
+
|
|
9
|
+
<div id="support" class="text-center" style="display: none;">
|
|
10
|
+
<p i18n="support" i18n_replace="github"></p>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div id="intro" class="text-center" style="display: none;">
|
|
14
|
+
<p class="lead" i18n="thankYou" i18n_replace="dummy"></p></br>
|
|
15
|
+
<p i18n="migrate"></p></br>
|
|
16
|
+
<button type="button" class="btn btn-primary" id="showSettings" i18n="no"></button>
|
|
17
|
+
<button type="button" class="btn btn-primary" id="showMigration" i18n="yes"></button>
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
<div id="migration" class="text-center" style="display: none;">
|
|
21
|
+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/Warning.svg/156px-Warning.svg.png"/>
|
|
22
|
+
</br></br>
|
|
23
|
+
<p class="lead" i18n="migrationDetails1"></p>
|
|
24
|
+
<p class="lead" i18n="migrationDetails2" i18n_replace="dummy"></p>
|
|
25
|
+
</br>
|
|
26
|
+
<p i18n="migrationDetails3" i18n_replace="dummy"></p>
|
|
27
|
+
<p i18n="migrationDetails4"></p>
|
|
28
|
+
</br>
|
|
29
|
+
<button type="button" class="btn btn-primary" id="skipMigration" i18n="no"></button>
|
|
30
|
+
<button type="button" class="btn btn-primary" id="doMigration" i18n="yes"></button>
|
|
31
|
+
</br></br></br>
|
|
32
|
+
<em><p i18n="migrationDetails5" i18n_replace="migration"></p></em></br>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<script src="ui.js"></script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(()=>{var a="Homebridge Dummy";var d={github:'<a target="_blank" href="https://github.com/mpatfield/homebridge-dummy/">GitHub</a>',migration:'<a target="_blank" href="https://github.com/mpatfield/homebridge-dummy?tab=readme-ov-file#v100-migration">GitHub</a>',dummy:a},g=e=>{document.querySelectorAll("[i18n]").forEach(n=>{let i=n.getAttribute("i18n"),o=e.config[i],t=n.getAttribute("i18n_replace");t&&(o=o.replace("%s",d[t])),n.innerHTML=o})},u=e=>{let n=["span","label","legend","option","p"];Array.from(window.parent.document.querySelectorAll(n.join(","))).sort((o,t)=>n.indexOf(o.tagName.toLowerCase())-n.indexOf(t.tagName.toLowerCase())).forEach(o=>{let t=o.innerHTML;t=t.replaceAll(/\$\{config\.(title|description|enumNames)\.([^}]+)\}/g,(m,r,c)=>e.config[r]&&typeof e.config[r]=="object"&&c in e.config[r]?e.config[r][c]:m),o.innerHTML!==t&&(o.innerHTML=t)})},l=e=>{let n=Array.from(window.parent.document.querySelectorAll("fieldset legend"));for(let i of n){let t=i.closest("fieldset")?.querySelector('input[type="text"][name="name"]');t&&i.textContent!==(t.value||e.config.title.accessory)&&(i.textContent=t.value!==""?t.value:e.config.title.accessory),t&&!t.dataset.accessoryNameListener&&(t.addEventListener("input",()=>l(e)),t.dataset.accessoryNameListener="true")}},s=e=>{document.getElementById("intro").style.display="none",document.getElementById("migration").style.display="none",document.getElementById("support").style.display="block",new MutationObserver(()=>{u(e),l(e)}).observe(window.parent.document.body,{childList:!0,subtree:!0}),homebridge.showSchemaForm(),homebridge.enableSaveButton(),homebridge.hideSpinner()},f=e=>{document.getElementById("intro").style.display="none",document.getElementById("migration").style.display="block",document.getElementById("skipMigration").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a}]),await homebridge.savePluginConfig(),s(e)}),document.getElementById("doMigration").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a,migrationNeeded:!0}]),await homebridge.savePluginConfig(),homebridge.closeSettings(),homebridge.toast.info(e.config.migrationRestartDescription.replace("%s",a),e.config.migrationRestartTitle)})},y=e=>{homebridge.disableSaveButton(),document.getElementById("showSettings").addEventListener("click",async()=>{await homebridge.updatePluginConfig([{name:a}]),s(e)}),document.getElementById("showMigration").addEventListener("click",()=>{f(e)}),document.getElementById("intro").style.display="block",homebridge.hideSpinner()};(async()=>{homebridge.showSpinner();let e=await homebridge.i18nCurrentLang(),n=await homebridge.request("i18n",e);g(n),(await homebridge.getPluginConfig()).length?s(n):y(n)})();})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils';
|
|
2
|
+
import { getAllTranslations, setLanguage } from '../i18n/i18n.js';
|
|
3
|
+
class DummyConfigUiServer extends HomebridgePluginUiServer {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.onRequest('i18n', this.i18n.bind(this));
|
|
7
|
+
this.ready();
|
|
8
|
+
}
|
|
9
|
+
async i18n(language) {
|
|
10
|
+
setLanguage(language);
|
|
11
|
+
return getAllTranslations();
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
(() => new DummyConfigUiServer())();
|
|
15
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/homebridge-ui/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAe,MAAM,iBAAiB,CAAC;AAE/E,MAAM,mBAAoB,SAAQ,wBAAwB;IACxD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7C,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;IAGD,KAAK,CAAC,IAAI,CAAC,QAAgB;QACzB,WAAW,CAAC,QAAQ,CAAC,CAAC;QACtB,OAAO,kBAAkB,EAAE,CAAC;IAC9B,CAAC;CACF;AAED,CAAC,GAAG,EAAE,CAAC,IAAI,mBAAmB,EAAE,CAAC,EAAE,CAAC"}
|
package/dist/i18n/en.d.ts
CHANGED
|
@@ -1,20 +1,55 @@
|
|
|
1
1
|
declare const en: {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
accessory: {
|
|
3
|
+
missingRequired: string;
|
|
4
|
+
lightbulb: {
|
|
5
|
+
brightness: string;
|
|
6
|
+
stateOn: string;
|
|
7
|
+
};
|
|
8
|
+
onOff: {
|
|
9
|
+
stateOn: string;
|
|
10
|
+
stateOff: string;
|
|
11
|
+
};
|
|
12
|
+
timer: {
|
|
13
|
+
cancel: string;
|
|
14
|
+
reset: string;
|
|
15
|
+
setSeconds: string;
|
|
16
|
+
setMinutes: string;
|
|
17
|
+
setHours: string;
|
|
18
|
+
};
|
|
4
19
|
};
|
|
5
20
|
config: {
|
|
21
|
+
migrate: string;
|
|
22
|
+
migrationDetails1: string;
|
|
23
|
+
migrationDetails2: string;
|
|
24
|
+
migrationDetails3: string;
|
|
25
|
+
migrationDetails4: string;
|
|
26
|
+
migrationDetails5: string;
|
|
27
|
+
migrationRestartTitle: string;
|
|
28
|
+
migrationRestartDescription: string;
|
|
6
29
|
support: string;
|
|
30
|
+
thankYou: string;
|
|
31
|
+
yes: string;
|
|
32
|
+
no: string;
|
|
33
|
+
description: {};
|
|
34
|
+
title: {
|
|
35
|
+
accessory: string;
|
|
36
|
+
disableLogging: string;
|
|
37
|
+
name: string;
|
|
38
|
+
};
|
|
7
39
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
40
|
+
startup: {
|
|
41
|
+
migrationBridge: string;
|
|
42
|
+
migrationComplete: string;
|
|
43
|
+
migrationNoAccessories: string;
|
|
44
|
+
migrationIgnore: string;
|
|
45
|
+
migrationFailed: string;
|
|
46
|
+
migrationRevert: string;
|
|
47
|
+
newAccessory: string;
|
|
48
|
+
removeAccessory: string;
|
|
49
|
+
restoringAccessory: string;
|
|
50
|
+
setupComplete: string;
|
|
51
|
+
unsupportedType: string;
|
|
52
|
+
welcome: string[];
|
|
18
53
|
};
|
|
19
54
|
};
|
|
20
55
|
export default en;
|