Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more HomeKit device enumeration tests #22194

Merged
merged 3 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 9 additions & 4 deletions tests/components/homekit_controller/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Code to support homekit_controller tests."""
import json
import os
from datetime import timedelta
from unittest import mock

Expand All @@ -12,7 +13,8 @@
DOMAIN, HOMEKIT_ACCESSORY_DISPATCH, SERVICE_HOMEKIT)
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
from tests.common import async_fire_time_changed, fire_service_discovered
from tests.common import (
async_fire_time_changed, fire_service_discovered, load_fixture)


class FakePairing:
Expand Down Expand Up @@ -148,10 +150,13 @@ def add_characteristic(self, name):
return char


def setup_accessories_from_file(path):
async def setup_accessories_from_file(hass, path):
"""Load an collection of accessory defs from JSON data."""
with open(path, 'r') as accessories_data:
accessories_json = json.load(accessories_data)
accessories_fixture = await hass.async_add_executor_job(
load_fixture,
os.path.join('homekit_controller', path),
)
accessories_json = json.loads(accessories_fixture)

accessories = []

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
Regression tests for Aqara Gateway V3.

https://github.com/home-assistant/home-assistant/issues/20957
"""

from homeassistant.components.light import SUPPORT_BRIGHTNESS, SUPPORT_COLOR
from tests.components.homekit_controller.common import (
setup_accessories_from_file, setup_test_accessories, Helper
)


async def test_aqara_gateway_setup(hass):
"""Test that a Aqara Gateway can be correctly setup in HA."""
accessories = await setup_accessories_from_file(
hass, 'aqara_gateway.json')
pairing = await setup_test_accessories(hass, accessories)

entity_registry = await hass.helpers.entity_registry.async_get_registry()

# Check that the light is correctly found and set up
alarm_id = "alarm_control_panel.aqara_hub_1563"
alarm = entity_registry.async_get(alarm_id)
assert alarm.unique_id == 'homekit-0000000123456789-66304'

alarm_helper = Helper(
hass, 'alarm_control_panel.aqara_hub_1563', pairing, accessories[0])
alarm_state = await alarm_helper.poll_and_get_state()
assert alarm_state.attributes['friendly_name'] == 'Aqara Hub-1563'

# Check that the light is correctly found and set up
light = entity_registry.async_get('light.aqara_hub_1563')
assert light.unique_id == 'homekit-0000000123456789-65792'

light_helper = Helper(
hass, 'light.aqara_hub_1563', pairing, accessories[0])
light_state = await light_helper.poll_and_get_state()
assert light_state.attributes['friendly_name'] == 'Aqara Hub-1563'
assert light_state.attributes['supported_features'] == (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Regression tests for Ecobee 3.

https://github.com/home-assistant/home-assistant/issues/15336
"""

from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
from tests.components.homekit_controller.common import (
setup_accessories_from_file, setup_test_accessories, Helper
)


async def test_ecobee3_setup(hass):
"""Test that a Ecbobee 3 can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, 'ecobee3.json')
pairing = await setup_test_accessories(hass, accessories)

entity_registry = await hass.helpers.entity_registry.async_get_registry()

climate = entity_registry.async_get('climate.homew')
assert climate.unique_id == 'homekit-123456789012-16'

climate_helper = Helper(hass, 'climate.homew', pairing, accessories[0])
climate_state = await climate_helper.poll_and_get_state()
assert climate_state.attributes['friendly_name'] == 'HomeW'
assert climate_state.attributes['supported_features'] == (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
)

occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56'

occ1_helper = Helper(
hass, 'binary_sensor.kitchen', pairing, accessories[0])
occ1_state = await occ1_helper.poll_and_get_state()
assert occ1_state.attributes['friendly_name'] == 'Kitchen'

occ2 = entity_registry.async_get('binary_sensor.porch')
assert occ2.unique_id == 'homekit-AB2C-56'

occ3 = entity_registry.async_get('binary_sensor.basement')
assert occ3.unique_id == 'homekit-AB3C-56'
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Make sure that existing Koogeek LS1 support isn't broken."""

import os
from datetime import timedelta
from unittest import mock

Expand All @@ -19,8 +18,7 @@

async def test_koogeek_ls1_setup(hass):
"""Test that a Koogeek LS1 can be correctly setup in HA."""
profile_path = os.path.join(os.path.dirname(__file__), 'koogeek_ls1.json')
accessories = setup_accessories_from_file(profile_path)
accessories = await setup_accessories_from_file(hass, 'koogeek_ls1.json')
pairing = await setup_test_accessories(hass, accessories)

entity_registry = await hass.helpers.entity_registry.async_get_registry()
Expand Down Expand Up @@ -50,8 +48,7 @@ async def test_recover_from_failure(hass, utcnow, failure_cls):

See https://github.com/home-assistant/home-assistant/issues/18949
"""
profile_path = os.path.join(os.path.dirname(__file__), 'koogeek_ls1.json')
accessories = setup_accessories_from_file(profile_path)
accessories = await setup_accessories_from_file(hass, 'koogeek_ls1.json')
pairing = await setup_test_accessories(hass, accessories)

helper = Helper(hass, 'light.koogeek_ls1_20833f', pairing, accessories[0])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Regression tests for Aqara Gateway V3.

https://github.com/home-assistant/home-assistant/issues/20885
"""

from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, SUPPORT_OPERATION_MODE)
from tests.components.homekit_controller.common import (
setup_accessories_from_file, setup_test_accessories, Helper
)


async def test_lennox_e30_setup(hass):
"""Test that a Lennox E30 can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, 'lennox_e30.json')
pairing = await setup_test_accessories(hass, accessories)

entity_registry = await hass.helpers.entity_registry.async_get_registry()

climate = entity_registry.async_get('climate.lennox')
assert climate.unique_id == 'homekit-XXXXXXXX-100'

climate_helper = Helper(hass, 'climate.lennox', pairing, accessories[0])
climate_state = await climate_helper.poll_and_get_state()
assert climate_state.attributes['friendly_name'] == 'Lennox'
assert climate_state.attributes['supported_features'] == (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_OPERATION_MODE
)
Loading