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.regoheatpump.internal.handler;
15 import java.io.IOException;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.regoheatpump.internal.RegoHeatPumpBindingConstants;
20 import org.openhab.binding.regoheatpump.internal.protocol.RegoConnection;
21 import org.openhab.binding.regoheatpump.internal.protocol.SerialRegoConnection;
22 import org.openhab.core.io.transport.serial.SerialPortIdentifier;
23 import org.openhab.core.io.transport.serial.SerialPortManager;
24 import org.openhab.core.thing.Thing;
25 import org.openhab.core.thing.ThingStatus;
26 import org.openhab.core.thing.ThingStatusDetail;
29 * The {@link SerialRego6xxHeatPumpHandler} is responsible for handling commands, which are
30 * sent to one of the channels.
32 * @author Boris Krivonog - Initial contribution
35 public class SerialRego6xxHeatPumpHandler extends Rego6xxHeatPumpHandler {
36 private final SerialPortManager serialPortManager;
37 private @Nullable SerialPortIdentifier serialPortIdentifier;
39 public SerialRego6xxHeatPumpHandler(Thing thing, SerialPortManager serialPortManager) {
41 this.serialPortManager = serialPortManager;
45 public void initialize() {
46 String portName = (String) getConfig().get(RegoHeatPumpBindingConstants.PORT_NAME);
47 serialPortIdentifier = serialPortManager.getIdentifier(portName);
48 if (serialPortIdentifier == null) {
49 updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
50 "Serial port does not exist: " + portName);
57 protected RegoConnection createConnection() throws IOException {
58 SerialPortIdentifier serialPortIdentifier = this.serialPortIdentifier;
59 if (serialPortIdentifier == null) {
60 throw new IOException("Serial port does not exist");
62 return new SerialRegoConnection(serialPortIdentifier, 19200);