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.neohub.internal;
15 import static org.openhab.binding.neohub.internal.NeoHubBindingConstants.*;
17 import javax.measure.Unit;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.core.library.types.OnOffType;
21 import org.openhab.core.library.types.QuantityType;
22 import org.openhab.core.library.types.StringType;
23 import org.openhab.core.thing.Thing;
24 import org.openhab.core.types.Command;
27 * The {@link NeoStatHandler} is the openHAB Handler for NeoStat devices Note:
28 * inherits almost all the functionality of a {@link NeoBaseHandler}
30 * @author Andrew Fiddian-Green - Initial contribution
34 public class NeoStatHandler extends NeoBaseHandler {
36 public NeoStatHandler(Thing thing) {
41 protected String toNeoHubBuildCommandString(String channelId, Command command) {
42 NeoBaseConfiguration config = this.config;
44 if (command instanceof QuantityType<?> && channelId.equals(CHAN_TARGET_TEMP)) {
45 Command doCommand = command;
46 QuantityType<?> temp = ((QuantityType<?>) command).toUnit(getTemperatureUnit());
50 return String.format(CMD_CODE_TEMP, ((QuantityType<?>) doCommand).toBigDecimal().toString(),
51 config.deviceNameInHub);
54 if (command instanceof OnOffType && channelId.equals(CHAN_OCC_MODE_PRESENT)) {
55 return String.format(CMD_CODE_AWAY, invert((OnOffType) command).toString(), config.deviceNameInHub);
62 protected void toOpenHabSendChannelValues(NeoHubAbstractDeviceData.AbstractRecord deviceRecord) {
63 Unit<?> unit = getTemperatureUnit();
64 boolean offline = deviceRecord.offline();
66 toOpenHabSendValueDebounced(CHAN_TARGET_TEMP, new QuantityType<>(deviceRecord.getTargetTemperature(), unit),
69 toOpenHabSendValueDebounced(CHAN_ROOM_TEMP, new QuantityType<>(deviceRecord.getActualTemperature(), unit),
72 toOpenHabSendValueDebounced(CHAN_FLOOR_TEMP, new QuantityType<>(deviceRecord.getFloorTemperature(), unit),
75 toOpenHabSendValueDebounced(CHAN_OCC_MODE_PRESENT, OnOffType.from(!deviceRecord.isStandby()), offline);
77 toOpenHabSendValueDebounced(CHAN_STAT_OUTPUT_STATE,
78 (deviceRecord.isHeating() || deviceRecord.isPreHeating() ? new StringType(VAL_HEATING)
79 : new StringType(VAL_OFF)),
82 toOpenHabSendValueDebounced(CHAN_BATTERY_LOW_ALARM, OnOffType.from(deviceRecord.isBatteryLow()), offline);