This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

@@ -6,14 +6,15 @@ 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
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')
accessories = await setup_accessories_from_file(hass, "aqara_gateway.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
@@ -21,24 +22,28 @@ async def test_aqara_gateway_setup(hass):
# 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'
assert alarm.unique_id == "homekit-0000000123456789-66304"
alarm_helper = Helper(
hass, 'alarm_control_panel.aqara_hub_1563', pairing, accessories[0],
config_entry
hass,
"alarm_control_panel.aqara_hub_1563",
pairing,
accessories[0],
config_entry,
)
alarm_state = await alarm_helper.poll_and_get_state()
assert alarm_state.attributes['friendly_name'] == 'Aqara Hub-1563'
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 = 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], config_entry)
hass, "light.aqara_hub_1563", pairing, accessories[0], config_entry
)
light_state = await light_helper.poll_and_get_state()
assert light_state.attributes['friendly_name'] == 'Aqara Hub-1563'
assert light_state.attributes['supported_features'] == (
assert light_state.attributes["friendly_name"] == "Aqara Hub-1563"
assert light_state.attributes["supported_features"] == (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR
)
@@ -49,8 +54,8 @@ async def test_aqara_gateway_setup(hass):
assert alarm.device_id == light.device_id
device = device_registry.async_get(light.device_id)
assert device.manufacturer == 'Aqara'
assert device.name == 'Aqara Hub-1563'
assert device.model == 'ZHWA11LM'
assert device.sw_version == '1.4.7'
assert device.manufacturer == "Aqara"
assert device.name == "Aqara Hub-1563"
assert device.model == "ZHWA11LM"
assert device.sw_version == "1.4.7"
assert device.via_device_id is None
@@ -10,132 +10,139 @@ from homekit import AccessoryDisconnectedError
from homeassistant.config_entries import ENTRY_STATE_SETUP_RETRY
from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_HUMIDITY)
SUPPORT_TARGET_TEMPERATURE,
SUPPORT_TARGET_HUMIDITY,
)
from tests.components.homekit_controller.common import (
FakePairing, device_config_changed, setup_accessories_from_file,
setup_test_accessories, Helper, time_changed
FakePairing,
device_config_changed,
setup_accessories_from_file,
setup_test_accessories,
Helper,
time_changed,
)
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')
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
config_entry, 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 = entity_registry.async_get("climate.homew")
assert climate.unique_id == "homekit-123456789012-16"
climate_helper = Helper(
hass, 'climate.homew', pairing, accessories[0], config_entry
hass, "climate.homew", pairing, accessories[0], config_entry
)
climate_state = await climate_helper.poll_and_get_state()
assert climate_state.attributes['friendly_name'] == 'HomeW'
assert climate_state.attributes['supported_features'] == (
assert climate_state.attributes["friendly_name"] == "HomeW"
assert climate_state.attributes["supported_features"] == (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_HUMIDITY
)
assert climate_state.attributes['hvac_modes'] == [
'off',
'heat',
'cool',
'heat_cool',
assert climate_state.attributes["hvac_modes"] == [
"off",
"heat",
"cool",
"heat_cool",
]
assert climate_state.attributes['min_temp'] == 7.2
assert climate_state.attributes['max_temp'] == 33.3
assert climate_state.attributes['min_humidity'] == 20
assert climate_state.attributes['max_humidity'] == 50
assert climate_state.attributes["min_temp"] == 7.2
assert climate_state.attributes["max_temp"] == 33.3
assert climate_state.attributes["min_humidity"] == 20
assert climate_state.attributes["max_humidity"] == 50
occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56'
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], config_entry)
hass, "binary_sensor.kitchen", pairing, accessories[0], config_entry
)
occ1_state = await occ1_helper.poll_and_get_state()
assert occ1_state.attributes['friendly_name'] == 'Kitchen'
assert occ1_state.attributes["friendly_name"] == "Kitchen"
occ2 = entity_registry.async_get('binary_sensor.porch')
assert occ2.unique_id == 'homekit-AB2C-56'
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'
occ3 = entity_registry.async_get("binary_sensor.basement")
assert occ3.unique_id == "homekit-AB3C-56"
device_registry = await hass.helpers.device_registry.async_get_registry()
climate_device = device_registry.async_get(climate.device_id)
assert climate_device.manufacturer == 'ecobee Inc.'
assert climate_device.name == 'HomeW'
assert climate_device.model == 'ecobee3'
assert climate_device.sw_version == '4.2.394'
assert climate_device.manufacturer == "ecobee Inc."
assert climate_device.name == "HomeW"
assert climate_device.model == "ecobee3"
assert climate_device.sw_version == "4.2.394"
assert climate_device.via_device_id is None
# Check that an attached sensor has its own device entity that
# is linked to the bridge
sensor_device = device_registry.async_get(occ1.device_id)
assert sensor_device.manufacturer == 'ecobee Inc.'
assert sensor_device.name == 'Kitchen'
assert sensor_device.model == 'REMOTE SENSOR'
assert sensor_device.sw_version == '1.0.0'
assert sensor_device.manufacturer == "ecobee Inc."
assert sensor_device.name == "Kitchen"
assert sensor_device.model == "REMOTE SENSOR"
assert sensor_device.sw_version == "1.0.0"
assert sensor_device.via_device_id == climate_device.id
async def test_ecobee3_setup_from_cache(hass, hass_storage):
"""Test that Ecbobee can be correctly setup from its cached entity map."""
accessories = await setup_accessories_from_file(hass, 'ecobee3.json')
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
hass_storage['homekit_controller-entity-map'] = {
'version': 1,
'data': {
'pairings': {
'00:00:00:00:00:00': {
'config_num': 1,
'accessories': [
hass_storage["homekit_controller-entity-map"] = {
"version": 1,
"data": {
"pairings": {
"00:00:00:00:00:00": {
"config_num": 1,
"accessories": [
a.to_accessory_and_service_list() for a in accessories
],
}
}
}
},
}
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 = entity_registry.async_get("climate.homew")
assert climate.unique_id == "homekit-123456789012-16"
occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56'
occ1 = entity_registry.async_get("binary_sensor.kitchen")
assert occ1.unique_id == "homekit-AB1C-56"
occ2 = entity_registry.async_get('binary_sensor.porch')
assert occ2.unique_id == 'homekit-AB2C-56'
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'
occ3 = entity_registry.async_get("binary_sensor.basement")
assert occ3.unique_id == "homekit-AB3C-56"
async def test_ecobee3_setup_connection_failure(hass):
"""Test that Ecbobee can be correctly setup from its cached entity map."""
accessories = await setup_accessories_from_file(hass, 'ecobee3.json')
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
entity_registry = await hass.helpers.entity_registry.async_get_registry()
# Test that the connection fails during initial setup.
# No entities should be created.
list_accessories = 'list_accessories_and_characteristics'
list_accessories = "list_accessories_and_characteristics"
with mock.patch.object(FakePairing, list_accessories) as laac:
laac.side_effect = AccessoryDisconnectedError('Connection failed')
laac.side_effect = AccessoryDisconnectedError("Connection failed")
# If there is no cached entity map and the accessory connection is
# failing then we have to fail the config entry setup.
config_entry, pairing = await setup_test_accessories(hass, accessories)
assert config_entry.state == ENTRY_STATE_SETUP_RETRY
climate = entity_registry.async_get('climate.homew')
climate = entity_registry.async_get("climate.homew")
assert climate is None
# When accessory raises ConfigEntryNoteReady HA will retry - lets make
@@ -147,22 +154,22 @@ async def test_ecobee3_setup_connection_failure(hass):
# make sure the IpPairing mock is in place or we'll try to connect to
# a real device. Normally this mocking is done by the helper in
# setup_test_accessories.
pairing_cls_loc = 'homekit.controller.ip_implementation.IpPairing'
pairing_cls_loc = "homekit.controller.ip_implementation.IpPairing"
with mock.patch(pairing_cls_loc) as pairing_cls:
pairing_cls.return_value = pairing
await time_changed(hass, 5 * 60)
climate = entity_registry.async_get('climate.homew')
assert climate.unique_id == 'homekit-123456789012-16'
climate = entity_registry.async_get("climate.homew")
assert climate.unique_id == "homekit-123456789012-16"
occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56'
occ1 = entity_registry.async_get("binary_sensor.kitchen")
assert occ1.unique_id == "homekit-AB1C-56"
occ2 = entity_registry.async_get('binary_sensor.porch')
assert occ2.unique_id == 'homekit-AB2C-56'
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'
occ3 = entity_registry.async_get("binary_sensor.basement")
assert occ3.unique_id == "homekit-AB3C-56"
async def test_ecobee3_add_sensors_at_runtime(hass):
@@ -171,32 +178,31 @@ async def test_ecobee3_add_sensors_at_runtime(hass):
# Set up a base Ecobee 3 with no additional sensors.
# There shouldn't be any entities but climate visible.
accessories = await setup_accessories_from_file(
hass, 'ecobee3_no_sensors.json')
accessories = await setup_accessories_from_file(hass, "ecobee3_no_sensors.json")
await setup_test_accessories(hass, accessories)
climate = entity_registry.async_get('climate.homew')
assert climate.unique_id == 'homekit-123456789012-16'
climate = entity_registry.async_get("climate.homew")
assert climate.unique_id == "homekit-123456789012-16"
occ1 = entity_registry.async_get('binary_sensor.kitchen')
occ1 = entity_registry.async_get("binary_sensor.kitchen")
assert occ1 is None
occ2 = entity_registry.async_get('binary_sensor.porch')
occ2 = entity_registry.async_get("binary_sensor.porch")
assert occ2 is None
occ3 = entity_registry.async_get('binary_sensor.basement')
occ3 = entity_registry.async_get("binary_sensor.basement")
assert occ3 is None
# Now added 3 new sensors at runtime - sensors should appear and climate
# shouldn't be duplicated.
accessories = await setup_accessories_from_file(hass, 'ecobee3.json')
accessories = await setup_accessories_from_file(hass, "ecobee3.json")
await device_config_changed(hass, accessories)
occ1 = entity_registry.async_get('binary_sensor.kitchen')
assert occ1.unique_id == 'homekit-AB1C-56'
occ1 = entity_registry.async_get("binary_sensor.kitchen")
assert occ1.unique_id == "homekit-AB1C-56"
occ2 = entity_registry.async_get('binary_sensor.porch')
assert occ2.unique_id == 'homekit-AB2C-56'
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'
occ3 = entity_registry.async_get("binary_sensor.basement")
assert occ3.unique_id == "homekit-AB3C-56"
@@ -10,64 +10,61 @@ import homeassistant.util.dt as dt_util
from homeassistant.components.light import SUPPORT_BRIGHTNESS, SUPPORT_COLOR
from tests.common import async_fire_time_changed
from tests.components.homekit_controller.common import (
setup_accessories_from_file, setup_test_accessories, FakePairing, Helper
setup_accessories_from_file,
setup_test_accessories,
FakePairing,
Helper,
)
LIGHT_ON = ('lightbulb', 'on')
LIGHT_ON = ("lightbulb", "on")
async def test_koogeek_ls1_setup(hass):
"""Test that a Koogeek LS1 can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, 'koogeek_ls1.json')
accessories = await setup_accessories_from_file(hass, "koogeek_ls1.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('light.koogeek_ls1_20833f')
assert entry.unique_id == 'homekit-AAAA011111111111-7'
entry = entity_registry.async_get("light.koogeek_ls1_20833f")
assert entry.unique_id == "homekit-AAAA011111111111-7"
helper = Helper(
hass,
'light.koogeek_ls1_20833f',
pairing,
accessories[0],
config_entry
hass, "light.koogeek_ls1_20833f", 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'] == 'Koogeek-LS1-20833F'
assert state.attributes["friendly_name"] == "Koogeek-LS1-20833F"
# Assert that all optional features the LS1 supports are detected
assert state.attributes['supported_features'] == (
assert state.attributes["supported_features"] == (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR
)
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entry.device_id)
assert device.manufacturer == 'Koogeek'
assert device.name == 'Koogeek-LS1-20833F'
assert device.model == 'LS1'
assert device.sw_version == '2.2.15'
assert device.manufacturer == "Koogeek"
assert device.name == "Koogeek-LS1-20833F"
assert device.model == "LS1"
assert device.sw_version == "2.2.15"
assert device.via_device_id is None
@pytest.mark.parametrize('failure_cls', [
AccessoryDisconnectedError, EncryptionError
])
@pytest.mark.parametrize("failure_cls", [AccessoryDisconnectedError, EncryptionError])
async def test_recover_from_failure(hass, utcnow, failure_cls):
"""
Test that entity actually recovers from a network connection drop.
See https://github.com/home-assistant/home-assistant/issues/18949
"""
accessories = await setup_accessories_from_file(hass, 'koogeek_ls1.json')
accessories = await setup_accessories_from_file(hass, "koogeek_ls1.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
helper = Helper(
hass, 'light.koogeek_ls1_20833f', pairing, accessories[0], config_entry
hass, "light.koogeek_ls1_20833f", pairing, accessories[0], config_entry
)
# Set light state on fake device to off
@@ -75,18 +72,18 @@ async def test_recover_from_failure(hass, utcnow, failure_cls):
# Test that entity starts off in a known state
state = await helper.poll_and_get_state()
assert state.state == 'off'
assert state.state == "off"
# Set light state on fake device to on
helper.characteristics[LIGHT_ON].set_value(True)
# Test that entity remains in the same state if there is a network error
next_update = dt_util.utcnow() + timedelta(seconds=60)
with mock.patch.object(FakePairing, 'get_characteristics') as get_char:
get_char.side_effect = failure_cls('Disconnected')
with mock.patch.object(FakePairing, "get_characteristics") as get_char:
get_char.side_effect = failure_cls("Disconnected")
state = await helper.poll_and_get_state()
assert state.state == 'off'
assert state.state == "off"
chars = get_char.call_args[0][0]
assert set(chars) == {(1, 8), (1, 9), (1, 10), (1, 11)}
@@ -97,4 +94,4 @@ async def test_recover_from_failure(hass, utcnow, failure_cls):
await hass.async_block_till_done()
state = await helper.poll_and_get_state()
assert state.state == 'on'
assert state.state == "on"
@@ -4,39 +4,40 @@ Regression tests for Aqara Gateway V3.
https://github.com/home-assistant/home-assistant/issues/20885
"""
from homeassistant.components.climate.const import (
SUPPORT_TARGET_TEMPERATURE)
from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE
from tests.components.homekit_controller.common import (
setup_accessories_from_file, setup_test_accessories, Helper
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')
accessories = await setup_accessories_from_file(hass, "lennox_e30.json")
config_entry, 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 = entity_registry.async_get("climate.lennox")
assert climate.unique_id == "homekit-XXXXXXXX-100"
climate_helper = Helper(
hass, 'climate.lennox', pairing, accessories[0], config_entry
hass, "climate.lennox", pairing, accessories[0], config_entry
)
climate_state = await climate_helper.poll_and_get_state()
assert climate_state.attributes['friendly_name'] == 'Lennox'
assert climate_state.attributes['supported_features'] == (
assert climate_state.attributes["friendly_name"] == "Lennox"
assert climate_state.attributes["supported_features"] == (
SUPPORT_TARGET_TEMPERATURE
)
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(climate.device_id)
assert device.manufacturer == 'Lennox'
assert device.name == 'Lennox'
assert device.model == 'E30 2B'
assert device.sw_version == '3.40.XX'
assert device.manufacturer == "Lennox"
assert device.name == "Lennox"
assert device.model == "E30 2B"
assert device.sw_version == "3.40.XX"
# The fixture contains a single accessory - so its a single device
# and no bridge