Skip to content

Commit 1feb253

Browse files
authored
[netatmo] Home properties are not persisted (openhab#17601)
* Lazy reading of thing in Capability Signed-off-by: Gaël L'hopital <[email protected]>
1 parent 51e1205 commit 1feb253

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/CameraCapability.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public CameraCapability(CommonInterface handler, NetatmoDescriptionProvider desc
8080

8181
@Override
8282
public void initialize() {
83-
hasSubEventGroup = !thing.getChannelsOfGroup(GROUP_SUB_EVENT).isEmpty();
84-
hasLastEventGroup = !thing.getChannelsOfGroup(GROUP_LAST_EVENT).isEmpty();
83+
hasSubEventGroup = !getThing().getChannelsOfGroup(GROUP_SUB_EVENT).isEmpty();
84+
hasLastEventGroup = !getThing().getChannelsOfGroup(GROUP_LAST_EVENT).isEmpty();
8585
}
8686

8787
@Override

bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/Capability.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
*/
4646
@NonNullByDefault
4747
public class Capability {
48-
protected final Thing thing;
4948
protected final CommonInterface handler;
5049
protected final ModuleType moduleType;
5150
protected final ThingUID thingUID;
@@ -56,9 +55,8 @@ public class Capability {
5655

5756
Capability(CommonInterface handler) {
5857
this.handler = handler;
59-
this.thing = handler.getThing();
60-
this.thingUID = thing.getUID();
61-
this.moduleType = ModuleType.from(thing.getThingTypeUID());
58+
this.thingUID = getThing().getUID();
59+
this.moduleType = ModuleType.from(getThing().getThingTypeUID());
6260
}
6361

6462
public final @Nullable String setNewData(NAObject newData) {
@@ -100,13 +98,13 @@ public class Capability {
10098
}
10199

102100
protected void beforeNewData() {
103-
properties = new HashMap<>(thing.getProperties());
101+
properties = new HashMap<>(getThing().getProperties());
104102
statusReason = null;
105103
}
106104

107105
protected void afterNewData(@Nullable NAObject newData) {
108-
if (!properties.equals(thing.getProperties())) {
109-
thing.setProperties(properties);
106+
if (!properties.equals(getThing().getProperties())) {
107+
getThing().setProperties(properties);
110108
}
111109
firstLaunch = false;
112110
}
@@ -177,4 +175,8 @@ public Collection<Class<? extends ThingHandlerService>> getServices() {
177175
public List<NAObject> updateReadings() {
178176
return List.of();
179177
}
178+
179+
protected Thing getThing() {
180+
return handler.getThing();
181+
}
180182
}

bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/handler/capability/HomeCapability.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.openhab.binding.netatmo.internal.api.NetatmoException;
2828
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
2929
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
30-
import org.openhab.binding.netatmo.internal.api.dto.Location;
3130
import org.openhab.binding.netatmo.internal.api.dto.NAError;
3231
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
3332
import org.openhab.binding.netatmo.internal.config.HomeConfiguration;
@@ -82,17 +81,17 @@ protected void updateHomeData(HomeData home) {
8281
if (featureAreas.contains(FeatureArea.SECURITY)) {
8382
handler.getCapabilities().put(new SecurityCapability(handler));
8483
} else {
85-
handler.removeChannels(thing.getChannelsOfGroup(GROUP_SECURITY));
84+
handler.removeChannels(getThing().getChannelsOfGroup(GROUP_SECURITY));
8685
}
8786
if (featureAreas.contains(FeatureArea.ENERGY)) {
8887
handler.getCapabilities().put(new EnergyCapability(handler, descriptionProvider));
8988
} else {
90-
handler.removeChannels(thing.getChannelsOfGroup(GROUP_ENERGY));
89+
handler.removeChannels(getThing().getChannelsOfGroup(GROUP_ENERGY));
9190
}
9291
home.getCountry().map(country -> properties.put(PROPERTY_COUNTRY, country));
9392
zoneId = home.getZoneId(handler.getSystemTimeZone());
9493
properties.put(PROPERTY_TIMEZONE, zoneId.toString());
95-
properties.put(GROUP_LOCATION, ((Location) home).getLocation().toString());
94+
properties.put(GROUP_LOCATION, home.getLocation().toString());
9695
properties.put(PROPERTY_FEATURE,
9796
featureAreas.stream().map(FeatureArea::name).collect(Collectors.joining(",")));
9897
}
@@ -104,8 +103,9 @@ protected void updateHomeData(HomeData home) {
104103
*/
105104
@Override
106105
protected void updateErrors(NAError error) {
107-
handler.getAllActiveChildren((Bridge) thing).stream().filter(handler -> handler.getId().equals(error.getId()))
108-
.findFirst().ifPresent(handler -> handler.setNewData(error));
106+
handler.getAllActiveChildren((Bridge) getThing()).stream()
107+
.filter(handler -> handler.getId().equals(error.getId())).findFirst()
108+
.ifPresent(handler -> handler.setNewData(error));
109109
}
110110

111111
@Override

0 commit comments

Comments
 (0)