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.fineoffsetweatherstation.internal.service;
15 import java.util.Collections;
16 import java.util.List;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.openhab.binding.fineoffsetweatherstation.internal.FineOffsetGatewayConfiguration;
22 import org.openhab.binding.fineoffsetweatherstation.internal.domain.Command;
23 import org.openhab.binding.fineoffsetweatherstation.internal.domain.ConversionContext;
24 import org.openhab.binding.fineoffsetweatherstation.internal.domain.DebugDetails;
25 import org.openhab.binding.fineoffsetweatherstation.internal.domain.Protocol;
26 import org.openhab.binding.fineoffsetweatherstation.internal.domain.SensorGatewayBinding;
27 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.MeasuredValue;
28 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SensorDevice;
29 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SystemInfo;
30 import org.openhab.binding.fineoffsetweatherstation.internal.handler.ThingStatusListener;
33 * Service to query an ELV gateway device.
35 * @author Andreas Berger - Initial contribution
38 public class ELVGatewayQueryService extends GatewayQueryService {
40 private final FineOffsetDataParser fineOffsetDataParser;
42 private final ConversionContext conversionContext;
44 public ELVGatewayQueryService(FineOffsetGatewayConfiguration config,
45 @Nullable ThingStatusListener thingStatusListener, ConversionContext conversionContext) {
46 super(config, thingStatusListener);
47 this.fineOffsetDataParser = new FineOffsetDataParser(Protocol.ELV);
48 this.conversionContext = conversionContext;
52 public @Nullable String getFirmwareVersion() {
53 Command command = Command.CMD_READ_FIRMWARE_VERSION;
54 var data = executeCommand(command.name(), command.getPayloadAlternative(), bytes -> true);
56 return fineOffsetDataParser.getFirmwareVersion(data);
62 public Map<SensorGatewayBinding, SensorDevice> getRegisteredSensors() {
63 // not supported by ELV device
64 return Collections.emptyMap();
68 public @Nullable SystemInfo fetchSystemInfo() {
69 // not supported by ELV device
74 public List<MeasuredValue> getMeasuredValues() {
75 Command command = Command.CMD_WS980_LIVEDATA;
76 // since this request has 2 checksums we shortcut it here and provide the concrete payload directly
77 byte[] payload = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0x0b, (byte) 0x00, (byte) 0x06, (byte) 0x04,
78 (byte) 0x04, (byte) 0x19 };
79 byte[] data = executeCommand(command.name(), payload, command::isResponseValid);
81 return Collections.emptyList();
83 DebugDetails debugDetails = new DebugDetails(data, Command.CMD_WS980_LIVEDATA, Protocol.ELV);
84 List<MeasuredValue> measuredValues = fineOffsetDataParser.getMeasuredValues(data, conversionContext,
86 logger.trace("{}", debugDetails);
87 return measuredValues;