]> git.basschouten.com Git - openhab-addons.git/blob
78cc04350e2c58bb404d1c881513974f7fc802ef
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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     private double altitude;
42     private double[] coordinates = {};
43     private @Nullable String country;
44     private @Nullable String timezone;
45
46     private @Nullable String temperatureControlMode;
47     private SetpointMode thermMode = SetpointMode.UNKNOWN;
48     private int thermSetpointDefaultDuration;
49     private List<ThermProgram> schedules = List.of();
50
51     private NAObjectMap<HomeDataPerson> persons = new NAObjectMap<>();
52     private NAObjectMap<HomeDataRoom> rooms = new NAObjectMap<>();
53     private NAObjectMap<HomeDataModule> modules = new NAObjectMap<>();
54
55     @Override
56     public ModuleType getType() {
57         return ModuleType.HOME;
58     }
59
60     @Override
61     public double getAltitude() {
62         return altitude;
63     }
64
65     @Override
66     public double[] getCoordinates() {
67         return coordinates;
68     }
69
70     @Override
71     public Optional<String> getCountry() {
72         return Optional.ofNullable(country);
73     }
74
75     @Override
76     public Optional<String> getTimezone() {
77         return Optional.ofNullable(timezone);
78     }
79
80     public int getThermSetpointDefaultDuration() {
81         return thermSetpointDefaultDuration;
82     }
83
84     public SetpointMode getThermMode() {
85         return thermMode;
86     }
87
88     public NAObjectMap<HomeDataPerson> getPersons() {
89         return persons;
90     }
91
92     public List<HomeDataPerson> getKnownPersons() {
93         return persons.values().stream().filter(HomeDataPerson::isKnown).collect(Collectors.toList());
94     }
95
96     public Optional<String> getTemperatureControlMode() {
97         return Optional.ofNullable(temperatureControlMode);
98     }
99
100     public NAObjectMap<HomeDataRoom> getRooms() {
101         return rooms;
102     }
103
104     public NAObjectMap<HomeDataModule> getModules() {
105         return modules;
106     }
107
108     public Set<FeatureArea> getFeatures() {
109         return getModules().values().stream().map(m -> m.getType().feature).collect(Collectors.toSet());
110     }
111
112     public List<ThermProgram> getThermSchedules() {
113         return schedules;
114     }
115
116     public @Nullable ThermProgram getActiveProgram() {
117         return schedules.stream().filter(ThermProgram::isSelected).findFirst().orElse(null);
118     }
119 }