Bump bluecurrent-api to 1.2.2 (#110483)

This commit is contained in:
Floris272 2024-03-20 11:28:27 +01:00 committed by GitHub
parent 6552e12161
commit 249f708071
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 86 additions and 91 deletions

View file

@ -29,15 +29,22 @@ async def test_load_unload_entry(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test load and unload entry."""
with patch("homeassistant.components.blue_current.Client", autospec=True):
with patch(
"homeassistant.components.blue_current.Client.validate_api_token"
), patch(
"homeassistant.components.blue_current.Client.wait_for_charge_points"
), patch("homeassistant.components.blue_current.Client.disconnect"), patch(
"homeassistant.components.blue_current.Client.connect",
lambda self, on_data: hass.loop.create_future(),
):
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.LOADED
assert config_entry.state == ConfigEntryState.LOADED
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.NOT_LOADED
await hass.config_entries.async_unload(config_entry.entry_id)
await hass.async_block_till_done()
assert config_entry.state == ConfigEntryState.NOT_LOADED
@pytest.mark.parametrize(
@ -55,43 +62,29 @@ async def test_config_exceptions(
) -> None:
"""Test if the correct config error is raised when connecting to the api fails."""
with patch(
"homeassistant.components.blue_current.Client.connect",
"homeassistant.components.blue_current.Client.validate_api_token",
side_effect=api_error,
), pytest.raises(config_error):
config_entry.add_to_hass(hass)
await async_setup_entry(hass, config_entry)
async def test_start_loop(hass: HomeAssistant, config_entry: MockConfigEntry) -> None:
"""Test start_loop."""
async def test_connect_websocket_error(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test reconnect when connect throws a WebsocketError."""
with patch("homeassistant.components.blue_current.SMALL_DELAY", 0):
with patch("homeassistant.components.blue_current.DELAY", 0):
mock_client, started_loop, future_container = await init_integration(
hass, config_entry
)
future_container.future.set_exception(BlueCurrentException)
future_container.future.set_exception(WebsocketError)
await started_loop.wait()
assert mock_client.connect.call_count == 2
async def test_reconnect_websocket_error(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test reconnect when connect throws a WebsocketError."""
with patch("homeassistant.components.blue_current.LARGE_DELAY", 0):
mock_client, started_loop, future_container = await init_integration(
hass, config_entry
)
future_container.future.set_exception(BlueCurrentException)
mock_client.connect.side_effect = [WebsocketError, None]
await started_loop.wait()
assert mock_client.connect.call_count == 3
async def test_reconnect_request_limit_reached_error(
async def test_connect_request_limit_reached_error(
hass: HomeAssistant, config_entry: MockConfigEntry
) -> None:
"""Test reconnect when connect throws a RequestLimitReached."""
@ -99,10 +92,9 @@ async def test_reconnect_request_limit_reached_error(
mock_client, started_loop, future_container = await init_integration(
hass, config_entry
)
future_container.future.set_exception(BlueCurrentException)
mock_client.connect.side_effect = [RequestLimitReached, None]
future_container.future.set_exception(RequestLimitReached)
mock_client.get_next_reset_delta.return_value = timedelta(seconds=0)
await started_loop.wait()
assert mock_client.get_next_reset_delta.call_count == 1
assert mock_client.connect.call_count == 3
assert mock_client.connect.call_count == 2