Cleanup BOM dependencies + add basic test + IDEA autoformat (#18462)

* Cleanup BOM dependencies + add basic test
pull/19133/head
Nick Whyte 2018-11-22 12:41:53 +11:00 committed by Charles Garwood
parent 1ad3c3b1e2
commit 22ab83acae
3 changed files with 15 additions and 6 deletions

View File

@ -119,7 +119,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.error("Could not get BOM weather station from lat/lon")
return
bom_data = BOMCurrentData(hass, station)
bom_data = BOMCurrentData(station)
try:
bom_data.update()
@ -181,9 +181,8 @@ class BOMCurrentSensor(Entity):
class BOMCurrentData:
"""Get data from BOM."""
def __init__(self, hass, station_id):
def __init__(self, station_id):
"""Initialize the data object."""
self._hass = hass
self._zone_id, self._wmo_id = station_id.split('.')
self._data = None
self.last_updated = None

View File

@ -33,7 +33,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
if station is None:
_LOGGER.error("Could not get BOM weather station from lat/lon")
return False
bom_data = BOMCurrentData(hass, station)
bom_data = BOMCurrentData(station)
try:
bom_data.update()
except ValueError as err:

View File

@ -6,11 +6,12 @@ from unittest.mock import patch
from urllib.parse import urlparse
import requests
from tests.common import (
assert_setup_component, get_test_home_assistant, load_fixture)
from homeassistant.components import sensor
from homeassistant.components.sensor.bom import BOMCurrentData
from homeassistant.setup import setup_component
from tests.common import (
assert_setup_component, get_test_home_assistant, load_fixture)
VALID_CONFIG = {
'platform': 'bom',
@ -97,3 +98,12 @@ class TestBOMWeatherSensor(unittest.TestCase):
feels_like = self.hass.states.get('sensor.bom_fake_feels_like_c').state
assert '25.0' == feels_like
class TestBOMCurrentData(unittest.TestCase):
"""Test the BOM data container."""
def test_should_update_initial(self):
"""Test that the first update always occurs."""
bom_data = BOMCurrentData('IDN60901.94767')
assert bom_data.should_update() is True