Fix of cover-tilt in homekit_controller (#91631)
* Fix of cover-tilt in homekit_controller * Fix of cover-tilt and its tests
This commit is contained in:
parent
9231010402
commit
393dbb6dc0
2 changed files with 159 additions and 4 deletions
|
@ -39,9 +39,28 @@ def create_window_covering_service_with_h_tilt(accessory):
|
|||
|
||||
tilt_current = service.add_char(CharacteristicsTypes.HORIZONTAL_TILT_CURRENT)
|
||||
tilt_current.value = 0
|
||||
tilt_current.minValue = 0
|
||||
tilt_current.maxValue = 90
|
||||
|
||||
tilt_target = service.add_char(CharacteristicsTypes.HORIZONTAL_TILT_TARGET)
|
||||
tilt_target.value = 0
|
||||
tilt_target.minValue = 0
|
||||
tilt_target.maxValue = 90
|
||||
|
||||
|
||||
def create_window_covering_service_with_h_tilt_2(accessory):
|
||||
"""Define a window-covering characteristics as per page 219 of HAP spec."""
|
||||
service = create_window_covering_service(accessory)
|
||||
|
||||
tilt_current = service.add_char(CharacteristicsTypes.HORIZONTAL_TILT_CURRENT)
|
||||
tilt_current.value = 0
|
||||
tilt_current.minValue = -90
|
||||
tilt_current.maxValue = 0
|
||||
|
||||
tilt_target = service.add_char(CharacteristicsTypes.HORIZONTAL_TILT_TARGET)
|
||||
tilt_target.value = 0
|
||||
tilt_target.minValue = -90
|
||||
tilt_target.maxValue = 0
|
||||
|
||||
|
||||
def create_window_covering_service_with_v_tilt(accessory):
|
||||
|
@ -50,9 +69,28 @@ def create_window_covering_service_with_v_tilt(accessory):
|
|||
|
||||
tilt_current = service.add_char(CharacteristicsTypes.VERTICAL_TILT_CURRENT)
|
||||
tilt_current.value = 0
|
||||
tilt_current.minValue = 0
|
||||
tilt_current.maxValue = 90
|
||||
|
||||
tilt_target = service.add_char(CharacteristicsTypes.VERTICAL_TILT_TARGET)
|
||||
tilt_target.value = 0
|
||||
tilt_target.minValue = 0
|
||||
tilt_target.maxValue = 90
|
||||
|
||||
|
||||
def create_window_covering_service_with_v_tilt_2(accessory):
|
||||
"""Define a window-covering characteristics as per page 219 of HAP spec."""
|
||||
service = create_window_covering_service(accessory)
|
||||
|
||||
tilt_current = service.add_char(CharacteristicsTypes.VERTICAL_TILT_CURRENT)
|
||||
tilt_current.value = 0
|
||||
tilt_current.minValue = -90
|
||||
tilt_current.maxValue = 0
|
||||
|
||||
tilt_target = service.add_char(CharacteristicsTypes.VERTICAL_TILT_TARGET)
|
||||
tilt_target.value = 0
|
||||
tilt_target.minValue = -90
|
||||
tilt_target.maxValue = 0
|
||||
|
||||
|
||||
async def test_change_window_cover_state(hass: HomeAssistant, utcnow) -> None:
|
||||
|
@ -124,7 +162,23 @@ async def test_read_window_cover_tilt_horizontal(hass: HomeAssistant, utcnow) ->
|
|||
{CharacteristicsTypes.HORIZONTAL_TILT_CURRENT: 75},
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["current_tilt_position"] == 75
|
||||
# Expect converted value from arcdegree scale to percentage scale.
|
||||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_horizontal_2(hass: HomeAssistant, utcnow) -> None:
|
||||
"""Test that horizontal tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt_2
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{CharacteristicsTypes.HORIZONTAL_TILT_CURRENT: -75},
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
# Expect converted value from arcdegree scale to percentage scale.
|
||||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_vertical(hass: HomeAssistant, utcnow) -> None:
|
||||
|
@ -138,7 +192,23 @@ async def test_read_window_cover_tilt_vertical(hass: HomeAssistant, utcnow) -> N
|
|||
{CharacteristicsTypes.VERTICAL_TILT_CURRENT: 75},
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["current_tilt_position"] == 75
|
||||
# Expect converted value from arcdegree scale to percentage scale.
|
||||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_vertical_2(hass: HomeAssistant, utcnow) -> None:
|
||||
"""Test that vertical tilt is handled correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt_2
|
||||
)
|
||||
|
||||
await helper.async_update(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{CharacteristicsTypes.VERTICAL_TILT_CURRENT: -75},
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
# Expect converted value from arcdegree scale to percentage scale.
|
||||
assert state.attributes["current_tilt_position"] == 83
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant, utcnow) -> None:
|
||||
|
@ -153,10 +223,34 @@ async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant, utcnow) -
|
|||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
# Expect converted value from percentage scale to arcdegree scale.
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{
|
||||
CharacteristicsTypes.HORIZONTAL_TILT_TARGET: 90,
|
||||
CharacteristicsTypes.HORIZONTAL_TILT_TARGET: 81,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_horizontal_2(
|
||||
hass: HomeAssistant, utcnow
|
||||
) -> None:
|
||||
"""Test that horizontal tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_h_tilt_2
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_tilt_position",
|
||||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
# Expect converted value from percentage scale to arcdegree scale.
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{
|
||||
CharacteristicsTypes.HORIZONTAL_TILT_TARGET: -81,
|
||||
},
|
||||
)
|
||||
|
||||
|
@ -173,10 +267,32 @@ async def test_write_window_cover_tilt_vertical(hass: HomeAssistant, utcnow) ->
|
|||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
# Expect converted value from percentage scale to arcdegree scale.
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{
|
||||
CharacteristicsTypes.VERTICAL_TILT_TARGET: 90,
|
||||
CharacteristicsTypes.VERTICAL_TILT_TARGET: 81,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_vertical_2(hass: HomeAssistant, utcnow) -> None:
|
||||
"""Test that vertical tilt is written correctly."""
|
||||
helper = await setup_test_component(
|
||||
hass, create_window_covering_service_with_v_tilt_2
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_tilt_position",
|
||||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
# Expect converted value from percentage scale to arcdegree scale.
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.WINDOW_COVERING,
|
||||
{
|
||||
CharacteristicsTypes.VERTICAL_TILT_TARGET: -81,
|
||||
},
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue