homebridge-virtual-accessories
Version:
Virtual HomeKit accessories for Homebridge.
87 lines • 3.45 kB
JavaScript
/* eslint-disable brace-style */
/* eslint-disable curly */
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { ValveType } from '../schema.js';
import { Utils } from '../../utils/utils.js';
import { Type } from 'typeserializer';
/**
*
*/
class ValveDurationConfiguration {
static MINUTES_MAX_VALUE = 60;
static SECONDS_MAX_VALUE = 59;
minutes;
seconds = 0;
errorFields = [];
fieldNames = Utils.proxiedPropertiesOf(this);
isValid(prefix) {
const isValidMinutes = (Utils.required(this.minutes) &&
(this.minutes >= 0 && this.minutes <= ValveDurationConfiguration.MINUTES_MAX_VALUE));
// Do not exceed maximum value (MINUTES_MAX_VALUE)
if (isValidMinutes && this.minutes === ValveDurationConfiguration.MINUTES_MAX_VALUE) {
this.seconds = 0;
}
const isValidSeconds = (Utils.required(this.seconds) &&
(this.seconds >= 0 && this.seconds <= ValveDurationConfiguration.SECONDS_MAX_VALUE));
if (!isValidMinutes)
this.errorFields.push(prefix + '.' + this.fieldNames.minutes);
if (!isValidSeconds)
this.errorFields.push(prefix + '.' + this.fieldNames.seconds);
return [
(isValidMinutes &&
isValidSeconds),
this.errorFields,
];
}
toSeconds() {
const seconds = Utils.daysHoursMinutesSecondsToSeconds(0, 0, this.minutes, this.seconds);
return seconds;
}
}
/**
*
*/
export class ValveConfiguration {
type;
duration;
errorFields = [];
fieldNames = Utils.proxiedPropertiesOf(this);
isValid(prefix) {
const isValidType = (Utils.required(this.type) &&
ValveType.Types.includes(this.type));
let isValidDuration = true;
let durationErrorFields = [];
if (this.duration !== undefined) {
[isValidDuration, durationErrorFields] = this.duration.isValid(this.fieldNames.duration);
}
else {
[isValidDuration, durationErrorFields] = [false, [this.fieldNames.duration]];
}
// Store fields failing validation
if (!isValidType)
this.errorFields.push(prefix + '.' + this.fieldNames.type);
if (!isValidDuration) {
durationErrorFields.forEach((errorField) => {
this.errorFields.push(prefix + '.' + errorField);
});
}
return [
(isValidType &&
isValidDuration),
this.errorFields,
];
}
}
__decorate([
Type(ValveDurationConfiguration),
__metadata("design:type", ValveDurationConfiguration)
], ValveConfiguration.prototype, "duration", void 0);
//# sourceMappingURL=configurationValve.js.map