Add faucet, shower, sprinkler, valve to HomeKit (#17145)
This commit is contained in:
1 parent
2e62afabdc
commit
37a47b5a59
7 files changed
+168
-12
No files matched your search
@@ -9,7 +9,8 @@ import homeassistant.components.climate as climate
|
||||
import homeassistant.components.media_player as media_player
|
||||
from homeassistant.components.homekit import get_accessory, TYPES
|
||||
from homeassistant.components.homekit.const import (
|
||||
CONF_FEATURE_LIST, FEATURE_ON_OFF, TYPE_OUTLET, TYPE_SWITCH)
|
||||
CONF_FEATURE_LIST, FEATURE_ON_OFF, TYPE_FAUCET, TYPE_OUTLET, TYPE_SHOWER,
|
||||
TYPE_SPRINKLER, TYPE_SWITCH, TYPE_VALVE)
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE, ATTR_DEVICE_CLASS, ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, CONF_TYPE, TEMP_CELSIUS,
|
||||
@@ -140,6 +141,10 @@ def test_type_sensors(type_name, entity_id, state, attrs):
|
||||
('Switch', 'script.test', 'on', {}, {}),
|
||||
('Switch', 'switch.test', 'on', {}, {}),
|
||||
('Switch', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_SWITCH}),
|
||||
('Valve', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_FAUCET}),
|
||||
('Valve', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_VALVE}),
|
||||
('Valve', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_SHOWER}),
|
||||
('Valve', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_SPRINKLER}),
|
||||
])
|
||||
def test_type_switches(type_name, entity_id, state, attrs, config):
|
||||
"""Test if switch types are associated correctly."""
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
"""Test different accessory types: Switches."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.homekit.type_switches import Outlet, Switch
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_OFF, STATE_ON
|
||||
from homeassistant.components.homekit.const import (
|
||||
TYPE_FAUCET, TYPE_SHOWER, TYPE_SPRINKLER, TYPE_VALVE)
|
||||
from homeassistant.components.homekit.type_switches import (
|
||||
Outlet, Switch, Valve)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, CONF_TYPE, STATE_OFF, STATE_ON
|
||||
from homeassistant.core import split_entity_id
|
||||
|
||||
from tests.common import async_mock_service
|
||||
@@ -90,3 +93,70 @@ async def test_switch_set_state(hass, hk_driver, entity_id):
|
||||
await hass.async_block_till_done()
|
||||
assert call_turn_off
|
||||
assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
|
||||
|
||||
|
||||
async def test_valve_set_state(hass, hk_driver):
|
||||
"""Test if Valve accessory and HA are updated accordingly."""
|
||||
entity_id = 'switch.valve_test'
|
||||
|
||||
hass.states.async_set(entity_id, None)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
acc = Valve(hass, hk_driver, 'Valve', entity_id, 2,
|
||||
{CONF_TYPE: TYPE_FAUCET})
|
||||
await hass.async_add_job(acc.run)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 29 # Faucet
|
||||
assert acc.char_valve_type.value == 3 # Water faucet
|
||||
|
||||
acc = Valve(hass, hk_driver, 'Valve', entity_id, 2,
|
||||
{CONF_TYPE: TYPE_SHOWER})
|
||||
await hass.async_add_job(acc.run)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 30 # Shower
|
||||
assert acc.char_valve_type.value == 2 # Shower head
|
||||
|
||||
acc = Valve(hass, hk_driver, 'Valve', entity_id, 2,
|
||||
{CONF_TYPE: TYPE_SPRINKLER})
|
||||
await hass.async_add_job(acc.run)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.category == 28 # Sprinkler
|
||||
assert acc.char_valve_type.value == 1 # Irrigation
|
||||
|
||||
acc = Valve(hass, hk_driver, 'Valve', entity_id, 2,
|
||||
{CONF_TYPE: TYPE_VALVE})
|
||||
await hass.async_add_job(acc.run)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.aid == 2
|
||||
assert acc.category == 29 # Faucet
|
||||
|
||||
assert acc.char_active.value is False
|
||||
assert acc.char_in_use.value is False
|
||||
assert acc.char_valve_type.value == 0 # Generic Valve
|
||||
|
||||
hass.states.async_set(entity_id, STATE_ON)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_active.value is True
|
||||
assert acc.char_in_use.value is True
|
||||
|
||||
hass.states.async_set(entity_id, STATE_OFF)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_active.value is False
|
||||
assert acc.char_in_use.value is False
|
||||
|
||||
# Set from HomeKit
|
||||
call_turn_on = async_mock_service(hass, 'switch', 'turn_on')
|
||||
call_turn_off = async_mock_service(hass, 'switch', 'turn_off')
|
||||
|
||||
await hass.async_add_job(acc.char_active.client_update_value, True)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_in_use.value is True
|
||||
assert call_turn_on
|
||||
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
|
||||
|
||||
await hass.async_add_job(acc.char_active.client_update_value, False)
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_in_use.value is False
|
||||
assert call_turn_off
|
||||
assert call_turn_off[0].data[ATTR_ENTITY_ID] == entity_id
|
||||
@@ -4,7 +4,8 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.components.homekit.const import (
|
||||
CONF_FEATURE, CONF_FEATURE_LIST, HOMEKIT_NOTIFY_ID, FEATURE_ON_OFF,
|
||||
FEATURE_PLAY_PAUSE, TYPE_OUTLET)
|
||||
FEATURE_PLAY_PAUSE, TYPE_FAUCET, TYPE_OUTLET, TYPE_SHOWER, TYPE_SPRINKLER,
|
||||
TYPE_SWITCH, TYPE_VALVE)
|
||||
from homeassistant.components.homekit.util import (
|
||||
convert_to_float, density_to_air_quality, dismiss_setup_message,
|
||||
show_setup_message, temperature_to_homekit, temperature_to_states,
|
||||
@@ -58,8 +59,19 @@ def test_validate_entity_config():
|
||||
assert vec({'media_player.demo': config}) == \
|
||||
{'media_player.demo': {CONF_FEATURE_LIST:
|
||||
{FEATURE_ON_OFF: {}, FEATURE_PLAY_PAUSE: {}}}}
|
||||
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_FAUCET}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_FAUCET}}
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_OUTLET}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_OUTLET}}
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_SHOWER}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_SHOWER}}
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_SPRINKLER}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_SPRINKLER}}
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_SWITCH}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_SWITCH}}
|
||||
assert vec({'switch.demo': {CONF_TYPE: TYPE_VALVE}}) == \
|
||||
{'switch.demo': {CONF_TYPE: TYPE_VALVE}}
|
||||
|
||||
|
||||
def test_validate_media_player_features():
|
||||
|
||||
Reference in new issue
Block a user