Skip to content

Commit

Permalink
[wundergroundupdatereceiver] Add some more channel types per request
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Demus <daniel-github@demus.dk>
  • Loading branch information
danieldemus committed Feb 25, 2021
1 parent f68cd20 commit 0421ec4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class WundergroundUpdateReceiverBindingConstants {
// List of all Channel ids without groups
public static final String DATEUTC = "dateutc";
public static final String SOFTWARE_TYPE = "softwaretype";
public static final String LOW_BATTERY = "lowbatt";
public static final String REALTIME_FREQUENCY = "rtfreq";
public static final String WIND_DIRECTION = "winddir";
public static final String WIND_SPEED = "windspeedmph";
public static final String GUST_SPEED = "windgustmph";
Expand Down Expand Up @@ -108,13 +110,13 @@ public class WundergroundUpdateReceiverBindingConstants {
public static final Unit<Length> NAUTICAL_MILE = addUnit(
new TransformedUnit<>("NM", METRE, new MultiplyConverter(1852.0)));

public static final Set<String> CHANNEL_KEYS = Set.of(DATEUTC, SOFTWARE_TYPE, WIND_DIRECTION, WIND_SPEED,
GUST_SPEED, GUST_DIRECTION, WIND_SPEED_AVG_2MIN, WIND_DIRECTION_AVG_2MIN, GUST_SPEED_AVG_10MIN,
GUST_DIRECTION_AVG_10MIN, TEMPERATURE, INDOOR_TEMPERATURE, SOIL_TEMPERATURE, WIND_CHILL, HUMIDITY,
INDOOR_HUMIDITY, DEWPOINT, SOIL_MOISTURE, LEAF_WETNESS, RAIN_IN, DAILY_RAIN_IN, WEEKLY_RAIN_IN,
MONTHLY_RAIN_IN, YEARLY_RAIN_IN, SOLAR_RADIATION, UV, VISIBILITY, WEATHER, CLOUDS, BAROM_IN, AQ_NO, AQ_NO2,
AQ_NO2T, AQ_NO2Y, AQ_NOX, AQ_NOY, AQ_NO3, AQ_SO2, AQ_SO2T, AQ_SO4, AQ_CO, AQ_COT, AQ_EC, AQ_OC, AQ_BC,
AQ_UV_AETH, AQ_PM2_5, AQ_PM10, AQ_OZONE);
public static final Set<String> CHANNEL_KEYS = Set.of(DATEUTC, SOFTWARE_TYPE, LOW_BATTERY, REALTIME_FREQUENCY,
WIND_DIRECTION, WIND_SPEED, GUST_SPEED, GUST_DIRECTION, WIND_SPEED_AVG_2MIN, WIND_DIRECTION_AVG_2MIN,
GUST_SPEED_AVG_10MIN, GUST_DIRECTION_AVG_10MIN, TEMPERATURE, INDOOR_TEMPERATURE, SOIL_TEMPERATURE,
WIND_CHILL, HUMIDITY, INDOOR_HUMIDITY, DEWPOINT, SOIL_MOISTURE, LEAF_WETNESS, RAIN_IN, DAILY_RAIN_IN,
WEEKLY_RAIN_IN, MONTHLY_RAIN_IN, YEARLY_RAIN_IN, SOLAR_RADIATION, UV, VISIBILITY, WEATHER, CLOUDS, BAROM_IN,
AQ_NO, AQ_NO2, AQ_NO2T, AQ_NO2Y, AQ_NOX, AQ_NOY, AQ_NO3, AQ_SO2, AQ_SO2T, AQ_SO4, AQ_CO, AQ_COT, AQ_EC,
AQ_OC, AQ_BC, AQ_UV_AETH, AQ_PM2_5, AQ_PM10, AQ_OZONE);

public static final Map<String, Unit<? extends Quantity<?>>> CHANNEL_UNIT_MAPPING = Map.ofEntries(
entry(TEMPERATURE, FAHRENHEIT), entry(DEWPOINT, FAHRENHEIT), entry(SOIL_TEMPERATURE, FAHRENHEIT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.thing.Channel;
Expand Down Expand Up @@ -139,6 +140,8 @@ public void updateChannelState(String channelId, String state) {
Unit<? extends Quantity<?>> unit = CHANNEL_UNIT_MAPPING.get(channelId);
if (unit != null) {
updateState(channelUID, new QuantityType<>(numberValue, unit));
} else if (LOW_BATTERY.equals(channelId)) {
updateState(channelUID, OnOffType.from(state));
} else {
updateState(channelUID, new DecimalType(numberValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ channel-type.wundergroundupdatereceiver.last-received-datetime.description=Tidsp
channel-type.wundergroundupdatereceiver.last-received-datetime.label=Sidst modtaget
channel-type.wundergroundupdatereceiver.datetime-utc.description=Stationens værdi for sidst opdateringstidspunkt. Kan være 'now'
channel-type.wundergroundupdatereceiver.datetime-utc.label=Sidst opdateret
channel-type.system.low-battery.description=Stationens batteri er ved være flad
channel-type.system.low-battery.label=Lav batteri
channel-type.wundergroundupdatereceiver.realtime-frequency.description=Stationens angivelse af opdateringsfrekvensen
channel-type.wundergroundupdatereceiver.realtime-frequency.label=Opdateringsfrekvens
channel-type.wundergroundupdatereceiver.wind-speed.description=Øjeblikkelig vindhastighed i mph
channel-type.wundergroundupdatereceiver.wind-speed.label=Vindhastighed
channel-type.wundergroundupdatereceiver.wind-gust-speed.description=Øjeblikkelig vindstødshastighed
Expand All @@ -51,6 +55,8 @@ channel-type.wundergroundupdatereceiver.indoor-humidity.description=Indendørs f
channel-type.wundergroundupdatereceiver.indoor-humidity.label=Indendørs fugtighed
channel-type.wundergroundupdatereceiver.dew-point.description=Dugpunkt
channel-type.wundergroundupdatereceiver.dew-point.label=Dugpunkt
channel-type.wundergroundupdatereceiver.wind-chill.description=Kuldeindeks
channel-type.wundergroundupdatereceiver.wind-chill.label=Kuldeindeks
channel-type.system.temperature.description=Udendørs temperatur
channel-type.system.temperature.label=Udendørs temperatur
channel-type.wundergroundupdatereceiver.indoor-temperature.description=Indendørs temperatur
Expand All @@ -59,8 +65,14 @@ channel-type.wundergroundupdatereceiver.soil-temperature.description=Jordtemeper
channel-type.wundergroundupdatereceiver.soil-temperature.label=Jordtemeperatur
channel-type.wundergroundupdatereceiver.rain.description=Regnmængde i den sidste time
channel-type.wundergroundupdatereceiver.rain.label=Regn (sidste time)
channel-type.wundergroundupdatereceiver.rain-daily.description=Regnmængde sidsen starten af dagen
channel-type.wundergroundupdatereceiver.rain-daily.description=Regnmængde siden starten af dagen
channel-type.wundergroundupdatereceiver.rain-daily.label=Regn (i dag)
channel-type.wundergroundupdatereceiver.rain-weekly.description=Regnmængde siden starten af ugen
channel-type.wundergroundupdatereceiver.rain-weekly.label=Regn (denne uge)
channel-type.wundergroundupdatereceiver.rain-monthly.description=Regnmængde siden starten af måneden
channel-type.wundergroundupdatereceiver.rain-monthly.label=Regn (denne måned)
channel-type.wundergroundupdatereceiver.rain-yearly.description=Regnmængde siden starten af året
channel-type.wundergroundupdatereceiver.rain-yearly.label=Regn (i år)
channel-type.wundergroundupdatereceiver.metar.description=Vejrmelding i METAR format
channel-type.wundergroundupdatereceiver.metar.label=METAR vejrmelding
channel-type.wundergroundupdatereceiver.clouds.description=Skydække
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<channel id="last-received" typeId="last-received-datetime"/>
<channel id="dateutc" typeId="datetime-utc"/>
<channel id="softwaretype" typeId="softwaretype"/>
<channel id="rtfreq" typeId="realtime-frequency"/>
<channel id="lowbatt" typeId="system.low-battery"/>
<channel id="last-query-state" typeId="last-query-state"/>
<channel id="last-query-trigger" typeId="last-query-trigger"/>
</channels>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,14 @@
<state readOnly="true"/>
</channel-type>

<channel-type id="realtime-frequency" advanced="true">
<item-type>Number</item-type>
<label>Realtime Frequency</label>
<description>How often does the weather station submit measurements</description>
<category>Number</category>
<state readOnly="true" pattern="%.0f"/>
</channel-type>

<channel-type id="last-query-state" advanced="true">
<item-type>String</item-type>
<kind>state</kind>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.mockito.Mock;
import org.openhab.core.config.core.Configuration;
import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.ImperialUnits;
Expand Down Expand Up @@ -164,13 +165,21 @@ void a_get_request_is_correctly_parsed() throws IOException {
// Given
ThingUID testThingUID = new ThingUID(WundergroundUpdateReceiverBindingConstants.THING_TYPE_UPDATE_RECEIVER,
"test-receiver");
final String queryString = "ID=dfggger&PASSWORD=XXXXXX&tempf=26.1&humidity=74&dewptf=18.9&windchillf=26.1&winddir=14&windspeedmph=1.34&windgustmph=2.46&rainin=0.00&dailyrainin=0.00&weeklyrainin=0.00&monthlyrainin=0.08&yearlyrainin=3.06&solarradiation=42.24&UV=1&indoortempf=69.3&indoorhumidity=32&baromin=30.39&AqNOX=21&dateutc=2021-02-07%2014:04:03&softwaretype=WH2600%20V2.2.8&action=updateraw&realtime=1&rtfreq=5";
final String queryString = "ID=dfggger&PASSWORD=XXXXXX&tempf=26.1&humidity=74&dewptf=18.9&windchillf=26.1&winddir=14&windspeedmph=1.34&windgustmph=2.46&rainin=0.00&dailyrainin=0.00&weeklyrainin=0.00&monthlyrainin=0.08&yearlyrainin=3.06&solarradiation=42.24&UV=1&indoortempf=69.3&indoorhumidity=32&baromin=30.39&AqNOX=21&lowbatt=1&dateutc=2021-02-07%2014:04:03&softwaretype=WH2600%20V2.2.8&action=updateraw&realtime=1&rtfreq=5";
WundergroundUpdateReceiverServlet sut = new WundergroundUpdateReceiverServlet(httpService);
List<Channel> channels = List.of(
ChannelBuilder
.create(new ChannelUID(testThingUID, "metadata",
WundergroundUpdateReceiverBindingConstants.DATEUTC), "String")
.withKind(ChannelKind.STATE).build(),
ChannelBuilder
.create(new ChannelUID(testThingUID, "metadata",
WundergroundUpdateReceiverBindingConstants.REALTIME_FREQUENCY), "Number")
.withKind(ChannelKind.STATE).build(),
ChannelBuilder
.create(new ChannelUID(testThingUID, "metadata",
WundergroundUpdateReceiverBindingConstants.LOW_BATTERY), "Switch")
.withKind(ChannelKind.STATE).build(),
ChannelBuilder
.create(new ChannelUID(testThingUID, "wind",
WundergroundUpdateReceiverBindingConstants.WIND_DIRECTION), "Number:Angle")
Expand Down Expand Up @@ -243,6 +252,12 @@ void a_get_request_is_correctly_parsed() throws IOException {
verify(callback).stateUpdated(
new ChannelUID(testThindUid, "metadata", WundergroundUpdateReceiverBindingConstants.DATEUTC),
StringType.valueOf("2021-02-07 14:04:03"));
verify(callback).stateUpdated(
new ChannelUID(testThindUid, "metadata", WundergroundUpdateReceiverBindingConstants.LOW_BATTERY),
OnOffType.ON);
verify(callback).stateUpdated(
new ChannelUID(testThindUid, "metadata", WundergroundUpdateReceiverBindingConstants.REALTIME_FREQUENCY),
new DecimalType(5));
verify(callback).stateUpdated(
new ChannelUID(testThindUid, "wind", WundergroundUpdateReceiverBindingConstants.WIND_DIRECTION),
new QuantityType<>(14, Units.DEGREE_ANGLE));
Expand Down

0 comments on commit 0421ec4

Please sign in to comment.