4444import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellySettingsStatus ;
4545import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyShortLightStatus ;
4646import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyShortStatusRelay ;
47+ import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyStatusLight ;
48+ import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyStatusLightChannel ;
4749import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyStatusRelay ;
4850import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyStatusSensor ;
4951import org .openhab .binding .shelly .internal .api1 .Shelly1ApiJsonDTO .ShellyStatusSensor .ShellyExtAnalogInput ;
6062import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2DevConfigCover ;
6163import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2DevConfigInput ;
6264import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2DevConfigSwitch ;
65+ import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2GetConfigLight ;
6366import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .Shelly2GetConfigResult ;
6467import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceConfig .ShellyDeviceConfigCB ;
6568import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2DeviceStatus .Shelly2DeviceStatusLight ;
8083import org .openhab .binding .shelly .internal .api2 .Shelly2ApiJsonDTO .Shelly2StatusEm1 ;
8184import org .openhab .binding .shelly .internal .config .ShellyThingConfiguration ;
8285import org .openhab .binding .shelly .internal .handler .ShellyBaseHandler ;
86+ import org .openhab .binding .shelly .internal .handler .ShellyColorUtils ;
8387import org .openhab .binding .shelly .internal .handler .ShellyComponents ;
8488import org .openhab .binding .shelly .internal .handler .ShellyThingInterface ;
8589import org .openhab .core .types .State ;
@@ -96,6 +100,7 @@ public class Shelly2ApiClient extends ShellyHttpClient {
96100 private final Logger logger = LoggerFactory .getLogger (Shelly2ApiClient .class );
97101 protected final Random random = new Random ();
98102 protected final ShellyStatusRelay relayStatus = new ShellyStatusRelay ();
103+ protected final ShellyStatusLight lightStatus = new ShellyStatusLight ();
99104 protected final ShellyStatusSensor sensorData = new ShellyStatusSensor ();
100105 protected final ArrayList <ShellyRollerStatus > rollerStatus = new ArrayList <>();
101106 protected @ Nullable ShellyThingInterface thing ;
@@ -159,7 +164,7 @@ public Shelly2ApiClient(String thingName, ShellyThingConfiguration config, HttpC
159164 SHELLY2_RSTATE_STOPPED , SHELLY_RSTATE_STOP , //
160165 SHELLY2_RSTATE_CALIB , SHELLY2_RSTATE_CALIB ); // Gen2-only
161166
162- protected static final Map <String , String > MAP_PROFILE = Map .of (//
167+ protected static final Map <String , String > MAP_DEVICE_PROFILE = Map .of (//
163168 SHELLY2_PROFILE_RELAY , SHELLY_CLASS_RELAY , //
164169 SHELLY2_PROFILE_COVER , SHELLY_CLASS_ROLLER , //
165170 SHELLY2_PROFILE_LIGHT , SHELLY_MODE_WHITE , //
@@ -246,6 +251,12 @@ protected boolean fillDeviceStatus(ShellySettingsStatus status, Shelly2DeviceSta
246251 updated |= updateEmStatus (11 , status , result .em11 , channelUpdate );
247252 updated |= updateRollerStatus (0 , status , result .cover0 , channelUpdate );
248253 updated |= updateDimmerStatus (0 , status , result .light0 , channelUpdate );
254+ updated |= updateDimmerStatus (1 , status , result .light1 , channelUpdate );
255+ updated |= updateLightStatus (0 , status , result .light0 , channelUpdate );
256+ updated |= updateLightStatus (1 , status , result .light1 , channelUpdate );
257+ updated |= updateLightStatus (2 , status , result .light2 , channelUpdate );
258+ updated |= updateLightStatus (3 , status , result .light3 , channelUpdate );
259+ updated |= updateLightStatus (4 , status , result .light4 , channelUpdate );
249260 updated |= updateRGBWStatus (0 , status , result .rgbw0 , channelUpdate );
250261 if (channelUpdate ) {
251262 updated |= ShellyComponents .updateMeters (getThing (), status );
@@ -742,21 +753,6 @@ protected void fillDimmerSettings(ShellyDeviceProfile profile, Shelly2GetConfigR
742753 }
743754 }
744755
745- protected void fillRgbwSettings (ShellyDeviceProfile profile , Shelly2GetConfigResult dc ) {
746- if (!profile .isRGBW2 || dc .rgbw0 == null ) {
747- return ;
748- }
749-
750- List <ShellySettingsRgbwLight > lights = profile .settings .lights ;
751- if (lights != null ) {
752- ShellySettingsRgbwLight ls = lights .get (0 );
753- ls .autoOn = dc .rgbw0 .autoOnDelay ;
754- ls .autoOff = dc .rgbw0 .autoOffDelay ;
755- ls .name = dc .rgbw0 .name ;
756- lights .set (0 , ls );
757- }
758- }
759-
760756 private boolean updateDimmerStatus (int id , ShellySettingsStatus status , @ Nullable Shelly2DeviceStatusLight value ,
761757 boolean channelUpdate ) throws ShellyApiException {
762758 ShellyDeviceProfile profile = getProfile ();
@@ -778,6 +774,71 @@ private boolean updateDimmerStatus(int id, ShellySettingsStatus status, @Nullabl
778774 return channelUpdate ? ShellyComponents .updateDimmers (getThing (), status ) : false ;
779775 }
780776
777+ protected @ Nullable ArrayList <@ Nullable ShellySettingsRgbwLight > fillLightSettings (ShellyDeviceProfile profile ,
778+ Shelly2GetConfigResult dc ) {
779+ ArrayList <@ Nullable ShellySettingsRgbwLight > lights = new ArrayList <>();
780+ addLightSettings (lights , dc .light0 );
781+ addLightSettings (lights , dc .light1 );
782+ addLightSettings (lights , dc .light2 );
783+ addLightSettings (lights , dc .light3 );
784+ return !lights .isEmpty () ? lights : null ;
785+ }
786+
787+ private void addLightSettings (ArrayList <@ Nullable ShellySettingsRgbwLight > lights ,
788+ @ Nullable Shelly2GetConfigLight cl ) {
789+ if (cl == null ) {
790+ return ;
791+ }
792+
793+ ShellySettingsRgbwLight ls = new ShellySettingsRgbwLight ();
794+ ls .defaultState = cl .initialState ;
795+ ls .name = cl .name ;
796+ ls .ison = false ;
797+ ls .autoOn = getBool (cl .autoOn ) ? cl .autoOnDelay : 0 ;
798+ ls .autoOff = getBool (cl .autoOff ) ? cl .autoOffDelay : 0 ;
799+ lights .add (ls );
800+ }
801+
802+ private boolean updateLightStatus (int id , ShellySettingsStatus status , @ Nullable Shelly2DeviceStatusLight value ,
803+ boolean channelUpdate ) throws ShellyApiException {
804+ ShellyDeviceProfile profile = getProfile ();
805+ if (!profile .isLight || value == null ) {
806+ return false ;
807+ }
808+ if (value .id == null ) { // fw 1.6.1
809+ value .id = id ;
810+ }
811+
812+ ShellySettingsLight ls = status .lights .get (id );
813+ ShellyStatusLightChannel lc = new ShellyStatusLightChannel ();
814+ ls .mode = profile .device .mode ;
815+ ls .ison = lc .ison = value .output ;
816+ ls .dcpower = getDouble (value .apower ).intValue ();
817+ if (value .brightness != null ) {
818+ ls .brightness = lc .brightness = getDouble (value .brightness ).intValue ();
819+ }
820+
821+ status .lights .set (id , ls );
822+ lightStatus .lights .set (id , lc );
823+
824+ return channelUpdate ? ShellyComponents .updateLights (getThing (), lc , value .id , new ShellyColorUtils ()) : false ;
825+ }
826+
827+ protected void fillRgbwSettings (ShellyDeviceProfile profile , Shelly2GetConfigResult dc ) {
828+ if (!profile .isRGBW2 || dc .rgbw0 == null ) {
829+ return ;
830+ }
831+
832+ List <ShellySettingsRgbwLight > lights = profile .settings .lights ;
833+ if (lights != null ) {
834+ ShellySettingsRgbwLight ls = lights .get (0 );
835+ ls .autoOn = dc .rgbw0 .autoOnDelay ;
836+ ls .autoOff = dc .rgbw0 .autoOffDelay ;
837+ ls .name = dc .rgbw0 .name ;
838+ lights .set (0 , ls );
839+ }
840+ }
841+
781842 private boolean updateRGBWStatus (int id , ShellySettingsStatus status , @ Nullable Shelly2RGBWStatus value ,
782843 boolean channelUpdate ) throws ShellyApiException {
783844 ShellyDeviceProfile profile = getProfile ();
@@ -934,6 +995,7 @@ private void postAlarms(@Nullable ArrayList<@Nullable String> errors) throws She
934995 addInputSettings (inputs , dc .input1 );
935996 addInputSettings (inputs , dc .input2 );
936997 addInputSettings (inputs , dc .input3 );
998+ addInputSettings (inputs , dc .input4 );
937999
9381000 return inputs ;
9391001 }
@@ -956,6 +1018,7 @@ protected boolean updateInputStatus(ShellySettingsStatus status, Shelly2DeviceSt
9561018 updated |= addInputStatus (1 , status , ds .input1 , updateChannels );
9571019 updated |= addInputStatus (2 , status , ds .input2 , updateChannels );
9581020 updated |= addInputStatus (3 , status , ds .input3 , updateChannels );
1021+ updated |= addInputStatus (4 , status , ds .input4 , updateChannels );
9591022 status .inputs = relayStatus .inputs ;
9601023 return updated ;
9611024 }
0 commit comments