Search is not available for this dataset
identifier
stringlengths 1
155
| parameters
stringlengths 2
6.09k
| docstring
stringlengths 11
63.4k
| docstring_summary
stringlengths 0
63.4k
| function
stringlengths 29
99.8k
| function_tokens
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
test_lights_turn_on_when_coming_home_after_sun_set_person | (hass, scanner) | Test lights turn on when coming home after sun set. | Test lights turn on when coming home after sun set. | async def test_lights_turn_on_when_coming_home_after_sun_set_person(hass, scanner):
"""Test lights turn on when coming home after sun set."""
device_1 = f"{DOMAIN}.device_1"
device_2 = f"{DOMAIN}.device_2"
test_time = datetime(2017, 4, 5, 3, 2, 3, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=test_time):
await hass.services.async_call(
light.DOMAIN, light.SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "all"}, blocking=True
)
hass.states.async_set(device_1, STATE_NOT_HOME)
hass.states.async_set(device_2, STATE_NOT_HOME)
await hass.async_block_till_done()
assert all(
not light.is_on(hass, ent_id)
for ent_id in hass.states.async_entity_ids("light")
)
assert hass.states.get(device_1).state == "not_home"
assert hass.states.get(device_2).state == "not_home"
assert await async_setup_component(
hass,
"person",
{"person": [{"id": "me", "name": "Me", "device_trackers": [device_1]}]},
)
assert await async_setup_component(hass, "group", {})
await hass.async_block_till_done()
await group.Group.async_create_group(hass, "person_me", ["person.me"])
assert await async_setup_component(
hass,
device_sun_light_trigger.DOMAIN,
{device_sun_light_trigger.DOMAIN: {"device_group": "group.person_me"}},
)
assert all(
hass.states.get(ent_id).state == STATE_OFF
for ent_id in hass.states.async_entity_ids("light")
)
assert hass.states.get(device_1).state == "not_home"
assert hass.states.get(device_2).state == "not_home"
assert hass.states.get("person.me").state == "not_home"
# Unrelated device has no impact
hass.states.async_set(device_2, STATE_HOME)
await hass.async_block_till_done()
assert all(
hass.states.get(ent_id).state == STATE_OFF
for ent_id in hass.states.async_entity_ids("light")
)
assert hass.states.get(device_1).state == "not_home"
assert hass.states.get(device_2).state == "home"
assert hass.states.get("person.me").state == "not_home"
# person home switches on
hass.states.async_set(device_1, STATE_HOME)
await hass.async_block_till_done()
await hass.async_block_till_done()
assert all(
hass.states.get(ent_id).state == light.STATE_ON
for ent_id in hass.states.async_entity_ids("light")
)
assert hass.states.get(device_1).state == "home"
assert hass.states.get(device_2).state == "home"
assert hass.states.get("person.me").state == "home" | [
"async",
"def",
"test_lights_turn_on_when_coming_home_after_sun_set_person",
"(",
"hass",
",",
"scanner",
")",
":",
"device_1",
"=",
"f\"{DOMAIN}.device_1\"",
"device_2",
"=",
"f\"{DOMAIN}.device_2\"",
"test_time",
"=",
"datetime",
"(",
"2017",
",",
"4",
",",
"5",
",",
"3",
",",
"2",
",",
"3",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"test_time",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"light",
".",
"DOMAIN",
",",
"light",
".",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"all\"",
"}",
",",
"blocking",
"=",
"True",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"device_1",
",",
"STATE_NOT_HOME",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"device_2",
",",
"STATE_NOT_HOME",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"all",
"(",
"not",
"light",
".",
"is_on",
"(",
"hass",
",",
"ent_id",
")",
"for",
"ent_id",
"in",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"\"light\"",
")",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_1",
")",
".",
"state",
"==",
"\"not_home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_2",
")",
".",
"state",
"==",
"\"not_home\"",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"person\"",
",",
"{",
"\"person\"",
":",
"[",
"{",
"\"id\"",
":",
"\"me\"",
",",
"\"name\"",
":",
"\"Me\"",
",",
"\"device_trackers\"",
":",
"[",
"device_1",
"]",
"}",
"]",
"}",
",",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"group\"",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"group",
".",
"Group",
".",
"async_create_group",
"(",
"hass",
",",
"\"person_me\"",
",",
"[",
"\"person.me\"",
"]",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"device_sun_light_trigger",
".",
"DOMAIN",
",",
"{",
"device_sun_light_trigger",
".",
"DOMAIN",
":",
"{",
"\"device_group\"",
":",
"\"group.person_me\"",
"}",
"}",
",",
")",
"assert",
"all",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"ent_id",
")",
".",
"state",
"==",
"STATE_OFF",
"for",
"ent_id",
"in",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"\"light\"",
")",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_1",
")",
".",
"state",
"==",
"\"not_home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_2",
")",
".",
"state",
"==",
"\"not_home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"person.me\"",
")",
".",
"state",
"==",
"\"not_home\"",
"# Unrelated device has no impact",
"hass",
".",
"states",
".",
"async_set",
"(",
"device_2",
",",
"STATE_HOME",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"all",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"ent_id",
")",
".",
"state",
"==",
"STATE_OFF",
"for",
"ent_id",
"in",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"\"light\"",
")",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_1",
")",
".",
"state",
"==",
"\"not_home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_2",
")",
".",
"state",
"==",
"\"home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"person.me\"",
")",
".",
"state",
"==",
"\"not_home\"",
"# person home switches on",
"hass",
".",
"states",
".",
"async_set",
"(",
"device_1",
",",
"STATE_HOME",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"all",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"ent_id",
")",
".",
"state",
"==",
"light",
".",
"STATE_ON",
"for",
"ent_id",
"in",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"\"light\"",
")",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_1",
")",
".",
"state",
"==",
"\"home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"device_2",
")",
".",
"state",
"==",
"\"home\"",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"person.me\"",
")",
".",
"state",
"==",
"\"home\""
] | [
151,
0
] | [
219,
59
] | python | en | ['en', 'en', 'en'] | True |
test_initialize_start | (hass) | Test we initialize when HA starts. | Test we initialize when HA starts. | async def test_initialize_start(hass):
"""Test we initialize when HA starts."""
hass.state = CoreState.not_running
assert await async_setup_component(
hass,
device_sun_light_trigger.DOMAIN,
{device_sun_light_trigger.DOMAIN: {}},
)
with patch(
"homeassistant.components.device_sun_light_trigger.activate_automation"
) as mock_activate:
hass.bus.fire(EVENT_HOMEASSISTANT_START)
await hass.async_block_till_done()
assert len(mock_activate.mock_calls) == 1 | [
"async",
"def",
"test_initialize_start",
"(",
"hass",
")",
":",
"hass",
".",
"state",
"=",
"CoreState",
".",
"not_running",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"device_sun_light_trigger",
".",
"DOMAIN",
",",
"{",
"device_sun_light_trigger",
".",
"DOMAIN",
":",
"{",
"}",
"}",
",",
")",
"with",
"patch",
"(",
"\"homeassistant.components.device_sun_light_trigger.activate_automation\"",
")",
"as",
"mock_activate",
":",
"hass",
".",
"bus",
".",
"fire",
"(",
"EVENT_HOMEASSISTANT_START",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_activate",
".",
"mock_calls",
")",
"==",
"1"
] | [
222,
0
] | [
237,
45
] | python | en | ['en', 'en', 'en'] | True |
light_mock_data_fixture | () | Create light mock data. | Create light mock data. | def light_mock_data_fixture() -> None:
"""Create light mock data."""
sys_info = {
"sw_ver": "1.2.3",
"hw_ver": "2.3.4",
"mac": "aa:bb:cc:dd:ee:ff",
"mic_mac": "00:11:22:33:44",
"type": "light",
"hwId": "1234",
"fwId": "4567",
"oemId": "891011",
"dev_name": "light1",
"rssi": 11,
"latitude": "0",
"longitude": "0",
"is_color": True,
"is_dimmable": True,
"is_variable_color_temp": True,
"model": "LB120",
"alias": "light1",
}
light_state = {
"on_off": True,
"dft_on_state": {
"brightness": 12,
"color_temp": 3200,
"hue": 110,
"saturation": 90,
},
"brightness": 13,
"color_temp": 3300,
"hue": 110,
"saturation": 90,
}
def set_light_state(state) -> None:
nonlocal light_state
drt_on_state = light_state["dft_on_state"]
drt_on_state.update(state.get("dft_on_state", {}))
light_state.update(state)
light_state["dft_on_state"] = drt_on_state
return light_state
set_light_state_patch = patch(
"homeassistant.components.tplink.common.SmartBulb.set_light_state",
side_effect=set_light_state,
)
get_light_state_patch = patch(
"homeassistant.components.tplink.common.SmartBulb.get_light_state",
return_value=light_state,
)
current_consumption_patch = patch(
"homeassistant.components.tplink.common.SmartDevice.current_consumption",
return_value=3.23,
)
get_sysinfo_patch = patch(
"homeassistant.components.tplink.common.SmartDevice.get_sysinfo",
return_value=sys_info,
)
get_emeter_daily_patch = patch(
"homeassistant.components.tplink.common.SmartDevice.get_emeter_daily",
return_value={
1: 1.01,
2: 1.02,
3: 1.03,
4: 1.04,
5: 1.05,
6: 1.06,
7: 1.07,
8: 1.08,
9: 1.09,
10: 1.10,
11: 1.11,
12: 1.12,
},
)
get_emeter_monthly_patch = patch(
"homeassistant.components.tplink.common.SmartDevice.get_emeter_monthly",
return_value={
1: 2.01,
2: 2.02,
3: 2.03,
4: 2.04,
5: 2.05,
6: 2.06,
7: 2.07,
8: 2.08,
9: 2.09,
10: 2.10,
11: 2.11,
12: 2.12,
},
)
with set_light_state_patch as set_light_state_mock, get_light_state_patch as get_light_state_mock, current_consumption_patch as current_consumption_mock, get_sysinfo_patch as get_sysinfo_mock, get_emeter_daily_patch as get_emeter_daily_mock, get_emeter_monthly_patch as get_emeter_monthly_mock:
yield LightMockData(
sys_info=sys_info,
light_state=light_state,
set_light_state=set_light_state,
set_light_state_mock=set_light_state_mock,
get_light_state_mock=get_light_state_mock,
current_consumption_mock=current_consumption_mock,
get_sysinfo_mock=get_sysinfo_mock,
get_emeter_daily_mock=get_emeter_daily_mock,
get_emeter_monthly_mock=get_emeter_monthly_mock,
) | [
"def",
"light_mock_data_fixture",
"(",
")",
"->",
"None",
":",
"sys_info",
"=",
"{",
"\"sw_ver\"",
":",
"\"1.2.3\"",
",",
"\"hw_ver\"",
":",
"\"2.3.4\"",
",",
"\"mac\"",
":",
"\"aa:bb:cc:dd:ee:ff\"",
",",
"\"mic_mac\"",
":",
"\"00:11:22:33:44\"",
",",
"\"type\"",
":",
"\"light\"",
",",
"\"hwId\"",
":",
"\"1234\"",
",",
"\"fwId\"",
":",
"\"4567\"",
",",
"\"oemId\"",
":",
"\"891011\"",
",",
"\"dev_name\"",
":",
"\"light1\"",
",",
"\"rssi\"",
":",
"11",
",",
"\"latitude\"",
":",
"\"0\"",
",",
"\"longitude\"",
":",
"\"0\"",
",",
"\"is_color\"",
":",
"True",
",",
"\"is_dimmable\"",
":",
"True",
",",
"\"is_variable_color_temp\"",
":",
"True",
",",
"\"model\"",
":",
"\"LB120\"",
",",
"\"alias\"",
":",
"\"light1\"",
",",
"}",
"light_state",
"=",
"{",
"\"on_off\"",
":",
"True",
",",
"\"dft_on_state\"",
":",
"{",
"\"brightness\"",
":",
"12",
",",
"\"color_temp\"",
":",
"3200",
",",
"\"hue\"",
":",
"110",
",",
"\"saturation\"",
":",
"90",
",",
"}",
",",
"\"brightness\"",
":",
"13",
",",
"\"color_temp\"",
":",
"3300",
",",
"\"hue\"",
":",
"110",
",",
"\"saturation\"",
":",
"90",
",",
"}",
"def",
"set_light_state",
"(",
"state",
")",
"->",
"None",
":",
"nonlocal",
"light_state",
"drt_on_state",
"=",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"drt_on_state",
".",
"update",
"(",
"state",
".",
"get",
"(",
"\"dft_on_state\"",
",",
"{",
"}",
")",
")",
"light_state",
".",
"update",
"(",
"state",
")",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"=",
"drt_on_state",
"return",
"light_state",
"set_light_state_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartBulb.set_light_state\"",
",",
"side_effect",
"=",
"set_light_state",
",",
")",
"get_light_state_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartBulb.get_light_state\"",
",",
"return_value",
"=",
"light_state",
",",
")",
"current_consumption_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.current_consumption\"",
",",
"return_value",
"=",
"3.23",
",",
")",
"get_sysinfo_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.get_sysinfo\"",
",",
"return_value",
"=",
"sys_info",
",",
")",
"get_emeter_daily_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.get_emeter_daily\"",
",",
"return_value",
"=",
"{",
"1",
":",
"1.01",
",",
"2",
":",
"1.02",
",",
"3",
":",
"1.03",
",",
"4",
":",
"1.04",
",",
"5",
":",
"1.05",
",",
"6",
":",
"1.06",
",",
"7",
":",
"1.07",
",",
"8",
":",
"1.08",
",",
"9",
":",
"1.09",
",",
"10",
":",
"1.10",
",",
"11",
":",
"1.11",
",",
"12",
":",
"1.12",
",",
"}",
",",
")",
"get_emeter_monthly_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.get_emeter_monthly\"",
",",
"return_value",
"=",
"{",
"1",
":",
"2.01",
",",
"2",
":",
"2.02",
",",
"3",
":",
"2.03",
",",
"4",
":",
"2.04",
",",
"5",
":",
"2.05",
",",
"6",
":",
"2.06",
",",
"7",
":",
"2.07",
",",
"8",
":",
"2.08",
",",
"9",
":",
"2.09",
",",
"10",
":",
"2.10",
",",
"11",
":",
"2.11",
",",
"12",
":",
"2.12",
",",
"}",
",",
")",
"with",
"set_light_state_patch",
"as",
"set_light_state_mock",
",",
"get_light_state_patch",
"as",
"get_light_state_mock",
",",
"current_consumption_patch",
"as",
"current_consumption_mock",
",",
"get_sysinfo_patch",
"as",
"get_sysinfo_mock",
",",
"get_emeter_daily_patch",
"as",
"get_emeter_daily_mock",
",",
"get_emeter_monthly_patch",
"as",
"get_emeter_monthly_mock",
":",
"yield",
"LightMockData",
"(",
"sys_info",
"=",
"sys_info",
",",
"light_state",
"=",
"light_state",
",",
"set_light_state",
"=",
"set_light_state",
",",
"set_light_state_mock",
"=",
"set_light_state_mock",
",",
"get_light_state_mock",
"=",
"get_light_state_mock",
",",
"current_consumption_mock",
"=",
"current_consumption_mock",
",",
"get_sysinfo_mock",
"=",
"get_sysinfo_mock",
",",
"get_emeter_daily_mock",
"=",
"get_emeter_daily_mock",
",",
"get_emeter_monthly_mock",
"=",
"get_emeter_monthly_mock",
",",
")"
] | [
63,
0
] | [
170,
9
] | python | en | ['es', 'no', 'en'] | False |
dimmer_switch_mock_data_fixture | () | Create dimmer switch mock data. | Create dimmer switch mock data. | def dimmer_switch_mock_data_fixture() -> None:
"""Create dimmer switch mock data."""
sys_info = {
"sw_ver": "1.2.3",
"hw_ver": "2.3.4",
"mac": "aa:bb:cc:dd:ee:ff",
"mic_mac": "00:11:22:33:44",
"type": "switch",
"hwId": "1234",
"fwId": "4567",
"oemId": "891011",
"dev_name": "dimmer1",
"rssi": 11,
"latitude": "0",
"longitude": "0",
"is_color": False,
"is_dimmable": True,
"is_variable_color_temp": False,
"model": "HS220",
"alias": "dimmer1",
"feature": ":",
"relay_state": 1,
"brightness": 13,
}
def state(*args, **kwargs):
nonlocal sys_info
if len(args) == 0:
return sys_info["relay_state"]
if args[0] == "ON":
sys_info["relay_state"] = 1
else:
sys_info["relay_state"] = 0
def brightness(*args, **kwargs):
nonlocal sys_info
if len(args) == 0:
return sys_info["brightness"]
if sys_info["brightness"] == 0:
sys_info["relay_state"] = 0
else:
sys_info["relay_state"] = 1
sys_info["brightness"] = args[0]
get_sysinfo_patch = patch(
"homeassistant.components.tplink.common.SmartDevice.get_sysinfo",
return_value=sys_info,
)
state_patch = patch(
"homeassistant.components.tplink.common.SmartPlug.state",
new_callable=PropertyMock,
side_effect=state,
)
brightness_patch = patch(
"homeassistant.components.tplink.common.SmartPlug.brightness",
new_callable=PropertyMock,
side_effect=brightness,
)
with brightness_patch as brightness_mock, state_patch as state_mock, get_sysinfo_patch as get_sysinfo_mock:
yield SmartSwitchMockData(
sys_info=sys_info,
brightness_mock=brightness_mock,
state_mock=state_mock,
get_sysinfo_mock=get_sysinfo_mock,
) | [
"def",
"dimmer_switch_mock_data_fixture",
"(",
")",
"->",
"None",
":",
"sys_info",
"=",
"{",
"\"sw_ver\"",
":",
"\"1.2.3\"",
",",
"\"hw_ver\"",
":",
"\"2.3.4\"",
",",
"\"mac\"",
":",
"\"aa:bb:cc:dd:ee:ff\"",
",",
"\"mic_mac\"",
":",
"\"00:11:22:33:44\"",
",",
"\"type\"",
":",
"\"switch\"",
",",
"\"hwId\"",
":",
"\"1234\"",
",",
"\"fwId\"",
":",
"\"4567\"",
",",
"\"oemId\"",
":",
"\"891011\"",
",",
"\"dev_name\"",
":",
"\"dimmer1\"",
",",
"\"rssi\"",
":",
"11",
",",
"\"latitude\"",
":",
"\"0\"",
",",
"\"longitude\"",
":",
"\"0\"",
",",
"\"is_color\"",
":",
"False",
",",
"\"is_dimmable\"",
":",
"True",
",",
"\"is_variable_color_temp\"",
":",
"False",
",",
"\"model\"",
":",
"\"HS220\"",
",",
"\"alias\"",
":",
"\"dimmer1\"",
",",
"\"feature\"",
":",
"\":\"",
",",
"\"relay_state\"",
":",
"1",
",",
"\"brightness\"",
":",
"13",
",",
"}",
"def",
"state",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"nonlocal",
"sys_info",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"return",
"sys_info",
"[",
"\"relay_state\"",
"]",
"if",
"args",
"[",
"0",
"]",
"==",
"\"ON\"",
":",
"sys_info",
"[",
"\"relay_state\"",
"]",
"=",
"1",
"else",
":",
"sys_info",
"[",
"\"relay_state\"",
"]",
"=",
"0",
"def",
"brightness",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"nonlocal",
"sys_info",
"if",
"len",
"(",
"args",
")",
"==",
"0",
":",
"return",
"sys_info",
"[",
"\"brightness\"",
"]",
"if",
"sys_info",
"[",
"\"brightness\"",
"]",
"==",
"0",
":",
"sys_info",
"[",
"\"relay_state\"",
"]",
"=",
"0",
"else",
":",
"sys_info",
"[",
"\"relay_state\"",
"]",
"=",
"1",
"sys_info",
"[",
"\"brightness\"",
"]",
"=",
"args",
"[",
"0",
"]",
"get_sysinfo_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.get_sysinfo\"",
",",
"return_value",
"=",
"sys_info",
",",
")",
"state_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartPlug.state\"",
",",
"new_callable",
"=",
"PropertyMock",
",",
"side_effect",
"=",
"state",
",",
")",
"brightness_patch",
"=",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartPlug.brightness\"",
",",
"new_callable",
"=",
"PropertyMock",
",",
"side_effect",
"=",
"brightness",
",",
")",
"with",
"brightness_patch",
"as",
"brightness_mock",
",",
"state_patch",
"as",
"state_mock",
",",
"get_sysinfo_patch",
"as",
"get_sysinfo_mock",
":",
"yield",
"SmartSwitchMockData",
"(",
"sys_info",
"=",
"sys_info",
",",
"brightness_mock",
"=",
"brightness_mock",
",",
"state_mock",
"=",
"state_mock",
",",
"get_sysinfo_mock",
"=",
"get_sysinfo_mock",
",",
")"
] | [
174,
0
] | [
238,
9
] | python | en | ['en', 'en', 'it'] | True |
update_entity | (hass: HomeAssistant, entity_id: str) | Run an update action for an entity. | Run an update action for an entity. | async def update_entity(hass: HomeAssistant, entity_id: str) -> None:
"""Run an update action for an entity."""
await hass.services.async_call(
HA_DOMAIN,
SERVICE_UPDATE_ENTITY,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
await hass.async_block_till_done() | [
"async",
"def",
"update_entity",
"(",
"hass",
":",
"HomeAssistant",
",",
"entity_id",
":",
"str",
")",
"->",
"None",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"HA_DOMAIN",
",",
"SERVICE_UPDATE_ENTITY",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
241,
0
] | [
249,
38
] | python | en | ['br', 'en', 'en'] | True |
test_smartswitch | (
hass: HomeAssistant, dimmer_switch_mock_data: SmartSwitchMockData
) | Test function. | Test function. | async def test_smartswitch(
hass: HomeAssistant, dimmer_switch_mock_data: SmartSwitchMockData
) -> None:
"""Test function."""
sys_info = dimmer_switch_mock_data.sys_info
await async_setup_component(hass, HA_DOMAIN, {})
await hass.async_block_till_done()
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_DISCOVERY: False,
CONF_DIMMER: [{CONF_HOST: "123.123.123.123"}],
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.dimmer1")
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "light.dimmer1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.dimmer1")
assert hass.states.get("light.dimmer1").state == "off"
assert sys_info["relay_state"] == 0
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.dimmer1", ATTR_BRIGHTNESS: 50},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.dimmer1")
state = hass.states.get("light.dimmer1")
assert state.state == "on"
assert state.attributes["brightness"] == 51
assert sys_info["relay_state"] == 1
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.dimmer1", ATTR_BRIGHTNESS: 55},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.dimmer1")
state = hass.states.get("light.dimmer1")
assert state.state == "on"
assert state.attributes["brightness"] == 56
assert sys_info["brightness"] == 22
sys_info["relay_state"] = 0
sys_info["brightness"] = 66
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "light.dimmer1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.dimmer1")
state = hass.states.get("light.dimmer1")
assert state.state == "off"
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.dimmer1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.dimmer1")
state = hass.states.get("light.dimmer1")
assert state.state == "on"
assert state.attributes["brightness"] == 168
assert sys_info["brightness"] == 66 | [
"async",
"def",
"test_smartswitch",
"(",
"hass",
":",
"HomeAssistant",
",",
"dimmer_switch_mock_data",
":",
"SmartSwitchMockData",
")",
"->",
"None",
":",
"sys_info",
"=",
"dimmer_switch_mock_data",
".",
"sys_info",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"tplink",
".",
"DOMAIN",
",",
"{",
"tplink",
".",
"DOMAIN",
":",
"{",
"CONF_DISCOVERY",
":",
"False",
",",
"CONF_DIMMER",
":",
"[",
"{",
"CONF_HOST",
":",
"\"123.123.123.123\"",
"}",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.dimmer1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.dimmer1\"",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
".",
"state",
"==",
"\"off\"",
"assert",
"sys_info",
"[",
"\"relay_state\"",
"]",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.dimmer1\"",
",",
"ATTR_BRIGHTNESS",
":",
"50",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.dimmer1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"51",
"assert",
"sys_info",
"[",
"\"relay_state\"",
"]",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.dimmer1\"",
",",
"ATTR_BRIGHTNESS",
":",
"55",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.dimmer1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"56",
"assert",
"sys_info",
"[",
"\"brightness\"",
"]",
"==",
"22",
"sys_info",
"[",
"\"relay_state\"",
"]",
"=",
"0",
"sys_info",
"[",
"\"brightness\"",
"]",
"=",
"66",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.dimmer1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.dimmer1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"off\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.dimmer1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.dimmer1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"168",
"assert",
"sys_info",
"[",
"\"brightness\"",
"]",
"==",
"66"
] | [
252,
0
] | [
342,
39
] | python | en | ['en', 'en', 'en'] | False |
test_light | (hass: HomeAssistant, light_mock_data: LightMockData) | Test function. | Test function. | async def test_light(hass: HomeAssistant, light_mock_data: LightMockData) -> None:
"""Test function."""
light_state = light_mock_data.light_state
set_light_state = light_mock_data.set_light_state
await async_setup_component(hass, HA_DOMAIN, {})
await hass.async_block_till_done()
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_DISCOVERY: False,
CONF_LIGHT: [{CONF_HOST: "123.123.123.123"}],
}
},
)
await hass.async_block_till_done()
assert hass.states.get("light.light1")
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "light.light1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
assert hass.states.get("light.light1").state == "off"
assert light_state["on_off"] == 0
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.light1", ATTR_COLOR_TEMP: 222, ATTR_BRIGHTNESS: 50},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
state = hass.states.get("light.light1")
assert state.state == "on"
assert state.attributes["brightness"] == 51
assert state.attributes["hs_color"] == (110, 90)
assert state.attributes["color_temp"] == 222
assert light_state["on_off"] == 1
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.light1", ATTR_BRIGHTNESS: 55, ATTR_HS_COLOR: (23, 27)},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
state = hass.states.get("light.light1")
assert state.state == "on"
assert state.attributes["brightness"] == 56
assert state.attributes["hs_color"] == (23, 27)
assert light_state["brightness"] == 22
assert light_state["hue"] == 23
assert light_state["saturation"] == 27
light_state["on_off"] = 0
light_state["dft_on_state"]["on_off"] = 0
light_state["brightness"] = 66
light_state["dft_on_state"]["brightness"] = 66
light_state["color_temp"] = 6400
light_state["dft_on_state"]["color_temp"] = 123
light_state["hue"] = 77
light_state["dft_on_state"]["hue"] = 77
light_state["saturation"] = 78
light_state["dft_on_state"]["saturation"] = 78
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "light.light1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
state = hass.states.get("light.light1")
assert state.state == "off"
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: "light.light1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
state = hass.states.get("light.light1")
assert state.state == "on"
assert state.attributes["brightness"] == 168
assert state.attributes["hs_color"] == (77, 78)
assert state.attributes["color_temp"] == 156
assert light_state["brightness"] == 66
assert light_state["hue"] == 77
assert light_state["saturation"] == 78
set_light_state({"brightness": 91, "dft_on_state": {"brightness": 91}})
await update_entity(hass, "light.light1")
state = hass.states.get("light.light1")
assert state.attributes["brightness"] == 232 | [
"async",
"def",
"test_light",
"(",
"hass",
":",
"HomeAssistant",
",",
"light_mock_data",
":",
"LightMockData",
")",
"->",
"None",
":",
"light_state",
"=",
"light_mock_data",
".",
"light_state",
"set_light_state",
"=",
"light_mock_data",
".",
"set_light_state",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"tplink",
".",
"DOMAIN",
",",
"{",
"tplink",
".",
"DOMAIN",
":",
"{",
"CONF_DISCOVERY",
":",
"False",
",",
"CONF_LIGHT",
":",
"[",
"{",
"CONF_HOST",
":",
"\"123.123.123.123\"",
"}",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
".",
"state",
"==",
"\"off\"",
"assert",
"light_state",
"[",
"\"on_off\"",
"]",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
",",
"ATTR_COLOR_TEMP",
":",
"222",
",",
"ATTR_BRIGHTNESS",
":",
"50",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"51",
"assert",
"state",
".",
"attributes",
"[",
"\"hs_color\"",
"]",
"==",
"(",
"110",
",",
"90",
")",
"assert",
"state",
".",
"attributes",
"[",
"\"color_temp\"",
"]",
"==",
"222",
"assert",
"light_state",
"[",
"\"on_off\"",
"]",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
",",
"ATTR_BRIGHTNESS",
":",
"55",
",",
"ATTR_HS_COLOR",
":",
"(",
"23",
",",
"27",
")",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"56",
"assert",
"state",
".",
"attributes",
"[",
"\"hs_color\"",
"]",
"==",
"(",
"23",
",",
"27",
")",
"assert",
"light_state",
"[",
"\"brightness\"",
"]",
"==",
"22",
"assert",
"light_state",
"[",
"\"hue\"",
"]",
"==",
"23",
"assert",
"light_state",
"[",
"\"saturation\"",
"]",
"==",
"27",
"light_state",
"[",
"\"on_off\"",
"]",
"=",
"0",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"[",
"\"on_off\"",
"]",
"=",
"0",
"light_state",
"[",
"\"brightness\"",
"]",
"=",
"66",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"[",
"\"brightness\"",
"]",
"=",
"66",
"light_state",
"[",
"\"color_temp\"",
"]",
"=",
"6400",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"[",
"\"color_temp\"",
"]",
"=",
"123",
"light_state",
"[",
"\"hue\"",
"]",
"=",
"77",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"[",
"\"hue\"",
"]",
"=",
"77",
"light_state",
"[",
"\"saturation\"",
"]",
"=",
"78",
"light_state",
"[",
"\"dft_on_state\"",
"]",
"[",
"\"saturation\"",
"]",
"=",
"78",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"off\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"168",
"assert",
"state",
".",
"attributes",
"[",
"\"hs_color\"",
"]",
"==",
"(",
"77",
",",
"78",
")",
"assert",
"state",
".",
"attributes",
"[",
"\"color_temp\"",
"]",
"==",
"156",
"assert",
"light_state",
"[",
"\"brightness\"",
"]",
"==",
"66",
"assert",
"light_state",
"[",
"\"hue\"",
"]",
"==",
"77",
"assert",
"light_state",
"[",
"\"saturation\"",
"]",
"==",
"78",
"set_light_state",
"(",
"{",
"\"brightness\"",
":",
"91",
",",
"\"dft_on_state\"",
":",
"{",
"\"brightness\"",
":",
"91",
"}",
"}",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"assert",
"state",
".",
"attributes",
"[",
"\"brightness\"",
"]",
"==",
"232"
] | [
345,
0
] | [
457,
48
] | python | en | ['en', 'en', 'en'] | False |
test_get_light_state_retry | (
hass: HomeAssistant, light_mock_data: LightMockData
) | Test function. | Test function. | async def test_get_light_state_retry(
hass: HomeAssistant, light_mock_data: LightMockData
) -> None:
"""Test function."""
# Setup test for retries for sysinfo.
get_sysinfo_call_count = 0
def get_sysinfo_side_effect():
nonlocal get_sysinfo_call_count
get_sysinfo_call_count += 1
# Need to fail on the 2nd call because the first call is used to
# determine if the device is online during the light platform's
# setup hook.
if get_sysinfo_call_count == 2:
raise SmartDeviceException()
return light_mock_data.sys_info
light_mock_data.get_sysinfo_mock.side_effect = get_sysinfo_side_effect
# Setup test for retries of setting state information.
set_state_call_count = 0
def set_light_state_side_effect(state_data: dict):
nonlocal set_state_call_count, light_mock_data
set_state_call_count += 1
if set_state_call_count == 1:
raise SmartDeviceException()
return light_mock_data.set_light_state(state_data)
light_mock_data.set_light_state_mock.side_effect = set_light_state_side_effect
# Setup component.
await async_setup_component(hass, HA_DOMAIN, {})
await hass.async_block_till_done()
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_DISCOVERY: False,
CONF_LIGHT: [{CONF_HOST: "123.123.123.123"}],
}
},
)
await hass.async_block_till_done()
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "light.light1"},
blocking=True,
)
await hass.async_block_till_done()
await update_entity(hass, "light.light1")
assert light_mock_data.get_sysinfo_mock.call_count > 1
assert light_mock_data.get_light_state_mock.call_count > 1
assert light_mock_data.set_light_state_mock.call_count > 1
assert light_mock_data.get_sysinfo_mock.call_count < 40
assert light_mock_data.get_light_state_mock.call_count < 40
assert light_mock_data.set_light_state_mock.call_count < 10 | [
"async",
"def",
"test_get_light_state_retry",
"(",
"hass",
":",
"HomeAssistant",
",",
"light_mock_data",
":",
"LightMockData",
")",
"->",
"None",
":",
"# Setup test for retries for sysinfo.",
"get_sysinfo_call_count",
"=",
"0",
"def",
"get_sysinfo_side_effect",
"(",
")",
":",
"nonlocal",
"get_sysinfo_call_count",
"get_sysinfo_call_count",
"+=",
"1",
"# Need to fail on the 2nd call because the first call is used to",
"# determine if the device is online during the light platform's",
"# setup hook.",
"if",
"get_sysinfo_call_count",
"==",
"2",
":",
"raise",
"SmartDeviceException",
"(",
")",
"return",
"light_mock_data",
".",
"sys_info",
"light_mock_data",
".",
"get_sysinfo_mock",
".",
"side_effect",
"=",
"get_sysinfo_side_effect",
"# Setup test for retries of setting state information.",
"set_state_call_count",
"=",
"0",
"def",
"set_light_state_side_effect",
"(",
"state_data",
":",
"dict",
")",
":",
"nonlocal",
"set_state_call_count",
",",
"light_mock_data",
"set_state_call_count",
"+=",
"1",
"if",
"set_state_call_count",
"==",
"1",
":",
"raise",
"SmartDeviceException",
"(",
")",
"return",
"light_mock_data",
".",
"set_light_state",
"(",
"state_data",
")",
"light_mock_data",
".",
"set_light_state_mock",
".",
"side_effect",
"=",
"set_light_state_side_effect",
"# Setup component.",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"tplink",
".",
"DOMAIN",
",",
"{",
"tplink",
".",
"DOMAIN",
":",
"{",
"CONF_DISCOVERY",
":",
"False",
",",
"CONF_LIGHT",
":",
"[",
"{",
"CONF_HOST",
":",
"\"123.123.123.123\"",
"}",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.light1\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"assert",
"light_mock_data",
".",
"get_sysinfo_mock",
".",
"call_count",
">",
"1",
"assert",
"light_mock_data",
".",
"get_light_state_mock",
".",
"call_count",
">",
"1",
"assert",
"light_mock_data",
".",
"set_light_state_mock",
".",
"call_count",
">",
"1",
"assert",
"light_mock_data",
".",
"get_sysinfo_mock",
".",
"call_count",
"<",
"40",
"assert",
"light_mock_data",
".",
"get_light_state_mock",
".",
"call_count",
"<",
"40",
"assert",
"light_mock_data",
".",
"set_light_state_mock",
".",
"call_count",
"<",
"10"
] | [
460,
0
] | [
526,
63
] | python | en | ['en', 'en', 'en'] | False |
test_update_failure | (
hass: HomeAssistant, light_mock_data: LightMockData, caplog
) | Test that update failures are logged. | Test that update failures are logged. | async def test_update_failure(
hass: HomeAssistant, light_mock_data: LightMockData, caplog
):
"""Test that update failures are logged."""
await async_setup_component(hass, HA_DOMAIN, {})
await hass.async_block_till_done()
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_DISCOVERY: False,
CONF_LIGHT: [{CONF_HOST: "123.123.123.123"}],
}
},
)
await hass.async_block_till_done()
caplog.clear()
caplog.set_level(logging.WARNING)
await hass.helpers.entity_component.async_update_entity("light.light1")
assert caplog.text == ""
with patch("homeassistant.components.tplink.light.MAX_ATTEMPTS", 0):
caplog.clear()
caplog.set_level(logging.WARNING)
await hass.helpers.entity_component.async_update_entity("light.light1")
assert "Could not read state for 123.123.123.123|light1" in caplog.text
get_state_call_count = 0
def get_light_state_side_effect():
nonlocal get_state_call_count
get_state_call_count += 1
if get_state_call_count == 1:
raise SmartDeviceException()
return light_mock_data.light_state
light_mock_data.get_light_state_mock.side_effect = get_light_state_side_effect
with patch("homeassistant.components.tplink.light", MAX_ATTEMPTS=2, SLEEP_TIME=0):
caplog.clear()
caplog.set_level(logging.DEBUG)
await update_entity(hass, "light.light1")
assert (
f"Retrying in {SLEEP_TIME} seconds for 123.123.123.123|light1"
in caplog.text
)
assert "Device 123.123.123.123|light1 responded after " in caplog.text | [
"async",
"def",
"test_update_failure",
"(",
"hass",
":",
"HomeAssistant",
",",
"light_mock_data",
":",
"LightMockData",
",",
"caplog",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"tplink",
".",
"DOMAIN",
",",
"{",
"tplink",
".",
"DOMAIN",
":",
"{",
"CONF_DISCOVERY",
":",
"False",
",",
"CONF_LIGHT",
":",
"[",
"{",
"CONF_HOST",
":",
"\"123.123.123.123\"",
"}",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"caplog",
".",
"clear",
"(",
")",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"WARNING",
")",
"await",
"hass",
".",
"helpers",
".",
"entity_component",
".",
"async_update_entity",
"(",
"\"light.light1\"",
")",
"assert",
"caplog",
".",
"text",
"==",
"\"\"",
"with",
"patch",
"(",
"\"homeassistant.components.tplink.light.MAX_ATTEMPTS\"",
",",
"0",
")",
":",
"caplog",
".",
"clear",
"(",
")",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"WARNING",
")",
"await",
"hass",
".",
"helpers",
".",
"entity_component",
".",
"async_update_entity",
"(",
"\"light.light1\"",
")",
"assert",
"\"Could not read state for 123.123.123.123|light1\"",
"in",
"caplog",
".",
"text",
"get_state_call_count",
"=",
"0",
"def",
"get_light_state_side_effect",
"(",
")",
":",
"nonlocal",
"get_state_call_count",
"get_state_call_count",
"+=",
"1",
"if",
"get_state_call_count",
"==",
"1",
":",
"raise",
"SmartDeviceException",
"(",
")",
"return",
"light_mock_data",
".",
"light_state",
"light_mock_data",
".",
"get_light_state_mock",
".",
"side_effect",
"=",
"get_light_state_side_effect",
"with",
"patch",
"(",
"\"homeassistant.components.tplink.light\"",
",",
"MAX_ATTEMPTS",
"=",
"2",
",",
"SLEEP_TIME",
"=",
"0",
")",
":",
"caplog",
".",
"clear",
"(",
")",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"DEBUG",
")",
"await",
"update_entity",
"(",
"hass",
",",
"\"light.light1\"",
")",
"assert",
"(",
"f\"Retrying in {SLEEP_TIME} seconds for 123.123.123.123|light1\"",
"in",
"caplog",
".",
"text",
")",
"assert",
"\"Device 123.123.123.123|light1 responded after \"",
"in",
"caplog",
".",
"text"
] | [
529,
0
] | [
581,
78
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry_unavailable | (
hass: HomeAssistant, light_mock_data: LightMockData, caplog
) | Test unavailable devices trigger a later retry. | Test unavailable devices trigger a later retry. | async def test_async_setup_entry_unavailable(
hass: HomeAssistant, light_mock_data: LightMockData, caplog
):
"""Test unavailable devices trigger a later retry."""
caplog.clear()
caplog.set_level(logging.WARNING)
with patch(
"homeassistant.components.tplink.common.SmartDevice.get_sysinfo",
side_effect=SmartDeviceException,
):
await async_setup_component(hass, HA_DOMAIN, {})
await hass.async_block_till_done()
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_DISCOVERY: False,
CONF_LIGHT: [{CONF_HOST: "123.123.123.123"}],
}
},
)
await hass.async_block_till_done()
assert not hass.states.get("light.light1")
future = utcnow() + timedelta(seconds=30)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get("light.light1") | [
"async",
"def",
"test_async_setup_entry_unavailable",
"(",
"hass",
":",
"HomeAssistant",
",",
"light_mock_data",
":",
"LightMockData",
",",
"caplog",
")",
":",
"caplog",
".",
"clear",
"(",
")",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"WARNING",
")",
"with",
"patch",
"(",
"\"homeassistant.components.tplink.common.SmartDevice.get_sysinfo\"",
",",
"side_effect",
"=",
"SmartDeviceException",
",",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"tplink",
".",
"DOMAIN",
",",
"{",
"tplink",
".",
"DOMAIN",
":",
"{",
"CONF_DISCOVERY",
":",
"False",
",",
"CONF_LIGHT",
":",
"[",
"{",
"CONF_HOST",
":",
"\"123.123.123.123\"",
"}",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"not",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")",
"future",
"=",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"30",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"future",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.light1\"",
")"
] | [
584,
0
] | [
615,
42
] | python | ca | ['ca', 'en', 'it'] | False |
random_archi_generator | (nas_ss, random_state) | random
| random
| def random_archi_generator(nas_ss, random_state):
'''random
'''
chosen_arch = {}
for key, val in nas_ss.items():
assert val['_type'] in ['layer_choice', 'input_choice'], \
"Random NAS Tuner only receives NAS search space whose _type is 'layer_choice' or 'input_choice'"
if val['_type'] == 'layer_choice':
choices = val['_value']
index = random_state.randint(len(choices))
chosen_arch[key] = {'_value': choices[index], '_idx': index}
elif val['_type'] == 'input_choice':
choices = val['_value']['candidates']
n_chosen = val['_value']['n_chosen']
chosen = []
idxs = []
for _ in range(n_chosen):
index = random_state.randint(len(choices))
chosen.append(choices[index])
idxs.append(index)
chosen_arch[key] = {'_value': chosen, '_idx': idxs}
else:
raise ValueError('Unknown key %s and value %s' % (key, val))
return chosen_arch | [
"def",
"random_archi_generator",
"(",
"nas_ss",
",",
"random_state",
")",
":",
"chosen_arch",
"=",
"{",
"}",
"for",
"key",
",",
"val",
"in",
"nas_ss",
".",
"items",
"(",
")",
":",
"assert",
"val",
"[",
"'_type'",
"]",
"in",
"[",
"'layer_choice'",
",",
"'input_choice'",
"]",
",",
"\"Random NAS Tuner only receives NAS search space whose _type is 'layer_choice' or 'input_choice'\"",
"if",
"val",
"[",
"'_type'",
"]",
"==",
"'layer_choice'",
":",
"choices",
"=",
"val",
"[",
"'_value'",
"]",
"index",
"=",
"random_state",
".",
"randint",
"(",
"len",
"(",
"choices",
")",
")",
"chosen_arch",
"[",
"key",
"]",
"=",
"{",
"'_value'",
":",
"choices",
"[",
"index",
"]",
",",
"'_idx'",
":",
"index",
"}",
"elif",
"val",
"[",
"'_type'",
"]",
"==",
"'input_choice'",
":",
"choices",
"=",
"val",
"[",
"'_value'",
"]",
"[",
"'candidates'",
"]",
"n_chosen",
"=",
"val",
"[",
"'_value'",
"]",
"[",
"'n_chosen'",
"]",
"chosen",
"=",
"[",
"]",
"idxs",
"=",
"[",
"]",
"for",
"_",
"in",
"range",
"(",
"n_chosen",
")",
":",
"index",
"=",
"random_state",
".",
"randint",
"(",
"len",
"(",
"choices",
")",
")",
"chosen",
".",
"append",
"(",
"choices",
"[",
"index",
"]",
")",
"idxs",
".",
"append",
"(",
"index",
")",
"chosen_arch",
"[",
"key",
"]",
"=",
"{",
"'_value'",
":",
"chosen",
",",
"'_idx'",
":",
"idxs",
"}",
"else",
":",
"raise",
"ValueError",
"(",
"'Unknown key %s and value %s'",
"%",
"(",
"key",
",",
"val",
")",
")",
"return",
"chosen_arch"
] | [
5,
0
] | [
28,
22
] | python | en | ['en', 'mn', 'en'] | False |
RandomNASTuner.update_search_space | (self, search_space) | update
| update
| def update_search_space(self, search_space):
'''update
'''
self.searchspace_json = search_space
self.random_state = np.random.RandomState() | [
"def",
"update_search_space",
"(",
"self",
",",
"search_space",
")",
":",
"self",
".",
"searchspace_json",
"=",
"search_space",
"self",
".",
"random_state",
"=",
"np",
".",
"random",
".",
"RandomState",
"(",
")"
] | [
39,
4
] | [
43,
51
] | python | co | ['en', 'co', 'sw'] | False |
RandomNASTuner.generate_parameters | (self, parameter_id, **kwargs) | generate
| generate
| def generate_parameters(self, parameter_id, **kwargs):
'''generate
'''
return random_archi_generator(self.searchspace_json, self.random_state) | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"random_archi_generator",
"(",
"self",
".",
"searchspace_json",
",",
"self",
".",
"random_state",
")"
] | [
45,
4
] | [
48,
79
] | python | en | ['en', 'la', 'en'] | False |
RandomNASTuner.receive_trial_result | (self, parameter_id, parameters, value, **kwargs) | receive
| receive
| def receive_trial_result(self, parameter_id, parameters, value, **kwargs):
'''receive
'''
pass | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"pass"
] | [
50,
4
] | [
53,
12
] | python | en | ['en', 'sr', 'en'] | False |
_async_reproduce_state | (
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce a single state. | Reproduce a single state. | async def _async_reproduce_state(
hass: HomeAssistantType,
state: State,
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce a single state."""
cur_state = hass.states.get(state.entity_id)
if cur_state is None:
_LOGGER.warning("Unable to find entity %s", state.entity_id)
return
if not (state.state in VALID_STATES_TOGGLE or state.state in VALID_STATES_STATE):
_LOGGER.warning(
"Invalid state specified for %s: %s", state.entity_id, state.state
)
return
# Return if we are already at the right state.
if cur_state.state == state.state and cur_state.attributes.get(
ATTR_FAN_SPEED
) == state.attributes.get(ATTR_FAN_SPEED):
return
service_data = {ATTR_ENTITY_ID: state.entity_id}
if cur_state.state != state.state:
# Wrong state
if state.state == STATE_ON:
service = SERVICE_TURN_ON
elif state.state == STATE_OFF:
service = SERVICE_TURN_OFF
elif state.state == STATE_CLEANING:
service = SERVICE_START
elif state.state in [STATE_DOCKED, STATE_RETURNING]:
service = SERVICE_RETURN_TO_BASE
elif state.state == STATE_IDLE:
service = SERVICE_STOP
elif state.state == STATE_PAUSED:
service = SERVICE_PAUSE
await hass.services.async_call(
DOMAIN, service, service_data, context=context, blocking=True
)
if cur_state.attributes.get(ATTR_FAN_SPEED) != state.attributes.get(ATTR_FAN_SPEED):
# Wrong fan speed
service_data["fan_speed"] = state.attributes[ATTR_FAN_SPEED]
await hass.services.async_call(
DOMAIN, SERVICE_SET_FAN_SPEED, service_data, context=context, blocking=True
) | [
"async",
"def",
"_async_reproduce_state",
"(",
"hass",
":",
"HomeAssistantType",
",",
"state",
":",
"State",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"cur_state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"state",
".",
"entity_id",
")",
"if",
"cur_state",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unable to find entity %s\"",
",",
"state",
".",
"entity_id",
")",
"return",
"if",
"not",
"(",
"state",
".",
"state",
"in",
"VALID_STATES_TOGGLE",
"or",
"state",
".",
"state",
"in",
"VALID_STATES_STATE",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Invalid state specified for %s: %s\"",
",",
"state",
".",
"entity_id",
",",
"state",
".",
"state",
")",
"return",
"# Return if we are already at the right state.",
"if",
"cur_state",
".",
"state",
"==",
"state",
".",
"state",
"and",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_FAN_SPEED",
")",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_FAN_SPEED",
")",
":",
"return",
"service_data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"state",
".",
"entity_id",
"}",
"if",
"cur_state",
".",
"state",
"!=",
"state",
".",
"state",
":",
"# Wrong state",
"if",
"state",
".",
"state",
"==",
"STATE_ON",
":",
"service",
"=",
"SERVICE_TURN_ON",
"elif",
"state",
".",
"state",
"==",
"STATE_OFF",
":",
"service",
"=",
"SERVICE_TURN_OFF",
"elif",
"state",
".",
"state",
"==",
"STATE_CLEANING",
":",
"service",
"=",
"SERVICE_START",
"elif",
"state",
".",
"state",
"in",
"[",
"STATE_DOCKED",
",",
"STATE_RETURNING",
"]",
":",
"service",
"=",
"SERVICE_RETURN_TO_BASE",
"elif",
"state",
".",
"state",
"==",
"STATE_IDLE",
":",
"service",
"=",
"SERVICE_STOP",
"elif",
"state",
".",
"state",
"==",
"STATE_PAUSED",
":",
"service",
"=",
"SERVICE_PAUSE",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service",
",",
"service_data",
",",
"context",
"=",
"context",
",",
"blocking",
"=",
"True",
")",
"if",
"cur_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_FAN_SPEED",
")",
"!=",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_FAN_SPEED",
")",
":",
"# Wrong fan speed",
"service_data",
"[",
"\"fan_speed\"",
"]",
"=",
"state",
".",
"attributes",
"[",
"ATTR_FAN_SPEED",
"]",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SET_FAN_SPEED",
",",
"service_data",
",",
"context",
"=",
"context",
",",
"blocking",
"=",
"True",
")"
] | [
42,
0
] | [
94,
9
] | python | en | ['en', 'en', 'en'] | True |
async_reproduce_states | (
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) | Reproduce Vacuum states. | Reproduce Vacuum states. | async def async_reproduce_states(
hass: HomeAssistantType,
states: Iterable[State],
*,
context: Optional[Context] = None,
reproduce_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Reproduce Vacuum states."""
# Reproduce states in parallel.
await asyncio.gather(
*(
_async_reproduce_state(
hass, state, context=context, reproduce_options=reproduce_options
)
for state in states
)
) | [
"async",
"def",
"async_reproduce_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"states",
":",
"Iterable",
"[",
"State",
"]",
",",
"*",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
"=",
"None",
",",
"reproduce_options",
":",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
"=",
"None",
",",
")",
"->",
"None",
":",
"# Reproduce states in parallel.",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"_async_reproduce_state",
"(",
"hass",
",",
"state",
",",
"context",
"=",
"context",
",",
"reproduce_options",
"=",
"reproduce_options",
")",
"for",
"state",
"in",
"states",
")",
")"
] | [
97,
0
] | [
113,
5
] | python | de | ['de', 'la', 'en'] | False |
dimmer_fixture | () | Return a default light entity mock. | Return a default light entity mock. | def dimmer_fixture():
"""Return a default light entity mock."""
feature = mock_feature(
"lights",
blebox_uniapi.light.Light,
unique_id="BleBox-dimmerBox-1afe34e750b8-brightness",
full_name="dimmerBox-brightness",
device_class=None,
brightness=65,
is_on=True,
supports_color=False,
supports_white=False,
)
product = feature.product
type(product).name = PropertyMock(return_value="My dimmer")
type(product).model = PropertyMock(return_value="dimmerBox")
return (feature, "light.dimmerbox_brightness") | [
"def",
"dimmer_fixture",
"(",
")",
":",
"feature",
"=",
"mock_feature",
"(",
"\"lights\"",
",",
"blebox_uniapi",
".",
"light",
".",
"Light",
",",
"unique_id",
"=",
"\"BleBox-dimmerBox-1afe34e750b8-brightness\"",
",",
"full_name",
"=",
"\"dimmerBox-brightness\"",
",",
"device_class",
"=",
"None",
",",
"brightness",
"=",
"65",
",",
"is_on",
"=",
"True",
",",
"supports_color",
"=",
"False",
",",
"supports_white",
"=",
"False",
",",
")",
"product",
"=",
"feature",
".",
"product",
"type",
"(",
"product",
")",
".",
"name",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"My dimmer\"",
")",
"type",
"(",
"product",
")",
".",
"model",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"dimmerBox\"",
")",
"return",
"(",
"feature",
",",
"\"light.dimmerbox_brightness\"",
")"
] | [
32,
0
] | [
49,
50
] | python | en | ['en', 'da', 'en'] | True |
test_dimmer_init | (dimmer, hass, config) | Test cover default state. | Test cover default state. | async def test_dimmer_init(dimmer, hass, config):
"""Test cover default state."""
_, entity_id = dimmer
entry = await async_setup_entity(hass, config, entity_id)
assert entry.unique_id == "BleBox-dimmerBox-1afe34e750b8-brightness"
state = hass.states.get(entity_id)
assert state.name == "dimmerBox-brightness"
supported_features = state.attributes[ATTR_SUPPORTED_FEATURES]
assert supported_features & SUPPORT_BRIGHTNESS
assert state.attributes[ATTR_BRIGHTNESS] == 65
assert state.state == STATE_ON
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entry.device_id)
assert device.name == "My dimmer"
assert device.identifiers == {("blebox", "abcd0123ef5678")}
assert device.manufacturer == "BleBox"
assert device.model == "dimmerBox"
assert device.sw_version == "1.23" | [
"async",
"def",
"test_dimmer_init",
"(",
"dimmer",
",",
"hass",
",",
"config",
")",
":",
"_",
",",
"entity_id",
"=",
"dimmer",
"entry",
"=",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"assert",
"entry",
".",
"unique_id",
"==",
"\"BleBox-dimmerBox-1afe34e750b8-brightness\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"name",
"==",
"\"dimmerBox-brightness\"",
"supported_features",
"=",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"assert",
"supported_features",
"&",
"SUPPORT_BRIGHTNESS",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"65",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device",
"=",
"device_registry",
".",
"async_get",
"(",
"entry",
".",
"device_id",
")",
"assert",
"device",
".",
"name",
"==",
"\"My dimmer\"",
"assert",
"device",
".",
"identifiers",
"==",
"{",
"(",
"\"blebox\"",
",",
"\"abcd0123ef5678\"",
")",
"}",
"assert",
"device",
".",
"manufacturer",
"==",
"\"BleBox\"",
"assert",
"device",
".",
"model",
"==",
"\"dimmerBox\"",
"assert",
"device",
".",
"sw_version",
"==",
"\"1.23\""
] | [
52,
0
] | [
75,
38
] | python | en | ['da', 'en', 'en'] | True |
test_dimmer_update | (dimmer, hass, config) | Test light updating. | Test light updating. | async def test_dimmer_update(dimmer, hass, config):
"""Test light updating."""
feature_mock, entity_id = dimmer
def initial_update():
feature_mock.brightness = 53
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 53
assert state.state == STATE_ON | [
"async",
"def",
"test_dimmer_update",
"(",
"dimmer",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"dimmer",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"brightness",
"=",
"53",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"53",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
78,
0
] | [
91,
34
] | python | en | ['en', 'no', 'en'] | True |
test_dimmer_on | (dimmer, hass, config) | Test light on. | Test light on. | async def test_dimmer_on(dimmer, hass, config):
"""Test light on."""
feature_mock, entity_id = dimmer
def initial_update():
feature_mock.is_on = False
feature_mock.brightness = 0 # off
feature_mock.sensible_on_value = 254
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(brightness):
assert brightness == 254
feature_mock.brightness = 254 # on
feature_mock.is_on = True # on
feature_mock.async_on = AsyncMock(side_effect=turn_on)
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.attributes[ATTR_BRIGHTNESS] == 254 | [
"async",
"def",
"test_dimmer_on",
"(",
"dimmer",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"dimmer",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"brightness",
"=",
"0",
"# off",
"feature_mock",
".",
"sensible_on_value",
"=",
"254",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"brightness",
")",
":",
"assert",
"brightness",
"==",
"254",
"feature_mock",
".",
"brightness",
"=",
"254",
"# on",
"feature_mock",
".",
"is_on",
"=",
"True",
"# on",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"254"
] | [
94,
0
] | [
126,
51
] | python | en | ['en', 'et', 'en'] | True |
test_dimmer_on_with_brightness | (dimmer, hass, config) | Test light on with a brightness value. | Test light on with a brightness value. | async def test_dimmer_on_with_brightness(dimmer, hass, config):
"""Test light on with a brightness value."""
feature_mock, entity_id = dimmer
def initial_update():
feature_mock.is_on = False
feature_mock.brightness = 0 # off
feature_mock.sensible_on_value = 254
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(brightness):
assert brightness == 202
feature_mock.brightness = 202 # on
feature_mock.is_on = True # on
feature_mock.async_on = AsyncMock(side_effect=turn_on)
def apply(value, brightness):
assert value == 254
return brightness
feature_mock.apply_brightness = apply
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_BRIGHTNESS: 202},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 202
assert state.state == STATE_ON | [
"async",
"def",
"test_dimmer_on_with_brightness",
"(",
"dimmer",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"dimmer",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"brightness",
"=",
"0",
"# off",
"feature_mock",
".",
"sensible_on_value",
"=",
"254",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"brightness",
")",
":",
"assert",
"brightness",
"==",
"202",
"feature_mock",
".",
"brightness",
"=",
"202",
"# on",
"feature_mock",
".",
"is_on",
"=",
"True",
"# on",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"def",
"apply",
"(",
"value",
",",
"brightness",
")",
":",
"assert",
"value",
"==",
"254",
"return",
"brightness",
"feature_mock",
".",
"apply_brightness",
"=",
"apply",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
",",
"ATTR_BRIGHTNESS",
":",
"202",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"202",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
129,
0
] | [
167,
34
] | python | en | ['en', 'en', 'en'] | True |
test_dimmer_off | (dimmer, hass, config) | Test light off. | Test light off. | async def test_dimmer_off(dimmer, hass, config):
"""Test light off."""
feature_mock, entity_id = dimmer
def initial_update():
feature_mock.is_on = True
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
def turn_off():
feature_mock.is_on = False
feature_mock.brightness = 0 # off
feature_mock.async_off = AsyncMock(side_effect=turn_off)
await hass.services.async_call(
"light",
SERVICE_TURN_OFF,
{"entity_id": entity_id},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
assert ATTR_BRIGHTNESS not in state.attributes | [
"async",
"def",
"test_dimmer_off",
"(",
"dimmer",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"dimmer",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"def",
"turn_off",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"brightness",
"=",
"0",
"# off",
"feature_mock",
".",
"async_off",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_off",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_OFF",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"assert",
"ATTR_BRIGHTNESS",
"not",
"in",
"state",
".",
"attributes"
] | [
170,
0
] | [
199,
50
] | python | en | ['en', 'lb', 'en'] | True |
wlightboxs_fixture | () | Return a default light entity mock. | Return a default light entity mock. | def wlightboxs_fixture():
"""Return a default light entity mock."""
feature = mock_feature(
"lights",
blebox_uniapi.light.Light,
unique_id="BleBox-wLightBoxS-1afe34e750b8-color",
full_name="wLightBoxS-color",
device_class=None,
brightness=None,
is_on=None,
supports_color=False,
supports_white=False,
)
product = feature.product
type(product).name = PropertyMock(return_value="My wLightBoxS")
type(product).model = PropertyMock(return_value="wLightBoxS")
return (feature, "light.wlightboxs_color") | [
"def",
"wlightboxs_fixture",
"(",
")",
":",
"feature",
"=",
"mock_feature",
"(",
"\"lights\"",
",",
"blebox_uniapi",
".",
"light",
".",
"Light",
",",
"unique_id",
"=",
"\"BleBox-wLightBoxS-1afe34e750b8-color\"",
",",
"full_name",
"=",
"\"wLightBoxS-color\"",
",",
"device_class",
"=",
"None",
",",
"brightness",
"=",
"None",
",",
"is_on",
"=",
"None",
",",
"supports_color",
"=",
"False",
",",
"supports_white",
"=",
"False",
",",
")",
"product",
"=",
"feature",
".",
"product",
"type",
"(",
"product",
")",
".",
"name",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"My wLightBoxS\"",
")",
"type",
"(",
"product",
")",
".",
"model",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"wLightBoxS\"",
")",
"return",
"(",
"feature",
",",
"\"light.wlightboxs_color\"",
")"
] | [
203,
0
] | [
220,
46
] | python | en | ['en', 'da', 'en'] | True |
test_wlightbox_s_init | (wlightbox_s, hass, config) | Test cover default state. | Test cover default state. | async def test_wlightbox_s_init(wlightbox_s, hass, config):
"""Test cover default state."""
_, entity_id = wlightbox_s
entry = await async_setup_entity(hass, config, entity_id)
assert entry.unique_id == "BleBox-wLightBoxS-1afe34e750b8-color"
state = hass.states.get(entity_id)
assert state.name == "wLightBoxS-color"
supported_features = state.attributes[ATTR_SUPPORTED_FEATURES]
assert supported_features & SUPPORT_BRIGHTNESS
assert ATTR_BRIGHTNESS not in state.attributes
assert state.state == STATE_OFF
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entry.device_id)
assert device.name == "My wLightBoxS"
assert device.identifiers == {("blebox", "abcd0123ef5678")}
assert device.manufacturer == "BleBox"
assert device.model == "wLightBoxS"
assert device.sw_version == "1.23" | [
"async",
"def",
"test_wlightbox_s_init",
"(",
"wlightbox_s",
",",
"hass",
",",
"config",
")",
":",
"_",
",",
"entity_id",
"=",
"wlightbox_s",
"entry",
"=",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"assert",
"entry",
".",
"unique_id",
"==",
"\"BleBox-wLightBoxS-1afe34e750b8-color\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"name",
"==",
"\"wLightBoxS-color\"",
"supported_features",
"=",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"assert",
"supported_features",
"&",
"SUPPORT_BRIGHTNESS",
"assert",
"ATTR_BRIGHTNESS",
"not",
"in",
"state",
".",
"attributes",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device",
"=",
"device_registry",
".",
"async_get",
"(",
"entry",
".",
"device_id",
")",
"assert",
"device",
".",
"name",
"==",
"\"My wLightBoxS\"",
"assert",
"device",
".",
"identifiers",
"==",
"{",
"(",
"\"blebox\"",
",",
"\"abcd0123ef5678\"",
")",
"}",
"assert",
"device",
".",
"manufacturer",
"==",
"\"BleBox\"",
"assert",
"device",
".",
"model",
"==",
"\"wLightBoxS\"",
"assert",
"device",
".",
"sw_version",
"==",
"\"1.23\""
] | [
223,
0
] | [
246,
38
] | python | en | ['da', 'en', 'en'] | True |
test_wlightbox_s_update | (wlightbox_s, hass, config) | Test light updating. | Test light updating. | async def test_wlightbox_s_update(wlightbox_s, hass, config):
"""Test light updating."""
feature_mock, entity_id = wlightbox_s
def initial_update():
feature_mock.brightness = 0xAB
feature_mock.is_on = True
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.attributes[ATTR_BRIGHTNESS] == 0xAB | [
"async",
"def",
"test_wlightbox_s_update",
"(",
"wlightbox_s",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox_s",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"brightness",
"=",
"0xAB",
"feature_mock",
".",
"is_on",
"=",
"True",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"0xAB"
] | [
249,
0
] | [
264,
52
] | python | en | ['en', 'no', 'en'] | True |
test_wlightbox_s_on | (wlightbox_s, hass, config) | Test light on. | Test light on. | async def test_wlightbox_s_on(wlightbox_s, hass, config):
"""Test light on."""
feature_mock, entity_id = wlightbox_s
def initial_update():
feature_mock.is_on = False
feature_mock.sensible_on_value = 254
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(brightness):
assert brightness == 254
feature_mock.brightness = 254 # on
feature_mock.is_on = True # on
feature_mock.async_on = AsyncMock(side_effect=turn_on)
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_BRIGHTNESS] == 254
assert state.state == STATE_ON | [
"async",
"def",
"test_wlightbox_s_on",
"(",
"wlightbox_s",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox_s",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"sensible_on_value",
"=",
"254",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"brightness",
")",
":",
"assert",
"brightness",
"==",
"254",
"feature_mock",
".",
"brightness",
"=",
"254",
"# on",
"feature_mock",
".",
"is_on",
"=",
"True",
"# on",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"254",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
267,
0
] | [
298,
34
] | python | en | ['en', 'et', 'en'] | True |
wlightbox_fixture | () | Return a default light entity mock. | Return a default light entity mock. | def wlightbox_fixture():
"""Return a default light entity mock."""
feature = mock_feature(
"lights",
blebox_uniapi.light.Light,
unique_id="BleBox-wLightBox-1afe34e750b8-color",
full_name="wLightBox-color",
device_class=None,
is_on=None,
supports_color=True,
supports_white=True,
white_value=None,
rgbw_hex=None,
)
product = feature.product
type(product).name = PropertyMock(return_value="My wLightBox")
type(product).model = PropertyMock(return_value="wLightBox")
return (feature, "light.wlightbox_color") | [
"def",
"wlightbox_fixture",
"(",
")",
":",
"feature",
"=",
"mock_feature",
"(",
"\"lights\"",
",",
"blebox_uniapi",
".",
"light",
".",
"Light",
",",
"unique_id",
"=",
"\"BleBox-wLightBox-1afe34e750b8-color\"",
",",
"full_name",
"=",
"\"wLightBox-color\"",
",",
"device_class",
"=",
"None",
",",
"is_on",
"=",
"None",
",",
"supports_color",
"=",
"True",
",",
"supports_white",
"=",
"True",
",",
"white_value",
"=",
"None",
",",
"rgbw_hex",
"=",
"None",
",",
")",
"product",
"=",
"feature",
".",
"product",
"type",
"(",
"product",
")",
".",
"name",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"My wLightBox\"",
")",
"type",
"(",
"product",
")",
".",
"model",
"=",
"PropertyMock",
"(",
"return_value",
"=",
"\"wLightBox\"",
")",
"return",
"(",
"feature",
",",
"\"light.wlightbox_color\"",
")"
] | [
302,
0
] | [
320,
45
] | python | en | ['en', 'da', 'en'] | True |
test_wlightbox_init | (wlightbox, hass, config) | Test cover default state. | Test cover default state. | async def test_wlightbox_init(wlightbox, hass, config):
"""Test cover default state."""
_, entity_id = wlightbox
entry = await async_setup_entity(hass, config, entity_id)
assert entry.unique_id == "BleBox-wLightBox-1afe34e750b8-color"
state = hass.states.get(entity_id)
assert state.name == "wLightBox-color"
supported_features = state.attributes[ATTR_SUPPORTED_FEATURES]
assert supported_features & SUPPORT_WHITE_VALUE
assert supported_features & SUPPORT_COLOR
assert ATTR_WHITE_VALUE not in state.attributes
assert ATTR_HS_COLOR not in state.attributes
assert ATTR_BRIGHTNESS not in state.attributes
assert state.state == STATE_OFF
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entry.device_id)
assert device.name == "My wLightBox"
assert device.identifiers == {("blebox", "abcd0123ef5678")}
assert device.manufacturer == "BleBox"
assert device.model == "wLightBox"
assert device.sw_version == "1.23" | [
"async",
"def",
"test_wlightbox_init",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"_",
",",
"entity_id",
"=",
"wlightbox",
"entry",
"=",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"assert",
"entry",
".",
"unique_id",
"==",
"\"BleBox-wLightBox-1afe34e750b8-color\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"name",
"==",
"\"wLightBox-color\"",
"supported_features",
"=",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"assert",
"supported_features",
"&",
"SUPPORT_WHITE_VALUE",
"assert",
"supported_features",
"&",
"SUPPORT_COLOR",
"assert",
"ATTR_WHITE_VALUE",
"not",
"in",
"state",
".",
"attributes",
"assert",
"ATTR_HS_COLOR",
"not",
"in",
"state",
".",
"attributes",
"assert",
"ATTR_BRIGHTNESS",
"not",
"in",
"state",
".",
"attributes",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device",
"=",
"device_registry",
".",
"async_get",
"(",
"entry",
".",
"device_id",
")",
"assert",
"device",
".",
"name",
"==",
"\"My wLightBox\"",
"assert",
"device",
".",
"identifiers",
"==",
"{",
"(",
"\"blebox\"",
",",
"\"abcd0123ef5678\"",
")",
"}",
"assert",
"device",
".",
"manufacturer",
"==",
"\"BleBox\"",
"assert",
"device",
".",
"model",
"==",
"\"wLightBox\"",
"assert",
"device",
".",
"sw_version",
"==",
"\"1.23\""
] | [
323,
0
] | [
349,
38
] | python | en | ['da', 'en', 'en'] | True |
test_wlightbox_update | (wlightbox, hass, config) | Test light updating. | Test light updating. | async def test_wlightbox_update(wlightbox, hass, config):
"""Test light updating."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = True
feature_mock.rgbw_hex = "fa00203A"
feature_mock.white_value = 0x3A
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_HS_COLOR] == (352.32, 100.0)
assert state.attributes[ATTR_WHITE_VALUE] == 0x3A
assert state.state == STATE_ON | [
"async",
"def",
"test_wlightbox_update",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"feature_mock",
".",
"rgbw_hex",
"=",
"\"fa00203A\"",
"feature_mock",
".",
"white_value",
"=",
"0x3A",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"(",
"352.32",
",",
"100.0",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_WHITE_VALUE",
"]",
"==",
"0x3A",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
352,
0
] | [
368,
34
] | python | en | ['en', 'no', 'en'] | True |
test_wlightbox_on_via_just_whiteness | (wlightbox, hass, config) | Test light on. | Test light on. | async def test_wlightbox_on_via_just_whiteness(wlightbox, hass, config):
"""Test light on."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = False
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(value):
feature_mock.is_on = True
assert value == "f1e2d3c7"
feature_mock.white_value = 0xC7 # on
feature_mock.rgbw_hex = "f1e2d3c7"
feature_mock.async_on = AsyncMock(side_effect=turn_on)
def apply_white(value, white):
assert value == "f1e2d305"
assert white == 0xC7
return "f1e2d3c7"
feature_mock.apply_white = apply_white
feature_mock.sensible_on_value = "f1e2d305"
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_WHITE_VALUE: 0xC7},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.attributes[ATTR_WHITE_VALUE] == 0xC7
assert state.attributes[ATTR_HS_COLOR] == color.color_RGB_to_hs(0xF1, 0xE2, 0xD3) | [
"async",
"def",
"test_wlightbox_on_via_just_whiteness",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"value",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"assert",
"value",
"==",
"\"f1e2d3c7\"",
"feature_mock",
".",
"white_value",
"=",
"0xC7",
"# on",
"feature_mock",
".",
"rgbw_hex",
"=",
"\"f1e2d3c7\"",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"def",
"apply_white",
"(",
"value",
",",
"white",
")",
":",
"assert",
"value",
"==",
"\"f1e2d305\"",
"assert",
"white",
"==",
"0xC7",
"return",
"\"f1e2d3c7\"",
"feature_mock",
".",
"apply_white",
"=",
"apply_white",
"feature_mock",
".",
"sensible_on_value",
"=",
"\"f1e2d305\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
",",
"ATTR_WHITE_VALUE",
":",
"0xC7",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_WHITE_VALUE",
"]",
"==",
"0xC7",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"color",
".",
"color_RGB_to_hs",
"(",
"0xF1",
",",
"0xE2",
",",
"0xD3",
")"
] | [
371,
0
] | [
414,
85
] | python | en | ['en', 'et', 'en'] | True |
test_wlightbox_on_via_reset_whiteness | (wlightbox, hass, config) | Test light on. | Test light on. | async def test_wlightbox_on_via_reset_whiteness(wlightbox, hass, config):
"""Test light on."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = False
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(value):
feature_mock.is_on = True
feature_mock.white_value = 0x0
assert value == "f1e2d300"
feature_mock.rgbw_hex = "f1e2d300"
feature_mock.async_on = AsyncMock(side_effect=turn_on)
def apply_white(value, white):
assert value == "f1e2d305"
assert white == 0x0
return "f1e2d300"
feature_mock.apply_white = apply_white
feature_mock.sensible_on_value = "f1e2d305"
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_WHITE_VALUE: 0x0},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.state == STATE_ON
assert state.attributes[ATTR_WHITE_VALUE] == 0x0
assert state.attributes[ATTR_HS_COLOR] == color.color_RGB_to_hs(0xF1, 0xE2, 0xD3) | [
"async",
"def",
"test_wlightbox_on_via_reset_whiteness",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"value",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"feature_mock",
".",
"white_value",
"=",
"0x0",
"assert",
"value",
"==",
"\"f1e2d300\"",
"feature_mock",
".",
"rgbw_hex",
"=",
"\"f1e2d300\"",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"def",
"apply_white",
"(",
"value",
",",
"white",
")",
":",
"assert",
"value",
"==",
"\"f1e2d305\"",
"assert",
"white",
"==",
"0x0",
"return",
"\"f1e2d300\"",
"feature_mock",
".",
"apply_white",
"=",
"apply_white",
"feature_mock",
".",
"sensible_on_value",
"=",
"\"f1e2d305\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
",",
"ATTR_WHITE_VALUE",
":",
"0x0",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_WHITE_VALUE",
"]",
"==",
"0x0",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"color",
".",
"color_RGB_to_hs",
"(",
"0xF1",
",",
"0xE2",
",",
"0xD3",
")"
] | [
417,
0
] | [
459,
85
] | python | en | ['en', 'et', 'en'] | True |
test_wlightbox_on_via_just_hsl_color | (wlightbox, hass, config) | Test light on. | Test light on. | async def test_wlightbox_on_via_just_hsl_color(wlightbox, hass, config):
"""Test light on."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = False
feature_mock.rgbw_hex = "00000000"
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
hs_color = color.color_RGB_to_hs(0xFF, 0xA1, 0xB2)
def turn_on(value):
feature_mock.is_on = True
assert value == "ffa1b2e4"
feature_mock.white_value = 0xE4
feature_mock.rgbw_hex = value
feature_mock.async_on = AsyncMock(side_effect=turn_on)
def apply_color(value, color_value):
assert value == "c1a2e3e4"
assert color_value == "ffa0b1"
return "ffa1b2e4"
feature_mock.apply_color = apply_color
feature_mock.sensible_on_value = "c1a2e3e4"
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id, ATTR_HS_COLOR: hs_color},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_HS_COLOR] == hs_color
assert state.attributes[ATTR_WHITE_VALUE] == 0xE4
assert state.state == STATE_ON | [
"async",
"def",
"test_wlightbox_on_via_just_hsl_color",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"rgbw_hex",
"=",
"\"00000000\"",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"hs_color",
"=",
"color",
".",
"color_RGB_to_hs",
"(",
"0xFF",
",",
"0xA1",
",",
"0xB2",
")",
"def",
"turn_on",
"(",
"value",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"assert",
"value",
"==",
"\"ffa1b2e4\"",
"feature_mock",
".",
"white_value",
"=",
"0xE4",
"feature_mock",
".",
"rgbw_hex",
"=",
"value",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"def",
"apply_color",
"(",
"value",
",",
"color_value",
")",
":",
"assert",
"value",
"==",
"\"c1a2e3e4\"",
"assert",
"color_value",
"==",
"\"ffa0b1\"",
"return",
"\"ffa1b2e4\"",
"feature_mock",
".",
"apply_color",
"=",
"apply_color",
"feature_mock",
".",
"sensible_on_value",
"=",
"\"c1a2e3e4\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
",",
"ATTR_HS_COLOR",
":",
"hs_color",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"hs_color",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_WHITE_VALUE",
"]",
"==",
"0xE4",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
462,
0
] | [
506,
34
] | python | en | ['en', 'et', 'en'] | True |
test_wlightbox_on_to_last_color | (wlightbox, hass, config) | Test light on. | Test light on. | async def test_wlightbox_on_to_last_color(wlightbox, hass, config):
"""Test light on."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = False
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_OFF
def turn_on(value):
feature_mock.is_on = True
assert value == "f1e2d3e4"
feature_mock.white_value = 0xE4
feature_mock.rgbw_hex = value
feature_mock.async_on = AsyncMock(side_effect=turn_on)
feature_mock.sensible_on_value = "f1e2d3e4"
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id},
blocking=True,
)
state = hass.states.get(entity_id)
assert state.attributes[ATTR_WHITE_VALUE] == 0xE4
assert state.attributes[ATTR_HS_COLOR] == color.color_RGB_to_hs(0xF1, 0xE2, 0xD3)
assert state.state == STATE_ON | [
"async",
"def",
"test_wlightbox_on_to_last_color",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"def",
"turn_on",
"(",
"value",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"assert",
"value",
"==",
"\"f1e2d3e4\"",
"feature_mock",
".",
"white_value",
"=",
"0xE4",
"feature_mock",
".",
"rgbw_hex",
"=",
"value",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_on",
")",
"feature_mock",
".",
"sensible_on_value",
"=",
"\"f1e2d3e4\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_WHITE_VALUE",
"]",
"==",
"0xE4",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"color",
".",
"color_RGB_to_hs",
"(",
"0xF1",
",",
"0xE2",
",",
"0xD3",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
509,
0
] | [
543,
34
] | python | en | ['en', 'et', 'en'] | True |
test_wlightbox_off | (wlightbox, hass, config) | Test light off. | Test light off. | async def test_wlightbox_off(wlightbox, hass, config):
"""Test light off."""
feature_mock, entity_id = wlightbox
def initial_update():
feature_mock.is_on = True
feature_mock.async_update = AsyncMock(side_effect=initial_update)
await async_setup_entity(hass, config, entity_id)
feature_mock.async_update = AsyncMock()
state = hass.states.get(entity_id)
assert state.state == STATE_ON
def turn_off():
feature_mock.is_on = False
feature_mock.white_value = 0x0
feature_mock.rgbw_hex = "00000000"
feature_mock.async_off = AsyncMock(side_effect=turn_off)
await hass.services.async_call(
"light",
SERVICE_TURN_OFF,
{"entity_id": entity_id},
blocking=True,
)
state = hass.states.get(entity_id)
assert ATTR_WHITE_VALUE not in state.attributes
assert ATTR_HS_COLOR not in state.attributes
assert state.state == STATE_OFF | [
"async",
"def",
"test_wlightbox_off",
"(",
"wlightbox",
",",
"hass",
",",
"config",
")",
":",
"feature_mock",
",",
"entity_id",
"=",
"wlightbox",
"def",
"initial_update",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"True",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"initial_update",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON",
"def",
"turn_off",
"(",
")",
":",
"feature_mock",
".",
"is_on",
"=",
"False",
"feature_mock",
".",
"white_value",
"=",
"0x0",
"feature_mock",
".",
"rgbw_hex",
"=",
"\"00000000\"",
"feature_mock",
".",
"async_off",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"turn_off",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_OFF",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
"assert",
"ATTR_WHITE_VALUE",
"not",
"in",
"state",
".",
"attributes",
"assert",
"ATTR_HS_COLOR",
"not",
"in",
"state",
".",
"attributes",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF"
] | [
546,
0
] | [
578,
35
] | python | en | ['en', 'lb', 'en'] | True |
test_update_failure | (feature, hass, config, caplog) | Test that update failures are logged. | Test that update failures are logged. | async def test_update_failure(feature, hass, config, caplog):
"""Test that update failures are logged."""
caplog.set_level(logging.ERROR)
feature_mock, entity_id = feature
feature_mock.async_update = AsyncMock(side_effect=blebox_uniapi.error.ClientError)
await async_setup_entity(hass, config, entity_id)
assert f"Updating '{feature_mock.full_name}' failed: " in caplog.text | [
"async",
"def",
"test_update_failure",
"(",
"feature",
",",
"hass",
",",
"config",
",",
"caplog",
")",
":",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"ERROR",
")",
"feature_mock",
",",
"entity_id",
"=",
"feature",
"feature_mock",
".",
"async_update",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"blebox_uniapi",
".",
"error",
".",
"ClientError",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"assert",
"f\"Updating '{feature_mock.full_name}' failed: \"",
"in",
"caplog",
".",
"text"
] | [
582,
0
] | [
591,
73
] | python | en | ['en', 'en', 'en'] | True |
test_turn_on_failure | (feature, hass, config, caplog) | Test that turn_on failures are logged. | Test that turn_on failures are logged. | async def test_turn_on_failure(feature, hass, config, caplog):
"""Test that turn_on failures are logged."""
caplog.set_level(logging.ERROR)
feature_mock, entity_id = feature
feature_mock.async_on = AsyncMock(side_effect=blebox_uniapi.error.BadOnValueError)
await async_setup_entity(hass, config, entity_id)
feature_mock.sensible_on_value = 123
await hass.services.async_call(
"light",
SERVICE_TURN_ON,
{"entity_id": entity_id},
blocking=True,
)
assert (
f"Turning on '{feature_mock.full_name}' failed: Bad value 123 ()" in caplog.text
) | [
"async",
"def",
"test_turn_on_failure",
"(",
"feature",
",",
"hass",
",",
"config",
",",
"caplog",
")",
":",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"ERROR",
")",
"feature_mock",
",",
"entity_id",
"=",
"feature",
"feature_mock",
".",
"async_on",
"=",
"AsyncMock",
"(",
"side_effect",
"=",
"blebox_uniapi",
".",
"error",
".",
"BadOnValueError",
")",
"await",
"async_setup_entity",
"(",
"hass",
",",
"config",
",",
"entity_id",
")",
"feature_mock",
".",
"sensible_on_value",
"=",
"123",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"(",
"f\"Turning on '{feature_mock.full_name}' failed: Bad value 123 ()\"",
"in",
"caplog",
".",
"text",
")"
] | [
595,
0
] | [
614,
5
] | python | en | ['en', 'en', 'en'] | True |
cls | () | Patch debounce decorator during import of type_covers. | Patch debounce decorator during import of type_covers. | def cls():
"""Patch debounce decorator during import of type_covers."""
patcher = patch_debounce()
patcher.start()
_import = __import__(
"homeassistant.components.homekit.type_covers",
fromlist=["GarageDoorOpener", "WindowCovering", "WindowCoveringBasic"],
)
patcher_tuple = namedtuple(
"Cls", ["window", "windowcovering", "windowcovering_basic", "garage"]
)
yield patcher_tuple(
window=_import.Window,
windowcovering=_import.WindowCovering,
windowcovering_basic=_import.WindowCoveringBasic,
garage=_import.GarageDoorOpener,
)
patcher.stop() | [
"def",
"cls",
"(",
")",
":",
"patcher",
"=",
"patch_debounce",
"(",
")",
"patcher",
".",
"start",
"(",
")",
"_import",
"=",
"__import__",
"(",
"\"homeassistant.components.homekit.type_covers\"",
",",
"fromlist",
"=",
"[",
"\"GarageDoorOpener\"",
",",
"\"WindowCovering\"",
",",
"\"WindowCoveringBasic\"",
"]",
",",
")",
"patcher_tuple",
"=",
"namedtuple",
"(",
"\"Cls\"",
",",
"[",
"\"window\"",
",",
"\"windowcovering\"",
",",
"\"windowcovering_basic\"",
",",
"\"garage\"",
"]",
")",
"yield",
"patcher_tuple",
"(",
"window",
"=",
"_import",
".",
"Window",
",",
"windowcovering",
"=",
"_import",
".",
"WindowCovering",
",",
"windowcovering_basic",
"=",
"_import",
".",
"WindowCoveringBasic",
",",
"garage",
"=",
"_import",
".",
"GarageDoorOpener",
",",
")",
"patcher",
".",
"stop",
"(",
")"
] | [
46,
0
] | [
63,
18
] | python | en | ['en', 'en', 'en'] | True |
test_garage_door_open_close | (hass, hk_driver, cls, events) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_garage_door_open_close(hass, hk_driver, cls, events):
"""Test if accessory and HA are updated accordingly."""
entity_id = "cover.garage_door"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = cls.garage(hass, hk_driver, "Garage Door", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 4 # GarageDoorOpener
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
hass.states.async_set(entity_id, STATE_CLOSED, {ATTR_OBSTRUCTION_DETECTED: False})
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_CLOSED
assert acc.char_target_state.value == HK_DOOR_CLOSED
assert acc.char_obstruction_detected.value is False
hass.states.async_set(entity_id, STATE_OPEN, {ATTR_OBSTRUCTION_DETECTED: True})
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
assert acc.char_obstruction_detected.value is True
hass.states.async_set(
entity_id, STATE_UNAVAILABLE, {ATTR_OBSTRUCTION_DETECTED: False}
)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
assert acc.char_obstruction_detected.value is False
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
# Set from HomeKit
call_close_cover = async_mock_service(hass, DOMAIN, "close_cover")
call_open_cover = async_mock_service(hass, DOMAIN, "open_cover")
await hass.async_add_executor_job(acc.char_target_state.client_update_value, 1)
await hass.async_block_till_done()
assert call_close_cover
assert call_close_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_state.value == HK_DOOR_CLOSING
assert acc.char_target_state.value == HK_DOOR_CLOSED
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] is None
hass.states.async_set(entity_id, STATE_CLOSED)
await hass.async_block_till_done()
await hass.async_add_executor_job(acc.char_target_state.client_update_value, 1)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_CLOSED
assert acc.char_target_state.value == HK_DOOR_CLOSED
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] is None
await hass.async_add_executor_job(acc.char_target_state.client_update_value, 0)
await hass.async_block_till_done()
assert call_open_cover
assert call_open_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_state.value == HK_DOOR_OPENING
assert acc.char_target_state.value == HK_DOOR_OPEN
assert len(events) == 3
assert events[-1].data[ATTR_VALUE] is None
hass.states.async_set(entity_id, STATE_OPEN)
await hass.async_block_till_done()
await hass.async_add_executor_job(acc.char_target_state.client_update_value, 0)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
assert len(events) == 4
assert events[-1].data[ATTR_VALUE] is None | [
"async",
"def",
"test_garage_door_open_close",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.garage_door\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"None",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"garage",
"(",
"hass",
",",
"hk_driver",
",",
"\"Garage Door\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"4",
"# GarageDoorOpener",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSED",
",",
"{",
"ATTR_OBSTRUCTION_DETECTED",
":",
"False",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"False",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPEN",
",",
"{",
"ATTR_OBSTRUCTION_DETECTED",
":",
"True",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"True",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNAVAILABLE",
",",
"{",
"ATTR_OBSTRUCTION_DETECTED",
":",
"False",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"False",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"# Set from HomeKit",
"call_close_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"close_cover\"",
")",
"call_open_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"open_cover\"",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_state",
".",
"client_update_value",
",",
"1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_close_cover",
"assert",
"call_close_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_CLOSING",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSED",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_state",
".",
"client_update_value",
",",
"1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_state",
".",
"client_update_value",
",",
"0",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_open_cover",
"assert",
"call_open_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPENING",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"len",
"(",
"events",
")",
"==",
"3",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPEN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_state",
".",
"client_update_value",
",",
"0",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"len",
"(",
"events",
")",
"==",
"4",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None"
] | [
66,
0
] | [
147,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_set_cover_position | (hass, hk_driver, cls, events) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_windowcovering_set_cover_position(hass, hk_driver, cls, events):
"""Test if accessory and HA are updated accordingly."""
entity_id = "cover.window"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = cls.windowcovering(hass, hk_driver, "Cover", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 14 # WindowCovering
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_CURRENT_POSITION: None})
await hass.async_block_till_done()
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
hass.states.async_set(entity_id, STATE_OPENING, {ATTR_CURRENT_POSITION: 60})
await hass.async_block_till_done()
assert acc.char_current_position.value == 60
assert acc.char_target_position.value == 60
assert acc.char_position_state.value == 1
hass.states.async_set(entity_id, STATE_OPENING, {ATTR_CURRENT_POSITION: 70.0})
await hass.async_block_till_done()
assert acc.char_current_position.value == 70
assert acc.char_target_position.value == 70
assert acc.char_position_state.value == 1
hass.states.async_set(entity_id, STATE_CLOSING, {ATTR_CURRENT_POSITION: 50})
await hass.async_block_till_done()
assert acc.char_current_position.value == 50
assert acc.char_target_position.value == 50
assert acc.char_position_state.value == 0
hass.states.async_set(entity_id, STATE_OPEN, {ATTR_CURRENT_POSITION: 50})
await hass.async_block_till_done()
assert acc.char_current_position.value == 50
assert acc.char_target_position.value == 50
assert acc.char_position_state.value == 2
# Set from HomeKit
call_set_cover_position = async_mock_service(hass, DOMAIN, "set_cover_position")
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 25)
await hass.async_block_till_done()
assert call_set_cover_position[0]
assert call_set_cover_position[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_cover_position[0].data[ATTR_POSITION] == 25
assert acc.char_current_position.value == 50
assert acc.char_target_position.value == 25
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == 25
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 75)
await hass.async_block_till_done()
assert call_set_cover_position[1]
assert call_set_cover_position[1].data[ATTR_ENTITY_ID] == entity_id
assert call_set_cover_position[1].data[ATTR_POSITION] == 75
assert acc.char_current_position.value == 50
assert acc.char_target_position.value == 75
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] == 75 | [
"async",
"def",
"test_windowcovering_set_cover_position",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"None",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"windowcovering",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"14",
"# WindowCovering",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_CURRENT_POSITION",
":",
"None",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPENING",
",",
"{",
"ATTR_CURRENT_POSITION",
":",
"60",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"60",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"60",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPENING",
",",
"{",
"ATTR_CURRENT_POSITION",
":",
"70.0",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"70",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"70",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSING",
",",
"{",
"ATTR_CURRENT_POSITION",
":",
"50",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPEN",
",",
"{",
"ATTR_CURRENT_POSITION",
":",
"50",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"# Set from HomeKit",
"call_set_cover_position",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"set_cover_position\"",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"25",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_set_cover_position",
"[",
"0",
"]",
"assert",
"call_set_cover_position",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_cover_position",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_POSITION",
"]",
"==",
"25",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"25",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"25",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"75",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_set_cover_position",
"[",
"1",
"]",
"assert",
"call_set_cover_position",
"[",
"1",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_cover_position",
"[",
"1",
"]",
".",
"data",
"[",
"ATTR_POSITION",
"]",
"==",
"75",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"75",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"75"
] | [
150,
0
] | [
217,
44
] | python | en | ['en', 'en', 'en'] | True |
test_window_instantiate | (hass, hk_driver, cls, events) | Test if Window accessory is instantiated correctly. | Test if Window accessory is instantiated correctly. | async def test_window_instantiate(hass, hk_driver, cls, events):
"""Test if Window accessory is instantiated correctly."""
entity_id = "cover.window"
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = cls.window(hass, hk_driver, "Window", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 13 # Window
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0 | [
"async",
"def",
"test_window_instantiate",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"None",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"window",
"(",
"hass",
",",
"hk_driver",
",",
"\"Window\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"13",
"# Window",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0"
] | [
220,
0
] | [
234,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_cover_set_tilt | (hass, hk_driver, cls, events) | Test if accessory and HA update slat tilt accordingly. | Test if accessory and HA update slat tilt accordingly. | async def test_windowcovering_cover_set_tilt(hass, hk_driver, cls, events):
"""Test if accessory and HA update slat tilt accordingly."""
entity_id = "cover.window"
hass.states.async_set(
entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: SUPPORT_SET_TILT_POSITION}
)
await hass.async_block_till_done()
acc = cls.windowcovering(hass, hk_driver, "Cover", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 14 # CATEGORY_WINDOW_COVERING
assert acc.char_current_tilt.value == 0
assert acc.char_target_tilt.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_CURRENT_TILT_POSITION: None})
await hass.async_block_till_done()
assert acc.char_current_tilt.value == 0
assert acc.char_target_tilt.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_CURRENT_TILT_POSITION: 100})
await hass.async_block_till_done()
assert acc.char_current_tilt.value == 90
assert acc.char_target_tilt.value == 90
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_CURRENT_TILT_POSITION: 50})
await hass.async_block_till_done()
assert acc.char_current_tilt.value == 0
assert acc.char_target_tilt.value == 0
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_CURRENT_TILT_POSITION: 0})
await hass.async_block_till_done()
assert acc.char_current_tilt.value == -90
assert acc.char_target_tilt.value == -90
# set from HomeKit
call_set_tilt_position = async_mock_service(
hass, DOMAIN, SERVICE_SET_COVER_TILT_POSITION
)
# HomeKit sets tilts between -90 and 90 (degrees), whereas
# Homeassistant expects a % between 0 and 100. Keep that in mind
# when comparing
await hass.async_add_executor_job(acc.char_target_tilt.client_update_value, 90)
await hass.async_block_till_done()
assert call_set_tilt_position[0]
assert call_set_tilt_position[0].data[ATTR_ENTITY_ID] == entity_id
assert call_set_tilt_position[0].data[ATTR_TILT_POSITION] == 100
assert acc.char_current_tilt.value == -90
assert acc.char_target_tilt.value == 90
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] == 100
await hass.async_add_executor_job(acc.char_target_tilt.client_update_value, 45)
await hass.async_block_till_done()
assert call_set_tilt_position[1]
assert call_set_tilt_position[1].data[ATTR_ENTITY_ID] == entity_id
assert call_set_tilt_position[1].data[ATTR_TILT_POSITION] == 75
assert acc.char_current_tilt.value == -90
assert acc.char_target_tilt.value == 45
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] == 75 | [
"async",
"def",
"test_windowcovering_cover_set_tilt",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"SUPPORT_SET_TILT_POSITION",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"windowcovering",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"14",
"# CATEGORY_WINDOW_COVERING",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_CURRENT_TILT_POSITION",
":",
"None",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_CURRENT_TILT_POSITION",
":",
"100",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"90",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"90",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_CURRENT_TILT_POSITION",
":",
"50",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_CURRENT_TILT_POSITION",
":",
"0",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"-",
"90",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"-",
"90",
"# set from HomeKit",
"call_set_tilt_position",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"SERVICE_SET_COVER_TILT_POSITION",
")",
"# HomeKit sets tilts between -90 and 90 (degrees), whereas",
"# Homeassistant expects a % between 0 and 100. Keep that in mind",
"# when comparing",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_tilt",
".",
"client_update_value",
",",
"90",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_set_tilt_position",
"[",
"0",
"]",
"assert",
"call_set_tilt_position",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_tilt_position",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_TILT_POSITION",
"]",
"==",
"100",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"-",
"90",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"90",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"100",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_tilt",
".",
"client_update_value",
",",
"45",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_set_tilt_position",
"[",
"1",
"]",
"assert",
"call_set_tilt_position",
"[",
"1",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"call_set_tilt_position",
"[",
"1",
"]",
".",
"data",
"[",
"ATTR_TILT_POSITION",
"]",
"==",
"75",
"assert",
"acc",
".",
"char_current_tilt",
".",
"value",
"==",
"-",
"90",
"assert",
"acc",
".",
"char_target_tilt",
".",
"value",
"==",
"45",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"==",
"75"
] | [
237,
0
] | [
301,
44
] | python | en | ['en', 'bg', 'en'] | True |
test_windowcovering_open_close | (hass, hk_driver, cls, events) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_windowcovering_open_close(hass, hk_driver, cls, events):
"""Test if accessory and HA are updated accordingly."""
entity_id = "cover.window"
hass.states.async_set(entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: 0})
acc = cls.windowcovering_basic(hass, hk_driver, "Cover", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 14 # WindowCovering
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
hass.states.async_set(entity_id, STATE_UNKNOWN)
await hass.async_block_till_done()
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
hass.states.async_set(entity_id, STATE_OPENING)
await hass.async_block_till_done()
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 1
hass.states.async_set(entity_id, STATE_OPEN)
await hass.async_block_till_done()
assert acc.char_current_position.value == 100
assert acc.char_target_position.value == 100
assert acc.char_position_state.value == 2
hass.states.async_set(entity_id, STATE_CLOSING)
await hass.async_block_till_done()
assert acc.char_current_position.value == 100
assert acc.char_target_position.value == 100
assert acc.char_position_state.value == 0
hass.states.async_set(entity_id, STATE_CLOSED)
await hass.async_block_till_done()
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
# Set from HomeKit
call_close_cover = async_mock_service(hass, DOMAIN, "close_cover")
call_open_cover = async_mock_service(hass, DOMAIN, "open_cover")
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 25)
await hass.async_block_till_done()
assert call_close_cover
assert call_close_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] is None
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 90)
await hass.async_block_till_done()
assert call_open_cover[0]
assert call_open_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 100
assert acc.char_target_position.value == 100
assert acc.char_position_state.value == 2
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] is None
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 55)
await hass.async_block_till_done()
assert call_open_cover[1]
assert call_open_cover[1].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 100
assert acc.char_target_position.value == 100
assert acc.char_position_state.value == 2
assert len(events) == 3
assert events[-1].data[ATTR_VALUE] is None | [
"async",
"def",
"test_windowcovering_open_close",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"0",
"}",
")",
"acc",
"=",
"cls",
".",
"windowcovering_basic",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"14",
"# WindowCovering",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPENING",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPEN",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSING",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSED",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"# Set from HomeKit",
"call_close_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"close_cover\"",
")",
"call_open_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"open_cover\"",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"25",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_close_cover",
"assert",
"call_close_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"90",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_open_cover",
"[",
"0",
"]",
"assert",
"call_open_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"55",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_open_cover",
"[",
"1",
"]",
"assert",
"call_open_cover",
"[",
"1",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"3",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None"
] | [
304,
0
] | [
382,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_open_close_stop | (hass, hk_driver, cls, events) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_windowcovering_open_close_stop(hass, hk_driver, cls, events):
"""Test if accessory and HA are updated accordingly."""
entity_id = "cover.window"
hass.states.async_set(
entity_id, STATE_UNKNOWN, {ATTR_SUPPORTED_FEATURES: SUPPORT_STOP}
)
acc = cls.windowcovering_basic(hass, hk_driver, "Cover", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
# Set from HomeKit
call_close_cover = async_mock_service(hass, DOMAIN, "close_cover")
call_open_cover = async_mock_service(hass, DOMAIN, "open_cover")
call_stop_cover = async_mock_service(hass, DOMAIN, "stop_cover")
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 25)
await hass.async_block_till_done()
assert call_close_cover
assert call_close_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 0
assert acc.char_target_position.value == 0
assert acc.char_position_state.value == 2
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] is None
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 90)
await hass.async_block_till_done()
assert call_open_cover
assert call_open_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 100
assert acc.char_target_position.value == 100
assert acc.char_position_state.value == 2
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] is None
await hass.async_add_executor_job(acc.char_target_position.client_update_value, 55)
await hass.async_block_till_done()
assert call_stop_cover
assert call_stop_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_position.value == 50
assert acc.char_target_position.value == 50
assert acc.char_position_state.value == 2
assert len(events) == 3
assert events[-1].data[ATTR_VALUE] is None | [
"async",
"def",
"test_windowcovering_open_close_stop",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"SUPPORT_STOP",
"}",
")",
"acc",
"=",
"cls",
".",
"windowcovering_basic",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Set from HomeKit",
"call_close_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"close_cover\"",
")",
"call_open_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"open_cover\"",
")",
"call_stop_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"stop_cover\"",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"25",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_close_cover",
"assert",
"call_close_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"0",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"90",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_open_cover",
"assert",
"call_open_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"100",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"2",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_target_position",
".",
"client_update_value",
",",
"55",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_stop_cover",
"assert",
"call_stop_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_current_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_target_position",
".",
"value",
"==",
"50",
"assert",
"acc",
".",
"char_position_state",
".",
"value",
"==",
"2",
"assert",
"len",
"(",
"events",
")",
"==",
"3",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None"
] | [
385,
0
] | [
429,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_open_close_with_position_and_stop | (
hass, hk_driver, cls, events
) | Test if accessory and HA are updated accordingly. | Test if accessory and HA are updated accordingly. | async def test_windowcovering_open_close_with_position_and_stop(
hass, hk_driver, cls, events
):
"""Test if accessory and HA are updated accordingly."""
entity_id = "cover.stop_window"
hass.states.async_set(
entity_id,
STATE_UNKNOWN,
{ATTR_SUPPORTED_FEATURES: SUPPORT_STOP | SUPPORT_SET_POSITION},
)
acc = cls.windowcovering(hass, hk_driver, "Cover", entity_id, 2, None)
await acc.run_handler()
await hass.async_block_till_done()
# Set from HomeKit
call_stop_cover = async_mock_service(hass, DOMAIN, "stop_cover")
await hass.async_add_executor_job(acc.char_hold_position.client_update_value, 0)
await hass.async_block_till_done()
assert not call_stop_cover
await hass.async_add_executor_job(acc.char_hold_position.client_update_value, 1)
await hass.async_block_till_done()
assert call_stop_cover
assert call_stop_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_hold_position.value == 1
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] is None | [
"async",
"def",
"test_windowcovering_open_close_with_position_and_stop",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"entity_id",
"=",
"\"cover.stop_window\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_UNKNOWN",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"SUPPORT_STOP",
"|",
"SUPPORT_SET_POSITION",
"}",
",",
")",
"acc",
"=",
"cls",
".",
"windowcovering",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"entity_id",
",",
"2",
",",
"None",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Set from HomeKit",
"call_stop_cover",
"=",
"async_mock_service",
"(",
"hass",
",",
"DOMAIN",
",",
"\"stop_cover\"",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_hold_position",
".",
"client_update_value",
",",
"0",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"not",
"call_stop_cover",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"acc",
".",
"char_hold_position",
".",
"client_update_value",
",",
"1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"call_stop_cover",
"assert",
"call_stop_cover",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"entity_id",
"assert",
"acc",
".",
"char_hold_position",
".",
"value",
"==",
"1",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"-",
"1",
"]",
".",
"data",
"[",
"ATTR_VALUE",
"]",
"is",
"None"
] | [
432,
0
] | [
460,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_basic_restore | (hass, hk_driver, cls, events) | Test setting up an entity from state in the event registry. | Test setting up an entity from state in the event registry. | async def test_windowcovering_basic_restore(hass, hk_driver, cls, events):
"""Test setting up an entity from state in the event registry."""
hass.state = CoreState.not_running
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
"cover",
"generic",
"1234",
suggested_object_id="simple",
)
registry.async_get_or_create(
"cover",
"generic",
"9012",
suggested_object_id="all_info_set",
capabilities={},
supported_features=SUPPORT_STOP,
device_class="mock-device-class",
)
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
await hass.async_block_till_done()
acc = cls.windowcovering_basic(hass, hk_driver, "Cover", "cover.simple", 2, None)
assert acc.category == 14
assert acc.char_current_position is not None
assert acc.char_target_position is not None
assert acc.char_position_state is not None
acc = cls.windowcovering_basic(
hass, hk_driver, "Cover", "cover.all_info_set", 2, None
)
assert acc.category == 14
assert acc.char_current_position is not None
assert acc.char_target_position is not None
assert acc.char_position_state is not None | [
"async",
"def",
"test_windowcovering_basic_restore",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"hass",
".",
"state",
"=",
"CoreState",
".",
"not_running",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"registry",
".",
"async_get_or_create",
"(",
"\"cover\"",
",",
"\"generic\"",
",",
"\"1234\"",
",",
"suggested_object_id",
"=",
"\"simple\"",
",",
")",
"registry",
".",
"async_get_or_create",
"(",
"\"cover\"",
",",
"\"generic\"",
",",
"\"9012\"",
",",
"suggested_object_id",
"=",
"\"all_info_set\"",
",",
"capabilities",
"=",
"{",
"}",
",",
"supported_features",
"=",
"SUPPORT_STOP",
",",
"device_class",
"=",
"\"mock-device-class\"",
",",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_HOMEASSISTANT_START",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"windowcovering_basic",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"\"cover.simple\"",
",",
"2",
",",
"None",
")",
"assert",
"acc",
".",
"category",
"==",
"14",
"assert",
"acc",
".",
"char_current_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_target_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_position_state",
"is",
"not",
"None",
"acc",
"=",
"cls",
".",
"windowcovering_basic",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"\"cover.all_info_set\"",
",",
"2",
",",
"None",
")",
"assert",
"acc",
".",
"category",
"==",
"14",
"assert",
"acc",
".",
"char_current_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_target_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_position_state",
"is",
"not",
"None"
] | [
463,
0
] | [
500,
46
] | python | en | ['en', 'en', 'en'] | True |
test_windowcovering_restore | (hass, hk_driver, cls, events) | Test setting up an entity from state in the event registry. | Test setting up an entity from state in the event registry. | async def test_windowcovering_restore(hass, hk_driver, cls, events):
"""Test setting up an entity from state in the event registry."""
hass.state = CoreState.not_running
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
"cover",
"generic",
"1234",
suggested_object_id="simple",
)
registry.async_get_or_create(
"cover",
"generic",
"9012",
suggested_object_id="all_info_set",
capabilities={},
supported_features=SUPPORT_STOP,
device_class="mock-device-class",
)
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
await hass.async_block_till_done()
acc = cls.windowcovering(hass, hk_driver, "Cover", "cover.simple", 2, None)
assert acc.category == 14
assert acc.char_current_position is not None
assert acc.char_target_position is not None
assert acc.char_position_state is not None
acc = cls.windowcovering(hass, hk_driver, "Cover", "cover.all_info_set", 2, None)
assert acc.category == 14
assert acc.char_current_position is not None
assert acc.char_target_position is not None
assert acc.char_position_state is not None | [
"async",
"def",
"test_windowcovering_restore",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"hass",
".",
"state",
"=",
"CoreState",
".",
"not_running",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"registry",
".",
"async_get_or_create",
"(",
"\"cover\"",
",",
"\"generic\"",
",",
"\"1234\"",
",",
"suggested_object_id",
"=",
"\"simple\"",
",",
")",
"registry",
".",
"async_get_or_create",
"(",
"\"cover\"",
",",
"\"generic\"",
",",
"\"9012\"",
",",
"suggested_object_id",
"=",
"\"all_info_set\"",
",",
"capabilities",
"=",
"{",
"}",
",",
"supported_features",
"=",
"SUPPORT_STOP",
",",
"device_class",
"=",
"\"mock-device-class\"",
",",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_HOMEASSISTANT_START",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"windowcovering",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"\"cover.simple\"",
",",
"2",
",",
"None",
")",
"assert",
"acc",
".",
"category",
"==",
"14",
"assert",
"acc",
".",
"char_current_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_target_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_position_state",
"is",
"not",
"None",
"acc",
"=",
"cls",
".",
"windowcovering",
"(",
"hass",
",",
"hk_driver",
",",
"\"Cover\"",
",",
"\"cover.all_info_set\"",
",",
"2",
",",
"None",
")",
"assert",
"acc",
".",
"category",
"==",
"14",
"assert",
"acc",
".",
"char_current_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_target_position",
"is",
"not",
"None",
"assert",
"acc",
".",
"char_position_state",
"is",
"not",
"None"
] | [
503,
0
] | [
538,
46
] | python | en | ['en', 'en', 'en'] | True |
test_garage_door_with_linked_obstruction_sensor | (hass, hk_driver, cls, events) | Test if accessory and HA are updated accordingly with a linked obstruction sensor. | Test if accessory and HA are updated accordingly with a linked obstruction sensor. | async def test_garage_door_with_linked_obstruction_sensor(hass, hk_driver, cls, events):
"""Test if accessory and HA are updated accordingly with a linked obstruction sensor."""
linked_obstruction_sensor_entity_id = "binary_sensor.obstruction"
entity_id = "cover.garage_door"
hass.states.async_set(linked_obstruction_sensor_entity_id, STATE_OFF)
hass.states.async_set(entity_id, None)
await hass.async_block_till_done()
acc = cls.garage(
hass,
hk_driver,
"Garage Door",
entity_id,
2,
{CONF_LINKED_OBSTRUCTION_SENSOR: linked_obstruction_sensor_entity_id},
)
await acc.run_handler()
await hass.async_block_till_done()
assert acc.aid == 2
assert acc.category == 4 # GarageDoorOpener
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
hass.states.async_set(entity_id, STATE_CLOSED)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_CLOSED
assert acc.char_target_state.value == HK_DOOR_CLOSED
assert acc.char_obstruction_detected.value is False
hass.states.async_set(entity_id, STATE_OPEN)
hass.states.async_set(linked_obstruction_sensor_entity_id, STATE_ON)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_OPEN
assert acc.char_target_state.value == HK_DOOR_OPEN
assert acc.char_obstruction_detected.value is True
hass.states.async_set(entity_id, STATE_CLOSED)
hass.states.async_set(linked_obstruction_sensor_entity_id, STATE_OFF)
await hass.async_block_till_done()
assert acc.char_current_state.value == HK_DOOR_CLOSED
assert acc.char_target_state.value == HK_DOOR_CLOSED
assert acc.char_obstruction_detected.value is False
hass.states.async_remove(entity_id)
hass.states.async_remove(linked_obstruction_sensor_entity_id)
await hass.async_block_till_done() | [
"async",
"def",
"test_garage_door_with_linked_obstruction_sensor",
"(",
"hass",
",",
"hk_driver",
",",
"cls",
",",
"events",
")",
":",
"linked_obstruction_sensor_entity_id",
"=",
"\"binary_sensor.obstruction\"",
"entity_id",
"=",
"\"cover.garage_door\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"linked_obstruction_sensor_entity_id",
",",
"STATE_OFF",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"None",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"acc",
"=",
"cls",
".",
"garage",
"(",
"hass",
",",
"hk_driver",
",",
"\"Garage Door\"",
",",
"entity_id",
",",
"2",
",",
"{",
"CONF_LINKED_OBSTRUCTION_SENSOR",
":",
"linked_obstruction_sensor_entity_id",
"}",
",",
")",
"await",
"acc",
".",
"run_handler",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"aid",
"==",
"2",
"assert",
"acc",
".",
"category",
"==",
"4",
"# GarageDoorOpener",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSED",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"False",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_OPEN",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"linked_obstruction_sensor_entity_id",
",",
"STATE_ON",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_OPEN",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"True",
"hass",
".",
"states",
".",
"async_set",
"(",
"entity_id",
",",
"STATE_CLOSED",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"linked_obstruction_sensor_entity_id",
",",
"STATE_OFF",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"acc",
".",
"char_current_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_target_state",
".",
"value",
"==",
"HK_DOOR_CLOSED",
"assert",
"acc",
".",
"char_obstruction_detected",
".",
"value",
"is",
"False",
"hass",
".",
"states",
".",
"async_remove",
"(",
"entity_id",
")",
"hass",
".",
"states",
".",
"async_remove",
"(",
"linked_obstruction_sensor_entity_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
541,
0
] | [
588,
38
] | python | en | ['en', 'en', 'en'] | True |
test_setup_missing_basic_config | (hass) | Test setup with configuration missing required entries. | Test setup with configuration missing required entries. | async def test_setup_missing_basic_config(hass):
"""Test setup with configuration missing required entries."""
assert await async_setup_component(
hass, binary_sensor.DOMAIN, {"binary_sensor": {"platform": "rest"}}
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 | [
"async",
"def",
"test_setup_missing_basic_config",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"0"
] | [
23,
0
] | [
29,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_missing_config | (hass) | Test setup with configuration missing required entries. | Test setup with configuration missing required entries. | async def test_setup_missing_config(hass):
"""Test setup with configuration missing required entries."""
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "localhost",
"method": "GET",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 | [
"async",
"def",
"test_setup_missing_config",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"0"
] | [
32,
0
] | [
46,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_failed_connect | (hass) | Test setup when connection error occurs. | Test setup when connection error occurs. | async def test_setup_failed_connect(hass):
"""Test setup when connection error occurs."""
respx.get(
"http://localhost", content=httpx.RequestError(message="any", request=Mock())
)
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 | [
"async",
"def",
"test_setup_failed_connect",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"content",
"=",
"httpx",
".",
"RequestError",
"(",
"message",
"=",
"\"any\"",
",",
"request",
"=",
"Mock",
"(",
")",
")",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"0"
] | [
50,
0
] | [
67,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_timeout | (hass) | Test setup when connection timeout occurs. | Test setup when connection timeout occurs. | async def test_setup_timeout(hass):
"""Test setup when connection timeout occurs."""
respx.get("http://localhost", content=asyncio.TimeoutError())
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "localhost",
"method": "GET",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 | [
"async",
"def",
"test_setup_timeout",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"content",
"=",
"asyncio",
".",
"TimeoutError",
"(",
")",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"0"
] | [
71,
0
] | [
86,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_minimum | (hass) | Test setup with minimum configuration. | Test setup with minimum configuration. | async def test_setup_minimum(hass):
"""Test setup with minimum configuration."""
respx.get("http://localhost", status_code=200)
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_minimum",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
90,
0
] | [
105,
44
] | python | en | ['en', 'zu', 'en'] | True |
test_setup_minimum_resource_template | (hass) | Test setup with minimum configuration (resource_template). | Test setup with minimum configuration (resource_template). | async def test_setup_minimum_resource_template(hass):
"""Test setup with minimum configuration (resource_template)."""
respx.get("http://localhost", status_code=200)
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource_template": "{% set url = 'http://localhost' %}{{ url }}",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_minimum_resource_template",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource_template\"",
":",
"\"{% set url = 'http://localhost' %}{{ url }}\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
109,
0
] | [
123,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_duplicate_resource_template | (hass) | Test setup with duplicate resources. | Test setup with duplicate resources. | async def test_setup_duplicate_resource_template(hass):
"""Test setup with duplicate resources."""
respx.get("http://localhost", status_code=200)
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"resource_template": "http://localhost",
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 0 | [
"async",
"def",
"test_setup_duplicate_resource_template",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"resource_template\"",
":",
"\"http://localhost\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"0"
] | [
127,
0
] | [
142,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_get | (hass) | Test setup with valid configuration. | Test setup with valid configuration. | async def test_setup_get(hass):
"""Test setup with valid configuration."""
respx.get("http://localhost", status_code=200, content="{}")
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"value_template": "{{ value_json.key }}",
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
"authentication": "basic",
"username": "my username",
"password": "my password",
"headers": {"Accept": CONTENT_TYPE_JSON},
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_get",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"content",
"=",
"\"{}\"",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.key }}\"",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"\"authentication\"",
":",
"\"basic\"",
",",
"\"username\"",
":",
"\"my username\"",
",",
"\"password\"",
":",
"\"my password\"",
",",
"\"headers\"",
":",
"{",
"\"Accept\"",
":",
"CONTENT_TYPE_JSON",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
146,
0
] | [
170,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_get_digest_auth | (hass) | Test setup with valid configuration. | Test setup with valid configuration. | async def test_setup_get_digest_auth(hass):
"""Test setup with valid configuration."""
respx.get("http://localhost", status_code=200, content="{}")
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"value_template": "{{ value_json.key }}",
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
"authentication": "digest",
"username": "my username",
"password": "my password",
"headers": {"Accept": CONTENT_TYPE_JSON},
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_get_digest_auth",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"content",
"=",
"\"{}\"",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.key }}\"",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"\"authentication\"",
":",
"\"digest\"",
",",
"\"username\"",
":",
"\"my username\"",
",",
"\"password\"",
":",
"\"my password\"",
",",
"\"headers\"",
":",
"{",
"\"Accept\"",
":",
"CONTENT_TYPE_JSON",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
174,
0
] | [
198,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_post | (hass) | Test setup with valid configuration. | Test setup with valid configuration. | async def test_setup_post(hass):
"""Test setup with valid configuration."""
respx.post("http://localhost", status_code=200, content="{}")
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "POST",
"value_template": "{{ value_json.key }}",
"payload": '{ "device": "toaster"}',
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
"authentication": "basic",
"username": "my username",
"password": "my password",
"headers": {"Accept": CONTENT_TYPE_JSON},
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_post",
"(",
"hass",
")",
":",
"respx",
".",
"post",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"content",
"=",
"\"{}\"",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"POST\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.key }}\"",
",",
"\"payload\"",
":",
"'{ \"device\": \"toaster\"}'",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"\"authentication\"",
":",
"\"basic\"",
",",
"\"username\"",
":",
"\"my username\"",
",",
"\"password\"",
":",
"\"my password\"",
",",
"\"headers\"",
":",
"{",
"\"Accept\"",
":",
"CONTENT_TYPE_JSON",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
202,
0
] | [
226,
44
] | python | en | ['en', 'en', 'en'] | True |
test_setup_get_off | (hass) | Test setup with valid off configuration. | Test setup with valid off configuration. | async def test_setup_get_off(hass):
"""Test setup with valid off configuration."""
respx.get(
"http://localhost",
status_code=200,
headers={"content-type": "text/json"},
content='{"dog": false}',
)
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"value_template": "{{ value_json.dog }}",
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
state = hass.states.get("binary_sensor.foo")
assert state.state == STATE_OFF | [
"async",
"def",
"test_setup_get_off",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"headers",
"=",
"{",
"\"content-type\"",
":",
"\"text/json\"",
"}",
",",
"content",
"=",
"'{\"dog\": false}'",
",",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.dog }}\"",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.foo\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF"
] | [
230,
0
] | [
257,
35
] | python | en | ['en', 'en', 'en'] | True |
test_setup_get_on | (hass) | Test setup with valid on configuration. | Test setup with valid on configuration. | async def test_setup_get_on(hass):
"""Test setup with valid on configuration."""
respx.get(
"http://localhost",
status_code=200,
headers={"content-type": "text/json"},
content='{"dog": true}',
)
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"value_template": "{{ value_json.dog }}",
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
state = hass.states.get("binary_sensor.foo")
assert state.state == STATE_ON | [
"async",
"def",
"test_setup_get_on",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"headers",
"=",
"{",
"\"content-type\"",
":",
"\"text/json\"",
"}",
",",
"content",
"=",
"'{\"dog\": true}'",
",",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.dog }}\"",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.foo\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_ON"
] | [
261,
0
] | [
288,
34
] | python | en | ['en', 'en', 'en'] | True |
test_setup_with_exception | (hass) | Test setup with exception. | Test setup with exception. | async def test_setup_with_exception(hass):
"""Test setup with exception."""
respx.get("http://localhost", status_code=200, content="{}")
assert await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"value_template": "{{ value_json.dog }}",
"name": "foo",
"verify_ssl": "true",
"timeout": 30,
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
state = hass.states.get("binary_sensor.foo")
assert state.state == STATE_OFF
await async_setup_component(hass, "homeassistant", {})
await hass.async_block_till_done()
respx.clear()
respx.get(
"http://localhost", content=httpx.RequestError(message="any", request=Mock())
)
await hass.services.async_call(
"homeassistant",
"update_entity",
{ATTR_ENTITY_ID: ["binary_sensor.foo"]},
blocking=True,
)
await hass.async_block_till_done()
state = hass.states.get("binary_sensor.foo")
assert state.state == STATE_UNAVAILABLE | [
"async",
"def",
"test_setup_with_exception",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
",",
"content",
"=",
"\"{}\"",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"value_template\"",
":",
"\"{{ value_json.dog }}\"",
",",
"\"name\"",
":",
"\"foo\"",
",",
"\"verify_ssl\"",
":",
"\"true\"",
",",
"\"timeout\"",
":",
"30",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.foo\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_OFF",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"homeassistant\"",
",",
"{",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"respx",
".",
"clear",
"(",
")",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"content",
"=",
"httpx",
".",
"RequestError",
"(",
"message",
"=",
"\"any\"",
",",
"request",
"=",
"Mock",
"(",
")",
")",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"homeassistant\"",
",",
"\"update_entity\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"[",
"\"binary_sensor.foo\"",
"]",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.foo\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
292,
0
] | [
332,
43
] | python | en | ['en', 'en', 'en'] | True |
test_reload | (hass) | Verify we can reload reset sensors. | Verify we can reload reset sensors. | async def test_reload(hass):
"""Verify we can reload reset sensors."""
respx.get("http://localhost", status_code=200)
await async_setup_component(
hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "rest",
"method": "GET",
"name": "mockrest",
"resource": "http://localhost",
}
},
)
await hass.async_block_till_done()
await hass.async_start()
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1
assert hass.states.get("binary_sensor.mockrest")
yaml_path = path.join(
_get_fixtures_base_path(),
"fixtures",
"rest/configuration.yaml",
)
with patch.object(hass_config, "YAML_CONFIG_FILE", yaml_path):
await hass.services.async_call(
"rest",
SERVICE_RELOAD,
{},
blocking=True,
)
await hass.async_block_till_done()
assert hass.states.get("binary_sensor.mockreset") is None
assert hass.states.get("binary_sensor.rollout") | [
"async",
"def",
"test_reload",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost\"",
",",
"status_code",
"=",
"200",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"name\"",
":",
"\"mockrest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"async_start",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.mockrest\"",
")",
"yaml_path",
"=",
"path",
".",
"join",
"(",
"_get_fixtures_base_path",
"(",
")",
",",
"\"fixtures\"",
",",
"\"rest/configuration.yaml\"",
",",
")",
"with",
"patch",
".",
"object",
"(",
"hass_config",
",",
"\"YAML_CONFIG_FILE\"",
",",
"yaml_path",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"rest\"",
",",
"SERVICE_RELOAD",
",",
"{",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.mockreset\"",
")",
"is",
"None",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"binary_sensor.rollout\"",
")"
] | [
336,
0
] | [
376,
51
] | python | en | ['en', 'ca', 'en'] | True |
test_setup_query_params | (hass) | Test setup with query params. | Test setup with query params. | async def test_setup_query_params(hass):
"""Test setup with query params."""
respx.get(
"http://localhost?search=something",
status_code=200,
)
assert await async_setup_component(
hass,
binary_sensor.DOMAIN,
{
"binary_sensor": {
"platform": "rest",
"resource": "http://localhost",
"method": "GET",
"params": {"search": "something"},
}
},
)
await hass.async_block_till_done()
assert len(hass.states.async_all()) == 1 | [
"async",
"def",
"test_setup_query_params",
"(",
"hass",
")",
":",
"respx",
".",
"get",
"(",
"\"http://localhost?search=something\"",
",",
"status_code",
"=",
"200",
",",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"binary_sensor",
".",
"DOMAIN",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"rest\"",
",",
"\"resource\"",
":",
"\"http://localhost\"",
",",
"\"method\"",
":",
"\"GET\"",
",",
"\"params\"",
":",
"{",
"\"search\"",
":",
"\"something\"",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1"
] | [
380,
0
] | [
399,
44
] | python | en | ['en', 'en', 'en'] | True |
sha512half | (buf) |
Return the first 256 bits (32 bytes) of a SHA-512 hash.
|
Return the first 256 bits (32 bytes) of a SHA-512 hash.
| def sha512half(buf):
"""
Return the first 256 bits (32 bytes) of a SHA-512 hash.
"""
return sha512(buf).digest()[:32] | [
"def",
"sha512half",
"(",
"buf",
")",
":",
"return",
"sha512",
"(",
"buf",
")",
".",
"digest",
"(",
")",
"[",
":",
"32",
"]"
] | [
39,
0
] | [
43,
36
] | python | en | ['en', 'error', 'th'] | False |
secp256k1_secret_key_from | (seed) |
Calculate a valid secp256k1 secret key by hashing a seed value;
if the result isn't a valid key, increment a seq value and try
again.
Returns a secret key as a 32-byte integer.
|
Calculate a valid secp256k1 secret key by hashing a seed value;
if the result isn't a valid key, increment a seq value and try
again. | def secp256k1_secret_key_from(seed):
"""
Calculate a valid secp256k1 secret key by hashing a seed value;
if the result isn't a valid key, increment a seq value and try
again.
Returns a secret key as a 32-byte integer.
"""
seq = 0
while True:
buf = seed + seq.to_bytes(4, byteorder="big", signed=False)
h = sha512half(buf)
h_i = int.from_bytes(h, byteorder="big", signed=False)
if h_i < curve.secp256k1.q and h_i != 0:
return h_i
# Else, not a valid secp256k1 key; try again with a new sequence value.
seq += 1 | [
"def",
"secp256k1_secret_key_from",
"(",
"seed",
")",
":",
"seq",
"=",
"0",
"while",
"True",
":",
"buf",
"=",
"seed",
"+",
"seq",
".",
"to_bytes",
"(",
"4",
",",
"byteorder",
"=",
"\"big\"",
",",
"signed",
"=",
"False",
")",
"h",
"=",
"sha512half",
"(",
"buf",
")",
"h_i",
"=",
"int",
".",
"from_bytes",
"(",
"h",
",",
"byteorder",
"=",
"\"big\"",
",",
"signed",
"=",
"False",
")",
"if",
"h_i",
"<",
"curve",
".",
"secp256k1",
".",
"q",
"and",
"h_i",
"!=",
"0",
":",
"return",
"h_i",
"# Else, not a valid secp256k1 key; try again with a new sequence value.",
"seq",
"+=",
"1"
] | [
245,
0
] | [
261,
16
] | python | en | ['en', 'error', 'th'] | False |
compress_secp256k1_public | (point) |
Returns a 33-byte compressed key from an secp256k1 public key,
which is a point in the form (x,y) where both x and y are 32-byte ints
|
Returns a 33-byte compressed key from an secp256k1 public key,
which is a point in the form (x,y) where both x and y are 32-byte ints
| def compress_secp256k1_public(point):
"""
Returns a 33-byte compressed key from an secp256k1 public key,
which is a point in the form (x,y) where both x and y are 32-byte ints
"""
if point.y % 2:
prefix = b'\x03'
else:
prefix = b'\x02'
return prefix + point.x.to_bytes(32, byteorder="big", signed=False) | [
"def",
"compress_secp256k1_public",
"(",
"point",
")",
":",
"if",
"point",
".",
"y",
"%",
"2",
":",
"prefix",
"=",
"b'\\x03'",
"else",
":",
"prefix",
"=",
"b'\\x02'",
"return",
"prefix",
"+",
"point",
".",
"x",
".",
"to_bytes",
"(",
"32",
",",
"byteorder",
"=",
"\"big\"",
",",
"signed",
"=",
"False",
")"
] | [
263,
0
] | [
272,
71
] | python | en | ['en', 'error', 'th'] | False |
swap_byte_order | (buf) |
Swap the byte order of a bytes object.
The rippled implementation of RFC-1751 uses the reversed byte order as the
examples included in the RFC-1751 spec (which doesn't mention byte order).
|
Swap the byte order of a bytes object.
The rippled implementation of RFC-1751 uses the reversed byte order as the
examples included in the RFC-1751 spec (which doesn't mention byte order).
| def swap_byte_order(buf):
"""
Swap the byte order of a bytes object.
The rippled implementation of RFC-1751 uses the reversed byte order as the
examples included in the RFC-1751 spec (which doesn't mention byte order).
"""
size = len(buf)
# doesn't actually matter if it's "really" big-endian
i = int.from_bytes(buf, byteorder="big", signed=False)
revbuf = i.to_bytes(size, byteorder="little", signed=False)
return revbuf | [
"def",
"swap_byte_order",
"(",
"buf",
")",
":",
"size",
"=",
"len",
"(",
"buf",
")",
"# doesn't actually matter if it's \"really\" big-endian",
"i",
"=",
"int",
".",
"from_bytes",
"(",
"buf",
",",
"byteorder",
"=",
"\"big\"",
",",
"signed",
"=",
"False",
")",
"revbuf",
"=",
"i",
".",
"to_bytes",
"(",
"size",
",",
"byteorder",
"=",
"\"little\"",
",",
"signed",
"=",
"False",
")",
"return",
"revbuf"
] | [
274,
0
] | [
284,
17
] | python | en | ['en', 'error', 'th'] | False |
Seed.__init__ | (self, in_string=None, correct_rfc1751=False) |
Decode a buffer input in one of the formats the XRPL supports and convert
it to a buffer representing the 16-byte seed to use for key derivation.
Formats include:
- XRPL base58 encoding
- RFC-1751
- hexadecimal
- passphrase
|
Decode a buffer input in one of the formats the XRPL supports and convert
it to a buffer representing the 16-byte seed to use for key derivation.
Formats include:
- XRPL base58 encoding
- RFC-1751
- hexadecimal
- passphrase
| def __init__(self, in_string=None, correct_rfc1751=False):
"""
Decode a buffer input in one of the formats the XRPL supports and convert
it to a buffer representing the 16-byte seed to use for key derivation.
Formats include:
- XRPL base58 encoding
- RFC-1751
- hexadecimal
- passphrase
"""
self.correct_rfc1751 = correct_rfc1751
# Keys are lazy-derived later
self._secp256k1_sec = None
self._secp256k1_pub = None
self._secp256k1_root_pub = None
self._ed25519_sec = None
self._ed25519_pub = None
if in_string is None:
# Generate a new seed randomly from OS-level RNG.
self.bytes = randbits(16*8).to_bytes(16, byteorder="big")
return
# Is it base58?
try:
decoded = base58.b58decode_check(in_string)
if decoded[:1] == XRPL_SEED_PREFIX and len(decoded) == 17:
self.bytes = decoded[1:]
return
else:
raise ValueError
except:
pass
# Maybe it's RFC1751?
try:
decoded = RFC1751.english_to_key(in_string)
if len(decoded) == 16:
if correct_rfc1751:
self.bytes = decoded
else:
self.bytes = swap_byte_order(decoded)
return
else:
raise ValueError
except:
pass
# OK, how about hexadecimal?
try:
decoded = bytes.fromhex(in_string)
if len(decoded) == 16:
self.bytes = decoded
return
else:
raise ValueError
except ValueError as e:
pass
# Fallback: Guess it's a passphrase.
encoded = in_string.encode("UTF-8")
self.bytes = sha512(encoded).digest()[:16]
return | [
"def",
"__init__",
"(",
"self",
",",
"in_string",
"=",
"None",
",",
"correct_rfc1751",
"=",
"False",
")",
":",
"self",
".",
"correct_rfc1751",
"=",
"correct_rfc1751",
"# Keys are lazy-derived later",
"self",
".",
"_secp256k1_sec",
"=",
"None",
"self",
".",
"_secp256k1_pub",
"=",
"None",
"self",
".",
"_secp256k1_root_pub",
"=",
"None",
"self",
".",
"_ed25519_sec",
"=",
"None",
"self",
".",
"_ed25519_pub",
"=",
"None",
"if",
"in_string",
"is",
"None",
":",
"# Generate a new seed randomly from OS-level RNG.",
"self",
".",
"bytes",
"=",
"randbits",
"(",
"16",
"*",
"8",
")",
".",
"to_bytes",
"(",
"16",
",",
"byteorder",
"=",
"\"big\"",
")",
"return",
"# Is it base58?",
"try",
":",
"decoded",
"=",
"base58",
".",
"b58decode_check",
"(",
"in_string",
")",
"if",
"decoded",
"[",
":",
"1",
"]",
"==",
"XRPL_SEED_PREFIX",
"and",
"len",
"(",
"decoded",
")",
"==",
"17",
":",
"self",
".",
"bytes",
"=",
"decoded",
"[",
"1",
":",
"]",
"return",
"else",
":",
"raise",
"ValueError",
"except",
":",
"pass",
"# Maybe it's RFC1751?",
"try",
":",
"decoded",
"=",
"RFC1751",
".",
"english_to_key",
"(",
"in_string",
")",
"if",
"len",
"(",
"decoded",
")",
"==",
"16",
":",
"if",
"correct_rfc1751",
":",
"self",
".",
"bytes",
"=",
"decoded",
"else",
":",
"self",
".",
"bytes",
"=",
"swap_byte_order",
"(",
"decoded",
")",
"return",
"else",
":",
"raise",
"ValueError",
"except",
":",
"pass",
"# OK, how about hexadecimal?",
"try",
":",
"decoded",
"=",
"bytes",
".",
"fromhex",
"(",
"in_string",
")",
"if",
"len",
"(",
"decoded",
")",
"==",
"16",
":",
"self",
".",
"bytes",
"=",
"decoded",
"return",
"else",
":",
"raise",
"ValueError",
"except",
"ValueError",
"as",
"e",
":",
"pass",
"# Fallback: Guess it's a passphrase.",
"encoded",
"=",
"in_string",
".",
"encode",
"(",
"\"UTF-8\"",
")",
"self",
".",
"bytes",
"=",
"sha512",
"(",
"encoded",
")",
".",
"digest",
"(",
")",
"[",
":",
"16",
"]",
"return"
] | [
50,
4
] | [
113,
14
] | python | en | ['en', 'error', 'th'] | False |
Seed.encode_base58 | (self) |
Returns a string representation of this seed as an XRPL base58 encoded
string such as 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'.
|
Returns a string representation of this seed as an XRPL base58 encoded
string such as 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'.
| def encode_base58(self):
"""
Returns a string representation of this seed as an XRPL base58 encoded
string such as 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb'.
"""
return base58.b58encode_check(XRPL_SEED_PREFIX + self.bytes).decode() | [
"def",
"encode_base58",
"(",
"self",
")",
":",
"return",
"base58",
".",
"b58encode_check",
"(",
"XRPL_SEED_PREFIX",
"+",
"self",
".",
"bytes",
")",
".",
"decode",
"(",
")"
] | [
115,
4
] | [
120,
77
] | python | en | ['en', 'error', 'th'] | False |
Seed.encode_hex | (self) |
Returns a string representation of this seed as hexadecimal.
|
Returns a string representation of this seed as hexadecimal.
| def encode_hex(self):
"""
Returns a string representation of this seed as hexadecimal.
"""
return self.bytes.hex().upper() | [
"def",
"encode_hex",
"(",
"self",
")",
":",
"return",
"self",
".",
"bytes",
".",
"hex",
"(",
")",
".",
"upper",
"(",
")"
] | [
122,
4
] | [
126,
39
] | python | en | ['en', 'error', 'th'] | False |
Seed.encode_rfc1751 | (self, correct_rfc1751=None) |
Returns a string representation of this seed as an RFC-1751 encoded
passphrase.
|
Returns a string representation of this seed as an RFC-1751 encoded
passphrase.
| def encode_rfc1751(self, correct_rfc1751=None):
"""
Returns a string representation of this seed as an RFC-1751 encoded
passphrase.
"""
# Use the default byte order swap this Seed was generated with
# unless the method call overrides it.
if correct_rfc1751 is None:
correct_rfc1751=self.correct_rfc1751
if correct_rfc1751:
buf = self.bytes
else:
buf = swap_byte_order(self.bytes)
return RFC1751.key_to_english(buf) | [
"def",
"encode_rfc1751",
"(",
"self",
",",
"correct_rfc1751",
"=",
"None",
")",
":",
"# Use the default byte order swap this Seed was generated with",
"# unless the method call overrides it.",
"if",
"correct_rfc1751",
"is",
"None",
":",
"correct_rfc1751",
"=",
"self",
".",
"correct_rfc1751",
"if",
"correct_rfc1751",
":",
"buf",
"=",
"self",
".",
"bytes",
"else",
":",
"buf",
"=",
"swap_byte_order",
"(",
"self",
".",
"bytes",
")",
"return",
"RFC1751",
".",
"key_to_english",
"(",
"buf",
")"
] | [
128,
4
] | [
142,
42
] | python | en | ['en', 'error', 'th'] | False |
Seed.ed25519_secret_key | (self) |
Returns a 32-byte Ed25519 secret key (bytes).
Saves the calculation for later calls.
|
Returns a 32-byte Ed25519 secret key (bytes).
Saves the calculation for later calls.
| def ed25519_secret_key(self):
"""
Returns a 32-byte Ed25519 secret key (bytes).
Saves the calculation for later calls.
"""
if self._ed25519_sec is None:
self._ed25519_sec = sha512half(self.bytes)
return self._ed25519_sec | [
"def",
"ed25519_secret_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"_ed25519_sec",
"is",
"None",
":",
"self",
".",
"_ed25519_sec",
"=",
"sha512half",
"(",
"self",
".",
"bytes",
")",
"return",
"self",
".",
"_ed25519_sec"
] | [
145,
4
] | [
152,
32
] | python | en | ['en', 'error', 'th'] | False |
Seed.ed25519_public_key | (self) |
33-byte Ed25519 public key (bytes)—really a 32-byte key
prefixed with the byte 0xED to indicate that it's an Ed25519 key.
|
33-byte Ed25519 public key (bytes)—really a 32-byte key
prefixed with the byte 0xED to indicate that it's an Ed25519 key.
| def ed25519_public_key(self):
"""
33-byte Ed25519 public key (bytes)—really a 32-byte key
prefixed with the byte 0xED to indicate that it's an Ed25519 key.
"""
if self._ed25519_pub is None:
self._ed25519_pub = (ED_PREFIX +
ed25519.publickey(self.ed25519_secret_key))
return self._ed25519_pub | [
"def",
"ed25519_public_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"_ed25519_pub",
"is",
"None",
":",
"self",
".",
"_ed25519_pub",
"=",
"(",
"ED_PREFIX",
"+",
"ed25519",
".",
"publickey",
"(",
"self",
".",
"ed25519_secret_key",
")",
")",
"return",
"self",
".",
"_ed25519_pub"
] | [
155,
4
] | [
163,
32
] | python | en | ['en', 'error', 'th'] | False |
Seed.secp256k1_secret_key | (self) |
32-byte secp256k1 secret key (bytes)
|
32-byte secp256k1 secret key (bytes)
| def secp256k1_secret_key(self):
"""
32-byte secp256k1 secret key (bytes)
"""
if self._secp256k1_sec is None:
self.derive_secp256k1_master_keys()
return self._secp256k1_sec | [
"def",
"secp256k1_secret_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"_secp256k1_sec",
"is",
"None",
":",
"self",
".",
"derive_secp256k1_master_keys",
"(",
")",
"return",
"self",
".",
"_secp256k1_sec"
] | [
166,
4
] | [
172,
34
] | python | en | ['en', 'error', 'th'] | False |
Seed.secp256k1_public_key | (self) |
33-byte secp256k1 account public key (bytes)
|
33-byte secp256k1 account public key (bytes)
| def secp256k1_public_key(self):
"""
33-byte secp256k1 account public key (bytes)
"""
if self._secp256k1_pub is None:
self.derive_secp256k1_master_keys()
return self._secp256k1_pub | [
"def",
"secp256k1_public_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"_secp256k1_pub",
"is",
"None",
":",
"self",
".",
"derive_secp256k1_master_keys",
"(",
")",
"return",
"self",
".",
"_secp256k1_pub"
] | [
175,
4
] | [
181,
34
] | python | en | ['en', 'error', 'th'] | False |
Seed.secp256k1_root_public_key | (self) |
33-byte secp256k1 root public key (bytes)
This is the public key used for validators.
|
33-byte secp256k1 root public key (bytes)
This is the public key used for validators.
| def secp256k1_root_public_key(self):
"""
33-byte secp256k1 root public key (bytes)
This is the public key used for validators.
"""
if self._secp256k1_root_pub is None:
self.derive_secp256k1_master_keys()
return self._secp256k1_root_pub | [
"def",
"secp256k1_root_public_key",
"(",
"self",
")",
":",
"if",
"self",
".",
"_secp256k1_root_pub",
"is",
"None",
":",
"self",
".",
"derive_secp256k1_master_keys",
"(",
")",
"return",
"self",
".",
"_secp256k1_root_pub"
] | [
184,
4
] | [
191,
39
] | python | en | ['en', 'error', 'th'] | False |
Seed.derive_secp256k1_master_keys | (self) |
Uses the XRPL's convoluted key derivation process to get the
secp256k1 master keypair for this seed value.
Saves the values to the object for later reference.
|
Uses the XRPL's convoluted key derivation process to get the
secp256k1 master keypair for this seed value.
Saves the values to the object for later reference.
| def derive_secp256k1_master_keys(self):
"""
Uses the XRPL's convoluted key derivation process to get the
secp256k1 master keypair for this seed value.
Saves the values to the object for later reference.
"""
root_sec_i = secp256k1_secret_key_from(self.bytes)
root_pub_point = keys.get_public_key(root_sec_i, curve.secp256k1)
root_pub_b = compress_secp256k1_public(root_pub_point)
fam_b = bytes(4) # Account families are unused; just 4 bytes of zeroes
inter_pk_i = secp256k1_secret_key_from( b''.join([root_pub_b, fam_b]) )
inter_pub_point = keys.get_public_key(inter_pk_i, curve.secp256k1)
# Secret keys are ints, so just add them mod the secp256k1 group order
master_sec_i = (root_sec_i + inter_pk_i) % curve.secp256k1.q
# Public keys are points, so the fastecdsa lib handles adding them
master_pub_point = root_pub_point + inter_pub_point
self._secp256k1_sec = master_sec_i.to_bytes(32, byteorder="big", signed=False)
self._secp256k1_pub = compress_secp256k1_public(master_pub_point)
self._secp256k1_root_pub = root_pub_b
# Saving the full key to make it easier to sign things later
self._secp256k1_full = master_pub_point | [
"def",
"derive_secp256k1_master_keys",
"(",
"self",
")",
":",
"root_sec_i",
"=",
"secp256k1_secret_key_from",
"(",
"self",
".",
"bytes",
")",
"root_pub_point",
"=",
"keys",
".",
"get_public_key",
"(",
"root_sec_i",
",",
"curve",
".",
"secp256k1",
")",
"root_pub_b",
"=",
"compress_secp256k1_public",
"(",
"root_pub_point",
")",
"fam_b",
"=",
"bytes",
"(",
"4",
")",
"# Account families are unused; just 4 bytes of zeroes",
"inter_pk_i",
"=",
"secp256k1_secret_key_from",
"(",
"b''",
".",
"join",
"(",
"[",
"root_pub_b",
",",
"fam_b",
"]",
")",
")",
"inter_pub_point",
"=",
"keys",
".",
"get_public_key",
"(",
"inter_pk_i",
",",
"curve",
".",
"secp256k1",
")",
"# Secret keys are ints, so just add them mod the secp256k1 group order",
"master_sec_i",
"=",
"(",
"root_sec_i",
"+",
"inter_pk_i",
")",
"%",
"curve",
".",
"secp256k1",
".",
"q",
"# Public keys are points, so the fastecdsa lib handles adding them",
"master_pub_point",
"=",
"root_pub_point",
"+",
"inter_pub_point",
"self",
".",
"_secp256k1_sec",
"=",
"master_sec_i",
".",
"to_bytes",
"(",
"32",
",",
"byteorder",
"=",
"\"big\"",
",",
"signed",
"=",
"False",
")",
"self",
".",
"_secp256k1_pub",
"=",
"compress_secp256k1_public",
"(",
"master_pub_point",
")",
"self",
".",
"_secp256k1_root_pub",
"=",
"root_pub_b",
"# Saving the full key to make it easier to sign things later",
"self",
".",
"_secp256k1_full",
"=",
"master_pub_point"
] | [
193,
4
] | [
217,
47
] | python | en | ['en', 'error', 'th'] | False |
Seed.encode_secp256k1_public_base58 | (self, validator=False) |
Return the base58-encoded version of the secp256k1 public key.
|
Return the base58-encoded version of the secp256k1 public key.
| def encode_secp256k1_public_base58(self, validator=False):
"""
Return the base58-encoded version of the secp256k1 public key.
"""
if validator:
# Validators use the "root" public key
key = self.secp256k1_root_public_key
prefix = XRPL_VALIDATOR_PUBKEY_PREFIX
else:
# Accounts use the derived "master" public key
key = self.secp256k1_public_key
prefix = XRPL_ACCT_PUBKEY_PREFIX
return base58.b58encode_check(prefix + key).decode() | [
"def",
"encode_secp256k1_public_base58",
"(",
"self",
",",
"validator",
"=",
"False",
")",
":",
"if",
"validator",
":",
"# Validators use the \"root\" public key",
"key",
"=",
"self",
".",
"secp256k1_root_public_key",
"prefix",
"=",
"XRPL_VALIDATOR_PUBKEY_PREFIX",
"else",
":",
"# Accounts use the derived \"master\" public key",
"key",
"=",
"self",
".",
"secp256k1_public_key",
"prefix",
"=",
"XRPL_ACCT_PUBKEY_PREFIX",
"return",
"base58",
".",
"b58encode_check",
"(",
"prefix",
"+",
"key",
")",
".",
"decode",
"(",
")"
] | [
219,
4
] | [
232,
60
] | python | en | ['en', 'error', 'th'] | False |
Seed.encode_ed25519_public_base58 | (self) |
Return the base58-encoded version of the Ed25519 public key.
|
Return the base58-encoded version of the Ed25519 public key.
| def encode_ed25519_public_base58(self):
"""
Return the base58-encoded version of the Ed25519 public key.
"""
# Unlike secp256k1, Ed25519 public keys are the same for
# accounts and for validators.
prefix = XRPL_ACCT_PUBKEY_PREFIX
return base58.b58encode_check(prefix +
self.ed25519_public_key).decode() | [
"def",
"encode_ed25519_public_base58",
"(",
"self",
")",
":",
"# Unlike secp256k1, Ed25519 public keys are the same for",
"# accounts and for validators.",
"prefix",
"=",
"XRPL_ACCT_PUBKEY_PREFIX",
"return",
"base58",
".",
"b58encode_check",
"(",
"prefix",
"+",
"self",
".",
"ed25519_public_key",
")",
".",
"decode",
"(",
")"
] | [
234,
4
] | [
243,
71
] | python | en | ['en', 'error', 'th'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up a Nest Cam.
No longer in use.
| Set up a Nest Cam. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a Nest Cam.
No longer in use.
""" | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":"
] | [
17,
0
] | [
21,
7
] | python | en | ['en', 'pt', 'en'] | True |
async_setup_legacy_entry | (hass, entry, async_add_entities) | Set up a Nest sensor based on a config entry. | Set up a Nest sensor based on a config entry. | async def async_setup_legacy_entry(hass, entry, async_add_entities):
"""Set up a Nest sensor based on a config entry."""
camera_devices = await hass.async_add_executor_job(
hass.data[nest.DATA_NEST].cameras
)
cameras = [NestCamera(structure, device) for structure, device in camera_devices]
async_add_entities(cameras, True) | [
"async",
"def",
"async_setup_legacy_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"camera_devices",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"hass",
".",
"data",
"[",
"nest",
".",
"DATA_NEST",
"]",
".",
"cameras",
")",
"cameras",
"=",
"[",
"NestCamera",
"(",
"structure",
",",
"device",
")",
"for",
"structure",
",",
"device",
"in",
"camera_devices",
"]",
"async_add_entities",
"(",
"cameras",
",",
"True",
")"
] | [
24,
0
] | [
30,
37
] | python | en | ['en', 'da', 'en'] | True |
NestCamera.__init__ | (self, structure, device) | Initialize a Nest Camera. | Initialize a Nest Camera. | def __init__(self, structure, device):
"""Initialize a Nest Camera."""
super().__init__()
self.structure = structure
self.device = device
self._location = None
self._name = None
self._online = None
self._is_streaming = None
self._is_video_history_enabled = False
# Default to non-NestAware subscribed, but will be fixed during update
self._time_between_snapshots = timedelta(seconds=30)
self._last_image = None
self._next_snapshot_at = None | [
"def",
"__init__",
"(",
"self",
",",
"structure",
",",
"device",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"structure",
"=",
"structure",
"self",
".",
"device",
"=",
"device",
"self",
".",
"_location",
"=",
"None",
"self",
".",
"_name",
"=",
"None",
"self",
".",
"_online",
"=",
"None",
"self",
".",
"_is_streaming",
"=",
"None",
"self",
".",
"_is_video_history_enabled",
"=",
"False",
"# Default to non-NestAware subscribed, but will be fixed during update",
"self",
".",
"_time_between_snapshots",
"=",
"timedelta",
"(",
"seconds",
"=",
"30",
")",
"self",
".",
"_last_image",
"=",
"None",
"self",
".",
"_next_snapshot_at",
"=",
"None"
] | [
36,
4
] | [
49,
37
] | python | co | ['en', 'co', 'it'] | False |
NestCamera.name | (self) | Return the name of the nest, if any. | Return the name of the nest, if any. | def name(self):
"""Return the name of the nest, if any."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
52,
4
] | [
54,
25
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.unique_id | (self) | Return the serial number. | Return the serial number. | def unique_id(self):
"""Return the serial number."""
return self.device.device_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"device_id"
] | [
57,
4
] | [
59,
36
] | python | en | ['en', 'id', 'en'] | True |
NestCamera.device_info | (self) | Return information about the device. | Return information about the device. | def device_info(self):
"""Return information about the device."""
return {
"identifiers": {(nest.DOMAIN, self.device.device_id)},
"name": self.device.name_long,
"manufacturer": "Nest Labs",
"model": "Camera",
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"nest",
".",
"DOMAIN",
",",
"self",
".",
"device",
".",
"device_id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"device",
".",
"name_long",
",",
"\"manufacturer\"",
":",
"\"Nest Labs\"",
",",
"\"model\"",
":",
"\"Camera\"",
",",
"}"
] | [
62,
4
] | [
69,
9
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.should_poll | (self) | Nest camera should poll periodically. | Nest camera should poll periodically. | def should_poll(self):
"""Nest camera should poll periodically."""
return True | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"True"
] | [
72,
4
] | [
74,
19
] | python | en | ['en', 'pt', 'en'] | True |
NestCamera.is_recording | (self) | Return true if the device is recording. | Return true if the device is recording. | def is_recording(self):
"""Return true if the device is recording."""
return self._is_streaming | [
"def",
"is_recording",
"(",
"self",
")",
":",
"return",
"self",
".",
"_is_streaming"
] | [
77,
4
] | [
79,
33
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.brand | (self) | Return the brand of the camera. | Return the brand of the camera. | def brand(self):
"""Return the brand of the camera."""
return NEST_BRAND | [
"def",
"brand",
"(",
"self",
")",
":",
"return",
"NEST_BRAND"
] | [
82,
4
] | [
84,
25
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.supported_features | (self) | Nest Cam support turn on and off. | Nest Cam support turn on and off. | def supported_features(self):
"""Nest Cam support turn on and off."""
return SUPPORT_ON_OFF | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_ON_OFF"
] | [
87,
4
] | [
89,
29
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.is_on | (self) | Return true if on. | Return true if on. | def is_on(self):
"""Return true if on."""
return self._online and self._is_streaming | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_online",
"and",
"self",
".",
"_is_streaming"
] | [
92,
4
] | [
94,
50
] | python | en | ['en', 'mt', 'en'] | True |
NestCamera.turn_off | (self) | Turn off camera. | Turn off camera. | def turn_off(self):
"""Turn off camera."""
_LOGGER.debug("Turn off camera %s", self._name)
# Calling Nest API in is_streaming setter.
# device.is_streaming would not immediately change until the process
# finished in Nest Cam.
self.device.is_streaming = False | [
"def",
"turn_off",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Turn off camera %s\"",
",",
"self",
".",
"_name",
")",
"# Calling Nest API in is_streaming setter.",
"# device.is_streaming would not immediately change until the process",
"# finished in Nest Cam.",
"self",
".",
"device",
".",
"is_streaming",
"=",
"False"
] | [
96,
4
] | [
102,
40
] | python | en | ['en', 'ja', 'en'] | True |
NestCamera.turn_on | (self) | Turn on camera. | Turn on camera. | def turn_on(self):
"""Turn on camera."""
if not self._online:
_LOGGER.error("Camera %s is offline", self._name)
return
_LOGGER.debug("Turn on camera %s", self._name)
# Calling Nest API in is_streaming setter.
# device.is_streaming would not immediately change until the process
# finished in Nest Cam.
self.device.is_streaming = True | [
"def",
"turn_on",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_online",
":",
"_LOGGER",
".",
"error",
"(",
"\"Camera %s is offline\"",
",",
"self",
".",
"_name",
")",
"return",
"_LOGGER",
".",
"debug",
"(",
"\"Turn on camera %s\"",
",",
"self",
".",
"_name",
")",
"# Calling Nest API in is_streaming setter.",
"# device.is_streaming would not immediately change until the process",
"# finished in Nest Cam.",
"self",
".",
"device",
".",
"is_streaming",
"=",
"True"
] | [
104,
4
] | [
114,
39
] | python | en | ['en', 'et', 'en'] | True |
NestCamera.update | (self) | Cache value from Python-nest. | Cache value from Python-nest. | def update(self):
"""Cache value from Python-nest."""
self._location = self.device.where
self._name = self.device.name
self._online = self.device.online
self._is_streaming = self.device.is_streaming
self._is_video_history_enabled = self.device.is_video_history_enabled
if self._is_video_history_enabled:
# NestAware allowed 10/min
self._time_between_snapshots = timedelta(seconds=6)
else:
# Otherwise, 2/min
self._time_between_snapshots = timedelta(seconds=30) | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_location",
"=",
"self",
".",
"device",
".",
"where",
"self",
".",
"_name",
"=",
"self",
".",
"device",
".",
"name",
"self",
".",
"_online",
"=",
"self",
".",
"device",
".",
"online",
"self",
".",
"_is_streaming",
"=",
"self",
".",
"device",
".",
"is_streaming",
"self",
".",
"_is_video_history_enabled",
"=",
"self",
".",
"device",
".",
"is_video_history_enabled",
"if",
"self",
".",
"_is_video_history_enabled",
":",
"# NestAware allowed 10/min",
"self",
".",
"_time_between_snapshots",
"=",
"timedelta",
"(",
"seconds",
"=",
"6",
")",
"else",
":",
"# Otherwise, 2/min",
"self",
".",
"_time_between_snapshots",
"=",
"timedelta",
"(",
"seconds",
"=",
"30",
")"
] | [
116,
4
] | [
129,
64
] | python | en | ['en', 'en', 'en'] | True |
NestCamera.camera_image | (self) | Return a still image response from the camera. | Return a still image response from the camera. | def camera_image(self):
"""Return a still image response from the camera."""
now = utcnow()
if self._ready_for_snapshot(now):
url = self.device.snapshot_url
try:
response = requests.get(url)
except requests.exceptions.RequestException as error:
_LOGGER.error("Error getting camera image: %s", error)
return None
self._next_snapshot_at = now + self._time_between_snapshots
self._last_image = response.content
return self._last_image | [
"def",
"camera_image",
"(",
"self",
")",
":",
"now",
"=",
"utcnow",
"(",
")",
"if",
"self",
".",
"_ready_for_snapshot",
"(",
"now",
")",
":",
"url",
"=",
"self",
".",
"device",
".",
"snapshot_url",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
")",
"except",
"requests",
".",
"exceptions",
".",
"RequestException",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error getting camera image: %s\"",
",",
"error",
")",
"return",
"None",
"self",
".",
"_next_snapshot_at",
"=",
"now",
"+",
"self",
".",
"_time_between_snapshots",
"self",
".",
"_last_image",
"=",
"response",
".",
"content",
"return",
"self",
".",
"_last_image"
] | [
134,
4
] | [
149,
31
] | python | en | ['en', 'en', 'en'] | True |
run | (args) | Handle benchmark commandline script. | Handle benchmark commandline script. | def run(args):
"""Handle benchmark commandline script."""
# Disable logging
logging.getLogger("homeassistant.core").setLevel(logging.CRITICAL)
parser = argparse.ArgumentParser(description=("Run a Home Assistant benchmark."))
parser.add_argument("name", choices=BENCHMARKS)
parser.add_argument("--script", choices=["benchmark"])
args = parser.parse_args()
bench = BENCHMARKS[args.name]
print("Using event loop:", asyncio.get_event_loop_policy().loop_name)
with suppress(KeyboardInterrupt):
while True:
asyncio.run(run_benchmark(bench)) | [
"def",
"run",
"(",
"args",
")",
":",
"# Disable logging",
"logging",
".",
"getLogger",
"(",
"\"homeassistant.core\"",
")",
".",
"setLevel",
"(",
"logging",
".",
"CRITICAL",
")",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"(",
"\"Run a Home Assistant benchmark.\"",
")",
")",
"parser",
".",
"add_argument",
"(",
"\"name\"",
",",
"choices",
"=",
"BENCHMARKS",
")",
"parser",
".",
"add_argument",
"(",
"\"--script\"",
",",
"choices",
"=",
"[",
"\"benchmark\"",
"]",
")",
"args",
"=",
"parser",
".",
"parse_args",
"(",
")",
"bench",
"=",
"BENCHMARKS",
"[",
"args",
".",
"name",
"]",
"print",
"(",
"\"Using event loop:\"",
",",
"asyncio",
".",
"get_event_loop_policy",
"(",
")",
".",
"loop_name",
")",
"with",
"suppress",
"(",
"KeyboardInterrupt",
")",
":",
"while",
"True",
":",
"asyncio",
".",
"run",
"(",
"run_benchmark",
"(",
"bench",
")",
")"
] | [
26,
0
] | [
42,
45
] | python | de | ['de', 'nl', 'en'] | False |
run_benchmark | (bench) | Run a benchmark. | Run a benchmark. | async def run_benchmark(bench):
"""Run a benchmark."""
hass = core.HomeAssistant()
runtime = await bench(hass)
print(f"Benchmark {bench.__name__} done in {runtime}s")
await hass.async_stop() | [
"async",
"def",
"run_benchmark",
"(",
"bench",
")",
":",
"hass",
"=",
"core",
".",
"HomeAssistant",
"(",
")",
"runtime",
"=",
"await",
"bench",
"(",
"hass",
")",
"print",
"(",
"f\"Benchmark {bench.__name__} done in {runtime}s\"",
")",
"await",
"hass",
".",
"async_stop",
"(",
")"
] | [
45,
0
] | [
50,
27
] | python | en | ['it', 'gl', 'en'] | False |
benchmark | (func: CALLABLE_T) | Decorate to mark a benchmark. | Decorate to mark a benchmark. | def benchmark(func: CALLABLE_T) -> CALLABLE_T:
"""Decorate to mark a benchmark."""
BENCHMARKS[func.__name__] = func
return func | [
"def",
"benchmark",
"(",
"func",
":",
"CALLABLE_T",
")",
"->",
"CALLABLE_T",
":",
"BENCHMARKS",
"[",
"func",
".",
"__name__",
"]",
"=",
"func",
"return",
"func"
] | [
53,
0
] | [
56,
15
] | python | en | ['en', 'en', 'en'] | True |
fire_events | (hass) | Fire a million events. | Fire a million events. | async def fire_events(hass):
"""Fire a million events."""
count = 0
event_name = "benchmark_event"
event = asyncio.Event()
@core.callback
def listener(_):
"""Handle event."""
nonlocal count
count += 1
if count == 10 ** 6:
event.set()
hass.bus.async_listen(event_name, listener)
for _ in range(10 ** 6):
hass.bus.async_fire(event_name)
start = timer()
await event.wait()
return timer() - start | [
"async",
"def",
"fire_events",
"(",
"hass",
")",
":",
"count",
"=",
"0",
"event_name",
"=",
"\"benchmark_event\"",
"event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"@",
"core",
".",
"callback",
"def",
"listener",
"(",
"_",
")",
":",
"\"\"\"Handle event.\"\"\"",
"nonlocal",
"count",
"count",
"+=",
"1",
"if",
"count",
"==",
"10",
"**",
"6",
":",
"event",
".",
"set",
"(",
")",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"event_name",
",",
"listener",
")",
"for",
"_",
"in",
"range",
"(",
"10",
"**",
"6",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"event_name",
")",
"start",
"=",
"timer",
"(",
")",
"await",
"event",
".",
"wait",
"(",
")",
"return",
"timer",
"(",
")",
"-",
"start"
] | [
60,
0
] | [
84,
26
] | python | en | ['fr', 'en', 'en'] | True |
time_changed_helper | (hass) | Run a million events through time changed helper. | Run a million events through time changed helper. | async def time_changed_helper(hass):
"""Run a million events through time changed helper."""
count = 0
event = asyncio.Event()
@core.callback
def listener(_):
"""Handle event."""
nonlocal count
count += 1
if count == 10 ** 6:
event.set()
hass.helpers.event.async_track_time_change(listener, minute=0, second=0)
event_data = {ATTR_NOW: datetime(2017, 10, 10, 15, 0, 0, tzinfo=dt_util.UTC)}
for _ in range(10 ** 6):
hass.bus.async_fire(EVENT_TIME_CHANGED, event_data)
start = timer()
await event.wait()
return timer() - start | [
"async",
"def",
"time_changed_helper",
"(",
"hass",
")",
":",
"count",
"=",
"0",
"event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"@",
"core",
".",
"callback",
"def",
"listener",
"(",
"_",
")",
":",
"\"\"\"Handle event.\"\"\"",
"nonlocal",
"count",
"count",
"+=",
"1",
"if",
"count",
"==",
"10",
"**",
"6",
":",
"event",
".",
"set",
"(",
")",
"hass",
".",
"helpers",
".",
"event",
".",
"async_track_time_change",
"(",
"listener",
",",
"minute",
"=",
"0",
",",
"second",
"=",
"0",
")",
"event_data",
"=",
"{",
"ATTR_NOW",
":",
"datetime",
"(",
"2017",
",",
"10",
",",
"10",
",",
"15",
",",
"0",
",",
"0",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"}",
"for",
"_",
"in",
"range",
"(",
"10",
"**",
"6",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_TIME_CHANGED",
",",
"event_data",
")",
"start",
"=",
"timer",
"(",
")",
"await",
"event",
".",
"wait",
"(",
")",
"return",
"timer",
"(",
")",
"-",
"start"
] | [
88,
0
] | [
112,
26
] | python | en | ['en', 'gd', 'en'] | True |
state_changed_helper | (hass) | Run a million events through state changed helper with 1000 entities. | Run a million events through state changed helper with 1000 entities. | async def state_changed_helper(hass):
"""Run a million events through state changed helper with 1000 entities."""
count = 0
entity_id = "light.kitchen"
event = asyncio.Event()
@core.callback
def listener(*args):
"""Handle event."""
nonlocal count
count += 1
if count == 10 ** 6:
event.set()
for idx in range(1000):
hass.helpers.event.async_track_state_change(
f"{entity_id}{idx}", listener, "off", "on"
)
event_data = {
"entity_id": f"{entity_id}0",
"old_state": core.State(entity_id, "off"),
"new_state": core.State(entity_id, "on"),
}
for _ in range(10 ** 6):
hass.bus.async_fire(EVENT_STATE_CHANGED, event_data)
start = timer()
await event.wait()
return timer() - start | [
"async",
"def",
"state_changed_helper",
"(",
"hass",
")",
":",
"count",
"=",
"0",
"entity_id",
"=",
"\"light.kitchen\"",
"event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"@",
"core",
".",
"callback",
"def",
"listener",
"(",
"*",
"args",
")",
":",
"\"\"\"Handle event.\"\"\"",
"nonlocal",
"count",
"count",
"+=",
"1",
"if",
"count",
"==",
"10",
"**",
"6",
":",
"event",
".",
"set",
"(",
")",
"for",
"idx",
"in",
"range",
"(",
"1000",
")",
":",
"hass",
".",
"helpers",
".",
"event",
".",
"async_track_state_change",
"(",
"f\"{entity_id}{idx}\"",
",",
"listener",
",",
"\"off\"",
",",
"\"on\"",
")",
"event_data",
"=",
"{",
"\"entity_id\"",
":",
"f\"{entity_id}0\"",
",",
"\"old_state\"",
":",
"core",
".",
"State",
"(",
"entity_id",
",",
"\"off\"",
")",
",",
"\"new_state\"",
":",
"core",
".",
"State",
"(",
"entity_id",
",",
"\"on\"",
")",
",",
"}",
"for",
"_",
"in",
"range",
"(",
"10",
"**",
"6",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_STATE_CHANGED",
",",
"event_data",
")",
"start",
"=",
"timer",
"(",
")",
"await",
"event",
".",
"wait",
"(",
")",
"return",
"timer",
"(",
")",
"-",
"start"
] | [
116,
0
] | [
148,
26
] | python | en | ['en', 'en', 'en'] | True |
state_changed_event_helper | (hass) | Run a million events through state changed event helper with 1000 entities. | Run a million events through state changed event helper with 1000 entities. | async def state_changed_event_helper(hass):
"""Run a million events through state changed event helper with 1000 entities."""
count = 0
entity_id = "light.kitchen"
event = asyncio.Event()
@core.callback
def listener(*args):
"""Handle event."""
nonlocal count
count += 1
if count == 10 ** 6:
event.set()
hass.helpers.event.async_track_state_change_event(
[f"{entity_id}{idx}" for idx in range(1000)], listener
)
event_data = {
"entity_id": f"{entity_id}0",
"old_state": core.State(entity_id, "off"),
"new_state": core.State(entity_id, "on"),
}
for _ in range(10 ** 6):
hass.bus.async_fire(EVENT_STATE_CHANGED, event_data)
start = timer()
await event.wait()
return timer() - start | [
"async",
"def",
"state_changed_event_helper",
"(",
"hass",
")",
":",
"count",
"=",
"0",
"entity_id",
"=",
"\"light.kitchen\"",
"event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"@",
"core",
".",
"callback",
"def",
"listener",
"(",
"*",
"args",
")",
":",
"\"\"\"Handle event.\"\"\"",
"nonlocal",
"count",
"count",
"+=",
"1",
"if",
"count",
"==",
"10",
"**",
"6",
":",
"event",
".",
"set",
"(",
")",
"hass",
".",
"helpers",
".",
"event",
".",
"async_track_state_change_event",
"(",
"[",
"f\"{entity_id}{idx}\"",
"for",
"idx",
"in",
"range",
"(",
"1000",
")",
"]",
",",
"listener",
")",
"event_data",
"=",
"{",
"\"entity_id\"",
":",
"f\"{entity_id}0\"",
",",
"\"old_state\"",
":",
"core",
".",
"State",
"(",
"entity_id",
",",
"\"off\"",
")",
",",
"\"new_state\"",
":",
"core",
".",
"State",
"(",
"entity_id",
",",
"\"on\"",
")",
",",
"}",
"for",
"_",
"in",
"range",
"(",
"10",
"**",
"6",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_STATE_CHANGED",
",",
"event_data",
")",
"start",
"=",
"timer",
"(",
")",
"await",
"event",
".",
"wait",
"(",
")",
"return",
"timer",
"(",
")",
"-",
"start"
] | [
152,
0
] | [
184,
26
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.