]> git.basschouten.com Git - openhab-addons.git/blob
0423ed44bc13290edcf9782b472bb724b37fd68c
[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.jeelink.internal.lacrosse;
14
15 import org.openhab.binding.jeelink.internal.ReadingPublisher;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
18
19 /**
20  * Checks that the given temperature is in range before passing it on to the next publisher.
21  *
22  * @author Volker Bier - Initial contribution
23  */
24 public class BoundsCheckingPublisher implements ReadingPublisher<LaCrosseTemperatureReading> {
25     private final Logger logger = LoggerFactory.getLogger(BoundsCheckingPublisher.class);
26
27     private final ReadingPublisher<LaCrosseTemperatureReading> publisher;
28
29     private final float minTemp;
30     private final float maxTemp;
31
32     public BoundsCheckingPublisher(float min, float max, ReadingPublisher<LaCrosseTemperatureReading> p) {
33         minTemp = min;
34         maxTemp = max;
35         publisher = p;
36     }
37
38     @Override
39     public void publish(LaCrosseTemperatureReading reading) {
40         if (reading.getTemperature() >= minTemp && reading.getTemperature() <= maxTemp) {
41             publisher.publish(reading);
42         } else {
43             logger.debug("Ignoring out of bounds reading {}", reading.getTemperature());
44         }
45     }
46
47     @Override
48     public void dispose() {
49         publisher.dispose();
50     }
51 }