Skip to content
Draft
Changes from 12 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
17 changes: 11 additions & 6 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,20 +3315,25 @@
return await tz.on_off.convertSet(entity, key, value, meta);
}
if (message.brightness != null) {
// set brightness
if (state.state === "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}};

if (state[stateKey] === "OFF") {
await entity.command("genOnOff", "on", {}, utils.getOptions(meta.mapped, entity));
}

Comment thread
phyzical marked this conversation as resolved.
Outdated
return {state: {[stateKey]: "ON", brightness}};
Comment thread
phyzical marked this conversation as resolved.
Outdated
}
},
convertGet: async (entity, key, meta) => {
Expand Down
Loading