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.Protocol;
25 import org.openhab.binding.fineoffsetweatherstation.internal.domain.SensorGatewayBinding;
26 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.MeasuredValue;
27 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SensorDevice;
28 import org.openhab.binding.fineoffsetweatherstation.internal.domain.response.SystemInfo;
29 import org.openhab.binding.fineoffsetweatherstation.internal.handler.ThingStatusListener;
32 * Service to query an ELV gateway device.
34 * @author Andreas Berger - Initial contribution
37 public class ELVGatewayQueryService extends GatewayQueryService {
39 private final FineOffsetDataParser fineOffsetDataParser;
41 private final ConversionContext conversionContext;
43 public ELVGatewayQueryService(FineOffsetGatewayConfiguration config,
44 @Nullable ThingStatusListener thingStatusListener, ConversionContext conversionContext) {
45 super(config, thingStatusListener);
46 this.fineOffsetDataParser = new FineOffsetDataParser(Protocol.ELV);
47 this.conversionContext = conversionContext;
51 public @Nullable String getFirmwareVersion() {
52 Command command = Command.CMD_READ_FIRMWARE_VERSION;
53 var data = executeCommand(command.name(), command.getPayloadAlternative(), bytes -> true);
55 return fineOffsetDataParser.getFirmwareVersion(data);
61 public Map<SensorGatewayBinding, SensorDevice> getRegisteredSensors() {
62 // not supported by ELV device
63 return Collections.emptyMap();
67 public @Nullable SystemInfo fetchSystemInfo() {
68 // not supported by ELV device
73 public List<MeasuredValue> getMeasuredValues() {
74 Command command = Command.CMD_WS980_LIVEDATA;
75 // since this request has 2 checksums we shortcut it here and provide the concrete payload directly
76 byte[] payload = new byte[] { (byte) 0xff, (byte) 0xff, (byte) 0x0b, (byte) 0x00, (byte) 0x06, (byte) 0x04,
77 (byte) 0x04, (byte) 0x19 };
78 byte[] data = executeCommand(command.name(), payload, command::isResponseValid);
80 return Collections.emptyList();
82 return fineOffsetDataParser.getMeasuredValues(data, conversionContext);