Skip to content

Commit acf608f

Browse files
committed
Fixed an issue where the setMode command for Air Purifier VOC,Table VOC,PM2.5,Table PM2.5 was not functioning properly.
1 parent 83eabed commit acf608f

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

_build_on_haos/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "SwitchBot-Mqtt"
22
description: "Integrate SwitchBot Devices into Home Assistant via MQTT"
3-
version: "1.0.33"
3+
version: "1.0.34"
44
slug: "switchbot_mqtt"
55
url: "https://github.com/hsakoh/switchbot-mqtt"
66
ports:

_compile_self/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: "SwitchBot-Mqtt"
22
description: "Integrate SwitchBot Devices into Home Assistant via MQTT"
3-
version: "1.0.33"
3+
version: "1.0.34"
44
slug: "switchbot_mqtt"
55
url: "https://github.com/hsakoh/switchbot-mqtt"
66
ports:

src/SwitchBotMqttApp/Components/Pages/Modal/CommandTestModal.razor

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@using SwitchBotMqttApp.Logics;
1+
@using SwitchBotMqttApp.Logics;
22
@using SwitchBotMqttApp.Models.DeviceConfiguration;
33
@using SwitchBotMqttApp.Models.DeviceDefinitions;
44
@using SwitchBotMqttApp.Models.Enums;
@@ -84,13 +84,13 @@
8484
<div class="col-2">@param.def.ParameterType</div>
8585
<div class="col-2">
8686
@if (param.def.ParameterType == ParameterType.Range
87-
|| param.def.ParameterType == ParameterType.SelectOrRange)
87+
|| param.def.ParameterType == ParameterType.SelectOrRange)
8888
{
8989

9090
<div>@param.def.RangeMin - @param.def.RangeMax</div>
9191
}
9292
@if (param.def.ParameterType == ParameterType.Select
93-
|| param.def.ParameterType == ParameterType.SelectOrRange)
93+
|| param.def.ParameterType == ParameterType.SelectOrRange)
9494
{
9595
for (int i = 0; i < param.def.GetOptions()!.Length; i++)
9696
{
@@ -225,7 +225,19 @@
225225
}
226226
else
227227
{
228-
json[paramDef.Name] = JsonValue.Create<string>(commandParam.value);
228+
if ((Device.DeviceType == DeviceType.AirPurifierPM25
229+
|| Device.DeviceType == DeviceType.AirPurifierTablePM25
230+
|| Device.DeviceType == DeviceType.AirPurifierVOC
231+
|| Device.DeviceType == DeviceType.AirPurifierTableVOC)
232+
&& CommandConf.Command == "setMode"
233+
&& CommandParams[0].def.ParameterType == ParameterType.Select)
234+
{
235+
json[paramDef.Name] = JsonValue.Create<int>(int.Parse((string)commandParam.value));
236+
}
237+
else
238+
{
239+
json[paramDef.Name] = JsonValue.Create<string>(commandParam.value);
240+
}
229241
}
230242
});
231243
Response = await SwitchBotApiClient.SendDeviceControlCommandAsync(Device, CommandConf, jsonRoot, CancellationToken.None);

src/SwitchBotMqttApp/Services/MqttCoreService.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using HomeAssistantAddOn.Mqtt;
1+
using HomeAssistantAddOn.Mqtt;
22
using Microsoft.AspNetCore;
33
using Microsoft.Extensions.Options;
44
using SwitchBotMqttApp.Configurations;
@@ -442,7 +442,19 @@ private async Task ReceiveCommandAsync(string payloadRaw, DeviceBase device)
442442
}
443443
else
444444
{
445-
json[paramDef.Name] = JsonValue.Create<string>((string)payloadDict[paramDef.Name]);
445+
if ((device.DeviceType == DeviceType.AirPurifierPM25
446+
|| device.DeviceType == DeviceType.AirPurifierTablePM25
447+
|| device.DeviceType == DeviceType.AirPurifierVOC
448+
|| device.DeviceType == DeviceType.AirPurifierTableVOC)
449+
&& commandDef.Command == "setMode"
450+
&& paramDef.ParameterType == ParameterType.Select)
451+
{
452+
json[paramDef.Name] = JsonValue.Create<int>(int.Parse((string)payloadDict[paramDef.Name]));
453+
}
454+
else
455+
{
456+
json[paramDef.Name] = JsonValue.Create<string>((string)payloadDict[paramDef.Name]);
457+
}
446458
}
447459
});
448460
await switchBotApiClient.SendDeviceControlCommandAsync(device, commandConf, jsonRoot, CancellationToken.None);

0 commit comments

Comments
 (0)