Skip to content

Commit

Permalink
openweathermap: move beaufort calculation from struct to plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Dec 13, 2024
1 parent 1b0c89a commit 8b1ee10
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
15 changes: 15 additions & 0 deletions openweathermap/__init__.py
Original file line number Diff line number Diff line change
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
22 changes: 8 additions & 14 deletions openweathermap/plugin.yaml
Original file line number Diff line number Diff line change
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.return_plugin('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.return_plugin('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.return_plugin('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.return_plugin('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.return_plugin('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.return_plugin('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 8b1ee10

Please sign in to comment.