Surepetcare, bug fix (#55842)

pull/55871/head
Daniel Hjelseth Høyer 2021-09-06 22:36:45 +02:00 committed by GitHub
parent 9093819671
commit bcfedeb797
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 6 deletions

View File

@ -144,7 +144,7 @@ class SurePetcareAPI:
"""Get the latest data from Sure Petcare."""
try:
self.states = await self.surepy.get_entities()
self.states = await self.surepy.get_entities(refresh=True)
except SurePetcareError as error:
_LOGGER.error("Unable to fetch data: %s", error)
return

View File

@ -7,12 +7,16 @@ from surepy import MESTART_RESOURCE
from . import MOCK_API_DATA
async def _mock_call(method, resource):
if method == "GET" and resource == MESTART_RESOURCE:
return {"data": MOCK_API_DATA}
@pytest.fixture
async def surepetcare():
"""Mock the SurePetcare for easier testing."""
with patch("surepy.SureAPIClient", autospec=True) as mock_client_class, patch(
"surepy.find_token"
):
with patch("surepy.SureAPIClient", autospec=True) as mock_client_class:
client = mock_client_class.return_value
client.resources = {MESTART_RESOURCE: {"data": MOCK_API_DATA}}
client.resources = {}
client.call = _mock_call
yield client

View File

@ -12,7 +12,7 @@ EXPECTED_ENTITY_IDS = {
}
async def test_binary_sensors(hass, surepetcare) -> None:
async def test_sensors(hass, surepetcare) -> None:
"""Test the generation of unique ids."""
assert await async_setup_component(hass, DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()