UNPKG

@zegl/homebridge-z2m

Version:

Expose your Zigbee devices to HomeKit with ease, by integrating Zigbee2MQTT with Homebridge.

80 lines 4.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAvailabilityConfigurationForDevices = exports.isAvailabilityEnabledGlobally = void 0; /** * Check if availability is configured. Based on utils.isAvailabilityEnabledForEntity from Zigbee2MQTT code base. * @param config config part of the object published to bridge/info * @returns True if availability is configured */ function isAvailabilityEnabledGlobally(config) { var _a, _b, _c, _d, _e; const availabilityEnabled = config.availability || ((_a = config.advanced) === null || _a === void 0 ? void 0 : _a.availability_timeout); if (!availabilityEnabled) { return false; } let passList = (_c = (_b = config.advanced) === null || _b === void 0 ? void 0 : _b.availability_passlist) !== null && _c !== void 0 ? _c : []; passList = passList.concat((_e = (_d = config.advanced) === null || _d === void 0 ? void 0 : _d.availability_whitelist) !== null && _e !== void 0 ? _e : []); // If a pass list is defined, availability cannot be considered globally enabled. return passList.length === 0; } exports.isAvailabilityEnabledGlobally = isAvailabilityEnabledGlobally; /** * Check if availability is explicitly enabled or disabled for any devices. * Based on utils.isAvailabilityEnabledForEntity from Zigbee2MQTT code base. * @param config config part of the object published to bridge/info * @param logger Logger */ function getAvailabilityConfigurationForDevices(config, logger) { var _a, _b, _c, _d; const result = getAvailabilityFromDeviceConfigurations(config, logger); // Also check availability_passlist, availability_blocklist, availability_whitelist and availability_blacklist. if ('advanced' in config) { let passList = (_a = config.advanced.availability_passlist) !== null && _a !== void 0 ? _a : []; passList = passList.concat((_b = config.advanced.availability_whitelist) !== null && _b !== void 0 ? _b : []); if (passList.length > 0) { // Add all entries from pass list to result.enabled for (const device of passList) { _logAvailabilityConfigForDevice(logger, device, true, 'pass list'); result.enabled.push(device); } } else { // Block list only used if pass list is not defined. let blockList = (_c = config.advanced.availability_blocklist) !== null && _c !== void 0 ? _c : []; blockList = blockList.concat((_d = config.advanced.availability_blacklist) !== null && _d !== void 0 ? _d : []); for (const device of blockList) { _logAvailabilityConfigForDevice(logger, device, false, 'block list'); result.disabled.push(device); } } } return result; } exports.getAvailabilityConfigurationForDevices = getAvailabilityConfigurationForDevices; function getAvailabilityFromDeviceConfigurations(config, logger) { var _a; const result = { enabled: new Array(), disabled: new Array(), }; if ('devices' in config && typeof config.devices === 'object') { for (const device of Object.keys(config.devices)) { if (config.devices[device].availability !== undefined) { const name = (_a = config.devices[device].friendly_name) !== null && _a !== void 0 ? _a : device; if (config.devices[device].availability === false) { _logAvailabilityConfigForDevice(logger, name, false, 'device config'); result.disabled.push(device); } else { _logAvailabilityConfigForDevice(logger, name, true, 'device config'); result.enabled.push(device); } } } } return result; } function _logAvailabilityConfigForDevice(logger, device, enabled, source) { logger === null || logger === void 0 ? void 0 : logger.debug(`Availability feature is ${enabled ? 'enabled' : 'disabled'} for device '${device}' (via ${source})`); } //# sourceMappingURL=configHelpers.js.map