]> git.basschouten.com Git - openhab-addons.git/blob
160748df9c782f22bfc5c8e2c67d57ff67988ede
[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.onewire.internal.device;
14
15 import static org.openhab.binding.onewire.internal.OwBindingConstants.CHANNEL_COUNTER;
16
17 import java.util.List;
18
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.openhab.binding.onewire.internal.OwException;
21 import org.openhab.binding.onewire.internal.SensorId;
22 import org.openhab.binding.onewire.internal.handler.OwBaseThingHandler;
23 import org.openhab.binding.onewire.internal.handler.OwserverBridgeHandler;
24 import org.openhab.binding.onewire.internal.owserver.OwserverDeviceParameter;
25 import org.openhab.core.types.State;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28
29 /**
30  * The {@link DS2423} class defines a DS2423 device
31  *
32  * @author Jan N. Klug - Initial contribution
33  */
34 @NonNullByDefault
35 public class DS2423 extends AbstractOwDevice {
36     private final Logger logger = LoggerFactory.getLogger(DS2423.class);
37     private final OwserverDeviceParameter counterParameter = new OwserverDeviceParameter("/counters.ALL");
38
39     public DS2423(SensorId sensorId, OwBaseThingHandler callback) {
40         super(sensorId, callback);
41     }
42
43     @Override
44     public void configureChannels() throws OwException {
45         isConfigured = true;
46     }
47
48     @Override
49     public void refresh(OwserverBridgeHandler bridgeHandler, Boolean forcedRefresh) throws OwException {
50         if (isConfigured) {
51             logger.trace("refresh of sensor {} started", sensorId);
52             List<State> states = bridgeHandler.readDecimalTypeArray(sensorId, counterParameter);
53
54             if (states.size() != 2) {
55                 throw new OwException("Expected exactly two values, got " + states.size());
56             } else {
57                 callback.postUpdate(CHANNEL_COUNTER + "0", states.get(0));
58                 callback.postUpdate(CHANNEL_COUNTER + "1", states.get(1));
59             }
60         }
61     }
62 }