Add support for homekit valve accessories to homekit_controller (#32937)
This commit is contained in:
5 files changed
+1351
-17
No files matched your search
@@ -0,0 +1,65 @@
|
||||
"""
|
||||
Make sure that existing RainMachine support isn't broken.
|
||||
|
||||
https://github.com/home-assistant/core/issues/31745
|
||||
"""
|
||||
|
||||
from tests.components.homekit_controller.common import (
|
||||
Helper,
|
||||
setup_accessories_from_file,
|
||||
setup_test_accessories,
|
||||
)
|
||||
|
||||
|
||||
async def test_rainmachine_pro_8_setup(hass):
|
||||
"""Test that a RainMachine can be correctly setup in HA."""
|
||||
accessories = await setup_accessories_from_file(hass, "rainmachine-pro-8.json")
|
||||
config_entry, pairing = await setup_test_accessories(hass, accessories)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
# Assert that the entity is correctly added to the entity registry
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-512"
|
||||
|
||||
helper = Helper(
|
||||
hass, "switch.rainmachine_00ce4a", pairing, accessories[0], config_entry
|
||||
)
|
||||
state = await helper.poll_and_get_state()
|
||||
|
||||
# Assert that the friendly name is detected correctly
|
||||
assert state.attributes["friendly_name"] == "RainMachine-00ce4a"
|
||||
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
device = device_registry.async_get(entry.device_id)
|
||||
assert device.manufacturer == "Green Electronics LLC"
|
||||
assert device.name == "RainMachine-00ce4a"
|
||||
assert device.model == "SPK5 Pro"
|
||||
assert device.sw_version == "1.0.4"
|
||||
assert device.via_device_id is None
|
||||
|
||||
# The device is made up of multiple valves - make sure we have enumerated them all
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_2")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-768"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_3")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-1024"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_4")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-1280"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_5")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-1536"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_6")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-1792"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_7")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-2048"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_8")
|
||||
assert entry.unique_id == "homekit-00aa0000aa0a-2304"
|
||||
|
||||
entry = entity_registry.async_get("switch.rainmachine_00ce4a_9")
|
||||
assert entry is None
|
||||
@@ -1,6 +1,10 @@
|
||||
"""Basic checks for HomeKitSwitch."""
|
||||
|
||||
from aiohomekit.model.characteristics import CharacteristicsTypes
|
||||
from aiohomekit.model.characteristics import (
|
||||
CharacteristicsTypes,
|
||||
InUseValues,
|
||||
IsConfiguredValues,
|
||||
)
|
||||
from aiohomekit.model.services import ServicesTypes
|
||||
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
@@ -17,6 +21,23 @@ def create_switch_service(accessory):
|
||||
outlet_in_use.value = False
|
||||
|
||||
|
||||
def create_valve_service(accessory):
|
||||
"""Define valve characteristics."""
|
||||
service = accessory.add_service(ServicesTypes.VALVE)
|
||||
|
||||
on_char = service.add_char(CharacteristicsTypes.ACTIVE)
|
||||
on_char.value = False
|
||||
|
||||
in_use = service.add_char(CharacteristicsTypes.IN_USE)
|
||||
in_use.value = InUseValues.IN_USE
|
||||
|
||||
configured = service.add_char(CharacteristicsTypes.IS_CONFIGURED)
|
||||
configured.value = IsConfiguredValues.CONFIGURED
|
||||
|
||||
remaining = service.add_char(CharacteristicsTypes.REMAINING_DURATION)
|
||||
remaining.value = 99
|
||||
|
||||
|
||||
async def test_switch_change_outlet_state(hass, utcnow):
|
||||
"""Test that we can turn a HomeKit outlet on and off again."""
|
||||
helper = await setup_test_component(hass, create_switch_service)
|
||||
@@ -57,3 +78,47 @@ async def test_switch_read_outlet_state(hass, utcnow):
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == "off"
|
||||
assert switch_1.attributes["outlet_in_use"] is True
|
||||
|
||||
|
||||
async def test_valve_change_active_state(hass, utcnow):
|
||||
"""Test that we can turn a valve on and off again."""
|
||||
helper = await setup_test_component(hass, create_valve_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_on", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[("valve", "active")].value == 1
|
||||
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_off", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[("valve", "active")].value == 0
|
||||
|
||||
|
||||
async def test_valve_read_state(hass, utcnow):
|
||||
"""Test that we can read the state of a valve accessory."""
|
||||
helper = await setup_test_component(hass, create_valve_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"
|
||||
assert switch_1.attributes["in_use"] is True
|
||||
assert switch_1.attributes["is_configured"] is True
|
||||
assert switch_1.attributes["remaining_duration"] == 99
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
helper.characteristics[("valve", "active")].set_value(True)
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == "on"
|
||||
|
||||
# Simulate that someone configured the device in the real world not via HA
|
||||
helper.characteristics[
|
||||
("valve", "is-configured")
|
||||
].value = IsConfiguredValues.NOT_CONFIGURED
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.attributes["is_configured"] is False
|
||||
|
||||
# Simulate that someone using the device in the real world not via HA
|
||||
helper.characteristics[("valve", "in-use")].value = InUseValues.NOT_IN_USE
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.attributes["in_use"] is False
|
||||
Reference in new issue
Block a user