]> git.basschouten.com Git - openhab-addons.git/blob
9c1bc0e4001898707f25349218d6095e40232442
[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.tado.internal.builder;
14
15 import java.io.IOException;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.tado.internal.api.ApiException;
20 import org.openhab.binding.tado.internal.api.model.ZoneState;
21 import org.openhab.binding.tado.internal.handler.TadoZoneHandler;
22
23 /**
24  * Wrapper for zone state to support lazy loading.
25  *
26  * @author Dennis Frommknecht - Initial contribution
27  */
28 @NonNullByDefault
29 public class ZoneStateProvider {
30     private final TadoZoneHandler zoneHandler;
31     private @Nullable ZoneState zoneState;
32
33     public ZoneStateProvider(TadoZoneHandler zoneHandler) {
34         this.zoneHandler = zoneHandler;
35     }
36
37     public synchronized ZoneState getZoneState() throws IOException, ApiException {
38         ZoneState zoneState = this.zoneState;
39         if (zoneState == null) {
40             zoneState = this.zoneState = zoneHandler.getZoneState();
41         }
42         return zoneState;
43     }
44 }