2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.tado.internal.builder;
15 import java.io.IOException;
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;
22 * Wrapper for zone state to support lazy loading.
24 * @author Dennis Frommknecht - Initial contribution
26 public class ZoneStateProvider {
27 private TadoZoneHandler zoneHandler;
28 private ZoneState zoneState;
30 public ZoneStateProvider(TadoZoneHandler zoneHandler) {
31 this.zoneHandler = zoneHandler;
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();
41 return this.zoneState;