]> git.basschouten.com Git - openhab-addons.git/blob
2f211b17c2dbaf84324122237eb7df671b1c7e0e
[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.sensibo.internal.model;
14
15 import java.util.ArrayList;
16 import java.util.List;
17 import java.util.Optional;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20
21 /**
22  * The {@link SensiboModel} represents the home structure as designed by the user in the Sensibo app.
23  *
24  * @author Arne Seime - Initial contribution
25  */
26 @NonNullByDefault
27 public class SensiboModel {
28     private final long lastUpdated;
29     private final List<SensiboSky> pods = new ArrayList<>();
30
31     public SensiboModel(final long lastUpdated) {
32         this.lastUpdated = lastUpdated;
33     }
34
35     public void addPod(final SensiboSky pod) {
36         pods.add(pod);
37     }
38
39     public List<SensiboSky> getPods() {
40         return pods;
41     }
42
43     public long getLastUpdated() {
44         return lastUpdated;
45     }
46
47     public Optional<SensiboSky> findSensiboSkyByMacAddress(final String macAddress) {
48         final String macAddressWithoutColons = macAddress.replace(":", "");
49         return pods.stream().filter(pod -> macAddressWithoutColons.equals(pod.getMacAddress())).findFirst();
50     }
51
52     /**
53      * @param macAddress
54      * @param acState
55      */
56     public void updateAcState(String macAddress, AcState acState) {
57         findSensiboSkyByMacAddress(macAddress).ifPresent(sky -> sky.updateAcState(acState));
58     }
59 }