2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.netatmo.internal.api.dto;
15 import java.util.List;
16 import java.util.Optional;
18 import java.util.stream.Collectors;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.netatmo.internal.api.ApiResponse;
23 import org.openhab.binding.netatmo.internal.api.ListBodyResponse;
24 import org.openhab.binding.netatmo.internal.api.data.ModuleType;
25 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.FeatureArea;
26 import org.openhab.binding.netatmo.internal.api.data.NetatmoConstants.SetpointMode;
27 import org.openhab.binding.netatmo.internal.deserialization.NAObjectMap;
30 * The {@link HomeData} holds home information returned by homesdata endpoint.
32 * @author Gaƫl L'hopital - Initial contribution
37 public class HomeData extends NAThing implements NAModule, LocationEx {
38 public class HomesDataResponse extends ApiResponse<ListBodyResponse<HomeData>> {
41 public class Security extends HomeData {
42 private @Nullable NAObjectMap<HomeDataPerson> persons;
44 public NAObjectMap<HomeDataPerson> getPersons() {
45 NAObjectMap<HomeDataPerson> localPersons = persons;
46 return localPersons != null ? localPersons : new NAObjectMap<>();
49 public List<HomeDataPerson> getKnownPersons() {
50 NAObjectMap<HomeDataPerson> localPersons = persons;
51 return localPersons != null ? localPersons.values().stream().filter(HomeDataPerson::isKnown).toList()
56 public class Energy extends HomeData {
57 private String temperatureControlMode = "";
58 private SetpointMode thermMode = SetpointMode.UNKNOWN;
59 private int thermSetpointDefaultDuration;
60 private List<ThermProgram> schedules = List.of();
62 public int getThermSetpointDefaultDuration() {
63 return thermSetpointDefaultDuration;
66 public SetpointMode getThermMode() {
70 public String getTemperatureControlMode() {
71 return temperatureControlMode;
74 public List<ThermProgram> getThermSchedules() {
78 public @Nullable ThermProgram getActiveProgram() {
79 return schedules.stream().filter(ThermProgram::isSelected).findFirst().orElse(null);
83 private double altitude;
84 private double[] coordinates = {};
85 private @Nullable String country;
86 private @Nullable String timezone;
88 private NAObjectMap<HomeDataRoom> rooms = new NAObjectMap<>();
89 private @Nullable NAObjectMap<HomeDataModule> modules;
92 public ModuleType getType() {
93 return ModuleType.HOME;
97 public double getAltitude() {
102 public double[] getCoordinates() {
107 public Optional<String> getCountry() {
108 return Optional.ofNullable(country);
112 public Optional<String> getTimezone() {
113 return Optional.ofNullable(timezone);
116 public NAObjectMap<HomeDataRoom> getRooms() {
120 public NAObjectMap<HomeDataModule> getModules() {
121 NAObjectMap<HomeDataModule> local = modules;
122 return local != null ? local : new NAObjectMap<>();
125 public Set<FeatureArea> getFeatures() {
126 return getModules().values().stream().map(m -> m.getType().feature).collect(Collectors.toSet());