mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Replace aiohttp mock with patch in Advantage Air (#104932)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
6a6956573f
commit
e1df1f9ffe
@ -1,12 +1,14 @@
|
|||||||
"""Tests for the Advantage Air component."""
|
"""Tests for the Advantage Air component."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.const import DOMAIN
|
from homeassistant.components.advantage_air.const import DOMAIN
|
||||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
||||||
|
|
||||||
from tests.common import MockConfigEntry, load_fixture
|
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||||
|
|
||||||
TEST_SYSTEM_DATA = load_fixture("advantage_air/getSystemData.json")
|
TEST_SYSTEM_DATA = load_json_object_fixture("getSystemData.json", DOMAIN)
|
||||||
TEST_SET_RESPONSE = load_fixture("advantage_air/setAircon.json")
|
TEST_SET_RESPONSE = None
|
||||||
|
|
||||||
USER_INPUT = {
|
USER_INPUT = {
|
||||||
CONF_IP_ADDRESS: "1.2.3.4",
|
CONF_IP_ADDRESS: "1.2.3.4",
|
||||||
@ -25,6 +27,22 @@ TEST_SET_THING_URL = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def patch_get(return_value=TEST_SYSTEM_DATA, side_effect=None):
|
||||||
|
"""Patch the Advantage Air async_get method."""
|
||||||
|
return patch(
|
||||||
|
"homeassistant.components.advantage_air.advantage_air.async_get",
|
||||||
|
new=AsyncMock(return_value=return_value, side_effect=side_effect),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def patch_update(return_value=True, side_effect=None):
|
||||||
|
"""Patch the Advantage Air async_set method."""
|
||||||
|
return patch(
|
||||||
|
"homeassistant.components.advantage_air.advantage_air._endpoint.async_update",
|
||||||
|
new=AsyncMock(return_value=return_value, side_effect=side_effect),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def add_mock_config(hass):
|
async def add_mock_config(hass):
|
||||||
"""Create a fake Advantage Air Config Entry."""
|
"""Create a fake Advantage Air Config Entry."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
@ -33,6 +51,7 @@ async def add_mock_config(hass):
|
|||||||
unique_id="0123456",
|
unique_id="0123456",
|
||||||
data=USER_INPUT,
|
data=USER_INPUT,
|
||||||
)
|
)
|
||||||
|
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
20
tests/components/advantage_air/conftest.py
Normal file
20
tests/components/advantage_air/conftest.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
"""Fixtures for advantage_air."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from . import patch_get, patch_update
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_get():
|
||||||
|
"""Fixture to patch the Advantage Air async_get method."""
|
||||||
|
with patch_get() as mock_get:
|
||||||
|
yield mock_get
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def mock_update():
|
||||||
|
"""Fixture to patch the Advantage Air async_get method."""
|
||||||
|
with patch_update() as mock_get:
|
||||||
|
yield mock_get
|
@ -1,5 +1,6 @@
|
|||||||
"""Test the Advantage Air Binary Sensor Platform."""
|
"""Test the Advantage Air Binary Sensor Platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
|
from homeassistant.config_entries import RELOAD_AFTER_UPDATE_DELAY
|
||||||
from homeassistant.const import STATE_OFF, STATE_ON
|
from homeassistant.const import STATE_OFF, STATE_ON
|
||||||
@ -7,37 +8,20 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_binary_sensor_async_setup_entry(
|
async def test_binary_sensor_async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test binary sensor setup."""
|
"""Test binary sensor setup."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
|
||||||
|
|
||||||
# Test First Air Filter
|
# Test First Air Filter
|
||||||
entity_id = "binary_sensor.myzone_filter"
|
entity_id = "binary_sensor.myzone_filter"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -83,6 +67,7 @@ async def test_binary_sensor_async_setup_entry(
|
|||||||
|
|
||||||
assert not hass.states.get(entity_id)
|
assert not hass.states.get(entity_id)
|
||||||
|
|
||||||
|
mock_get.reset_mock()
|
||||||
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -91,6 +76,7 @@ async def test_binary_sensor_async_setup_entry(
|
|||||||
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert len(mock_get.mock_calls) == 2
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
@ -105,6 +91,7 @@ async def test_binary_sensor_async_setup_entry(
|
|||||||
|
|
||||||
assert not hass.states.get(entity_id)
|
assert not hass.states.get(entity_id)
|
||||||
|
|
||||||
|
mock_get.reset_mock()
|
||||||
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -113,6 +100,7 @@ async def test_binary_sensor_async_setup_entry(
|
|||||||
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert len(mock_get.mock_calls) == 2
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
|
@ -1,20 +1,10 @@
|
|||||||
"""Test the Advantage Air Climate Platform."""
|
"""Test the Advantage Air Climate Platform."""
|
||||||
from json import loads
|
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from advantage_air import ApiError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.climate import (
|
|
||||||
ADVANTAGE_AIR_COOL_TARGET,
|
|
||||||
ADVANTAGE_AIR_HEAT_TARGET,
|
|
||||||
HASS_FAN_MODES,
|
|
||||||
HASS_HVAC_MODES,
|
|
||||||
)
|
|
||||||
from homeassistant.components.advantage_air.const import (
|
|
||||||
ADVANTAGE_AIR_STATE_CLOSE,
|
|
||||||
ADVANTAGE_AIR_STATE_OFF,
|
|
||||||
ADVANTAGE_AIR_STATE_ON,
|
|
||||||
ADVANTAGE_AIR_STATE_OPEN,
|
|
||||||
)
|
|
||||||
from homeassistant.components.climate import (
|
from homeassistant.components.climate import (
|
||||||
ATTR_CURRENT_TEMPERATURE,
|
ATTR_CURRENT_TEMPERATURE,
|
||||||
ATTR_FAN_MODE,
|
ATTR_FAN_MODE,
|
||||||
@ -37,35 +27,20 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config, patch_update
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_async_setup_entry(
|
async def test_climate_myzone_main(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test climate platform."""
|
"""Test climate platform main entity."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test MyZone Climate Entity
|
# Test MyZone main climate entity
|
||||||
entity_id = "climate.myzone"
|
entity_id = "climate.myzone"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
@ -80,19 +55,24 @@ async def test_climate_async_setup_entry(
|
|||||||
assert entry.unique_id == "uniqueid-ac1"
|
assert entry.unique_id == "uniqueid-ac1"
|
||||||
|
|
||||||
# Test setting HVAC Mode
|
# Test setting HVAC Mode
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
CLIMATE_DOMAIN,
|
||||||
|
SERVICE_SET_HVAC_MODE,
|
||||||
|
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.COOL},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
mock_update.assert_called_once()
|
||||||
|
mock_update.reset_mock()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_HVAC_MODE,
|
SERVICE_SET_HVAC_MODE,
|
||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.FAN_ONLY},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.FAN_ONLY},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["state"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert data["ac1"]["info"]["mode"] == HASS_HVAC_MODES[HVACMode.FAN_ONLY]
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test Turning Off with HVAC Mode
|
# Test Turning Off with HVAC Mode
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -101,26 +81,17 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.OFF},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.OFF},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["state"] == ADVANTAGE_AIR_STATE_OFF
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test changing Fan Mode
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_FAN_MODE,
|
SERVICE_SET_FAN_MODE,
|
||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_FAN_MODE: FAN_LOW},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_FAN_MODE: FAN_LOW},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["fan"] == HASS_FAN_MODES[FAN_LOW]
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test changing Temperature
|
# Test changing Temperature
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -129,12 +100,8 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_TEMPERATURE: 25},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_TEMPERATURE: 25},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["setTemp"] == 25
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test Turning On
|
# Test Turning On
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -143,12 +110,8 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["state"] == ADVANTAGE_AIR_STATE_OFF
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test Turning Off
|
# Test Turning Off
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -157,12 +120,19 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["state"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
async def test_climate_myzone_zone(
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
hass: HomeAssistant,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test climate platform myzone zone entity."""
|
||||||
|
|
||||||
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Climate Zone Entity
|
# Test Climate Zone Entity
|
||||||
entity_id = "climate.myzone_zone_open_with_sensor"
|
entity_id = "climate.myzone_zone_open_with_sensor"
|
||||||
@ -184,14 +154,8 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.FAN_ONLY},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.FAN_ONLY},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.reset_mock()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
|
|
||||||
assert data["ac1"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_OPEN
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test Climate Zone Off
|
# Test Climate Zone Off
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -200,13 +164,8 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.OFF},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_HVAC_MODE: HVACMode.OFF},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.reset_mock()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_CLOSE
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
@ -214,11 +173,19 @@ async def test_climate_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_TEMPERATURE: 25},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_TEMPERATURE: 25},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
mock_update.assert_called_once()
|
||||||
|
mock_update.reset_mock()
|
||||||
|
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
async def test_climate_myauto_main(
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
hass: HomeAssistant,
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
|
) -> None:
|
||||||
|
"""Test climate platform zone entity."""
|
||||||
|
|
||||||
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test MyAuto Climate Entity
|
# Test MyAuto Climate Entity
|
||||||
entity_id = "climate.myauto"
|
entity_id = "climate.myauto"
|
||||||
@ -231,6 +198,7 @@ async def test_climate_async_setup_entry(
|
|||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-ac3"
|
assert entry.unique_id == "uniqueid-ac3"
|
||||||
|
|
||||||
|
with patch_update() as mock_update:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
@ -241,34 +209,23 @@ async def test_climate_async_setup_entry(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["info"][ADVANTAGE_AIR_HEAT_TARGET] == 21
|
|
||||||
assert data["ac3"]["info"][ADVANTAGE_AIR_COOL_TARGET] == 23
|
|
||||||
|
|
||||||
|
|
||||||
async def test_climate_async_failed_update(
|
async def test_climate_async_failed_update(
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
hass: HomeAssistant,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test climate change failure."""
|
"""Test climate change failure."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
exc=SyntaxError,
|
|
||||||
)
|
|
||||||
await add_mock_config(hass)
|
|
||||||
|
|
||||||
with pytest.raises(HomeAssistantError):
|
with pytest.raises(HomeAssistantError):
|
||||||
|
mock_update.side_effect = ApiError
|
||||||
|
await add_mock_config(hass)
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
CLIMATE_DOMAIN,
|
CLIMATE_DOMAIN,
|
||||||
SERVICE_SET_TEMPERATURE,
|
SERVICE_SET_TEMPERATURE,
|
||||||
{ATTR_ENTITY_ID: ["climate.myzone"], ATTR_TEMPERATURE: 25},
|
{ATTR_ENTITY_ID: ["climate.myzone"], ATTR_TEMPERATURE: 25},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/setAircon"
|
|
||||||
|
@ -1,23 +1,18 @@
|
|||||||
"""Test the Advantage Air config flow."""
|
"""Test the Advantage Air config flow."""
|
||||||
from unittest.mock import patch
|
from unittest.mock import AsyncMock, patch
|
||||||
|
|
||||||
|
from advantage_air import ApiError
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
from homeassistant.components.advantage_air.const import DOMAIN
|
from homeassistant.components.advantage_air.const import DOMAIN
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import TEST_SYSTEM_DATA, TEST_SYSTEM_URL, USER_INPUT
|
from . import TEST_SYSTEM_DATA, USER_INPUT
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_form(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) -> None:
|
async def test_form(hass: HomeAssistant) -> None:
|
||||||
"""Test that form shows up."""
|
"""Test that form shows up."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
|
|
||||||
result1 = await hass.config_entries.flow.async_init(
|
result1 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
@ -26,6 +21,9 @@ async def test_form(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) ->
|
|||||||
assert result1["errors"] == {}
|
assert result1["errors"] == {}
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
"homeassistant.components.advantage_air.config_flow.advantage_air.async_get",
|
||||||
|
new=AsyncMock(return_value=TEST_SYSTEM_DATA),
|
||||||
|
) as mock_get, patch(
|
||||||
"homeassistant.components.advantage_air.async_setup_entry",
|
"homeassistant.components.advantage_air.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
) as mock_setup_entry:
|
) as mock_setup_entry:
|
||||||
@ -34,17 +32,21 @@ async def test_form(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) ->
|
|||||||
USER_INPUT,
|
USER_INPUT,
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
mock_setup_entry.assert_called_once()
|
||||||
|
mock_get.assert_called_once()
|
||||||
|
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
|
||||||
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
||||||
assert result2["title"] == "testname"
|
assert result2["title"] == "testname"
|
||||||
assert result2["data"] == USER_INPUT
|
assert result2["data"] == USER_INPUT
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
|
||||||
|
|
||||||
# Test Duplicate Config Flow
|
# Test Duplicate Config Flow
|
||||||
result3 = await hass.config_entries.flow.async_init(
|
result3 = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.advantage_air.config_flow.advantage_air.async_get",
|
||||||
|
new=AsyncMock(return_value=TEST_SYSTEM_DATA),
|
||||||
|
) as mock_get:
|
||||||
result4 = await hass.config_entries.flow.async_configure(
|
result4 = await hass.config_entries.flow.async_configure(
|
||||||
result3["flow_id"],
|
result3["flow_id"],
|
||||||
USER_INPUT,
|
USER_INPUT,
|
||||||
@ -52,25 +54,22 @@ async def test_form(hass: HomeAssistant, aioclient_mock: AiohttpClientMocker) ->
|
|||||||
assert result4["type"] == data_entry_flow.FlowResultType.ABORT
|
assert result4["type"] == data_entry_flow.FlowResultType.ABORT
|
||||||
|
|
||||||
|
|
||||||
async def test_form_cannot_connect(
|
async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
||||||
) -> None:
|
|
||||||
"""Test we handle cannot connect error."""
|
"""Test we handle cannot connect error."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
exc=SyntaxError,
|
|
||||||
)
|
|
||||||
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.advantage_air.config_flow.advantage_air.async_get",
|
||||||
|
new=AsyncMock(side_effect=ApiError),
|
||||||
|
) as mock_get:
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
USER_INPUT,
|
USER_INPUT,
|
||||||
)
|
)
|
||||||
|
mock_get.assert_called_once()
|
||||||
|
|
||||||
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
assert result2["type"] == data_entry_flow.FlowResultType.FORM
|
||||||
assert result2["step_id"] == "user"
|
assert result2["step_id"] == "user"
|
||||||
assert result2["errors"] == {"base": "cannot_connect"}
|
assert result2["errors"] == {"base": "cannot_connect"}
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
"""Test the Advantage Air Cover Platform."""
|
"""Test the Advantage Air Cover Platform."""
|
||||||
from json import loads
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.const import (
|
|
||||||
ADVANTAGE_AIR_STATE_CLOSE,
|
|
||||||
ADVANTAGE_AIR_STATE_OPEN,
|
|
||||||
)
|
|
||||||
from homeassistant.components.cover import (
|
from homeassistant.components.cover import (
|
||||||
ATTR_POSITION,
|
ATTR_POSITION,
|
||||||
DOMAIN as COVER_DOMAIN,
|
DOMAIN as COVER_DOMAIN,
|
||||||
@ -17,34 +13,17 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_OPEN
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_ac_cover(
|
async def test_ac_cover(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cover platform."""
|
"""Test cover platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Cover Zone Entity
|
# Test Cover Zone Entity
|
||||||
@ -65,12 +44,8 @@ async def test_ac_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_CLOSE
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
@ -78,13 +53,8 @@ async def test_ac_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_OPEN
|
|
||||||
assert data["ac3"]["zones"]["z01"]["value"] == 100
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
@ -92,12 +62,8 @@ async def test_ac_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_POSITION: 50},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_POSITION: 50},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["zones"]["z01"]["value"] == 50
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
@ -105,12 +71,8 @@ async def test_ac_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_POSITION: 0},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_POSITION: 0},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_CLOSE
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test controlling multiple Cover Zone Entity
|
# Test controlling multiple Cover Zone Entity
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -124,9 +86,9 @@ async def test_ac_cover(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
assert len(mock_update.mock_calls) == 2
|
||||||
assert data["ac3"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_CLOSE
|
mock_update.reset_mock()
|
||||||
assert data["ac3"]["zones"]["z02"]["state"] == ADVANTAGE_AIR_STATE_CLOSE
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
SERVICE_OPEN_COVER,
|
SERVICE_OPEN_COVER,
|
||||||
@ -138,27 +100,18 @@ async def test_ac_cover(
|
|||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac3"]["zones"]["z01"]["state"] == ADVANTAGE_AIR_STATE_OPEN
|
assert len(mock_update.mock_calls) == 2
|
||||||
assert data["ac3"]["zones"]["z02"]["state"] == ADVANTAGE_AIR_STATE_OPEN
|
|
||||||
|
|
||||||
|
|
||||||
async def test_things_cover(
|
async def test_things_cover(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test cover platform."""
|
"""Test cover platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Blind 1 Entity
|
# Test Blind 1 Entity
|
||||||
@ -171,7 +124,7 @@ async def test_things_cover(
|
|||||||
|
|
||||||
entry = entity_registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-200"
|
assert entry.unique_id == f"uniqueid-{thing_id}"
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
@ -179,13 +132,8 @@ async def test_things_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(thing_id)
|
|
||||||
assert data["id"] == thing_id
|
|
||||||
assert data["value"] == 0
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
COVER_DOMAIN,
|
COVER_DOMAIN,
|
||||||
@ -193,10 +141,4 @@ async def test_things_cover(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(thing_id)
|
|
||||||
assert data["id"] == thing_id
|
|
||||||
assert data["value"] == 100
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
@ -1,28 +1,24 @@
|
|||||||
"""Test the Advantage Air Diagnostics."""
|
"""Test the Advantage Air Diagnostics."""
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import TEST_SYSTEM_DATA, TEST_SYSTEM_URL, add_mock_config
|
from . import add_mock_config
|
||||||
|
|
||||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
from tests.typing import ClientSessionGenerator
|
from tests.typing import ClientSessionGenerator
|
||||||
|
|
||||||
|
|
||||||
async def test_select_async_setup_entry(
|
async def test_select_async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
hass_client: ClientSessionGenerator,
|
hass_client: ClientSessionGenerator,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
snapshot: SnapshotAssertion,
|
snapshot: SnapshotAssertion,
|
||||||
|
mock_get: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test select platform."""
|
"""Test select platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = await add_mock_config(hass)
|
entry = await add_mock_config(hass)
|
||||||
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
|
||||||
assert diag == snapshot
|
assert diag == snapshot
|
||||||
|
@ -1,22 +1,17 @@
|
|||||||
"""Test the Advantage Air Initialization."""
|
"""Test the Advantage Air Initialization."""
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from advantage_air import ApiError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from . import TEST_SYSTEM_DATA, TEST_SYSTEM_URL, add_mock_config
|
from . import add_mock_config, patch_get
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry(
|
async def test_async_setup_entry(hass: HomeAssistant, mock_get: AsyncMock) -> None:
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
||||||
) -> None:
|
|
||||||
"""Test a successful setup entry and unload."""
|
"""Test a successful setup entry and unload."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = await add_mock_config(hass)
|
entry = await add_mock_config(hass)
|
||||||
assert entry.state is ConfigEntryState.LOADED
|
assert entry.state is ConfigEntryState.LOADED
|
||||||
|
|
||||||
@ -25,15 +20,9 @@ async def test_async_setup_entry(
|
|||||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||||
|
|
||||||
|
|
||||||
async def test_async_setup_entry_failure(
|
async def test_async_setup_entry_failure(hass: HomeAssistant) -> None:
|
||||||
hass: HomeAssistant, aioclient_mock: AiohttpClientMocker
|
|
||||||
) -> None:
|
|
||||||
"""Test a unsuccessful setup entry."""
|
"""Test a unsuccessful setup entry."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
with patch_get(side_effect=ApiError):
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
exc=SyntaxError,
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = await add_mock_config(hass)
|
entry = await add_mock_config(hass)
|
||||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
"""Test the Advantage Air Switch Platform."""
|
"""Test the Advantage Air Switch Platform."""
|
||||||
from json import loads
|
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.const import (
|
|
||||||
ADVANTAGE_AIR_STATE_OFF,
|
from unittest.mock import AsyncMock
|
||||||
ADVANTAGE_AIR_STATE_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
DOMAIN as LIGHT_DOMAIN,
|
DOMAIN as LIGHT_DOMAIN,
|
||||||
@ -15,34 +13,17 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_LIGHT_URL,
|
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_light(
|
async def test_light(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test light setup."""
|
"""Test light setup."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_LIGHT_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Light Entity
|
# Test Light Entity
|
||||||
@ -62,13 +43,9 @@ async def test_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setLights"
|
mock_update.assert_called_once()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
mock_update.reset_mock()
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["state"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -76,13 +53,8 @@ async def test_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setLights"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["state"] == ADVANTAGE_AIR_STATE_OFF
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test Dimmable Light Entity
|
# Test Dimmable Light Entity
|
||||||
entity_id = "light.light_b"
|
entity_id = "light.light_b"
|
||||||
@ -98,13 +70,8 @@ async def test_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setLights"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["state"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -112,32 +79,17 @@ async def test_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_BRIGHTNESS: 128},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_BRIGHTNESS: 128},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setLights"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["value"] == 50
|
|
||||||
assert data["state"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_things_light(
|
async def test_things_light(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test things lights."""
|
"""Test things lights."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Switch Entity
|
# Test Switch Entity
|
||||||
@ -149,7 +101,7 @@ async def test_things_light(
|
|||||||
|
|
||||||
entry = entity_registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-204"
|
assert entry.unique_id == f"uniqueid-{light_id}"
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -157,13 +109,8 @@ async def test_things_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["value"] == 0
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -171,10 +118,4 @@ async def test_things_light(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ATTR_BRIGHTNESS: 128},
|
{ATTR_ENTITY_ID: [entity_id], ATTR_BRIGHTNESS: 128},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(light_id)
|
|
||||||
assert data["id"] == light_id
|
|
||||||
assert data["value"] == 50
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Test the Advantage Air Select Platform."""
|
"""Test the Advantage Air Select Platform."""
|
||||||
from json import loads
|
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.components.select import (
|
from homeassistant.components.select import (
|
||||||
ATTR_OPTION,
|
ATTR_OPTION,
|
||||||
@ -10,37 +12,19 @@ from homeassistant.const import ATTR_ENTITY_ID
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_select_async_setup_entry(
|
async def test_select_async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test select platform."""
|
"""Test select platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
|
||||||
|
|
||||||
# Test MyZone Select Entity
|
# Test MyZone Select Entity
|
||||||
entity_id = "select.myzone_myzone"
|
entity_id = "select.myzone_myzone"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -57,10 +41,4 @@ async def test_select_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: entity_id, ATTR_OPTION: "Zone 3"},
|
{ATTR_ENTITY_ID: entity_id, ATTR_OPTION: "Zone 3"},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(aioclient_mock.mock_calls) == 3
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["myZone"] == 3
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
"""Test the Advantage Air Sensor Platform."""
|
"""Test the Advantage Air Sensor Platform."""
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from json import loads
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.const import DOMAIN as ADVANTAGE_AIR_DOMAIN
|
from homeassistant.components.advantage_air.const import DOMAIN as ADVANTAGE_AIR_DOMAIN
|
||||||
from homeassistant.components.advantage_air.sensor import (
|
from homeassistant.components.advantage_air.sensor import (
|
||||||
@ -13,37 +13,21 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_sensor_platform(
|
async def test_sensor_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test sensor platform."""
|
"""Test sensor platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
assert len(aioclient_mock.mock_calls) == 1
|
|
||||||
|
|
||||||
# Test First TimeToOn Sensor
|
# Test First TimeToOn Sensor
|
||||||
entity_id = "sensor.myzone_time_to_on"
|
entity_id = "sensor.myzone_time_to_on"
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
@ -55,19 +39,15 @@ async def test_sensor_platform(
|
|||||||
assert entry.unique_id == "uniqueid-ac1-timetoOn"
|
assert entry.unique_id == "uniqueid-ac1-timetoOn"
|
||||||
|
|
||||||
value = 20
|
value = 20
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
ADVANTAGE_AIR_DOMAIN,
|
ADVANTAGE_AIR_DOMAIN,
|
||||||
ADVANTAGE_AIR_SERVICE_SET_TIME_TO,
|
ADVANTAGE_AIR_SERVICE_SET_TIME_TO,
|
||||||
{ATTR_ENTITY_ID: [entity_id], ADVANTAGE_AIR_SET_COUNTDOWN_VALUE: value},
|
{ATTR_ENTITY_ID: [entity_id], ADVANTAGE_AIR_SET_COUNTDOWN_VALUE: value},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(aioclient_mock.mock_calls) == 3
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.reset_mock()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["countDownToOn"] == value
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test First TimeToOff Sensor
|
# Test First TimeToOff Sensor
|
||||||
entity_id = "sensor.myzone_time_to_off"
|
entity_id = "sensor.myzone_time_to_off"
|
||||||
@ -86,13 +66,8 @@ async def test_sensor_platform(
|
|||||||
{ATTR_ENTITY_ID: [entity_id], ADVANTAGE_AIR_SET_COUNTDOWN_VALUE: value},
|
{ATTR_ENTITY_ID: [entity_id], ADVANTAGE_AIR_SET_COUNTDOWN_VALUE: value},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert len(aioclient_mock.mock_calls) == 5
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.reset_mock()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["countDownToOff"] == value
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
# Test First Zone Vent Sensor
|
# Test First Zone Vent Sensor
|
||||||
entity_id = "sensor.myzone_zone_open_with_sensor_vent"
|
entity_id = "sensor.myzone_zone_open_with_sensor_vent"
|
||||||
@ -139,6 +114,7 @@ async def test_sensor_platform(
|
|||||||
|
|
||||||
assert not hass.states.get(entity_id)
|
assert not hass.states.get(entity_id)
|
||||||
|
|
||||||
|
mock_get.reset_mock()
|
||||||
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
entity_registry.async_update_entity(entity_id=entity_id, disabled_by=None)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
@ -147,6 +123,7 @@ async def test_sensor_platform(
|
|||||||
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
dt_util.utcnow() + timedelta(seconds=RELOAD_AFTER_UPDATE_DELAY + 1),
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
assert len(mock_get.mock_calls) == 2
|
||||||
|
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert state
|
assert state
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
"""Test the Advantage Air Switch Platform."""
|
"""Test the Advantage Air Switch Platform."""
|
||||||
from json import loads
|
|
||||||
|
|
||||||
from homeassistant.components.advantage_air.const import (
|
|
||||||
ADVANTAGE_AIR_STATE_OFF,
|
from unittest.mock import AsyncMock
|
||||||
ADVANTAGE_AIR_STATE_ON,
|
|
||||||
)
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
DOMAIN as SWITCH_DOMAIN,
|
DOMAIN as SWITCH_DOMAIN,
|
||||||
SERVICE_TURN_OFF,
|
SERVICE_TURN_OFF,
|
||||||
@ -14,34 +12,17 @@ from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import (
|
from . import add_mock_config
|
||||||
TEST_SET_RESPONSE,
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
TEST_SET_URL,
|
|
||||||
TEST_SYSTEM_DATA,
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
add_mock_config,
|
|
||||||
)
|
|
||||||
|
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
|
||||||
|
|
||||||
async def test_cover_async_setup_entry(
|
async def test_cover_async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test switch platform."""
|
"""Test switch platform."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Switch Entity
|
# Test Switch Entity
|
||||||
@ -60,12 +41,8 @@ async def test_cover_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["freshAirStatus"] == ADVANTAGE_AIR_STATE_ON
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
@ -73,30 +50,17 @@ async def test_cover_async_setup_entry(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setAircon"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"])
|
|
||||||
assert data["ac1"]["info"]["freshAirStatus"] == ADVANTAGE_AIR_STATE_OFF
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_things_switch(
|
async def test_things_switch(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
|
mock_update: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test things switches."""
|
"""Test things switches."""
|
||||||
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=TEST_SYSTEM_DATA,
|
|
||||||
)
|
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SET_THING_URL,
|
|
||||||
text=TEST_SET_RESPONSE,
|
|
||||||
)
|
|
||||||
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
# Test Switch Entity
|
# Test Switch Entity
|
||||||
@ -108,7 +72,7 @@ async def test_things_switch(
|
|||||||
|
|
||||||
entry = entity_registry.async_get(entity_id)
|
entry = entity_registry.async_get(entity_id)
|
||||||
assert entry
|
assert entry
|
||||||
assert entry.unique_id == "uniqueid-205"
|
assert entry.unique_id == f"uniqueid-{thing_id}"
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
@ -116,13 +80,8 @@ async def test_things_switch(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
mock_update.reset_mock()
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(thing_id)
|
|
||||||
assert data["id"] == thing_id
|
|
||||||
assert data["value"] == 0
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
SWITCH_DOMAIN,
|
SWITCH_DOMAIN,
|
||||||
@ -130,10 +89,4 @@ async def test_things_switch(
|
|||||||
{ATTR_ENTITY_ID: [entity_id]},
|
{ATTR_ENTITY_ID: [entity_id]},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
assert aioclient_mock.mock_calls[-2][0] == "GET"
|
mock_update.assert_called_once()
|
||||||
assert aioclient_mock.mock_calls[-2][1].path == "/setThings"
|
|
||||||
data = loads(aioclient_mock.mock_calls[-2][1].query["json"]).get(thing_id)
|
|
||||||
assert data["id"] == thing_id
|
|
||||||
assert data["value"] == 100
|
|
||||||
assert aioclient_mock.mock_calls[-1][0] == "GET"
|
|
||||||
assert aioclient_mock.mock_calls[-1][1].path == "/getSystemData"
|
|
||||||
|
@ -1,25 +1,26 @@
|
|||||||
"""Test the Advantage Air Update Platform."""
|
"""Test the Advantage Air Update Platform."""
|
||||||
|
|
||||||
|
from unittest.mock import AsyncMock
|
||||||
|
|
||||||
|
from homeassistant.components.advantage_air.const import DOMAIN
|
||||||
from homeassistant.const import STATE_ON
|
from homeassistant.const import STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import entity_registry as er
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
from . import TEST_SYSTEM_URL, add_mock_config
|
from . import add_mock_config
|
||||||
|
|
||||||
from tests.common import load_fixture
|
from tests.common import load_json_object_fixture
|
||||||
from tests.test_util.aiohttp import AiohttpClientMocker
|
|
||||||
|
TEST_NEEDS_UPDATE = load_json_object_fixture("needsUpdate.json", DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def test_update_platform(
|
async def test_update_platform(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
aioclient_mock: AiohttpClientMocker,
|
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
mock_get: AsyncMock,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update platform."""
|
"""Test update platform."""
|
||||||
|
mock_get.return_value = TEST_NEEDS_UPDATE
|
||||||
aioclient_mock.get(
|
|
||||||
TEST_SYSTEM_URL,
|
|
||||||
text=load_fixture("advantage_air/needsUpdate.json"),
|
|
||||||
)
|
|
||||||
await add_mock_config(hass)
|
await add_mock_config(hass)
|
||||||
|
|
||||||
entity_id = "update.testname_app"
|
entity_id = "update.testname_app"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user