mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Enable home being both energy and security (#16026)
Signed-off-by: clinique <gael@lhopital.org>
This commit is contained in:
parent
5e26b7073a
commit
13a06167cc
@ -33,24 +33,18 @@ public class NAHomeStatus {
|
||||
|
||||
public class HomeStatus extends NAThing {
|
||||
private @Nullable NAObjectMap<HomeStatusModule> modules;
|
||||
private @Nullable NAObjectMap<Room> rooms;
|
||||
private @Nullable NAObjectMap<HomeStatusPerson> persons;
|
||||
|
||||
public NAObjectMap<HomeStatusModule> getModules() {
|
||||
NAObjectMap<HomeStatusModule> local = modules;
|
||||
return local != null ? local : new NAObjectMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Energy extends HomeStatus {
|
||||
private @Nullable NAObjectMap<Room> rooms;
|
||||
|
||||
public NAObjectMap<Room> getRooms() {
|
||||
NAObjectMap<Room> local = rooms;
|
||||
return local != null ? local : new NAObjectMap<>();
|
||||
}
|
||||
}
|
||||
|
||||
public class Security extends HomeStatus {
|
||||
private @Nullable NAObjectMap<HomeStatusPerson> persons;
|
||||
|
||||
public NAObjectMap<HomeStatusPerson> getPersons() {
|
||||
NAObjectMap<HomeStatusPerson> local = persons;
|
||||
|
@ -20,8 +20,6 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.netatmo.internal.api.NetatmoException;
|
||||
import org.openhab.binding.netatmo.internal.api.data.ModuleType;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.HomeStatus;
|
||||
import org.openhab.core.i18n.TimeZoneProvider;
|
||||
import org.openhab.core.library.types.OnOffType;
|
||||
import org.openhab.core.library.types.OpenClosedType;
|
||||
@ -52,10 +50,6 @@ public class NADeserializer {
|
||||
.registerTypeAdapter(NAObjectMap.class, new NAObjectMapDeserializer())
|
||||
.registerTypeAdapter(NAPushType.class, new NAPushTypeDeserializer())
|
||||
.registerTypeAdapter(ModuleType.class, new ModuleTypeDeserializer())
|
||||
.registerTypeAdapter(HomeStatus.class,
|
||||
(JsonDeserializer<HomeStatus>) (json, type, context) -> context.deserialize(json,
|
||||
json.getAsJsonObject().has("persons") ? NAHomeStatus.Security.class
|
||||
: NAHomeStatus.Energy.class))
|
||||
.registerTypeAdapter(HomeData.class,
|
||||
(JsonDeserializer<HomeData>) (json, type, context) -> context.deserialize(json,
|
||||
json.getAsJsonObject().has("therm_mode") ? HomeData.Energy.class
|
||||
|
@ -25,7 +25,6 @@ import org.openhab.binding.netatmo.internal.api.dto.HomeData;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeDataModule;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeDataRoom;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.HomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.Room;
|
||||
import org.openhab.binding.netatmo.internal.config.HomeConfiguration;
|
||||
@ -85,29 +84,27 @@ public class EnergyCapability extends RestCapability<EnergyApi> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateHomeStatus(HomeStatus homeStatus) {
|
||||
if (homeStatus instanceof NAHomeStatus.Energy energyStatus) {
|
||||
NAObjectMap<Room> rooms = energyStatus.getRooms();
|
||||
NAObjectMap<HomeStatusModule> modules = energyStatus.getModules();
|
||||
handler.getActiveChildren(FeatureArea.ENERGY).forEach(childHandler -> {
|
||||
String childId = childHandler.getId();
|
||||
logger.trace("childId: {}", childId);
|
||||
rooms.getOpt(childId).ifPresentOrElse(roomData -> {
|
||||
logger.trace("roomData: {}", roomData);
|
||||
childHandler.setNewData(roomData);
|
||||
}, () -> {
|
||||
modules.getOpt(childId).ifPresent(moduleData -> {
|
||||
logger.trace("moduleData: {}", moduleData);
|
||||
childHandler.setNewData(moduleData);
|
||||
modules.values().stream().filter(module -> childId.equals(module.getBridge()))
|
||||
.forEach(bridgedModule -> {
|
||||
logger.trace("bridgedModule: {}", bridgedModule);
|
||||
childHandler.setNewData(bridgedModule);
|
||||
});
|
||||
});
|
||||
protected void updateHomeStatus(HomeStatus energyStatus) {
|
||||
NAObjectMap<Room> rooms = energyStatus.getRooms();
|
||||
NAObjectMap<HomeStatusModule> modules = energyStatus.getModules();
|
||||
handler.getActiveChildren(FeatureArea.ENERGY).forEach(childHandler -> {
|
||||
String childId = childHandler.getId();
|
||||
logger.trace("childId: {}", childId);
|
||||
rooms.getOpt(childId).ifPresentOrElse(roomData -> {
|
||||
logger.trace("roomData: {}", roomData);
|
||||
childHandler.setNewData(roomData);
|
||||
}, () -> {
|
||||
modules.getOpt(childId).ifPresent(moduleData -> {
|
||||
logger.trace("moduleData: {}", moduleData);
|
||||
childHandler.setNewData(moduleData);
|
||||
modules.values().stream().filter(module -> childId.equals(module.getBridge()))
|
||||
.forEach(bridgedModule -> {
|
||||
logger.trace("bridgedModule: {}", bridgedModule);
|
||||
childHandler.setNewData(bridgedModule);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setThermPoint(String roomId, SetpointMode mode, long endtime, double temp) {
|
||||
|
@ -32,7 +32,6 @@ import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeEvent;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusModule;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusPerson;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.HomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
||||
import org.openhab.binding.netatmo.internal.config.HomeConfiguration;
|
||||
@ -88,21 +87,19 @@ class SecurityCapability extends RestCapability<SecurityApi> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateHomeStatus(HomeStatus homeStatus) {
|
||||
if (homeStatus instanceof NAHomeStatus.Security securityStatus) {
|
||||
NAObjectMap<HomeStatusPerson> persons = securityStatus.getPersons();
|
||||
NAObjectMap<HomeStatusModule> modules = securityStatus.getModules();
|
||||
handler.getActiveChildren(FeatureArea.SECURITY).forEach(childHandler -> {
|
||||
String childId = childHandler.getId();
|
||||
persons.getOpt(childId).ifPresentOrElse(personData -> childHandler.setNewData(personData), () -> {
|
||||
modules.getOpt(childId).ifPresent(childData -> {
|
||||
childHandler.setNewData(childData);
|
||||
modules.values().stream().filter(module -> childId.equals(module.getBridge()))
|
||||
.forEach(bridgedModule -> childHandler.setNewData(bridgedModule));
|
||||
});
|
||||
protected void updateHomeStatus(HomeStatus securityStatus) {
|
||||
NAObjectMap<HomeStatusPerson> persons = securityStatus.getPersons();
|
||||
NAObjectMap<HomeStatusModule> modules = securityStatus.getModules();
|
||||
handler.getActiveChildren(FeatureArea.SECURITY).forEach(childHandler -> {
|
||||
String childId = childHandler.getId();
|
||||
persons.getOpt(childId).ifPresentOrElse(personData -> childHandler.setNewData(personData), () -> {
|
||||
modules.getOpt(childId).ifPresent(childData -> {
|
||||
childHandler.setNewData(childData);
|
||||
modules.values().stream().filter(module -> childId.equals(module.getBridge()))
|
||||
.forEach(bridgedModule -> childHandler.setNewData(bridgedModule));
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.Nullable;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeData;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeDataPerson;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.HomeStatusPerson;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAHomeStatus.HomeStatus;
|
||||
import org.openhab.binding.netatmo.internal.api.dto.NAObject;
|
||||
import org.openhab.core.library.types.DecimalType;
|
||||
import org.openhab.core.types.State;
|
||||
@ -51,7 +51,7 @@ public class SecurityChannelHelper extends ChannelHelper {
|
||||
super.setNewData(data);
|
||||
if (data instanceof HomeData.Security securityData) {
|
||||
knownIds = securityData.getKnownPersons().stream().map(HomeDataPerson::getId).toList();
|
||||
} else if (data instanceof NAHomeStatus.Security securityStatus) {
|
||||
} else if (data instanceof HomeStatus securityStatus) {
|
||||
List<HomeStatusPerson> present = securityStatus.getPersons().values().stream()
|
||||
.filter(HomeStatusPerson::atHome).toList();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user