]> git.basschouten.com Git - openhab-addons.git/blob
e28a4a9a8216e240408f11e82a8ab1d3ab77d291
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.netatmo.internal.api.dto;
14
15 import java.util.List;
16 import java.util.Optional;
17 import java.util.Set;
18 import java.util.stream.Collectors;
19
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;
28
29 /**
30  * The {@link HomeData} holds home information returned by homesdata endpoint.
31  *
32  * @author GaĆ«l L'hopital - Initial contribution
33  *
34  */
35
36 @NonNullByDefault
37 public class HomeData extends NAThing implements NAModule, LocationEx {
38     public class HomesDataResponse extends ApiResponse<ListBodyResponse<HomeData>> {
39     }
40
41     public class Security extends HomeData {
42         private @Nullable NAObjectMap<HomeDataPerson> persons;
43
44         public NAObjectMap<HomeDataPerson> getPersons() {
45             NAObjectMap<HomeDataPerson> localPersons = persons;
46             return localPersons != null ? localPersons : new NAObjectMap<>();
47         }
48
49         public List<HomeDataPerson> getKnownPersons() {
50             NAObjectMap<HomeDataPerson> localPersons = persons;
51             return localPersons != null ? localPersons.values().stream().filter(HomeDataPerson::isKnown).toList()
52                     : List.of();
53         }
54     }
55
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();
61
62         public int getThermSetpointDefaultDuration() {
63             return thermSetpointDefaultDuration;
64         }
65
66         public SetpointMode getThermMode() {
67             return thermMode;
68         }
69
70         public String getTemperatureControlMode() {
71             return temperatureControlMode;
72         }
73
74         public List<ThermProgram> getThermSchedules() {
75             return schedules;
76         }
77
78         public @Nullable ThermProgram getActiveProgram() {
79             return schedules.stream().filter(ThermProgram::isSelected).findFirst().orElse(null);
80         }
81     }
82
83     private double altitude;
84     private double[] coordinates = {};
85     private @Nullable String country;
86     private @Nullable String timezone;
87
88     private NAObjectMap<HomeDataRoom> rooms = new NAObjectMap<>();
89     private @Nullable NAObjectMap<HomeDataModule> modules;
90
91     @Override
92     public ModuleType getType() {
93         return ModuleType.HOME;
94     }
95
96     @Override
97     public double getAltitude() {
98         return altitude;
99     }
100
101     @Override
102     public double[] getCoordinates() {
103         return coordinates;
104     }
105
106     @Override
107     public Optional<String> getCountry() {
108         return Optional.ofNullable(country);
109     }
110
111     @Override
112     public Optional<String> getTimezone() {
113         return Optional.ofNullable(timezone);
114     }
115
116     public NAObjectMap<HomeDataRoom> getRooms() {
117         return rooms;
118     }
119
120     public NAObjectMap<HomeDataModule> getModules() {
121         NAObjectMap<HomeDataModule> local = modules;
122         return local != null ? local : new NAObjectMap<>();
123     }
124
125     public Set<FeatureArea> getFeatures() {
126         return getModules().values().stream().map(m -> m.getType().feature).collect(Collectors.toSet());
127     }
128 }