]> git.basschouten.com Git - openhab-addons.git/blob
2e60c9f2ff27ed85473ffd5674caf3a62191e739
[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.fineoffsetweatherstation.internal.service;
14
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18
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;
30
31 /**
32  * Service to query an ELV gateway device.
33  *
34  * @author Andreas Berger - Initial contribution
35  */
36 @NonNullByDefault
37 public class ELVGatewayQueryService extends GatewayQueryService {
38
39     private final FineOffsetDataParser fineOffsetDataParser;
40
41     private final ConversionContext conversionContext;
42
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;
48     }
49
50     @Override
51     public @Nullable String getFirmwareVersion() {
52         Command command = Command.CMD_READ_FIRMWARE_VERSION;
53         var data = executeCommand(command.name(), command.getPayloadAlternative(), bytes -> true);
54         if (null != data) {
55             return fineOffsetDataParser.getFirmwareVersion(data);
56         }
57         return null;
58     }
59
60     @Override
61     public Map<SensorGatewayBinding, SensorDevice> getRegisteredSensors() {
62         // not supported by ELV device
63         return Collections.emptyMap();
64     }
65
66     @Override
67     public @Nullable SystemInfo fetchSystemInfo() {
68         // not supported by ELV device
69         return null;
70     }
71
72     @Override
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);
79         if (data == null) {
80             return Collections.emptyList();
81         }
82         return fineOffsetDataParser.getMeasuredValues(data, conversionContext);
83     }
84 }