hass-core/tests/components/nexia/util.py
Benjamin Paul [MSFT] 5965918c86
Add Fan Speed number entity to Nexia (#98642)
* Add Fan Speed support to Nexia integration

Adds a new "set_fan_speed" service to the Nexia integration, to allow
setting speed of the air-handler/blower fans.

* Add Fan Speed to Nexia Tests

* Remove mistakenly-added changes to Climate tests

A previous version of this change made modifications to the base
Climate entity, but that approach was later abandonded. These changes
to Climate tests were left over from that, and should never have been
included.

* Add Fan Speed Number Entity

* Remove Set Fan Speed Service

* Remove fan_speed attribute

The fan_speed attribute is not necessary with the new Number entity.

* Address reviewer feedback

Rename test function to reflect fact that fan speed entities are
entities, and not sensors.
Added missing typing to variables.
Sorted list of platforms

* Add test_set_fan_speed

Also adds new test fixture for mock response to API call

* Update homeassistant/components/nexia/number.py

* Name change

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
2023-08-19 16:42:13 +02:00

63 lines
2.1 KiB
Python

"""Tests for the nexia integration."""
from unittest.mock import patch
import uuid
from nexia.home import NexiaHome
from homeassistant.components.nexia.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
from tests.test_util.aiohttp import mock_aiohttp_client
async def async_init_integration(
hass: HomeAssistant,
skip_setup: bool = False,
exception: Exception | None = None,
) -> MockConfigEntry:
"""Set up the nexia integration in Home Assistant."""
house_fixture = "nexia/mobile_houses_123456.json"
session_fixture = "nexia/session_123456.json"
sign_in_fixture = "nexia/sign_in.json"
set_fan_speed_fixture = "nexia/set_fan_speed_2293892.json"
with mock_aiohttp_client() as mock_session, patch(
"nexia.home.load_or_create_uuid", return_value=uuid.uuid4()
):
nexia = NexiaHome(mock_session)
if exception:
async def _raise_exception(*args, **kwargs):
raise exception
mock_session.post(
nexia.API_MOBILE_SESSION_URL, side_effect=_raise_exception
)
else:
mock_session.post(
nexia.API_MOBILE_SESSION_URL, text=load_fixture(session_fixture)
)
mock_session.get(
nexia.API_MOBILE_HOUSES_URL.format(house_id=123456),
text=load_fixture(house_fixture),
)
mock_session.post(
nexia.API_MOBILE_ACCOUNTS_SIGN_IN_URL,
text=load_fixture(sign_in_fixture),
)
mock_session.post(
"https://www.mynexia.com/mobile/xxl_thermostats/2293892/fan_speed",
text=load_fixture(set_fan_speed_fixture),
)
entry = MockConfigEntry(
domain=DOMAIN, data={CONF_USERNAME: "mock", CONF_PASSWORD: "mock"}
)
entry.add_to_hass(hass)
if not skip_setup:
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry