UNPKG

homebridge-homewizard-energy-socket

Version:

This Homebridge plugin exposes your HomeWizard Energy Sockets to Apple HomeKit. So you can use the Home App to switch your Energy Sockets on or off and integrate the Energy Sockets into your Home Automations.

87 lines 3.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.configSchema = exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MAX = exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MIN = exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION = exports.DEFAULT_OUTLETINUSE_THRESHOLD_MAX = exports.DEFAULT_OUTLETINUSE_THRESHOLD_MIN = exports.DEFAULT_OUTLETINUSE_THRESHOLD = exports.DEFAULT_OUTLETINUSE_ISACTIVE = void 0; const zod_1 = require("zod"); const isIP_1 = __importDefault(require("validator/lib/isIP")); exports.DEFAULT_OUTLETINUSE_ISACTIVE = false; exports.DEFAULT_OUTLETINUSE_THRESHOLD = 5; exports.DEFAULT_OUTLETINUSE_THRESHOLD_MIN = 0.1; exports.DEFAULT_OUTLETINUSE_THRESHOLD_MAX = 3680; exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION = 10; exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MIN = 0; exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MAX = 86400; exports.configSchema = zod_1.z.object({ name: zod_1.z.string({ required_error: 'A bridge name is required', }), energySockets: zod_1.z .array(zod_1.z.object({ ip: zod_1.z .string({ required_error: 'IP address is required for each Energy Socket', invalid_type_error: "'ip' must be a string", }) .refine(ip => (0, isIP_1.default)(ip, 4), ip => ({ message: `'${ip}' is not a valid IPv4 address`, })), name: zod_1.z.string({ required_error: 'Name is required for each Energy Socket', invalid_type_error: "'name' must be a string", }), outletInUse: zod_1.z .object({ isActive: zod_1.z .boolean({ invalid_type_error: "'isActive' must be a boolean", }) .optional(), threshold: zod_1.z .number({ invalid_type_error: "'threshold' must be a number", }) .min(exports.DEFAULT_OUTLETINUSE_THRESHOLD_MIN) .max(exports.DEFAULT_OUTLETINUSE_THRESHOLD_MAX) .optional(), thresholdDuration: zod_1.z .number({ invalid_type_error: "'thresholdDuration' must be a number", }) .min(exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MIN) .max(exports.DEFAULT_OUTLETINUSE_THRESHOLD_DURATION_MAX) .optional(), verboseLogging: zod_1.z .boolean({ invalid_type_error: "'verboseLogging' must be a boolean", }) .optional(), }) .optional() .superRefine((schema, ctx) => { const isActive = schema === null || schema === void 0 ? void 0 : schema.isActive; const threshold = schema === null || schema === void 0 ? void 0 : schema.threshold; const thresholdDuration = schema === null || schema === void 0 ? void 0 : schema.thresholdDuration; if (isActive) { if (!threshold) { ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ['threshold'], message: 'A threshold is required when outletInUse.isActive is true', }); } if (!thresholdDuration) { ctx.addIssue({ code: zod_1.z.ZodIssueCode.custom, path: ['thresholdDuration'], message: 'A thresholdDuration is required when outletInUse.isActive is true', }); } } return zod_1.z.NEVER; }), })) .optional(), }); //# sourceMappingURL=config.schema.js.map