Skip to content
Draft
Changes from all 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
10 changes: 8 additions & 2 deletions src/lib/tuya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3301,7 +3301,7 @@
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

Property 'ID' does not exist on type 'Endpoint | Group'.
const endpoint = meta.device.getEndpoint(1);
await endpoint.read<"genOnOff", TuyaGenOnOff>("genOnOff", ["tuyaOperationMode"]);
},
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") {
// If state includes state_l1 assume we need to use a custom lookup
const stateKey = Object.keys(state).find((k) => k.startsWith("state_l1")) ? `state_l${entity.ID}` : "state";
// turn on
Comment thread
phyzical marked this conversation as resolved.
if (state[stateKey] === "OFF") {
await entity.command("genOnOff", "on", {}, utils.getOptions(meta.mapped, entity));
}

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