Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue