Skip to content

Commit

Permalink
Add dimmer lamp type settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JELoohuis committed Jul 17, 2024
1 parent 517c629 commit 3b8c33f
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 1 deletion.
56 changes: 56 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,34 @@
"step": 0.1,
"units": "%"
},
{
"id": "led_type_1",
"type": "dropdown",
"label": {
"en": "Lamp Type 1"
},
"value": "led",
"values": [
{
"id": "led",
"label": {
"en": "LED"
}
},
{
"id": "incandescent",
"label": {
"en": "Incandescent"
}
},
{
"id": "halogen",
"label": {
"en": "Halogen"
}
}
]
},
{
"id": "brightness_min_2",
"type": "number",
Expand All @@ -701,6 +729,34 @@
"max": 100,
"step": 0.1,
"units": "%"
},
{
"id": "led_type_2",
"type": "dropdown",
"label": {
"en": "Lamp Type 2"
},
"value": "led",
"values": [
{
"id": "led",
"label": {
"en": "LED"
}
},
{
"id": "incandescent",
"label": {
"en": "Incandescent"
}
},
{
"id": "halogen",
"label": {
"en": "Halogen"
}
}
]
}
]
}
Expand Down
10 changes: 9 additions & 1 deletion drivers/dimmer/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ class TuyaOAuth2DeviceDimmer extends TuyaOAuth2Device {
const tuyaBrightnessCapability = `bright_value_${switch_i}`;
const tuyaBrightnessMin = `brightness_min_${switch_i}`;
const tuyaBrightnessMax = `brightness_max_${switch_i}`;
const tuyaLampType = `led_type_${switch_i}`;

const switchStatus = status[tuyaSwitchCapability];
const brightnessStatus = status[tuyaBrightnessCapability];
const brightnessMin = status[tuyaBrightnessMin];
const brightnessMax = status[tuyaBrightnessMax];
const lampType = status[tuyaLampType];

if (typeof switchStatus === "boolean") {
anySwitchOn = anySwitchOn || switchStatus;
Expand Down Expand Up @@ -80,6 +82,12 @@ class TuyaOAuth2DeviceDimmer extends TuyaOAuth2Device {
});
}

if (lampType !== undefined) {
await this.setSettings({
[tuyaLampType]: lampType,
});
}

if (typeof brightnessStatus === "number") {
const scaleMin = this.getSetting(tuyaBrightnessMin) * 10;
const scaleMax = this.getSetting(tuyaBrightnessMax) * 10;
Expand Down Expand Up @@ -119,7 +127,7 @@ class TuyaOAuth2DeviceDimmer extends TuyaOAuth2Device {
const newValue = newSettings[changedKey];
await this.sendCommand({
code: changedKey,
value: newValue * 10,
value: typeof newValue === "number" ? newValue * 10 : newValue, // Convert numeric values from (0,100) to (0,1000)
}).catch((err) => {
if (err.tuyaCode === 2008) {
unsupportedSettings.push(changedKey);
Expand Down
4 changes: 4 additions & 0 deletions drivers/dimmer/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class TuyaOAuth2DriverDimmer extends TuyaOAuth2Driver {
brightness_max_1: "Maximum Brightness 1",
brightness_min_2: "Minimum Brightness 2",
brightness_max_2: "Maximum Brightness 2",
led_type_1: "Lamp Type 1",
led_type_2: "Lamp Type 2",
};

static SIMPLE_DIMMER_CAPABILITIES = {
Expand All @@ -60,6 +62,8 @@ class TuyaOAuth2DriverDimmer extends TuyaOAuth2Driver {
"brightness_max_1",
"brightness_min_2",
"brightness_max_2",
"led_type_1",
"led_type_2",
],
};

Expand Down
56 changes: 56 additions & 0 deletions drivers/dimmer/driver.settings.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@
"step": 0.1,
"units": "%"
},
{
"id": "led_type_1",
"type": "dropdown",
"label": {
"en": "Lamp Type 1"
},
"value": "led",
"values": [
{
"id": "led",
"label": {
"en": "LED"
}
},
{
"id": "incandescent",
"label": {
"en": "Incandescent"
}
},
{
"id": "halogen",
"label": {
"en": "Halogen"
}
}
]
},
{
"id": "brightness_min_2",
"type": "number",
Expand All @@ -52,6 +80,34 @@
"max": 100,
"step": 0.1,
"units": "%"
},
{
"id": "led_type_2",
"type": "dropdown",
"label": {
"en": "Lamp Type 2"
},
"value": "led",
"values": [
{
"id": "led",
"label": {
"en": "LED"
}
},
{
"id": "incandescent",
"label": {
"en": "Incandescent"
}
},
{
"id": "halogen",
"label": {
"en": "Halogen"
}
}
]
}
]
}
Expand Down

0 comments on commit 3b8c33f

Please sign in to comment.