79
79
Change Log
80
80
==========
81
81
82
+ * 23/11/20: Added support for day of the week in the current local language
82
83
* 01/11/19: Corrected an issue where the Items were not linking.
83
84
* 01/12/19: Removed Forecast_Temperature_X, and added
84
85
Forecast_Temperature_High_X and Forecast_Temperature_Low_X
105
106
* -6/14/20: Only check for SCALE transformation service if using Linux OS
106
107
* 06/14/20: Using System properties for HTTP/HTTPS ports, rather than hard coded 8080/8443
107
108
"""
109
+ from __future__ import unicode_literals
108
110
from core .log import logging , LOG_PREFIX , log_traceback
111
+ from core .actions import Transformation
109
112
110
113
111
114
@log_traceback
@@ -128,6 +131,32 @@ def remove_owm_items():
128
131
129
132
#remove_owm_items()
130
133
134
+ @log_traceback
135
+ def current_lang ():
136
+ """
137
+ Determines the current language of the openhab.
138
+ You need to assure you have setup JAVA_OPTS in the start.sh to your preferred language and country, e.g.
139
+ EXTRA_JAVA_OPTS="-Duser.language=pl -Duser.country=PL"
140
+ """
141
+ default_locale = locale .getdefaultlocale ()[0 ]
142
+ if default_locale :
143
+ return default_locale if "_" not in default_locale else default_locale .split ("_" )[0 ]
144
+ return "en"
145
+
146
+ @log_traceback
147
+ def map_day_of_week (index , last_reading ):
148
+ """
149
+ Method calculates the day index and maps into the day of the week for the current language
150
+
151
+ Args:
152
+ index: Forecast group id
153
+ last_reading: Forecast group id of the last reading
154
+
155
+ Returns:
156
+ str: A name of the day in the week for current language
157
+ """
158
+ day_week_idx = "TODAY" if index == 1 else str ((last_reading + index - 1 ) % 7 )
159
+ return Transformation .transform ("MAP" , "weather-{}.map" .format (current_lang ()), day_week_idx ) or u"UNKNOWN"
131
160
132
161
def add_owm_items ():
133
162
add_owm_items .log = logging .getLogger ("{}.add_owm_items" .format (LOG_PREFIX ))
@@ -266,11 +295,10 @@ def add_owm_items():
266
295
add_link ("Current_SnowVolume" , ChannelUID (owm_thing_uid + ":current#snow" ))
267
296
268
297
# create Forecast groups
269
- import calendar
270
298
from org .joda .time import DateTime
271
299
last_reading = DateTime (str (items ["Current_Timestamp" ])).getDayOfWeek () - 1
272
300
for index in range (1 , 6 ):
273
- day_of_the_week = "Today" if index == 1 else calendar . day_name [( last_reading + index - 1 ) % 7 ]
301
+ day_of_the_week = map_day_of_week ( index , last_reading )
274
302
if itemRegistry .getItems ("gForecast_" + str (index )) == []:
275
303
add_item ("gForecast_" + str (index ), item_type = "Group" , groups = ["gOpenWeatherMap" ], label = day_of_the_week , tags = ["OpenWeatherMap" ])
276
304
if itemRegistry .getItems ("gForecast_Timestamp_" + str (index )) == []:
@@ -392,10 +420,9 @@ def add_owm_items_to_groups(event):
392
420
393
421
# update group labels to reflect week day
394
422
from org .joda .time import DateTime
395
- import calendar
396
423
last_reading = DateTime (str (items ["Current_Timestamp" ])).getDayOfWeek () - 1
397
424
for index in range (1 , 6 ):
398
- day_of_the_week = "Today" if index == 1 else calendar . day_name [( last_reading + index - 1 ) % 7 ]
425
+ day_of_the_week = map_day_of_week ( index , last_reading )
399
426
itemRegistry .getItem ("gForecast_" + str (index )).setLabel (day_of_the_week )
400
427
itemRegistry .getItem ("gForecast_Timestamp_" + str (index )).setLabel (day_of_the_week + ": Timestamp" )
401
428
itemRegistry .getItem ("gForecast_Condition_" + str (index )).setLabel (day_of_the_week + ": Condition [%s]" )
0 commit comments