]> git.basschouten.com Git - openhab-addons.git/blob
a37d471fe8ed7430c0de9f9f5c861ff6b778d44d
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.regoheatpump.internal.handler;
14
15 import org.openhab.binding.regoheatpump.internal.RegoHeatPumpBindingConstants;
16 import org.openhab.binding.regoheatpump.internal.protocol.RegoConnection;
17 import org.openhab.binding.regoheatpump.internal.protocol.SerialRegoConnection;
18 import org.openhab.core.io.transport.serial.SerialPortIdentifier;
19 import org.openhab.core.io.transport.serial.SerialPortManager;
20 import org.openhab.core.thing.Thing;
21 import org.openhab.core.thing.ThingStatus;
22 import org.openhab.core.thing.ThingStatusDetail;
23
24 /**
25  * The {@link SerialHusdataHandler} is responsible for handling commands, which are
26  * sent to one of the channels.
27  *
28  * @author Boris Krivonog - Initial contribution
29  */
30 public class SerialHusdataHandler extends HusdataHandler {
31     private final SerialPortManager serialPortManager;
32     private SerialPortIdentifier serialPortIdentifier;
33
34     public SerialHusdataHandler(Thing thing, SerialPortManager serialPortManager) {
35         super(thing);
36         this.serialPortManager = serialPortManager;
37     }
38
39     @Override
40     public void initialize() {
41         String portName = (String) getConfig().get(RegoHeatPumpBindingConstants.PORT_NAME);
42         serialPortIdentifier = serialPortManager.getIdentifier(portName);
43         if (serialPortIdentifier == null) {
44             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
45                     "Serial port does not exist: " + portName);
46         } else {
47             super.initialize();
48         }
49     }
50
51     @Override
52     protected RegoConnection createConnection() {
53         return new SerialRegoConnection(serialPortIdentifier, 19200);
54     }
55 }