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_template | (hass) | Test a configuration using a complex template. | Test a configuration using a complex template. | async def test_template(hass):
"""Test a configuration using a complex template."""
config = CONFIG_FAN[DOMAIN][CONF_ENTITIES]
assert await async_setup_component(
hass, FAN_DOMAIN, {FAN_DOMAIN: {"platform": "demo"}}
)
with patch(
"sense_energy.SenseLink",
return_value=Mock(start=AsyncMock(), close=AsyncMock()),
):
assert await async_setup_component(hass, DOMAIN, CONFIG_FAN) is True
await hass.async_block_till_done()
await emulated_kasa.validate_configs(hass, config)
# Turn all devices on to known state
await hass.services.async_call(
FAN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_FAN}, blocking=True
)
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_SET_SPEED,
{ATTR_ENTITY_ID: ENTITY_FAN, ATTR_SPEED: "low"},
blocking=True,
)
fan = hass.states.get(ENTITY_FAN)
assert fan.state == STATE_ON
# Fan low:
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_FAN_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, ENTITY_FAN_SPEED_LOW)
# Fan High:
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_SET_SPEED,
{ATTR_ENTITY_ID: ENTITY_FAN, ATTR_SPEED: "high"},
blocking=True,
)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_FAN_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, ENTITY_FAN_SPEED_HIGH)
# Fan off:
await hass.services.async_call(
FAN_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_FAN}, blocking=True
)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_FAN_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 0) | [
"async",
"def",
"test_template",
"(",
"hass",
")",
":",
"config",
"=",
"CONFIG_FAN",
"[",
"DOMAIN",
"]",
"[",
"CONF_ENTITIES",
"]",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"{",
"FAN_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
")",
"with",
"patch",
"(",
"\"sense_energy.SenseLink\"",
",",
"return_value",
"=",
"Mock",
"(",
"start",
"=",
"AsyncMock",
"(",
")",
",",
"close",
"=",
"AsyncMock",
"(",
")",
")",
",",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"CONFIG_FAN",
")",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"emulated_kasa",
".",
"validate_configs",
"(",
"hass",
",",
"config",
")",
"# Turn all devices on to known state",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
"}",
",",
"blocking",
"=",
"True",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_SET_SPEED",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
",",
"ATTR_SPEED",
":",
"\"low\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"fan",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_FAN",
")",
"assert",
"fan",
".",
"state",
"==",
"STATE_ON",
"# Fan low:",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_FAN_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"ENTITY_FAN_SPEED_LOW",
")",
"# Fan High:",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_SET_SPEED",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
",",
"ATTR_SPEED",
":",
"\"high\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_FAN_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"ENTITY_FAN_SPEED_HIGH",
")",
"# Fan off:",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
"}",
",",
"blocking",
"=",
"True",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_FAN_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"0",
")"
] | [
258,
0
] | [
314,
33
] | python | en | ['en', 'en', 'en'] | True |
test_sensor | (hass) | Test a configuration using a sensor in a template. | Test a configuration using a sensor in a template. | async def test_sensor(hass):
"""Test a configuration using a sensor in a template."""
config = CONFIG_LIGHT[DOMAIN][CONF_ENTITIES]
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": "demo"}}
)
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{SENSOR_DOMAIN: {"platform": "demo"}},
)
with patch(
"sense_energy.SenseLink",
return_value=Mock(start=AsyncMock(), close=AsyncMock()),
):
assert await async_setup_component(hass, DOMAIN, CONFIG_LIGHT) is True
await hass.async_block_till_done()
await emulated_kasa.validate_configs(hass, config)
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
hass.states.async_set(ENTITY_SENSOR, 35)
light = hass.states.get(ENTITY_LIGHT)
assert light.state == STATE_ON
sensor = hass.states.get(ENTITY_SENSOR)
assert sensor.state == "35"
# light
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_LIGHT_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 35)
# change power sensor
hass.states.async_set(ENTITY_SENSOR, 40)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_LIGHT_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 40)
# report 0 if device is off
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_LIGHT_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 0) | [
"async",
"def",
"test_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"CONFIG_LIGHT",
"[",
"DOMAIN",
"]",
"[",
"CONF_ENTITIES",
"]",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"{",
"LIGHT_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"SENSOR_DOMAIN",
",",
"{",
"SENSOR_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
",",
")",
"with",
"patch",
"(",
"\"sense_energy.SenseLink\"",
",",
"return_value",
"=",
"Mock",
"(",
"start",
"=",
"AsyncMock",
"(",
")",
",",
"close",
"=",
"AsyncMock",
"(",
")",
")",
",",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"CONFIG_LIGHT",
")",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"emulated_kasa",
".",
"validate_configs",
"(",
"hass",
",",
"config",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
"}",
",",
"blocking",
"=",
"True",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"35",
")",
"light",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"light",
".",
"state",
"==",
"STATE_ON",
"sensor",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_SENSOR",
")",
"assert",
"sensor",
".",
"state",
"==",
"\"35\"",
"# light",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_LIGHT_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"35",
")",
"# change power sensor",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"40",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_LIGHT_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"40",
")",
"# report 0 if device is off",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
"}",
",",
"blocking",
"=",
"True",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_LIGHT_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"0",
")"
] | [
317,
0
] | [
371,
33
] | python | en | ['en', 'en', 'en'] | True |
test_sensor_state | (hass) | Test a configuration using a sensor in a template. | Test a configuration using a sensor in a template. | async def test_sensor_state(hass):
"""Test a configuration using a sensor in a template."""
config = CONFIG_SENSOR[DOMAIN][CONF_ENTITIES]
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{SENSOR_DOMAIN: {"platform": "demo"}},
)
with patch(
"sense_energy.SenseLink",
return_value=Mock(start=AsyncMock(), close=AsyncMock()),
):
assert await async_setup_component(hass, DOMAIN, CONFIG_SENSOR) is True
await hass.async_block_till_done()
await emulated_kasa.validate_configs(hass, config)
hass.states.async_set(ENTITY_SENSOR, 35)
sensor = hass.states.get(ENTITY_SENSOR)
assert sensor.state == "35"
# sensor
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_SENSOR_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 35)
# change power sensor
hass.states.async_set(ENTITY_SENSOR, 40)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_SENSOR_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 40)
# report 0 if device is off
hass.states.async_set(ENTITY_SENSOR, 0)
plug_it = emulated_kasa.get_plug_devices(hass, config)
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_SENSOR_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 0) | [
"async",
"def",
"test_sensor_state",
"(",
"hass",
")",
":",
"config",
"=",
"CONFIG_SENSOR",
"[",
"DOMAIN",
"]",
"[",
"CONF_ENTITIES",
"]",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"SENSOR_DOMAIN",
",",
"{",
"SENSOR_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
",",
")",
"with",
"patch",
"(",
"\"sense_energy.SenseLink\"",
",",
"return_value",
"=",
"Mock",
"(",
"start",
"=",
"AsyncMock",
"(",
")",
",",
"close",
"=",
"AsyncMock",
"(",
")",
")",
",",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"CONFIG_SENSOR",
")",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"emulated_kasa",
".",
"validate_configs",
"(",
"hass",
",",
"config",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"35",
")",
"sensor",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_SENSOR",
")",
"assert",
"sensor",
".",
"state",
"==",
"\"35\"",
"# sensor",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_SENSOR_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"35",
")",
"# change power sensor",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"40",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_SENSOR_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"40",
")",
"# report 0 if device is off",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"0",
")",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_SENSOR_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"0",
")"
] | [
374,
0
] | [
418,
33
] | python | en | ['en', 'en', 'en'] | True |
test_multiple_devices | (hass) | Test that devices are reported correctly. | Test that devices are reported correctly. | async def test_multiple_devices(hass):
"""Test that devices are reported correctly."""
config = CONFIG[DOMAIN][CONF_ENTITIES]
assert await async_setup_component(
hass, SWITCH_DOMAIN, {SWITCH_DOMAIN: {"platform": "demo"}}
)
assert await async_setup_component(
hass, LIGHT_DOMAIN, {LIGHT_DOMAIN: {"platform": "demo"}}
)
assert await async_setup_component(
hass, FAN_DOMAIN, {FAN_DOMAIN: {"platform": "demo"}}
)
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{SENSOR_DOMAIN: {"platform": "demo"}},
)
with patch(
"sense_energy.SenseLink",
return_value=Mock(start=AsyncMock(), close=AsyncMock()),
):
assert await emulated_kasa.async_setup(hass, CONFIG) is True
await hass.async_block_till_done()
await emulated_kasa.validate_configs(hass, config)
# Turn all devices on to known state
await hass.services.async_call(
SWITCH_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_SWITCH}, blocking=True
)
await hass.services.async_call(
LIGHT_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_LIGHT}, blocking=True
)
hass.states.async_set(ENTITY_SENSOR, 35)
await hass.services.async_call(
FAN_DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: ENTITY_FAN}, blocking=True
)
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_SET_SPEED,
{ATTR_ENTITY_ID: ENTITY_FAN, ATTR_SPEED: "medium"},
blocking=True,
)
# All of them should now be on
switch = hass.states.get(ENTITY_SWITCH)
assert switch.state == STATE_ON
light = hass.states.get(ENTITY_LIGHT)
assert light.state == STATE_ON
sensor = hass.states.get(ENTITY_SENSOR)
assert sensor.state == "35"
fan = hass.states.get(ENTITY_FAN)
assert fan.state == STATE_ON
plug_it = emulated_kasa.get_plug_devices(hass, config)
# switch
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_SWITCH_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, ENTITY_SWITCH_POWER)
# light
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_LIGHT_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, 35)
# fan
plug = next(plug_it).generate_response()
assert nested_value(plug, "system", "get_sysinfo", "alias") == ENTITY_FAN_NAME
power = nested_value(plug, "emeter", "get_realtime", "power")
assert math.isclose(power, ENTITY_FAN_SPEED_MED)
# No more devices
assert next(plug_it, None) is None | [
"async",
"def",
"test_multiple_devices",
"(",
"hass",
")",
":",
"config",
"=",
"CONFIG",
"[",
"DOMAIN",
"]",
"[",
"CONF_ENTITIES",
"]",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"SWITCH_DOMAIN",
",",
"{",
"SWITCH_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"{",
"LIGHT_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"{",
"FAN_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"SENSOR_DOMAIN",
",",
"{",
"SENSOR_DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"demo\"",
"}",
"}",
",",
")",
"with",
"patch",
"(",
"\"sense_energy.SenseLink\"",
",",
"return_value",
"=",
"Mock",
"(",
"start",
"=",
"AsyncMock",
"(",
")",
",",
"close",
"=",
"AsyncMock",
"(",
")",
")",
",",
")",
":",
"assert",
"await",
"emulated_kasa",
".",
"async_setup",
"(",
"hass",
",",
"CONFIG",
")",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"emulated_kasa",
".",
"validate_configs",
"(",
"hass",
",",
"config",
")",
"# Turn all devices on to known state",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"SWITCH_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_SWITCH",
"}",
",",
"blocking",
"=",
"True",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"LIGHT_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_LIGHT",
"}",
",",
"blocking",
"=",
"True",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"ENTITY_SENSOR",
",",
"35",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
"}",
",",
"blocking",
"=",
"True",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"FAN_DOMAIN",
",",
"SERVICE_SET_SPEED",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_FAN",
",",
"ATTR_SPEED",
":",
"\"medium\"",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"# All of them should now be on",
"switch",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_SWITCH",
")",
"assert",
"switch",
".",
"state",
"==",
"STATE_ON",
"light",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_LIGHT",
")",
"assert",
"light",
".",
"state",
"==",
"STATE_ON",
"sensor",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_SENSOR",
")",
"assert",
"sensor",
".",
"state",
"==",
"\"35\"",
"fan",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_FAN",
")",
"assert",
"fan",
".",
"state",
"==",
"STATE_ON",
"plug_it",
"=",
"emulated_kasa",
".",
"get_plug_devices",
"(",
"hass",
",",
"config",
")",
"# switch",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_SWITCH_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"ENTITY_SWITCH_POWER",
")",
"# light",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_LIGHT_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"35",
")",
"# fan",
"plug",
"=",
"next",
"(",
"plug_it",
")",
".",
"generate_response",
"(",
")",
"assert",
"nested_value",
"(",
"plug",
",",
"\"system\"",
",",
"\"get_sysinfo\"",
",",
"\"alias\"",
")",
"==",
"ENTITY_FAN_NAME",
"power",
"=",
"nested_value",
"(",
"plug",
",",
"\"emeter\"",
",",
"\"get_realtime\"",
",",
"\"power\"",
")",
"assert",
"math",
".",
"isclose",
"(",
"power",
",",
"ENTITY_FAN_SPEED_MED",
")",
"# No more devices",
"assert",
"next",
"(",
"plug_it",
",",
"None",
")",
"is",
"None"
] | [
421,
0
] | [
494,
38
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up sensors for device. | Set up sensors for device. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up sensors for device."""
await async_setup_entry_attribute_entities(
hass, config_entry, async_add_entities, SENSORS, ShellySensor
)
await async_setup_entry_rest(
hass, config_entry, async_add_entities, REST_SENSORS, ShellyRestSensor
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"await",
"async_setup_entry_attribute_entities",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
",",
"SENSORS",
",",
"ShellySensor",
")",
"await",
"async_setup_entry_rest",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
",",
"REST_SENSORS",
",",
"ShellyRestSensor",
")"
] | [
179,
0
] | [
186,
5
] | python | en | ['en', 'en', 'en'] | True |
ShellySensor.state | (self) | Return value of sensor. | Return value of sensor. | def state(self):
"""Return value of sensor."""
return self.attribute_value | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"attribute_value"
] | [
193,
4
] | [
195,
35
] | python | en | ['en', 'no', 'en'] | True |
ShellyRestSensor.state | (self) | Return value of sensor. | Return value of sensor. | def state(self):
"""Return value of sensor."""
return self.attribute_value | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"attribute_value"
] | [
202,
4
] | [
204,
35
] | python | en | ['en', 'no', 'en'] | True |
gdacs_setup_fixture | () | Mock gdacs entry setup. | Mock gdacs entry setup. | def gdacs_setup_fixture():
"""Mock gdacs entry setup."""
with patch("homeassistant.components.gdacs.async_setup_entry", return_value=True):
yield | [
"def",
"gdacs_setup_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.gdacs.async_setup_entry\"",
",",
"return_value",
"=",
"True",
")",
":",
"yield"
] | [
18,
0
] | [
21,
13
] | python | en | ['en', 'st', 'en'] | True |
test_duplicate_error | (hass, config_entry) | Test that errors are shown when duplicates are added. | Test that errors are shown when duplicates are added. | async def test_duplicate_error(hass, config_entry):
"""Test that errors are shown when duplicates are added."""
conf = {CONF_LATITUDE: -41.2, CONF_LONGITUDE: 174.7, CONF_RADIUS: 25}
config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}, data=conf
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "already_configured" | [
"async",
"def",
"test_duplicate_error",
"(",
"hass",
",",
"config_entry",
")",
":",
"conf",
"=",
"{",
"CONF_LATITUDE",
":",
"-",
"41.2",
",",
"CONF_LONGITUDE",
":",
"174.7",
",",
"CONF_RADIUS",
":",
"25",
"}",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"conf",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\""
] | [
24,
0
] | [
33,
51
] | python | en | ['en', 'en', 'en'] | True |
test_show_form | (hass) | Test that the form is served with no input. | Test that the form is served with no input. | async def test_show_form(hass):
"""Test that the form is served with no input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user" | [
"async",
"def",
"test_show_form",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\""
] | [
36,
0
] | [
42,
38
] | python | en | ['en', 'en', 'en'] | True |
test_step_import | (hass) | Test that the import step works. | Test that the import step works. | async def test_step_import(hass):
"""Test that the import step works."""
conf = {
CONF_LATITUDE: -41.2,
CONF_LONGITUDE: 174.7,
CONF_RADIUS: 25,
CONF_SCAN_INTERVAL: timedelta(minutes=4),
CONF_CATEGORIES: ["Drought", "Earthquake"],
}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "import"}, data=conf
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "-41.2, 174.7"
assert result["data"] == {
CONF_LATITUDE: -41.2,
CONF_LONGITUDE: 174.7,
CONF_RADIUS: 25,
CONF_SCAN_INTERVAL: 240.0,
CONF_CATEGORIES: ["Drought", "Earthquake"],
} | [
"async",
"def",
"test_step_import",
"(",
"hass",
")",
":",
"conf",
"=",
"{",
"CONF_LATITUDE",
":",
"-",
"41.2",
",",
"CONF_LONGITUDE",
":",
"174.7",
",",
"CONF_RADIUS",
":",
"25",
",",
"CONF_SCAN_INTERVAL",
":",
"timedelta",
"(",
"minutes",
"=",
"4",
")",
",",
"CONF_CATEGORIES",
":",
"[",
"\"Drought\"",
",",
"\"Earthquake\"",
"]",
",",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"import\"",
"}",
",",
"data",
"=",
"conf",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"-41.2, 174.7\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_LATITUDE",
":",
"-",
"41.2",
",",
"CONF_LONGITUDE",
":",
"174.7",
",",
"CONF_RADIUS",
":",
"25",
",",
"CONF_SCAN_INTERVAL",
":",
"240.0",
",",
"CONF_CATEGORIES",
":",
"[",
"\"Drought\"",
",",
"\"Earthquake\"",
"]",
",",
"}"
] | [
45,
0
] | [
66,
5
] | python | en | ['en', 'en', 'en'] | True |
test_step_user | (hass) | Test that the user step works. | Test that the user step works. | async def test_step_user(hass):
"""Test that the user step works."""
hass.config.latitude = -41.2
hass.config.longitude = 174.7
conf = {CONF_RADIUS: 25}
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}, data=conf
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "-41.2, 174.7"
assert result["data"] == {
CONF_LATITUDE: -41.2,
CONF_LONGITUDE: 174.7,
CONF_RADIUS: 25,
CONF_SCAN_INTERVAL: 300.0,
CONF_CATEGORIES: [],
} | [
"async",
"def",
"test_step_user",
"(",
"hass",
")",
":",
"hass",
".",
"config",
".",
"latitude",
"=",
"-",
"41.2",
"hass",
".",
"config",
".",
"longitude",
"=",
"174.7",
"conf",
"=",
"{",
"CONF_RADIUS",
":",
"25",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"conf",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"-41.2, 174.7\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_LATITUDE",
":",
"-",
"41.2",
",",
"CONF_LONGITUDE",
":",
"174.7",
",",
"CONF_RADIUS",
":",
"25",
",",
"CONF_SCAN_INTERVAL",
":",
"300.0",
",",
"CONF_CATEGORIES",
":",
"[",
"]",
",",
"}"
] | [
69,
0
] | [
86,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistant, config: ConfigType) | Set up the Spotify integration. | Set up the Spotify integration. | async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the Spotify integration."""
if DOMAIN not in config:
return True
if CONF_CLIENT_ID in config[DOMAIN]:
config_flow.SpotifyFlowHandler.async_register_implementation(
hass,
config_entry_oauth2_flow.LocalOAuth2Implementation(
hass,
DOMAIN,
config[DOMAIN][CONF_CLIENT_ID],
config[DOMAIN][CONF_CLIENT_SECRET],
"https://accounts.spotify.com/authorize",
"https://accounts.spotify.com/api/token",
),
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"if",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"True",
"if",
"CONF_CLIENT_ID",
"in",
"config",
"[",
"DOMAIN",
"]",
":",
"config_flow",
".",
"SpotifyFlowHandler",
".",
"async_register_implementation",
"(",
"hass",
",",
"config_entry_oauth2_flow",
".",
"LocalOAuth2Implementation",
"(",
"hass",
",",
"DOMAIN",
",",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_CLIENT_ID",
"]",
",",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_CLIENT_SECRET",
"]",
",",
"\"https://accounts.spotify.com/authorize\"",
",",
"\"https://accounts.spotify.com/api/token\"",
",",
")",
",",
")",
"return",
"True"
] | [
39,
0
] | [
57,
15
] | python | en | ['en', 'cs', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up Spotify from a config entry. | Set up Spotify from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Spotify from a config entry."""
implementation = await async_get_config_entry_implementation(hass, entry)
session = OAuth2Session(hass, entry, implementation)
await session.async_ensure_token_valid()
spotify = Spotify(auth=session.token["access_token"])
try:
current_user = await hass.async_add_executor_job(spotify.me)
except SpotifyException as err:
raise ConfigEntryNotReady from err
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = {
DATA_SPOTIFY_CLIENT: spotify,
DATA_SPOTIFY_ME: current_user,
DATA_SPOTIFY_SESSION: session,
}
if not set(session.token["scope"].split(" ")).issuperset(SPOTIFY_SCOPES):
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": "reauth"},
data=entry.data,
)
)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, MEDIA_PLAYER_DOMAIN)
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"implementation",
"=",
"await",
"async_get_config_entry_implementation",
"(",
"hass",
",",
"entry",
")",
"session",
"=",
"OAuth2Session",
"(",
"hass",
",",
"entry",
",",
"implementation",
")",
"await",
"session",
".",
"async_ensure_token_valid",
"(",
")",
"spotify",
"=",
"Spotify",
"(",
"auth",
"=",
"session",
".",
"token",
"[",
"\"access_token\"",
"]",
")",
"try",
":",
"current_user",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"spotify",
".",
"me",
")",
"except",
"SpotifyException",
"as",
"err",
":",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"=",
"{",
"DATA_SPOTIFY_CLIENT",
":",
"spotify",
",",
"DATA_SPOTIFY_ME",
":",
"current_user",
",",
"DATA_SPOTIFY_SESSION",
":",
"session",
",",
"}",
"if",
"not",
"set",
"(",
"session",
".",
"token",
"[",
"\"scope\"",
"]",
".",
"split",
"(",
"\" \"",
")",
")",
".",
"issuperset",
"(",
"SPOTIFY_SCOPES",
")",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"reauth\"",
"}",
",",
"data",
"=",
"entry",
".",
"data",
",",
")",
")",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"MEDIA_PLAYER_DOMAIN",
")",
")",
"return",
"True"
] | [
60,
0
] | [
91,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload Spotify config entry. | Unload Spotify config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload Spotify config entry."""
# Unload entities for this entry/device.
await hass.config_entries.async_forward_entry_unload(entry, MEDIA_PLAYER_DOMAIN)
# Cleanup
del hass.data[DOMAIN][entry.entry_id]
if not hass.data[DOMAIN]:
del hass.data[DOMAIN]
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"# Unload entities for this entry/device.",
"await",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"MEDIA_PLAYER_DOMAIN",
")",
"# Cleanup",
"del",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"if",
"not",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"del",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"return",
"True"
] | [
94,
0
] | [
104,
15
] | python | en | ['da', 'en', 'en'] | True |
test_invalid_path_setup | (hass) | Test that an invalid path is not set up. | Test that an invalid path is not set up. | async def test_invalid_path_setup(hass):
"""Test that an invalid path is not set up."""
assert not await async_setup_component(
hass,
folder_watcher.DOMAIN,
{folder_watcher.DOMAIN: {folder_watcher.CONF_FOLDER: "invalid_path"}},
) | [
"async",
"def",
"test_invalid_path_setup",
"(",
"hass",
")",
":",
"assert",
"not",
"await",
"async_setup_component",
"(",
"hass",
",",
"folder_watcher",
".",
"DOMAIN",
",",
"{",
"folder_watcher",
".",
"DOMAIN",
":",
"{",
"folder_watcher",
".",
"CONF_FOLDER",
":",
"\"invalid_path\"",
"}",
"}",
",",
")"
] | [
9,
0
] | [
15,
5
] | python | en | ['en', 'en', 'en'] | True |
test_valid_path_setup | (hass) | Test that a valid path is setup. | Test that a valid path is setup. | async def test_valid_path_setup(hass):
"""Test that a valid path is setup."""
cwd = os.path.join(os.path.dirname(__file__))
hass.config.allowlist_external_dirs = {cwd}
with patch.object(folder_watcher, "Watcher"):
assert await async_setup_component(
hass,
folder_watcher.DOMAIN,
{folder_watcher.DOMAIN: {folder_watcher.CONF_FOLDER: cwd}},
) | [
"async",
"def",
"test_valid_path_setup",
"(",
"hass",
")",
":",
"cwd",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"hass",
".",
"config",
".",
"allowlist_external_dirs",
"=",
"{",
"cwd",
"}",
"with",
"patch",
".",
"object",
"(",
"folder_watcher",
",",
"\"Watcher\"",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"folder_watcher",
".",
"DOMAIN",
",",
"{",
"folder_watcher",
".",
"DOMAIN",
":",
"{",
"folder_watcher",
".",
"CONF_FOLDER",
":",
"cwd",
"}",
"}",
",",
")"
] | [
18,
0
] | [
27,
9
] | python | en | ['en', 'en', 'en'] | True |
test_event | () | Check that Home Assistant events are fired correctly on watchdog event. | Check that Home Assistant events are fired correctly on watchdog event. | def test_event():
"""Check that Home Assistant events are fired correctly on watchdog event."""
class MockPatternMatchingEventHandler:
"""Mock base class for the pattern matcher event handler."""
def __init__(self, patterns):
pass
with patch(
"homeassistant.components.folder_watcher.PatternMatchingEventHandler",
MockPatternMatchingEventHandler,
):
hass = Mock()
handler = folder_watcher.create_event_handler(["*"], hass)
handler.on_created(
Mock(is_directory=False, src_path="/hello/world.txt", event_type="created")
)
assert hass.bus.fire.called
assert hass.bus.fire.mock_calls[0][1][0] == folder_watcher.DOMAIN
assert hass.bus.fire.mock_calls[0][1][1] == {
"event_type": "created",
"path": "/hello/world.txt",
"file": "world.txt",
"folder": "/hello",
} | [
"def",
"test_event",
"(",
")",
":",
"class",
"MockPatternMatchingEventHandler",
":",
"\"\"\"Mock base class for the pattern matcher event handler.\"\"\"",
"def",
"__init__",
"(",
"self",
",",
"patterns",
")",
":",
"pass",
"with",
"patch",
"(",
"\"homeassistant.components.folder_watcher.PatternMatchingEventHandler\"",
",",
"MockPatternMatchingEventHandler",
",",
")",
":",
"hass",
"=",
"Mock",
"(",
")",
"handler",
"=",
"folder_watcher",
".",
"create_event_handler",
"(",
"[",
"\"*\"",
"]",
",",
"hass",
")",
"handler",
".",
"on_created",
"(",
"Mock",
"(",
"is_directory",
"=",
"False",
",",
"src_path",
"=",
"\"/hello/world.txt\"",
",",
"event_type",
"=",
"\"created\"",
")",
")",
"assert",
"hass",
".",
"bus",
".",
"fire",
".",
"called",
"assert",
"hass",
".",
"bus",
".",
"fire",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"0",
"]",
"==",
"folder_watcher",
".",
"DOMAIN",
"assert",
"hass",
".",
"bus",
".",
"fire",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"1",
"]",
"==",
"{",
"\"event_type\"",
":",
"\"created\"",
",",
"\"path\"",
":",
"\"/hello/world.txt\"",
",",
"\"file\"",
":",
"\"world.txt\"",
",",
"\"folder\"",
":",
"\"/hello\"",
",",
"}"
] | [
30,
0
] | [
55,
9
] | python | en | ['en', 'en', 'en'] | True |
turn_on | (hass, entity_id=ENTITY_MATCH_ALL) | Turn all or specified switch on. | Turn all or specified switch on. | def turn_on(hass, entity_id=ENTITY_MATCH_ALL):
"""Turn all or specified switch on."""
hass.add_job(async_turn_on, hass, entity_id) | [
"def",
"turn_on",
"(",
"hass",
",",
"entity_id",
"=",
"ENTITY_MATCH_ALL",
")",
":",
"hass",
".",
"add_job",
"(",
"async_turn_on",
",",
"hass",
",",
"entity_id",
")"
] | [
16,
0
] | [
18,
48
] | python | en | ['en', 'en', 'en'] | True |
async_turn_on | (hass, entity_id=ENTITY_MATCH_ALL) | Turn all or specified switch on. | Turn all or specified switch on. | async def async_turn_on(hass, entity_id=ENTITY_MATCH_ALL):
"""Turn all or specified switch on."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data, blocking=True) | [
"async",
"def",
"async_turn_on",
"(",
"hass",
",",
"entity_id",
"=",
"ENTITY_MATCH_ALL",
")",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"None",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON",
",",
"data",
",",
"blocking",
"=",
"True",
")"
] | [
21,
0
] | [
24,
80
] | python | en | ['en', 'en', 'en'] | True |
turn_off | (hass, entity_id=ENTITY_MATCH_ALL) | Turn all or specified switch off. | Turn all or specified switch off. | def turn_off(hass, entity_id=ENTITY_MATCH_ALL):
"""Turn all or specified switch off."""
hass.add_job(async_turn_off, hass, entity_id) | [
"def",
"turn_off",
"(",
"hass",
",",
"entity_id",
"=",
"ENTITY_MATCH_ALL",
")",
":",
"hass",
".",
"add_job",
"(",
"async_turn_off",
",",
"hass",
",",
"entity_id",
")"
] | [
28,
0
] | [
30,
49
] | python | en | ['en', 'en', 'en'] | True |
async_turn_off | (hass, entity_id=ENTITY_MATCH_ALL) | Turn all or specified switch off. | Turn all or specified switch off. | async def async_turn_off(hass, entity_id=ENTITY_MATCH_ALL):
"""Turn all or specified switch off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
await hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data, blocking=True) | [
"async",
"def",
"async_turn_off",
"(",
"hass",
",",
"entity_id",
"=",
"ENTITY_MATCH_ALL",
")",
":",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
"if",
"entity_id",
"else",
"None",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"data",
",",
"blocking",
"=",
"True",
")"
] | [
33,
0
] | [
36,
81
] | python | en | ['en', 'en', 'en'] | True |
mock_test_component | (hass) | Ensure a component called 'test' exists. | Ensure a component called 'test' exists. | def mock_test_component(hass):
"""Ensure a component called 'test' exists."""
mock_integration(hass, MockModule("test")) | [
"def",
"mock_test_component",
"(",
"hass",
")",
":",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
")",
")"
] | [
24,
0
] | [
26,
46
] | python | en | ['en', 'en', 'en'] | True |
client | (hass, hass_client) | Fixture that can interact with the config manager API. | Fixture that can interact with the config manager API. | def client(hass, hass_client):
"""Fixture that can interact with the config manager API."""
hass.loop.run_until_complete(async_setup_component(hass, "http", {}))
hass.loop.run_until_complete(config_entries.async_setup(hass))
yield hass.loop.run_until_complete(hass_client()) | [
"def",
"client",
"(",
"hass",
",",
"hass_client",
")",
":",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"}",
")",
")",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"config_entries",
".",
"async_setup",
"(",
"hass",
")",
")",
"yield",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"hass_client",
"(",
")",
")"
] | [
30,
0
] | [
34,
53
] | python | en | ['en', 'en', 'en'] | True |
test_get_entries | (hass, client) | Test get entries. | Test get entries. | async def test_get_entries(hass, client):
"""Test get entries."""
with patch.dict(HANDLERS, clear=True):
@HANDLERS.register("comp1")
class Comp1ConfigFlow:
"""Config flow with options flow."""
@staticmethod
@callback
def async_get_options_flow(config, options):
"""Get options flow."""
pass
hass.helpers.config_entry_flow.register_discovery_flow(
"comp2", "Comp 2", lambda: None, core_ce.CONN_CLASS_ASSUMED
)
entry = MockConfigEntry(
domain="comp1",
title="Test 1",
source="bla",
connection_class=core_ce.CONN_CLASS_LOCAL_POLL,
)
entry.supports_unload = True
entry.add_to_hass(hass)
MockConfigEntry(
domain="comp2",
title="Test 2",
source="bla2",
state=core_ce.ENTRY_STATE_LOADED,
connection_class=core_ce.CONN_CLASS_ASSUMED,
).add_to_hass(hass)
resp = await client.get("/api/config/config_entries/entry")
assert resp.status == 200
data = await resp.json()
for entry in data:
entry.pop("entry_id")
assert data == [
{
"domain": "comp1",
"title": "Test 1",
"source": "bla",
"state": "not_loaded",
"connection_class": "local_poll",
"supports_options": True,
"supports_unload": True,
},
{
"domain": "comp2",
"title": "Test 2",
"source": "bla2",
"state": "loaded",
"connection_class": "assumed",
"supports_options": False,
"supports_unload": False,
},
] | [
"async",
"def",
"test_get_entries",
"(",
"hass",
",",
"client",
")",
":",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"clear",
"=",
"True",
")",
":",
"@",
"HANDLERS",
".",
"register",
"(",
"\"comp1\"",
")",
"class",
"Comp1ConfigFlow",
":",
"\"\"\"Config flow with options flow.\"\"\"",
"@",
"staticmethod",
"@",
"callback",
"def",
"async_get_options_flow",
"(",
"config",
",",
"options",
")",
":",
"\"\"\"Get options flow.\"\"\"",
"pass",
"hass",
".",
"helpers",
".",
"config_entry_flow",
".",
"register_discovery_flow",
"(",
"\"comp2\"",
",",
"\"Comp 2\"",
",",
"lambda",
":",
"None",
",",
"core_ce",
".",
"CONN_CLASS_ASSUMED",
")",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"comp1\"",
",",
"title",
"=",
"\"Test 1\"",
",",
"source",
"=",
"\"bla\"",
",",
"connection_class",
"=",
"core_ce",
".",
"CONN_CLASS_LOCAL_POLL",
",",
")",
"entry",
".",
"supports_unload",
"=",
"True",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"MockConfigEntry",
"(",
"domain",
"=",
"\"comp2\"",
",",
"title",
"=",
"\"Test 2\"",
",",
"source",
"=",
"\"bla2\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_LOADED",
",",
"connection_class",
"=",
"core_ce",
".",
"CONN_CLASS_ASSUMED",
",",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"get",
"(",
"\"/api/config/config_entries/entry\"",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"for",
"entry",
"in",
"data",
":",
"entry",
".",
"pop",
"(",
"\"entry_id\"",
")",
"assert",
"data",
"==",
"[",
"{",
"\"domain\"",
":",
"\"comp1\"",
",",
"\"title\"",
":",
"\"Test 1\"",
",",
"\"source\"",
":",
"\"bla\"",
",",
"\"state\"",
":",
"\"not_loaded\"",
",",
"\"connection_class\"",
":",
"\"local_poll\"",
",",
"\"supports_options\"",
":",
"True",
",",
"\"supports_unload\"",
":",
"True",
",",
"}",
",",
"{",
"\"domain\"",
":",
"\"comp2\"",
",",
"\"title\"",
":",
"\"Test 2\"",
",",
"\"source\"",
":",
"\"bla2\"",
",",
"\"state\"",
":",
"\"loaded\"",
",",
"\"connection_class\"",
":",
"\"assumed\"",
",",
"\"supports_options\"",
":",
"False",
",",
"\"supports_unload\"",
":",
"False",
",",
"}",
",",
"]"
] | [
37,
0
] | [
95,
9
] | python | de | ['nl', 'de', 'en'] | False |
test_remove_entry | (hass, client) | Test removing an entry via the API. | Test removing an entry via the API. | async def test_remove_entry(hass, client):
"""Test removing an entry via the API."""
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
entry.add_to_hass(hass)
resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
assert resp.status == 200
data = await resp.json()
assert data == {"require_restart": True}
assert len(hass.config_entries.async_entries()) == 0 | [
"async",
"def",
"test_remove_entry",
"(",
"hass",
",",
"client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_LOADED",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"delete",
"(",
"f\"/api/config/config_entries/entry/{entry.entry_id}\"",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"assert",
"data",
"==",
"{",
"\"require_restart\"",
":",
"True",
"}",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
")",
")",
"==",
"0"
] | [
98,
0
] | [
106,
56
] | python | en | ['en', 'pt', 'en'] | True |
test_reload_entry | (hass, client) | Test reloading an entry via the API. | Test reloading an entry via the API. | async def test_reload_entry(hass, client):
"""Test reloading an entry via the API."""
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
entry.add_to_hass(hass)
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 200
data = await resp.json()
assert data == {"require_restart": True}
assert len(hass.config_entries.async_entries()) == 1 | [
"async",
"def",
"test_reload_entry",
"(",
"hass",
",",
"client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_LOADED",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/entry/{entry.entry_id}/reload\"",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"assert",
"data",
"==",
"{",
"\"require_restart\"",
":",
"True",
"}",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
")",
")",
"==",
"1"
] | [
109,
0
] | [
119,
56
] | python | en | ['en', 'no', 'en'] | True |
test_reload_invalid_entry | (hass, client) | Test reloading an invalid entry via the API. | Test reloading an invalid entry via the API. | async def test_reload_invalid_entry(hass, client):
"""Test reloading an invalid entry via the API."""
resp = await client.post("/api/config/config_entries/entry/invalid/reload")
assert resp.status == 404 | [
"async",
"def",
"test_reload_invalid_entry",
"(",
"hass",
",",
"client",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/entry/invalid/reload\"",
")",
"assert",
"resp",
".",
"status",
"==",
"404"
] | [
122,
0
] | [
125,
29
] | python | en | ['en', 'en', 'en'] | True |
test_remove_entry_unauth | (hass, client, hass_admin_user) | Test removing an entry via the API. | Test removing an entry via the API. | async def test_remove_entry_unauth(hass, client, hass_admin_user):
"""Test removing an entry via the API."""
hass_admin_user.groups = []
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
entry.add_to_hass(hass)
resp = await client.delete(f"/api/config/config_entries/entry/{entry.entry_id}")
assert resp.status == 401
assert len(hass.config_entries.async_entries()) == 1 | [
"async",
"def",
"test_remove_entry_unauth",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_LOADED",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"delete",
"(",
"f\"/api/config/config_entries/entry/{entry.entry_id}\"",
")",
"assert",
"resp",
".",
"status",
"==",
"401",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
")",
")",
"==",
"1"
] | [
128,
0
] | [
135,
56
] | python | en | ['en', 'pt', 'en'] | True |
test_reload_entry_unauth | (hass, client, hass_admin_user) | Test reloading an entry via the API. | Test reloading an entry via the API. | async def test_reload_entry_unauth(hass, client, hass_admin_user):
"""Test reloading an entry via the API."""
hass_admin_user.groups = []
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_LOADED)
entry.add_to_hass(hass)
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 401
assert len(hass.config_entries.async_entries()) == 1 | [
"async",
"def",
"test_reload_entry_unauth",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_LOADED",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/entry/{entry.entry_id}/reload\"",
")",
"assert",
"resp",
".",
"status",
"==",
"401",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
")",
")",
"==",
"1"
] | [
138,
0
] | [
147,
56
] | python | en | ['en', 'no', 'en'] | True |
test_reload_entry_in_failed_state | (hass, client, hass_admin_user) | Test reloading an entry via the API that has already failed to unload. | Test reloading an entry via the API that has already failed to unload. | async def test_reload_entry_in_failed_state(hass, client, hass_admin_user):
"""Test reloading an entry via the API that has already failed to unload."""
entry = MockConfigEntry(domain="demo", state=core_ce.ENTRY_STATE_FAILED_UNLOAD)
entry.add_to_hass(hass)
resp = await client.post(
f"/api/config/config_entries/entry/{entry.entry_id}/reload"
)
assert resp.status == 403
assert len(hass.config_entries.async_entries()) == 1 | [
"async",
"def",
"test_reload_entry_in_failed_state",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"state",
"=",
"core_ce",
".",
"ENTRY_STATE_FAILED_UNLOAD",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/entry/{entry.entry_id}/reload\"",
")",
"assert",
"resp",
".",
"status",
"==",
"403",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
")",
")",
"==",
"1"
] | [
150,
0
] | [
158,
56
] | python | en | ['en', 'en', 'en'] | True |
test_available_flows | (hass, client) | Test querying the available flows. | Test querying the available flows. | async def test_available_flows(hass, client):
"""Test querying the available flows."""
with patch.object(config_flows, "FLOWS", ["hello", "world"]):
resp = await client.get("/api/config/config_entries/flow_handlers")
assert resp.status == 200
data = await resp.json()
assert set(data) == {"hello", "world"} | [
"async",
"def",
"test_available_flows",
"(",
"hass",
",",
"client",
")",
":",
"with",
"patch",
".",
"object",
"(",
"config_flows",
",",
"\"FLOWS\"",
",",
"[",
"\"hello\"",
",",
"\"world\"",
"]",
")",
":",
"resp",
"=",
"await",
"client",
".",
"get",
"(",
"\"/api/config/config_entries/flow_handlers\"",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"assert",
"set",
"(",
"data",
")",
"==",
"{",
"\"hello\"",
",",
"\"world\"",
"}"
] | [
161,
0
] | [
167,
46
] | python | en | ['en', 'en', 'en'] | True |
test_initialize_flow | (hass, client) | Test we can initialize a flow. | Test we can initialize a flow. | async def test_initialize_flow(hass, client):
"""Test we can initialize a flow."""
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
async def async_step_user(self, user_input=None):
schema = OrderedDict()
schema[vol.Required("username")] = str
schema[vol.Required("password")] = str
return self.async_show_form(
step_id="user",
data_schema=schema,
description_placeholders={
"url": "https://example.com",
"show_advanced_options": self.show_advanced_options,
},
errors={"username": "Should be unique."},
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow",
json={"handler": "test", "show_advanced_options": True},
)
assert resp.status == 200
data = await resp.json()
data.pop("flow_id")
assert data == {
"type": "form",
"handler": "test",
"step_id": "user",
"data_schema": [
{"name": "username", "required": True, "type": "string"},
{"name": "password", "required": True, "type": "string"},
],
"description_placeholders": {
"url": "https://example.com",
"show_advanced_options": True,
},
"errors": {"username": "Should be unique."},
} | [
"async",
"def",
"test_initialize_flow",
"(",
"hass",
",",
"client",
")",
":",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"schema",
"=",
"OrderedDict",
"(",
")",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"username\"",
")",
"]",
"=",
"str",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"password\"",
")",
"]",
"=",
"str",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
",",
"description_placeholders",
"=",
"{",
"\"url\"",
":",
"\"https://example.com\"",
",",
"\"show_advanced_options\"",
":",
"self",
".",
"show_advanced_options",
",",
"}",
",",
"errors",
"=",
"{",
"\"username\"",
":",
"\"Should be unique.\"",
"}",
",",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
",",
"\"show_advanced_options\"",
":",
"True",
"}",
",",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"type\"",
":",
"\"form\"",
",",
"\"handler\"",
":",
"\"test\"",
",",
"\"step_id\"",
":",
"\"user\"",
",",
"\"data_schema\"",
":",
"[",
"{",
"\"name\"",
":",
"\"username\"",
",",
"\"required\"",
":",
"True",
",",
"\"type\"",
":",
"\"string\"",
"}",
",",
"{",
"\"name\"",
":",
"\"password\"",
",",
"\"required\"",
":",
"True",
",",
"\"type\"",
":",
"\"string\"",
"}",
",",
"]",
",",
"\"description_placeholders\"",
":",
"{",
"\"url\"",
":",
"\"https://example.com\"",
",",
"\"show_advanced_options\"",
":",
"True",
",",
"}",
",",
"\"errors\"",
":",
"{",
"\"username\"",
":",
"\"Should be unique.\"",
"}",
",",
"}"
] | [
175,
0
] | [
219,
5
] | python | en | ['en', 'en', 'en'] | True |
test_initialize_flow_unauth | (hass, client, hass_admin_user) | Test we can initialize a flow. | Test we can initialize a flow. | async def test_initialize_flow_unauth(hass, client, hass_admin_user):
"""Test we can initialize a flow."""
hass_admin_user.groups = []
class TestFlow(core_ce.ConfigFlow):
async def async_step_user(self, user_input=None):
schema = OrderedDict()
schema[vol.Required("username")] = str
schema[vol.Required("password")] = str
return self.async_show_form(
step_id="user",
data_schema=schema,
description_placeholders={"url": "https://example.com"},
errors={"username": "Should be unique."},
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 401 | [
"async",
"def",
"test_initialize_flow_unauth",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"schema",
"=",
"OrderedDict",
"(",
")",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"username\"",
")",
"]",
"=",
"str",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"password\"",
")",
"]",
"=",
"str",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
",",
"description_placeholders",
"=",
"{",
"\"url\"",
":",
"\"https://example.com\"",
"}",
",",
"errors",
"=",
"{",
"\"username\"",
":",
"\"Should be unique.\"",
"}",
",",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"401"
] | [
222,
0
] | [
244,
29
] | python | en | ['en', 'en', 'en'] | True |
test_abort | (hass, client) | Test a flow that aborts. | Test a flow that aborts. | async def test_abort(hass, client):
"""Test a flow that aborts."""
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
async def async_step_user(self, user_input=None):
return self.async_abort(reason="bla")
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
data = await resp.json()
data.pop("flow_id")
assert data == {
"description_placeholders": None,
"handler": "test",
"reason": "bla",
"type": "abort",
} | [
"async",
"def",
"test_abort",
"(",
"hass",
",",
"client",
")",
":",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"bla\"",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"description_placeholders\"",
":",
"None",
",",
"\"handler\"",
":",
"\"test\"",
",",
"\"reason\"",
":",
"\"bla\"",
",",
"\"type\"",
":",
"\"abort\"",
",",
"}"
] | [
247,
0
] | [
268,
5
] | python | en | ['en', 'en', 'en'] | True |
test_create_account | (hass, client) | Test a flow that creates an account. | Test a flow that creates an account. | async def test_create_account(hass, client):
"""Test a flow that creates an account."""
mock_entity_platform(hass, "config_flow.test", None)
mock_integration(
hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True))
)
class TestFlow(core_ce.ConfigFlow):
VERSION = 1
async def async_step_user(self, user_input=None):
return self.async_create_entry(
title="Test Entry", data={"secret": "account_token"}
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
entries = hass.config_entries.async_entries("test")
assert len(entries) == 1
data = await resp.json()
data.pop("flow_id")
assert data == {
"handler": "test",
"title": "Test Entry",
"type": "create_entry",
"version": 1,
"result": entries[0].entry_id,
"description": None,
"description_placeholders": None,
} | [
"async",
"def",
"test_create_account",
"(",
"hass",
",",
"client",
")",
":",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
",",
"async_setup_entry",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True",
")",
")",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"VERSION",
"=",
"1",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"Test Entry\"",
",",
"data",
"=",
"{",
"\"secret\"",
":",
"\"account_token\"",
"}",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"\"test\"",
")",
"assert",
"len",
"(",
"entries",
")",
"==",
"1",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"handler\"",
":",
"\"test\"",
",",
"\"title\"",
":",
"\"Test Entry\"",
",",
"\"type\"",
":",
"\"create_entry\"",
",",
"\"version\"",
":",
"1",
",",
"\"result\"",
":",
"entries",
"[",
"0",
"]",
".",
"entry_id",
",",
"\"description\"",
":",
"None",
",",
"\"description_placeholders\"",
":",
"None",
",",
"}"
] | [
271,
0
] | [
307,
5
] | python | en | ['en', 'gd', 'en'] | True |
test_two_step_flow | (hass, client) | Test we can finish a two step flow. | Test we can finish a two step flow. | async def test_two_step_flow(hass, client):
"""Test we can finish a two step flow."""
mock_integration(
hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True))
)
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
VERSION = 1
async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="account", data_schema=vol.Schema({"user_title": str})
)
async def async_step_account(self, user_input=None):
return self.async_create_entry(
title=user_input["user_title"], data={"secret": "account_token"}
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
"type": "form",
"handler": "test",
"step_id": "account",
"data_schema": [{"name": "user_title", "type": "string"}],
"description_placeholders": None,
"errors": None,
}
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
f"/api/config/config_entries/flow/{flow_id}",
json={"user_title": "user-title"},
)
assert resp.status == 200
entries = hass.config_entries.async_entries("test")
assert len(entries) == 1
data = await resp.json()
data.pop("flow_id")
assert data == {
"handler": "test",
"type": "create_entry",
"title": "user-title",
"version": 1,
"result": entries[0].entry_id,
"description": None,
"description_placeholders": None,
} | [
"async",
"def",
"test_two_step_flow",
"(",
"hass",
",",
"client",
")",
":",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
",",
"async_setup_entry",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True",
")",
")",
")",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"VERSION",
"=",
"1",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"account\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"\"user_title\"",
":",
"str",
"}",
")",
")",
"async",
"def",
"async_step_account",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"user_input",
"[",
"\"user_title\"",
"]",
",",
"data",
"=",
"{",
"\"secret\"",
":",
"\"account_token\"",
"}",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"flow_id",
"=",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"type\"",
":",
"\"form\"",
",",
"\"handler\"",
":",
"\"test\"",
",",
"\"step_id\"",
":",
"\"account\"",
",",
"\"data_schema\"",
":",
"[",
"{",
"\"name\"",
":",
"\"user_title\"",
",",
"\"type\"",
":",
"\"string\"",
"}",
"]",
",",
"\"description_placeholders\"",
":",
"None",
",",
"\"errors\"",
":",
"None",
",",
"}",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/flow/{flow_id}\"",
",",
"json",
"=",
"{",
"\"user_title\"",
":",
"\"user-title\"",
"}",
",",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"\"test\"",
")",
"assert",
"len",
"(",
"entries",
")",
"==",
"1",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"handler\"",
":",
"\"test\"",
",",
"\"type\"",
":",
"\"create_entry\"",
",",
"\"title\"",
":",
"\"user-title\"",
",",
"\"version\"",
":",
"1",
",",
"\"result\"",
":",
"entries",
"[",
"0",
"]",
".",
"entry_id",
",",
"\"description\"",
":",
"None",
",",
"\"description_placeholders\"",
":",
"None",
",",
"}"
] | [
310,
0
] | [
366,
9
] | python | en | ['en', 'en', 'en'] | True |
test_continue_flow_unauth | (hass, client, hass_admin_user) | Test we can't finish a two step flow. | Test we can't finish a two step flow. | async def test_continue_flow_unauth(hass, client, hass_admin_user):
"""Test we can't finish a two step flow."""
mock_integration(
hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True))
)
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
VERSION = 1
async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="account", data_schema=vol.Schema({"user_title": str})
)
async def async_step_account(self, user_input=None):
return self.async_create_entry(
title=user_input["user_title"], data={"secret": "account_token"}
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
"type": "form",
"handler": "test",
"step_id": "account",
"data_schema": [{"name": "user_title", "type": "string"}],
"description_placeholders": None,
"errors": None,
}
hass_admin_user.groups = []
resp = await client.post(
f"/api/config/config_entries/flow/{flow_id}",
json={"user_title": "user-title"},
)
assert resp.status == 401 | [
"async",
"def",
"test_continue_flow_unauth",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
",",
"async_setup_entry",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True",
")",
")",
")",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"VERSION",
"=",
"1",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"account\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"\"user_title\"",
":",
"str",
"}",
")",
")",
"async",
"def",
"async_step_account",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"user_input",
"[",
"\"user_title\"",
"]",
",",
"data",
"=",
"{",
"\"secret\"",
":",
"\"account_token\"",
"}",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"flow_id",
"=",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"type\"",
":",
"\"form\"",
",",
"\"handler\"",
":",
"\"test\"",
",",
"\"step_id\"",
":",
"\"account\"",
",",
"\"data_schema\"",
":",
"[",
"{",
"\"name\"",
":",
"\"user_title\"",
",",
"\"type\"",
":",
"\"string\"",
"}",
"]",
",",
"\"description_placeholders\"",
":",
"None",
",",
"\"errors\"",
":",
"None",
",",
"}",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/flow/{flow_id}\"",
",",
"json",
"=",
"{",
"\"user_title\"",
":",
"\"user-title\"",
"}",
",",
")",
"assert",
"resp",
".",
"status",
"==",
"401"
] | [
369,
0
] | [
411,
29
] | python | en | ['en', 'en', 'en'] | True |
test_get_progress_index | (hass, hass_ws_client) | Test querying for the flows that are in progress. | Test querying for the flows that are in progress. | async def test_get_progress_index(hass, hass_ws_client):
"""Test querying for the flows that are in progress."""
assert await async_setup_component(hass, "config", {})
mock_entity_platform(hass, "config_flow.test", None)
ws_client = await hass_ws_client(hass)
class TestFlow(core_ce.ConfigFlow):
VERSION = 5
async def async_step_hassio(self, info):
return await self.async_step_account()
async def async_step_account(self, user_input=None):
return self.async_show_form(step_id="account")
with patch.dict(HANDLERS, {"test": TestFlow}):
form = await hass.config_entries.flow.async_init(
"test", context={"source": "hassio"}
)
await ws_client.send_json({"id": 5, "type": "config_entries/flow/progress"})
response = await ws_client.receive_json()
assert response["success"]
assert response["result"] == [
{
"flow_id": form["flow_id"],
"handler": "test",
"step_id": "account",
"context": {"source": "hassio"},
}
] | [
"async",
"def",
"test_get_progress_index",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"VERSION",
"=",
"5",
"async",
"def",
"async_step_hassio",
"(",
"self",
",",
"info",
")",
":",
"return",
"await",
"self",
".",
"async_step_account",
"(",
")",
"async",
"def",
"async_step_account",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"account\"",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"form",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"test\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"hassio\"",
"}",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/flow/progress\"",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"result\"",
"]",
"==",
"[",
"{",
"\"flow_id\"",
":",
"form",
"[",
"\"flow_id\"",
"]",
",",
"\"handler\"",
":",
"\"test\"",
",",
"\"step_id\"",
":",
"\"account\"",
",",
"\"context\"",
":",
"{",
"\"source\"",
":",
"\"hassio\"",
"}",
",",
"}",
"]"
] | [
414,
0
] | [
445,
5
] | python | en | ['en', 'en', 'en'] | True |
test_get_progress_index_unauth | (hass, hass_ws_client, hass_admin_user) | Test we can't get flows that are in progress. | Test we can't get flows that are in progress. | async def test_get_progress_index_unauth(hass, hass_ws_client, hass_admin_user):
"""Test we can't get flows that are in progress."""
assert await async_setup_component(hass, "config", {})
hass_admin_user.groups = []
ws_client = await hass_ws_client(hass)
await ws_client.send_json({"id": 5, "type": "config_entries/flow/progress"})
response = await ws_client.receive_json()
assert not response["success"]
assert response["error"]["code"] == "unauthorized" | [
"async",
"def",
"test_get_progress_index_unauth",
"(",
"hass",
",",
"hass_ws_client",
",",
"hass_admin_user",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/flow/progress\"",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"not",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"error\"",
"]",
"[",
"\"code\"",
"]",
"==",
"\"unauthorized\""
] | [
448,
0
] | [
458,
54
] | python | en | ['en', 'en', 'en'] | True |
test_get_progress_flow | (hass, client) | Test we can query the API for same result as we get from init a flow. | Test we can query the API for same result as we get from init a flow. | async def test_get_progress_flow(hass, client):
"""Test we can query the API for same result as we get from init a flow."""
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
async def async_step_user(self, user_input=None):
schema = OrderedDict()
schema[vol.Required("username")] = str
schema[vol.Required("password")] = str
return self.async_show_form(
step_id="user",
data_schema=schema,
errors={"username": "Should be unique."},
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
data = await resp.json()
resp2 = await client.get(
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
assert resp2.status == 200
data2 = await resp2.json()
assert data == data2 | [
"async",
"def",
"test_get_progress_flow",
"(",
"hass",
",",
"client",
")",
":",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"schema",
"=",
"OrderedDict",
"(",
")",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"username\"",
")",
"]",
"=",
"str",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"password\"",
")",
"]",
"=",
"str",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
",",
"errors",
"=",
"{",
"\"username\"",
":",
"\"Should be unique.\"",
"}",
",",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"resp2",
"=",
"await",
"client",
".",
"get",
"(",
"\"/api/config/config_entries/flow/{}\"",
".",
"format",
"(",
"data",
"[",
"\"flow_id\"",
"]",
")",
")",
"assert",
"resp2",
".",
"status",
"==",
"200",
"data2",
"=",
"await",
"resp2",
".",
"json",
"(",
")",
"assert",
"data",
"==",
"data2"
] | [
461,
0
] | [
492,
24
] | python | en | ['en', 'en', 'en'] | True |
test_get_progress_flow_unauth | (hass, client, hass_admin_user) | Test we can can't query the API for result of flow. | Test we can can't query the API for result of flow. | async def test_get_progress_flow_unauth(hass, client, hass_admin_user):
"""Test we can can't query the API for result of flow."""
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
async def async_step_user(self, user_input=None):
schema = OrderedDict()
schema[vol.Required("username")] = str
schema[vol.Required("password")] = str
return self.async_show_form(
step_id="user",
data_schema=schema,
errors={"username": "Should be unique."},
)
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
"/api/config/config_entries/flow", json={"handler": "test"}
)
assert resp.status == 200
data = await resp.json()
hass_admin_user.groups = []
resp2 = await client.get(
"/api/config/config_entries/flow/{}".format(data["flow_id"])
)
assert resp2.status == 401 | [
"async",
"def",
"test_get_progress_flow_unauth",
"(",
"hass",
",",
"client",
",",
"hass_admin_user",
")",
":",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"schema",
"=",
"OrderedDict",
"(",
")",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"username\"",
")",
"]",
"=",
"str",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"password\"",
")",
"]",
"=",
"str",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
",",
"errors",
"=",
"{",
"\"username\"",
":",
"\"Should be unique.\"",
"}",
",",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"\"/api/config/config_entries/flow\"",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"\"test\"",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"hass_admin_user",
".",
"groups",
"=",
"[",
"]",
"resp2",
"=",
"await",
"client",
".",
"get",
"(",
"\"/api/config/config_entries/flow/{}\"",
".",
"format",
"(",
"data",
"[",
"\"flow_id\"",
"]",
")",
")",
"assert",
"resp2",
".",
"status",
"==",
"401"
] | [
495,
0
] | [
525,
30
] | python | en | ['en', 'en', 'en'] | True |
test_options_flow | (hass, client) | Test we can change options. | Test we can change options. | async def test_options_flow(hass, client):
"""Test we can change options."""
class TestFlow(core_ce.ConfigFlow):
@staticmethod
@callback
def async_get_options_flow(config_entry):
class OptionsFlowHandler(data_entry_flow.FlowHandler):
async def async_step_init(self, user_input=None):
schema = OrderedDict()
schema[vol.Required("enabled")] = bool
return self.async_show_form(
step_id="user",
data_schema=schema,
description_placeholders={"enabled": "Set to true to be true"},
)
return OptionsFlowHandler()
MockConfigEntry(
domain="test",
entry_id="test1",
source="bla",
connection_class=core_ce.CONN_CLASS_LOCAL_POLL,
).add_to_hass(hass)
entry = hass.config_entries._entries[0]
with patch.dict(HANDLERS, {"test": TestFlow}):
url = "/api/config/config_entries/options/flow"
resp = await client.post(url, json={"handler": entry.entry_id})
assert resp.status == 200
data = await resp.json()
data.pop("flow_id")
assert data == {
"type": "form",
"handler": "test1",
"step_id": "user",
"data_schema": [{"name": "enabled", "required": True, "type": "boolean"}],
"description_placeholders": {"enabled": "Set to true to be true"},
"errors": None,
} | [
"async",
"def",
"test_options_flow",
"(",
"hass",
",",
"client",
")",
":",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"@",
"staticmethod",
"@",
"callback",
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"class",
"OptionsFlowHandler",
"(",
"data_entry_flow",
".",
"FlowHandler",
")",
":",
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"schema",
"=",
"OrderedDict",
"(",
")",
"schema",
"[",
"vol",
".",
"Required",
"(",
"\"enabled\"",
")",
"]",
"=",
"bool",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
",",
"description_placeholders",
"=",
"{",
"\"enabled\"",
":",
"\"Set to true to be true\"",
"}",
",",
")",
"return",
"OptionsFlowHandler",
"(",
")",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"entry_id",
"=",
"\"test1\"",
",",
"source",
"=",
"\"bla\"",
",",
"connection_class",
"=",
"core_ce",
".",
"CONN_CLASS_LOCAL_POLL",
",",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"entry",
"=",
"hass",
".",
"config_entries",
".",
"_entries",
"[",
"0",
"]",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"url",
"=",
"\"/api/config/config_entries/options/flow\"",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"entry",
".",
"entry_id",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"type\"",
":",
"\"form\"",
",",
"\"handler\"",
":",
"\"test1\"",
",",
"\"step_id\"",
":",
"\"user\"",
",",
"\"data_schema\"",
":",
"[",
"{",
"\"name\"",
":",
"\"enabled\"",
",",
"\"required\"",
":",
"True",
",",
"\"type\"",
":",
"\"boolean\"",
"}",
"]",
",",
"\"description_placeholders\"",
":",
"{",
"\"enabled\"",
":",
"\"Set to true to be true\"",
"}",
",",
"\"errors\"",
":",
"None",
",",
"}"
] | [
528,
0
] | [
570,
5
] | python | en | ['en', 'en', 'en'] | True |
test_two_step_options_flow | (hass, client) | Test we can finish a two step options flow. | Test we can finish a two step options flow. | async def test_two_step_options_flow(hass, client):
"""Test we can finish a two step options flow."""
mock_integration(
hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True))
)
class TestFlow(core_ce.ConfigFlow):
@staticmethod
@callback
def async_get_options_flow(config_entry):
class OptionsFlowHandler(data_entry_flow.FlowHandler):
async def async_step_init(self, user_input=None):
return self.async_show_form(
step_id="finish", data_schema=vol.Schema({"enabled": bool})
)
async def async_step_finish(self, user_input=None):
return self.async_create_entry(
title="Enable disable", data=user_input
)
return OptionsFlowHandler()
MockConfigEntry(
domain="test",
entry_id="test1",
source="bla",
connection_class=core_ce.CONN_CLASS_LOCAL_POLL,
).add_to_hass(hass)
entry = hass.config_entries._entries[0]
with patch.dict(HANDLERS, {"test": TestFlow}):
url = "/api/config/config_entries/options/flow"
resp = await client.post(url, json={"handler": entry.entry_id})
assert resp.status == 200
data = await resp.json()
flow_id = data.pop("flow_id")
assert data == {
"type": "form",
"handler": "test1",
"step_id": "finish",
"data_schema": [{"name": "enabled", "type": "boolean"}],
"description_placeholders": None,
"errors": None,
}
with patch.dict(HANDLERS, {"test": TestFlow}):
resp = await client.post(
f"/api/config/config_entries/options/flow/{flow_id}",
json={"enabled": True},
)
assert resp.status == 200
data = await resp.json()
data.pop("flow_id")
assert data == {
"handler": "test1",
"type": "create_entry",
"title": "Enable disable",
"version": 1,
"description": None,
"description_placeholders": None,
} | [
"async",
"def",
"test_two_step_options_flow",
"(",
"hass",
",",
"client",
")",
":",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
",",
"async_setup_entry",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True",
")",
")",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"@",
"staticmethod",
"@",
"callback",
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"class",
"OptionsFlowHandler",
"(",
"data_entry_flow",
".",
"FlowHandler",
")",
":",
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"finish\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"\"enabled\"",
":",
"bool",
"}",
")",
")",
"async",
"def",
"async_step_finish",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"Enable disable\"",
",",
"data",
"=",
"user_input",
")",
"return",
"OptionsFlowHandler",
"(",
")",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"entry_id",
"=",
"\"test1\"",
",",
"source",
"=",
"\"bla\"",
",",
"connection_class",
"=",
"core_ce",
".",
"CONN_CLASS_LOCAL_POLL",
",",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"entry",
"=",
"hass",
".",
"config_entries",
".",
"_entries",
"[",
"0",
"]",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"url",
"=",
"\"/api/config/config_entries/options/flow\"",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"json",
"=",
"{",
"\"handler\"",
":",
"entry",
".",
"entry_id",
"}",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"flow_id",
"=",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"type\"",
":",
"\"form\"",
",",
"\"handler\"",
":",
"\"test1\"",
",",
"\"step_id\"",
":",
"\"finish\"",
",",
"\"data_schema\"",
":",
"[",
"{",
"\"name\"",
":",
"\"enabled\"",
",",
"\"type\"",
":",
"\"boolean\"",
"}",
"]",
",",
"\"description_placeholders\"",
":",
"None",
",",
"\"errors\"",
":",
"None",
",",
"}",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"resp",
"=",
"await",
"client",
".",
"post",
"(",
"f\"/api/config/config_entries/options/flow/{flow_id}\"",
",",
"json",
"=",
"{",
"\"enabled\"",
":",
"True",
"}",
",",
")",
"assert",
"resp",
".",
"status",
"==",
"200",
"data",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"data",
".",
"pop",
"(",
"\"flow_id\"",
")",
"assert",
"data",
"==",
"{",
"\"handler\"",
":",
"\"test1\"",
",",
"\"type\"",
":",
"\"create_entry\"",
",",
"\"title\"",
":",
"\"Enable disable\"",
",",
"\"version\"",
":",
"1",
",",
"\"description\"",
":",
"None",
",",
"\"description_placeholders\"",
":",
"None",
",",
"}"
] | [
573,
0
] | [
635,
9
] | python | en | ['en', 'en', 'en'] | True |
test_list_system_options | (hass, hass_ws_client) | Test that we can list an entries system options. | Test that we can list an entries system options. | async def test_list_system_options(hass, hass_ws_client):
"""Test that we can list an entries system options."""
assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass)
entry = MockConfigEntry(domain="demo")
entry.add_to_hass(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config_entries/system_options/list",
"entry_id": entry.entry_id,
}
)
response = await ws_client.receive_json()
assert response["success"]
assert response["result"] == {"disable_new_entities": False} | [
"async",
"def",
"test_list_system_options",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/system_options/list\"",
",",
"\"entry_id\"",
":",
"entry",
".",
"entry_id",
",",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"result\"",
"]",
"==",
"{",
"\"disable_new_entities\"",
":",
"False",
"}"
] | [
638,
0
] | [
656,
64
] | python | en | ['en', 'en', 'en'] | True |
test_update_system_options | (hass, hass_ws_client) | Test that we can update system options. | Test that we can update system options. | async def test_update_system_options(hass, hass_ws_client):
"""Test that we can update system options."""
assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass)
entry = MockConfigEntry(domain="demo")
entry.add_to_hass(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config_entries/system_options/update",
"entry_id": entry.entry_id,
"disable_new_entities": True,
}
)
response = await ws_client.receive_json()
assert response["success"]
assert response["result"]["disable_new_entities"]
assert entry.system_options.disable_new_entities | [
"async",
"def",
"test_update_system_options",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/system_options/update\"",
",",
"\"entry_id\"",
":",
"entry",
".",
"entry_id",
",",
"\"disable_new_entities\"",
":",
"True",
",",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"result\"",
"]",
"[",
"\"disable_new_entities\"",
"]",
"assert",
"entry",
".",
"system_options",
".",
"disable_new_entities"
] | [
659,
0
] | [
679,
52
] | python | en | ['en', 'en', 'en'] | True |
test_update_entry | (hass, hass_ws_client) | Test that we can update entry. | Test that we can update entry. | async def test_update_entry(hass, hass_ws_client):
"""Test that we can update entry."""
assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass)
entry = MockConfigEntry(domain="demo", title="Initial Title")
entry.add_to_hass(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config_entries/update",
"entry_id": entry.entry_id,
"title": "Updated Title",
}
)
response = await ws_client.receive_json()
assert response["success"]
assert response["result"]["title"] == "Updated Title"
assert entry.title == "Updated Title" | [
"async",
"def",
"test_update_entry",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"demo\"",
",",
"title",
"=",
"\"Initial Title\"",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/update\"",
",",
"\"entry_id\"",
":",
"entry",
".",
"entry_id",
",",
"\"title\"",
":",
"\"Updated Title\"",
",",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"result\"",
"]",
"[",
"\"title\"",
"]",
"==",
"\"Updated Title\"",
"assert",
"entry",
".",
"title",
"==",
"\"Updated Title\""
] | [
682,
0
] | [
702,
41
] | python | en | ['en', 'en', 'en'] | True |
test_update_entry_nonexisting | (hass, hass_ws_client) | Test that we can update entry. | Test that we can update entry. | async def test_update_entry_nonexisting(hass, hass_ws_client):
"""Test that we can update entry."""
assert await async_setup_component(hass, "config", {})
ws_client = await hass_ws_client(hass)
await ws_client.send_json(
{
"id": 5,
"type": "config_entries/update",
"entry_id": "non_existing",
"title": "Updated Title",
}
)
response = await ws_client.receive_json()
assert not response["success"]
assert response["error"]["code"] == "not_found" | [
"async",
"def",
"test_update_entry_nonexisting",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/update\"",
",",
"\"entry_id\"",
":",
"\"non_existing\"",
",",
"\"title\"",
":",
"\"Updated Title\"",
",",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"not",
"response",
"[",
"\"success\"",
"]",
"assert",
"response",
"[",
"\"error\"",
"]",
"[",
"\"code\"",
"]",
"==",
"\"not_found\""
] | [
705,
0
] | [
721,
51
] | python | en | ['en', 'en', 'en'] | True |
test_ignore_flow | (hass, hass_ws_client) | Test we can ignore a flow. | Test we can ignore a flow. | async def test_ignore_flow(hass, hass_ws_client):
"""Test we can ignore a flow."""
assert await async_setup_component(hass, "config", {})
mock_integration(
hass, MockModule("test", async_setup_entry=AsyncMock(return_value=True))
)
mock_entity_platform(hass, "config_flow.test", None)
class TestFlow(core_ce.ConfigFlow):
VERSION = 1
async def async_step_user(self, user_input=None):
await self.async_set_unique_id("mock-unique-id")
return self.async_show_form(step_id="account", data_schema=vol.Schema({}))
ws_client = await hass_ws_client(hass)
with patch.dict(HANDLERS, {"test": TestFlow}):
result = await hass.config_entries.flow.async_init(
"test", context={"source": "user"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
await ws_client.send_json(
{
"id": 5,
"type": "config_entries/ignore_flow",
"flow_id": result["flow_id"],
}
)
response = await ws_client.receive_json()
assert response["success"]
assert len(hass.config_entries.flow.async_progress()) == 0
entry = hass.config_entries.async_entries("test")[0]
assert entry.source == "ignore"
assert entry.unique_id == "mock-unique-id" | [
"async",
"def",
"test_ignore_flow",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"config\"",
",",
"{",
"}",
")",
"mock_integration",
"(",
"hass",
",",
"MockModule",
"(",
"\"test\"",
",",
"async_setup_entry",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True",
")",
")",
")",
"mock_entity_platform",
"(",
"hass",
",",
"\"config_flow.test\"",
",",
"None",
")",
"class",
"TestFlow",
"(",
"core_ce",
".",
"ConfigFlow",
")",
":",
"VERSION",
"=",
"1",
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"await",
"self",
".",
"async_set_unique_id",
"(",
"\"mock-unique-id\"",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"account\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"}",
")",
")",
"ws_client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"with",
"patch",
".",
"dict",
"(",
"HANDLERS",
",",
"{",
"\"test\"",
":",
"TestFlow",
"}",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"test\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"await",
"ws_client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"5",
",",
"\"type\"",
":",
"\"config_entries/ignore_flow\"",
",",
"\"flow_id\"",
":",
"result",
"[",
"\"flow_id\"",
"]",
",",
"}",
")",
"response",
"=",
"await",
"ws_client",
".",
"receive_json",
"(",
")",
"assert",
"response",
"[",
"\"success\"",
"]",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_progress",
"(",
")",
")",
"==",
"0",
"entry",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"\"test\"",
")",
"[",
"0",
"]",
"assert",
"entry",
".",
"source",
"==",
"\"ignore\"",
"assert",
"entry",
".",
"unique_id",
"==",
"\"mock-unique-id\""
] | [
724,
0
] | [
762,
46
] | python | en | ['en', 'en', 'en'] | True |
FilesystemTables.create | (self: "FilesystemTables", schema: Schema, table_identifier: str, spec: PartitionSpec = None,
properties: dict = None, location: str = None) |
Create a new table on the filesystem.
Note: it is expected that the filesystem has atomic operations to ensure consistency for metadata updates.
Filesystems that don't have this guarantee could lead to data loss.
Location should always be None as the table location on disk is taken from `table_identifier`
|
Create a new table on the filesystem. | def create(self: "FilesystemTables", schema: Schema, table_identifier: str, spec: PartitionSpec = None,
properties: dict = None, location: str = None) -> Table:
"""
Create a new table on the filesystem.
Note: it is expected that the filesystem has atomic operations to ensure consistency for metadata updates.
Filesystems that don't have this guarantee could lead to data loss.
Location should always be None as the table location on disk is taken from `table_identifier`
"""
from ..base_table import BaseTable
if location:
raise RuntimeError("""location has to be None. Both table_identifier and location have been declared.
table_identifier: {} and location: {}""".format(table_identifier, location))
full_spec, properties = super(FilesystemTables, self).default_args(spec, properties)
ops = self.new_table_ops(table_identifier)
metadata = TableMetadata.new_table_metadata(ops, schema, full_spec, table_identifier, properties)
ops.commit(None, metadata)
return BaseTable(ops, table_identifier) | [
"def",
"create",
"(",
"self",
":",
"\"FilesystemTables\"",
",",
"schema",
":",
"Schema",
",",
"table_identifier",
":",
"str",
",",
"spec",
":",
"PartitionSpec",
"=",
"None",
",",
"properties",
":",
"dict",
"=",
"None",
",",
"location",
":",
"str",
"=",
"None",
")",
"->",
"Table",
":",
"from",
".",
".",
"base_table",
"import",
"BaseTable",
"if",
"location",
":",
"raise",
"RuntimeError",
"(",
"\"\"\"location has to be None. Both table_identifier and location have been declared.\n table_identifier: {} and location: {}\"\"\"",
".",
"format",
"(",
"table_identifier",
",",
"location",
")",
")",
"full_spec",
",",
"properties",
"=",
"super",
"(",
"FilesystemTables",
",",
"self",
")",
".",
"default_args",
"(",
"spec",
",",
"properties",
")",
"ops",
"=",
"self",
".",
"new_table_ops",
"(",
"table_identifier",
")",
"metadata",
"=",
"TableMetadata",
".",
"new_table_metadata",
"(",
"ops",
",",
"schema",
",",
"full_spec",
",",
"table_identifier",
",",
"properties",
")",
"ops",
".",
"commit",
"(",
"None",
",",
"metadata",
")",
"return",
"BaseTable",
"(",
"ops",
",",
"table_identifier",
")"
] | [
37,
4
] | [
58,
47
] | python | en | ['en', 'error', 'th'] | False |
async_setup | (hass, config) | Track states and offer events for sensors. | Track states and offer events for sensors. | async def async_setup(hass, config):
"""Track states and offer events for sensors."""
component = hass.data[DOMAIN] = EntityComponent(
logging.getLogger(__name__), DOMAIN, hass, SCAN_INTERVAL
)
await component.async_setup(config)
component.async_register_entity_service(
SERVICE_ALARM_DISARM, ALARM_SERVICE_SCHEMA, "async_alarm_disarm"
)
component.async_register_entity_service(
SERVICE_ALARM_ARM_HOME,
ALARM_SERVICE_SCHEMA,
"async_alarm_arm_home",
[SUPPORT_ALARM_ARM_HOME],
)
component.async_register_entity_service(
SERVICE_ALARM_ARM_AWAY,
ALARM_SERVICE_SCHEMA,
"async_alarm_arm_away",
[SUPPORT_ALARM_ARM_AWAY],
)
component.async_register_entity_service(
SERVICE_ALARM_ARM_NIGHT,
ALARM_SERVICE_SCHEMA,
"async_alarm_arm_night",
[SUPPORT_ALARM_ARM_NIGHT],
)
component.async_register_entity_service(
SERVICE_ALARM_ARM_CUSTOM_BYPASS,
ALARM_SERVICE_SCHEMA,
"async_alarm_arm_custom_bypass",
[SUPPORT_ALARM_ARM_CUSTOM_BYPASS],
)
component.async_register_entity_service(
SERVICE_ALARM_TRIGGER,
ALARM_SERVICE_SCHEMA,
"async_alarm_trigger",
[SUPPORT_ALARM_TRIGGER],
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"component",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"EntityComponent",
"(",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
",",
"DOMAIN",
",",
"hass",
",",
"SCAN_INTERVAL",
")",
"await",
"component",
".",
"async_setup",
"(",
"config",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_DISARM",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_disarm\"",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_ARM_HOME",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_arm_home\"",
",",
"[",
"SUPPORT_ALARM_ARM_HOME",
"]",
",",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_ARM_AWAY",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_arm_away\"",
",",
"[",
"SUPPORT_ALARM_ARM_AWAY",
"]",
",",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_ARM_NIGHT",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_arm_night\"",
",",
"[",
"SUPPORT_ALARM_ARM_NIGHT",
"]",
",",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_ARM_CUSTOM_BYPASS",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_arm_custom_bypass\"",
",",
"[",
"SUPPORT_ALARM_ARM_CUSTOM_BYPASS",
"]",
",",
")",
"component",
".",
"async_register_entity_service",
"(",
"SERVICE_ALARM_TRIGGER",
",",
"ALARM_SERVICE_SCHEMA",
",",
"\"async_alarm_trigger\"",
",",
"[",
"SUPPORT_ALARM_TRIGGER",
"]",
",",
")",
"return",
"True"
] | [
48,
0
] | [
90,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry) | Set up a config entry. | Set up a config entry. | async def async_setup_entry(hass, entry):
"""Set up a config entry."""
return await hass.data[DOMAIN].async_setup_entry(entry) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
")",
":",
"return",
"await",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"async_setup_entry",
"(",
"entry",
")"
] | [
93,
0
] | [
95,
59
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, entry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass, entry):
"""Unload a config entry."""
return await hass.data[DOMAIN].async_unload_entry(entry) | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"entry",
")",
":",
"return",
"await",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"async_unload_entry",
"(",
"entry",
")"
] | [
98,
0
] | [
100,
60
] | python | en | ['en', 'es', 'en'] | True |
AlarmControlPanelEntity.code_format | (self) | Regex for code format or None if no code is required. | Regex for code format or None if no code is required. | def code_format(self):
"""Regex for code format or None if no code is required."""
return None | [
"def",
"code_format",
"(",
"self",
")",
":",
"return",
"None"
] | [
107,
4
] | [
109,
19
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.changed_by | (self) | Last change triggered by. | Last change triggered by. | def changed_by(self):
"""Last change triggered by."""
return None | [
"def",
"changed_by",
"(",
"self",
")",
":",
"return",
"None"
] | [
112,
4
] | [
114,
19
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.code_arm_required | (self) | Whether the code is required for arm actions. | Whether the code is required for arm actions. | def code_arm_required(self):
"""Whether the code is required for arm actions."""
return True | [
"def",
"code_arm_required",
"(",
"self",
")",
":",
"return",
"True"
] | [
117,
4
] | [
119,
19
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | def alarm_disarm(self, code=None):
"""Send disarm command."""
raise NotImplementedError() | [
"def",
"alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
121,
4
] | [
123,
35
] | python | en | ['en', 'pt', 'en'] | True |
AlarmControlPanelEntity.async_alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | async def async_alarm_disarm(self, code=None):
"""Send disarm command."""
await self.hass.async_add_executor_job(self.alarm_disarm, code) | [
"async",
"def",
"async_alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_disarm",
",",
"code",
")"
] | [
125,
4
] | [
127,
71
] | python | en | ['en', 'pt', 'en'] | True |
AlarmControlPanelEntity.alarm_arm_home | (self, code=None) | Send arm home command. | Send arm home command. | def alarm_arm_home(self, code=None):
"""Send arm home command."""
raise NotImplementedError() | [
"def",
"alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
129,
4
] | [
131,
35
] | python | en | ['en', 'pt', 'en'] | True |
AlarmControlPanelEntity.async_alarm_arm_home | (self, code=None) | Send arm home command. | Send arm home command. | async def async_alarm_arm_home(self, code=None):
"""Send arm home command."""
await self.hass.async_add_executor_job(self.alarm_arm_home, code) | [
"async",
"def",
"async_alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_arm_home",
",",
"code",
")"
] | [
133,
4
] | [
135,
73
] | python | en | ['en', 'pt', 'en'] | True |
AlarmControlPanelEntity.alarm_arm_away | (self, code=None) | Send arm away command. | Send arm away command. | def alarm_arm_away(self, code=None):
"""Send arm away command."""
raise NotImplementedError() | [
"def",
"alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
137,
4
] | [
139,
35
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.async_alarm_arm_away | (self, code=None) | Send arm away command. | Send arm away command. | async def async_alarm_arm_away(self, code=None):
"""Send arm away command."""
await self.hass.async_add_executor_job(self.alarm_arm_away, code) | [
"async",
"def",
"async_alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_arm_away",
",",
"code",
")"
] | [
141,
4
] | [
143,
73
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.alarm_arm_night | (self, code=None) | Send arm night command. | Send arm night command. | def alarm_arm_night(self, code=None):
"""Send arm night command."""
raise NotImplementedError() | [
"def",
"alarm_arm_night",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
145,
4
] | [
147,
35
] | python | en | ['en', 'zh', 'en'] | True |
AlarmControlPanelEntity.async_alarm_arm_night | (self, code=None) | Send arm night command. | Send arm night command. | async def async_alarm_arm_night(self, code=None):
"""Send arm night command."""
await self.hass.async_add_executor_job(self.alarm_arm_night, code) | [
"async",
"def",
"async_alarm_arm_night",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_arm_night",
",",
"code",
")"
] | [
149,
4
] | [
151,
74
] | python | en | ['en', 'zh', 'en'] | True |
AlarmControlPanelEntity.alarm_trigger | (self, code=None) | Send alarm trigger command. | Send alarm trigger command. | def alarm_trigger(self, code=None):
"""Send alarm trigger command."""
raise NotImplementedError() | [
"def",
"alarm_trigger",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
153,
4
] | [
155,
35
] | python | en | ['en', 'ca', 'en'] | True |
AlarmControlPanelEntity.async_alarm_trigger | (self, code=None) | Send alarm trigger command. | Send alarm trigger command. | async def async_alarm_trigger(self, code=None):
"""Send alarm trigger command."""
await self.hass.async_add_executor_job(self.alarm_trigger, code) | [
"async",
"def",
"async_alarm_trigger",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_trigger",
",",
"code",
")"
] | [
157,
4
] | [
159,
72
] | python | en | ['en', 'ca', 'en'] | True |
AlarmControlPanelEntity.alarm_arm_custom_bypass | (self, code=None) | Send arm custom bypass command. | Send arm custom bypass command. | def alarm_arm_custom_bypass(self, code=None):
"""Send arm custom bypass command."""
raise NotImplementedError() | [
"def",
"alarm_arm_custom_bypass",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
161,
4
] | [
163,
35
] | python | en | ['en', 'ga', 'en'] | True |
AlarmControlPanelEntity.async_alarm_arm_custom_bypass | (self, code=None) | Send arm custom bypass command. | Send arm custom bypass command. | async def async_alarm_arm_custom_bypass(self, code=None):
"""Send arm custom bypass command."""
await self.hass.async_add_executor_job(self.alarm_arm_custom_bypass, code) | [
"async",
"def",
"async_alarm_arm_custom_bypass",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"alarm_arm_custom_bypass",
",",
"code",
")"
] | [
165,
4
] | [
167,
82
] | python | en | ['en', 'ga', 'en'] | True |
AlarmControlPanelEntity.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features.""" | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":"
] | [
171,
4
] | [
172,
52
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanelEntity.state_attributes | (self) | Return the state attributes. | Return the state attributes. | def state_attributes(self):
"""Return the state attributes."""
return {
ATTR_CODE_FORMAT: self.code_format,
ATTR_CHANGED_BY: self.changed_by,
ATTR_CODE_ARM_REQUIRED: self.code_arm_required,
} | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_CODE_FORMAT",
":",
"self",
".",
"code_format",
",",
"ATTR_CHANGED_BY",
":",
"self",
".",
"changed_by",
",",
"ATTR_CODE_ARM_REQUIRED",
":",
"self",
".",
"code_arm_required",
",",
"}"
] | [
175,
4
] | [
181,
9
] | python | en | ['en', 'en', 'en'] | True |
AlarmControlPanel.__init_subclass__ | (cls, **kwargs) | Print deprecation warning. | Print deprecation warning. | def __init_subclass__(cls, **kwargs):
"""Print deprecation warning."""
super().__init_subclass__(**kwargs)
_LOGGER.warning(
"AlarmControlPanel is deprecated, modify %s to extend AlarmControlPanelEntity",
cls.__name__,
) | [
"def",
"__init_subclass__",
"(",
"cls",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
")",
".",
"__init_subclass__",
"(",
"*",
"*",
"kwargs",
")",
"_LOGGER",
".",
"warning",
"(",
"\"AlarmControlPanel is deprecated, modify %s to extend AlarmControlPanelEntity\"",
",",
"cls",
".",
"__name__",
",",
")"
] | [
187,
4
] | [
193,
9
] | python | de | ['de', 'sv', 'en'] | False |
async_setup | (hass: HomeAssistant, config: dict) | Set up the Sense component. | Set up the Sense component. | async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the Sense component."""
hass.data.setdefault(DOMAIN, {})
conf = config.get(DOMAIN)
if not conf:
return True
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={
CONF_EMAIL: conf[CONF_EMAIL],
CONF_PASSWORD: conf[CONF_PASSWORD],
CONF_TIMEOUT: conf[CONF_TIMEOUT],
},
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
")",
"if",
"not",
"conf",
":",
"return",
"True",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"{",
"CONF_EMAIL",
":",
"conf",
"[",
"CONF_EMAIL",
"]",
",",
"CONF_PASSWORD",
":",
"conf",
"[",
"CONF_PASSWORD",
"]",
",",
"CONF_TIMEOUT",
":",
"conf",
"[",
"CONF_TIMEOUT",
"]",
",",
"}",
",",
")",
")",
"return",
"True"
] | [
69,
0
] | [
87,
15
] | python | en | ['en', 'fr', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up Sense from a config entry. | Set up Sense from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up Sense from a config entry."""
entry_data = entry.data
email = entry_data[CONF_EMAIL]
password = entry_data[CONF_PASSWORD]
timeout = entry_data[CONF_TIMEOUT]
gateway = ASyncSenseable(api_timeout=timeout, wss_timeout=timeout)
gateway.rate_limit = ACTIVE_UPDATE_RATE
try:
await gateway.authenticate(email, password)
except SenseAuthenticationException:
_LOGGER.error("Could not authenticate with sense server")
return False
except SENSE_TIMEOUT_EXCEPTIONS as err:
raise ConfigEntryNotReady from err
sense_devices_data = SenseDevicesData()
try:
sense_discovered_devices = await gateway.get_discovered_device_data()
await gateway.update_realtime()
except SENSE_TIMEOUT_EXCEPTIONS as err:
raise ConfigEntryNotReady from err
trends_coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name=f"Sense Trends {email}",
update_method=gateway.update_trend_data,
update_interval=timedelta(seconds=300),
)
# This can take longer than 60s and we already know
# sense is online since get_discovered_device_data was
# successful so we do it later.
hass.loop.create_task(trends_coordinator.async_request_refresh())
hass.data[DOMAIN][entry.entry_id] = {
SENSE_DATA: gateway,
SENSE_DEVICES_DATA: sense_devices_data,
SENSE_TRENDS_COORDINATOR: trends_coordinator,
SENSE_DISCOVERED_DEVICES_DATA: sense_discovered_devices,
}
for component in PLATFORMS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component)
)
async def async_sense_update(_):
"""Retrieve latest state."""
try:
await gateway.update_realtime()
except SenseAPITimeoutException:
_LOGGER.error("Timeout retrieving data")
data = gateway.get_realtime()
if "devices" in data:
sense_devices_data.set_devices_data(data["devices"])
async_dispatcher_send(hass, f"{SENSE_DEVICE_UPDATE}-{gateway.sense_monitor_id}")
hass.data[DOMAIN][entry.entry_id][
"track_time_remove_callback"
] = async_track_time_interval(
hass, async_sense_update, timedelta(seconds=ACTIVE_UPDATE_RATE)
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"entry_data",
"=",
"entry",
".",
"data",
"email",
"=",
"entry_data",
"[",
"CONF_EMAIL",
"]",
"password",
"=",
"entry_data",
"[",
"CONF_PASSWORD",
"]",
"timeout",
"=",
"entry_data",
"[",
"CONF_TIMEOUT",
"]",
"gateway",
"=",
"ASyncSenseable",
"(",
"api_timeout",
"=",
"timeout",
",",
"wss_timeout",
"=",
"timeout",
")",
"gateway",
".",
"rate_limit",
"=",
"ACTIVE_UPDATE_RATE",
"try",
":",
"await",
"gateway",
".",
"authenticate",
"(",
"email",
",",
"password",
")",
"except",
"SenseAuthenticationException",
":",
"_LOGGER",
".",
"error",
"(",
"\"Could not authenticate with sense server\"",
")",
"return",
"False",
"except",
"SENSE_TIMEOUT_EXCEPTIONS",
"as",
"err",
":",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"sense_devices_data",
"=",
"SenseDevicesData",
"(",
")",
"try",
":",
"sense_discovered_devices",
"=",
"await",
"gateway",
".",
"get_discovered_device_data",
"(",
")",
"await",
"gateway",
".",
"update_realtime",
"(",
")",
"except",
"SENSE_TIMEOUT_EXCEPTIONS",
"as",
"err",
":",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"trends_coordinator",
"=",
"DataUpdateCoordinator",
"(",
"hass",
",",
"_LOGGER",
",",
"name",
"=",
"f\"Sense Trends {email}\"",
",",
"update_method",
"=",
"gateway",
".",
"update_trend_data",
",",
"update_interval",
"=",
"timedelta",
"(",
"seconds",
"=",
"300",
")",
",",
")",
"# This can take longer than 60s and we already know",
"# sense is online since get_discovered_device_data was",
"# successful so we do it later.",
"hass",
".",
"loop",
".",
"create_task",
"(",
"trends_coordinator",
".",
"async_request_refresh",
"(",
")",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"=",
"{",
"SENSE_DATA",
":",
"gateway",
",",
"SENSE_DEVICES_DATA",
":",
"sense_devices_data",
",",
"SENSE_TRENDS_COORDINATOR",
":",
"trends_coordinator",
",",
"SENSE_DISCOVERED_DEVICES_DATA",
":",
"sense_discovered_devices",
",",
"}",
"for",
"component",
"in",
"PLATFORMS",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"entry",
",",
"component",
")",
")",
"async",
"def",
"async_sense_update",
"(",
"_",
")",
":",
"\"\"\"Retrieve latest state.\"\"\"",
"try",
":",
"await",
"gateway",
".",
"update_realtime",
"(",
")",
"except",
"SenseAPITimeoutException",
":",
"_LOGGER",
".",
"error",
"(",
"\"Timeout retrieving data\"",
")",
"data",
"=",
"gateway",
".",
"get_realtime",
"(",
")",
"if",
"\"devices\"",
"in",
"data",
":",
"sense_devices_data",
".",
"set_devices_data",
"(",
"data",
"[",
"\"devices\"",
"]",
")",
"async_dispatcher_send",
"(",
"hass",
",",
"f\"{SENSE_DEVICE_UPDATE}-{gateway.sense_monitor_id}\"",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"track_time_remove_callback\"",
"]",
"=",
"async_track_time_interval",
"(",
"hass",
",",
"async_sense_update",
",",
"timedelta",
"(",
"seconds",
"=",
"ACTIVE_UPDATE_RATE",
")",
")",
"return",
"True"
] | [
90,
0
] | [
158,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, component)
for component in PLATFORMS
]
)
)
track_time_remove_callback = hass.data[DOMAIN][entry.entry_id][
"track_time_remove_callback"
]
track_time_remove_callback()
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"component",
")",
"for",
"component",
"in",
"PLATFORMS",
"]",
")",
")",
"track_time_remove_callback",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"track_time_remove_callback\"",
"]",
"track_time_remove_callback",
"(",
")",
"if",
"unload_ok",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"return",
"unload_ok"
] | [
161,
0
] | [
179,
20
] | python | en | ['en', 'es', 'en'] | True |
SenseDevicesData.set_devices_data | (self, devices) | Store a device update. | Store a device update. | def set_devices_data(self, devices):
"""Store a device update."""
self._data_by_device = {}
for device in devices:
self._data_by_device[device["id"]] = device | [
"def",
"set_devices_data",
"(",
"self",
",",
"devices",
")",
":",
"self",
".",
"_data_by_device",
"=",
"{",
"}",
"for",
"device",
"in",
"devices",
":",
"self",
".",
"_data_by_device",
"[",
"device",
"[",
"\"id\"",
"]",
"]",
"=",
"device"
] | [
58,
4
] | [
62,
55
] | python | en | ['it', 'en', 'en'] | True |
SenseDevicesData.get_device_by_id | (self, sense_device_id) | Get the latest device data. | Get the latest device data. | def get_device_by_id(self, sense_device_id):
"""Get the latest device data."""
return self._data_by_device.get(sense_device_id) | [
"def",
"get_device_by_id",
"(",
"self",
",",
"sense_device_id",
")",
":",
"return",
"self",
".",
"_data_by_device",
".",
"get",
"(",
"sense_device_id",
")"
] | [
64,
4
] | [
66,
56
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Open Hardware Monitor platform. | Set up the Open Hardware Monitor platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Open Hardware Monitor platform."""
data = OpenHardwareMonitorData(config, hass)
if data.data is None:
raise PlatformNotReady
add_entities(data.devices, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"data",
"=",
"OpenHardwareMonitorData",
"(",
"config",
",",
"hass",
")",
"if",
"data",
".",
"data",
"is",
"None",
":",
"raise",
"PlatformNotReady",
"add_entities",
"(",
"data",
".",
"devices",
",",
"True",
")"
] | [
38,
0
] | [
43,
36
] | python | en | ['en', 'zu', 'en'] | True |
OpenHardwareMonitorDevice.__init__ | (self, data, name, path, unit_of_measurement) | Initialize an OpenHardwareMonitor sensor. | Initialize an OpenHardwareMonitor sensor. | def __init__(self, data, name, path, unit_of_measurement):
"""Initialize an OpenHardwareMonitor sensor."""
self._name = name
self._data = data
self.path = path
self.attributes = {}
self._unit_of_measurement = unit_of_measurement
self.value = None | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"name",
",",
"path",
",",
"unit_of_measurement",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_data",
"=",
"data",
"self",
".",
"path",
"=",
"path",
"self",
".",
"attributes",
"=",
"{",
"}",
"self",
".",
"_unit_of_measurement",
"=",
"unit_of_measurement",
"self",
".",
"value",
"=",
"None"
] | [
49,
4
] | [
57,
25
] | python | en | ['en', 'zh-Latn', 'en'] | True |
OpenHardwareMonitorDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
60,
4
] | [
62,
25
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorDevice.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
65,
4
] | [
67,
40
] | python | en | ['en', 'la', 'en'] | True |
OpenHardwareMonitorDevice.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self.value | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"value"
] | [
70,
4
] | [
72,
25
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorDevice.state_attributes | (self) | Return the state attributes of the sun. | Return the state attributes of the sun. | def state_attributes(self):
"""Return the state attributes of the sun."""
return self.attributes | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"attributes"
] | [
75,
4
] | [
77,
30
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorDevice.parse_number | (cls, string) | In some locales a decimal numbers uses ',' instead of '.'. | In some locales a decimal numbers uses ',' instead of '.'. | def parse_number(cls, string):
"""In some locales a decimal numbers uses ',' instead of '.'."""
return string.replace(",", ".") | [
"def",
"parse_number",
"(",
"cls",
",",
"string",
")",
":",
"return",
"string",
".",
"replace",
"(",
"\",\"",
",",
"\".\"",
")"
] | [
80,
4
] | [
82,
39
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorDevice.update | (self) | Update the device from a new JSON object. | Update the device from a new JSON object. | def update(self):
"""Update the device from a new JSON object."""
self._data.update()
array = self._data.data[OHM_CHILDREN]
_attributes = {}
for path_index in range(0, len(self.path)):
path_number = self.path[path_index]
values = array[path_number]
if path_index == len(self.path) - 1:
self.value = self.parse_number(values[OHM_VALUE].split(" ")[0])
_attributes.update(
{
"name": values[OHM_NAME],
STATE_MIN_VALUE: self.parse_number(
values[OHM_MIN].split(" ")[0]
),
STATE_MAX_VALUE: self.parse_number(
values[OHM_MAX].split(" ")[0]
),
}
)
self.attributes = _attributes
return
array = array[path_number][OHM_CHILDREN]
_attributes.update({"level_%s" % path_index: values[OHM_NAME]}) | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_data",
".",
"update",
"(",
")",
"array",
"=",
"self",
".",
"_data",
".",
"data",
"[",
"OHM_CHILDREN",
"]",
"_attributes",
"=",
"{",
"}",
"for",
"path_index",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"path",
")",
")",
":",
"path_number",
"=",
"self",
".",
"path",
"[",
"path_index",
"]",
"values",
"=",
"array",
"[",
"path_number",
"]",
"if",
"path_index",
"==",
"len",
"(",
"self",
".",
"path",
")",
"-",
"1",
":",
"self",
".",
"value",
"=",
"self",
".",
"parse_number",
"(",
"values",
"[",
"OHM_VALUE",
"]",
".",
"split",
"(",
"\" \"",
")",
"[",
"0",
"]",
")",
"_attributes",
".",
"update",
"(",
"{",
"\"name\"",
":",
"values",
"[",
"OHM_NAME",
"]",
",",
"STATE_MIN_VALUE",
":",
"self",
".",
"parse_number",
"(",
"values",
"[",
"OHM_MIN",
"]",
".",
"split",
"(",
"\" \"",
")",
"[",
"0",
"]",
")",
",",
"STATE_MAX_VALUE",
":",
"self",
".",
"parse_number",
"(",
"values",
"[",
"OHM_MAX",
"]",
".",
"split",
"(",
"\" \"",
")",
"[",
"0",
"]",
")",
",",
"}",
")",
"self",
".",
"attributes",
"=",
"_attributes",
"return",
"array",
"=",
"array",
"[",
"path_number",
"]",
"[",
"OHM_CHILDREN",
"]",
"_attributes",
".",
"update",
"(",
"{",
"\"level_%s\"",
"%",
"path_index",
":",
"values",
"[",
"OHM_NAME",
"]",
"}",
")"
] | [
84,
4
] | [
112,
75
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorData.__init__ | (self, config, hass) | Initialize the Open Hardware Monitor data-handler. | Initialize the Open Hardware Monitor data-handler. | def __init__(self, config, hass):
"""Initialize the Open Hardware Monitor data-handler."""
self.data = None
self._config = config
self._hass = hass
self.devices = []
self.initialize(utcnow()) | [
"def",
"__init__",
"(",
"self",
",",
"config",
",",
"hass",
")",
":",
"self",
".",
"data",
"=",
"None",
"self",
".",
"_config",
"=",
"config",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"devices",
"=",
"[",
"]",
"self",
".",
"initialize",
"(",
"utcnow",
"(",
")",
")"
] | [
118,
4
] | [
124,
33
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorData.update | (self) | Hit by the timer with the configured interval. | Hit by the timer with the configured interval. | def update(self):
"""Hit by the timer with the configured interval."""
if self.data is None:
self.initialize(utcnow())
else:
self.refresh() | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"self",
".",
"data",
"is",
"None",
":",
"self",
".",
"initialize",
"(",
"utcnow",
"(",
")",
")",
"else",
":",
"self",
".",
"refresh",
"(",
")"
] | [
127,
4
] | [
132,
26
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorData.refresh | (self) | Download and parse JSON from OHM. | Download and parse JSON from OHM. | def refresh(self):
"""Download and parse JSON from OHM."""
data_url = (
f"http://{self._config.get(CONF_HOST)}:"
f"{self._config.get(CONF_PORT)}/data.json"
)
try:
response = requests.get(data_url, timeout=30)
self.data = response.json()
except requests.exceptions.ConnectionError:
_LOGGER.debug("ConnectionError: Is OpenHardwareMonitor running?") | [
"def",
"refresh",
"(",
"self",
")",
":",
"data_url",
"=",
"(",
"f\"http://{self._config.get(CONF_HOST)}:\"",
"f\"{self._config.get(CONF_PORT)}/data.json\"",
")",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"data_url",
",",
"timeout",
"=",
"30",
")",
"self",
".",
"data",
"=",
"response",
".",
"json",
"(",
")",
"except",
"requests",
".",
"exceptions",
".",
"ConnectionError",
":",
"_LOGGER",
".",
"debug",
"(",
"\"ConnectionError: Is OpenHardwareMonitor running?\"",
")"
] | [
134,
4
] | [
145,
77
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorData.initialize | (self, now) | Parse of the sensors and adding of devices. | Parse of the sensors and adding of devices. | def initialize(self, now):
"""Parse of the sensors and adding of devices."""
self.refresh()
if self.data is None:
return
self.devices = self.parse_children(self.data, [], [], []) | [
"def",
"initialize",
"(",
"self",
",",
"now",
")",
":",
"self",
".",
"refresh",
"(",
")",
"if",
"self",
".",
"data",
"is",
"None",
":",
"return",
"self",
".",
"devices",
"=",
"self",
".",
"parse_children",
"(",
"self",
".",
"data",
",",
"[",
"]",
",",
"[",
"]",
",",
"[",
"]",
")"
] | [
147,
4
] | [
154,
65
] | python | en | ['en', 'en', 'en'] | True |
OpenHardwareMonitorData.parse_children | (self, json, devices, path, names) | Recursively loop through child objects, finding the values. | Recursively loop through child objects, finding the values. | def parse_children(self, json, devices, path, names):
"""Recursively loop through child objects, finding the values."""
result = devices.copy()
if json[OHM_CHILDREN]:
for child_index in range(0, len(json[OHM_CHILDREN])):
child_path = path.copy()
child_path.append(child_index)
child_names = names.copy()
if path:
child_names.append(json[OHM_NAME])
obj = json[OHM_CHILDREN][child_index]
added_devices = self.parse_children(
obj, devices, child_path, child_names
)
result = result + added_devices
return result
if json[OHM_VALUE].find(" ") == -1:
return result
unit_of_measurement = json[OHM_VALUE].split(" ")[1]
child_names = names.copy()
child_names.append(json[OHM_NAME])
fullname = " ".join(child_names)
dev = OpenHardwareMonitorDevice(self, fullname, path, unit_of_measurement)
result.append(dev)
return result | [
"def",
"parse_children",
"(",
"self",
",",
"json",
",",
"devices",
",",
"path",
",",
"names",
")",
":",
"result",
"=",
"devices",
".",
"copy",
"(",
")",
"if",
"json",
"[",
"OHM_CHILDREN",
"]",
":",
"for",
"child_index",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"json",
"[",
"OHM_CHILDREN",
"]",
")",
")",
":",
"child_path",
"=",
"path",
".",
"copy",
"(",
")",
"child_path",
".",
"append",
"(",
"child_index",
")",
"child_names",
"=",
"names",
".",
"copy",
"(",
")",
"if",
"path",
":",
"child_names",
".",
"append",
"(",
"json",
"[",
"OHM_NAME",
"]",
")",
"obj",
"=",
"json",
"[",
"OHM_CHILDREN",
"]",
"[",
"child_index",
"]",
"added_devices",
"=",
"self",
".",
"parse_children",
"(",
"obj",
",",
"devices",
",",
"child_path",
",",
"child_names",
")",
"result",
"=",
"result",
"+",
"added_devices",
"return",
"result",
"if",
"json",
"[",
"OHM_VALUE",
"]",
".",
"find",
"(",
"\" \"",
")",
"==",
"-",
"1",
":",
"return",
"result",
"unit_of_measurement",
"=",
"json",
"[",
"OHM_VALUE",
"]",
".",
"split",
"(",
"\" \"",
")",
"[",
"1",
"]",
"child_names",
"=",
"names",
".",
"copy",
"(",
")",
"child_names",
".",
"append",
"(",
"json",
"[",
"OHM_NAME",
"]",
")",
"fullname",
"=",
"\" \"",
".",
"join",
"(",
"child_names",
")",
"dev",
"=",
"OpenHardwareMonitorDevice",
"(",
"self",
",",
"fullname",
",",
"path",
",",
"unit_of_measurement",
")",
"result",
".",
"append",
"(",
"dev",
")",
"return",
"result"
] | [
156,
4
] | [
189,
21
] | python | en | ['en', 'en', 'en'] | True |
_has_all_unique_names_and_ports | (bridges) | Validate that each homekit bridge configured has a unique name. | Validate that each homekit bridge configured has a unique name. | def _has_all_unique_names_and_ports(bridges):
"""Validate that each homekit bridge configured has a unique name."""
names = [bridge[CONF_NAME] for bridge in bridges]
ports = [bridge[CONF_PORT] for bridge in bridges]
vol.Schema(vol.Unique())(names)
vol.Schema(vol.Unique())(ports)
return bridges | [
"def",
"_has_all_unique_names_and_ports",
"(",
"bridges",
")",
":",
"names",
"=",
"[",
"bridge",
"[",
"CONF_NAME",
"]",
"for",
"bridge",
"in",
"bridges",
"]",
"ports",
"=",
"[",
"bridge",
"[",
"CONF_PORT",
"]",
"for",
"bridge",
"in",
"bridges",
"]",
"vol",
".",
"Schema",
"(",
"vol",
".",
"Unique",
"(",
")",
")",
"(",
"names",
")",
"vol",
".",
"Schema",
"(",
"vol",
".",
"Unique",
"(",
")",
")",
"(",
"ports",
")",
"return",
"bridges"
] | [
105,
0
] | [
111,
18
] | python | en | ['en', 'fr', 'en'] | True |
_async_get_entries_by_name | (current_entries) | Return a dict of the entries by name. | Return a dict of the entries by name. | def _async_get_entries_by_name(current_entries):
"""Return a dict of the entries by name."""
# For backwards compat, its possible the first bridge is using the default
# name.
return {entry.data.get(CONF_NAME, BRIDGE_NAME): entry for entry in current_entries} | [
"def",
"_async_get_entries_by_name",
"(",
"current_entries",
")",
":",
"# For backwards compat, its possible the first bridge is using the default",
"# name.",
"return",
"{",
"entry",
".",
"data",
".",
"get",
"(",
"CONF_NAME",
",",
"BRIDGE_NAME",
")",
":",
"entry",
"for",
"entry",
"in",
"current_entries",
"}"
] | [
148,
0
] | [
153,
87
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistant, config: dict) | Set up the HomeKit from yaml. | Set up the HomeKit from yaml. | async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the HomeKit from yaml."""
hass.data.setdefault(DOMAIN, {})
_async_register_events_and_services(hass)
if DOMAIN not in config:
return True
current_entries = hass.config_entries.async_entries(DOMAIN)
entries_by_name = _async_get_entries_by_name(current_entries)
for index, conf in enumerate(config[DOMAIN]):
if _async_update_config_entry_if_from_yaml(hass, entries_by_name, conf):
continue
conf[CONF_ENTRY_INDEX] = index
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data=conf,
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"_async_register_events_and_services",
"(",
"hass",
")",
"if",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"True",
"current_entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"entries_by_name",
"=",
"_async_get_entries_by_name",
"(",
"current_entries",
")",
"for",
"index",
",",
"conf",
"in",
"enumerate",
"(",
"config",
"[",
"DOMAIN",
"]",
")",
":",
"if",
"_async_update_config_entry_if_from_yaml",
"(",
"hass",
",",
"entries_by_name",
",",
"conf",
")",
":",
"continue",
"conf",
"[",
"CONF_ENTRY_INDEX",
"]",
"=",
"index",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_IMPORT",
"}",
",",
"data",
"=",
"conf",
",",
")",
")",
"return",
"True"
] | [
156,
0
] | [
181,
15
] | python | en | ['en', 'sn', 'en'] | True |
_async_update_config_entry_if_from_yaml | (hass, entries_by_name, conf) | Update a config entry with the latest yaml.
Returns True if a matching config entry was found
Returns False if there is no matching config entry
| Update a config entry with the latest yaml. | def _async_update_config_entry_if_from_yaml(hass, entries_by_name, conf):
"""Update a config entry with the latest yaml.
Returns True if a matching config entry was found
Returns False if there is no matching config entry
"""
bridge_name = conf[CONF_NAME]
if (
bridge_name in entries_by_name
and entries_by_name[bridge_name].source == SOURCE_IMPORT
):
entry = entries_by_name[bridge_name]
# If they alter the yaml config we import the changes
# since there currently is no practical way to support
# all the options in the UI at this time.
data = conf.copy()
options = {}
for key in CONFIG_OPTIONS:
options[key] = data[key]
del data[key]
hass.config_entries.async_update_entry(entry, data=data, options=options)
return True
return False | [
"def",
"_async_update_config_entry_if_from_yaml",
"(",
"hass",
",",
"entries_by_name",
",",
"conf",
")",
":",
"bridge_name",
"=",
"conf",
"[",
"CONF_NAME",
"]",
"if",
"(",
"bridge_name",
"in",
"entries_by_name",
"and",
"entries_by_name",
"[",
"bridge_name",
"]",
".",
"source",
"==",
"SOURCE_IMPORT",
")",
":",
"entry",
"=",
"entries_by_name",
"[",
"bridge_name",
"]",
"# If they alter the yaml config we import the changes",
"# since there currently is no practical way to support",
"# all the options in the UI at this time.",
"data",
"=",
"conf",
".",
"copy",
"(",
")",
"options",
"=",
"{",
"}",
"for",
"key",
"in",
"CONFIG_OPTIONS",
":",
"options",
"[",
"key",
"]",
"=",
"data",
"[",
"key",
"]",
"del",
"data",
"[",
"key",
"]",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"data",
",",
"options",
"=",
"options",
")",
"return",
"True",
"return",
"False"
] | [
185,
0
] | [
211,
16
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up HomeKit from a config entry. | Set up HomeKit from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up HomeKit from a config entry."""
_async_import_options_from_data_if_missing(hass, entry)
conf = entry.data
options = entry.options
name = conf[CONF_NAME]
port = conf[CONF_PORT]
_LOGGER.debug("Begin setup HomeKit for %s", name)
# If the previous instance hasn't cleaned up yet
# we need to wait a bit
if not await hass.async_add_executor_job(port_is_available, port):
_LOGGER.warning("The local port %s is in use", port)
raise ConfigEntryNotReady
if CONF_ENTRY_INDEX in conf and conf[CONF_ENTRY_INDEX] == 0:
_LOGGER.debug("Migrating legacy HomeKit data for %s", name)
hass.async_add_executor_job(
migrate_filesystem_state_data_for_primary_imported_entry_id,
hass,
entry.entry_id,
)
aid_storage = AccessoryAidStorage(hass, entry.entry_id)
await aid_storage.async_initialize()
# ip_address and advertise_ip are yaml only
ip_address = conf.get(CONF_IP_ADDRESS)
advertise_ip = conf.get(CONF_ADVERTISE_IP)
homekit_mode = options.get(CONF_HOMEKIT_MODE, DEFAULT_HOMEKIT_MODE)
entity_config = options.get(CONF_ENTITY_CONFIG, {}).copy()
auto_start = options.get(CONF_AUTO_START, DEFAULT_AUTO_START)
safe_mode = options.get(CONF_SAFE_MODE, DEFAULT_SAFE_MODE)
entity_filter = FILTER_SCHEMA(options.get(CONF_FILTER, {}))
homekit = HomeKit(
hass,
name,
port,
ip_address,
entity_filter,
entity_config,
safe_mode,
homekit_mode,
advertise_ip,
entry.entry_id,
)
zeroconf_instance = await zeroconf.async_get_instance(hass)
await hass.async_add_executor_job(homekit.setup, zeroconf_instance)
undo_listener = entry.add_update_listener(_async_update_listener)
hass.data[DOMAIN][entry.entry_id] = {
AID_STORAGE: aid_storage,
HOMEKIT: homekit,
UNDO_UPDATE_LISTENER: undo_listener,
}
if hass.state == CoreState.running:
await homekit.async_start()
elif auto_start:
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, homekit.async_start)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"_async_import_options_from_data_if_missing",
"(",
"hass",
",",
"entry",
")",
"conf",
"=",
"entry",
".",
"data",
"options",
"=",
"entry",
".",
"options",
"name",
"=",
"conf",
"[",
"CONF_NAME",
"]",
"port",
"=",
"conf",
"[",
"CONF_PORT",
"]",
"_LOGGER",
".",
"debug",
"(",
"\"Begin setup HomeKit for %s\"",
",",
"name",
")",
"# If the previous instance hasn't cleaned up yet",
"# we need to wait a bit",
"if",
"not",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"port_is_available",
",",
"port",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"The local port %s is in use\"",
",",
"port",
")",
"raise",
"ConfigEntryNotReady",
"if",
"CONF_ENTRY_INDEX",
"in",
"conf",
"and",
"conf",
"[",
"CONF_ENTRY_INDEX",
"]",
"==",
"0",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Migrating legacy HomeKit data for %s\"",
",",
"name",
")",
"hass",
".",
"async_add_executor_job",
"(",
"migrate_filesystem_state_data_for_primary_imported_entry_id",
",",
"hass",
",",
"entry",
".",
"entry_id",
",",
")",
"aid_storage",
"=",
"AccessoryAidStorage",
"(",
"hass",
",",
"entry",
".",
"entry_id",
")",
"await",
"aid_storage",
".",
"async_initialize",
"(",
")",
"# ip_address and advertise_ip are yaml only",
"ip_address",
"=",
"conf",
".",
"get",
"(",
"CONF_IP_ADDRESS",
")",
"advertise_ip",
"=",
"conf",
".",
"get",
"(",
"CONF_ADVERTISE_IP",
")",
"homekit_mode",
"=",
"options",
".",
"get",
"(",
"CONF_HOMEKIT_MODE",
",",
"DEFAULT_HOMEKIT_MODE",
")",
"entity_config",
"=",
"options",
".",
"get",
"(",
"CONF_ENTITY_CONFIG",
",",
"{",
"}",
")",
".",
"copy",
"(",
")",
"auto_start",
"=",
"options",
".",
"get",
"(",
"CONF_AUTO_START",
",",
"DEFAULT_AUTO_START",
")",
"safe_mode",
"=",
"options",
".",
"get",
"(",
"CONF_SAFE_MODE",
",",
"DEFAULT_SAFE_MODE",
")",
"entity_filter",
"=",
"FILTER_SCHEMA",
"(",
"options",
".",
"get",
"(",
"CONF_FILTER",
",",
"{",
"}",
")",
")",
"homekit",
"=",
"HomeKit",
"(",
"hass",
",",
"name",
",",
"port",
",",
"ip_address",
",",
"entity_filter",
",",
"entity_config",
",",
"safe_mode",
",",
"homekit_mode",
",",
"advertise_ip",
",",
"entry",
".",
"entry_id",
",",
")",
"zeroconf_instance",
"=",
"await",
"zeroconf",
".",
"async_get_instance",
"(",
"hass",
")",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"homekit",
".",
"setup",
",",
"zeroconf_instance",
")",
"undo_listener",
"=",
"entry",
".",
"add_update_listener",
"(",
"_async_update_listener",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"=",
"{",
"AID_STORAGE",
":",
"aid_storage",
",",
"HOMEKIT",
":",
"homekit",
",",
"UNDO_UPDATE_LISTENER",
":",
"undo_listener",
",",
"}",
"if",
"hass",
".",
"state",
"==",
"CoreState",
".",
"running",
":",
"await",
"homekit",
".",
"async_start",
"(",
")",
"elif",
"auto_start",
":",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STARTED",
",",
"homekit",
".",
"async_start",
")",
"return",
"True"
] | [
214,
0
] | [
279,
15
] | python | en | ['en', 'en', 'en'] | True |
_async_update_listener | (hass: HomeAssistant, entry: ConfigEntry) | Handle options update. | Handle options update. | async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry):
"""Handle options update."""
if entry.source == SOURCE_IMPORT:
return
await hass.config_entries.async_reload(entry.entry_id) | [
"async",
"def",
"_async_update_listener",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"if",
"entry",
".",
"source",
"==",
"SOURCE_IMPORT",
":",
"return",
"await",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"entry",
".",
"entry_id",
")"
] | [
282,
0
] | [
286,
58
] | python | en | ['en', 'nl', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
dismiss_setup_message(hass, entry.entry_id)
hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]()
homekit = hass.data[DOMAIN][entry.entry_id][HOMEKIT]
if homekit.status == STATUS_RUNNING:
await homekit.async_stop()
for _ in range(0, SHUTDOWN_TIMEOUT):
if not await hass.async_add_executor_job(
port_is_available, entry.data[CONF_PORT]
):
_LOGGER.info("Waiting for the HomeKit server to shutdown")
await asyncio.sleep(1)
hass.data[DOMAIN].pop(entry.entry_id)
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"dismiss_setup_message",
"(",
"hass",
",",
"entry",
".",
"entry_id",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"UNDO_UPDATE_LISTENER",
"]",
"(",
")",
"homekit",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"HOMEKIT",
"]",
"if",
"homekit",
".",
"status",
"==",
"STATUS_RUNNING",
":",
"await",
"homekit",
".",
"async_stop",
"(",
")",
"for",
"_",
"in",
"range",
"(",
"0",
",",
"SHUTDOWN_TIMEOUT",
")",
":",
"if",
"not",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"port_is_available",
",",
"entry",
".",
"data",
"[",
"CONF_PORT",
"]",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Waiting for the HomeKit server to shutdown\"",
")",
"await",
"asyncio",
".",
"sleep",
"(",
"1",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"return",
"True"
] | [
289,
0
] | [
309,
15
] | python | en | ['en', 'es', 'en'] | True |
async_remove_entry | (hass: HomeAssistant, entry: ConfigEntry) | Remove a config entry. | Remove a config entry. | async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Remove a config entry."""
return await hass.async_add_executor_job(
remove_state_files_for_entry_id, hass, entry.entry_id
) | [
"async",
"def",
"async_remove_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"return",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"remove_state_files_for_entry_id",
",",
"hass",
",",
"entry",
".",
"entry_id",
")"
] | [
312,
0
] | [
316,
5
] | python | en | ['en', 'gl', 'en'] | True |
_async_register_events_and_services | (hass: HomeAssistant) | Register events and services for HomeKit. | Register events and services for HomeKit. | def _async_register_events_and_services(hass: HomeAssistant):
"""Register events and services for HomeKit."""
hass.http.register_view(HomeKitPairingQRView)
def handle_homekit_reset_accessory(service):
"""Handle start HomeKit service call."""
for entry_id in hass.data[DOMAIN]:
if HOMEKIT not in hass.data[DOMAIN][entry_id]:
continue
homekit = hass.data[DOMAIN][entry_id][HOMEKIT]
if homekit.status != STATUS_RUNNING:
_LOGGER.warning(
"HomeKit is not running. Either it is waiting to be "
"started or has been stopped"
)
continue
entity_ids = service.data.get("entity_id")
homekit.reset_accessories(entity_ids)
hass.services.async_register(
DOMAIN,
SERVICE_HOMEKIT_RESET_ACCESSORY,
handle_homekit_reset_accessory,
schema=RESET_ACCESSORY_SERVICE_SCHEMA,
)
async def async_handle_homekit_service_start(service):
"""Handle start HomeKit service call."""
tasks = []
for entry_id in hass.data[DOMAIN]:
if HOMEKIT not in hass.data[DOMAIN][entry_id]:
continue
homekit = hass.data[DOMAIN][entry_id][HOMEKIT]
if homekit.status == STATUS_RUNNING:
_LOGGER.debug("HomeKit is already running")
continue
if homekit.status != STATUS_READY:
_LOGGER.warning(
"HomeKit is not ready. Either it is already starting up or has "
"been stopped"
)
continue
tasks.append(homekit.async_start())
await asyncio.gather(*tasks)
hass.services.async_register(
DOMAIN, SERVICE_HOMEKIT_START, async_handle_homekit_service_start
)
async def _handle_homekit_reload(service):
"""Handle start HomeKit service call."""
config = await async_integration_yaml_config(hass, DOMAIN)
if not config or DOMAIN not in config:
return
current_entries = hass.config_entries.async_entries(DOMAIN)
entries_by_name = _async_get_entries_by_name(current_entries)
for conf in config[DOMAIN]:
_async_update_config_entry_if_from_yaml(hass, entries_by_name, conf)
reload_tasks = [
hass.config_entries.async_reload(entry.entry_id)
for entry in current_entries
]
await asyncio.gather(*reload_tasks)
hass.helpers.service.async_register_admin_service(
DOMAIN,
SERVICE_RELOAD,
_handle_homekit_reload,
) | [
"def",
"_async_register_events_and_services",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"hass",
".",
"http",
".",
"register_view",
"(",
"HomeKitPairingQRView",
")",
"def",
"handle_homekit_reset_accessory",
"(",
"service",
")",
":",
"\"\"\"Handle start HomeKit service call.\"\"\"",
"for",
"entry_id",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"if",
"HOMEKIT",
"not",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
":",
"continue",
"homekit",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
"[",
"HOMEKIT",
"]",
"if",
"homekit",
".",
"status",
"!=",
"STATUS_RUNNING",
":",
"_LOGGER",
".",
"warning",
"(",
"\"HomeKit is not running. Either it is waiting to be \"",
"\"started or has been stopped\"",
")",
"continue",
"entity_ids",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"entity_id\"",
")",
"homekit",
".",
"reset_accessories",
"(",
"entity_ids",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"SERVICE_HOMEKIT_RESET_ACCESSORY",
",",
"handle_homekit_reset_accessory",
",",
"schema",
"=",
"RESET_ACCESSORY_SERVICE_SCHEMA",
",",
")",
"async",
"def",
"async_handle_homekit_service_start",
"(",
"service",
")",
":",
"\"\"\"Handle start HomeKit service call.\"\"\"",
"tasks",
"=",
"[",
"]",
"for",
"entry_id",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"if",
"HOMEKIT",
"not",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
":",
"continue",
"homekit",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry_id",
"]",
"[",
"HOMEKIT",
"]",
"if",
"homekit",
".",
"status",
"==",
"STATUS_RUNNING",
":",
"_LOGGER",
".",
"debug",
"(",
"\"HomeKit is already running\"",
")",
"continue",
"if",
"homekit",
".",
"status",
"!=",
"STATUS_READY",
":",
"_LOGGER",
".",
"warning",
"(",
"\"HomeKit is not ready. Either it is already starting up or has \"",
"\"been stopped\"",
")",
"continue",
"tasks",
".",
"append",
"(",
"homekit",
".",
"async_start",
"(",
")",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"tasks",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"SERVICE_HOMEKIT_START",
",",
"async_handle_homekit_service_start",
")",
"async",
"def",
"_handle_homekit_reload",
"(",
"service",
")",
":",
"\"\"\"Handle start HomeKit service call.\"\"\"",
"config",
"=",
"await",
"async_integration_yaml_config",
"(",
"hass",
",",
"DOMAIN",
")",
"if",
"not",
"config",
"or",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"current_entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"entries_by_name",
"=",
"_async_get_entries_by_name",
"(",
"current_entries",
")",
"for",
"conf",
"in",
"config",
"[",
"DOMAIN",
"]",
":",
"_async_update_config_entry_if_from_yaml",
"(",
"hass",
",",
"entries_by_name",
",",
"conf",
")",
"reload_tasks",
"=",
"[",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"entry",
".",
"entry_id",
")",
"for",
"entry",
"in",
"current_entries",
"]",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"reload_tasks",
")",
"hass",
".",
"helpers",
".",
"service",
".",
"async_register_admin_service",
"(",
"DOMAIN",
",",
"SERVICE_RELOAD",
",",
"_handle_homekit_reload",
",",
")"
] | [
335,
0
] | [
409,
5
] | python | en | ['en', 'en', 'en'] | True |
HomeKit.__init__ | (
self,
hass,
name,
port,
ip_address,
entity_filter,
entity_config,
safe_mode,
homekit_mode,
advertise_ip=None,
entry_id=None,
) | Initialize a HomeKit object. | Initialize a HomeKit object. | def __init__(
self,
hass,
name,
port,
ip_address,
entity_filter,
entity_config,
safe_mode,
homekit_mode,
advertise_ip=None,
entry_id=None,
):
"""Initialize a HomeKit object."""
self.hass = hass
self._name = name
self._port = port
self._ip_address = ip_address
self._filter = entity_filter
self._config = entity_config
self._safe_mode = safe_mode
self._advertise_ip = advertise_ip
self._entry_id = entry_id
self._homekit_mode = homekit_mode
self.status = STATUS_READY
self.bridge = None
self.driver = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"name",
",",
"port",
",",
"ip_address",
",",
"entity_filter",
",",
"entity_config",
",",
"safe_mode",
",",
"homekit_mode",
",",
"advertise_ip",
"=",
"None",
",",
"entry_id",
"=",
"None",
",",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_port",
"=",
"port",
"self",
".",
"_ip_address",
"=",
"ip_address",
"self",
".",
"_filter",
"=",
"entity_filter",
"self",
".",
"_config",
"=",
"entity_config",
"self",
".",
"_safe_mode",
"=",
"safe_mode",
"self",
".",
"_advertise_ip",
"=",
"advertise_ip",
"self",
".",
"_entry_id",
"=",
"entry_id",
"self",
".",
"_homekit_mode",
"=",
"homekit_mode",
"self",
".",
"status",
"=",
"STATUS_READY",
"self",
".",
"bridge",
"=",
"None",
"self",
".",
"driver",
"=",
"None"
] | [
415,
4
] | [
442,
26
] | python | en | ['en', 'haw', 'en'] | True |
HomeKit.setup | (self, zeroconf_instance) | Set up bridge and accessory driver. | Set up bridge and accessory driver. | def setup(self, zeroconf_instance):
"""Set up bridge and accessory driver."""
# pylint: disable=import-outside-toplevel
from .accessories import HomeDriver
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.async_stop)
ip_addr = self._ip_address or get_local_ip()
persist_file = get_persist_fullpath_for_entry_id(self.hass, self._entry_id)
self.driver = HomeDriver(
self.hass,
self._entry_id,
self._name,
loop=self.hass.loop,
address=ip_addr,
port=self._port,
persist_file=persist_file,
advertised_address=self._advertise_ip,
zeroconf_instance=zeroconf_instance,
)
# If we do not load the mac address will be wrong
# as pyhap uses a random one until state is restored
if os.path.exists(persist_file):
self.driver.load()
else:
self.driver.persist()
if self._safe_mode:
_LOGGER.debug("Safe_mode selected for %s", self._name)
self.driver.safe_mode = True | [
"def",
"setup",
"(",
"self",
",",
"zeroconf_instance",
")",
":",
"# pylint: disable=import-outside-toplevel",
"from",
".",
"accessories",
"import",
"HomeDriver",
"self",
".",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"self",
".",
"async_stop",
")",
"ip_addr",
"=",
"self",
".",
"_ip_address",
"or",
"get_local_ip",
"(",
")",
"persist_file",
"=",
"get_persist_fullpath_for_entry_id",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_entry_id",
")",
"self",
".",
"driver",
"=",
"HomeDriver",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_entry_id",
",",
"self",
".",
"_name",
",",
"loop",
"=",
"self",
".",
"hass",
".",
"loop",
",",
"address",
"=",
"ip_addr",
",",
"port",
"=",
"self",
".",
"_port",
",",
"persist_file",
"=",
"persist_file",
",",
"advertised_address",
"=",
"self",
".",
"_advertise_ip",
",",
"zeroconf_instance",
"=",
"zeroconf_instance",
",",
")",
"# If we do not load the mac address will be wrong",
"# as pyhap uses a random one until state is restored",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"persist_file",
")",
":",
"self",
".",
"driver",
".",
"load",
"(",
")",
"else",
":",
"self",
".",
"driver",
".",
"persist",
"(",
")",
"if",
"self",
".",
"_safe_mode",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Safe_mode selected for %s\"",
",",
"self",
".",
"_name",
")",
"self",
".",
"driver",
".",
"safe_mode",
"=",
"True"
] | [
444,
4
] | [
474,
40
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.