Skip to content

Commit f819833

Browse files
svhelgeSvhelgeCopilot
authored
fix: Move Heiman‑specific converters to local and leverage cluster definitions (#12076)
Co-authored-by: Svhelge <svein.helge@hoydal.net> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 8929d72 commit f819833

3 files changed

Lines changed: 481 additions & 586 deletions

File tree

src/converters/fromZigbee.ts

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import assert from "node:assert";
22
import * as libColor from "../lib/color";
33
import * as constants from "../lib/constants";
44
import * as exposes from "../lib/exposes";
5-
import type {HeimanSpecificAirQualityCluster, HeimanSpecificInfraRedRemoteCluster, HeimanSpecificScenesCluster} from "../lib/heiman";
65
import {logger} from "../lib/logger";
76
import * as globalStore from "../lib/store";
87
import type {Fz, KeyValue, KeyValueAny, KeyValueNumberString} from "../lib/types";
@@ -2651,68 +2650,6 @@ export const plaid_battery: Fz.Converter<"genPowerCfg", undefined, ["readRespons
26512650
return payload;
26522651
},
26532652
};
2654-
export const heiman_ir_remote: Fz.Converter<
2655-
"heimanSpecificInfraRedRemote",
2656-
HeimanSpecificInfraRedRemoteCluster,
2657-
["commandStudyKeyRsp", "commandCreateIdRsp", "commandGetIdAndKeyCodeListRsp"]
2658-
> = {
2659-
cluster: "heimanSpecificInfraRedRemote",
2660-
type: ["commandStudyKeyRsp", "commandCreateIdRsp", "commandGetIdAndKeyCodeListRsp"],
2661-
convert: (model, msg, publish, options, meta) => {
2662-
// TODO: split converter for each cmd?
2663-
switch (msg.type) {
2664-
case "commandStudyKeyRsp":
2665-
assert("keyCode" in msg.data);
2666-
return {
2667-
action: "learn",
2668-
action_result: msg.data.result === 1 ? "success" : "error",
2669-
action_key_code: msg.data.keyCode,
2670-
action_id: msg.data.result === 1 ? msg.data.id : undefined,
2671-
};
2672-
case "commandCreateIdRsp":
2673-
assert("id" in msg.data);
2674-
assert("modelType" in msg.data);
2675-
return {
2676-
action: "create",
2677-
action_result: msg.data.id === 0xff ? "error" : "success",
2678-
action_model_type: msg.data.modelType,
2679-
action_id: msg.data.id !== 0xff ? msg.data.id : undefined,
2680-
};
2681-
case "commandGetIdAndKeyCodeListRsp": {
2682-
assert("packetNumber" in msg.data);
2683-
// See cluster.js with data format description
2684-
if (msg.data.packetNumber === 1) {
2685-
// start to collect and merge list
2686-
// so, we use store instance for temp storage during merging
2687-
globalStore.putValue(msg.endpoint, "db", []);
2688-
}
2689-
const buffer = msg.data.learnedDevicesList;
2690-
for (let i = 0; i < msg.data.packetLength; ) {
2691-
const modelDescription: KeyValueAny = {
2692-
id: buffer[i],
2693-
model_type: buffer[i + 1],
2694-
key_codes: [],
2695-
};
2696-
const numberOfKeys = buffer[i + 2];
2697-
for (let j = i + 3; j < i + 3 + numberOfKeys; j++) {
2698-
modelDescription.key_codes.push(buffer[j]);
2699-
}
2700-
i = i + 3 + numberOfKeys;
2701-
globalStore.getValue(msg.endpoint, "db").push(modelDescription);
2702-
}
2703-
if (msg.data.packetNumber === msg.data.packetsTotal) {
2704-
// last packet, all data collected, can publish
2705-
const result: KeyValueAny = {
2706-
devices: globalStore.getValue(msg.endpoint, "db"),
2707-
};
2708-
globalStore.clearValue(msg.endpoint, "db");
2709-
return result;
2710-
}
2711-
break;
2712-
}
2713-
}
2714-
},
2715-
};
27162653
export const meazon_meter: Fz.Converter<"seMetering", undefined, ["attributeReport", "readResponse"]> = {
27172654
cluster: "seMetering",
27182655
type: ["attributeReport", "readResponse"],
@@ -3311,34 +3248,6 @@ export const U02I007C01_water_leak: Fz.Converter<"ssIasZone", undefined, "comman
33113248
};
33123249
},
33133250
};
3314-
export const heiman_hcho: Fz.Converter<"msFormaldehyde", undefined, ["attributeReport", "readResponse"]> = {
3315-
cluster: "msFormaldehyde",
3316-
type: ["attributeReport", "readResponse"],
3317-
convert: (model, msg, publish, options, meta) => {
3318-
if (msg.data.measuredValue) {
3319-
return {hcho: msg.data.measuredValue / 1000.0};
3320-
}
3321-
},
3322-
};
3323-
export const heiman_air_quality: Fz.Converter<"heimanSpecificAirQuality", HeimanSpecificAirQualityCluster, ["attributeReport", "readResponse"]> = {
3324-
cluster: "heimanSpecificAirQuality",
3325-
type: ["attributeReport", "readResponse"],
3326-
convert: (model, msg, publish, options, meta) => {
3327-
const result: KeyValueAny = {};
3328-
if (msg.data.batteryState) {
3329-
const lookup: KeyValueAny = {
3330-
0: "not_charging",
3331-
1: "charging",
3332-
2: "charged",
3333-
};
3334-
result.battery_state = lookup[msg.data.batteryState];
3335-
}
3336-
if (msg.data.tvocMeasuredValue) result.voc = msg.data.tvocMeasuredValue;
3337-
if (msg.data.aqiMeasuredValue) result.aqi = msg.data.aqiMeasuredValue;
3338-
if (msg.data.pm10measuredValue) result.pm10 = msg.data.pm10measuredValue;
3339-
return result;
3340-
},
3341-
};
33423251
export const scenes_recall_scene_65024: Fz.Converter<65024, undefined, ["raw"]> = {
33433252
cluster: 65024,
33443253
type: ["raw"],
@@ -3508,24 +3417,6 @@ export const STS_PRS_251_presence: Fz.Converter<"genBinaryInput", undefined, ["a
35083417
return {presence: true};
35093418
},
35103419
};
3511-
export const heiman_scenes: Fz.Converter<
3512-
"heimanSpecificScenes",
3513-
HeimanSpecificScenesCluster,
3514-
["commandAtHome", "commandGoOut", "commandCinema", "commandRepast", "commandSleep"]
3515-
> = {
3516-
cluster: "heimanSpecificScenes",
3517-
type: ["commandAtHome", "commandGoOut", "commandCinema", "commandRepast", "commandSleep"],
3518-
convert: (model, msg, publish, options, meta) => {
3519-
const lookup: KeyValueAny = {
3520-
commandCinema: "cinema",
3521-
commandAtHome: "at_home",
3522-
commandSleep: "sleep",
3523-
commandGoOut: "go_out",
3524-
commandRepast: "repast",
3525-
};
3526-
if (lookup[msg.type] !== undefined) return {action: lookup[msg.type]};
3527-
},
3528-
};
35293420
export const javis_lock_report: Fz.Converter<"genBasic", undefined, "attributeReport"> = {
35303421
cluster: "genBasic",
35313422
type: "attributeReport",
@@ -4023,23 +3914,6 @@ export const rc_110_level_to_scene: Fz.Converter<"genLevelCtrl", undefined, ["co
40233914
return {action: `scene_${scenes[msg.data.level]}`};
40243915
},
40253916
};
4026-
export const heiman_doorbell_button: Fz.Converter<"ssIasZone", undefined, "commandStatusChangeNotification"> = {
4027-
cluster: "ssIasZone",
4028-
type: "commandStatusChangeNotification",
4029-
convert: (model, msg, publish, options, meta) => {
4030-
if (hasAlreadyProcessedMessage(msg, model)) return;
4031-
const lookup: KeyValueAny = {
4032-
32768: "pressed",
4033-
32772: "pressed",
4034-
};
4035-
const zoneStatus = msg.data.zonestatus;
4036-
return {
4037-
action: lookup[zoneStatus],
4038-
tamper: (zoneStatus & (1 << 2)) > 0,
4039-
battery_low: (zoneStatus & (1 << 3)) > 0,
4040-
};
4041-
},
4042-
};
40433917
export const sihas_people_cnt: Fz.Converter<"genAnalogInput", undefined, ["attributeReport", "readResponse"]> = {
40443918
cluster: "genAnalogInput",
40453919
type: ["attributeReport", "readResponse"],

src/converters/toZigbee.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {TClusterCommandPayload} from "zigbee-herdsman/dist/zspec/zcl/defini
33
import * as libColor from "../lib/color";
44
import * as constants from "../lib/constants";
55
import * as exposes from "../lib/exposes";
6-
import type {HeimanSpecificInfraRedRemoteCluster} from "../lib/heiman";
76
import * as legacy from "../lib/legacy";
87
import * as light from "../lib/light";
98
import {logger} from "../lib/logger";
@@ -3359,66 +3358,6 @@ export const power_source: Tz.Converter = {
33593358
await entity.read("genBasic", ["powerSource"]);
33603359
},
33613360
};
3362-
export const heiman_ir_remote: Tz.Converter = {
3363-
key: ["send_key", "create", "learn", "delete", "get_list"],
3364-
convertSet: async (entity, key, value, meta) => {
3365-
const options = {
3366-
// Don't send a manufacturerCode (otherwise set in herdsman):
3367-
// https://github.com/Koenkk/zigbee-herdsman-converters/pull/2827
3368-
// @ts-expect-error ignore
3369-
manufacturerCode: null,
3370-
...utils.getOptions(meta.mapped, entity),
3371-
};
3372-
switch (key) {
3373-
case "send_key":
3374-
utils.assertObject(value);
3375-
await entity.command<"heimanSpecificInfraRedRemote", "sendKey", HeimanSpecificInfraRedRemoteCluster>(
3376-
"heimanSpecificInfraRedRemote",
3377-
"sendKey",
3378-
{id: value.id, keyCode: value.key_code},
3379-
options,
3380-
);
3381-
break;
3382-
case "create":
3383-
utils.assertObject(value);
3384-
await entity.command<"heimanSpecificInfraRedRemote", "createId", HeimanSpecificInfraRedRemoteCluster>(
3385-
"heimanSpecificInfraRedRemote",
3386-
"createId",
3387-
{modelType: value.model_type},
3388-
options,
3389-
);
3390-
break;
3391-
case "learn":
3392-
utils.assertObject(value);
3393-
await entity.command<"heimanSpecificInfraRedRemote", "studyKey", HeimanSpecificInfraRedRemoteCluster>(
3394-
"heimanSpecificInfraRedRemote",
3395-
"studyKey",
3396-
{id: value.id, keyCode: value.key_code},
3397-
options,
3398-
);
3399-
break;
3400-
case "delete":
3401-
utils.assertObject(value);
3402-
await entity.command<"heimanSpecificInfraRedRemote", "deleteKey", HeimanSpecificInfraRedRemoteCluster>(
3403-
"heimanSpecificInfraRedRemote",
3404-
"deleteKey",
3405-
{id: value.id, keyCode: value.key_code},
3406-
options,
3407-
);
3408-
break;
3409-
case "get_list":
3410-
await entity.command<"heimanSpecificInfraRedRemote", "getIdAndKeyCodeList", HeimanSpecificInfraRedRemoteCluster>(
3411-
"heimanSpecificInfraRedRemote",
3412-
"getIdAndKeyCodeList",
3413-
{},
3414-
options,
3415-
);
3416-
break;
3417-
default: // Unknown key
3418-
throw new Error(`Unhandled key ${key}`);
3419-
}
3420-
},
3421-
};
34223361
export const scene_store: Tz.Converter = {
34233362
key: ["scene_store"],
34243363
convertSet: async (entity, key, value: KeyValueAny, meta) => {

0 commit comments

Comments
 (0)