mclimate-payload-helper 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/decoders/payloadParsers/index.d.ts +1 -1
- package/dist/decoders/payloadParsers/index.js +1 -1
- package/dist/decoders/payloadParsers/pirMiniPayloadParser.d.ts +2 -0
- package/dist/decoders/payloadParsers/pirMiniPayloadParser.d.ts.map +1 -0
- package/dist/decoders/payloadParsers/pirMiniPayloadParser.js +82 -0
- package/dist/decoders/payloadParsers/pirMiniPayloadParser.js.map +1 -0
- package/dist/decoders/payloadParsers/types/allDevices.d.ts +1 -1
- package/dist/decoders/payloadParsers/types/allDevices.js +1 -1
- package/dist/decoders/payloadParsers/uplinkPayloadParser.js +2 -2
- package/dist/encoders/CommandBuilder.js +1 -1
- package/dist/encoders/PirMiniCommands.d.ts +17 -0
- package/dist/encoders/PirMiniCommands.d.ts.map +1 -0
- package/dist/encoders/PirMiniCommands.js +152 -0
- package/dist/encoders/PirMiniCommands.js.map +1 -0
- package/dist/encoders/PirMiniCommands.test.d.ts +2 -0
- package/dist/encoders/PirMiniCommands.test.d.ts.map +1 -0
- package/dist/encoders/PirMiniCommands.test.js +38 -0
- package/dist/encoders/PirMiniCommands.test.js.map +1 -0
- package/dist/encoders/index.d.ts +1 -1
- package/dist/encoders/index.js +1 -1
- package/dist/encoders/types/schemas.d.ts +15 -15
- package/dist/encoders/types/schemas.js +5 -5
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -3
- package/dist/test/payloadDecoders.test.js +4 -4
- package/package.json +1 -1
- package/src/decoders/payloadParsers/index.ts +1 -1
- package/src/decoders/payloadParsers/{pirOnlyPayloadParser.ts → pirMiniPayloadParser.ts} +6 -6
- package/src/decoders/payloadParsers/types/allDevices.ts +1 -1
- package/src/decoders/payloadParsers/uplinkPayloadParser.ts +3 -3
- package/src/encoders/CommandBuilder.ts +2 -2
- package/src/encoders/{PirOnlyCommands.test.ts → PirMiniCommands.test.ts} +2 -2
- package/src/encoders/{PirOnlyCommands.ts → PirMiniCommands.ts} +14 -14
- package/src/encoders/index.ts +1 -1
- package/src/encoders/types/schemas.ts +16 -16
- package/src/index.ts +2 -2
- package/src/test/payloadDecoders.test.ts +4 -4
|
@@ -20,5 +20,5 @@ export * from './melissaLorawanPayloadParser';
|
|
|
20
20
|
export * from './co2PirLitePayloadParser';
|
|
21
21
|
export * from './htPirLitePayloadParser';
|
|
22
22
|
export * from './multisensorPayloadParser';
|
|
23
|
-
export * from './
|
|
23
|
+
export * from './pirMiniPayloadParser';
|
|
24
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -36,5 +36,5 @@ __exportStar(require("./melissaLorawanPayloadParser"), exports);
|
|
|
36
36
|
__exportStar(require("./co2PirLitePayloadParser"), exports);
|
|
37
37
|
__exportStar(require("./htPirLitePayloadParser"), exports);
|
|
38
38
|
__exportStar(require("./multisensorPayloadParser"), exports);
|
|
39
|
-
__exportStar(require("./
|
|
39
|
+
__exportStar(require("./pirMiniPayloadParser"), exports);
|
|
40
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pirMiniPayloadParser.d.ts","sourceRoot":"","sources":["../../../src/decoders/payloadParsers/pirMiniPayloadParser.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,oBAAoB,YAAa,MAAM,wCA+EnD,CAAA"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pirMiniPayloadParser = void 0;
|
|
4
|
+
const commandsReadingHelper_1 = require("../../decoders/commandsReadingHelper");
|
|
5
|
+
const types_1 = require("../../decoders/payloadParsers/types");
|
|
6
|
+
const helpers_1 = require("../../helpers");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const pirMiniPayloadParser = (hexData) => {
|
|
9
|
+
const deviceData = {};
|
|
10
|
+
try {
|
|
11
|
+
const handleKeepAliveData = (bytes) => {
|
|
12
|
+
const keepaliveData = {};
|
|
13
|
+
// Byte 1 (bits 1:0) and Byte 2: Internal temperature sensor data
|
|
14
|
+
// Formula: t[°C] = (T[9:0] - 400) / 10
|
|
15
|
+
// Extract bits 1:0 from byte 1 for the higher bits (bits 9:8)
|
|
16
|
+
const tempHighBits = (bytes[1] & 0x03) << 8;
|
|
17
|
+
// Use all bits from byte 2 for the lower bits (bits 7:0)
|
|
18
|
+
const tempLowBits = bytes[2];
|
|
19
|
+
// Combine to get the full 10-bit temperature value
|
|
20
|
+
const tempValue = tempHighBits | tempLowBits;
|
|
21
|
+
keepaliveData.sensorTemperature = Number(((tempValue - 400) / 10).toFixed(2));
|
|
22
|
+
// Byte 3: Relative Humidity data
|
|
23
|
+
// Formula: RH[%] = (XX * 100) / 256
|
|
24
|
+
keepaliveData.relativeHumidity = Number(((bytes[3] * 100) / 256).toFixed(2));
|
|
25
|
+
// Bytes 4-5: Light sensor data
|
|
26
|
+
// Byte 4: Light sensor data bits [15:8]
|
|
27
|
+
// Byte 5: Light sensor data bits [7:0]
|
|
28
|
+
keepaliveData.light = (bytes[4] << 8) | bytes[5];
|
|
29
|
+
// Byte 6: Battery Voltage
|
|
30
|
+
// Battery voltage [mV] = ((XX * 2200) / 255) + 1600
|
|
31
|
+
keepaliveData.batteryVoltage = Number((((bytes[6] * 2200) / 255 + 1600) / 1000).toFixed(2));
|
|
32
|
+
// Byte 7 bit 0: Occupancy Flag (1 = Occupied, 0 = Unoccupied)
|
|
33
|
+
keepaliveData.occupied = (bytes[7] & 0x01) === 1;
|
|
34
|
+
// Bytes 8-9: PIR trigger count data
|
|
35
|
+
// Byte 8: PIR trigger count bits [15:8]
|
|
36
|
+
// Byte 9: PIR trigger count bits [7:0]
|
|
37
|
+
keepaliveData.pirTriggerCount = (bytes[8] << 8) | bytes[9];
|
|
38
|
+
Object.assign(deviceData, Object.assign({}, deviceData), Object.assign({}, keepaliveData));
|
|
39
|
+
};
|
|
40
|
+
if (hexData) {
|
|
41
|
+
const byteArray = (0, helpers_1.byteArrayParser)(hexData);
|
|
42
|
+
if (!byteArray)
|
|
43
|
+
return;
|
|
44
|
+
// Route the message based on the command byte
|
|
45
|
+
if (byteArray[0] == 1) {
|
|
46
|
+
// This is a keepalive message
|
|
47
|
+
handleKeepAliveData(byteArray);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
// parse command answers
|
|
51
|
+
const data = (0, commandsReadingHelper_1.commandsReadingHelper)(hexData, 20, types_1.DeviceType.PirMini);
|
|
52
|
+
if (!data)
|
|
53
|
+
return;
|
|
54
|
+
const shouldKeepAlive = Object.prototype.hasOwnProperty.call(data, 'decodeKeepalive');
|
|
55
|
+
if ('decodeKeepalive' in data) {
|
|
56
|
+
delete data.decodeKeepalive;
|
|
57
|
+
}
|
|
58
|
+
Object.assign(deviceData, Object.assign({}, deviceData), Object.assign({}, data));
|
|
59
|
+
// Handle the remaining keepalive data if present
|
|
60
|
+
if (shouldKeepAlive) {
|
|
61
|
+
// Extract the last 10 bytes which contain keepalive data for PIR Mini
|
|
62
|
+
const keepaliveData = hexData.slice(-20); // 10 bytes = 20 hex chars
|
|
63
|
+
const dataToPass = (0, helpers_1.byteArrayParser)(keepaliveData);
|
|
64
|
+
if (!dataToPass)
|
|
65
|
+
return;
|
|
66
|
+
handleKeepAliveData(dataToPass);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return deviceData;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
throw new utils_1.CustomError({
|
|
74
|
+
message: `Unhandled data`,
|
|
75
|
+
hexData: hexData,
|
|
76
|
+
deviceType: 'pir_mini',
|
|
77
|
+
originalError: e,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
exports.pirMiniPayloadParser = pirMiniPayloadParser;
|
|
82
|
+
//# sourceMappingURL=pirMiniPayloadParser.js.map
|
|
@@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D,iDAAiD;gBACjD,IAAI,eAAe,EAAE,CAAC;oBACrB,sEAAsE;oBACtE,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAA,CAAC,0BAA0B;oBACnE,MAAM,UAAU,GAAG,IAAA,yBAAe,EAAC,aAAa,CAAC,CAAA;oBACjD,IAAI,CAAC,UAAU;wBAAE,OAAM;oBACvB,mBAAmB,CAAC,UAAU,CAAC,CAAA;gBAChC,CAAC;YACF,CAAC;YACD,OAAO,UAAU,CAAA;QAClB,CAAC;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,MAAM,IAAI,mBAAW,CAAC;YACrB,OAAO,EAAE,gBAAgB;YACzB,OAAO,EAAE,OAAO;YAChB,UAAU,EAAE,UAAU;YACtB,aAAa,EAAE,CAAU;SACzB,CAAC,CAAA;IACH,CAAC;AACF,CAAC,CAAA;AA/EY,QAAA,oBAAoB,wBA+EhC"}
|
|
@@ -24,6 +24,6 @@ var DeviceType;
|
|
|
24
24
|
DeviceType["CO2PirLite"] = "co2_pir_lite";
|
|
25
25
|
DeviceType["HTPirLite"] = "ht_pir_lite";
|
|
26
26
|
DeviceType["MultiSensor"] = "multisensor";
|
|
27
|
-
DeviceType["
|
|
27
|
+
DeviceType["PirMini"] = "pir_mini";
|
|
28
28
|
})(DeviceType || (exports.DeviceType = DeviceType = {}));
|
|
29
29
|
//# sourceMappingURL=allDevices.js.map
|
|
@@ -47,8 +47,8 @@ const uplinkPayloadParser = (hexData, deviceType) => {
|
|
|
47
47
|
return (0, payloadParsers_1.htPirLitePayloadParser)(hexData);
|
|
48
48
|
case types_1.DeviceType.MultiSensor:
|
|
49
49
|
return (0, payloadParsers_1.multisensorPayloadParser)(hexData);
|
|
50
|
-
case types_1.DeviceType.
|
|
51
|
-
return (0, payloadParsers_1.
|
|
50
|
+
case types_1.DeviceType.PirMini:
|
|
51
|
+
return (0, payloadParsers_1.pirMiniPayloadParser)(hexData);
|
|
52
52
|
default:
|
|
53
53
|
// Q: is this OK?
|
|
54
54
|
return (0, payloadParsers_1.vickiPayloadParser)(hexData); // Default case if deviceType is not recognized
|
|
@@ -28,7 +28,7 @@ class CommandBuilder {
|
|
|
28
28
|
co2_pir_lite: encoders_1.Co2PirLiteCommands,
|
|
29
29
|
melissa_lorawan: encoders_1.MelissaCommands,
|
|
30
30
|
multisensor: encoders_1.MultiSensorCommands,
|
|
31
|
-
|
|
31
|
+
pir_mini: encoders_1.PirMiniCommands,
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
build(command, params) {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GeneralCommands } from '../encoders';
|
|
2
|
+
import { PirMiniCommandTypes } from '../encoders/types';
|
|
3
|
+
import { BaseCommand } from '../encoders';
|
|
4
|
+
export declare class PirMiniCommands extends GeneralCommands {
|
|
5
|
+
static setLightSensorState(params: PirMiniCommandTypes.SetLightSensorStateParams): BaseCommand;
|
|
6
|
+
static getLightSensorState(): BaseCommand;
|
|
7
|
+
static setLedBrightness(params: PirMiniCommandTypes.SetLedBrightnessParams): BaseCommand;
|
|
8
|
+
static getLedBrightness(): BaseCommand;
|
|
9
|
+
static setPIRSensorState(params: PirMiniCommandTypes.SetPIRSensorStateParams): BaseCommand;
|
|
10
|
+
static getPIRSensorState(): BaseCommand;
|
|
11
|
+
static setOccupancyTimeout(params: PirMiniCommandTypes.SetOccupancyTimeoutParams): BaseCommand;
|
|
12
|
+
static getOccupancyTimeout(): BaseCommand;
|
|
13
|
+
static setPIRDemoMode(params: PirMiniCommandTypes.SetPIRDemoModeParams): BaseCommand;
|
|
14
|
+
static getPIRDemoMode(): BaseCommand;
|
|
15
|
+
static restartDevice(): BaseCommand;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=PirMiniCommands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PirMiniCommands.d.ts","sourceRoot":"","sources":["../../src/encoders/PirMiniCommands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE5C,OAAO,EAAE,mBAAmB,EAAwB,MAAM,kBAAkB,CAAA;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAKxC,qBAAa,eAAgB,SAAQ,eAAe;IACnD,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,CAAC,yBAAyB;IAsBhF,MAAM,CAAC,mBAAmB;IAI1B,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,mBAAmB,CAAC,sBAAsB;IAsB1E,MAAM,CAAC,gBAAgB;IAIvB,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,CAAC,uBAAuB;IAsB5E,MAAM,CAAC,iBAAiB;IAIxB,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,CAAC,yBAAyB;IA0BhF,MAAM,CAAC,mBAAmB;IAI1B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,mBAAmB,CAAC,oBAAoB;IAsBtE,MAAM,CAAC,cAAc;IAIrB,MAAM,CAAC,aAAa;CAGpB"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PirMiniCommands = void 0;
|
|
4
|
+
const encoders_1 = require("../encoders");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const types_1 = require("../encoders/types");
|
|
7
|
+
const encoders_2 = require("../encoders");
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
const utils_2 = require("../utils");
|
|
10
|
+
const utils_3 = require("../utils");
|
|
11
|
+
class PirMiniCommands extends encoders_1.GeneralCommands {
|
|
12
|
+
static setLightSensorState(params) {
|
|
13
|
+
try {
|
|
14
|
+
types_1.DeviceCommandSchemas.PirMiniCommandSchemas.setLightSensorState.parse(params);
|
|
15
|
+
const { state } = params;
|
|
16
|
+
return new encoders_2.BaseCommand('SetLightSensorState', 0x1e, (0, utils_3.decToHex)(state));
|
|
17
|
+
}
|
|
18
|
+
catch (e) {
|
|
19
|
+
if (e instanceof zod_1.ZodError) {
|
|
20
|
+
throw new utils_2.CustomError({
|
|
21
|
+
message: 'Zod validation error during SetLightSensorState execution',
|
|
22
|
+
command: 'SetLightSensorState',
|
|
23
|
+
originalError: e,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new utils_2.CustomError({
|
|
28
|
+
message: 'Error during SetLightSensorState execution',
|
|
29
|
+
command: 'SetLightSensorState',
|
|
30
|
+
originalError: e,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
static getLightSensorState() {
|
|
36
|
+
return new encoders_2.BaseCommand('GetLightSensorState', 0x1f);
|
|
37
|
+
}
|
|
38
|
+
static setLedBrightness(params) {
|
|
39
|
+
try {
|
|
40
|
+
types_1.DeviceCommandSchemas.PirMiniCommandSchemas.setLedBrightness.parse(params);
|
|
41
|
+
const { red, green, blue } = params;
|
|
42
|
+
return new encoders_2.BaseCommand('SetLedBrightness', 0x21, (0, utils_3.decToHex)(red), (0, utils_3.decToHex)(green), (0, utils_3.decToHex)(blue));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
if (e instanceof zod_1.ZodError) {
|
|
46
|
+
throw new utils_2.CustomError({
|
|
47
|
+
message: 'Zod validation error during SetLedBrightness execution',
|
|
48
|
+
command: 'SetLedBrightness',
|
|
49
|
+
originalError: e,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
throw new utils_2.CustomError({
|
|
54
|
+
message: 'Error during SetLedBrightness execution',
|
|
55
|
+
command: 'SetLedBrightness',
|
|
56
|
+
originalError: e,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static getLedBrightness() {
|
|
62
|
+
return new encoders_2.BaseCommand('GetLedBrightness', 0x22);
|
|
63
|
+
}
|
|
64
|
+
static setPIRSensorState(params) {
|
|
65
|
+
try {
|
|
66
|
+
types_1.DeviceCommandSchemas.PirMiniCommandSchemas.setPIRSensorState.parse(params);
|
|
67
|
+
const { state } = params;
|
|
68
|
+
return new encoders_2.BaseCommand('SetPIRSensorState', 0x36, (0, utils_3.decToHex)(state));
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
if (e instanceof zod_1.ZodError) {
|
|
72
|
+
throw new utils_2.CustomError({
|
|
73
|
+
message: 'Zod validation error during SetPIRSensorState execution',
|
|
74
|
+
command: 'SetPIRSensorState',
|
|
75
|
+
originalError: e,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new utils_2.CustomError({
|
|
80
|
+
message: 'Error during SetPIRSensorState execution',
|
|
81
|
+
command: 'SetPIRSensorState',
|
|
82
|
+
originalError: e,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
static getPIRSensorState() {
|
|
88
|
+
return new encoders_2.BaseCommand('GetPIRSensorState', 0x37);
|
|
89
|
+
}
|
|
90
|
+
static setOccupancyTimeout(params) {
|
|
91
|
+
try {
|
|
92
|
+
types_1.DeviceCommandSchemas.PirMiniCommandSchemas.setOccupancyTimeout.parse(params);
|
|
93
|
+
const { timeout } = params;
|
|
94
|
+
// Convert timeout to two bytes (high byte and low byte)
|
|
95
|
+
const highByte = (timeout >> 8) & 0xff;
|
|
96
|
+
const lowByte = timeout & 0xff;
|
|
97
|
+
return new encoders_2.BaseCommand('SetOccupancyTimeout', 0x38, (0, utils_3.decToHex)(highByte) + (0, utils_3.decToHex)(lowByte));
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
if (e instanceof zod_1.ZodError) {
|
|
101
|
+
throw new utils_2.CustomError({
|
|
102
|
+
message: 'Zod validation error during SetOccupancyTimeout execution',
|
|
103
|
+
command: 'SetOccupancyTimeout',
|
|
104
|
+
originalError: e,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
throw new utils_2.CustomError({
|
|
109
|
+
message: 'Error during SetOccupancyTimeout execution',
|
|
110
|
+
command: 'SetOccupancyTimeout',
|
|
111
|
+
originalError: e,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
static getOccupancyTimeout() {
|
|
117
|
+
return new encoders_2.BaseCommand('GetOccupancyTimeout', 0x39);
|
|
118
|
+
}
|
|
119
|
+
static setPIRDemoMode(params) {
|
|
120
|
+
try {
|
|
121
|
+
types_1.DeviceCommandSchemas.PirMiniCommandSchemas.setPIRDemoMode.parse(params);
|
|
122
|
+
const { state } = params;
|
|
123
|
+
return new encoders_2.BaseCommand('SetPIRDemoMode', 0x3a, (0, utils_3.decToHex)(state));
|
|
124
|
+
}
|
|
125
|
+
catch (e) {
|
|
126
|
+
if (e instanceof zod_1.ZodError) {
|
|
127
|
+
throw new utils_2.CustomError({
|
|
128
|
+
message: 'Zod validation error during SetPIRDemoMode execution',
|
|
129
|
+
command: 'SetPIRDemoMode',
|
|
130
|
+
originalError: e,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
throw new utils_2.CustomError({
|
|
135
|
+
message: 'Error during SetPIRDemoMode execution',
|
|
136
|
+
command: 'SetPIRDemoMode',
|
|
137
|
+
originalError: e,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
static getPIRDemoMode() {
|
|
143
|
+
return new encoders_2.BaseCommand('GetPIRDemoMode', 0x3b);
|
|
144
|
+
}
|
|
145
|
+
static restartDevice() {
|
|
146
|
+
return new encoders_2.BaseCommand('RestartDevice', 0xa5);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
exports.PirMiniCommands = PirMiniCommands;
|
|
150
|
+
(0, utils_1.applyMixins)(PirMiniCommands, [encoders_1.GeneralCommands]);
|
|
151
|
+
(0, utils_1.delMethods)(PirMiniCommands, []);
|
|
152
|
+
//# sourceMappingURL=PirMiniCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PirMiniCommands.js","sourceRoot":"","sources":["../../src/encoders/PirMiniCommands.ts"],"names":[],"mappings":";;;AAAA,yCAA4C;AAC5C,mCAAiD;AACjD,4CAA4E;AAC5E,yCAAwC;AACxC,6BAA8B;AAC9B,mCAAqC;AACrC,mCAAkC;AAElC,MAAa,eAAgB,SAAQ,0BAAe;IACnD,MAAM,CAAC,mBAAmB,CAAC,MAAqD;QAC/E,IAAI,CAAC;YACJ,4BAAoB,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC5E,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;YACxB,OAAO,IAAI,sBAAW,CAAC,qBAAqB,EAAE,IAAI,EAAE,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC,CAAA;QACrE,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACZ,IAAI,CAAC,YAAY,cAAQ,EAAE,CAAC;gBAC3B,MAAM,IAAI,mBAAW,CAAC;oBACrB,OAAO,EAAE,2DAA2D;oBACpE,OAAO,EAAE,qBAAqB;oBAC9B,aAAa,EAAE,CAAC;iBAChB,CAAC,CAAA;YACH,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,mBAAW,CAAC;oBACrB,OAAO,EAAE,4CAA4C;oBACrD,OAAO,EAAE,qBAAqB;oBAC9B,aAAa,EAAE,CAAU;iBACzB,CAAC,CAAA;YACH,CAAC;QACF,CAAC;IACF,CAAC;IAED,MAAM,CAAC,mBAAmB;QACzB,OAAO,IAAI,sBAAW,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAkD;QACz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
|
+
{"version":3,"file":"PirMiniCommands.test.d.ts","sourceRoot":"","sources":["../../src/encoders/PirMiniCommands.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const encoders_1 = require("../encoders");
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
describe('PirMiniCommands payload encoder', () => {
|
|
6
|
+
const commandBuilder = new encoders_1.CommandBuilder('pir_mini');
|
|
7
|
+
test('SetLightSensorState encodes enabled flag', () => {
|
|
8
|
+
expect(commandBuilder.build('SetLightSensorState', { state: 1 })).toStrictEqual(new encoders_1.BaseCommand('SetLightSensorState', 0x1e, '01'));
|
|
9
|
+
});
|
|
10
|
+
test('SetLightSensorState encodes disabled flag', () => {
|
|
11
|
+
expect(commandBuilder.build('SetLightSensorState', { state: 0 })).toStrictEqual(new encoders_1.BaseCommand('SetLightSensorState', 0x1e, '00'));
|
|
12
|
+
});
|
|
13
|
+
test('SetLedBrightness encodes RGB values', () => {
|
|
14
|
+
expect(commandBuilder.build('SetLedBrightness', { red: 47, green: 42, blue: 59 })).toStrictEqual(new encoders_1.BaseCommand('SetLedBrightness', 0x21, '2F', '2A', '3B'));
|
|
15
|
+
});
|
|
16
|
+
test('SetPIRSensorState encodes enabled flag', () => {
|
|
17
|
+
expect(commandBuilder.build('SetPIRSensorState', { state: 1 })).toStrictEqual(new encoders_1.BaseCommand('SetPIRSensorState', 0x36, '01'));
|
|
18
|
+
});
|
|
19
|
+
test('SetOccupancyTimeout encodes timeout into two bytes', () => {
|
|
20
|
+
expect(commandBuilder.build('SetOccupancyTimeout', { timeout: 60 })).toStrictEqual(new encoders_1.BaseCommand('SetOccupancyTimeout', 0x38, '003C'));
|
|
21
|
+
});
|
|
22
|
+
test('SetPIRDemoMode encodes enabled flag', () => {
|
|
23
|
+
expect(commandBuilder.build('SetPIRDemoMode', { state: 1 })).toStrictEqual(new encoders_1.BaseCommand('SetPIRDemoMode', 0x3a, '01'));
|
|
24
|
+
});
|
|
25
|
+
test('RestartDevice emits restart command', () => {
|
|
26
|
+
expect(commandBuilder.build('RestartDevice')).toStrictEqual(new encoders_1.BaseCommand('RestartDevice', 0xa5));
|
|
27
|
+
});
|
|
28
|
+
test('Invalid SetPIRSensorState throws validation error', () => {
|
|
29
|
+
expect(() => commandBuilder.build('SetPIRSensorState', { state: 2 })).toThrow(utils_1.CustomError);
|
|
30
|
+
});
|
|
31
|
+
test('Invalid SetLedBrightness throws validation error', () => {
|
|
32
|
+
expect(() => commandBuilder.build('SetLedBrightness', { red: 101, green: 0, blue: 0 })).toThrow(utils_1.CustomError);
|
|
33
|
+
});
|
|
34
|
+
test('Invalid SetLightSensorState throws validation error', () => {
|
|
35
|
+
expect(() => commandBuilder.build('SetLightSensorState', { state: 2 })).toThrow(utils_1.CustomError);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=PirMiniCommands.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PirMiniCommands.test.js","sourceRoot":"","sources":["../../src/encoders/PirMiniCommands.test.ts"],"names":[],"mappings":";;AAAA,yCAAwD;AACxD,mCAAqC;AAErC,QAAQ,CAAC,iCAAiC,EAAE,GAAG,EAAE;IAChD,MAAM,cAAc,GAAG,IAAI,yBAAc,CAAC,UAAU,CAAC,CAAA;IAErD,IAAI,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACrD,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAC9E,IAAI,sBAAW,CAAC,qBAAqB,EAAE,IAAI,EAAE,IAAI,CAAC,CAClD,CAAA;IACF,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,2CAA2C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,qBAAq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;IACF,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,qCAAqC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,sBAAW,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAA;IACpG,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC9D,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,mBAAmB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAW,CAAC,CAAA;IAC3F,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC7D,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,kBAAkB,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAW,CAAC,CAAA;IAC7G,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAChE,MAAM,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,mBAAW,CAAC,CAAA;IAC7F,CAAC,CAAC,CAAA;AACH,CAAC,CAAC,CAAA"}
|
package/dist/encoders/index.d.ts
CHANGED
|
@@ -26,5 +26,5 @@ export * from './HTPirLiteCommands';
|
|
|
26
26
|
export * from './Co2PirLiteCommands';
|
|
27
27
|
export * from './MelissaCommands';
|
|
28
28
|
export * from './MultiSensorCommands';
|
|
29
|
-
export * from './
|
|
29
|
+
export * from './PirMiniCommands';
|
|
30
30
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/encoders/index.js
CHANGED
|
@@ -42,5 +42,5 @@ __exportStar(require("./HTPirLiteCommands"), exports);
|
|
|
42
42
|
__exportStar(require("./Co2PirLiteCommands"), exports);
|
|
43
43
|
__exportStar(require("./MelissaCommands"), exports);
|
|
44
44
|
__exportStar(require("./MultiSensorCommands"), exports);
|
|
45
|
-
__exportStar(require("./
|
|
45
|
+
__exportStar(require("./PirMiniCommands"), exports);
|
|
46
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -186,7 +186,7 @@ export declare const Co2PirLiteEnums: {
|
|
|
186
186
|
1: string;
|
|
187
187
|
};
|
|
188
188
|
};
|
|
189
|
-
export declare const
|
|
189
|
+
export declare const PirMiniEnums: {
|
|
190
190
|
readonly setPIRSensorState: {
|
|
191
191
|
0: string;
|
|
192
192
|
1: string;
|
|
@@ -6028,7 +6028,7 @@ export declare namespace MultiSensorCommandTypes {
|
|
|
6028
6028
|
type SetPirStateParams = z.infer<typeof MultiSensorCommandSchemas.setPirState>;
|
|
6029
6029
|
type SetPirActiveReportingPeriodParams = z.infer<typeof MultiSensorCommandSchemas.setPirActiveReportingPeriod>;
|
|
6030
6030
|
}
|
|
6031
|
-
declare const
|
|
6031
|
+
declare const PirMiniCommandSchemas: {
|
|
6032
6032
|
setLightSensorState: z.ZodObject<{
|
|
6033
6033
|
state: z.ZodNumber;
|
|
6034
6034
|
commandNumber: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -6223,18 +6223,18 @@ declare const PirOnlyCommandSchemas: {
|
|
|
6223
6223
|
commandNumber?: string | undefined;
|
|
6224
6224
|
}>;
|
|
6225
6225
|
};
|
|
6226
|
-
export declare namespace
|
|
6227
|
-
type SetLightSensorStateParams = z.infer<typeof
|
|
6228
|
-
type GetLightSensorStateParams = z.infer<typeof
|
|
6229
|
-
type SetLedBrightnessParams = z.infer<typeof
|
|
6230
|
-
type GetLedBrightnessParams = z.infer<typeof
|
|
6231
|
-
type SetPIRSensorStateParams = z.infer<typeof
|
|
6232
|
-
type GetPIRSensorStateParams = z.infer<typeof
|
|
6233
|
-
type SetOccupancyTimeoutParams = z.infer<typeof
|
|
6234
|
-
type GetOccupancyTimeoutParams = z.infer<typeof
|
|
6235
|
-
type SetPIRDemoModeParams = z.infer<typeof
|
|
6236
|
-
type GetPIRDemoModeParams = z.infer<typeof
|
|
6237
|
-
type RestartDeviceParams = z.infer<typeof
|
|
6226
|
+
export declare namespace PirMiniCommandTypes {
|
|
6227
|
+
type SetLightSensorStateParams = z.infer<typeof PirMiniCommandSchemas.setLightSensorState>;
|
|
6228
|
+
type GetLightSensorStateParams = z.infer<typeof PirMiniCommandSchemas.getLightSensorState>;
|
|
6229
|
+
type SetLedBrightnessParams = z.infer<typeof PirMiniCommandSchemas.setLedBrightness>;
|
|
6230
|
+
type GetLedBrightnessParams = z.infer<typeof PirMiniCommandSchemas.getLedBrightness>;
|
|
6231
|
+
type SetPIRSensorStateParams = z.infer<typeof PirMiniCommandSchemas.setPIRSensorState>;
|
|
6232
|
+
type GetPIRSensorStateParams = z.infer<typeof PirMiniCommandSchemas.getPIRSensorState>;
|
|
6233
|
+
type SetOccupancyTimeoutParams = z.infer<typeof PirMiniCommandSchemas.setOccupancyTimeout>;
|
|
6234
|
+
type GetOccupancyTimeoutParams = z.infer<typeof PirMiniCommandSchemas.getOccupancyTimeout>;
|
|
6235
|
+
type SetPIRDemoModeParams = z.infer<typeof PirMiniCommandSchemas.setPIRDemoMode>;
|
|
6236
|
+
type GetPIRDemoModeParams = z.infer<typeof PirMiniCommandSchemas.getPIRDemoMode>;
|
|
6237
|
+
type RestartDeviceParams = z.infer<typeof PirMiniCommandSchemas.restartDevice>;
|
|
6238
6238
|
}
|
|
6239
6239
|
export declare const DeviceCommandSchemas: {
|
|
6240
6240
|
GeneralCommandSchemas: {
|
|
@@ -12081,7 +12081,7 @@ export declare const DeviceCommandSchemas: {
|
|
|
12081
12081
|
commandNumber?: string | undefined;
|
|
12082
12082
|
}>;
|
|
12083
12083
|
};
|
|
12084
|
-
|
|
12084
|
+
PirMiniCommandSchemas: {
|
|
12085
12085
|
setLightSensorState: z.ZodObject<{
|
|
12086
12086
|
state: z.ZodNumber;
|
|
12087
12087
|
commandNumber: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeviceCommandSchemas = exports.
|
|
3
|
+
exports.DeviceCommandSchemas = exports.PirMiniEnums = exports.Co2PirLiteEnums = exports.HTPirLiteEnums = exports.ButtonEnums = exports.WirelessThermostatEnums = exports.FloodEnums = exports.TValveEnums = exports.FanCoilThermostatEnums = exports.Relay16Enums = exports.VickiEnums = exports.GeneralCommandsEnums = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
/* ---------------------------------------HELPER ENUM DEFINITIONS--------------------------------------- */
|
|
@@ -193,7 +193,7 @@ exports.Co2PirLiteEnums = {
|
|
|
193
193
|
1: 'Enabled',
|
|
194
194
|
},
|
|
195
195
|
};
|
|
196
|
-
exports.
|
|
196
|
+
exports.PirMiniEnums = {
|
|
197
197
|
setPIRSensorState: {
|
|
198
198
|
0: 'Disabled',
|
|
199
199
|
1: 'Enabled',
|
|
@@ -1391,8 +1391,8 @@ const MultiSensorCommandSchemas = Object.assign(Object.assign({}, GeneralCommand
|
|
|
1391
1391
|
}), restart: zod_1.z.object({
|
|
1392
1392
|
commandNumber: zod_1.z.string().optional().default('a5'),
|
|
1393
1393
|
}) });
|
|
1394
|
-
/* --------------------------------------- PIR
|
|
1395
|
-
const
|
|
1394
|
+
/* --------------------------------------- PIR MINI COMMANDS --------------------------------------- */
|
|
1395
|
+
const PirMiniCommandSchemas = Object.assign(Object.assign({}, GeneralCommandSchemas), { setLightSensorState: zod_1.z.object({
|
|
1396
1396
|
state: zod_1.z.number().min(0).max(1), // 0: disabled, 1: enabled
|
|
1397
1397
|
commandNumber: zod_1.z.string().optional().default('1e'),
|
|
1398
1398
|
}), getLightSensorState: zod_1.z.object({
|
|
@@ -1449,6 +1449,6 @@ exports.DeviceCommandSchemas = {
|
|
|
1449
1449
|
Co2PirLiteCommandSchemas,
|
|
1450
1450
|
MelissaCommandSchemas,
|
|
1451
1451
|
MultiSensorCommandSchemas,
|
|
1452
|
-
|
|
1452
|
+
PirMiniCommandSchemas,
|
|
1453
1453
|
};
|
|
1454
1454
|
//# sourceMappingURL=schemas.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { uplinkPayloadParser } from './decoders/payloadParsers';
|
|
2
2
|
export { DeviceType } from './decoders/payloadParsers/types';
|
|
3
|
-
export { CommandBuilder, VickiCommands, WirelessThermostatCommands, SetAqiLedCommands, Relay16Commands, TFloodCommands, OpenCloseSensorCommands, TringThermostatCommands, FanCoilThermostatCommands, TValveCommands, CO2SensorCommands, CO2DisplayCommands, DskDeviceCommands, ButtonCommands, HTSensorCommands, HTDisplayLite, CO2DisplayLiteCommands, Relay16DryCommands, Co2PirLiteCommands, HTPirLiteCommands,
|
|
4
|
-
export { DeviceCommandSchemas, VickiEnums, Relay16Enums, FanCoilThermostatEnums, TValveEnums, WirelessThermostatEnums, ButtonEnums, GeneralCommandsEnums, FloodEnums, Co2PirLiteEnums, HTPirLiteEnums,
|
|
3
|
+
export { CommandBuilder, VickiCommands, WirelessThermostatCommands, SetAqiLedCommands, Relay16Commands, TFloodCommands, OpenCloseSensorCommands, TringThermostatCommands, FanCoilThermostatCommands, TValveCommands, CO2SensorCommands, CO2DisplayCommands, DskDeviceCommands, ButtonCommands, HTSensorCommands, HTDisplayLite, CO2DisplayLiteCommands, Relay16DryCommands, Co2PirLiteCommands, HTPirLiteCommands, PirMiniCommands, } from './encoders';
|
|
4
|
+
export { DeviceCommandSchemas, VickiEnums, Relay16Enums, FanCoilThermostatEnums, TValveEnums, WirelessThermostatEnums, ButtonEnums, GeneralCommandsEnums, FloodEnums, Co2PirLiteEnums, HTPirLiteEnums, PirMiniEnums, } from './encoders/types';
|
|
5
5
|
export { CustomError } from './utils';
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CustomError = exports.
|
|
3
|
+
exports.CustomError = exports.PirMiniEnums = exports.HTPirLiteEnums = exports.Co2PirLiteEnums = exports.FloodEnums = exports.GeneralCommandsEnums = exports.ButtonEnums = exports.WirelessThermostatEnums = exports.TValveEnums = exports.FanCoilThermostatEnums = exports.Relay16Enums = exports.VickiEnums = exports.DeviceCommandSchemas = exports.PirMiniCommands = exports.HTPirLiteCommands = exports.Co2PirLiteCommands = exports.Relay16DryCommands = exports.CO2DisplayLiteCommands = exports.HTDisplayLite = exports.HTSensorCommands = exports.ButtonCommands = exports.DskDeviceCommands = exports.CO2DisplayCommands = exports.CO2SensorCommands = exports.TValveCommands = exports.FanCoilThermostatCommands = exports.TringThermostatCommands = exports.OpenCloseSensorCommands = exports.TFloodCommands = exports.Relay16Commands = exports.SetAqiLedCommands = exports.WirelessThermostatCommands = exports.VickiCommands = exports.CommandBuilder = exports.DeviceType = exports.uplinkPayloadParser = void 0;
|
|
4
4
|
var payloadParsers_1 = require("./decoders/payloadParsers");
|
|
5
5
|
Object.defineProperty(exports, "uplinkPayloadParser", { enumerable: true, get: function () { return payloadParsers_1.uplinkPayloadParser; } });
|
|
6
6
|
var types_1 = require("./decoders/payloadParsers/types");
|
|
@@ -26,7 +26,7 @@ Object.defineProperty(exports, "CO2DisplayLiteCommands", { enumerable: true, get
|
|
|
26
26
|
Object.defineProperty(exports, "Relay16DryCommands", { enumerable: true, get: function () { return encoders_1.Relay16DryCommands; } });
|
|
27
27
|
Object.defineProperty(exports, "Co2PirLiteCommands", { enumerable: true, get: function () { return encoders_1.Co2PirLiteCommands; } });
|
|
28
28
|
Object.defineProperty(exports, "HTPirLiteCommands", { enumerable: true, get: function () { return encoders_1.HTPirLiteCommands; } });
|
|
29
|
-
Object.defineProperty(exports, "
|
|
29
|
+
Object.defineProperty(exports, "PirMiniCommands", { enumerable: true, get: function () { return encoders_1.PirMiniCommands; } });
|
|
30
30
|
var types_2 = require("./encoders/types");
|
|
31
31
|
Object.defineProperty(exports, "DeviceCommandSchemas", { enumerable: true, get: function () { return types_2.DeviceCommandSchemas; } });
|
|
32
32
|
Object.defineProperty(exports, "VickiEnums", { enumerable: true, get: function () { return types_2.VickiEnums; } });
|
|
@@ -39,7 +39,7 @@ Object.defineProperty(exports, "GeneralCommandsEnums", { enumerable: true, get:
|
|
|
39
39
|
Object.defineProperty(exports, "FloodEnums", { enumerable: true, get: function () { return types_2.FloodEnums; } });
|
|
40
40
|
Object.defineProperty(exports, "Co2PirLiteEnums", { enumerable: true, get: function () { return types_2.Co2PirLiteEnums; } });
|
|
41
41
|
Object.defineProperty(exports, "HTPirLiteEnums", { enumerable: true, get: function () { return types_2.HTPirLiteEnums; } });
|
|
42
|
-
Object.defineProperty(exports, "
|
|
42
|
+
Object.defineProperty(exports, "PirMiniEnums", { enumerable: true, get: function () { return types_2.PirMiniEnums; } });
|
|
43
43
|
var utils_1 = require("./utils");
|
|
44
44
|
Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return utils_1.CustomError; } });
|
|
45
45
|
//# sourceMappingURL=index.js.map
|
|
@@ -856,9 +856,9 @@ describe('HTPirLite payload decoder', () => {
|
|
|
856
856
|
});
|
|
857
857
|
});
|
|
858
858
|
});
|
|
859
|
-
describe('
|
|
859
|
+
describe('PirMini payload decoder', () => {
|
|
860
860
|
test('simple keepalive(doc)', () => {
|
|
861
|
-
expect((0, payloadParsers_1.uplinkPayloadParser)('0102888002F1C80101AF', types_1.DeviceType.
|
|
861
|
+
expect((0, payloadParsers_1.uplinkPayloadParser)('0102888002F1C80101AF', types_1.DeviceType.PirMini)).toStrictEqual({
|
|
862
862
|
sensorTemperature: 24.8,
|
|
863
863
|
relativeHumidity: 50,
|
|
864
864
|
light: 753,
|
|
@@ -868,7 +868,7 @@ describe('PirOnly payload decoder', () => {
|
|
|
868
868
|
});
|
|
869
869
|
});
|
|
870
870
|
test('simple keepalive', () => {
|
|
871
|
-
expect((0, payloadParsers_1.uplinkPayloadParser)('0102809903E1CC010012', types_1.DeviceType.
|
|
871
|
+
expect((0, payloadParsers_1.uplinkPayloadParser)('0102809903E1CC010012', types_1.DeviceType.PirMini)).toStrictEqual({
|
|
872
872
|
sensorTemperature: 24,
|
|
873
873
|
relativeHumidity: 59.77,
|
|
874
874
|
light: 993,
|
|
@@ -878,7 +878,7 @@ describe('PirOnly payload decoder', () => {
|
|
|
878
878
|
});
|
|
879
879
|
});
|
|
880
880
|
test('keepalive with response of preloaded code', () => {
|
|
881
|
-
expect((0, payloadParsers_1.uplinkPayloadParser)('120A0102809903E1CC010012', types_1.DeviceType.
|
|
881
|
+
expect((0, payloadParsers_1.uplinkPayloadParser)('120A0102809903E1CC010012', types_1.DeviceType.PirMini)).toStrictEqual({
|
|
882
882
|
keepAliveTime: 10,
|
|
883
883
|
sensorTemperature: 24,
|
|
884
884
|
relativeHumidity: 59.77,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import { DeviceType } from '@/decoders/payloadParsers/types'
|
|
|
3
3
|
import { byteArrayParser } from '@/helpers'
|
|
4
4
|
import { CustomError } from '@/utils'
|
|
5
5
|
|
|
6
|
-
interface
|
|
6
|
+
interface PirMiniData {
|
|
7
7
|
sensorTemperature?: number
|
|
8
8
|
relativeHumidity?: number
|
|
9
9
|
light?: number
|
|
@@ -12,12 +12,12 @@ interface PirOnlyData {
|
|
|
12
12
|
pirTriggerCount?: number
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const
|
|
15
|
+
export const pirMiniPayloadParser = (hexData: string) => {
|
|
16
16
|
const deviceData: Record<string, unknown> = {}
|
|
17
17
|
|
|
18
18
|
try {
|
|
19
19
|
const handleKeepAliveData = (bytes: number[]) => {
|
|
20
|
-
const keepaliveData:
|
|
20
|
+
const keepaliveData: PirMiniData = {}
|
|
21
21
|
|
|
22
22
|
// Byte 1 (bits 1:0) and Byte 2: Internal temperature sensor data
|
|
23
23
|
// Formula: t[°C] = (T[9:0] - 400) / 10
|
|
@@ -63,7 +63,7 @@ export const pirOnlyPayloadParser = (hexData: string) => {
|
|
|
63
63
|
handleKeepAliveData(byteArray)
|
|
64
64
|
} else {
|
|
65
65
|
// parse command answers
|
|
66
|
-
const data = commandsReadingHelper(hexData, 20, DeviceType.
|
|
66
|
+
const data = commandsReadingHelper(hexData, 20, DeviceType.PirMini) as Record<string, unknown> | undefined
|
|
67
67
|
if (!data) return
|
|
68
68
|
const shouldKeepAlive = Object.prototype.hasOwnProperty.call(data, 'decodeKeepalive')
|
|
69
69
|
if ('decodeKeepalive' in data) {
|
|
@@ -74,7 +74,7 @@ export const pirOnlyPayloadParser = (hexData: string) => {
|
|
|
74
74
|
|
|
75
75
|
// Handle the remaining keepalive data if present
|
|
76
76
|
if (shouldKeepAlive) {
|
|
77
|
-
// Extract the last 10 bytes which contain keepalive data for PIR
|
|
77
|
+
// Extract the last 10 bytes which contain keepalive data for PIR Mini
|
|
78
78
|
const keepaliveData = hexData.slice(-20) // 10 bytes = 20 hex chars
|
|
79
79
|
const dataToPass = byteArrayParser(keepaliveData)
|
|
80
80
|
if (!dataToPass) return
|
|
@@ -87,7 +87,7 @@ export const pirOnlyPayloadParser = (hexData: string) => {
|
|
|
87
87
|
throw new CustomError({
|
|
88
88
|
message: `Unhandled data`,
|
|
89
89
|
hexData: hexData,
|
|
90
|
-
deviceType: '
|
|
90
|
+
deviceType: 'pir_mini',
|
|
91
91
|
originalError: e as Error,
|
|
92
92
|
})
|
|
93
93
|
}
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
co2PirLitePayloadParser,
|
|
22
22
|
htPirLitePayloadParser,
|
|
23
23
|
multisensorPayloadParser,
|
|
24
|
-
|
|
24
|
+
pirMiniPayloadParser,
|
|
25
25
|
} from '@/decoders/payloadParsers'
|
|
26
26
|
|
|
27
27
|
export const uplinkPayloadParser = (hexData: string, deviceType: DeviceType) => {
|
|
@@ -68,8 +68,8 @@ export const uplinkPayloadParser = (hexData: string, deviceType: DeviceType) =>
|
|
|
68
68
|
return htPirLitePayloadParser(hexData)
|
|
69
69
|
case DeviceType.MultiSensor:
|
|
70
70
|
return multisensorPayloadParser(hexData)
|
|
71
|
-
case DeviceType.
|
|
72
|
-
return
|
|
71
|
+
case DeviceType.PirMini:
|
|
72
|
+
return pirMiniPayloadParser(hexData)
|
|
73
73
|
default:
|
|
74
74
|
// Q: is this OK?
|
|
75
75
|
return vickiPayloadParser(hexData) // Default case if deviceType is not recognized
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
Co2PirLiteCommands,
|
|
22
22
|
MelissaCommands,
|
|
23
23
|
MultiSensorCommands,
|
|
24
|
-
|
|
24
|
+
PirMiniCommands,
|
|
25
25
|
} from '@/encoders'
|
|
26
26
|
|
|
27
27
|
import { CustomError, toCamelCase } from '@/utils'
|
|
@@ -53,7 +53,7 @@ export class CommandBuilder {
|
|
|
53
53
|
co2_pir_lite: Co2PirLiteCommands,
|
|
54
54
|
melissa_lorawan: MelissaCommands,
|
|
55
55
|
multisensor: MultiSensorCommands,
|
|
56
|
-
|
|
56
|
+
pir_mini: PirMiniCommands,
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BaseCommand, CommandBuilder } from '@/encoders'
|
|
2
2
|
import { CustomError } from '@/utils'
|
|
3
3
|
|
|
4
|
-
describe('
|
|
5
|
-
const commandBuilder = new CommandBuilder('
|
|
4
|
+
describe('PirMiniCommands payload encoder', () => {
|
|
5
|
+
const commandBuilder = new CommandBuilder('pir_mini')
|
|
6
6
|
|
|
7
7
|
test('SetLightSensorState encodes enabled flag', () => {
|
|
8
8
|
expect(commandBuilder.build('SetLightSensorState', { state: 1 })).toStrictEqual(
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { GeneralCommands } from '@/encoders'
|
|
2
2
|
import { applyMixins, delMethods } from '@/utils'
|
|
3
|
-
import {
|
|
3
|
+
import { PirMiniCommandTypes, DeviceCommandSchemas } from '@/encoders/types'
|
|
4
4
|
import { BaseCommand } from '@/encoders'
|
|
5
5
|
import { ZodError } from 'zod'
|
|
6
6
|
import { CustomError } from '@/utils'
|
|
7
7
|
import { decToHex } from '@/utils'
|
|
8
8
|
|
|
9
|
-
export class
|
|
10
|
-
static setLightSensorState(params:
|
|
9
|
+
export class PirMiniCommands extends GeneralCommands {
|
|
10
|
+
static setLightSensorState(params: PirMiniCommandTypes.SetLightSensorStateParams) {
|
|
11
11
|
try {
|
|
12
|
-
DeviceCommandSchemas.
|
|
12
|
+
DeviceCommandSchemas.PirMiniCommandSchemas.setLightSensorState.parse(params)
|
|
13
13
|
const { state } = params
|
|
14
14
|
return new BaseCommand('SetLightSensorState', 0x1e, decToHex(state))
|
|
15
15
|
} catch (e) {
|
|
@@ -33,9 +33,9 @@ export class PirOnlyCommands extends GeneralCommands {
|
|
|
33
33
|
return new BaseCommand('GetLightSensorState', 0x1f)
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
static setLedBrightness(params:
|
|
36
|
+
static setLedBrightness(params: PirMiniCommandTypes.SetLedBrightnessParams) {
|
|
37
37
|
try {
|
|
38
|
-
DeviceCommandSchemas.
|
|
38
|
+
DeviceCommandSchemas.PirMiniCommandSchemas.setLedBrightness.parse(params)
|
|
39
39
|
const { red, green, blue } = params
|
|
40
40
|
return new BaseCommand('SetLedBrightness', 0x21, decToHex(red), decToHex(green), decToHex(blue))
|
|
41
41
|
} catch (e) {
|
|
@@ -59,9 +59,9 @@ export class PirOnlyCommands extends GeneralCommands {
|
|
|
59
59
|
return new BaseCommand('GetLedBrightness', 0x22)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
static setPIRSensorState(params:
|
|
62
|
+
static setPIRSensorState(params: PirMiniCommandTypes.SetPIRSensorStateParams) {
|
|
63
63
|
try {
|
|
64
|
-
DeviceCommandSchemas.
|
|
64
|
+
DeviceCommandSchemas.PirMiniCommandSchemas.setPIRSensorState.parse(params)
|
|
65
65
|
const { state } = params
|
|
66
66
|
return new BaseCommand('SetPIRSensorState', 0x36, decToHex(state))
|
|
67
67
|
} catch (e) {
|
|
@@ -85,9 +85,9 @@ export class PirOnlyCommands extends GeneralCommands {
|
|
|
85
85
|
return new BaseCommand('GetPIRSensorState', 0x37)
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
static setOccupancyTimeout(params:
|
|
88
|
+
static setOccupancyTimeout(params: PirMiniCommandTypes.SetOccupancyTimeoutParams) {
|
|
89
89
|
try {
|
|
90
|
-
DeviceCommandSchemas.
|
|
90
|
+
DeviceCommandSchemas.PirMiniCommandSchemas.setOccupancyTimeout.parse(params)
|
|
91
91
|
const { timeout } = params
|
|
92
92
|
// Convert timeout to two bytes (high byte and low byte)
|
|
93
93
|
const highByte = (timeout >> 8) & 0xff
|
|
@@ -115,9 +115,9 @@ export class PirOnlyCommands extends GeneralCommands {
|
|
|
115
115
|
return new BaseCommand('GetOccupancyTimeout', 0x39)
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
static setPIRDemoMode(params:
|
|
118
|
+
static setPIRDemoMode(params: PirMiniCommandTypes.SetPIRDemoModeParams) {
|
|
119
119
|
try {
|
|
120
|
-
DeviceCommandSchemas.
|
|
120
|
+
DeviceCommandSchemas.PirMiniCommandSchemas.setPIRDemoMode.parse(params)
|
|
121
121
|
const { state } = params
|
|
122
122
|
return new BaseCommand('SetPIRDemoMode', 0x3a, decToHex(state))
|
|
123
123
|
} catch (e) {
|
|
@@ -146,6 +146,6 @@ export class PirOnlyCommands extends GeneralCommands {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
applyMixins(
|
|
149
|
+
applyMixins(PirMiniCommands, [GeneralCommands])
|
|
150
150
|
|
|
151
|
-
delMethods(
|
|
151
|
+
delMethods(PirMiniCommands, [])
|
package/src/encoders/index.ts
CHANGED
|
@@ -212,7 +212,7 @@ export const Co2PirLiteEnums = {
|
|
|
212
212
|
} satisfies NumberEnum<0 | 1>,
|
|
213
213
|
} as const
|
|
214
214
|
|
|
215
|
-
export const
|
|
215
|
+
export const PirMiniEnums = {
|
|
216
216
|
setPIRSensorState: {
|
|
217
217
|
0: 'Disabled',
|
|
218
218
|
1: 'Enabled',
|
|
@@ -2114,8 +2114,8 @@ export namespace MultiSensorCommandTypes {
|
|
|
2114
2114
|
export type SetPirActiveReportingPeriodParams = z.infer<typeof MultiSensorCommandSchemas.setPirActiveReportingPeriod>
|
|
2115
2115
|
}
|
|
2116
2116
|
|
|
2117
|
-
/* --------------------------------------- PIR
|
|
2118
|
-
const
|
|
2117
|
+
/* --------------------------------------- PIR MINI COMMANDS --------------------------------------- */
|
|
2118
|
+
const PirMiniCommandSchemas = {
|
|
2119
2119
|
...GeneralCommandSchemas,
|
|
2120
2120
|
setLightSensorState: z.object({
|
|
2121
2121
|
state: z.number().min(0).max(1), // 0: disabled, 1: enabled
|
|
@@ -2159,18 +2159,18 @@ const PirOnlyCommandSchemas = {
|
|
|
2159
2159
|
}),
|
|
2160
2160
|
}
|
|
2161
2161
|
|
|
2162
|
-
export namespace
|
|
2163
|
-
export type SetLightSensorStateParams = z.infer<typeof
|
|
2164
|
-
export type GetLightSensorStateParams = z.infer<typeof
|
|
2165
|
-
export type SetLedBrightnessParams = z.infer<typeof
|
|
2166
|
-
export type GetLedBrightnessParams = z.infer<typeof
|
|
2167
|
-
export type SetPIRSensorStateParams = z.infer<typeof
|
|
2168
|
-
export type GetPIRSensorStateParams = z.infer<typeof
|
|
2169
|
-
export type SetOccupancyTimeoutParams = z.infer<typeof
|
|
2170
|
-
export type GetOccupancyTimeoutParams = z.infer<typeof
|
|
2171
|
-
export type SetPIRDemoModeParams = z.infer<typeof
|
|
2172
|
-
export type GetPIRDemoModeParams = z.infer<typeof
|
|
2173
|
-
export type RestartDeviceParams = z.infer<typeof
|
|
2162
|
+
export namespace PirMiniCommandTypes {
|
|
2163
|
+
export type SetLightSensorStateParams = z.infer<typeof PirMiniCommandSchemas.setLightSensorState>
|
|
2164
|
+
export type GetLightSensorStateParams = z.infer<typeof PirMiniCommandSchemas.getLightSensorState>
|
|
2165
|
+
export type SetLedBrightnessParams = z.infer<typeof PirMiniCommandSchemas.setLedBrightness>
|
|
2166
|
+
export type GetLedBrightnessParams = z.infer<typeof PirMiniCommandSchemas.getLedBrightness>
|
|
2167
|
+
export type SetPIRSensorStateParams = z.infer<typeof PirMiniCommandSchemas.setPIRSensorState>
|
|
2168
|
+
export type GetPIRSensorStateParams = z.infer<typeof PirMiniCommandSchemas.getPIRSensorState>
|
|
2169
|
+
export type SetOccupancyTimeoutParams = z.infer<typeof PirMiniCommandSchemas.setOccupancyTimeout>
|
|
2170
|
+
export type GetOccupancyTimeoutParams = z.infer<typeof PirMiniCommandSchemas.getOccupancyTimeout>
|
|
2171
|
+
export type SetPIRDemoModeParams = z.infer<typeof PirMiniCommandSchemas.setPIRDemoMode>
|
|
2172
|
+
export type GetPIRDemoModeParams = z.infer<typeof PirMiniCommandSchemas.getPIRDemoMode>
|
|
2173
|
+
export type RestartDeviceParams = z.infer<typeof PirMiniCommandSchemas.restartDevice>
|
|
2174
2174
|
}
|
|
2175
2175
|
|
|
2176
2176
|
/* --------------------------------------- EXPORT ALL SCHEMA GROUPS --------------------------------------- */
|
|
@@ -2200,5 +2200,5 @@ export const DeviceCommandSchemas = {
|
|
|
2200
2200
|
Co2PirLiteCommandSchemas,
|
|
2201
2201
|
MelissaCommandSchemas,
|
|
2202
2202
|
MultiSensorCommandSchemas,
|
|
2203
|
-
|
|
2203
|
+
PirMiniCommandSchemas,
|
|
2204
2204
|
}
|
package/src/index.ts
CHANGED
|
@@ -21,7 +21,7 @@ export {
|
|
|
21
21
|
Relay16DryCommands,
|
|
22
22
|
Co2PirLiteCommands,
|
|
23
23
|
HTPirLiteCommands,
|
|
24
|
-
|
|
24
|
+
PirMiniCommands,
|
|
25
25
|
} from '@/encoders'
|
|
26
26
|
export {
|
|
27
27
|
DeviceCommandSchemas,
|
|
@@ -35,6 +35,6 @@ export {
|
|
|
35
35
|
FloodEnums,
|
|
36
36
|
Co2PirLiteEnums,
|
|
37
37
|
HTPirLiteEnums,
|
|
38
|
-
|
|
38
|
+
PirMiniEnums,
|
|
39
39
|
} from '@/encoders/types'
|
|
40
40
|
export { CustomError } from '@/utils'
|
|
@@ -922,9 +922,9 @@ describe('HTPirLite payload decoder', () => {
|
|
|
922
922
|
})
|
|
923
923
|
})
|
|
924
924
|
})
|
|
925
|
-
describe('
|
|
925
|
+
describe('PirMini payload decoder', () => {
|
|
926
926
|
test('simple keepalive(doc)', () => {
|
|
927
|
-
expect(uplinkPayloadParser('0102888002F1C80101AF', DeviceType.
|
|
927
|
+
expect(uplinkPayloadParser('0102888002F1C80101AF', DeviceType.PirMini)).toStrictEqual({
|
|
928
928
|
sensorTemperature: 24.8,
|
|
929
929
|
relativeHumidity: 50,
|
|
930
930
|
light: 753,
|
|
@@ -934,7 +934,7 @@ describe('PirOnly payload decoder', () => {
|
|
|
934
934
|
})
|
|
935
935
|
})
|
|
936
936
|
test('simple keepalive', () => {
|
|
937
|
-
expect(uplinkPayloadParser('0102809903E1CC010012', DeviceType.
|
|
937
|
+
expect(uplinkPayloadParser('0102809903E1CC010012', DeviceType.PirMini)).toStrictEqual({
|
|
938
938
|
sensorTemperature: 24,
|
|
939
939
|
relativeHumidity: 59.77,
|
|
940
940
|
light: 993,
|
|
@@ -944,7 +944,7 @@ describe('PirOnly payload decoder', () => {
|
|
|
944
944
|
})
|
|
945
945
|
})
|
|
946
946
|
test('keepalive with response of preloaded code', () => {
|
|
947
|
-
expect(uplinkPayloadParser('120A0102809903E1CC010012', DeviceType.
|
|
947
|
+
expect(uplinkPayloadParser('120A0102809903E1CC010012', DeviceType.PirMini)).toStrictEqual({
|
|
948
948
|
keepAliveTime: 10,
|
|
949
949
|
sensorTemperature: 24,
|
|
950
950
|
relativeHumidity: 59.77,
|