#4421 - Forced icons to be displayed via SSL to avoid Mixed Content warnings (#4544)

* #4421 - Forced icons to be displayed via SSL to avoid Mixed Content warnings

* Fixed houndci-bot whitespace

* Using regex to replace http:// for https://

* Created assert test to verify https translation
This commit is contained in:
Marcelo Moreira de Mello 2016-11-25 15:03:12 -05:00 committed by Lewis Juggins
parent 2a7bc0e55c
commit 61653a517d
2 changed files with 6 additions and 4 deletions

View File

@ -7,6 +7,7 @@ https://home-assistant.io/components/sensor.wunderground/
from datetime import timedelta from datetime import timedelta
import logging import logging
import re
import requests import requests
import voluptuous as vol import voluptuous as vol
@ -172,7 +173,8 @@ class WUndergroundSensor(Entity):
def entity_picture(self): def entity_picture(self):
"""Return the entity picture.""" """Return the entity picture."""
if self._condition == 'weather': if self._condition == 'weather':
return self.rest.data['icon_url'] url = self.rest.data['icon_url']
return re.sub(r'^http://', 'https://', url, flags=re.IGNORECASE)
@property @property
def unit_of_measurement(self): def unit_of_measurement(self):

View File

@ -25,7 +25,7 @@ VALID_CONFIG = {
FEELS_LIKE = '40' FEELS_LIKE = '40'
WEATHER = 'Clear' WEATHER = 'Clear'
ICON_URL = 'http://icons.wxug.com/i/c/k/clear.gif' HTTPS_ICON_URL = 'https://icons.wxug.com/i/c/k/clear.gif'
ALERT_MESSAGE = 'This is a test alert message' ALERT_MESSAGE = 'This is a test alert message'
@ -61,7 +61,7 @@ def mocked_requests_get(*args, **kwargs):
}, },
"feelslike_c": FEELS_LIKE, "feelslike_c": FEELS_LIKE,
"weather": WEATHER, "weather": WEATHER,
"icon_url": ICON_URL, "icon_url": 'http://icons.wxug.com/i/c/k/clear.gif',
"display_location": { "display_location": {
"city": "Holly Springs", "city": "Holly Springs",
"country": "US", "country": "US",
@ -150,7 +150,7 @@ class TestWundergroundSetup(unittest.TestCase):
device.update() device.update()
self.assertTrue(str(device.name).startswith('PWS_')) self.assertTrue(str(device.name).startswith('PWS_'))
if device.name == 'PWS_weather': if device.name == 'PWS_weather':
self.assertEqual(ICON_URL, device.entity_picture) self.assertEqual(HTTPS_ICON_URL, device.entity_picture)
self.assertEqual(WEATHER, device.state) self.assertEqual(WEATHER, device.state)
self.assertIsNone(device.unit_of_measurement) self.assertIsNone(device.unit_of_measurement)
elif device.name == 'PWS_alerts': elif device.name == 'PWS_alerts':