]> git.basschouten.com Git - openhab-addons.git/blob
456b7dc5fd65cf2f2338a687ffe235c2653d4b2f
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.ambientweather.internal.processor;
14
15 import static org.openhab.binding.ambientweather.internal.AmbientWeatherBindingConstants.*;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.openhab.binding.ambientweather.internal.handler.AmbientWeatherStationHandler;
19 import org.openhab.binding.ambientweather.internal.model.EventDataJson;
20 import org.openhab.core.library.unit.ImperialUnits;
21
22 /**
23  * The {@link Ws0265Processor} is responsible for updating
24  * the channels associated with the WS-0265 series weather stations in
25  * response to the receipt of a weather data update from the Ambient
26  * Weather real-time API.
27  *
28  * @author Mark Hilbush - Initial contribution
29  */
30 @NonNullByDefault
31 public class Ws0265Processor extends AbstractProcessor {
32
33     @Override
34     public void setChannelGroupId() {
35         channelGroupId = CHGRP_WS0265;
36     }
37
38     @Override
39     public void setNumberOfSensors() {
40         remoteSensor.setNumberOfSensors(7);
41     }
42
43     @Override
44     public void processInfoUpdate(AmbientWeatherStationHandler handler, String station, String name, String location) {
45         // Update name and location channels
46         handler.updateString(CHGRP_STATION, CH_NAME, name);
47         handler.updateString(CHGRP_STATION, CH_LOCATION, location);
48     }
49
50     @Override
51     public void processWeatherData(AmbientWeatherStationHandler handler, String station, String jsonData) {
52         EventDataJson data = parseEventData(station, jsonData);
53         if (data == null) {
54             return;
55         }
56
57         // Update the weather data channels
58         handler.updateDate(channelGroupId, CH_OBSERVATION_TIME, data.date);
59         handler.updateQuantity(channelGroupId, CH_TEMPERATURE, data.tempinf, ImperialUnits.FAHRENHEIT);
60
61         // Update the remote sensor channels
62         remoteSensor.updateChannels(handler, jsonData);
63     }
64 }