Skip to content

Commit

Permalink
Merge pull request #985 from onkelandy/openweather
Browse files Browse the repository at this point in the history
Openweathermap: improve beaufort handling
  • Loading branch information
Morg42 authored Dec 20, 2024
2 parents cad42b6 + 8b1ee10 commit e321dc1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
17 changes: 16 additions & 1 deletion openweathermap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, *args: object) -> None:


class OpenWeatherMap(SmartPlugin):
PLUGIN_VERSION = "1.8.7"
PLUGIN_VERSION = "1.8.8"

_base_url = 'https://api.openweathermap.org/'
_base_img_url = 'https://tile.openweathermap.org/map/%s/%s/%s/%s.png?appid=%s'
Expand Down Expand Up @@ -396,6 +396,21 @@ def get_value_with_meta(self, owm_matchstring, correlation_hint=""):
else:
raise Exception(f"Cannot make sense of {s}")
s = updated_s
elif (s.startswith("current/") or s.startswith("daily/") or s.startswith("day/") or s.startswith("hour/")) and (s.endswith('/wind_gust/beaufort') or s.endswith('/wind_gust/description')):
wrk_typ = "onecall [bft-calculation]"
mps_string = s.replace('/wind_gust/beaufort', '/wind_gust')
mps_string = mps_string.replace(
'/wind_gust/description', '/wind_gust')
wind_mps, updated_s = self.__get_val_from_dict(
mps_string, wrk, correlation_hint, owm_matchstring)
bft_val = self.get_beaufort_number(wind_mps)
if s.endswith('/beaufort'):
ret_val = bft_val
elif s.endswith('/description'):
ret_val = self.get_beaufort_description(bft_val)
else:
raise Exception(f"Cannot make sense of {s}")
s = updated_s
else:
ret_val, s = self.__get_val_from_dict(s, wrk, correlation_hint, owm_matchstring)
except Exception as e:
Expand Down
24 changes: 9 additions & 15 deletions openweathermap/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugin:
keywords: weather precipation irrigation
documentation: ''
support: 'https://knx-user-forum.de/forum/supportforen/smarthome-py/1246998-support-thread-zum-openweathermap-plugin'
version: 1.8.7 # Plugin version
version: 1.8.8 # Plugin version
sh_minversion: '1.9.0' # minimum shNG version to use this plugin
# sh_maxversion: # maximum shNG version to use this plugin (leave empty if latest)
multi_instance: True # plugin supports multi instance
Expand Down Expand Up @@ -450,12 +450,12 @@ item_structs:
beaufort_nr:
name: wind speed as beaufort number
type: num
owm_matchstring: current/wind_speed/beaufort
owm_matchstring@instance: current/wind_speed/beaufort

beaufort_string:
name: wind speed as beaufort string
type: str
owm_matchstring: current/wind_speed/description
owm_matchstring@instance: current/wind_speed/description

wind_gust:
name: (where available) Wind gust. Units default metre/sec, metric metre/sec, imperial miles/hour.
Expand All @@ -465,14 +465,12 @@ item_structs:
beaufort_nr:
name: wind gusts as beaufort number
type: num
eval: sh.plugins.get('openweathermap').get_beaufort_number(sh....wind_gust())
eval_trigger: ...wind_gust
owm_matchstring@instance: current/wind_gust/beaufort

beaufort_string:
name: wind gusts as beaufort string
type: str
eval: sh.plugins.get('openweathermap').get_beaufort_description( sh...beaufort_nr() )
eval_trigger: ..beaufort_nr
owm_matchstring@instance: current/wind_gust/description

wind_deg:
name: Wind direction, degrees (meteorological)
Expand Down Expand Up @@ -630,13 +628,11 @@ item_structs:
beaufort_nr:
name: wind speed as beaufort number
type: num
eval: sh.plugins.get('openweathermap').get_beaufort_number(sh...())
eval_trigger: ..
owm_matchstring@instance: current/wind_speed/beaufort
beaufort_string:
name: wind speed as beaufort string
type: str
eval: sh.plugins.get('openweathermap').get_beaufort_description( sh...beaufort_nr() )
eval_trigger: ..beaufort_nr
owm_matchstring@instance: current/wind_speed/description

wind_gust:
name: (where available) Wind gust. Units default metre/sec, metric metre/sec, imperial miles/hour.
Expand All @@ -646,13 +642,11 @@ item_structs:
beaufort_nr:
name: wind gusts as beaufort number
type: num
eval: sh.plugins.get('openweathermap').get_beaufort_number(sh...())
eval_trigger: ..
owm_matchstring@instance: current/wind_gust/beaufort
beaufort_string:
name: wind gusts as beaufort string
type: str
eval: sh.plugins.get('openweathermap').get_beaufort_description( sh...beaufort_nr() )
eval_trigger: ..beaufort_nr
owm_matchstring@instance: current/wind_gust/description

wind_deg:
name: Wind direction, degrees (meteorological)
Expand Down

0 comments on commit e321dc1

Please sign in to comment.