Migrate Hydrawise to an async client library (#103636)
* Migrate Hydrawise to an async client library * Changes requested during review * Additional changes requested during review
This commit is contained in:
parent
45f1d50f03
commit
0899be6d4b
13 changed files with 254 additions and 232 deletions
|
@ -1,12 +1,16 @@
|
|||
"""Test Hydrawise switch."""
|
||||
|
||||
from unittest.mock import Mock
|
||||
from datetime import timedelta
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from pydrawise.schema import Zone
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.hydrawise.const import DEFAULT_WATERING_TIME
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
@ -14,7 +18,6 @@ from tests.common import MockConfigEntry
|
|||
async def test_states(
|
||||
hass: HomeAssistant,
|
||||
mock_added_config_entry: MockConfigEntry,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
) -> None:
|
||||
"""Test switch states."""
|
||||
watering1 = hass.states.get("switch.zone_one_manual_watering")
|
||||
|
@ -31,11 +34,14 @@ async def test_states(
|
|||
|
||||
auto_watering2 = hass.states.get("switch.zone_two_automatic_watering")
|
||||
assert auto_watering2 is not None
|
||||
assert auto_watering2.state == "off"
|
||||
assert auto_watering2.state == "on"
|
||||
|
||||
|
||||
async def test_manual_watering_services(
|
||||
hass: HomeAssistant, mock_added_config_entry: MockConfigEntry, mock_pydrawise: Mock
|
||||
hass: HomeAssistant,
|
||||
mock_added_config_entry: MockConfigEntry,
|
||||
mock_pydrawise: AsyncMock,
|
||||
zones: list[Zone],
|
||||
) -> None:
|
||||
"""Test Manual Watering services."""
|
||||
await hass.services.async_call(
|
||||
|
@ -44,7 +50,9 @@ async def test_manual_watering_services(
|
|||
service_data={ATTR_ENTITY_ID: "switch.zone_one_manual_watering"},
|
||||
blocking=True,
|
||||
)
|
||||
mock_pydrawise.run_zone.assert_called_once_with(15, 1)
|
||||
mock_pydrawise.start_zone.assert_called_once_with(
|
||||
zones[0], custom_run_duration=DEFAULT_WATERING_TIME
|
||||
)
|
||||
state = hass.states.get("switch.zone_one_manual_watering")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
@ -56,14 +64,18 @@ async def test_manual_watering_services(
|
|||
service_data={ATTR_ENTITY_ID: "switch.zone_one_manual_watering"},
|
||||
blocking=True,
|
||||
)
|
||||
mock_pydrawise.run_zone.assert_called_once_with(0, 1)
|
||||
mock_pydrawise.stop_zone.assert_called_once_with(zones[0])
|
||||
state = hass.states.get("switch.zone_one_manual_watering")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2023-10-01 00:00:00+00:00")
|
||||
async def test_auto_watering_services(
|
||||
hass: HomeAssistant, mock_added_config_entry: MockConfigEntry, mock_pydrawise: Mock
|
||||
hass: HomeAssistant,
|
||||
mock_added_config_entry: MockConfigEntry,
|
||||
mock_pydrawise: AsyncMock,
|
||||
zones: list[Zone],
|
||||
) -> None:
|
||||
"""Test Automatic Watering services."""
|
||||
await hass.services.async_call(
|
||||
|
@ -72,7 +84,9 @@ async def test_auto_watering_services(
|
|||
service_data={ATTR_ENTITY_ID: "switch.zone_one_automatic_watering"},
|
||||
blocking=True,
|
||||
)
|
||||
mock_pydrawise.suspend_zone.assert_called_once_with(365, 1)
|
||||
mock_pydrawise.suspend_zone.assert_called_once_with(
|
||||
zones[0], dt_util.now() + timedelta(days=365)
|
||||
)
|
||||
state = hass.states.get("switch.zone_one_automatic_watering")
|
||||
assert state is not None
|
||||
assert state.state == "off"
|
||||
|
@ -84,7 +98,7 @@ async def test_auto_watering_services(
|
|||
service_data={ATTR_ENTITY_ID: "switch.zone_one_automatic_watering"},
|
||||
blocking=True,
|
||||
)
|
||||
mock_pydrawise.suspend_zone.assert_called_once_with(0, 1)
|
||||
mock_pydrawise.resume_zone.assert_called_once_with(zones[0])
|
||||
state = hass.states.get("switch.zone_one_automatic_watering")
|
||||
assert state is not None
|
||||
assert state.state == "on"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue