2 * Copyright (c) 2010-2023 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.sensibo.internal.handler;
15 import java.util.Optional;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.sensibo.internal.model.SensiboModel;
19 import org.openhab.core.thing.Bridge;
20 import org.openhab.core.thing.Channel;
21 import org.openhab.core.thing.ChannelUID;
22 import org.openhab.core.thing.Thing;
23 import org.openhab.core.thing.binding.BaseThingHandler;
24 import org.openhab.core.types.Command;
25 import org.openhab.core.types.RefreshType;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
30 * @author Arne Seime - Initial contribution
33 public abstract class SensiboBaseThingHandler extends BaseThingHandler {
34 private final Logger logger = LoggerFactory.getLogger(SensiboBaseThingHandler.class);
36 public SensiboBaseThingHandler(final Thing thing) {
40 public void updateState(final SensiboModel model) {
41 for (final Channel channel : getThing().getChannels()) {
42 handleCommand(channel.getUID(), RefreshType.REFRESH, model);
46 public SensiboModel getSensiboModel() {
47 final Optional<SensiboAccountHandler> accountHandler = getAccountHandler();
48 if (accountHandler.isPresent()) {
49 return accountHandler.get().getModel();
52 "Thing {} cannot exist without a bridge and account handler - returning empty model. No heaters or rooms will be found",
54 return new SensiboModel(0);
58 protected Optional<SensiboAccountHandler> getAccountHandler() {
59 final Bridge bridge = getBridge();
61 final SensiboAccountHandler accountHandler = (SensiboAccountHandler) bridge.getHandler();
62 if (accountHandler != null) {
63 return Optional.of(accountHandler);
66 return Optional.empty();
69 protected abstract void handleCommand(ChannelUID uid, Command command, SensiboModel model);