6262import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2GetConfigResult ;
6363import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfigAp ;
6464import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfigAp .Shelly2DeviceConfigApRE ;
65+ import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceStatus .Shelly2CCTStatus ;
6566import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceStatus .Shelly2DeviceStatusLight ;
6667import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceStatus .Shelly2DeviceStatusResult ;
6768import 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