]> git.basschouten.com Git - openhab-addons.git/blob
4b75ab8f134e8ea04bff7f342069fe30e883dd13
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.herzborg.internal;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.core.io.transport.serial.SerialPortManager;
17 import org.openhab.core.thing.Bridge;
18 import org.openhab.core.thing.ThingStatus;
19 import org.openhab.core.thing.ThingStatusDetail;
20
21 /**
22  * The {@link SerialBusHandler} implements specific handling for Herzborg serial bus,
23  * connected directly via a serial port.
24  *
25  * @author Pavel Fedin - Initial contribution
26  */
27 @NonNullByDefault
28 public class SerialBusHandler extends BusHandler {
29     private SerialBusConfiguration config = new SerialBusConfiguration();
30
31     public SerialBusHandler(Bridge bridge, SerialPortManager portManager) {
32         super(bridge, new SerialBus(portManager));
33     }
34
35     @Override
36     public void initialize() {
37         config = getConfigAs(SerialBusConfiguration.class);
38
39         Bus.Result result = ((SerialBus) bus).initialize(config.port);
40
41         if (result.code == ThingStatusDetail.NONE) {
42             updateStatus(ThingStatus.ONLINE);
43         } else {
44             updateStatus(ThingStatus.OFFLINE, result.code, result.message);
45         }
46     }
47
48     @Override
49     public void dispose() {
50         bus.dispose();
51     }
52 }