mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 22:10:09 +00:00
Add support for Faucet services in HomeKit Controller (#129094)
This commit is contained in:
@@ -27,6 +27,14 @@ def create_switch_service(accessory: Accessory) -> None:
|
||||
outlet_in_use.value = False
|
||||
|
||||
|
||||
def create_faucet_service(accessory: Accessory) -> None:
|
||||
"""Define faucet characteristics."""
|
||||
service = accessory.add_service(ServicesTypes.FAUCET)
|
||||
|
||||
active_char = service.add_char(CharacteristicsTypes.ACTIVE)
|
||||
active_char.value = False
|
||||
|
||||
|
||||
def create_valve_service(accessory: Accessory) -> None:
|
||||
"""Define valve characteristics."""
|
||||
service = accessory.add_service(ServicesTypes.VALVE)
|
||||
@@ -115,6 +123,58 @@ async def test_switch_read_outlet_state(
|
||||
assert switch_1.attributes["outlet_in_use"] is True
|
||||
|
||||
|
||||
async def test_faucet_change_active_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can turn a HomeKit outlet on and off again."""
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_faucet_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_on", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAUCET,
|
||||
{
|
||||
CharacteristicsTypes.ACTIVE: 1,
|
||||
},
|
||||
)
|
||||
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_off", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
helper.async_assert_service_values(
|
||||
ServicesTypes.FAUCET,
|
||||
{
|
||||
CharacteristicsTypes.ACTIVE: 0,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def test_faucet_read_active_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
"""Test that we can read the state of a HomeKit outlet accessory."""
|
||||
helper = await setup_test_component(hass, get_next_aid(), create_faucet_service)
|
||||
|
||||
# Initial state is that the switch is off and the outlet isn't in use
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == "off"
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
switch_1 = await helper.async_update(
|
||||
ServicesTypes.FAUCET,
|
||||
{CharacteristicsTypes.ACTIVE: True},
|
||||
)
|
||||
assert switch_1.state == "on"
|
||||
|
||||
# Simulate that device switched off in the real world not via HA
|
||||
switch_1 = await helper.async_update(
|
||||
ServicesTypes.FAUCET,
|
||||
{CharacteristicsTypes.ACTIVE: False},
|
||||
)
|
||||
assert switch_1.state == "off"
|
||||
|
||||
|
||||
async def test_valve_change_active_state(
|
||||
hass: HomeAssistant, get_next_aid: Callable[[], int]
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user