mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Handle tilt position being None in HKC (#117141)
This commit is contained in:
parent
e4a3cab801
commit
4138c7a0ef
@ -212,13 +212,15 @@ class HomeKitWindowCover(HomeKitEntity, CoverEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_tilt_position(self) -> int:
|
def current_cover_tilt_position(self) -> int | None:
|
||||||
"""Return current position of cover tilt."""
|
"""Return current position of cover tilt."""
|
||||||
tilt_position = self.service.value(CharacteristicsTypes.VERTICAL_TILT_CURRENT)
|
tilt_position = self.service.value(CharacteristicsTypes.VERTICAL_TILT_CURRENT)
|
||||||
if not tilt_position:
|
if not tilt_position:
|
||||||
tilt_position = self.service.value(
|
tilt_position = self.service.value(
|
||||||
CharacteristicsTypes.HORIZONTAL_TILT_CURRENT
|
CharacteristicsTypes.HORIZONTAL_TILT_CURRENT
|
||||||
)
|
)
|
||||||
|
if tilt_position is None:
|
||||||
|
return None
|
||||||
# Recalculate to convert from arcdegree scale to percentage scale.
|
# Recalculate to convert from arcdegree scale to percentage scale.
|
||||||
if self.is_vertical_tilt:
|
if self.is_vertical_tilt:
|
||||||
scale = 0.9
|
scale = 0.9
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||||
from aiohomekit.model.services import ServicesTypes
|
from aiohomekit.model.services import ServicesTypes
|
||||||
|
|
||||||
|
from homeassistant.const import STATE_UNAVAILABLE
|
||||||
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
|
||||||
|
|
||||||
@ -94,6 +95,24 @@ def create_window_covering_service_with_v_tilt_2(accessory):
|
|||||||
tilt_target.maxValue = 0
|
tilt_target.maxValue = 0
|
||||||
|
|
||||||
|
|
||||||
|
def create_window_covering_service_with_none_tilt(accessory):
|
||||||
|
"""Define a window-covering characteristics as per page 219 of HAP spec.
|
||||||
|
|
||||||
|
This accessory uses None for the tilt value unexpectedly.
|
||||||
|
"""
|
||||||
|
service = create_window_covering_service(accessory)
|
||||||
|
|
||||||
|
tilt_current = service.add_char(CharacteristicsTypes.VERTICAL_TILT_CURRENT)
|
||||||
|
tilt_current.value = None
|
||||||
|
tilt_current.minValue = -90
|
||||||
|
tilt_current.maxValue = 0
|
||||||
|
|
||||||
|
tilt_target = service.add_char(CharacteristicsTypes.VERTICAL_TILT_TARGET)
|
||||||
|
tilt_target.value = None
|
||||||
|
tilt_target.minValue = -90
|
||||||
|
tilt_target.maxValue = 0
|
||||||
|
|
||||||
|
|
||||||
async def test_change_window_cover_state(hass: HomeAssistant) -> None:
|
async def test_change_window_cover_state(hass: HomeAssistant) -> None:
|
||||||
"""Test that we can turn a HomeKit alarm on and off again."""
|
"""Test that we can turn a HomeKit alarm on and off again."""
|
||||||
helper = await setup_test_component(hass, create_window_covering_service)
|
helper = await setup_test_component(hass, create_window_covering_service)
|
||||||
@ -212,6 +231,21 @@ async def test_read_window_cover_tilt_vertical_2(hass: HomeAssistant) -> None:
|
|||||||
assert state.attributes["current_tilt_position"] == 83
|
assert state.attributes["current_tilt_position"] == 83
|
||||||
|
|
||||||
|
|
||||||
|
async def test_read_window_cover_tilt_missing_tilt(hass: HomeAssistant) -> None:
|
||||||
|
"""Test that missing tilt is handled."""
|
||||||
|
helper = await setup_test_component(
|
||||||
|
hass, create_window_covering_service_with_none_tilt
|
||||||
|
)
|
||||||
|
|
||||||
|
await helper.async_update(
|
||||||
|
ServicesTypes.WINDOW_COVERING,
|
||||||
|
{CharacteristicsTypes.OBSTRUCTION_DETECTED: True},
|
||||||
|
)
|
||||||
|
state = await helper.poll_and_get_state()
|
||||||
|
assert "current_tilt_position" not in state.attributes
|
||||||
|
assert state.state != STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
|
||||||
async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
async def test_write_window_cover_tilt_horizontal(hass: HomeAssistant) -> None:
|
||||||
"""Test that horizontal tilt is written correctly."""
|
"""Test that horizontal tilt is written correctly."""
|
||||||
helper = await setup_test_component(
|
helper = await setup_test_component(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user