Skip to content
Draft
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/lib/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3301,12 +3301,12 @@
await endpoint.write<"genOnOff", TuyaGenOnOff>("genOnOff", {tuyaOperationMode: utils.getFromLookup(value, {command: 0, event: 1})});
return {state: {operation_mode: value.toLowerCase()}};
},
convertGet: async (entity, key, meta) => {

Check failure on line 3304 in src/lib/tuya.ts

View workflow job for this annotation

GitHub Actions / ci

Block-scoped variable 'stateKey' used before its declaration.
const endpoint = meta.device.getEndpoint(1);
await endpoint.read<"genOnOff", TuyaGenOnOff>("genOnOff", ["tuyaOperationMode"]);
},
} satisfies Tz.Converter,
// biome-ignore lint/style/useNamingConvention: ignored using `--suppress`

Check failure on line 3309 in src/lib/tuya.ts

View workflow job for this annotation

GitHub Actions / ci

Property 'ID' does not exist on type 'Endpoint | Group'.
TS110E_onoff_brightness: {
key: ["state", "brightness"],
convertSet: async (entity, key, value, meta) => {
Expand All @@ -3315,19 +3315,25 @@
return await tz.on_off.convertSet(entity, key, value, meta);
}
if (message.brightness != null) {
// set brightness
if (state.state === "OFF") {
// turn on
Comment thread
phyzical marked this conversation as resolved.
if (state[stateKey] === "OFF") {
await entity.command("genOnOff", "on", {}, utils.getOptions(meta.mapped, entity));
}


// If state includes state_l1 assume we need to use a custom lookup
Comment thread
phyzical marked this conversation as resolved.
const stateKey = Object.keys(state).find((k) => k.startsWith("state_l1")) ? `state_l${entity.ID}` : "state";
Comment thread
phyzical marked this conversation as resolved.
Outdated
const brightness = utils.toNumber(message.brightness, "brightness");

const level = utils.mapNumberRange(brightness, 0, 254, 0, 1000);

// set brightness
await entity.command<"genLevelCtrl", "moveToLevelTuya", TuyaGenLevelCtrl>(
"genLevelCtrl",
"moveToLevelTuya",
{level, transtime: 100},
utils.getOptions(meta.mapped, entity),
);

return {state: {state: "ON", brightness}};
}
},
Expand Down
Loading