2424import org .openhab .binding .simatic .internal .simatic .SimaticGenericDevice ;
2525import org .openhab .binding .simatic .internal .simatic .SimaticTCP ;
2626import org .openhab .binding .simatic .internal .simatic .SimaticTCP200 ;
27+ import org .openhab .binding .simatic .internal .simatic .SimaticUpdateMode ;
2728import org .openhab .core .library .types .DecimalType ;
2829import org .openhab .core .library .types .QuantityType ;
2930import org .openhab .core .library .types .StringType ;
@@ -96,38 +97,35 @@ public void initialize() {
9697
9798 config = getConfigAs (SimaticBridgeConfiguration .class );
9899
99- logger .debug ("{} - Bridge configuration: Host/IP={},Rack={},Slot={},Comm={},Is200={},Charset={},PollRate={}" ,
100+ logger .debug (
101+ "{} - Bridge configuration: Host/IP={},Rack={},Slot={},Comm={},Is200={},Charset={},PollRate={},Mode={}" ,
100102 getThing ().getLabel (), config .address , config .rack , config .slot , config .communicationType ,
101- config .isS7200 , config .charset , config .pollRate );
103+ config .isS7200 , config .charset , config .pollRate , config . updateMode );
102104
103105 // configuration validation
104106 boolean valid = true ;
105107
106108 if (config .address == null || config .address .isBlank ()) {
107109 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR , "No Host/IP address" );
108110 valid = false ;
109- return ;
110111 }
111112
112- if (config .rack < 0 || config .rack > 2 ) {
113+ if (valid && ( config .rack < 0 || config .rack > 2 ) ) {
113114 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR ,
114115 "Invalid Rack number. Valid is 0-2." );
115116 valid = false ;
116- return ;
117117 }
118118
119- if (config .slot < 0 || config .slot > 15 ) {
119+ if (valid && ( config .slot < 0 || config .slot > 15 ) ) {
120120 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR ,
121121 "Invalid Slot number. Valid is 0-15." );
122122 valid = false ;
123- return ;
124123 }
125124
126- if (config .communicationType == null || !(config .communicationType .equals ("S7" )
127- || config .communicationType .equals ("PG" ) || config .communicationType .equals ("OP" ))) {
125+ if (valid && ( config .communicationType == null || !(config .communicationType .equals ("S7" )
126+ || config .communicationType .equals ("PG" ) || config .communicationType .equals ("OP" )))) {
128127 updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR , "Invalid communication type." );
129128 valid = false ;
130- return ;
131129 }
132130
133131 if (config .pollRate <= 0 ) {
@@ -136,6 +134,19 @@ public void initialize() {
136134 getThing ().getLabel ());
137135 }
138136
137+ if (valid && (config .updateMode == null || !SimaticUpdateMode .validate (config .updateMode ))) {
138+ updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR , "Invalid value update mode." );
139+ valid = false ;
140+ }
141+
142+ if (!valid ) {
143+ // updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR);
144+ logger .error ("{} - Bridge configuration is invalid. Host/IP={},Rack={},Slot={},Comm={},Is200={},Mode={}" ,
145+ getThing ().getLabel (), config .address , config .rack , config .slot , config .communicationType ,
146+ config .isS7200 , config .updateMode );
147+ return ;
148+ }
149+
139150 Charset charset ;
140151 if (config .charset == null || config .charset .isBlank ()) {
141152 charset = Charset .defaultCharset ();
@@ -149,19 +160,13 @@ public void initialize() {
149160
150161 logger .info ("{} - Current charset {}" , getThing ().getLabel (), charset .name ());
151162
152- if (!valid ) {
153- updateStatus (ThingStatus .OFFLINE , ThingStatusDetail .CONFIGURATION_ERROR );
154- logger .error ("{} - Bridge configuration is invalid. Host/IP={},Rack={},Slot={},Comm={},Is200={}" ,
155- getThing ().getLabel (), config .address , config .rack , config .slot , config .communicationType ,
156- config .isS7200 );
157- }
158-
159163 // S7-200 PLC
160164 if (config .isS7200 ) {
161- connection = new SimaticTCP200 (config .address , config .rack , config .slot , config .pollRate , charset );
165+ connection = new SimaticTCP200 (config .address , config .rack , config .slot , config .pollRate , charset ,
166+ SimaticUpdateMode .fromString (config .updateMode ));
162167 } else {
163168 connection = new SimaticTCP (config .address , config .rack , config .slot , config .communicationType ,
164- config .pollRate , charset );
169+ config .pollRate , charset , SimaticUpdateMode . fromString ( config . updateMode ) );
165170 }
166171
167172 // react on connection changes
0 commit comments