2 * Copyright (c) 2010-2024 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.warmup.internal.handler;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.QuantityType;
18 import org.openhab.core.library.types.StringType;
19 import org.openhab.core.library.unit.SIUnits;
20 import org.openhab.core.library.unit.Units;
21 import org.openhab.core.thing.Bridge;
22 import org.openhab.core.thing.ChannelUID;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.thing.ThingStatus;
25 import org.openhab.core.thing.ThingStatusDetail;
26 import org.openhab.core.thing.binding.BaseThingHandler;
27 import org.openhab.core.types.Command;
28 import org.openhab.core.types.RefreshType;
29 import org.openhab.core.types.State;
30 import org.openhab.core.types.UnDefType;
33 * The {@link WarmupThingHandler} is a super class for Things related to the Bridge consolidating logic.
35 * @author James Melville - Initial contribution
38 public class WarmupThingHandler extends BaseThingHandler {
40 public WarmupThingHandler(Thing thing) {
45 public void initialize() {
46 final MyWarmupAccountHandler bridgeHandler = getBridgeHandler();
47 if (bridgeHandler != null) {
48 updateStatus(ThingStatus.UNKNOWN);
53 public void handleCommand(ChannelUID channelUID, Command command) {
54 final MyWarmupAccountHandler bridgeHandler = getBridgeHandler();
56 if (command instanceof RefreshType && bridgeHandler != null) {
57 bridgeHandler.refreshFromCache();
61 protected void refreshFromServer() {
62 final MyWarmupAccountHandler bridgeHandler = getBridgeHandler();
64 if (bridgeHandler != null) {
65 bridgeHandler.refreshFromServer();
69 protected @Nullable MyWarmupAccountHandler getBridgeHandler() {
70 final Bridge bridge = getBridge();
73 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
76 return (MyWarmupAccountHandler) bridge.getHandler();
82 * @param temperature value returned from the API as an Integer * 10. i.e. 215 = 21.5 degrees C
83 * @return the temperature as a {@link QuantityType}
85 protected State parseTemperature(@Nullable Integer temperature) {
86 return temperature != null ? new QuantityType<>(temperature / 10.0, SIUnits.CELSIUS) : UnDefType.UNDEF;
91 * @param value a string to convert to {@link StringType}
92 * @return the string as a {@link StringType}
94 protected State parseString(@Nullable String value) {
95 return value != null ? new StringType(value) : UnDefType.UNDEF;
100 * @param value an integer to convert to {@link QuantityType} in minutes
101 * @return the number of minutes as a {@link QuantityType}
103 protected State parseDuration(@Nullable Integer value) {
104 return value != null ? new QuantityType<>(value, Units.MINUTE) : UnDefType.UNDEF;