Skip to content

Commit 372058c

Browse files
authored
[openweathermap] Add daily moon channels to OneCall Thing (openhab#16350)
* [openweathermap] Add daily moon channels to OneCall Thing This adds the daily moon data provided by the API (https://openweathermap.org/api/one-call-api#parameter) to the OneCall Thing. Also-by: Florian Hotze <[email protected]> Signed-off-by: Erik De Boeck <[email protected]>
1 parent 448466f commit 372058c

File tree

8 files changed

+118
-32
lines changed

8 files changed

+118
-32
lines changed

bundles/org.openhab.binding.openweathermap/README.md

+35-31
Large diffs are not rendered by default.

bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/OpenWeatherMapBindingConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ public class OpenWeatherMapBindingConstants {
8383
public static final String CHANNEL_TIME_STAMP = "time-stamp";
8484
public static final String CHANNEL_SUNRISE = "sunrise";
8585
public static final String CHANNEL_SUNSET = "sunset";
86+
public static final String CHANNEL_MOONRISE = "moonrise";
87+
public static final String CHANNEL_MOONSET = "moonset";
88+
public static final String CHANNEL_MOON_PHASE = "moon-phase";
8689
public static final String CHANNEL_CONDITION = "condition";
8790
public static final String CHANNEL_CONDITION_ID = "condition-id";
8891
public static final String CHANNEL_CONDITION_ICON = "icon";

bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/dto/onecall/Daily.java

+16
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class Daily {
2828
private int dt;
2929
private int sunrise;
3030
private int sunset;
31+
private int moonrise;
32+
private int moonset;
33+
@SerializedName("moon_phase")
34+
private double moonPhase;
3135
private Temp temp;
3236
@SerializedName("feels_like")
3337
private FeelsLikeTemp feelsLikeTemp;
@@ -61,6 +65,18 @@ public int getSunset() {
6165
return sunset;
6266
}
6367

68+
public int getMoonrise() {
69+
return moonrise;
70+
}
71+
72+
public int getMoonset() {
73+
return moonset;
74+
}
75+
76+
public double getMoonPhase() {
77+
return moonPhase;
78+
}
79+
6480
public Temp getTemp() {
6581
return temp;
6682
}

bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java

+9
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,15 @@ private State getDailyForecastState(String channelId, Daily forecastData,
666666
case CHANNEL_SUNSET:
667667
state = getDateTimeTypeState(forecastData.getSunset());
668668
break;
669+
case CHANNEL_MOONRISE:
670+
state = getDateTimeTypeState(forecastData.getMoonrise());
671+
break;
672+
case CHANNEL_MOONSET:
673+
state = getDateTimeTypeState(forecastData.getMoonset());
674+
break;
675+
case CHANNEL_MOON_PHASE:
676+
state = getDecimalTypeState(forecastData.getMoonPhase());
677+
break;
669678
case CHANNEL_CONDITION:
670679
if (!forecastData.getWeather().isEmpty()) {
671680
state = getStringTypeState(forecastData.getWeather().get(0).getDescription());

bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/i18n/openweathermap.properties

+8
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,14 @@ channel-type.openweathermap.gust-speed.description = Current gust speed.
287287
channel-type.openweathermap.hourly-forecast-time-stamp.label = Forecast Time
288288
channel-type.openweathermap.hourly-forecast-time-stamp.description = Time of data forecasted.
289289
channel-type.openweathermap.hourly-forecast-time-stamp.state.pattern = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
290+
channel-type.openweathermap.moon-phase.label = Moon Phase
291+
channel-type.openweathermap.moon-phase.description = Moon phase for the given day. 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon' and 0.75 is 'last quarter moon'. The periods in between are called 'waxing crescent', 'waxing gibous', 'waning gibous', and 'waning crescent', respectively.
292+
channel-type.openweathermap.moonrise.label = Moonrise Time
293+
channel-type.openweathermap.moonrise.description = Time of moonrise for the given day.
294+
channel-type.openweathermap.moonrise.state.pattern = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
295+
channel-type.openweathermap.moonset.label = Moonset Time
296+
channel-type.openweathermap.moonset.description = Time of moonset for the given day.
297+
channel-type.openweathermap.moonset.state.pattern = %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS
290298
channel-type.openweathermap.morning-temperature.label = Morning Temperature
291299
channel-type.openweathermap.morning-temperature.description = Forecasted outdoor temperature for the morning.
292300
channel-type.openweathermap.night-temperature.label = Night Temperature

bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/thing/channel-types.xml

+32
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@
223223
<channels>
224224
<channel id="sunrise" typeId="sunrise"/>
225225
<channel id="sunset" typeId="sunset"/>
226+
<channel id="moonrise" typeId="moonrise"/>
227+
<channel id="moonset" typeId="moonset"/>
228+
<channel id="moon-phase" typeId="moon-phase"/>
226229
<channel id="condition" typeId="condition"/>
227230
<channel id="condition-id" typeId="condition-id"/>
228231
<channel id="icon" typeId="condition-icon"/>
@@ -258,6 +261,9 @@
258261
<channel id="time-stamp" typeId="daily-forecast-time-stamp"/>
259262
<channel id="sunrise" typeId="sunrise"/>
260263
<channel id="sunset" typeId="sunset"/>
264+
<channel id="moonrise" typeId="moonrise"/>
265+
<channel id="moonset" typeId="moonset"/>
266+
<channel id="moon-phase" typeId="moon-phase"/>
261267
<channel id="condition" typeId="condition"/>
262268
<channel id="condition-id" typeId="condition-id"/>
263269
<channel id="icon" typeId="condition-icon"/>
@@ -389,6 +395,32 @@
389395
<state readOnly="true" pattern="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"/>
390396
</channel-type>
391397

398+
<channel-type id="moonrise">
399+
<item-type>DateTime</item-type>
400+
<label>Moonrise Time</label>
401+
<description>Time of moonrise for the given day.</description>
402+
<category>Time</category>
403+
<state readOnly="true" pattern="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"/>
404+
</channel-type>
405+
406+
<channel-type id="moonset">
407+
<item-type>DateTime</item-type>
408+
<label>Moonset Time</label>
409+
<description>Time of moonset for the given day.</description>
410+
<category>Time</category>
411+
<state readOnly="true" pattern="%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"/>
412+
</channel-type>
413+
414+
<channel-type id="moon-phase">
415+
<item-type>Number</item-type>
416+
<label>Moon Phase</label>
417+
<description>Moon phase for the given day. 0 and 1 are 'new moon', 0.25 is 'first quarter moon', 0.5 is 'full moon'
418+
and 0.75 is 'last quarter moon'. The periods in between are called 'waxing crescent', 'waxing gibous', 'waning
419+
gibous', and 'waning crescent', respectively.</description>
420+
<category>Moon</category>
421+
<state readOnly="true" pattern="%.2f"/>
422+
</channel-type>
423+
392424
<channel-type id="hourly-forecast-time-stamp">
393425
<item-type>DateTime</item-type>
394426
<label>Forecast Time</label>

bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/thing/thing-types.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238
</channel-groups>
239239

240240
<properties>
241-
<property name="thingTypeVersion">1</property>
241+
<property name="thingTypeVersion">2</property>
242242
</properties>
243243
<representation-property>location</representation-property>
244244

bundles/org.openhab.binding.openweathermap/src/main/resources/OH-INF/update/instructions.xml

+14
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,20 @@
143143
<type>openweathermap:snow</type>
144144
</add-channel>
145145
</instruction-set>
146+
<instruction-set targetVersion="2">
147+
<add-channel id="moonrise"
148+
groupIds="forecastDaily,forecastToday,forecastTomorrow,forecastDay2,forecastDay3,forecastDay4,forecastDay5,forecastDay6,forecastDay7">
149+
<type>openweathermap:moonrise</type>
150+
</add-channel>
151+
<add-channel id="moonset"
152+
groupIds="forecastDaily,forecastToday,forecastTomorrow,forecastDay2,forecastDay3,forecastDay4,forecastDay5,forecastDay6,forecastDay7">
153+
<type>openweathermap:moonset</type>
154+
</add-channel>
155+
<add-channel id="moon-phase"
156+
groupIds="forecastDaily,forecastToday,forecastTomorrow,forecastDay2,forecastDay3,forecastDay4,forecastDay5,forecastDay6,forecastDay7">
157+
<type>openweathermap:moon-phase</type>
158+
</add-channel>
159+
</instruction-set>
146160
</thing-type>
147161

148162
</update:update-descriptions>

0 commit comments

Comments
 (0)