Skip to content

Commit

Permalink
refactor(dingz): start consolidation of config gathering
Browse files Browse the repository at this point in the history
- will eventually integrate all `_config` functions into one method
- work towards [FIX] refactor dingz.updateAccessory #103
  • Loading branch information
johannrichard committed Nov 22, 2020
1 parent 7934ed0 commit 7b55a0a
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/dingzAccessory.ts
Expand Up @@ -1451,6 +1451,25 @@ export class DingzDaAccessory extends EventEmitter {
throw new Error('dingz Device update failed -> Empty data.');
}

// Get Input & Dimmer Config
private async getConfigs(): Promise<[DingzInputConfig, DingzDimmerConfig]> {
const getInputConfigUrl = `${this.baseUrl}/api/v1/input_config`;
const getDimmerConfigUrl = `${this.baseUrl}/api/v1/dimmer_config`;

return Promise.all<DingzInputConfig, DingzDimmerConfig>([
this.platform.fetch({
url: getInputConfigUrl,
returnBody: true,
token: this.device.token,
}),
this.platform.fetch({
url: getDimmerConfigUrl,
returnBody: true,
token: this.device.token,
}),
]);
}

private async getDeviceMotion(): Promise<DingzMotionData> {
const getMotionUrl = `${this.baseUrl}/api/v1/motion`;
const release = await this.mutex.acquire();
Expand Down Expand Up @@ -1551,25 +1570,9 @@ export class DingzDaAccessory extends EventEmitter {
});
}

// Get Input & Dimmer Config
private async getConfigs(): Promise<[DingzInputConfig, DingzDimmerConfig]> {
const getInputConfigUrl = `${this.baseUrl}/api/v1/input_config`;
const getDimmerConfigUrl = `${this.baseUrl}/api/v1/dimmer_config`;

return Promise.all<DingzInputConfig, DingzDimmerConfig>([
this.platform.fetch({
url: getInputConfigUrl,
returnBody: true,
token: this.device.token,
}),
this.platform.fetch({
url: getDimmerConfigUrl,
returnBody: true,
token: this.device.token,
}),
]);
}

// Get the current state
// This function is called regularly and contains all necessary
// information for an update of all sensors and states
private async getDeviceState(): Promise<DingzState> {
const getDeviceStateUrl = `${this.baseUrl}/api/v1/state`;
const release = await this.mutex.acquire();
Expand Down

0 comments on commit 7b55a0a

Please sign in to comment.