UNPKG

@pst-on-npm/homebridge-enocean

Version:
118 lines 4.89 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.EepParser_A5_08 = void 0; const EnoCore = __importStar(require("enocean-core")); const EepParser_1 = require("./EepParser"); const util_1 = require("../util"); /* * A5-08: 4BS - Light, Temperature and Occupancy Sensor * * Supported types: * * 01 Range 0lx to 510lx, 0°C to +51°C and Occupancy Button * 02 Range 0lx to 1020lx, 0°C to +51°C and Occupancy Button * 03 Range 0lx to 1530lx, -30°C to +50°C and Occupancy Button */ class EepParser_A5_08 extends EepParser_1.EepParser { _limitsOfType = { // A5-08-01 Range 0lx to 510lx, 0°C to +51°C and Occupancy Button 0x01: { tMin: 0, mT: 51 / 255, lMin: 0, mL: 510 / 255, bMin: 0, mB: 5.1 / 255 }, // A5-08-02 Range 0lx to 1020lx, 0°C to +51°C and Occupancy Button 0x02: { tMin: 0, mT: 51 / 255, lMin: 0, mL: 1020 / 255, bMin: 0, mB: 5.1 / 255 }, // A5-08-03 Range 0lx to 1530lx, -30°C to +50°C and Occupancy Button 0x03: { tMin: -30, mT: 50 / 255, lMin: 0, mL: 1530 / 255, bMin: 0, mB: 5.1 / 255 }, }; _limits; /** * Initializes an instance of EepParser_A5_04 * @param type the EEP type */ constructor(type) { super(type); if (type in this._limitsOfType) { this._limits = this._limitsOfType[type]; } else { throw new Error(`${util_1.Util.toHexString(type)}: EEP type not supported`); } } parse(telegram) { this.assertROrg(EnoCore.RORGs.FOURBS, telegram); const db0 = telegram.getDB(0); const db1 = telegram.getDB(1); const db2 = telegram.getDB(2); const db3 = telegram.getDB(3); const eep = super.parseBase(telegram); eep.values.isMotionDetected = (db0 & 0x02) === 0; if (this.manufacturerId !== EnoCore.Manufacturers.ELTAKO) { eep.values.isOccupancyDetected = (db0 & 0x01) === 0; eep.values.temperature = this._limits.tMin + db1 * this._limits.mT; } // Extended range from Eltako const mL = (this.manufacturerId === EnoCore.Manufacturers.ELTAKO) ? 2048 / 255 : this._limits.mL; eep.values.ambientLightLevel = Math.round(this._limits.lMin + db2 * mL); const vBatt = this._limits.bMin + db3 * this._limits.mB; const vLow = 2.7; // From FHEM ELTAKO FABH65S const vHigh = 4.4; const batteryLevel = (vBatt - vLow) * 100 / (vHigh - vLow); eep.values.batteryLevel = Math.max(0, Math.min(100, batteryLevel)); eep.values.isBatteryLow = batteryLevel < 10; return eep; } toString(values) { const type = this.eepType.toString(16).padStart(2, '0').toUpperCase(); const temp = values.temperature?.toFixed(1); const alev = values.ambientLightLevel?.toFixed(0); let msg = `${this.constructor.name}-${type}: E=${alev} lx`; if (temp !== undefined) { msg += ` T=${temp} °C`; } if (values.batteryLevel !== undefined) { const bLev = values.batteryLevel?.toFixed(0); const bLow = values.isBatteryLow; msg += ` B=${bLev} % (${bLow ? 'low' : 'ok'})`; } if (values.isOccupancyDetected) { msg += ' OCCUPANCY'; } else if (values.isMotionDetected) { msg += ' MOTION'; } return msg; } } exports.EepParser_A5_08 = EepParser_A5_08; //# sourceMappingURL=EepParser_A5_08.js.map