mirror of
https://github.com/powerline/powerline.git
synced 2025-07-31 01:35:40 +02:00
Merge 96d4a5e2c01fc63eb431ec804676221b211bbdac into 574bb1887b9f27b3c046c6b74a1f3ed75b115a75
This commit is contained in:
commit
2a465e5217
@ -2,6 +2,7 @@
|
|||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
from powerline.lib.url import urllib_read, urllib_urlencode
|
from powerline.lib.url import urllib_read, urllib_urlencode
|
||||||
@ -16,85 +17,45 @@ _WeatherKey = namedtuple('Key', 'location_query weather_api_key')
|
|||||||
# segment is imported into powerline.segments.common module.
|
# segment is imported into powerline.segments.common module.
|
||||||
|
|
||||||
|
|
||||||
# Weather condition code descriptions available at
|
# Weather condition categories available at
|
||||||
# https://openweathermap.org/weather-conditions
|
# https://openweathermap.org/weather-conditions
|
||||||
weather_conditions_codes = {
|
|
||||||
200: ('stormy',),
|
|
||||||
201: ('stormy',),
|
|
||||||
202: ('stormy',),
|
|
||||||
210: ('stormy',),
|
|
||||||
211: ('stormy',),
|
|
||||||
212: ('stormy',),
|
|
||||||
221: ('stormy',),
|
|
||||||
230: ('stormy',),
|
|
||||||
231: ('stormy',),
|
|
||||||
232: ('stormy',),
|
|
||||||
300: ('rainy',),
|
|
||||||
301: ('rainy',),
|
|
||||||
302: ('rainy',),
|
|
||||||
310: ('rainy',),
|
|
||||||
311: ('rainy',),
|
|
||||||
312: ('rainy',),
|
|
||||||
313: ('rainy',),
|
|
||||||
314: ('rainy',),
|
|
||||||
321: ('rainy',),
|
|
||||||
500: ('rainy',),
|
|
||||||
501: ('rainy',),
|
|
||||||
502: ('rainy',),
|
|
||||||
503: ('rainy',),
|
|
||||||
504: ('rainy',),
|
|
||||||
511: ('snowy',),
|
|
||||||
520: ('rainy',),
|
|
||||||
521: ('rainy',),
|
|
||||||
522: ('rainy',),
|
|
||||||
531: ('rainy',),
|
|
||||||
600: ('snowy',),
|
|
||||||
601: ('snowy',),
|
|
||||||
602: ('snowy',),
|
|
||||||
611: ('snowy',),
|
|
||||||
612: ('snowy',),
|
|
||||||
613: ('snowy',),
|
|
||||||
615: ('snowy',),
|
|
||||||
616: ('snowy',),
|
|
||||||
620: ('snowy',),
|
|
||||||
621: ('snowy',),
|
|
||||||
622: ('snowy',),
|
|
||||||
701: ('foggy',),
|
|
||||||
711: ('foggy',),
|
|
||||||
721: ('foggy',),
|
|
||||||
731: ('foggy',),
|
|
||||||
741: ('foggy',),
|
|
||||||
751: ('foggy',),
|
|
||||||
761: ('foggy',),
|
|
||||||
762: ('foggy',),
|
|
||||||
771: ('foggy',),
|
|
||||||
781: ('foggy',),
|
|
||||||
800: ('sunny',),
|
|
||||||
801: ('cloudy',),
|
|
||||||
802: ('cloudy',),
|
|
||||||
803: ('cloudy',),
|
|
||||||
804: ('cloudy',),
|
|
||||||
}
|
|
||||||
|
|
||||||
weather_conditions_icons = {
|
weather_conditions_icons = {
|
||||||
'day': 'DAY',
|
# group 2xx: thunderstorm
|
||||||
'blustery': 'WIND',
|
'thunderstorm': 'STORM',
|
||||||
'rainy': 'RAIN',
|
|
||||||
'cloudy': 'CLOUDS',
|
# group 3xx: drizzle
|
||||||
'snowy': 'SNOW',
|
'drizzle': 'RAIN',
|
||||||
'stormy': 'STORM',
|
|
||||||
'foggy': 'FOG',
|
# group 5xx: rain
|
||||||
'sunny': 'SUN',
|
'rain': 'RAIN',
|
||||||
'night': 'NIGHT',
|
|
||||||
'windy': 'WINDY',
|
# group 6xx: snow
|
||||||
'not_available': 'NA',
|
'snow': 'SNOW',
|
||||||
'unknown': 'UKN',
|
|
||||||
|
# group 7xx: atmosphere
|
||||||
|
'ash': 'FOG',
|
||||||
|
'dust': 'FOG',
|
||||||
|
'fog': 'FOG',
|
||||||
|
'haze': 'FOG',
|
||||||
|
'mist': 'FOG',
|
||||||
|
'sand': 'FOG',
|
||||||
|
'smoke': 'FOG',
|
||||||
|
'squall': 'FOG',
|
||||||
|
'tornado': 'TORNADO',
|
||||||
|
|
||||||
|
# group 800: clear
|
||||||
|
'clear': 'CLEAR',
|
||||||
|
|
||||||
|
#group 80x: clouds
|
||||||
|
'clouds': 'CLOUDS',
|
||||||
|
|
||||||
|
'unknown': 'UKN',
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_conversions = {
|
temp_conversions = {
|
||||||
'C': lambda temp: temp - 273.15,
|
'C': lambda temp: temp,
|
||||||
'F': lambda temp: (temp * 9 / 5) - 459.67,
|
'F': lambda temp: (temp * 9 / 5) + 32,
|
||||||
'K': lambda temp: temp,
|
'K': lambda temp: temp + 273.15,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Note: there are also unicode characters for units: ℃, ℉ and K
|
# Note: there are also unicode characters for units: ℃, ℉ and K
|
||||||
@ -124,7 +85,8 @@ class WeatherSegment(KwThreadedSegment):
|
|||||||
return self.location_urls[weather_key]
|
return self.location_urls[weather_key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
query_data = {
|
query_data = {
|
||||||
"appid": weather_key.weather_api_key
|
"appid": weather_key.weather_api_key,
|
||||||
|
"units": "metric",
|
||||||
}
|
}
|
||||||
location_query = weather_key.location_query
|
location_query = weather_key.location_query
|
||||||
if location_query is None:
|
if location_query is None:
|
||||||
@ -147,22 +109,23 @@ class WeatherSegment(KwThreadedSegment):
|
|||||||
|
|
||||||
response = json.loads(raw_response)
|
response = json.loads(raw_response)
|
||||||
try:
|
try:
|
||||||
condition = response['weather'][0]
|
weather = response['weather'][0]
|
||||||
condition_code = int(condition['id'])
|
condition = weather['main'].lower()
|
||||||
|
desc = re.sub(r'[^A-Za-z0-9]+', '_', weather['description'])
|
||||||
temp = float(response['main']['temp'])
|
temp = float(response['main']['temp'])
|
||||||
except (KeyError, ValueError):
|
except (KeyError, ValueError):
|
||||||
self.exception('OpenWeatherMap returned malformed or unexpected response: {0}', repr(raw_response))
|
self.exception('OpenWeatherMap returned malformed or unexpected response: {0}', repr(raw_response))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
icon_names = weather_conditions_codes[condition_code]
|
icon_names = (desc, condition)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
icon_names = ('unknown',)
|
icon_names = ('unknown',)
|
||||||
self.error('Unknown condition code: {0}', condition_code)
|
self.error('Unknown condition code: {0}', condition_code)
|
||||||
|
|
||||||
return (temp, icon_names)
|
return (temp, icon_names)
|
||||||
|
|
||||||
def render_one(self, weather, icons=None, unit='C', temp_format=None, temp_coldest=-30, temp_hottest=40, **kwargs):
|
def render_one(self, weather, icons=None, unit='C', temp_format=None, temp_coldest=None, temp_hottest=None, **kwargs):
|
||||||
if not weather:
|
if not weather:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -178,6 +141,10 @@ class WeatherSegment(KwThreadedSegment):
|
|||||||
|
|
||||||
temp_format = temp_format or ('{temp:.0f}' + temp_units[unit])
|
temp_format = temp_format or ('{temp:.0f}' + temp_units[unit])
|
||||||
converted_temp = temp_conversions[unit](temp)
|
converted_temp = temp_conversions[unit](temp)
|
||||||
|
if not temp_coldest:
|
||||||
|
temp_coldest = temp_conversions[unit](-30)
|
||||||
|
if not temp_hottest:
|
||||||
|
temp_hottest = temp_conversions[unit](40)
|
||||||
if converted_temp <= temp_coldest:
|
if converted_temp <= temp_coldest:
|
||||||
gradient_level = 0
|
gradient_level = 0
|
||||||
elif converted_temp >= temp_hottest:
|
elif converted_temp >= temp_hottest:
|
||||||
@ -207,6 +174,13 @@ Uses GeoIP lookup from https://freegeoip.app to automatically determine
|
|||||||
your current location. This should be changed if you’re in a VPN or if your
|
your current location. This should be changed if you’re in a VPN or if your
|
||||||
IP address is registered at another location.
|
IP address is registered at another location.
|
||||||
|
|
||||||
|
Icons can be overridden with a dict (see below). Names for the icons can be
|
||||||
|
either the main category name or the description with any non-alphanumeric
|
||||||
|
characters replaced with ``_``. Names should be lowercase.
|
||||||
|
|
||||||
|
See https://openweathermap.org/weather-conditions for weather condition
|
||||||
|
categories and descriptions.
|
||||||
|
|
||||||
Returns a list of colorized icon and temperature segments depending on
|
Returns a list of colorized icon and temperature segments depending on
|
||||||
weather conditions.
|
weather conditions.
|
||||||
|
|
||||||
|
@ -49,16 +49,11 @@ def urllib_read(query_url):
|
|||||||
return '{"ip":"82.145.55.16","country_code":"DE","country_name":"Germany","region_code":"NI","region_name":"Lower Saxony","city":"Meppen","zip_code":"49716","time_zone":"Europe/Berlin","latitude":52.6833,"longitude":7.3167,"metro_code":0}'
|
return '{"ip":"82.145.55.16","country_code":"DE","country_name":"Germany","region_code":"NI","region_name":"Lower Saxony","city":"Meppen","zip_code":"49716","time_zone":"Europe/Berlin","latitude":52.6833,"longitude":7.3167,"metro_code":0}'
|
||||||
elif query_url.startswith('http://geoip.nekudo.com/api/'):
|
elif query_url.startswith('http://geoip.nekudo.com/api/'):
|
||||||
return r'{"city":"Meppen","country":{"name":"Germany", "code":"DE"},"location":{"accuracy_radius":100,"latitude":52.6833,"longitude":7.3167,"time_zone":"Europe\/Berlin"},"ip":"82.145.55.16"}'
|
return r'{"city":"Meppen","country":{"name":"Germany", "code":"DE"},"location":{"accuracy_radius":100,"latitude":52.6833,"longitude":7.3167,"time_zone":"Europe\/Berlin"},"ip":"82.145.55.16"}'
|
||||||
elif query_url.startswith('http://query.yahooapis.com/v1/public/'):
|
|
||||||
if 'Meppen' in query_url or '52.6833' in query_url:
|
|
||||||
return r'{"query":{"count":1,"created":"2016-05-13T19:43:18Z","lang":"en-US","results":{"channel":{"units":{"distance":"mi","pressure":"in","speed":"mph","temperature":"C"},"title":"Yahoo! Weather - Meppen, NI, DE","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-674836/","description":"Yahoo! Weather for Meppen, NI, DE","language":"en-us","lastBuildDate":"Fri, 13 May 2016 09:43 PM CEST","ttl":"60","location":{"city":"Meppen","country":"Germany","region":" NI"},"wind":{"chill":"55","direction":"350","speed":"25"},"atmosphere":{"humidity":"57","pressure":"1004.0","rising":"0","visibility":"16.1"},"astronomy":{"sunrise":"5:35 am","sunset":"9:21 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Meppen, NI, DE at 08:00 PM CEST","lat":"52.68993","long":"7.29115","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-674836/","pubDate":"Fri, 13 May 2016 08:00 PM CEST","condition":{"code":"23","date":"Fri, 13 May 2016 08:00 PM CEST","temp":"14","text":"Breezy"},"forecast":[{"code":"30","date":"13 May 2016","day":"Fri","high":"71","low":"48","text":"Partly Cloudy"},{"code":"28","date":"14 May 2016","day":"Sat","high":"54","low":"44","text":"Mostly Cloudy"},{"code":"11","date":"15 May 2016","day":"Sun","high":"55","low":"43","text":"Showers"},{"code":"28","date":"16 May 2016","day":"Mon","high":"54","low":"42","text":"Mostly Cloudy"},{"code":"28","date":"17 May 2016","day":"Tue","high":"57","low":"43","text":"Mostly Cloudy"},{"code":"12","date":"18 May 2016","day":"Wed","high":"62","low":"45","text":"Rain"},{"code":"28","date":"19 May 2016","day":"Thu","high":"63","low":"48","text":"Mostly Cloudy"},{"code":"28","date":"20 May 2016","day":"Fri","high":"67","low":"50","text":"Mostly Cloudy"},{"code":"30","date":"21 May 2016","day":"Sat","high":"71","low":"50","text":"Partly Cloudy"},{"code":"30","date":"22 May 2016","day":"Sun","high":"74","low":"54","text":"Partly Cloudy"}],"description":"<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/23.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Breezy\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Fri - Partly Cloudy. High: 71Low: 48\n<BR /> Sat - Mostly Cloudy. High: 54Low: 44\n<BR /> Sun - Showers. High: 55Low: 43\n<BR /> Mon - Mostly Cloudy. High: 54Low: 42\n<BR /> Tue - Mostly Cloudy. High: 57Low: 43\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-674836/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)\n<BR />\n]]>","guid":{"isPermaLink":"false"}}}}}}'
|
|
||||||
elif 'Moscow' in query_url:
|
|
||||||
return r'{"query":{"count":1,"created":"2016-05-13T19:47:01Z","lang":"en-US","results":{"channel":{"units":{"distance":"mi","pressure":"in","speed":"mph","temperature":"C"},"title":"Yahoo! Weather - Moscow, Moscow Federal City, RU","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2122265/","description":"Yahoo! Weather for Moscow, Moscow Federal City, RU","language":"en-us","lastBuildDate":"Fri, 13 May 2016 10:47 PM MSK","ttl":"60","location":{"city":"Moscow","country":"Russia","region":" Moscow Federal City"},"wind":{"chill":"45","direction":"80","speed":"11"},"atmosphere":{"humidity":"52","pressure":"993.0","rising":"0","visibility":"16.1"},"astronomy":{"sunrise":"4:19 am","sunset":"8:34 pm"},"image":{"title":"Yahoo! Weather","width":"142","height":"18","link":"http://weather.yahoo.com","url":"http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif"},"item":{"title":"Conditions for Moscow, Moscow Federal City, RU at 09:00 PM MSK","lat":"55.741638","long":"37.605061","link":"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2122265/","pubDate":"Fri, 13 May 2016 09:00 PM MSK","condition":{"code":"33","date":"Fri, 13 May 2016 09:00 PM MSK","temp":"9","text":"Mostly Clear"},"forecast":[{"code":"30","date":"13 May 2016","day":"Fri","high":"62","low":"41","text":"Partly Cloudy"},{"code":"30","date":"14 May 2016","day":"Sat","high":"64","low":"43","text":"Partly Cloudy"},{"code":"30","date":"15 May 2016","day":"Sun","high":"63","low":"44","text":"Partly Cloudy"},{"code":"12","date":"16 May 2016","day":"Mon","high":"60","low":"47","text":"Rain"},{"code":"12","date":"17 May 2016","day":"Tue","high":"64","low":"48","text":"Rain"},{"code":"28","date":"18 May 2016","day":"Wed","high":"67","low":"48","text":"Mostly Cloudy"},{"code":"12","date":"19 May 2016","day":"Thu","high":"68","low":"49","text":"Rain"},{"code":"39","date":"20 May 2016","day":"Fri","high":"66","low":"50","text":"Scattered Showers"},{"code":"39","date":"21 May 2016","day":"Sat","high":"69","low":"49","text":"Scattered Showers"},{"code":"30","date":"22 May 2016","day":"Sun","high":"73","low":"50","text":"Partly Cloudy"}],"description":"<![CDATA[<img src=\"http://l.yimg.com/a/i/us/we/52/33.gif\"/>\n<BR />\n<b>Current Conditions:</b>\n<BR />Mostly Clear\n<BR />\n<BR />\n<b>Forecast:</b>\n<BR /> Fri - Partly Cloudy. High: 62Low: 41\n<BR /> Sat - Partly Cloudy. High: 64Low: 43\n<BR /> Sun - Partly Cloudy. High: 63Low: 44\n<BR /> Mon - Rain. High: 60Low: 47\n<BR /> Tue - Rain. High: 64Low: 48\n<BR />\n<BR />\n<a href=\"http://us.rd.yahoo.com/dailynews/rss/weather/Country__Country/*https://weather.yahoo.com/country/state/city-2122265/\">Full Forecast at Yahoo! Weather</a>\n<BR />\n<BR />\n(provided by <a href=\"http://www.weather.com\" >The Weather Channel</a>)\n<BR />\n]]>","guid":{"isPermaLink":"false"}}}}}}'
|
|
||||||
elif query_url.startswith('https://api.openweathermap.org/data/2.5/'):
|
elif query_url.startswith('https://api.openweathermap.org/data/2.5/'):
|
||||||
if 'Meppen' in query_url or '52.6833' in query_url:
|
if 'Meppen' in query_url or '52.6833' in query_url:
|
||||||
return r'{"coord":{"lon":7.29,"lat":52.69},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":293.15,"feels_like":295.16,"temp_min":293.15,"temp_max":295.37,"pressure":1018,"humidity":77},"visibility":10000,"wind":{"speed":1.12,"deg":126},"clouds":{"all":0},"dt":1600196220,"sys":{"type":1,"id":1871,"country":"DE","sunrise":1600146332,"sunset":1600191996},"timezone":7200,"id":2871845,"name":"Meppen","cod":200}'
|
return r'{"coord":{"lon":7.29,"lat":52.69},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":20,"feels_like":22.01,"temp_min":20,"temp_max":22.22,"pressure":1018,"humidity":77},"visibility":10000,"wind":{"speed":1.12,"deg":126},"clouds":{"all":0},"dt":1600196220,"sys":{"type":1,"id":1871,"country":"DE","sunrise":1600146332,"sunset":1600191996},"timezone":7200,"id":2871845,"name":"Meppen","cod":200}'
|
||||||
elif 'Moscow' in query_url:
|
elif 'Moscow' in query_url:
|
||||||
return r'{"coord":{"lon":37.62,"lat":55.75},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":283.15,"feels_like":280.78,"temp_min":283.15,"temp_max":284.26,"pressure":1019,"humidity":71},"visibility":10000,"wind":{"speed":3,"deg":330},"clouds":{"all":0},"dt":1600196224,"sys":{"type":1,"id":9029,"country":"RU","sunrise":1600138909,"sunset":1600184863},"timezone":10800,"id":524901,"name":"Moscow","cod":200}'
|
return r'{"coord":{"lon":37.62,"lat":55.75},"weather":[{"id":800,"main":"Clear","description":"clear sky","icon":"01n"}],"base":"stations","main":{"temp":10,"feels_like":7.63,"temp_min":10,"temp_max":11.11,"pressure":1019,"humidity":71},"visibility":10000,"wind":{"speed":3,"deg":330},"clouds":{"all":0},"dt":1600196224,"sys":{"type":1,"id":9029,"country":"RU","sunrise":1600138909,"sunset":1600184863},"timezone":10800,"id":524901,"name":"Moscow","cod":200}'
|
||||||
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -954,46 +954,45 @@ class TestWthr(TestCommon):
|
|||||||
pl = Pl()
|
pl = Pl()
|
||||||
with replace_attr(self.module, 'urllib_read', urllib_read):
|
with replace_attr(self.module, 'urllib_read', urllib_read):
|
||||||
self.assertEqual(self.module.weather(pl=pl), [
|
self.assertEqual(self.module.weather(pl=pl), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, temp_coldest=0, temp_hottest=100), [
|
self.assertEqual(self.module.weather(pl=pl, temp_coldest=0, temp_hottest=100), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 20}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 20}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, temp_coldest=-100, temp_hottest=-50), [
|
self.assertEqual(self.module.weather(pl=pl, temp_coldest=-100, temp_hottest=-50), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 100}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 100}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, icons={'sunny': 'o'}), [
|
self.assertEqual(self.module.weather(pl=pl, icons={'clear': 'o'}), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'o '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'o '},
|
||||||
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
||||||
|
])
|
||||||
|
self.assertEqual(self.module.weather(pl=pl, icons={'clear_sky': 'x'}), [
|
||||||
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'x '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
||||||
])
|
])
|
||||||
# Test is disabled as no request has more than 1 weather condition associated currently
|
|
||||||
# self.assertEqual(self.module.weather(pl=pl, icons={'windy': 'x'}), [
|
|
||||||
# {'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_blustery', 'weather_condition_windy', 'weather_conditions', 'weather'], 'contents': 'x '},
|
|
||||||
# {'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '14°C', 'gradient_level': 62.857142857142854}
|
|
||||||
# ])
|
|
||||||
self.assertEqual(self.module.weather(pl=pl, unit='F'), [
|
self.assertEqual(self.module.weather(pl=pl, unit='F'), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '68°F', 'gradient_level': 100}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '68°F', 'gradient_level': 100}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, unit='K'), [
|
self.assertEqual(self.module.weather(pl=pl, unit='K'), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '293K', 'gradient_level': 100}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '293K', 'gradient_level': 100}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, temp_format='{temp:.1e}C'), [
|
self.assertEqual(self.module.weather(pl=pl, temp_format='{temp:.1e}C'), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '2.0e+01C', 'gradient_level': 71.42857142857143}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '2.0e+01C', 'gradient_level': 71.42857142857143}
|
||||||
])
|
])
|
||||||
with replace_attr(self.module, 'urllib_read', urllib_read):
|
with replace_attr(self.module, 'urllib_read', urllib_read):
|
||||||
self.module.weather.startup(pl=pl, location_query='Meppen,06,DE')
|
self.module.weather.startup(pl=pl, location_query='Meppen,06,DE')
|
||||||
self.assertEqual(self.module.weather(pl=pl), [
|
self.assertEqual(self.module.weather(pl=pl), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '20°C', 'gradient_level': 71.42857142857143}
|
||||||
])
|
])
|
||||||
self.assertEqual(self.module.weather(pl=pl, location_query='Moscow,RU'), [
|
self.assertEqual(self.module.weather(pl=pl, location_query='Moscow,RU'), [
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_sunny', 'weather_conditions', 'weather'], 'contents': 'SUN '},
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_condition_clear_sky', 'weather_condition_clear', 'weather_conditions', 'weather'], 'contents': 'CLEAR '},
|
||||||
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '10°C', 'gradient_level': 57.142857142857146}
|
{'divider_highlight_group': 'background:divider', 'highlight_groups': ['weather_temp_gradient', 'weather_temp', 'weather'], 'contents': '10°C', 'gradient_level': 57.142857142857146}
|
||||||
])
|
])
|
||||||
self.module.weather.shutdown()
|
self.module.weather.shutdown()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user