homebridge-yale-sync-keypad
Version:
A pluign to connect to your Yale Sync Alarm account and allow you to change the alarm state using Homekit. Motion sensors are not supported, due to the fact that they are only active when the alarm is set to away.
38 lines • 1.46 kB
JavaScript
export class YaleConfigHandler {
/**
* Decode the user's config file into a YaleSyncKeypadPlatformConfig object
* @param config The config from the user
* @returns The decoded config
*/
static decode(config) {
return {
...config,
username: config.username ?? '',
password: config.password ?? '',
backgroundRefresh: config.backgroundRefresh ?? true,
refreshInterval: config.refreshInterval ?? 5,
};
}
;
/**
* Check if the config is valid by checking if all required fields are present and some restrictions are met and return an error message if not
* @param config The YaleSyncKeypadPlatformConfig object to validate
* @returns An error message if the config is invalid, otherwise null
*/
static validate(config) {
if ((config.name?.trim().length ?? 0) === 0) {
return 'The name is required';
}
if ((config.username?.trim().length ?? 0) === 0) {
return 'The username is required';
}
if ((config.password?.trim().length ?? 0) === 0) {
return 'The password is required';
}
if (config.backgroundRefresh && (!config.refreshInterval || config.refreshInterval < 5)) {
return 'The refresh interval is required and must be at least 5 seconds';
}
return null;
}
}
//# sourceMappingURL=platformConfig.js.map