Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix light bugs #180

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion drivers/light/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default class TuyaOAuth2DeviceLight extends TuyaOAuth2Device {
light_saturation = this.getCapabilityValue('light_saturation'),
light_temperature = this.getCapabilityValue('light_temperature'),
}): Promise<void> {
const commands = [];
const commands: TuyaCommand[] = [];

// Light mode is not available when a light only has temperature or color
if (!this.hasCapability('light_mode')) {
Expand All @@ -351,6 +351,13 @@ export default class TuyaOAuth2DeviceLight extends TuyaOAuth2Device {
}
}

if (this.hasTuyaCapability('work_mode')) {
commands.push({
code: 'work_mode',
value: light_mode === 'color' ? 'colour' : 'white',
});
}

if (light_mode === 'color') {
if (this.hasTuyaCapability('colour_data')) {
commands.push({
Expand Down
22 changes: 16 additions & 6 deletions drivers/light/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,27 @@ module.exports = class TuyaOAuth2DriverLight extends TuyaOAuth2Driver {
const values = JSON.parse(functionSpecification.values);

if (tuyaCapability === 'bright_value') {
props.store.tuya_brightness = values;
props.store.tuya_brightness = { ...props.store.tuya_brightness, ...values };
} else if (tuyaCapability === 'bright_value_v2') {
props.store.tuya_brightness_v2 = values;
props.store.tuya_brightness_v2 = { ...props.store.tuya_brightness_v2, ...values };
} else if (tuyaCapability === 'temp_value') {
props.store.tuya_temperature = values;
props.store.tuya_temperature = { ...props.store.tuya_temperature, ...values };
} else if (tuyaCapability === 'temp_value_v2') {
props.store.tuya_temperature_v2 = values;
props.store.tuya_temperature_v2 = { ...props.store.tuya_temperature_v2, ...values };
} else if (tuyaCapability === 'colour_data') {
props.store.tuya_colour = values;
for (const index of ['h', 's', 'v']) {
props.store.tuya_colour[index] = {
...props.store.tuya_colour[index],
...values?.[index],
};
}
} else if (tuyaCapability === 'colour_data_v2') {
props.store.tuya_colour_v2 = values;
for (const index of ['h', 's', 'v']) {
props.store.tuya_colour_v2[index] = {
...props.store.tuya_colour_v2[index],
...values?.[index],
};
}
}
}

Expand Down
Loading