mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Fix HomeKit covers with device class window and no tilt (#61566)
This commit is contained in:
parent
c3e72bec0a
commit
8200101785
@ -249,14 +249,17 @@ class OpeningDeviceBase(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update cover position and tilt after state changed."""
|
"""Update cover position and tilt after state changed."""
|
||||||
# update tilt
|
# update tilt
|
||||||
|
if not self._supports_tilt:
|
||||||
|
return
|
||||||
current_tilt = new_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
|
current_tilt = new_state.attributes.get(ATTR_CURRENT_TILT_POSITION)
|
||||||
if isinstance(current_tilt, (float, int)):
|
if not isinstance(current_tilt, (float, int)):
|
||||||
# HomeKit sends values between -90 and 90.
|
return
|
||||||
# We'll have to normalize to [0,100]
|
# HomeKit sends values between -90 and 90.
|
||||||
current_tilt = (current_tilt / 100.0 * 180.0) - 90.0
|
# We'll have to normalize to [0,100]
|
||||||
current_tilt = int(current_tilt)
|
current_tilt = (current_tilt / 100.0 * 180.0) - 90.0
|
||||||
self.char_current_tilt.set_value(current_tilt)
|
current_tilt = int(current_tilt)
|
||||||
self.char_target_tilt.set_value(current_tilt)
|
self.char_current_tilt.set_value(current_tilt)
|
||||||
|
self.char_target_tilt.set_value(current_tilt)
|
||||||
|
|
||||||
|
|
||||||
class OpeningDevice(OpeningDeviceBase, HomeAccessory):
|
class OpeningDevice(OpeningDeviceBase, HomeAccessory):
|
||||||
|
@ -223,11 +223,15 @@ async def test_windowcovering_set_cover_position(hass, hk_driver, events):
|
|||||||
assert events[-1].data[ATTR_VALUE] == 75
|
assert events[-1].data[ATTR_VALUE] == 75
|
||||||
|
|
||||||
|
|
||||||
async def test_window_instantiate(hass, hk_driver, events):
|
async def test_window_instantiate_set_position(hass, hk_driver, events):
|
||||||
"""Test if Window accessory is instantiated correctly."""
|
"""Test if Window accessory is instantiated correctly and can set position."""
|
||||||
entity_id = "cover.window"
|
entity_id = "cover.window"
|
||||||
|
|
||||||
hass.states.async_set(entity_id, None)
|
hass.states.async_set(
|
||||||
|
entity_id,
|
||||||
|
STATE_OPEN,
|
||||||
|
{ATTR_SUPPORTED_FEATURES: SUPPORT_SET_POSITION, ATTR_CURRENT_POSITION: 0},
|
||||||
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
acc = Window(hass, hk_driver, "Window", entity_id, 2, None)
|
acc = Window(hass, hk_driver, "Window", entity_id, 2, None)
|
||||||
await acc.run()
|
await acc.run()
|
||||||
@ -239,6 +243,29 @@ async def test_window_instantiate(hass, hk_driver, events):
|
|||||||
assert acc.char_current_position.value == 0
|
assert acc.char_current_position.value == 0
|
||||||
assert acc.char_target_position.value == 0
|
assert acc.char_target_position.value == 0
|
||||||
|
|
||||||
|
hass.states.async_set(
|
||||||
|
entity_id,
|
||||||
|
STATE_OPEN,
|
||||||
|
{ATTR_SUPPORTED_FEATURES: SUPPORT_SET_POSITION, ATTR_CURRENT_POSITION: 50},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_current_position.value == 50
|
||||||
|
assert acc.char_target_position.value == 50
|
||||||
|
assert acc.char_position_state.value == 2
|
||||||
|
|
||||||
|
hass.states.async_set(
|
||||||
|
entity_id,
|
||||||
|
STATE_OPEN,
|
||||||
|
{
|
||||||
|
ATTR_SUPPORTED_FEATURES: SUPPORT_SET_POSITION,
|
||||||
|
ATTR_CURRENT_POSITION: "GARBAGE",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_current_position.value == 50
|
||||||
|
assert acc.char_target_position.value == 50
|
||||||
|
assert acc.char_position_state.value == 2
|
||||||
|
|
||||||
|
|
||||||
async def test_windowcovering_cover_set_tilt(hass, hk_driver, events):
|
async def test_windowcovering_cover_set_tilt(hass, hk_driver, events):
|
||||||
"""Test if accessory and HA update slat tilt accordingly."""
|
"""Test if accessory and HA update slat tilt accordingly."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user