]> git.basschouten.com Git - openhab-addons.git/blob
c45000d818de29eb24e409a173ab02ffc1443757
[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.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 import org.openhab.core.library.unit.Units;
22
23 /**
24  * The {@link Ws8482Processor} is responsible for updating
25  * the channels associated with the WS-1400-IP series weather stations in
26  * response to the receipt of a weather data update from the Ambient
27  * Weather real-time API.
28  *
29  * @author Mark Hilbush - Initial contribution
30  */
31 @NonNullByDefault
32 public class Ws8482Processor extends AbstractProcessor {
33
34     @Override
35     public void setChannelGroupId() {
36         channelGroupId = CHGRP_WS8482;
37     }
38
39     @Override
40     public void setNumberOfSensors() {
41         remoteSensor.setNumberOfSensors(7);
42     }
43
44     @Override
45     public void processInfoUpdate(AmbientWeatherStationHandler handler, String station, String name, String location) {
46         // Update name and location channels
47         handler.updateString(CHGRP_STATION, CH_NAME, name);
48         handler.updateString(CHGRP_STATION, CH_LOCATION, location);
49     }
50
51     @Override
52     public void processWeatherData(AmbientWeatherStationHandler handler, String station, String jsonData) {
53         EventDataJson data = parseEventData(station, jsonData);
54         if (data == null) {
55             return;
56         }
57
58         // Update the weather data channels
59         handler.updateDate(channelGroupId, CH_OBSERVATION_TIME, data.date);
60         handler.updateString(channelGroupId, CH_BATTERY_INDICATOR, data.battout);
61         handler.updateQuantity(channelGroupId, CH_TEMPERATURE, data.tempinf, ImperialUnits.FAHRENHEIT);
62         handler.updateQuantity(channelGroupId, CH_HUMIDITY, data.humidityin, Units.PERCENT);
63
64         // Update the remote sensor channels
65         remoteSensor.updateChannels(handler, jsonData);
66     }
67 }