Skip to content

Commit 61f03e8

Browse files
committed
@lolodomo review of 7/12:
fix bad error message on status when config is not valid fix initialization of config : now done in initialize Signed-off-by: Laurent ARNAL <[email protected]>
1 parent d2d6577 commit 61f03e8

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

bundles/org.openhab.binding.sedif/src/main/java/org/openhab/binding/sedif/internal/discovery/SedifDiscoveryService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import java.util.HashMap;
1818
import java.util.Map;
19+
import java.util.Objects;
1920
import java.util.Set;
2021

2122
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -139,9 +140,7 @@ private void detectNewWaterMeterFromContract(final Contract contract) {
139140
properties.put(PROPERTY_ELMB, compteInfo.eLmb);
140141
properties.put(PROPERTY_NUM_METER, compteInfo.numCompteur);
141142
properties.put(PROPERTY_ID_PDS, compteInfo.idPds);
142-
if (contract.name != null) {
143-
properties.put(PROPERTY_CONTRACT_ID, contract.name);
144-
}
143+
properties.put(PROPERTY_CONTRACT_ID, Objects.requireNonNull(contract.name));
145144

146145
DiscoveryResult discoveryResult = DiscoveryResultBuilder.create(thingUID)
147146
.withProperties(properties).withLabel("Water Meter " + compteInfo.numCompteur)

bundles/org.openhab.binding.sedif/src/main/java/org/openhab/binding/sedif/internal/handler/ThingSedifHandler.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class ThingSedifHandler extends BaseThingHandler {
102102

103103
protected final Gson gson;
104104

105-
protected SedifConfiguration config;
105+
protected @Nullable SedifConfiguration config;
106106

107107
public ThingSedifHandler(Thing thing, LocaleProvider localeProvider, TimeZoneProvider timeZoneProvider, Gson gson) {
108108
super(thing);
@@ -173,12 +173,13 @@ public ThingSedifHandler(Thing thing, LocaleProvider localeProvider, TimeZonePro
173173
return null;
174174
}
175175
});
176-
177-
config = getConfigAs(SedifConfiguration.class);
178176
}
179177

180178
@Override
181179
public synchronized void initialize() {
180+
SedifConfiguration lcConfig = getConfigAs(SedifConfiguration.class);
181+
config = lcConfig;
182+
182183
loadSedifState();
183184

184185
if (sedifState.getLastIndexDate() == null) {
@@ -189,9 +190,9 @@ public synchronized void initialize() {
189190
this.contractDetail.invalidate();
190191
this.consumption.invalidate();
191192

192-
if (config.seemsValid()) {
193-
contractName = config.contractId;
194-
numCompteur = config.meterId;
193+
if (lcConfig.seemsValid()) {
194+
contractName = lcConfig.contractId;
195+
numCompteur = lcConfig.meterId;
195196
updateStatus(ThingStatus.UNKNOWN);
196197
} else {
197198
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,

bundles/org.openhab.binding.sedif/src/main/resources/OH-INF/i18n/sedif.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ thing-type.config.sedif.meter.contractId.description = Your Contract Id
2121
thing-type.config.sedif.meter.meterId.label = Meter Id
2222
thing-type.config.sedif.meter.meterId.description = Your Meter Id
2323

24+
25+
offline.config-error-mandatory-settings = Incomplete configuration
26+
27+
2428
# channel group types
2529

2630
channel-group-type.sedif.base.label = Standard Base

0 commit comments

Comments
 (0)