-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Fix BOM weather '-' value #14042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
balloob
merged 1 commit into
home-assistant:dev
from
nickw444:nwhyte/bom-weather-improvement
May 8, 2018
Merged
Fix BOM weather '-' value #14042
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| """The tests for the BOM Weather sensor platform.""" | ||
| import re | ||
| import unittest | ||
| import json | ||
| import requests | ||
| from unittest.mock import patch | ||
| from urllib.parse import urlparse | ||
|
|
||
| from homeassistant.setup import setup_component | ||
| from homeassistant.components import sensor | ||
|
|
||
| from tests.common import ( | ||
| get_test_home_assistant, assert_setup_component, load_fixture) | ||
|
|
||
| VALID_CONFIG = { | ||
| 'platform': 'bom', | ||
| 'station': 'IDN60901.94767', | ||
| 'name': 'Fake', | ||
| 'monitored_conditions': [ | ||
| 'apparent_t', | ||
| 'press', | ||
| 'weather' | ||
| ] | ||
| } | ||
|
|
||
|
|
||
| def mocked_requests(*args, **kwargs): | ||
| """Mock requests.get invocations.""" | ||
| class MockResponse: | ||
| """Class to represent a mocked response.""" | ||
|
|
||
| def __init__(self, json_data, status_code): | ||
| """Initialize the mock response class.""" | ||
| self.json_data = json_data | ||
| self.status_code = status_code | ||
|
|
||
| def json(self): | ||
| """Return the json of the response.""" | ||
| return self.json_data | ||
|
|
||
| @property | ||
| def content(self): | ||
| """Return the content of the response.""" | ||
| return self.json() | ||
|
|
||
| def raise_for_status(self): | ||
| """Raise an HTTPError if status is not 200.""" | ||
| if self.status_code != 200: | ||
| raise requests.HTTPError(self.status_code) | ||
|
|
||
| url = urlparse(args[0]) | ||
| if re.match(r'^/fwo/[\w]+/[\w.]+\.json', url.path): | ||
| return MockResponse(json.loads(load_fixture('bom_weather.json')), 200) | ||
|
|
||
| raise NotImplementedError('Unknown route {}'.format(url.path)) | ||
|
|
||
|
|
||
| class TestBOMWeatherSensor(unittest.TestCase): | ||
| """Test the BOM Weather sensor.""" | ||
|
|
||
| def setUp(self): | ||
| """Set up things to be run when tests are started.""" | ||
| self.hass = get_test_home_assistant() | ||
| self.config = VALID_CONFIG | ||
|
|
||
| def tearDown(self): | ||
| """Stop everything that was started.""" | ||
| self.hass.stop() | ||
|
|
||
| @patch('requests.get', side_effect=mocked_requests) | ||
| def test_setup(self, mock_get): | ||
| """Test the setup with custom settings.""" | ||
| with assert_setup_component(1, sensor.DOMAIN): | ||
| self.assertTrue(setup_component(self.hass, sensor.DOMAIN, { | ||
| 'sensor': VALID_CONFIG})) | ||
|
|
||
| fake_entities = [ | ||
| 'bom_fake_feels_like_c', | ||
| 'bom_fake_pressure_mb', | ||
| 'bom_fake_weather'] | ||
|
|
||
| for entity_id in fake_entities: | ||
| state = self.hass.states.get('sensor.{}'.format(entity_id)) | ||
| self.assertIsNotNone(state) | ||
|
|
||
| @patch('requests.get', side_effect=mocked_requests) | ||
| def test_sensor_values(self, mock_get): | ||
| """Test retrieval of sensor values.""" | ||
| self.assertTrue(setup_component( | ||
| self.hass, sensor.DOMAIN, {'sensor': VALID_CONFIG})) | ||
|
|
||
| self.assertEqual('Fine', self.hass.states.get( | ||
| 'sensor.bom_fake_weather').state) | ||
| self.assertEqual('1021.7', self.hass.states.get( | ||
| 'sensor.bom_fake_pressure_mb').state) | ||
| self.assertEqual('25.0', self.hass.states.get( | ||
| 'sensor.bom_fake_feels_like_c').state) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "observations": { | ||
| "data": [ | ||
| { | ||
| "wmo": 94767, | ||
| "name": "Fake", | ||
| "history_product": "IDN00000", | ||
| "local_date_time_full": "20180422130000", | ||
| "apparent_t": 25.0, | ||
| "press": 1021.7, | ||
| "weather": "-" | ||
| }, | ||
| { | ||
| "wmo": 94767, | ||
| "name": "Fake", | ||
| "history_product": "IDN00000", | ||
| "local_date_time_full": "20180422130000", | ||
| "apparent_t": 22.0, | ||
| "press": 1019.7, | ||
| "weather": "-" | ||
| }, | ||
| { | ||
| "wmo": 94767, | ||
| "name": "Fake", | ||
| "history_product": "IDN00000", | ||
| "local_date_time_full": "20180422130000", | ||
| "apparent_t": 20.0, | ||
| "press": 1011.7, | ||
| "weather": "Fine" | ||
| }, | ||
| { | ||
| "wmo": 94767, | ||
| "name": "Fake", | ||
| "history_product": "IDN00000", | ||
| "local_date_time_full": "20180422130000", | ||
| "apparent_t": 18.0, | ||
| "press": 1010.0, | ||
| "weather": "-" | ||
| } | ||
| ] | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really part of this PR, but in the if statement above we check if the last update was within 35 minutes.
Can't we just set
MIN_TIME_BETWEEN_UPDATESto 35 minutes? TheThrottleshould take care of it. I'm a bit confused.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me I'll raise another PR