hass-core/tests/components/ondilo_ico/test_init.py
JeromeHXP c9930d912e
Handle errors retrieving Ondilo data and bump ondilo to 0.5.0 ()
* Bump ondilo to 0.5.0 and handle errors retrieving data

* Bump ondilo to 0.5.0 and handle errors retrieving data

* Updated ruff recommendation

* Refactor

* Refactor

* Added exception log and updated call to update data

* Updated test cases to test through state machine

* Updated test cases

* Updated test cases after comments

* REnamed file

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
2024-05-06 14:41:28 +02:00

31 lines
1.1 KiB
Python

"""Test Ondilo ICO initialization."""
from typing import Any
from unittest.mock import MagicMock
from homeassistant.config_entries import ConfigEntryState
from homeassistant.core import HomeAssistant
from . import setup_integration
from tests.common import MockConfigEntry
async def test_init_with_no_ico_attached(
hass: HomeAssistant,
mock_ondilo_client: MagicMock,
config_entry: MockConfigEntry,
pool1: dict[str, Any],
) -> None:
"""Test if an ICO is not attached to a pool, then no sensor is created."""
# Only one pool, but no ICO attached
mock_ondilo_client.get_pools.return_value = pool1
mock_ondilo_client.get_ICO_details.side_effect = None
mock_ondilo_client.get_ICO_details.return_value = None
await setup_integration(hass, config_entry, mock_ondilo_client)
# No sensor should be created
assert len(hass.states.async_all()) == 0
# We should not have tried to retrieve pool measures
mock_ondilo_client.get_last_pool_measures.assert_not_called()
assert config_entry.state is ConfigEntryState.SETUP_RETRY