Skip to content

Commit

Permalink
Read token from config
Browse files Browse the repository at this point in the history
  • Loading branch information
irinel-nistor-lego committed Jul 6, 2021
1 parent ec66826 commit 6c56bfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions config.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"pluginAlias": "ExampleHomebridgePlugin",
"pluginAlias": "HomebridgeSamsungACSmartThings",
"pluginType": "platform",
"singular": true,
"schema": {
Expand All @@ -9,7 +9,13 @@
"title": "Name",
"type": "string",
"required": true,
"default": "Example Dynamic Platform"
"default": "homebridge-samsung-air-conditioner-smart-things"
},
"token": {
"title": "Token",
"type": "string",
"required": true,
"default": ""
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ export class SamsungAC implements DynamicPlatformPlugin {
}

discoverDevices() {
const token = 'ef7a9c71-ef1a-4864-8bc9-7265b5deb355';
SamsungAPI.getDevices(token).then(samsungDevices => {
SamsungAPI.getDevices(this.config.token).then(samsungDevices => {
for (const device of samsungDevices) {
const uuid = this.api.hap.uuid.generate(device.deviceId.toString());

const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);

if (existingAccessory) {
this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);
existingAccessory.context.token = this.config.token;

new SamsungACPlatformAccessory(this, existingAccessory);
} else {
Expand All @@ -48,7 +48,7 @@ export class SamsungAC implements DynamicPlatformPlugin {
const accessory = new this.api.platformAccessory(device.label, uuid);

accessory.context.device = device;
accessory.context.token = token;
accessory.context.token = this.config.token;

new SamsungACPlatformAccessory(this, accessory);

Expand Down

0 comments on commit 6c56bfd

Please sign in to comment.