hass-core/tests/components/nexia/test_number.py
Benjamin Paul [MSFT] 5965918c86
Add Fan Speed number entity to Nexia ()
* 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

62 lines
2 KiB
Python

"""The number entity tests for the nexia platform."""
from homeassistant.components.number import (
ATTR_VALUE,
DOMAIN as NUMBER_DOMAIN,
SERVICE_SET_VALUE,
)
from homeassistant.core import HomeAssistant
from .util import async_init_integration
async def test_create_fan_speed_number_entities(hass: HomeAssistant) -> None:
"""Test creation of fan speed number entities."""
await async_init_integration(hass)
state = hass.states.get("number.master_suite_fan_speed")
assert state.state == "35.0"
expected_attributes = {
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Master Suite Fan speed",
"min": 35,
"max": 100,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
assert all(
state.attributes[key] == expected_attributes[key] for key in expected_attributes
)
state = hass.states.get("number.downstairs_east_wing_fan_speed")
assert state.state == "35.0"
expected_attributes = {
"attribution": "Data provided by Trane Technologies",
"friendly_name": "Downstairs East Wing Fan speed",
"min": 35,
"max": 100,
}
# Only test for a subset of attributes in case
# HA changes the implementation and a new one appears
assert all(
state.attributes[key] == expected_attributes[key] for key in expected_attributes
)
async def test_set_fan_speed(hass: HomeAssistant) -> None:
"""Test setting fan speed."""
await async_init_integration(hass)
state_before = hass.states.get("number.master_suite_fan_speed")
assert state_before.state == "35.0"
await hass.services.async_call(
NUMBER_DOMAIN,
SERVICE_SET_VALUE,
service_data={ATTR_VALUE: 50},
blocking=True,
target={"entity_id": "number.master_suite_fan_speed"},
)
state = hass.states.get("number.master_suite_fan_speed")
assert state.state == "50.0"