2023-10-06 12:42:08 +00:00
|
|
|
"""Tests for the Hydrawise integration."""
|
|
|
|
|
2023-10-30 14:18:59 +00:00
|
|
|
from unittest.mock import Mock
|
2023-10-06 12:42:08 +00:00
|
|
|
|
|
|
|
from requests.exceptions import HTTPError
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntryState
|
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
|
|
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
|
|
|
import homeassistant.helpers.issue_registry as ir
|
|
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_import_success(hass: HomeAssistant, mock_pydrawise: Mock) -> None:
|
|
|
|
"""Test that setup with a YAML config triggers an import and warning."""
|
2023-10-30 14:18:59 +00:00
|
|
|
mock_pydrawise.update_controller_info.return_value = True
|
2023-10-06 12:42:08 +00:00
|
|
|
mock_pydrawise.customer_id = 12345
|
|
|
|
mock_pydrawise.status = "unknown"
|
|
|
|
config = {"hydrawise": {CONF_ACCESS_TOKEN: "_access-token_"}}
|
|
|
|
assert await async_setup_component(hass, "hydrawise", config)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
issue_registry = ir.async_get(hass)
|
|
|
|
issue = issue_registry.async_get_issue(
|
|
|
|
HOMEASSISTANT_DOMAIN, "deprecated_yaml_hydrawise"
|
|
|
|
)
|
|
|
|
assert issue.translation_key == "deprecated_yaml"
|
|
|
|
|
|
|
|
|
|
|
|
async def test_connect_retry(
|
2023-10-30 14:18:59 +00:00
|
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_pydrawise: Mock
|
2023-10-06 12:42:08 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test that a connection error triggers a retry."""
|
2023-10-30 14:18:59 +00:00
|
|
|
mock_pydrawise.update_controller_info.side_effect = HTTPError
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
2023-10-06 12:42:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_setup_no_data(
|
2023-10-30 14:18:59 +00:00
|
|
|
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_pydrawise: Mock
|
2023-10-06 12:42:08 +00:00
|
|
|
) -> None:
|
|
|
|
"""Test that no data from the API triggers a retry."""
|
2023-10-30 14:18:59 +00:00
|
|
|
mock_pydrawise.update_controller_info.return_value = False
|
|
|
|
mock_config_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|