mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-25 14:55:55 +01:00
[netatmo] Home properties are not persisted (#17601)
* Lazy reading of thing in Capability Signed-off-by: Gaël L'hopital <gael@lhopital.org> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
8021d5b13c
commit
c8022bd1d4
@ -80,8 +80,8 @@ public class CameraCapability extends HomeSecurityThingCapability {
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
hasSubEventGroup = !thing.getChannelsOfGroup(GROUP_SUB_EVENT).isEmpty();
|
||||
hasLastEventGroup = !thing.getChannelsOfGroup(GROUP_LAST_EVENT).isEmpty();
|
||||
hasSubEventGroup = !getThing().getChannelsOfGroup(GROUP_SUB_EVENT).isEmpty();
|
||||
hasLastEventGroup = !getThing().getChannelsOfGroup(GROUP_LAST_EVENT).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,7 +45,6 @@ import org.openhab.core.types.Command;
|
||||
*/
|
||||
@NonNullByDefault
|
||||
public class Capability {
|
||||
protected final Thing thing;
|
||||
protected final CommonInterface handler;
|
||||
protected final ModuleType moduleType;
|
||||
protected final ThingUID thingUID;
|
||||
@ -56,9 +55,8 @@ public class Capability {
|
||||
|
||||
Capability(CommonInterface handler) {
|
||||
this.handler = handler;
|
||||
this.thing = handler.getThing();
|
||||
this.thingUID = thing.getUID();
|
||||
this.moduleType = ModuleType.from(thing.getThingTypeUID());
|
||||
this.thingUID = getThing().getUID();
|
||||
this.moduleType = ModuleType.from(getThing().getThingTypeUID());
|
||||
}
|
||||
|
||||
public final @Nullable String setNewData(NAObject newData) {
|
||||
@ -100,13 +98,13 @@ public class Capability {
|
||||
}
|
||||
|
||||
protected void beforeNewData() {
|
||||
properties = new HashMap<>(thing.getProperties());
|
||||
properties = new HashMap<>(getThing().getProperties());
|
||||
statusReason = null;
|
||||
}
|
||||
|
||||
protected void afterNewData(@Nullable NAObject newData) {
|
||||
if (!properties.equals(thing.getProperties())) {
|
||||
thing.setProperties(properties);
|
||||
if (!properties.equals(getThing().getProperties())) {
|
||||
getThing().setProperties(properties);
|
||||
}
|
||||
firstLaunch = false;
|
||||
}
|
||||
@ -177,4 +175,8 @@ public class Capability {
|
||||
public List<NAObject> updateReadings() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
protected Thing getThing() {
|
||||
return handler.getThing();
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ import org.openhab.binding.netatmo.internal.api.HomeApi;
|
||||
import org.openhab.binding.netatmo.internal.api.NetatmoException;
|
||||
import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.Location;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAError;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
||||
import org.openhab.binding.netatmo.internal.config.HomeConfiguration;
|
||||
@ -82,17 +81,17 @@ public class HomeCapability extends CacheCapability<HomeApi> {
|
||||
if (featureAreas.contains(FeatureArea.SECURITY)) {
|
||||
handler.getCapabilities().put(new SecurityCapability(handler));
|
||||
} else {
|
||||
handler.removeChannels(thing.getChannelsOfGroup(GROUP_SECURITY));
|
||||
handler.removeChannels(getThing().getChannelsOfGroup(GROUP_SECURITY));
|
||||
}
|
||||
if (featureAreas.contains(FeatureArea.ENERGY)) {
|
||||
handler.getCapabilities().put(new EnergyCapability(handler, descriptionProvider));
|
||||
} else {
|
||||
handler.removeChannels(thing.getChannelsOfGroup(GROUP_ENERGY));
|
||||
handler.removeChannels(getThing().getChannelsOfGroup(GROUP_ENERGY));
|
||||
}
|
||||
home.getCountry().map(country -> properties.put(PROPERTY_COUNTRY, country));
|
||||
zoneId = home.getZoneId(handler.getSystemTimeZone());
|
||||
properties.put(PROPERTY_TIMEZONE, zoneId.toString());
|
||||
properties.put(GROUP_LOCATION, ((Location) home).getLocation().toString());
|
||||
properties.put(GROUP_LOCATION, home.getLocation().toString());
|
||||
properties.put(PROPERTY_FEATURE,
|
||||
featureAreas.stream().map(FeatureArea::name).collect(Collectors.joining(",")));
|
||||
}
|
||||
@ -104,8 +103,9 @@ public class HomeCapability extends CacheCapability<HomeApi> {
|
||||
*/
|
||||
@Override
|
||||
protected void updateErrors(NAError error) {
|
||||
handler.getAllActiveChildren((Bridge) thing).stream().filter(handler -> handler.getId().equals(error.getId()))
|
||||
.findFirst().ifPresent(handler -> handler.setNewData(error));
|
||||
handler.getAllActiveChildren((Bridge) getThing()).stream()
|
||||
.filter(handler -> handler.getId().equals(error.getId())).findFirst()
|
||||
.ifPresent(handler -> handler.setNewData(error));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user