Cleanup BOM dependencies + add basic test + IDEA autoformat (#18462)
* Cleanup BOM dependencies + add basic testpull/19133/head
parent
1ad3c3b1e2
commit
22ab83acae
|
@ -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")
|
_LOGGER.error("Could not get BOM weather station from lat/lon")
|
||||||
return
|
return
|
||||||
|
|
||||||
bom_data = BOMCurrentData(hass, station)
|
bom_data = BOMCurrentData(station)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bom_data.update()
|
bom_data.update()
|
||||||
|
@ -181,9 +181,8 @@ class BOMCurrentSensor(Entity):
|
||||||
class BOMCurrentData:
|
class BOMCurrentData:
|
||||||
"""Get data from BOM."""
|
"""Get data from BOM."""
|
||||||
|
|
||||||
def __init__(self, hass, station_id):
|
def __init__(self, station_id):
|
||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
self._hass = hass
|
|
||||||
self._zone_id, self._wmo_id = station_id.split('.')
|
self._zone_id, self._wmo_id = station_id.split('.')
|
||||||
self._data = None
|
self._data = None
|
||||||
self.last_updated = None
|
self.last_updated = None
|
||||||
|
|
|
@ -33,7 +33,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
||||||
if station is None:
|
if station is None:
|
||||||
_LOGGER.error("Could not get BOM weather station from lat/lon")
|
_LOGGER.error("Could not get BOM weather station from lat/lon")
|
||||||
return False
|
return False
|
||||||
bom_data = BOMCurrentData(hass, station)
|
bom_data = BOMCurrentData(station)
|
||||||
try:
|
try:
|
||||||
bom_data.update()
|
bom_data.update()
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
|
|
|
@ -6,11 +6,12 @@ from unittest.mock import patch
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from tests.common import (
|
|
||||||
assert_setup_component, get_test_home_assistant, load_fixture)
|
|
||||||
|
|
||||||
from homeassistant.components import sensor
|
from homeassistant.components import sensor
|
||||||
|
from homeassistant.components.sensor.bom import BOMCurrentData
|
||||||
from homeassistant.setup import setup_component
|
from homeassistant.setup import setup_component
|
||||||
|
from tests.common import (
|
||||||
|
assert_setup_component, get_test_home_assistant, load_fixture)
|
||||||
|
|
||||||
VALID_CONFIG = {
|
VALID_CONFIG = {
|
||||||
'platform': 'bom',
|
'platform': 'bom',
|
||||||
|
@ -97,3 +98,12 @@ class TestBOMWeatherSensor(unittest.TestCase):
|
||||||
|
|
||||||
feels_like = self.hass.states.get('sensor.bom_fake_feels_like_c').state
|
feels_like = self.hass.states.get('sensor.bom_fake_feels_like_c').state
|
||||||
assert '25.0' == feels_like
|
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
|
||||||
|
|
Loading…
Reference in New Issue