mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Improve fans in homekit_controller (#74440)
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
"perms": ["pr", "pw", "ev"],
|
||||
"ev": true,
|
||||
"format": "bool",
|
||||
"value": false
|
||||
"value": true
|
||||
},
|
||||
{
|
||||
"aid": 1,
|
||||
@@ -83,7 +83,7 @@
|
||||
"minValue": 0,
|
||||
"maxValue": 3,
|
||||
"minStep": 1,
|
||||
"value": 3
|
||||
"value": 2
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
from homeassistant.components.climate.const import (
|
||||
SUPPORT_FAN_MODE,
|
||||
SUPPORT_TARGET_HUMIDITY,
|
||||
SUPPORT_TARGET_TEMPERATURE,
|
||||
SUPPORT_TARGET_TEMPERATURE_RANGE,
|
||||
@@ -43,9 +44,11 @@ async def test_ecobee501_setup(hass):
|
||||
SUPPORT_TARGET_TEMPERATURE
|
||||
| SUPPORT_TARGET_TEMPERATURE_RANGE
|
||||
| SUPPORT_TARGET_HUMIDITY
|
||||
| SUPPORT_FAN_MODE
|
||||
),
|
||||
capabilities={
|
||||
"hvac_modes": ["off", "heat", "cool", "heat_cool"],
|
||||
"fan_modes": ["on", "auto"],
|
||||
"min_temp": 7.2,
|
||||
"max_temp": 33.3,
|
||||
"min_humidity": 20,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Make sure that a H.A.A. fan can be setup."""
|
||||
|
||||
from homeassistant.components.fan import SUPPORT_SET_SPEED
|
||||
from homeassistant.components.fan import ATTR_PERCENTAGE, SUPPORT_SET_SPEED
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
|
||||
from tests.components.homekit_controller.common import (
|
||||
@@ -18,7 +18,9 @@ async def test_haa_fan_setup(hass):
|
||||
accessories = await setup_accessories_from_file(hass, "haa_fan.json")
|
||||
await setup_test_accessories(hass, accessories)
|
||||
|
||||
# FIXME: assert round(state.attributes["percentage_step"], 2) == 33.33
|
||||
haa_fan_state = hass.states.get("fan.haa_c718b3")
|
||||
attributes = haa_fan_state.attributes
|
||||
assert attributes[ATTR_PERCENTAGE] == 66
|
||||
|
||||
await assert_devices_and_entities_created(
|
||||
hass,
|
||||
@@ -55,7 +57,7 @@ async def test_haa_fan_setup(hass):
|
||||
entity_id="fan.haa_c718b3",
|
||||
friendly_name="HAA-C718B3",
|
||||
unique_id="homekit-C718B3-1-8",
|
||||
state="off",
|
||||
state="on",
|
||||
supported_features=SUPPORT_SET_SPEED,
|
||||
capabilities={
|
||||
"preset_modes": None,
|
||||
|
||||
@@ -10,6 +10,7 @@ from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from homeassistant.components.climate.const import (
|
||||
DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
SERVICE_SET_SWING_MODE,
|
||||
@@ -32,6 +33,9 @@ def create_thermostat_service(accessory):
|
||||
char = service.add_char(CharacteristicsTypes.HEATING_COOLING_CURRENT)
|
||||
char.value = 0
|
||||
|
||||
char = service.add_char(CharacteristicsTypes.FAN_STATE_TARGET)
|
||||
char.value = 0
|
||||
|
||||
char = service.add_char(CharacteristicsTypes.TEMPERATURE_COOLING_THRESHOLD)
|
||||
char.minValue = 15
|
||||
char.maxValue = 40
|
||||
@@ -144,6 +148,32 @@ async def test_climate_change_thermostat_state(hass, utcnow):
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
{"entity_id": "climate.testdevice", "fan_mode": "on"},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.THERMOSTAT,
|
||||
{
|
||||
CharacteristicsTypes.FAN_STATE_TARGET: 0,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_FAN_MODE,
|
||||
{"entity_id": "climate.testdevice", "fan_mode": "auto"},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.THERMOSTAT,
|
||||
{
|
||||
CharacteristicsTypes.FAN_STATE_TARGET: 1,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def test_climate_check_min_max_values_per_mode(hass, utcnow):
|
||||
"""Test that we we get the appropriate min/max values for each mode."""
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Basic checks for HomeKit motion sensors and contact sensors."""
|
||||
"""Basic checks for HomeKit fans."""
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
@@ -41,6 +41,20 @@ def create_fanv2_service(accessory):
|
||||
swing_mode.value = 0
|
||||
|
||||
|
||||
def create_fanv2_service_non_standard_rotation_range(accessory):
|
||||
"""Define fan v2 with a non-standard rotation range."""
|
||||
service = accessory.add_service(ServicesTypes.FAN_V2)
|
||||
|
||||
cur_state = service.add_char(CharacteristicsTypes.ACTIVE)
|
||||
cur_state.value = 0
|
||||
|
||||
speed = service.add_char(CharacteristicsTypes.ROTATION_SPEED)
|
||||
speed.value = 0
|
||||
speed.minValue = 0
|
||||
speed.maxValue = 3
|
||||
speed.minStep = 1
|
||||
|
||||
|
||||
def create_fanv2_service_with_min_step(accessory):
|
||||
"""Define fan v2 characteristics as per HAP spec."""
|
||||
service = accessory.add_service(ServicesTypes.FAN_V2)
|
||||
@@ -730,3 +744,64 @@ async def test_v2_oscillate_read(hass, utcnow):
|
||||
ServicesTypes.FAN_V2, {CharacteristicsTypes.SWING_MODE: 1}
|
||||
)
|
||||
assert state.attributes["oscillating"] is True
|
||||
|
||||
|
||||
async def test_v2_set_percentage_non_standard_rotation_range(hass, utcnow):
|
||||
"""Test that we set fan speed with a non-standard rotation range."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_fanv2_service_non_standard_rotation_range
|
||||
)
|
||||
|
||||
await helper.async_update(ServicesTypes.FAN_V2, {CharacteristicsTypes.ACTIVE: 1})
|
||||
|
||||
await hass.services.async_call(
|
||||
"fan",
|
||||
"set_percentage",
|
||||
{"entity_id": "fan.testdevice", "percentage": 100},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAN_V2,
|
||||
{
|
||||
CharacteristicsTypes.ROTATION_SPEED: 3,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"fan",
|
||||
"set_percentage",
|
||||
{"entity_id": "fan.testdevice", "percentage": 66},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAN_V2,
|
||||
{
|
||||
CharacteristicsTypes.ROTATION_SPEED: 2,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"fan",
|
||||
"set_percentage",
|
||||
{"entity_id": "fan.testdevice", "percentage": 33},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAN_V2,
|
||||
{
|
||||
CharacteristicsTypes.ROTATION_SPEED: 1,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"fan",
|
||||
"set_percentage",
|
||||
{"entity_id": "fan.testdevice", "percentage": 0},
|
||||
blocking=True,
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAN_V2,
|
||||
{
|
||||
CharacteristicsTypes.ACTIVE: 0,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -26,26 +26,6 @@ def create_switch_with_spray_level(accessory):
|
||||
return service
|
||||
|
||||
|
||||
def create_switch_with_ecobee_fan_mode(accessory):
|
||||
"""Define battery level characteristics."""
|
||||
service = accessory.add_service(ServicesTypes.OUTLET)
|
||||
|
||||
ecobee_fan_mode = service.add_char(
|
||||
CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED
|
||||
)
|
||||
|
||||
ecobee_fan_mode.value = 0
|
||||
ecobee_fan_mode.minStep = 1
|
||||
ecobee_fan_mode.minValue = 0
|
||||
ecobee_fan_mode.maxValue = 100
|
||||
ecobee_fan_mode.format = "float"
|
||||
|
||||
cur_state = service.add_char(CharacteristicsTypes.ON)
|
||||
cur_state.value = True
|
||||
|
||||
return service
|
||||
|
||||
|
||||
async def test_read_number(hass, utcnow):
|
||||
"""Test a switch service that has a sensor characteristic is correctly handled."""
|
||||
helper = await setup_test_component(hass, create_switch_with_spray_level)
|
||||
@@ -106,72 +86,3 @@ async def test_write_number(hass, utcnow):
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: 3},
|
||||
)
|
||||
|
||||
|
||||
async def test_write_ecobee_fan_mode_number(hass, utcnow):
|
||||
"""Test a switch service that has a sensor characteristic is correctly handled."""
|
||||
helper = await setup_test_component(hass, create_switch_with_ecobee_fan_mode)
|
||||
|
||||
# Helper will be for the primary entity, which is the outlet. Make a helper for the sensor.
|
||||
fan_mode = Helper(
|
||||
hass,
|
||||
"number.testdevice_fan_mode",
|
||||
helper.pairing,
|
||||
helper.accessory,
|
||||
helper.config_entry,
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"number",
|
||||
"set_value",
|
||||
{"entity_id": "number.testdevice_fan_mode", "value": 1},
|
||||
blocking=True,
|
||||
)
|
||||
fan_mode.async_assert_service_values(
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: 1},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"number",
|
||||
"set_value",
|
||||
{"entity_id": "number.testdevice_fan_mode", "value": 2},
|
||||
blocking=True,
|
||||
)
|
||||
fan_mode.async_assert_service_values(
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: 2},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"number",
|
||||
"set_value",
|
||||
{"entity_id": "number.testdevice_fan_mode", "value": 99},
|
||||
blocking=True,
|
||||
)
|
||||
fan_mode.async_assert_service_values(
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: 99},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"number",
|
||||
"set_value",
|
||||
{"entity_id": "number.testdevice_fan_mode", "value": 100},
|
||||
blocking=True,
|
||||
)
|
||||
fan_mode.async_assert_service_values(
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: 100},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"number",
|
||||
"set_value",
|
||||
{"entity_id": "number.testdevice_fan_mode", "value": 0},
|
||||
blocking=True,
|
||||
)
|
||||
fan_mode.async_assert_service_values(
|
||||
ServicesTypes.OUTLET,
|
||||
{CharacteristicsTypes.VENDOR_ECOBEE_FAN_WRITE_SPEED: 0},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user