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