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