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.smartmeter;
15 import java.io.IOException;
16 import java.util.function.Supplier;
18 import org.openhab.binding.smartmeter.connectors.ConnectorBase;
22 * @author Matthias Steigenberger - Initial contribution
25 public class MockMeterReaderConnector extends ConnectorBase<Object> {
27 private boolean applyRetry;
28 private Supplier<Object> readNextSupplier;
30 protected MockMeterReaderConnector(String portName, boolean applyRetry, Supplier<Object> readNextSupplier) {
32 this.applyRetry = applyRetry;
33 this.readNextSupplier = readNextSupplier;
37 public void openConnection() throws IOException {
41 public void closeConnection() {
45 protected Object readNext(byte[] initMessage) throws IOException {
47 return readNextSupplier.get();
48 } catch (RuntimeException e) {
49 if (e.getCause() instanceof IOException) {
50 throw (IOException) e.getCause();
57 protected boolean applyRetryHandling() {
58 return this.applyRetry;
62 protected boolean applyPeriod() {
67 protected void retryHook(int retryCount) {
68 super.retryHook(retryCount);