Skip to content

Commit

Permalink
Add error checking to getAccountSettings()
Browse files Browse the repository at this point in the history
  • Loading branch information
chase9 committed Oct 19, 2023
1 parent 719cf81 commit b7736ea
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,24 @@ class ADCPlatform implements DynamicPlatformPlugin {
* This method makes a call to alarm.com in order to retrieve global account information.
*/
async getAccountSettings() {
const authOpts = await this.loginSession();
const identities = await getIdentitiesState(authOpts.cookie, authOpts.ajaxKey);
const identity = identities.data[0];
if (identity) {
this.tempDisplayUnitSetting = identity.attributes.localizeTempUnitsToCelsius
? hapCharacteristic.TemperatureDisplayUnits.CELSIUS
: hapCharacteristic.TemperatureDisplayUnits.FAHRENHEIT;
try {
const authOpts = await this.loginSession();
const identities = await getIdentitiesState(authOpts.cookie, authOpts.ajaxKey);
const identity = identities.data[0];
if (identity) {
this.tempDisplayUnitSetting = identity.attributes.localizeTempUnitsToCelsius
? hapCharacteristic.TemperatureDisplayUnits.CELSIUS
: hapCharacteristic.TemperatureDisplayUnits.FAHRENHEIT;
}
} catch (e) {
this.log.error(
`There was an error retrieving account settings. Please check that your credentials are correct and restart the plugin.`
);
if (typeof e === typeof String) {
this.log.error(e);
} else if (e instanceof Error) {
this.log.error(e.message);
}
}
}

Expand Down

0 comments on commit b7736ea

Please sign in to comment.