UNPKG

homebridge-virtual-accessories

Version:
54 lines 2.31 kB
/* eslint-disable curly */ import { ColorTemperature, LightbulbType, PowerState } from '../schema.js'; import { Utils } from '../../utils/utils.js'; import { Colors } from '../../utils/colorUtils.js'; /** * */ export class LightbulbConfiguration { defaultState; type; brightness; colorTemperatureKelvin; colorHex; errorFields = []; fieldNames = Utils.proxiedPropertiesOf(this); isValid(prefix) { const isValidDefaultState = (Utils.required(this.defaultState) && PowerState.States.includes(this.defaultState)); const isValidType = (Utils.required(this.type) && LightbulbType.Types.includes(this.type)); const isValidBrightness = (([LightbulbType.White, LightbulbType.Ambiance].includes(this.type)) ? (Utils.required(this.brightness) && Utils.isPercentage(this.brightness)) : true); const isValidColorTemperature = ((this.type === LightbulbType.Ambiance) ? (Utils.required(this.colorTemperatureKelvin) && (this.colorTemperatureKelvin >= ColorTemperature.TemperatureKelvinMin && this.colorTemperatureKelvin <= ColorTemperature.TemperatureKelvinMax)) : true); const isValidColorRGB = ((this.type === LightbulbType.Color) ? (Utils.required(this.colorHex) && Colors.isValidHex(this.colorHex)) : true); // Store fields failing validation if (!isValidDefaultState) this.errorFields.push(prefix + '.' + this.fieldNames.defaultState); if (!isValidType) this.errorFields.push(prefix + '.' + this.fieldNames.type); if (!isValidBrightness) this.errorFields.push(prefix + '.' + this.fieldNames.brightness); if (!isValidColorTemperature) this.errorFields.push(prefix + '.' + this.fieldNames.colorTemperatureKelvin); if (!isValidColorRGB) this.errorFields.push(prefix + '.' + this.fieldNames.colorHex); return [ (isValidDefaultState && isValidType && isValidBrightness && isValidColorTemperature && isValidColorRGB), this.errorFields, ]; } } //# sourceMappingURL=configurationLightbulb.js.map