]> git.basschouten.com Git - openhab-addons.git/blob
91745219037ed0aac33d1605429ff3865efdc4da
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2021 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.tado.internal.builder;
14
15 import java.io.IOException;
16
17 import org.openhab.binding.tado.internal.api.ApiException;
18 import org.openhab.binding.tado.internal.api.model.ZoneState;
19 import org.openhab.binding.tado.internal.handler.TadoZoneHandler;
20
21 /**
22  * Wrapper for zone state to support lazy loading.
23  *
24  * @author Dennis Frommknecht - Initial contribution
25  */
26 public class ZoneStateProvider {
27     private TadoZoneHandler zoneHandler;
28     private ZoneState zoneState;
29
30     public ZoneStateProvider(TadoZoneHandler zoneHandler) {
31         this.zoneHandler = zoneHandler;
32     }
33
34     ZoneState getZoneState() throws IOException, ApiException {
35         if (this.zoneState == null) {
36             ZoneState retrievedZoneState = zoneHandler.getZoneState();
37             // empty zone state behaves like a NULL object
38             this.zoneState = retrievedZoneState != null ? retrievedZoneState : new ZoneState();
39         }
40
41         return this.zoneState;
42     }
43 }