Skip to content

Commit fda2178

Browse files
committed
Use RGB.GetStatus etc
Signed-off-by: Markus Michels <markus7017@gmail.com>
1 parent 5177697 commit fda2178

3 files changed

Lines changed: 58 additions & 11 deletions

File tree

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceConfig.Shelly2GetConfigResult;
7373
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceConfig.ShellyDeviceConfigCB;
7474
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceSettings;
75+
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2CCTStatus;
7576
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusLight;
7677
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
7778
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2CoverStatus;
@@ -549,7 +550,7 @@ protected boolean fillDeviceStatus(ShellySettingsStatus status, Shelly2DeviceSta
549550
updated |= updateEmStatus(11, status, result.em11, channelUpdate);
550551
updated |= updateRollerStatus(0, status, result.cover0, channelUpdate);
551552
updated |= updateDimmerStatus(0, status, result.light0, channelUpdate);
552-
updated |= updateDuoBulbStatus(0, status, result.light0, channelUpdate);
553+
updated |= updateDuoBulbStatus(0, status, result.cct0, channelUpdate);
553554
updated |= updateRGBWStatus(0, status, result.rgbw0, channelUpdate);
554555
updated |= updateRGBBulbStatus(0, status, result.rgb0, channelUpdate);
555556
if (channelUpdate) {
@@ -1066,7 +1067,7 @@ protected void fillDuoBulbSettings(ShellyDeviceProfile profile, Shelly2GetConfig
10661067
if (!(profile.isDuo && profile.isGen2)) {
10671068
return;
10681069
}
1069-
applyBulbLightSettings(profile, dc.light0);
1070+
applyBulbLightSettings(profile, dc.cct0);
10701071
}
10711072

10721073
protected void fillRGBBulbSettings(ShellyDeviceProfile profile, Shelly2GetConfigResult dc) {
@@ -1124,7 +1125,7 @@ private boolean updateRGBWStatus(int id, ShellySettingsStatus status, @Nullable
11241125
value.white, null, channelUpdate, true);
11251126
}
11261127

1127-
private boolean updateDuoBulbStatus(int id, ShellySettingsStatus status, @Nullable Shelly2DeviceStatusLight value,
1128+
private boolean updateDuoBulbStatus(int id, ShellySettingsStatus status, @Nullable Shelly2CCTStatus value,
11281129
boolean channelUpdate) throws ShellyApiException {
11291130
ShellyDeviceProfile profile = getProfile();
11301131
if (!(profile.isDuo && profile.isGen2) || value == null) {

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiJsonDTO.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class Shelly2ApiJsonDTO {
6262
public static final String SHELLYRPC_METHOD_RGBW_SET = "RGBW.Set";
6363
public static final String SHELLYRPC_METHOD_RGB_STATUS = "RGB.GetStatus";
6464
public static final String SHELLYRPC_METHOD_RGB_SET = "RGB.Set";
65+
public static final String SHELLYRPC_METHOD_CCT_STATUS = "CCT.GetStatus";
66+
public static final String SHELLYRPC_METHOD_CCT_SET = "CCT.Set";
67+
public static final String SHELLYRPC_METHOD_CCT_SETCONFIG = "CCT.SetConfig";
6568
public static final String SHELLYRPC_METHOD_LED_SETCONFIG = "WD_UI.SetConfig";
6669
public static final String SHELLYRPC_METHOD_WIFIGETCONG = "Wifi.GetConfig";
6770
public static final String SHELLYRPC_METHOD_WIFISETCONG = "Wifi.SetConfig";
@@ -534,6 +537,9 @@ public class Shelly2DevConfigMqtt {
534537
@SerializedName("rgb:0")
535538
public @Nullable Shelly2GetConfigLight rgb0;
536539

540+
@SerializedName("cct:0")
541+
public @Nullable Shelly2GetConfigLight cct0;
542+
537543
@SerializedName("smoke:0")
538544
public Shelly2ConfigSmoke smoke0;
539545
}
@@ -619,6 +625,17 @@ public static class Shelly2DeviceStatusLight {
619625
public @Nullable Double timerDuration;
620626
}
621627

628+
// Shelly Duo Bulb G3 and other CCT-only devices — component "cct:0"
629+
public static class Shelly2CCTStatus {
630+
public @Nullable Integer id;
631+
public @Nullable String source;
632+
public @Nullable Boolean output;
633+
public @Nullable Double brightness;
634+
public @Nullable Integer ct;
635+
public @Nullable Shelly2Energy aenergy;
636+
public @Nullable Double apower;
637+
}
638+
622639
public static class Shelly2DeviceStatusResult {
623640
public class Shelly2DeviceStatusBle {
624641

@@ -850,6 +867,9 @@ public static class Shelly2RGBStatus {
850867
@SerializedName("light:0")
851868
public @Nullable Shelly2DeviceStatusLight light0;
852869

870+
@SerializedName("cct:0")
871+
public @Nullable Shelly2CCTStatus cct0;
872+
853873
@SerializedName("temperature:0")
854874
public Shelly2DeviceStatusTempId temperature0;
855875
@SerializedName("temperature:100")

bundles/org.openhab.binding.shelly/src/main/java/org/openhab/binding/shelly/internal/api2/Shelly2ApiRpc.java

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceConfig.Shelly2GetConfigResult;
6363
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceConfigAp;
6464
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceConfigAp.Shelly2DeviceConfigApRE;
65+
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2CCTStatus;
6566
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusLight;
6667
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult;
6768
import org.openhab.binding.shelly.internal.api2.Shelly2ApiJsonDTO.Shelly2DeviceStatus.Shelly2DeviceStatusResult.Shelly2RGBStatus;
@@ -827,9 +828,8 @@ public ShellyStatusLight getLightStatus() throws ShellyApiException {
827828
return status;
828829
}
829830
if (profile.isDuo && profile.isGen2) {
830-
Shelly2DeviceStatusLight ls = apiRequest(
831-
new Shelly2RpcRequest().withMethod(SHELLYRPC_METHOD_LIGHT_STATUS).withId(0),
832-
Shelly2DeviceStatusLight.class);
831+
Shelly2CCTStatus ls = apiRequest(new Shelly2RpcRequest().withMethod(SHELLYRPC_METHOD_CCT_STATUS).withId(0),
832+
Shelly2CCTStatus.class);
833833
ShellyStatusLightChannel lightChannel = new ShellyStatusLightChannel();
834834
lightChannel.ison = ls.output;
835835
Double duoBrightness = ls.brightness;
@@ -851,7 +851,19 @@ public ShellyStatusLight getLightStatus() throws ShellyApiException {
851851

852852
@Override
853853
public ShellyShortLightStatus getLightStatus(int index) throws ShellyApiException {
854+
ShellyDeviceProfile profile = getProfile();
854855
ShellyShortLightStatus status = new ShellyShortLightStatus();
856+
if (profile.isDuo && profile.isGen2) {
857+
Shelly2CCTStatus ls = apiRequest(
858+
new Shelly2RpcRequest().withMethod(SHELLYRPC_METHOD_CCT_STATUS).withId(index),
859+
Shelly2CCTStatus.class);
860+
status.ison = ls.output;
861+
Double brightness = ls.brightness;
862+
if (brightness != null) {
863+
status.brightness = brightness.intValue();
864+
}
865+
return status;
866+
}
855867
Shelly2DeviceStatusLight ls = apiRequest(
856868
new Shelly2RpcRequest().withMethod(SHELLYRPC_METHOD_LIGHT_STATUS).withId(index),
857869
Shelly2DeviceStatusLight.class);
@@ -867,19 +879,23 @@ public ShellyShortLightStatus getLightStatus(int index) throws ShellyApiExceptio
867879

868880
@Override
869881
public void setBrightness(int id, int brightness, boolean autoOn) throws ShellyApiException {
882+
ShellyDeviceProfile profile = getProfile();
870883
Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
871884
params.id = id;
872885
params.brightness = brightness;
873886
params.on = brightness > 0;
874-
apiRequest(SHELLYRPC_METHOD_LIGHT_SET, params, String.class);
887+
String method = (profile.isDuo && profile.isGen2) ? SHELLYRPC_METHOD_CCT_SET : SHELLYRPC_METHOD_LIGHT_SET;
888+
apiRequest(method, params, String.class);
875889
}
876890

877891
@Override
878892
public ShellyShortLightStatus setLightTurn(int id, String turnMode) throws ShellyApiException {
893+
ShellyDeviceProfile profile = getProfile();
879894
Shelly2RpcRequestParams params = new Shelly2RpcRequestParams();
880895
params.id = id;
881896
params.on = turnMode.equals(SHELLY_API_ON);
882-
apiRequest(SHELLYRPC_METHOD_LIGHT_SET, params, String.class);
897+
String method = (profile.isDuo && profile.isGen2) ? SHELLYRPC_METHOD_CCT_SET : SHELLYRPC_METHOD_LIGHT_SET;
898+
apiRequest(method, params, String.class);
883899
return getLightStatus(id);
884900
}
885901

@@ -892,8 +908,18 @@ public ShellyStatusSensor getSensorStatus() throws ShellyApiException {
892908
public void setAutoTimer(int index, String timerName, double value) throws ShellyApiException {
893909
ShellyDeviceProfile profile = getProfile();
894910
boolean isLight = profile.isLight || profile.isDimmer;
895-
String method = isLight ? SHELLYRPC_METHOD_LIGHT_SETCONFIG : SHELLYRPC_METHOD_SWITCH_SETCONFIG;
896-
String component = isLight ? "Light" : "Switch";
911+
String method;
912+
String component;
913+
if (profile.isDuo && profile.isGen2) {
914+
method = SHELLYRPC_METHOD_CCT_SETCONFIG;
915+
component = "CCT";
916+
} else if (isLight) {
917+
method = SHELLYRPC_METHOD_LIGHT_SETCONFIG;
918+
component = "Light";
919+
} else {
920+
method = SHELLYRPC_METHOD_SWITCH_SETCONFIG;
921+
component = "Switch";
922+
}
897923
Shelly2RpcRequest req = new Shelly2RpcRequest().withMethod(method).withId(index);
898924
req.params.withConfig();
899925
req.params.config.name = component + index;
@@ -1088,7 +1114,7 @@ public void setLightParms(int lightIndex, Map<String, String> parameters) throws
10881114
if (ct != null) {
10891115
params.ct = Integer.parseInt(ct);
10901116
}
1091-
apiRequest(SHELLYRPC_METHOD_LIGHT_SET, params, String.class);
1117+
apiRequest(SHELLYRPC_METHOD_CCT_SET, params, String.class);
10921118
} else {
10931119
throw new ShellyApiException("setLightParms not implemented for this device type");
10941120
}

0 commit comments

Comments
 (0)