Skip to content

Commit

Permalink
Merge pull request #180 from Drenso/fix-missing-light-specs
Browse files Browse the repository at this point in the history
Fix light bugs
  • Loading branch information
bobvandevijver authored Aug 22, 2024
2 parents 1615dc6 + 97d08bb commit 99ef081
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
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

0 comments on commit 99ef081

Please sign in to comment.