mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Black
This commit is contained in:
@@ -6,20 +6,23 @@ from unittest import mock
|
||||
|
||||
from homekit.model.services import AbstractService, ServicesTypes
|
||||
from homekit.model.characteristics import (
|
||||
AbstractCharacteristic, CharacteristicPermissions, CharacteristicsTypes)
|
||||
AbstractCharacteristic,
|
||||
CharacteristicPermissions,
|
||||
CharacteristicsTypes,
|
||||
)
|
||||
from homekit.model import Accessory, get_id
|
||||
from homekit.exceptions import AccessoryNotFoundError
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.homekit_controller.const import (
|
||||
CONTROLLER, DOMAIN, HOMEKIT_ACCESSORY_DISPATCH)
|
||||
from homeassistant.components.homekit_controller import (
|
||||
config_flow)
|
||||
CONTROLLER,
|
||||
DOMAIN,
|
||||
HOMEKIT_ACCESSORY_DISPATCH,
|
||||
)
|
||||
from homeassistant.components.homekit_controller import config_flow
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.dt as dt_util
|
||||
from tests.common import (
|
||||
async_fire_time_changed, load_fixture, MockConfigEntry
|
||||
)
|
||||
from tests.common import async_fire_time_changed, load_fixture, MockConfigEntry
|
||||
|
||||
|
||||
class FakePairing:
|
||||
@@ -38,17 +41,15 @@ class FakePairing:
|
||||
|
||||
def list_accessories_and_characteristics(self):
|
||||
"""Fake implementation of list_accessories_and_characteristics."""
|
||||
accessories = [
|
||||
a.to_accessory_and_service_list() for a in self.accessories
|
||||
]
|
||||
accessories = [a.to_accessory_and_service_list() for a in self.accessories]
|
||||
# replicate what happens upstream right now
|
||||
self.pairing_data['accessories'] = accessories
|
||||
self.pairing_data["accessories"] = accessories
|
||||
return accessories
|
||||
|
||||
def get_characteristics(self, characteristics):
|
||||
"""Fake implementation of get_characteristics."""
|
||||
if not self.available:
|
||||
raise AccessoryNotFoundError('Accessory not found')
|
||||
raise AccessoryNotFoundError("Accessory not found")
|
||||
|
||||
results = {}
|
||||
for aid, cid in characteristics:
|
||||
@@ -59,9 +60,7 @@ class FakePairing:
|
||||
for char in service.characteristics:
|
||||
if char.iid != cid:
|
||||
continue
|
||||
results[(aid, cid)] = {
|
||||
'value': char.get_value()
|
||||
}
|
||||
results[(aid, cid)] = {"value": char.get_value()}
|
||||
return results
|
||||
|
||||
def put_characteristics(self, characteristics):
|
||||
@@ -92,7 +91,7 @@ class FakeController:
|
||||
def add(self, accessories):
|
||||
"""Create and register a fake pairing for a simulated accessory."""
|
||||
pairing = FakePairing(accessories)
|
||||
self.pairings['00:00:00:00:00:00'] = pairing
|
||||
self.pairings["00:00:00:00:00:00"] = pairing
|
||||
return pairing
|
||||
|
||||
|
||||
@@ -138,7 +137,7 @@ class FakeCharacteristic(AbstractCharacteristic):
|
||||
# is fixed.
|
||||
record = super().to_accessory_and_service_list()
|
||||
if self.valid_values:
|
||||
record['valid-values'] = self.valid_values
|
||||
record["valid-values"] = self.valid_values
|
||||
return record
|
||||
|
||||
|
||||
@@ -152,11 +151,11 @@ class FakeService(AbstractService):
|
||||
|
||||
def add_characteristic(self, name):
|
||||
"""Add a characteristic to this service by name."""
|
||||
full_name = 'public.hap.characteristic.' + name
|
||||
full_name = "public.hap.characteristic." + name
|
||||
char = FakeCharacteristic(get_id(), full_name, None)
|
||||
char.perms = [
|
||||
CharacteristicPermissions.paired_read,
|
||||
CharacteristicPermissions.paired_write
|
||||
CharacteristicPermissions.paired_write,
|
||||
]
|
||||
self.characteristics.append(char)
|
||||
return char
|
||||
@@ -172,38 +171,37 @@ async def time_changed(hass, seconds):
|
||||
async def setup_accessories_from_file(hass, path):
|
||||
"""Load an collection of accessory defs from JSON data."""
|
||||
accessories_fixture = await hass.async_add_executor_job(
|
||||
load_fixture,
|
||||
os.path.join('homekit_controller', path),
|
||||
load_fixture, os.path.join("homekit_controller", path)
|
||||
)
|
||||
accessories_json = json.loads(accessories_fixture)
|
||||
|
||||
accessories = []
|
||||
|
||||
for accessory_data in accessories_json:
|
||||
accessory = Accessory('Name', 'Mfr', 'Model', '0001', '0.1')
|
||||
accessory = Accessory("Name", "Mfr", "Model", "0001", "0.1")
|
||||
accessory.services = []
|
||||
accessory.aid = accessory_data['aid']
|
||||
for service_data in accessory_data['services']:
|
||||
service = FakeService('public.hap.service.accessory-information')
|
||||
service.type = service_data['type']
|
||||
service.iid = service_data['iid']
|
||||
accessory.aid = accessory_data["aid"]
|
||||
for service_data in accessory_data["services"]:
|
||||
service = FakeService("public.hap.service.accessory-information")
|
||||
service.type = service_data["type"]
|
||||
service.iid = service_data["iid"]
|
||||
|
||||
for char_data in service_data['characteristics']:
|
||||
char = FakeCharacteristic(1, '23', None)
|
||||
char.type = char_data['type']
|
||||
char.iid = char_data['iid']
|
||||
char.perms = char_data['perms']
|
||||
char.format = char_data['format']
|
||||
if 'description' in char_data:
|
||||
char.description = char_data['description']
|
||||
if 'value' in char_data:
|
||||
char.value = char_data['value']
|
||||
if 'minValue' in char_data:
|
||||
char.minValue = char_data['minValue']
|
||||
if 'maxValue' in char_data:
|
||||
char.maxValue = char_data['maxValue']
|
||||
if 'valid-values' in char_data:
|
||||
char.valid_values = char_data['valid-values']
|
||||
for char_data in service_data["characteristics"]:
|
||||
char = FakeCharacteristic(1, "23", None)
|
||||
char.type = char_data["type"]
|
||||
char.iid = char_data["iid"]
|
||||
char.perms = char_data["perms"]
|
||||
char.format = char_data["format"]
|
||||
if "description" in char_data:
|
||||
char.description = char_data["description"]
|
||||
if "value" in char_data:
|
||||
char.value = char_data["value"]
|
||||
if "minValue" in char_data:
|
||||
char.minValue = char_data["minValue"]
|
||||
if "maxValue" in char_data:
|
||||
char.maxValue = char_data["maxValue"]
|
||||
if "valid-values" in char_data:
|
||||
char.valid_values = char_data["valid-values"]
|
||||
service.characteristics.append(char)
|
||||
|
||||
accessory.services.append(service)
|
||||
@@ -215,12 +213,9 @@ async def setup_accessories_from_file(hass, path):
|
||||
|
||||
async def setup_platform(hass):
|
||||
"""Load the platform but with a fake Controller API."""
|
||||
config = {
|
||||
'discovery': {
|
||||
}
|
||||
}
|
||||
config = {"discovery": {}}
|
||||
|
||||
with mock.patch('homekit.Controller') as controller:
|
||||
with mock.patch("homekit.Controller") as controller:
|
||||
fake_controller = controller.return_value = FakeController()
|
||||
await async_setup_component(hass, DOMAIN, config)
|
||||
|
||||
@@ -233,32 +228,28 @@ async def setup_test_accessories(hass, accessories):
|
||||
pairing = fake_controller.add(accessories)
|
||||
|
||||
discovery_info = {
|
||||
'name': 'TestDevice',
|
||||
'host': '127.0.0.1',
|
||||
'port': 8080,
|
||||
'properties': {
|
||||
'md': 'TestDevice',
|
||||
'id': '00:00:00:00:00:00',
|
||||
'c#': 1,
|
||||
}
|
||||
"name": "TestDevice",
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
"properties": {"md": "TestDevice", "id": "00:00:00:00:00:00", "c#": 1},
|
||||
}
|
||||
|
||||
pairing.pairing_data.update({
|
||||
'AccessoryPairingID': discovery_info['properties']['id'],
|
||||
})
|
||||
pairing.pairing_data.update(
|
||||
{"AccessoryPairingID": discovery_info["properties"]["id"]}
|
||||
)
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
version=1,
|
||||
domain='homekit_controller',
|
||||
entry_id='TestData',
|
||||
domain="homekit_controller",
|
||||
entry_id="TestData",
|
||||
data=pairing.pairing_data,
|
||||
title='test',
|
||||
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
title="test",
|
||||
connection_class=config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
)
|
||||
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
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 config_entry.async_setup(hass)
|
||||
@@ -271,19 +262,19 @@ async def device_config_changed(hass, accessories):
|
||||
"""Discover new devices added to HomeAssistant at runtime."""
|
||||
# Update the accessories our FakePairing knows about
|
||||
controller = hass.data[CONTROLLER]
|
||||
pairing = controller.pairings['00:00:00:00:00:00']
|
||||
pairing = controller.pairings["00:00:00:00:00:00"]
|
||||
pairing.accessories = accessories
|
||||
|
||||
discovery_info = {
|
||||
'name': 'TestDevice',
|
||||
'host': '127.0.0.1',
|
||||
'port': 8080,
|
||||
'properties': {
|
||||
'md': 'TestDevice',
|
||||
'id': '00:00:00:00:00:00',
|
||||
'c#': '2',
|
||||
'sf': '0',
|
||||
}
|
||||
"name": "TestDevice",
|
||||
"host": "127.0.0.1",
|
||||
"port": 8080,
|
||||
"properties": {
|
||||
"md": "TestDevice",
|
||||
"id": "00:00:00:00:00:00",
|
||||
"c#": "2",
|
||||
"sf": "0",
|
||||
},
|
||||
}
|
||||
|
||||
# Config Flow will abort and notify us if the discovery event is of
|
||||
@@ -292,8 +283,8 @@ async def device_config_changed(hass, accessories):
|
||||
flow.hass = hass
|
||||
flow.context = {}
|
||||
result = await flow.async_step_zeroconf(discovery_info)
|
||||
assert result['type'] == 'abort'
|
||||
assert result['reason'] == 'already_configured'
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
# Wait for services to reconfigure
|
||||
await hass.async_block_till_done()
|
||||
@@ -314,13 +305,11 @@ async def setup_test_component(hass, services, capitalize=False, suffix=None):
|
||||
domain = HOMEKIT_ACCESSORY_DISPATCH[service_name]
|
||||
break
|
||||
|
||||
assert domain, 'Cannot map test homekit services to homeassistant domain'
|
||||
assert domain, "Cannot map test homekit services to homeassistant domain"
|
||||
|
||||
accessory = Accessory('TestDevice', 'example.com', 'Test', '0001', '0.1')
|
||||
accessory = Accessory("TestDevice", "example.com", "Test", "0001", "0.1")
|
||||
accessory.services.extend(services)
|
||||
|
||||
config_entry, pairing = await setup_test_accessories(hass, [accessory])
|
||||
entity = 'testdevice' if suffix is None else 'testdevice_{}'.format(suffix)
|
||||
return Helper(
|
||||
hass, '.'.join((domain, entity)), pairing, accessory, config_entry
|
||||
)
|
||||
entity = "testdevice" if suffix is None else "testdevice_{}".format(suffix)
|
||||
return Helper(hass, ".".join((domain, entity)), pairing, accessory, config_entry)
|
||||
|
||||
@@ -9,6 +9,6 @@ import pytest
|
||||
def utcnow(request):
|
||||
"""Freeze time at a known point."""
|
||||
start_dt = datetime.datetime(2019, 1, 1, 0, 0, 0)
|
||||
with mock.patch('homeassistant.util.dt.utcnow') as dt_utcnow:
|
||||
with mock.patch("homeassistant.util.dt.utcnow") as dt_utcnow:
|
||||
dt_utcnow.return_value = start_dt
|
||||
yield dt_utcnow
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
"""Basic checks for HomeKitalarm_control_panel."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
CURRENT_STATE = ('security-system', 'security-system-state.current')
|
||||
TARGET_STATE = ('security-system', 'security-system-state.target')
|
||||
CURRENT_STATE = ("security-system", "security-system-state.current")
|
||||
TARGET_STATE = ("security-system", "security-system-state.target")
|
||||
|
||||
|
||||
def create_security_system_service():
|
||||
"""Define a security-system characteristics as per page 219 of HAP spec."""
|
||||
service = FakeService('public.hap.service.security-system')
|
||||
service = FakeService("public.hap.service.security-system")
|
||||
|
||||
cur_state = service.add_characteristic('security-system-state.current')
|
||||
cur_state = service.add_characteristic("security-system-state.current")
|
||||
cur_state.value = 0
|
||||
|
||||
targ_state = service.add_characteristic('security-system-state.target')
|
||||
targ_state = service.add_characteristic("security-system-state.target")
|
||||
targ_state.value = 0
|
||||
|
||||
# According to the spec, a battery-level characteristic is normally
|
||||
# part of a seperate service. However as the code was written (which
|
||||
# predates this test) the battery level would have to be part of the lock
|
||||
# service as it is here.
|
||||
targ_state = service.add_characteristic('battery-level')
|
||||
targ_state = service.add_characteristic("battery-level")
|
||||
targ_state.value = 50
|
||||
|
||||
return service
|
||||
@@ -31,24 +30,36 @@ async def test_switch_change_alarm_state(hass, utcnow):
|
||||
alarm_control_panel = create_security_system_service()
|
||||
helper = await setup_test_component(hass, [alarm_control_panel])
|
||||
|
||||
await hass.services.async_call('alarm_control_panel', 'alarm_arm_home', {
|
||||
'entity_id': 'alarm_control_panel.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"alarm_control_panel",
|
||||
"alarm_arm_home",
|
||||
{"entity_id": "alarm_control_panel.testdevice"},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TARGET_STATE].value == 0
|
||||
|
||||
await hass.services.async_call('alarm_control_panel', 'alarm_arm_away', {
|
||||
'entity_id': 'alarm_control_panel.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"alarm_control_panel",
|
||||
"alarm_arm_away",
|
||||
{"entity_id": "alarm_control_panel.testdevice"},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TARGET_STATE].value == 1
|
||||
|
||||
await hass.services.async_call('alarm_control_panel', 'alarm_arm_night', {
|
||||
'entity_id': 'alarm_control_panel.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"alarm_control_panel",
|
||||
"alarm_arm_night",
|
||||
{"entity_id": "alarm_control_panel.testdevice"},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TARGET_STATE].value == 2
|
||||
|
||||
await hass.services.async_call('alarm_control_panel', 'alarm_disarm', {
|
||||
'entity_id': 'alarm_control_panel.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"alarm_control_panel",
|
||||
"alarm_disarm",
|
||||
{"entity_id": "alarm_control_panel.testdevice"},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TARGET_STATE].value == 3
|
||||
|
||||
|
||||
@@ -59,21 +70,21 @@ async def test_switch_read_alarm_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[CURRENT_STATE].value = 0
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'armed_home'
|
||||
assert state.attributes['battery_level'] == 50
|
||||
assert state.state == "armed_home"
|
||||
assert state.attributes["battery_level"] == 50
|
||||
|
||||
helper.characteristics[CURRENT_STATE].value = 1
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'armed_away'
|
||||
assert state.state == "armed_away"
|
||||
|
||||
helper.characteristics[CURRENT_STATE].value = 2
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'armed_night'
|
||||
assert state.state == "armed_night"
|
||||
|
||||
helper.characteristics[CURRENT_STATE].value = 3
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'disarmed'
|
||||
assert state.state == "disarmed"
|
||||
|
||||
helper.characteristics[CURRENT_STATE].value = 4
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'triggered'
|
||||
assert state.state == "triggered"
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
"""Basic checks for HomeKit motion sensors and contact sensors."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
MOTION_DETECTED = ('motion', 'motion-detected')
|
||||
CONTACT_STATE = ('contact', 'contact-state')
|
||||
MOTION_DETECTED = ("motion", "motion-detected")
|
||||
CONTACT_STATE = ("contact", "contact-state")
|
||||
|
||||
|
||||
def create_motion_sensor_service():
|
||||
"""Define motion characteristics as per page 225 of HAP spec."""
|
||||
service = FakeService('public.hap.service.sensor.motion')
|
||||
service = FakeService("public.hap.service.sensor.motion")
|
||||
|
||||
cur_state = service.add_characteristic('motion-detected')
|
||||
cur_state = service.add_characteristic("motion-detected")
|
||||
cur_state.value = 0
|
||||
|
||||
return service
|
||||
@@ -23,18 +22,18 @@ async def test_motion_sensor_read_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[MOTION_DETECTED].value = False
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
helper.characteristics[MOTION_DETECTED].value = True
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'on'
|
||||
assert state.state == "on"
|
||||
|
||||
|
||||
def create_contact_sensor_service():
|
||||
"""Define contact characteristics."""
|
||||
service = FakeService('public.hap.service.sensor.contact')
|
||||
service = FakeService("public.hap.service.sensor.contact")
|
||||
|
||||
cur_state = service.add_characteristic('contact-state')
|
||||
cur_state = service.add_characteristic("contact-state")
|
||||
cur_state.value = 0
|
||||
|
||||
return service
|
||||
@@ -47,8 +46,8 @@ async def test_contact_sensor_read_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[CONTACT_STATE].value = 0
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
helper.characteristics[CONTACT_STATE].value = 1
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'on'
|
||||
assert state.state == "on"
|
||||
|
||||
@@ -1,40 +1,45 @@
|
||||
"""Basic checks for HomeKitclimate."""
|
||||
from homeassistant.components.climate.const import (
|
||||
DOMAIN, SERVICE_SET_HVAC_MODE, SERVICE_SET_TEMPERATURE,
|
||||
HVAC_MODE_HEAT_COOL, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF,
|
||||
SERVICE_SET_HUMIDITY)
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
HVAC_MODE_HEAT_COOL,
|
||||
HVAC_MODE_COOL,
|
||||
HVAC_MODE_HEAT,
|
||||
HVAC_MODE_OFF,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
|
||||
HEATING_COOLING_TARGET = ('thermostat', 'heating-cooling.target')
|
||||
HEATING_COOLING_CURRENT = ('thermostat', 'heating-cooling.current')
|
||||
TEMPERATURE_TARGET = ('thermostat', 'temperature.target')
|
||||
TEMPERATURE_CURRENT = ('thermostat', 'temperature.current')
|
||||
HUMIDITY_TARGET = ('thermostat', 'relative-humidity.target')
|
||||
HUMIDITY_CURRENT = ('thermostat', 'relative-humidity.current')
|
||||
HEATING_COOLING_TARGET = ("thermostat", "heating-cooling.target")
|
||||
HEATING_COOLING_CURRENT = ("thermostat", "heating-cooling.current")
|
||||
TEMPERATURE_TARGET = ("thermostat", "temperature.target")
|
||||
TEMPERATURE_CURRENT = ("thermostat", "temperature.current")
|
||||
HUMIDITY_TARGET = ("thermostat", "relative-humidity.target")
|
||||
HUMIDITY_CURRENT = ("thermostat", "relative-humidity.current")
|
||||
|
||||
|
||||
def create_thermostat_service():
|
||||
"""Define thermostat characteristics."""
|
||||
service = FakeService('public.hap.service.thermostat')
|
||||
service = FakeService("public.hap.service.thermostat")
|
||||
|
||||
char = service.add_characteristic('heating-cooling.target')
|
||||
char = service.add_characteristic("heating-cooling.target")
|
||||
char.value = 0
|
||||
|
||||
char = service.add_characteristic('heating-cooling.current')
|
||||
char = service.add_characteristic("heating-cooling.current")
|
||||
char.value = 0
|
||||
|
||||
char = service.add_characteristic('temperature.target')
|
||||
char = service.add_characteristic("temperature.target")
|
||||
char.value = 0
|
||||
|
||||
char = service.add_characteristic('temperature.current')
|
||||
char = service.add_characteristic("temperature.current")
|
||||
char.value = 0
|
||||
|
||||
char = service.add_characteristic('relative-humidity.target')
|
||||
char = service.add_characteristic("relative-humidity.target")
|
||||
char.value = 0
|
||||
|
||||
char = service.add_characteristic('relative-humidity.current')
|
||||
char = service.add_characteristic("relative-humidity.current")
|
||||
char.value = 0
|
||||
|
||||
return service
|
||||
@@ -42,8 +47,8 @@ def create_thermostat_service():
|
||||
|
||||
async def test_climate_respect_supported_op_modes_1(hass, utcnow):
|
||||
"""Test that climate respects minValue/maxValue hints."""
|
||||
service = FakeService('public.hap.service.thermostat')
|
||||
char = service.add_characteristic('heating-cooling.target')
|
||||
service = FakeService("public.hap.service.thermostat")
|
||||
char = service.add_characteristic("heating-cooling.target")
|
||||
char.value = 0
|
||||
char.minValue = 0
|
||||
char.maxValue = 1
|
||||
@@ -51,20 +56,20 @@ async def test_climate_respect_supported_op_modes_1(hass, utcnow):
|
||||
helper = await setup_test_component(hass, [service])
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['hvac_modes'] == ['off', 'heat']
|
||||
assert state.attributes["hvac_modes"] == ["off", "heat"]
|
||||
|
||||
|
||||
async def test_climate_respect_supported_op_modes_2(hass, utcnow):
|
||||
"""Test that climate respects validValue hints."""
|
||||
service = FakeService('public.hap.service.thermostat')
|
||||
char = service.add_characteristic('heating-cooling.target')
|
||||
service = FakeService("public.hap.service.thermostat")
|
||||
char = service.add_characteristic("heating-cooling.target")
|
||||
char.value = 0
|
||||
char.valid_values = [0, 1, 2]
|
||||
|
||||
helper = await setup_test_component(hass, [service])
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['hvac_modes'] == ['off', 'heat', 'cool']
|
||||
assert state.attributes["hvac_modes"] == ["off", "heat", "cool"]
|
||||
|
||||
|
||||
async def test_climate_change_thermostat_state(hass, utcnow):
|
||||
@@ -73,29 +78,37 @@ async def test_climate_change_thermostat_state(hass, utcnow):
|
||||
|
||||
helper = await setup_test_component(hass, [ThermostatService()])
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HVAC_MODE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'hvac_mode': HVAC_MODE_HEAT,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{"entity_id": "climate.testdevice", "hvac_mode": HVAC_MODE_HEAT},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert helper.characteristics[HEATING_COOLING_TARGET].value == 1
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HVAC_MODE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'hvac_mode': HVAC_MODE_COOL,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{"entity_id": "climate.testdevice", "hvac_mode": HVAC_MODE_COOL},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[HEATING_COOLING_TARGET].value == 2
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HVAC_MODE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'hvac_mode': HVAC_MODE_HEAT_COOL,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{"entity_id": "climate.testdevice", "hvac_mode": HVAC_MODE_HEAT_COOL},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[HEATING_COOLING_TARGET].value == 3
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HVAC_MODE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'hvac_mode': HVAC_MODE_OFF,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HVAC_MODE,
|
||||
{"entity_id": "climate.testdevice", "hvac_mode": HVAC_MODE_OFF},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[HEATING_COOLING_TARGET].value == 0
|
||||
|
||||
|
||||
@@ -105,16 +118,20 @@ async def test_climate_change_thermostat_temperature(hass, utcnow):
|
||||
|
||||
helper = await setup_test_component(hass, [ThermostatService()])
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'temperature': 21,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
{"entity_id": "climate.testdevice", "temperature": 21},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TEMPERATURE_TARGET].value == 21
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_TEMPERATURE, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'temperature': 25,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_TEMPERATURE,
|
||||
{"entity_id": "climate.testdevice", "temperature": 25},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[TEMPERATURE_TARGET].value == 25
|
||||
|
||||
|
||||
@@ -122,16 +139,20 @@ async def test_climate_change_thermostat_humidity(hass, utcnow):
|
||||
"""Test that we can turn a HomeKit thermostat on and off again."""
|
||||
helper = await setup_test_component(hass, [create_thermostat_service()])
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HUMIDITY, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'humidity': 50,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{"entity_id": "climate.testdevice", "humidity": 50},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[HUMIDITY_TARGET].value == 50
|
||||
|
||||
await hass.services.async_call(DOMAIN, SERVICE_SET_HUMIDITY, {
|
||||
'entity_id': 'climate.testdevice',
|
||||
'humidity': 45,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
DOMAIN,
|
||||
SERVICE_SET_HUMIDITY,
|
||||
{"entity_id": "climate.testdevice", "humidity": 45},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[HUMIDITY_TARGET].value == 45
|
||||
|
||||
|
||||
@@ -149,10 +170,10 @@ async def test_climate_read_thermostat_state(hass, utcnow):
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == HVAC_MODE_HEAT
|
||||
assert state.attributes['current_temperature'] == 19
|
||||
assert state.attributes['current_humidity'] == 50
|
||||
assert state.attributes['min_temp'] == 7
|
||||
assert state.attributes['max_temp'] == 35
|
||||
assert state.attributes["current_temperature"] == 19
|
||||
assert state.attributes["current_humidity"] == 50
|
||||
assert state.attributes["min_temp"] == 7
|
||||
assert state.attributes["max_temp"] == 35
|
||||
|
||||
# Simulate that cooling is on
|
||||
helper.characteristics[TEMPERATURE_CURRENT].value = 21
|
||||
@@ -164,8 +185,8 @@ async def test_climate_read_thermostat_state(hass, utcnow):
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == HVAC_MODE_COOL
|
||||
assert state.attributes['current_temperature'] == 21
|
||||
assert state.attributes['current_humidity'] == 45
|
||||
assert state.attributes["current_temperature"] == 21
|
||||
assert state.attributes["current_humidity"] == 45
|
||||
|
||||
# Simulate that we are in heat/cool mode
|
||||
helper.characteristics[TEMPERATURE_CURRENT].value = 21
|
||||
@@ -191,8 +212,8 @@ async def test_hvac_mode_vs_hvac_action(hass, utcnow):
|
||||
helper.characteristics[HUMIDITY_TARGET].value = 45
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'heat'
|
||||
assert state.attributes['hvac_action'] == 'off'
|
||||
assert state.state == "heat"
|
||||
assert state.attributes["hvac_action"] == "off"
|
||||
|
||||
# Simulate that current temperature is below target temp
|
||||
# Heating might be on and hvac_action currently 'heat'
|
||||
@@ -200,5 +221,5 @@ async def test_hvac_mode_vs_hvac_action(hass, utcnow):
|
||||
helper.characteristics[HEATING_COOLING_CURRENT].value = 1
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'heat'
|
||||
assert state.attributes['hvac_action'] == 'heating'
|
||||
assert state.state == "heat"
|
||||
assert state.attributes["hvac_action"] == "heating"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,45 +1,44 @@
|
||||
"""Basic checks for HomeKitalarm_control_panel."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
POSITION_STATE = ('window-covering', 'position.state')
|
||||
POSITION_CURRENT = ('window-covering', 'position.current')
|
||||
POSITION_TARGET = ('window-covering', 'position.target')
|
||||
POSITION_HOLD = ('window-covering', 'position.hold')
|
||||
POSITION_STATE = ("window-covering", "position.state")
|
||||
POSITION_CURRENT = ("window-covering", "position.current")
|
||||
POSITION_TARGET = ("window-covering", "position.target")
|
||||
POSITION_HOLD = ("window-covering", "position.hold")
|
||||
|
||||
H_TILT_CURRENT = ('window-covering', 'horizontal-tilt.current')
|
||||
H_TILT_TARGET = ('window-covering', 'horizontal-tilt.target')
|
||||
H_TILT_CURRENT = ("window-covering", "horizontal-tilt.current")
|
||||
H_TILT_TARGET = ("window-covering", "horizontal-tilt.target")
|
||||
|
||||
V_TILT_CURRENT = ('window-covering', 'vertical-tilt.current')
|
||||
V_TILT_TARGET = ('window-covering', 'vertical-tilt.target')
|
||||
V_TILT_CURRENT = ("window-covering", "vertical-tilt.current")
|
||||
V_TILT_TARGET = ("window-covering", "vertical-tilt.target")
|
||||
|
||||
WINDOW_OBSTRUCTION = ('window-covering', 'obstruction-detected')
|
||||
WINDOW_OBSTRUCTION = ("window-covering", "obstruction-detected")
|
||||
|
||||
DOOR_CURRENT = ('garage-door-opener', 'door-state.current')
|
||||
DOOR_TARGET = ('garage-door-opener', 'door-state.target')
|
||||
DOOR_OBSTRUCTION = ('garage-door-opener', 'obstruction-detected')
|
||||
DOOR_CURRENT = ("garage-door-opener", "door-state.current")
|
||||
DOOR_TARGET = ("garage-door-opener", "door-state.target")
|
||||
DOOR_OBSTRUCTION = ("garage-door-opener", "obstruction-detected")
|
||||
|
||||
|
||||
def create_window_covering_service():
|
||||
"""Define a window-covering characteristics as per page 219 of HAP spec."""
|
||||
service = FakeService('public.hap.service.window-covering')
|
||||
service = FakeService("public.hap.service.window-covering")
|
||||
|
||||
cur_state = service.add_characteristic('position.current')
|
||||
cur_state = service.add_characteristic("position.current")
|
||||
cur_state.value = 0
|
||||
|
||||
targ_state = service.add_characteristic('position.target')
|
||||
targ_state = service.add_characteristic("position.target")
|
||||
targ_state.value = 0
|
||||
|
||||
position_state = service.add_characteristic('position.state')
|
||||
position_state = service.add_characteristic("position.state")
|
||||
position_state.value = 0
|
||||
|
||||
position_hold = service.add_characteristic('position.hold')
|
||||
position_hold = service.add_characteristic("position.hold")
|
||||
position_hold.value = 0
|
||||
|
||||
obstruction = service.add_characteristic('obstruction-detected')
|
||||
obstruction = service.add_characteristic("obstruction-detected")
|
||||
obstruction.value = False
|
||||
|
||||
name = service.add_characteristic('name')
|
||||
name = service.add_characteristic("name")
|
||||
name.value = "testdevice"
|
||||
|
||||
return service
|
||||
@@ -49,10 +48,10 @@ def create_window_covering_service_with_h_tilt():
|
||||
"""Define a window-covering characteristics as per page 219 of HAP spec."""
|
||||
service = create_window_covering_service()
|
||||
|
||||
tilt_current = service.add_characteristic('horizontal-tilt.current')
|
||||
tilt_current = service.add_characteristic("horizontal-tilt.current")
|
||||
tilt_current.value = 0
|
||||
|
||||
tilt_target = service.add_characteristic('horizontal-tilt.target')
|
||||
tilt_target = service.add_characteristic("horizontal-tilt.target")
|
||||
tilt_target.value = 0
|
||||
|
||||
return service
|
||||
@@ -62,10 +61,10 @@ def create_window_covering_service_with_v_tilt():
|
||||
"""Define a window-covering characteristics as per page 219 of HAP spec."""
|
||||
service = create_window_covering_service()
|
||||
|
||||
tilt_current = service.add_characteristic('vertical-tilt.current')
|
||||
tilt_current = service.add_characteristic("vertical-tilt.current")
|
||||
tilt_current.value = 0
|
||||
|
||||
tilt_target = service.add_characteristic('vertical-tilt.target')
|
||||
tilt_target = service.add_characteristic("vertical-tilt.target")
|
||||
tilt_target.value = 0
|
||||
|
||||
return service
|
||||
@@ -76,14 +75,14 @@ async def test_change_window_cover_state(hass, utcnow):
|
||||
window_cover = create_window_covering_service()
|
||||
helper = await setup_test_component(hass, [window_cover])
|
||||
|
||||
await hass.services.async_call('cover', 'open_cover', {
|
||||
'entity_id': helper.entity_id,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[POSITION_TARGET].value == 100
|
||||
|
||||
await hass.services.async_call('cover', 'close_cover', {
|
||||
'entity_id': helper.entity_id,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[POSITION_TARGET].value == 0
|
||||
|
||||
|
||||
@@ -94,19 +93,19 @@ async def test_read_window_cover_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[POSITION_STATE].value = 0
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'opening'
|
||||
assert state.state == "opening"
|
||||
|
||||
helper.characteristics[POSITION_STATE].value = 1
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'closing'
|
||||
assert state.state == "closing"
|
||||
|
||||
helper.characteristics[POSITION_STATE].value = 2
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'closed'
|
||||
assert state.state == "closed"
|
||||
|
||||
helper.characteristics[WINDOW_OBSTRUCTION].value = True
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['obstruction-detected'] is True
|
||||
assert state.attributes["obstruction-detected"] is True
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_horizontal(hass, utcnow):
|
||||
@@ -116,7 +115,7 @@ async def test_read_window_cover_tilt_horizontal(hass, utcnow):
|
||||
|
||||
helper.characteristics[H_TILT_CURRENT].value = 75
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['current_tilt_position'] == 75
|
||||
assert state.attributes["current_tilt_position"] == 75
|
||||
|
||||
|
||||
async def test_read_window_cover_tilt_vertical(hass, utcnow):
|
||||
@@ -126,7 +125,7 @@ async def test_read_window_cover_tilt_vertical(hass, utcnow):
|
||||
|
||||
helper.characteristics[V_TILT_CURRENT].value = 75
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['current_tilt_position'] == 75
|
||||
assert state.attributes["current_tilt_position"] == 75
|
||||
|
||||
|
||||
async def test_write_window_cover_tilt_horizontal(hass, utcnow):
|
||||
@@ -134,10 +133,12 @@ async def test_write_window_cover_tilt_horizontal(hass, utcnow):
|
||||
window_cover = create_window_covering_service_with_h_tilt()
|
||||
helper = await setup_test_component(hass, [window_cover])
|
||||
|
||||
await hass.services.async_call('cover', 'set_cover_tilt_position', {
|
||||
'entity_id': helper.entity_id,
|
||||
'tilt_position': 90
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_tilt_position",
|
||||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[H_TILT_TARGET].value == 90
|
||||
|
||||
|
||||
@@ -146,10 +147,12 @@ async def test_write_window_cover_tilt_vertical(hass, utcnow):
|
||||
window_cover = create_window_covering_service_with_v_tilt()
|
||||
helper = await setup_test_component(hass, [window_cover])
|
||||
|
||||
await hass.services.async_call('cover', 'set_cover_tilt_position', {
|
||||
'entity_id': helper.entity_id,
|
||||
'tilt_position': 90
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover",
|
||||
"set_cover_tilt_position",
|
||||
{"entity_id": helper.entity_id, "tilt_position": 90},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[V_TILT_TARGET].value == 90
|
||||
|
||||
|
||||
@@ -158,26 +161,26 @@ async def test_window_cover_stop(hass, utcnow):
|
||||
window_cover = create_window_covering_service_with_v_tilt()
|
||||
helper = await setup_test_component(hass, [window_cover])
|
||||
|
||||
await hass.services.async_call('cover', 'stop_cover', {
|
||||
'entity_id': helper.entity_id,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover", "stop_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[POSITION_HOLD].value == 1
|
||||
|
||||
|
||||
def create_garage_door_opener_service():
|
||||
"""Define a garage-door-opener chars as per page 217 of HAP spec."""
|
||||
service = FakeService('public.hap.service.garage-door-opener')
|
||||
service = FakeService("public.hap.service.garage-door-opener")
|
||||
|
||||
cur_state = service.add_characteristic('door-state.current')
|
||||
cur_state = service.add_characteristic("door-state.current")
|
||||
cur_state.value = 0
|
||||
|
||||
targ_state = service.add_characteristic('door-state.target')
|
||||
targ_state = service.add_characteristic("door-state.target")
|
||||
targ_state.value = 0
|
||||
|
||||
obstruction = service.add_characteristic('obstruction-detected')
|
||||
obstruction = service.add_characteristic("obstruction-detected")
|
||||
obstruction.value = False
|
||||
|
||||
name = service.add_characteristic('name')
|
||||
name = service.add_characteristic("name")
|
||||
name.value = "testdevice"
|
||||
|
||||
return service
|
||||
@@ -188,14 +191,14 @@ async def test_change_door_state(hass, utcnow):
|
||||
door = create_garage_door_opener_service()
|
||||
helper = await setup_test_component(hass, [door])
|
||||
|
||||
await hass.services.async_call('cover', 'open_cover', {
|
||||
'entity_id': helper.entity_id,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[DOOR_TARGET].value == 0
|
||||
|
||||
await hass.services.async_call('cover', 'close_cover', {
|
||||
'entity_id': helper.entity_id,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": helper.entity_id}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[DOOR_TARGET].value == 1
|
||||
|
||||
|
||||
@@ -206,20 +209,20 @@ async def test_read_door_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[DOOR_CURRENT].value = 0
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'open'
|
||||
assert state.state == "open"
|
||||
|
||||
helper.characteristics[DOOR_CURRENT].value = 1
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'closed'
|
||||
assert state.state == "closed"
|
||||
|
||||
helper.characteristics[DOOR_CURRENT].value = 2
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'opening'
|
||||
assert state.state == "opening"
|
||||
|
||||
helper.characteristics[DOOR_CURRENT].value = 3
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'closing'
|
||||
assert state.state == "closing"
|
||||
|
||||
helper.characteristics[DOOR_OBSTRUCTION].value = True
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes['obstruction-detected'] is True
|
||||
assert state.attributes["obstruction-detected"] is True
|
||||
|
||||
@@ -1,25 +1,24 @@
|
||||
"""Basic checks for HomeKitSwitch."""
|
||||
from homeassistant.components.homekit_controller.const import KNOWN_DEVICES
|
||||
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
|
||||
LIGHT_ON = ('lightbulb', 'on')
|
||||
LIGHT_BRIGHTNESS = ('lightbulb', 'brightness')
|
||||
LIGHT_HUE = ('lightbulb', 'hue')
|
||||
LIGHT_SATURATION = ('lightbulb', 'saturation')
|
||||
LIGHT_COLOR_TEMP = ('lightbulb', 'color-temperature')
|
||||
LIGHT_ON = ("lightbulb", "on")
|
||||
LIGHT_BRIGHTNESS = ("lightbulb", "brightness")
|
||||
LIGHT_HUE = ("lightbulb", "hue")
|
||||
LIGHT_SATURATION = ("lightbulb", "saturation")
|
||||
LIGHT_COLOR_TEMP = ("lightbulb", "color-temperature")
|
||||
|
||||
|
||||
def create_lightbulb_service():
|
||||
"""Define lightbulb characteristics."""
|
||||
service = FakeService('public.hap.service.lightbulb')
|
||||
service = FakeService("public.hap.service.lightbulb")
|
||||
|
||||
on_char = service.add_characteristic('on')
|
||||
on_char = service.add_characteristic("on")
|
||||
on_char.value = 0
|
||||
|
||||
brightness = service.add_characteristic('brightness')
|
||||
brightness = service.add_characteristic("brightness")
|
||||
brightness.value = 0
|
||||
|
||||
return service
|
||||
@@ -29,10 +28,10 @@ def create_lightbulb_service_with_hs():
|
||||
"""Define a lightbulb service with hue + saturation."""
|
||||
service = create_lightbulb_service()
|
||||
|
||||
hue = service.add_characteristic('hue')
|
||||
hue = service.add_characteristic("hue")
|
||||
hue.value = 0
|
||||
|
||||
saturation = service.add_characteristic('saturation')
|
||||
saturation = service.add_characteristic("saturation")
|
||||
saturation.value = 0
|
||||
|
||||
return service
|
||||
@@ -42,7 +41,7 @@ def create_lightbulb_service_with_color_temp():
|
||||
"""Define a lightbulb service with color temp."""
|
||||
service = create_lightbulb_service()
|
||||
|
||||
color_temp = service.add_characteristic('color-temperature')
|
||||
color_temp = service.add_characteristic("color-temperature")
|
||||
color_temp.value = 0
|
||||
|
||||
return service
|
||||
@@ -53,20 +52,21 @@ async def test_switch_change_light_state(hass, utcnow):
|
||||
bulb = create_lightbulb_service_with_hs()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
|
||||
await hass.services.async_call('light', 'turn_on', {
|
||||
'entity_id': 'light.testdevice',
|
||||
'brightness': 255,
|
||||
'hs_color': [4, 5],
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.testdevice", "brightness": 255, "hs_color": [4, 5]},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert helper.characteristics[LIGHT_ON].value == 1
|
||||
assert helper.characteristics[LIGHT_BRIGHTNESS].value == 100
|
||||
assert helper.characteristics[LIGHT_HUE].value == 4
|
||||
assert helper.characteristics[LIGHT_SATURATION].value == 5
|
||||
|
||||
await hass.services.async_call('light', 'turn_off', {
|
||||
'entity_id': 'light.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"light", "turn_off", {"entity_id": "light.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[LIGHT_ON].value == 0
|
||||
|
||||
|
||||
@@ -75,11 +75,12 @@ async def test_switch_change_light_state_color_temp(hass, utcnow):
|
||||
bulb = create_lightbulb_service_with_color_temp()
|
||||
helper = await setup_test_component(hass, [bulb])
|
||||
|
||||
await hass.services.async_call('light', 'turn_on', {
|
||||
'entity_id': 'light.testdevice',
|
||||
'brightness': 255,
|
||||
'color_temp': 400,
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{"entity_id": "light.testdevice", "brightness": 255, "color_temp": 400},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[LIGHT_ON].value == 1
|
||||
assert helper.characteristics[LIGHT_BRIGHTNESS].value == 100
|
||||
assert helper.characteristics[LIGHT_COLOR_TEMP].value == 400
|
||||
@@ -92,7 +93,7 @@ async def test_switch_read_light_state(hass, utcnow):
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
helper.characteristics[LIGHT_ON].set_value(True)
|
||||
@@ -100,14 +101,14 @@ async def test_switch_read_light_state(hass, utcnow):
|
||||
helper.characteristics[LIGHT_HUE].value = 4
|
||||
helper.characteristics[LIGHT_SATURATION].value = 5
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 255
|
||||
assert state.attributes['hs_color'] == (4, 5)
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 255
|
||||
assert state.attributes["hs_color"] == (4, 5)
|
||||
|
||||
# Simulate that device switched off in the real world not via HA
|
||||
helper.characteristics[LIGHT_ON].set_value(False)
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
|
||||
async def test_switch_read_light_state_color_temp(hass, utcnow):
|
||||
@@ -117,7 +118,7 @@ async def test_switch_read_light_state_color_temp(hass, utcnow):
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
helper.characteristics[LIGHT_ON].set_value(True)
|
||||
@@ -125,9 +126,9 @@ async def test_switch_read_light_state_color_temp(hass, utcnow):
|
||||
helper.characteristics[LIGHT_COLOR_TEMP].value = 400
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 255
|
||||
assert state.attributes['color_temp'] == 400
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 255
|
||||
assert state.attributes["color_temp"] == 400
|
||||
|
||||
|
||||
async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
||||
@@ -137,12 +138,12 @@ async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
# Test device goes offline
|
||||
helper.pairing.available = False
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'unavailable'
|
||||
assert state.state == "unavailable"
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
helper.characteristics[LIGHT_ON].set_value(True)
|
||||
@@ -151,9 +152,9 @@ async def test_light_becomes_unavailable_but_recovers(hass, utcnow):
|
||||
helper.pairing.available = True
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'on'
|
||||
assert state.attributes['brightness'] == 255
|
||||
assert state.attributes['color_temp'] == 400
|
||||
assert state.state == "on"
|
||||
assert state.attributes["brightness"] == 255
|
||||
assert state.attributes["color_temp"] == 400
|
||||
|
||||
|
||||
async def test_light_unloaded(hass, utcnow):
|
||||
@@ -163,7 +164,7 @@ async def test_light_unloaded(hass, utcnow):
|
||||
|
||||
# Initial state is that the light is off
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'off'
|
||||
assert state.state == "off"
|
||||
|
||||
unload_result = await helper.config_entry.async_unload(hass)
|
||||
assert unload_result is True
|
||||
@@ -172,5 +173,5 @@ async def test_light_unloaded(hass, utcnow):
|
||||
assert hass.states.get(helper.entity_id) is None
|
||||
|
||||
# Make sure HKDevice is no longer set to poll this accessory
|
||||
conn = hass.data[KNOWN_DEVICES]['00:00:00:00:00:00']
|
||||
conn = hass.data[KNOWN_DEVICES]["00:00:00:00:00:00"]
|
||||
assert not conn.pollable_characteristics
|
||||
|
||||
@@ -1,26 +1,25 @@
|
||||
"""Basic checks for HomeKitLock."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
LOCK_CURRENT_STATE = ('lock-mechanism', 'lock-mechanism.current-state')
|
||||
LOCK_TARGET_STATE = ('lock-mechanism', 'lock-mechanism.target-state')
|
||||
LOCK_CURRENT_STATE = ("lock-mechanism", "lock-mechanism.current-state")
|
||||
LOCK_TARGET_STATE = ("lock-mechanism", "lock-mechanism.target-state")
|
||||
|
||||
|
||||
def create_lock_service():
|
||||
"""Define a lock characteristics as per page 219 of HAP spec."""
|
||||
service = FakeService('public.hap.service.lock-mechanism')
|
||||
service = FakeService("public.hap.service.lock-mechanism")
|
||||
|
||||
cur_state = service.add_characteristic('lock-mechanism.current-state')
|
||||
cur_state = service.add_characteristic("lock-mechanism.current-state")
|
||||
cur_state.value = 0
|
||||
|
||||
targ_state = service.add_characteristic('lock-mechanism.target-state')
|
||||
targ_state = service.add_characteristic("lock-mechanism.target-state")
|
||||
targ_state.value = 0
|
||||
|
||||
# According to the spec, a battery-level characteristic is normally
|
||||
# part of a seperate service. However as the code was written (which
|
||||
# predates this test) the battery level would have to be part of the lock
|
||||
# service as it is here.
|
||||
targ_state = service.add_characteristic('battery-level')
|
||||
targ_state = service.add_characteristic("battery-level")
|
||||
targ_state.value = 50
|
||||
|
||||
return service
|
||||
@@ -31,14 +30,14 @@ async def test_switch_change_lock_state(hass, utcnow):
|
||||
lock = create_lock_service()
|
||||
helper = await setup_test_component(hass, [lock])
|
||||
|
||||
await hass.services.async_call('lock', 'lock', {
|
||||
'entity_id': 'lock.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"lock", "lock", {"entity_id": "lock.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[LOCK_TARGET_STATE].value == 1
|
||||
|
||||
await hass.services.async_call('lock', 'unlock', {
|
||||
'entity_id': 'lock.testdevice',
|
||||
}, blocking=True)
|
||||
await hass.services.async_call(
|
||||
"lock", "unlock", {"entity_id": "lock.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[LOCK_TARGET_STATE].value == 0
|
||||
|
||||
|
||||
@@ -50,10 +49,10 @@ async def test_switch_read_lock_state(hass, utcnow):
|
||||
helper.characteristics[LOCK_CURRENT_STATE].value = 0
|
||||
helper.characteristics[LOCK_TARGET_STATE].value = 0
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'unlocked'
|
||||
assert state.attributes['battery_level'] == 50
|
||||
assert state.state == "unlocked"
|
||||
assert state.attributes["battery_level"] == 50
|
||||
|
||||
helper.characteristics[LOCK_CURRENT_STATE].value = 1
|
||||
helper.characteristics[LOCK_TARGET_STATE].value = 1
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == 'locked'
|
||||
assert state.state == "locked"
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
"""Basic checks for HomeKit sensor."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component)
|
||||
from tests.components.homekit_controller.common import FakeService, setup_test_component
|
||||
|
||||
TEMPERATURE = ('temperature', 'temperature.current')
|
||||
HUMIDITY = ('humidity', 'relative-humidity.current')
|
||||
LIGHT_LEVEL = ('light', 'light-level.current')
|
||||
TEMPERATURE = ("temperature", "temperature.current")
|
||||
HUMIDITY = ("humidity", "relative-humidity.current")
|
||||
LIGHT_LEVEL = ("light", "light-level.current")
|
||||
|
||||
|
||||
def create_temperature_sensor_service():
|
||||
"""Define temperature characteristics."""
|
||||
service = FakeService('public.hap.service.sensor.temperature')
|
||||
service = FakeService("public.hap.service.sensor.temperature")
|
||||
|
||||
cur_state = service.add_characteristic('temperature.current')
|
||||
cur_state = service.add_characteristic("temperature.current")
|
||||
cur_state.value = 0
|
||||
|
||||
return service
|
||||
@@ -19,9 +18,9 @@ def create_temperature_sensor_service():
|
||||
|
||||
def create_humidity_sensor_service():
|
||||
"""Define humidity characteristics."""
|
||||
service = FakeService('public.hap.service.sensor.humidity')
|
||||
service = FakeService("public.hap.service.sensor.humidity")
|
||||
|
||||
cur_state = service.add_characteristic('relative-humidity.current')
|
||||
cur_state = service.add_characteristic("relative-humidity.current")
|
||||
cur_state.value = 0
|
||||
|
||||
return service
|
||||
@@ -29,9 +28,9 @@ def create_humidity_sensor_service():
|
||||
|
||||
def create_light_level_sensor_service():
|
||||
"""Define light level characteristics."""
|
||||
service = FakeService('public.hap.service.sensor.light')
|
||||
service = FakeService("public.hap.service.sensor.light")
|
||||
|
||||
cur_state = service.add_characteristic('light-level.current')
|
||||
cur_state = service.add_characteristic("light-level.current")
|
||||
cur_state.value = 0
|
||||
|
||||
return service
|
||||
@@ -44,11 +43,11 @@ async def test_temperature_sensor_read_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[TEMPERATURE].value = 10
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '10'
|
||||
assert state.state == "10"
|
||||
|
||||
helper.characteristics[TEMPERATURE].value = 20
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '20'
|
||||
assert state.state == "20"
|
||||
|
||||
|
||||
async def test_humidity_sensor_read_state(hass, utcnow):
|
||||
@@ -58,11 +57,11 @@ async def test_humidity_sensor_read_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[HUMIDITY].value = 10
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '10'
|
||||
assert state.state == "10"
|
||||
|
||||
helper.characteristics[HUMIDITY].value = 20
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '20'
|
||||
assert state.state == "20"
|
||||
|
||||
|
||||
async def test_light_level_sensor_read_state(hass, utcnow):
|
||||
@@ -72,8 +71,8 @@ async def test_light_level_sensor_read_state(hass, utcnow):
|
||||
|
||||
helper.characteristics[LIGHT_LEVEL].value = 10
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '10'
|
||||
assert state.state == "10"
|
||||
|
||||
helper.characteristics[LIGHT_LEVEL].value = 20
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.state == '20'
|
||||
assert state.state == "20"
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
"""Basic checks for entity map storage."""
|
||||
from tests.common import flush_store
|
||||
from tests.components.homekit_controller.common import (
|
||||
FakeService, setup_test_component, setup_platform)
|
||||
FakeService,
|
||||
setup_test_component,
|
||||
setup_platform,
|
||||
)
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.homekit_controller import async_remove_entry
|
||||
@@ -10,18 +13,11 @@ from homeassistant.components.homekit_controller.const import ENTITY_MAP
|
||||
|
||||
async def test_load_from_storage(hass, hass_storage):
|
||||
"""Test that entity map can be correctly loaded from cache."""
|
||||
hkid = '00:00:00:00:00:00'
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
hass_storage['homekit_controller-entity-map'] = {
|
||||
'version': 1,
|
||||
'data': {
|
||||
'pairings': {
|
||||
hkid: {
|
||||
'c#': 1,
|
||||
'accessories': [],
|
||||
}
|
||||
}
|
||||
}
|
||||
hass_storage["homekit_controller-entity-map"] = {
|
||||
"version": 1,
|
||||
"data": {"pairings": {hkid: {"c#": 1, "accessories": []}}},
|
||||
}
|
||||
|
||||
await setup_platform(hass)
|
||||
@@ -33,22 +29,18 @@ async def test_storage_is_removed(hass, hass_storage):
|
||||
await setup_platform(hass)
|
||||
|
||||
entity_map = hass.data[ENTITY_MAP]
|
||||
hkid = '00:00:00:00:00:01'
|
||||
hkid = "00:00:00:00:00:01"
|
||||
|
||||
entity_map.async_create_or_update_map(
|
||||
hkid,
|
||||
1,
|
||||
[],
|
||||
)
|
||||
entity_map.async_create_or_update_map(hkid, 1, [])
|
||||
assert hkid in entity_map.storage_data
|
||||
await flush_store(entity_map.store)
|
||||
assert hkid in hass_storage[ENTITY_MAP]['data']['pairings']
|
||||
assert hkid in hass_storage[ENTITY_MAP]["data"]["pairings"]
|
||||
|
||||
entity_map.async_delete_map(hkid)
|
||||
assert hkid not in hass.data[ENTITY_MAP].storage_data
|
||||
await flush_store(entity_map.store)
|
||||
|
||||
assert hass_storage[ENTITY_MAP]['data']['pairings'] == {}
|
||||
assert hass_storage[ENTITY_MAP]["data"]["pairings"] == {}
|
||||
|
||||
|
||||
async def test_storage_is_removed_idempotent(hass):
|
||||
@@ -56,7 +48,7 @@ async def test_storage_is_removed_idempotent(hass):
|
||||
await setup_platform(hass)
|
||||
|
||||
entity_map = hass.data[ENTITY_MAP]
|
||||
hkid = '00:00:00:00:00:01'
|
||||
hkid = "00:00:00:00:00:01"
|
||||
|
||||
assert hkid not in entity_map.storage_data
|
||||
|
||||
@@ -67,8 +59,8 @@ async def test_storage_is_removed_idempotent(hass):
|
||||
|
||||
def create_lightbulb_service():
|
||||
"""Define lightbulb characteristics."""
|
||||
service = FakeService('public.hap.service.lightbulb')
|
||||
on_char = service.add_characteristic('on')
|
||||
service = FakeService("public.hap.service.lightbulb")
|
||||
on_char = service.add_characteristic("on")
|
||||
on_char.value = 0
|
||||
return service
|
||||
|
||||
@@ -79,14 +71,14 @@ async def test_storage_is_updated_on_add(hass, hass_storage, utcnow):
|
||||
await setup_test_component(hass, [bulb])
|
||||
|
||||
entity_map = hass.data[ENTITY_MAP]
|
||||
hkid = '00:00:00:00:00:00'
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
# Is in memory store updated?
|
||||
assert hkid in entity_map.storage_data
|
||||
|
||||
# Is saved out to store?
|
||||
await flush_store(entity_map.store)
|
||||
assert hkid in hass_storage[ENTITY_MAP]['data']['pairings']
|
||||
assert hkid in hass_storage[ENTITY_MAP]["data"]["pairings"]
|
||||
|
||||
|
||||
async def test_storage_is_removed_on_config_entry_removal(hass, utcnow):
|
||||
@@ -94,15 +86,17 @@ async def test_storage_is_removed_on_config_entry_removal(hass, utcnow):
|
||||
bulb = create_lightbulb_service()
|
||||
await setup_test_component(hass, [bulb])
|
||||
|
||||
hkid = '00:00:00:00:00:00'
|
||||
hkid = "00:00:00:00:00:00"
|
||||
|
||||
pairing_data = {
|
||||
'AccessoryPairingID': hkid,
|
||||
}
|
||||
pairing_data = {"AccessoryPairingID": hkid}
|
||||
|
||||
entry = config_entries.ConfigEntry(
|
||||
1, 'homekit_controller', 'TestData', pairing_data,
|
||||
'test', config_entries.CONN_CLASS_LOCAL_PUSH
|
||||
1,
|
||||
"homekit_controller",
|
||||
"TestData",
|
||||
pairing_data,
|
||||
"test",
|
||||
config_entries.CONN_CLASS_LOCAL_PUSH,
|
||||
)
|
||||
|
||||
assert hkid in hass.data[ENTITY_MAP].storage_data
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
"""Basic checks for HomeKitSwitch."""
|
||||
from tests.components.homekit_controller.common import (
|
||||
setup_test_component)
|
||||
from tests.components.homekit_controller.common import setup_test_component
|
||||
|
||||
|
||||
async def test_switch_change_outlet_state(hass, utcnow):
|
||||
@@ -9,15 +8,15 @@ async def test_switch_change_outlet_state(hass, utcnow):
|
||||
|
||||
helper = await setup_test_component(hass, [OutletService()])
|
||||
|
||||
await hass.services.async_call('switch', 'turn_on', {
|
||||
'entity_id': 'switch.testdevice',
|
||||
}, blocking=True)
|
||||
assert helper.characteristics[('outlet', 'on')].value == 1
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_on", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[("outlet", "on")].value == 1
|
||||
|
||||
await hass.services.async_call('switch', 'turn_off', {
|
||||
'entity_id': 'switch.testdevice',
|
||||
}, blocking=True)
|
||||
assert helper.characteristics[('outlet', 'on')].value == 0
|
||||
await hass.services.async_call(
|
||||
"switch", "turn_off", {"entity_id": "switch.testdevice"}, blocking=True
|
||||
)
|
||||
assert helper.characteristics[("outlet", "on")].value == 0
|
||||
|
||||
|
||||
async def test_switch_read_outlet_state(hass, utcnow):
|
||||
@@ -28,22 +27,22 @@ async def test_switch_read_outlet_state(hass, utcnow):
|
||||
|
||||
# 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['outlet_in_use'] is False
|
||||
assert switch_1.state == "off"
|
||||
assert switch_1.attributes["outlet_in_use"] is False
|
||||
|
||||
# Simulate that someone switched on the device in the real world not via HA
|
||||
helper.characteristics[('outlet', 'on')].set_value(True)
|
||||
helper.characteristics[("outlet", "on")].set_value(True)
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == 'on'
|
||||
assert switch_1.attributes['outlet_in_use'] is False
|
||||
assert switch_1.state == "on"
|
||||
assert switch_1.attributes["outlet_in_use"] is False
|
||||
|
||||
# Simulate that device switched off in the real world not via HA
|
||||
helper.characteristics[('outlet', 'on')].set_value(False)
|
||||
helper.characteristics[("outlet", "on")].set_value(False)
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == 'off'
|
||||
assert switch_1.state == "off"
|
||||
|
||||
# Simulate that someone plugged something into the device
|
||||
helper.characteristics[('outlet', 'outlet-in-use')].value = True
|
||||
helper.characteristics[("outlet", "outlet-in-use")].value = True
|
||||
switch_1 = await helper.poll_and_get_state()
|
||||
assert switch_1.state == 'off'
|
||||
assert switch_1.attributes['outlet_in_use'] is True
|
||||
assert switch_1.state == "off"
|
||||
assert switch_1.attributes["outlet_in_use"] is True
|
||||
|
||||
Reference in New Issue
Block a user