Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
53c3e25
Add HomeKit Door accessory type
Dexwell Oct 21, 2022
ed6e722
Replace absolute positioning check with open/close
Dexwell Oct 22, 2022
4503911
feat: adding testing for the door type cover
jredd Jan 14, 2023
217ea79
Merge pull request #1 from jredd/feat-tests-for-door-cover
Dexwell Jan 14, 2023
21086a4
Merge branch 'dev' into homekit_door_accessory
jredd Jan 14, 2023
24ca92b
Merge branch 'dev' into homekit_door_accessory
bdraco Jan 17, 2023
3336dec
Fixed stale comment
Dexwell Jan 17, 2023
3fa617d
lint
bdraco Jan 17, 2023
b77bc0a
Base Door on Window instead of GarageDoorOpener
Dexwell Jan 20, 2023
0f76705
Base Door on Window
Dexwell Jan 20, 2023
8360d1f
Test Door the same way as Window
Dexwell Feb 2, 2023
d5aedd0
Fixes for flake8
Dexwell Feb 3, 2023
a41de92
Merge branch 'home-assistant:dev' into homekit_door_accessory
Dexwell Feb 3, 2023
7f7e1ab
Fix Black?
Dexwell Feb 3, 2023
b1d8f5d
Merge branch 'homekit_door_accessory' of https://github.com/Dexwell/c…
Dexwell Feb 3, 2023
e7af58c
Merge branch 'home-assistant:dev' into homekit_door_accessory
Dexwell Feb 3, 2023
5136a45
Merge latest changes
Dexwell Feb 13, 2023
7f5e9b1
Merge remote-tracking branch 'upstream/dev' into homekit_door_accessory
Dexwell Feb 13, 2023
38c48fd
Merge branch 'home-assistant:dev' into homekit_door_accessory
Dexwell Feb 13, 2023
6188b1f
Merge branch 'dev' into homekit_door_accessory
bdraco Feb 20, 2023
5d779f9
Merge branch 'dev' into homekit_door_accessory
Dexwell Feb 23, 2023
33c5c88
Merge branch 'dev' into homekit_door_accessory
bdraco Mar 2, 2023
f92a04b
Merge branch 'dev' into homekit_door_accessory
bdraco Mar 7, 2023
a4a936a
add missing coverage
bdraco Mar 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions homeassistant/components/homekit/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def get_accessory( # noqa: C901
and features & CoverEntityFeature.SET_POSITION
):
a_type = "Window"
elif (
device_class == CoverDeviceClass.DOOR
and features & CoverEntityFeature.SET_POSITION
Comment thread
Dexwell marked this conversation as resolved.
):
a_type = "Door"
elif features & CoverEntityFeature.SET_POSITION:
a_type = "WindowCovering"
elif features & (CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE):
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/homekit/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
SERV_CARBON_DIOXIDE_SENSOR = "CarbonDioxideSensor"
SERV_CARBON_MONOXIDE_SENSOR = "CarbonMonoxideSensor"
SERV_CONTACT_SENSOR = "ContactSensor"
SERV_DOOR = "Door"
SERV_DOORBELL = "Doorbell"
SERV_FANV2 = "Fanv2"
SERV_GARAGE_DOOR_OPENER = "GarageDoorOpener"
Expand Down
14 changes: 14 additions & 0 deletions homeassistant/components/homekit/type_covers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging

from pyhap.const import (
CATEGORY_DOOR,
CATEGORY_GARAGE_DOOR_OPENER,
CATEGORY_WINDOW,
CATEGORY_WINDOW_COVERING,
Expand Down Expand Up @@ -54,6 +55,7 @@
HK_POSITION_STOPPED,
PROP_MAX_VALUE,
PROP_MIN_VALUE,
SERV_DOOR,
SERV_GARAGE_DOOR_OPENER,
SERV_WINDOW,
SERV_WINDOW_COVERING,
Expand Down Expand Up @@ -323,6 +325,18 @@ def async_update_state(self, new_state: State) -> None:
super().async_update_state(new_state)


@TYPES.register("Door")
class Door(OpeningDevice):
"""Generate a Door accessory for a cover entity.

The entity must support: set_cover_position.
"""

def __init__(self, *args):
"""Initialize a Door accessory object."""
super().__init__(*args, category=CATEGORY_DOOR, service=SERV_DOOR)


@TYPES.register("Window")
class Window(OpeningDevice):
"""Generate a Window accessory for a cover entity with WINDOW device class.
Expand Down
9 changes: 9 additions & 0 deletions tests/components/homekit/test_get_accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ def test_types(type_name, entity_id, state, attrs, config) -> None:
)
},
),
(
"Door",
"cover.door",
"open",
{
ATTR_DEVICE_CLASS: "door",
ATTR_SUPPORTED_FEATURES: cover.SUPPORT_SET_POSITION,
},
),
],
)
def test_type_covers(type_name, entity_id, state, attrs) -> None:
Expand Down
53 changes: 53 additions & 0 deletions tests/components/homekit/test_type_covers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
PROP_MIN_VALUE,
)
from homeassistant.components.homekit.type_covers import (
Door,
GarageDoorOpener,
Window,
WindowCovering,
Expand Down Expand Up @@ -128,6 +129,58 @@ async def test_garage_door_open_close(hass: HomeAssistant, hk_driver, events) ->
assert events[-1].data[ATTR_VALUE] is None


async def test_door_instantiate_set_position(
hass: HomeAssistant, hk_driver, events
) -> None:
"""Test if Door accessory is instantiated correctly and can set position."""
entity_id = "cover.door"

hass.states.async_set(
entity_id,
STATE_OPEN,
{
ATTR_SUPPORTED_FEATURES: CoverEntityFeature.SET_POSITION,
ATTR_CURRENT_POSITION: 0,
},
)
await hass.async_block_till_done()
acc = Door(hass, hk_driver, "Door", entity_id, 2, None)
await acc.run()
await hass.async_block_till_done()

assert acc.aid == 2
assert acc.category == 12 # Door

assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0

hass.states.async_set(
entity_id,
STATE_OPEN,
{
ATTR_SUPPORTED_FEATURES: CoverEntityFeature.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: CoverEntityFeature.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_set_cover_position(
hass: HomeAssistant, hk_driver, events
) -> None:
Expand Down