Skip to content

Commit 23d5ee6

Browse files
candeodevelopmentautofix-ci[bot]Koenkk
authored
feat: Cando C203: improve support (#8907)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Koen Kanters <[email protected]>
1 parent 089aee1 commit 23d5ee6

File tree

1 file changed

+79
-3
lines changed

1 file changed

+79
-3
lines changed

src/devices/candeo.ts

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
import * as m from "../lib/modernExtend";
2-
import type {DefinitionWithExtend} from "../lib/types";
2+
import type {DefinitionWithExtend, Fz, Tz} from "../lib/types";
3+
4+
import * as fz from "../converters/fromZigbee";
5+
import * as tz from "../converters/toZigbee";
6+
import * as exposes from "../lib/exposes";
7+
import * as reporting from "../lib/reporting";
8+
9+
const e = exposes.presets;
10+
const ea = exposes.access;
11+
12+
const manufacturerSpecificClusterCode = 0x1224;
13+
const switchTypeAttribute = 0x8803;
14+
const dataType = 0x20;
15+
const valueMap: {[key: number]: string} = {
16+
0: "momentary",
17+
1: "toggle",
18+
};
19+
const valueLookup: {[key: string]: number} = {
20+
momentary: 0,
21+
toggle: 1,
22+
};
23+
24+
const fzLocal = {
25+
switch_type: {
26+
cluster: "genBasic",
27+
type: ["attributeReport", "readResponse"],
28+
convert: (model, msg, publish, options, meta) => {
29+
if (Object.prototype.hasOwnProperty.call(msg.data, switchTypeAttribute)) {
30+
const value = msg.data[switchTypeAttribute];
31+
return {
32+
external_switch_type: valueMap[value] || "unknown",
33+
external_switch_type_numeric: value,
34+
};
35+
}
36+
return undefined;
37+
},
38+
} satisfies Fz.Converter,
39+
};
40+
41+
const tzLocal = {
42+
switch_type: {
43+
key: ["external_switch_type"],
44+
convertSet: async (entity, key, value: string, meta) => {
45+
const numericValue = valueLookup[value] ?? Number.parseInt(value, 10);
46+
await entity.write(
47+
"genBasic",
48+
{[switchTypeAttribute]: {value: numericValue, type: dataType}},
49+
{manufacturerCode: manufacturerSpecificClusterCode},
50+
);
51+
return {state: {external_switch_type: value}};
52+
},
53+
convertGet: async (entity, key, meta) => {
54+
await entity.read("genBasic", [switchTypeAttribute], {manufacturerCode: manufacturerSpecificClusterCode});
55+
},
56+
} satisfies Tz.Converter,
57+
};
358

459
export const definitions: DefinitionWithExtend[] = [
560
{
@@ -180,10 +235,31 @@ export const definitions: DefinitionWithExtend[] = [
180235
extend: [m.onOff({powerOnBehavior: true})],
181236
},
182237
{
183-
fingerprint: [{modelID: "C203", manufacturerName: "Candeo"}],
238+
fingerprint: [
239+
{modelID: "C203", manufacturerName: "Candeo"},
240+
{modelID: "HK-LN-DIM-A", manufacturerName: "Candeo"},
241+
],
184242
model: "C203",
185243
vendor: "Candeo",
186244
description: "Zigbee micro smart dimmer",
187-
extend: [m.light({configureReporting: true})],
245+
extend: [
246+
m.light({configureReporting: true, levelConfig: {disabledFeatures: ["on_transition_time", "off_transition_time", "execute_if_off"]}}),
247+
],
248+
fromZigbee: [fzLocal.switch_type, fz.ignore_genOta],
249+
toZigbee: [tzLocal.switch_type],
250+
exposes: [e.enum("external_switch_type", ea.ALL, ["momentary", "toggle"]).withLabel("External switch type")],
251+
configure: async (device, coordinatorEndpoint, logger) => {
252+
const endpoint1 = device.getEndpoint(1);
253+
await endpoint1.write("genOnOff", {16387: {value: 0xff, type: 0x30}});
254+
await endpoint1.read("genOnOff", ["startUpOnOff"]);
255+
await endpoint1.read("genLevelCtrl", ["currentLevel"]);
256+
await endpoint1.write("genLevelCtrl", {17: {value: 0xff, type: 0x20}});
257+
await endpoint1.read("genLevelCtrl", ["onLevel"]);
258+
await endpoint1.write("genLevelCtrl", {16: {value: 0x0a, type: 0x21}});
259+
await endpoint1.read("genLevelCtrl", ["onOffTransitionTime"]);
260+
await endpoint1.write("genLevelCtrl", {16384: {value: 0xff, type: 0x20}});
261+
await endpoint1.read("genLevelCtrl", ["startUpCurrentLevel"]);
262+
await endpoint1.read("genBasic", [switchTypeAttribute], {manufacturerCode: manufacturerSpecificClusterCode});
263+
},
188264
},
189265
];

0 commit comments

Comments
 (0)