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_empty_update | (hass) | Test updating with no state from monoprice. | Test updating with no state from monoprice. | async def test_empty_update(hass):
"""Test updating with no state from monoprice."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
# Changing media player to new state
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 0.0}
)
await _call_media_player_service(
hass, SERVICE_SELECT_SOURCE, {"entity_id": ZONE_1_ID, "source": "one"}
)
monoprice.set_source(11, 3)
monoprice.set_volume(11, 38)
with patch.object(MockMonoprice, "zone_status", return_value=None):
await async_update_entity(hass, ZONE_1_ID)
await hass.async_block_till_done()
state = hass.states.get(ZONE_1_ID)
assert state.attributes[ATTR_MEDIA_VOLUME_LEVEL] == 0.0
assert state.attributes[ATTR_INPUT_SOURCE] == "one" | [
"async",
"def",
"test_empty_update",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"# Changing media player to new state",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"volume_level\"",
":",
"0.0",
"}",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"source\"",
":",
"\"one\"",
"}",
")",
"monoprice",
".",
"set_source",
"(",
"11",
",",
"3",
")",
"monoprice",
".",
"set_volume",
"(",
"11",
",",
"38",
")",
"with",
"patch",
".",
"object",
"(",
"MockMonoprice",
",",
"\"zone_status\"",
",",
"return_value",
"=",
"None",
")",
":",
"await",
"async_update_entity",
"(",
"hass",
",",
"ZONE_1_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ZONE_1_ID",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_MEDIA_VOLUME_LEVEL",
"]",
"==",
"0.0",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE",
"]",
"==",
"\"one\""
] | [
333,
0
] | [
356,
55
] | python | en | ['en', 'en', 'en'] | True |
test_supported_features | (hass) | Test supported features property. | Test supported features property. | async def test_supported_features(hass):
"""Test supported features property."""
await _setup_monoprice(hass, MockMonoprice())
state = hass.states.get(ZONE_1_ID)
assert (
SUPPORT_VOLUME_MUTE
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_STEP
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_SELECT_SOURCE
== state.attributes["supported_features"]
) | [
"async",
"def",
"test_supported_features",
"(",
"hass",
")",
":",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"MockMonoprice",
"(",
")",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ZONE_1_ID",
")",
"assert",
"(",
"SUPPORT_VOLUME_MUTE",
"|",
"SUPPORT_VOLUME_SET",
"|",
"SUPPORT_VOLUME_STEP",
"|",
"SUPPORT_TURN_ON",
"|",
"SUPPORT_TURN_OFF",
"|",
"SUPPORT_SELECT_SOURCE",
"==",
"state",
".",
"attributes",
"[",
"\"supported_features\"",
"]",
")"
] | [
359,
0
] | [
372,
5
] | python | en | ['en', 'en', 'en'] | True |
test_source_list | (hass) | Test source list property. | Test source list property. | async def test_source_list(hass):
"""Test source list property."""
await _setup_monoprice(hass, MockMonoprice())
state = hass.states.get(ZONE_1_ID)
# Note, the list is sorted!
assert state.attributes[ATTR_INPUT_SOURCE_LIST] == ["one", "three"] | [
"async",
"def",
"test_source_list",
"(",
"hass",
")",
":",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"MockMonoprice",
"(",
")",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ZONE_1_ID",
")",
"# Note, the list is sorted!",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE_LIST",
"]",
"==",
"[",
"\"one\"",
",",
"\"three\"",
"]"
] | [
375,
0
] | [
381,
71
] | python | en | ['fr', 'en', 'en'] | True |
test_source_list_with_options | (hass) | Test source list property. | Test source list property. | async def test_source_list_with_options(hass):
"""Test source list property."""
await _setup_monoprice_with_options(hass, MockMonoprice())
state = hass.states.get(ZONE_1_ID)
# Note, the list is sorted!
assert state.attributes[ATTR_INPUT_SOURCE_LIST] == ["two", "four"] | [
"async",
"def",
"test_source_list_with_options",
"(",
"hass",
")",
":",
"await",
"_setup_monoprice_with_options",
"(",
"hass",
",",
"MockMonoprice",
"(",
")",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ZONE_1_ID",
")",
"# Note, the list is sorted!",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_INPUT_SOURCE_LIST",
"]",
"==",
"[",
"\"two\"",
",",
"\"four\"",
"]"
] | [
384,
0
] | [
390,
70
] | python | en | ['fr', 'en', 'en'] | True |
test_select_source | (hass) | Test source selection methods. | Test source selection methods. | async def test_select_source(hass):
"""Test source selection methods."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
await _call_media_player_service(
hass,
SERVICE_SELECT_SOURCE,
{"entity_id": ZONE_1_ID, ATTR_INPUT_SOURCE: "three"},
)
assert monoprice.zones[11].source == 3
# Trying to set unknown source
await _call_media_player_service(
hass,
SERVICE_SELECT_SOURCE,
{"entity_id": ZONE_1_ID, ATTR_INPUT_SOURCE: "no name"},
)
assert monoprice.zones[11].source == 3 | [
"async",
"def",
"test_select_source",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"ATTR_INPUT_SOURCE",
":",
"\"three\"",
"}",
",",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"source",
"==",
"3",
"# Trying to set unknown source",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_SELECT_SOURCE",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"ATTR_INPUT_SOURCE",
":",
"\"no name\"",
"}",
",",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"source",
"==",
"3"
] | [
393,
0
] | [
411,
42
] | python | en | ['fr', 'en', 'en'] | True |
test_unknown_source | (hass) | Test behavior when device has unknown source. | Test behavior when device has unknown source. | async def test_unknown_source(hass):
"""Test behavior when device has unknown source."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
monoprice.set_source(11, 5)
await async_update_entity(hass, ZONE_1_ID)
await hass.async_block_till_done()
state = hass.states.get(ZONE_1_ID)
assert state.attributes.get(ATTR_INPUT_SOURCE) is None | [
"async",
"def",
"test_unknown_source",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"monoprice",
".",
"set_source",
"(",
"11",
",",
"5",
")",
"await",
"async_update_entity",
"(",
"hass",
",",
"ZONE_1_ID",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"ZONE_1_ID",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"ATTR_INPUT_SOURCE",
")",
"is",
"None"
] | [
414,
0
] | [
426,
58
] | python | en | ['en', 'de', 'en'] | True |
test_turn_on_off | (hass) | Test turning on the zone. | Test turning on the zone. | async def test_turn_on_off(hass):
"""Test turning on the zone."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
await _call_media_player_service(hass, SERVICE_TURN_OFF, {"entity_id": ZONE_1_ID})
assert not monoprice.zones[11].power
await _call_media_player_service(hass, SERVICE_TURN_ON, {"entity_id": ZONE_1_ID})
assert monoprice.zones[11].power | [
"async",
"def",
"test_turn_on_off",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_TURN_OFF",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"assert",
"not",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"power",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_TURN_ON",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"power"
] | [
429,
0
] | [
438,
36
] | python | en | ['en', 'en', 'en'] | True |
test_mute_volume | (hass) | Test mute functionality. | Test mute functionality. | async def test_mute_volume(hass):
"""Test mute functionality."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 0.5}
)
await _call_media_player_service(
hass, SERVICE_VOLUME_MUTE, {"entity_id": ZONE_1_ID, "is_volume_muted": False}
)
assert not monoprice.zones[11].mute
await _call_media_player_service(
hass, SERVICE_VOLUME_MUTE, {"entity_id": ZONE_1_ID, "is_volume_muted": True}
)
assert monoprice.zones[11].mute | [
"async",
"def",
"test_mute_volume",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"volume_level\"",
":",
"0.5",
"}",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"is_volume_muted\"",
":",
"False",
"}",
")",
"assert",
"not",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"mute",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_MUTE",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"is_volume_muted\"",
":",
"True",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"mute"
] | [
441,
0
] | [
457,
35
] | python | en | ['en', 'en', 'en'] | True |
test_volume_up_down | (hass) | Test increasing volume by one. | Test increasing volume by one. | async def test_volume_up_down(hass):
"""Test increasing volume by one."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 0.0}
)
assert monoprice.zones[11].volume == 0
await _call_media_player_service(
hass, SERVICE_VOLUME_DOWN, {"entity_id": ZONE_1_ID}
)
# should not go below zero
assert monoprice.zones[11].volume == 0
await _call_media_player_service(hass, SERVICE_VOLUME_UP, {"entity_id": ZONE_1_ID})
assert monoprice.zones[11].volume == 1
await _call_media_player_service(
hass, SERVICE_VOLUME_SET, {"entity_id": ZONE_1_ID, "volume_level": 1.0}
)
assert monoprice.zones[11].volume == 38
await _call_media_player_service(hass, SERVICE_VOLUME_UP, {"entity_id": ZONE_1_ID})
# should not go above 38
assert monoprice.zones[11].volume == 38
await _call_media_player_service(
hass, SERVICE_VOLUME_DOWN, {"entity_id": ZONE_1_ID}
)
assert monoprice.zones[11].volume == 37 | [
"async",
"def",
"test_volume_up_down",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"volume_level\"",
":",
"0.0",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"0",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_DOWN",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"# should not go below zero",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"0",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_UP",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"1",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_SET",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
",",
"\"volume_level\"",
":",
"1.0",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"38",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_UP",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"# should not go above 38",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"38",
"await",
"_call_media_player_service",
"(",
"hass",
",",
"SERVICE_VOLUME_DOWN",
",",
"{",
"\"entity_id\"",
":",
"ZONE_1_ID",
"}",
")",
"assert",
"monoprice",
".",
"zones",
"[",
"11",
"]",
".",
"volume",
"==",
"37"
] | [
460,
0
] | [
491,
43
] | python | en | ['en', 'en', 'en'] | True |
test_first_run_with_available_zones | (hass) | Test first run with all zones available. | Test first run with all zones available. | async def test_first_run_with_available_zones(hass):
"""Test first run with all zones available."""
monoprice = MockMonoprice()
await _setup_monoprice(hass, monoprice)
registry = await hass.helpers.entity_registry.async_get_registry()
entry = registry.async_get(ZONE_7_ID)
assert not entry.disabled | [
"async",
"def",
"test_first_run_with_available_zones",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"ZONE_7_ID",
")",
"assert",
"not",
"entry",
".",
"disabled"
] | [
494,
0
] | [
502,
29
] | python | en | ['en', 'en', 'en'] | True |
test_first_run_with_failing_zones | (hass) | Test first run with failed zones. | Test first run with failed zones. | async def test_first_run_with_failing_zones(hass):
"""Test first run with failed zones."""
monoprice = MockMonoprice()
with patch.object(MockMonoprice, "zone_status", side_effect=SerialException):
await _setup_monoprice(hass, monoprice)
registry = await hass.helpers.entity_registry.async_get_registry()
entry = registry.async_get(ZONE_1_ID)
assert not entry.disabled
entry = registry.async_get(ZONE_7_ID)
assert entry.disabled
assert entry.disabled_by == "integration" | [
"async",
"def",
"test_first_run_with_failing_zones",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"with",
"patch",
".",
"object",
"(",
"MockMonoprice",
",",
"\"zone_status\"",
",",
"side_effect",
"=",
"SerialException",
")",
":",
"await",
"_setup_monoprice",
"(",
"hass",
",",
"monoprice",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"ZONE_1_ID",
")",
"assert",
"not",
"entry",
".",
"disabled",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"ZONE_7_ID",
")",
"assert",
"entry",
".",
"disabled",
"assert",
"entry",
".",
"disabled_by",
"==",
"\"integration\""
] | [
505,
0
] | [
519,
45
] | python | en | ['en', 'en', 'en'] | True |
test_not_first_run_with_failing_zone | (hass) | Test first run with failed zones. | Test first run with failed zones. | async def test_not_first_run_with_failing_zone(hass):
"""Test first run with failed zones."""
monoprice = MockMonoprice()
with patch.object(MockMonoprice, "zone_status", side_effect=SerialException):
await _setup_monoprice_not_first_run(hass, monoprice)
registry = await hass.helpers.entity_registry.async_get_registry()
entry = registry.async_get(ZONE_1_ID)
assert not entry.disabled
entry = registry.async_get(ZONE_7_ID)
assert not entry.disabled | [
"async",
"def",
"test_not_first_run_with_failing_zone",
"(",
"hass",
")",
":",
"monoprice",
"=",
"MockMonoprice",
"(",
")",
"with",
"patch",
".",
"object",
"(",
"MockMonoprice",
",",
"\"zone_status\"",
",",
"side_effect",
"=",
"SerialException",
")",
":",
"await",
"_setup_monoprice_not_first_run",
"(",
"hass",
",",
"monoprice",
")",
"registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"ZONE_1_ID",
")",
"assert",
"not",
"entry",
".",
"disabled",
"entry",
"=",
"registry",
".",
"async_get",
"(",
"ZONE_7_ID",
")",
"assert",
"not",
"entry",
".",
"disabled"
] | [
522,
0
] | [
535,
29
] | python | en | ['en', 'en', 'en'] | True |
AttrDict.__setattr__ | (self, name, value) | Set attribute. | Set attribute. | def __setattr__(self, name, value):
"""Set attribute."""
self[name] = value | [
"def",
"__setattr__",
"(",
"self",
",",
"name",
",",
"value",
")",
":",
"self",
"[",
"name",
"]",
"=",
"value"
] | [
50,
4
] | [
52,
26
] | python | en | ['en', 'la', 'en'] | False |
AttrDict.__getattr__ | (self, item) | Get attribute. | Get attribute. | def __getattr__(self, item):
"""Get attribute."""
return self[item] | [
"def",
"__getattr__",
"(",
"self",
",",
"item",
")",
":",
"return",
"self",
"[",
"item",
"]"
] | [
54,
4
] | [
56,
25
] | python | en | ['en', 'de', 'en'] | False |
MockMonoprice.__init__ | (self) | Init mock object. | Init mock object. | def __init__(self):
"""Init mock object."""
self.zones = defaultdict(
lambda: AttrDict(power=True, volume=0, mute=True, source=1)
) | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"zones",
"=",
"defaultdict",
"(",
"lambda",
":",
"AttrDict",
"(",
"power",
"=",
"True",
",",
"volume",
"=",
"0",
",",
"mute",
"=",
"True",
",",
"source",
"=",
"1",
")",
")"
] | [
62,
4
] | [
66,
9
] | python | en | ['pl', 'fy', 'en'] | False |
MockMonoprice.zone_status | (self, zone_id) | Get zone status. | Get zone status. | def zone_status(self, zone_id):
"""Get zone status."""
status = self.zones[zone_id]
status.zone = zone_id
return AttrDict(status) | [
"def",
"zone_status",
"(",
"self",
",",
"zone_id",
")",
":",
"status",
"=",
"self",
".",
"zones",
"[",
"zone_id",
"]",
"status",
".",
"zone",
"=",
"zone_id",
"return",
"AttrDict",
"(",
"status",
")"
] | [
68,
4
] | [
72,
31
] | python | en | ['pl', 'la', 'en'] | False |
MockMonoprice.set_source | (self, zone_id, source_idx) | Set source for zone. | Set source for zone. | def set_source(self, zone_id, source_idx):
"""Set source for zone."""
self.zones[zone_id].source = source_idx | [
"def",
"set_source",
"(",
"self",
",",
"zone_id",
",",
"source_idx",
")",
":",
"self",
".",
"zones",
"[",
"zone_id",
"]",
".",
"source",
"=",
"source_idx"
] | [
74,
4
] | [
76,
47
] | python | en | ['en', 'en', 'en'] | True |
MockMonoprice.set_power | (self, zone_id, power) | Turn zone on/off. | Turn zone on/off. | def set_power(self, zone_id, power):
"""Turn zone on/off."""
self.zones[zone_id].power = power | [
"def",
"set_power",
"(",
"self",
",",
"zone_id",
",",
"power",
")",
":",
"self",
".",
"zones",
"[",
"zone_id",
"]",
".",
"power",
"=",
"power"
] | [
78,
4
] | [
80,
41
] | python | en | ['nl', 'en', 'en'] | True |
MockMonoprice.set_mute | (self, zone_id, mute) | Mute/unmute zone. | Mute/unmute zone. | def set_mute(self, zone_id, mute):
"""Mute/unmute zone."""
self.zones[zone_id].mute = mute | [
"def",
"set_mute",
"(",
"self",
",",
"zone_id",
",",
"mute",
")",
":",
"self",
".",
"zones",
"[",
"zone_id",
"]",
".",
"mute",
"=",
"mute"
] | [
82,
4
] | [
84,
39
] | python | it | ['pl', 'la', 'it'] | False |
MockMonoprice.set_volume | (self, zone_id, volume) | Set volume for zone. | Set volume for zone. | def set_volume(self, zone_id, volume):
"""Set volume for zone."""
self.zones[zone_id].volume = volume | [
"def",
"set_volume",
"(",
"self",
",",
"zone_id",
",",
"volume",
")",
":",
"self",
".",
"zones",
"[",
"zone_id",
"]",
".",
"volume",
"=",
"volume"
] | [
86,
4
] | [
88,
43
] | python | en | ['nl', 'no', 'en'] | False |
MockMonoprice.restore_zone | (self, zone) | Restore zone status. | Restore zone status. | def restore_zone(self, zone):
"""Restore zone status."""
self.zones[zone.zone] = AttrDict(zone) | [
"def",
"restore_zone",
"(",
"self",
",",
"zone",
")",
":",
"self",
".",
"zones",
"[",
"zone",
".",
"zone",
"]",
"=",
"AttrDict",
"(",
"zone",
")"
] | [
90,
4
] | [
92,
46
] | python | en | ['sk', 'sn', 'en'] | False |
train_model | (path, model, saveto=None, cv=12) |
Trains model from corpus at specified path; constructing cross-validation
scores using the cv parameter, then fitting the model on the full data and
writing it to disk at the saveto path if specified. Returns the scores.
|
Trains model from corpus at specified path; constructing cross-validation
scores using the cv parameter, then fitting the model on the full data and
writing it to disk at the saveto path if specified. Returns the scores.
| def train_model(path, model, saveto=None, cv=12):
"""
Trains model from corpus at specified path; constructing cross-validation
scores using the cv parameter, then fitting the model on the full data and
writing it to disk at the saveto path if specified. Returns the scores.
"""
# Load the corpus data and labels for classification
corpus = PickledCorpusReader(path)
X = documents(corpus)
y = labels(corpus)
# Compute cross validation scores
scores = cross_val_score(model, X, y, cv=cv)
# Fit the model on entire data set
model.fit(X, y)
# Write to disk if specified
if saveto:
joblib.dump(model, saveto)
# Return scores as well as training time via decorator
return scores | [
"def",
"train_model",
"(",
"path",
",",
"model",
",",
"saveto",
"=",
"None",
",",
"cv",
"=",
"12",
")",
":",
"# Load the corpus data and labels for classification",
"corpus",
"=",
"PickledCorpusReader",
"(",
"path",
")",
"X",
"=",
"documents",
"(",
"corpus",
")",
"y",
"=",
"labels",
"(",
"corpus",
")",
"# Compute cross validation scores",
"scores",
"=",
"cross_val_score",
"(",
"model",
",",
"X",
",",
"y",
",",
"cv",
"=",
"cv",
")",
"# Fit the model on entire data set",
"model",
".",
"fit",
"(",
"X",
",",
"y",
")",
"# Write to disk if specified",
"if",
"saveto",
":",
"joblib",
".",
"dump",
"(",
"model",
",",
"saveto",
")",
"# Return scores as well as training time via decorator",
"return",
"scores"
] | [
68,
0
] | [
90,
17
] | python | en | ['en', 'error', 'th'] | False |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Islamic prayer times sensor platform. | Set up the Islamic prayer times sensor platform. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Islamic prayer times sensor platform."""
client = hass.data[DOMAIN]
entities = []
for sensor_type in SENSOR_TYPES:
entities.append(IslamicPrayerTimeSensor(sensor_type, client))
async_add_entities(entities, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"client",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"entities",
"=",
"[",
"]",
"for",
"sensor_type",
"in",
"SENSOR_TYPES",
":",
"entities",
".",
"append",
"(",
"IslamicPrayerTimeSensor",
"(",
"sensor_type",
",",
"client",
")",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
")"
] | [
10,
0
] | [
19,
38
] | python | en | ['en', 'hi-Latn', 'en'] | True |
IslamicPrayerTimeSensor.__init__ | (self, sensor_type, client) | Initialize the Islamic prayer time sensor. | Initialize the Islamic prayer time sensor. | def __init__(self, sensor_type, client):
"""Initialize the Islamic prayer time sensor."""
self.sensor_type = sensor_type
self.client = client | [
"def",
"__init__",
"(",
"self",
",",
"sensor_type",
",",
"client",
")",
":",
"self",
".",
"sensor_type",
"=",
"sensor_type",
"self",
".",
"client",
"=",
"client"
] | [
25,
4
] | [
28,
28
] | python | en | ['en', 'sq', 'en'] | True |
IslamicPrayerTimeSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self.sensor_type} {SENSOR_TYPES[self.sensor_type]}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self.sensor_type} {SENSOR_TYPES[self.sensor_type]}\""
] | [
31,
4
] | [
33,
69
] | python | en | ['en', 'mi', 'en'] | True |
IslamicPrayerTimeSensor.unique_id | (self) | Return the unique id of the entity. | Return the unique id of the entity. | def unique_id(self):
"""Return the unique id of the entity."""
return self.sensor_type | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"sensor_type"
] | [
36,
4
] | [
38,
31
] | python | en | ['en', 'en', 'en'] | True |
IslamicPrayerTimeSensor.icon | (self) | Icon to display in the front end. | Icon to display in the front end. | def icon(self):
"""Icon to display in the front end."""
return PRAYER_TIMES_ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"PRAYER_TIMES_ICON"
] | [
41,
4
] | [
43,
32
] | python | en | ['en', 'en', 'en'] | True |
IslamicPrayerTimeSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return (
self.client.prayer_times_info.get(self.sensor_type)
.astimezone(dt_util.UTC)
.isoformat()
) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"client",
".",
"prayer_times_info",
".",
"get",
"(",
"self",
".",
"sensor_type",
")",
".",
"astimezone",
"(",
"dt_util",
".",
"UTC",
")",
".",
"isoformat",
"(",
")",
")"
] | [
46,
4
] | [
52,
9
] | python | en | ['en', 'en', 'en'] | True |
IslamicPrayerTimeSensor.should_poll | (self) | Disable polling. | Disable polling. | def should_poll(self):
"""Disable polling."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
55,
4
] | [
57,
20
] | python | en | ['fr', 'en', 'en'] | False |
IslamicPrayerTimeSensor.device_class | (self) | Return the device class. | Return the device class. | def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_TIMESTAMP | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_TIMESTAMP"
] | [
60,
4
] | [
62,
37
] | python | en | ['en', 'en', 'en'] | True |
IslamicPrayerTimeSensor.async_added_to_hass | (self) | Handle entity which will be added. | Handle entity which will be added. | async def async_added_to_hass(self):
"""Handle entity which will be added."""
self.async_on_remove(
async_dispatcher_connect(self.hass, DATA_UPDATED, self.async_write_ha_state)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"DATA_UPDATED",
",",
"self",
".",
"async_write_ha_state",
")",
")"
] | [
64,
4
] | [
68,
9
] | python | en | ['en', 'en', 'en'] | True |
value_changed | (value) | Fire a value changed. | Fire a value changed. | def value_changed(value):
"""Fire a value changed."""
dispatcher.send(
MockNetwork.SIGNAL_VALUE_CHANGED,
value=value,
node=value.node,
network=value.node._network,
) | [
"def",
"value_changed",
"(",
"value",
")",
":",
"dispatcher",
".",
"send",
"(",
"MockNetwork",
".",
"SIGNAL_VALUE_CHANGED",
",",
"value",
"=",
"value",
",",
"node",
"=",
"value",
".",
"node",
",",
"network",
"=",
"value",
".",
"node",
".",
"_network",
",",
")"
] | [
6,
0
] | [
13,
5
] | python | en | ['en', 'en', 'en'] | True |
node_changed | (node) | Fire a node changed. | Fire a node changed. | def node_changed(node):
"""Fire a node changed."""
dispatcher.send(MockNetwork.SIGNAL_NODE, node=node, network=node._network) | [
"def",
"node_changed",
"(",
"node",
")",
":",
"dispatcher",
".",
"send",
"(",
"MockNetwork",
".",
"SIGNAL_NODE",
",",
"node",
"=",
"node",
",",
"network",
"=",
"node",
".",
"_network",
")"
] | [
16,
0
] | [
18,
78
] | python | en | ['en', 'lb', 'en'] | True |
notification | (node_id, network=None) | Fire a notification. | Fire a notification. | def notification(node_id, network=None):
"""Fire a notification."""
dispatcher.send(
MockNetwork.SIGNAL_NOTIFICATION, args={"nodeId": node_id}, network=network
) | [
"def",
"notification",
"(",
"node_id",
",",
"network",
"=",
"None",
")",
":",
"dispatcher",
".",
"send",
"(",
"MockNetwork",
".",
"SIGNAL_NOTIFICATION",
",",
"args",
"=",
"{",
"\"nodeId\"",
":",
"node_id",
"}",
",",
"network",
"=",
"network",
")"
] | [
21,
0
] | [
25,
5
] | python | en | ['en', 'lb', 'en'] | True |
MockOption.__init__ | (self, device=None, config_path=None, user_path=None, cmd_line=None) | Initialize a Z-Wave mock options. | Initialize a Z-Wave mock options. | def __init__(self, device=None, config_path=None, user_path=None, cmd_line=None):
"""Initialize a Z-Wave mock options."""
super().__init__()
self.device = device
self.config_path = config_path
self.user_path = user_path
self.cmd_line = cmd_line | [
"def",
"__init__",
"(",
"self",
",",
"device",
"=",
"None",
",",
"config_path",
"=",
"None",
",",
"user_path",
"=",
"None",
",",
"cmd_line",
"=",
"None",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"device",
"=",
"device",
"self",
".",
"config_path",
"=",
"config_path",
"self",
".",
"user_path",
"=",
"user_path",
"self",
".",
"cmd_line",
"=",
"cmd_line"
] | [
31,
4
] | [
37,
32
] | python | en | ['en', 'cs', 'en'] | True |
MockOption._get_child_mock | (self, **kw) | Create child mocks with right MagicMock class. | Create child mocks with right MagicMock class. | def _get_child_mock(self, **kw):
"""Create child mocks with right MagicMock class."""
return MagicMock(**kw) | [
"def",
"_get_child_mock",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"return",
"MagicMock",
"(",
"*",
"*",
"kw",
")"
] | [
39,
4
] | [
41,
30
] | python | en | ['en', 'en', 'en'] | True |
MockNetwork.__init__ | (self, options=None, *args, **kwargs) | Initialize a Z-Wave mock network. | Initialize a Z-Wave mock network. | def __init__(self, options=None, *args, **kwargs):
"""Initialize a Z-Wave mock network."""
super().__init__()
self.options = options
self.state = MockNetwork.STATE_STOPPED | [
"def",
"__init__",
"(",
"self",
",",
"options",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"options",
"=",
"options",
"self",
".",
"state",
"=",
"MockNetwork",
".",
"STATE_STOPPED"
] | [
95,
4
] | [
99,
46
] | python | en | ['en', 'cs', 'en'] | True |
MockNode.__init__ | (
self,
*,
node_id=567,
name="Mock Node",
manufacturer_id="ABCD",
product_id="123",
product_type="678",
command_classes=None,
can_wake_up_value=True,
manufacturer_name="Test Manufacturer",
product_name="Test Product",
network=None,
**kwargs,
) | Initialize a Z-Wave mock node. | Initialize a Z-Wave mock node. | def __init__(
self,
*,
node_id=567,
name="Mock Node",
manufacturer_id="ABCD",
product_id="123",
product_type="678",
command_classes=None,
can_wake_up_value=True,
manufacturer_name="Test Manufacturer",
product_name="Test Product",
network=None,
**kwargs,
):
"""Initialize a Z-Wave mock node."""
super().__init__()
self.node_id = node_id
self.name = name
self.manufacturer_id = manufacturer_id
self.product_id = product_id
self.product_type = product_type
self.manufacturer_name = manufacturer_name
self.product_name = product_name
self.can_wake_up_value = can_wake_up_value
self._command_classes = command_classes or []
if network is not None:
self._network = network
for attr_name in kwargs:
setattr(self, attr_name, kwargs[attr_name]) | [
"def",
"__init__",
"(",
"self",
",",
"*",
",",
"node_id",
"=",
"567",
",",
"name",
"=",
"\"Mock Node\"",
",",
"manufacturer_id",
"=",
"\"ABCD\"",
",",
"product_id",
"=",
"\"123\"",
",",
"product_type",
"=",
"\"678\"",
",",
"command_classes",
"=",
"None",
",",
"can_wake_up_value",
"=",
"True",
",",
"manufacturer_name",
"=",
"\"Test Manufacturer\"",
",",
"product_name",
"=",
"\"Test Product\"",
",",
"network",
"=",
"None",
",",
"*",
"*",
"kwargs",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"node_id",
"=",
"node_id",
"self",
".",
"name",
"=",
"name",
"self",
".",
"manufacturer_id",
"=",
"manufacturer_id",
"self",
".",
"product_id",
"=",
"product_id",
"self",
".",
"product_type",
"=",
"product_type",
"self",
".",
"manufacturer_name",
"=",
"manufacturer_name",
"self",
".",
"product_name",
"=",
"product_name",
"self",
".",
"can_wake_up_value",
"=",
"can_wake_up_value",
"self",
".",
"_command_classes",
"=",
"command_classes",
"or",
"[",
"]",
"if",
"network",
"is",
"not",
"None",
":",
"self",
".",
"_network",
"=",
"network",
"for",
"attr_name",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"attr_name",
",",
"kwargs",
"[",
"attr_name",
"]",
")"
] | [
105,
4
] | [
134,
55
] | python | cs | ['en', 'cs', 'it'] | False |
MockNode.has_command_class | (self, command_class) | Test if mock has a command class. | Test if mock has a command class. | def has_command_class(self, command_class):
"""Test if mock has a command class."""
return command_class in self._command_classes | [
"def",
"has_command_class",
"(",
"self",
",",
"command_class",
")",
":",
"return",
"command_class",
"in",
"self",
".",
"_command_classes"
] | [
136,
4
] | [
138,
53
] | python | en | ['en', 'en', 'en'] | True |
MockNode.get_battery_level | (self) | Return mock battery level. | Return mock battery level. | def get_battery_level(self):
"""Return mock battery level."""
return 42 | [
"def",
"get_battery_level",
"(",
"self",
")",
":",
"return",
"42"
] | [
140,
4
] | [
142,
17
] | python | en | ['en', 'no', 'en'] | True |
MockNode.can_wake_up | (self) | Return whether the node can wake up. | Return whether the node can wake up. | def can_wake_up(self):
"""Return whether the node can wake up."""
return self.can_wake_up_value | [
"def",
"can_wake_up",
"(",
"self",
")",
":",
"return",
"self",
".",
"can_wake_up_value"
] | [
144,
4
] | [
146,
37
] | python | en | ['en', 'en', 'en'] | True |
MockNode._get_child_mock | (self, **kw) | Create child mocks with right MagicMock class. | Create child mocks with right MagicMock class. | def _get_child_mock(self, **kw):
"""Create child mocks with right MagicMock class."""
return MagicMock(**kw) | [
"def",
"_get_child_mock",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"return",
"MagicMock",
"(",
"*",
"*",
"kw",
")"
] | [
148,
4
] | [
150,
30
] | python | en | ['en', 'en', 'en'] | True |
MockValue.__init__ | (
self,
*,
label="Mock Value",
node=None,
instance=0,
index=0,
value_id=None,
**kwargs,
) | Initialize a Z-Wave mock value. | Initialize a Z-Wave mock value. | def __init__(
self,
*,
label="Mock Value",
node=None,
instance=0,
index=0,
value_id=None,
**kwargs,
):
"""Initialize a Z-Wave mock value."""
super().__init__()
self.label = label
self.node = node
self.instance = instance
self.index = index
if value_id is None:
MockValue._mock_value_id += 1
value_id = MockValue._mock_value_id
self.value_id = value_id
self.object_id = value_id
for attr_name in kwargs:
setattr(self, attr_name, kwargs[attr_name]) | [
"def",
"__init__",
"(",
"self",
",",
"*",
",",
"label",
"=",
"\"Mock Value\"",
",",
"node",
"=",
"None",
",",
"instance",
"=",
"0",
",",
"index",
"=",
"0",
",",
"value_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"label",
"=",
"label",
"self",
".",
"node",
"=",
"node",
"self",
".",
"instance",
"=",
"instance",
"self",
".",
"index",
"=",
"index",
"if",
"value_id",
"is",
"None",
":",
"MockValue",
".",
"_mock_value_id",
"+=",
"1",
"value_id",
"=",
"MockValue",
".",
"_mock_value_id",
"self",
".",
"value_id",
"=",
"value_id",
"self",
".",
"object_id",
"=",
"value_id",
"for",
"attr_name",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"attr_name",
",",
"kwargs",
"[",
"attr_name",
"]",
")"
] | [
158,
4
] | [
180,
55
] | python | en | ['en', 'cs', 'en'] | True |
MockValue._get_child_mock | (self, **kw) | Create child mocks with right MagicMock class. | Create child mocks with right MagicMock class. | def _get_child_mock(self, **kw):
"""Create child mocks with right MagicMock class."""
return MagicMock(**kw) | [
"def",
"_get_child_mock",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"return",
"MagicMock",
"(",
"*",
"*",
"kw",
")"
] | [
182,
4
] | [
184,
30
] | python | en | ['en', 'en', 'en'] | True |
MockValue.refresh | (self) | Mock refresh of node value. | Mock refresh of node value. | def refresh(self):
"""Mock refresh of node value."""
value_changed(self) | [
"def",
"refresh",
"(",
"self",
")",
":",
"value_changed",
"(",
"self",
")"
] | [
186,
4
] | [
188,
27
] | python | en | ['en', 'da', 'en'] | True |
MockEntityValues.__init__ | (self, **kwargs) | Initialize the mock zwave values. | Initialize the mock zwave values. | def __init__(self, **kwargs):
"""Initialize the mock zwave values."""
self.primary = None
self.wakeup = None
self.battery = None
self.power = None
for name in kwargs:
setattr(self, name, kwargs[name]) | [
"def",
"__init__",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"primary",
"=",
"None",
"self",
".",
"wakeup",
"=",
"None",
"self",
".",
"battery",
"=",
"None",
"self",
".",
"power",
"=",
"None",
"for",
"name",
"in",
"kwargs",
":",
"setattr",
"(",
"self",
",",
"name",
",",
"kwargs",
"[",
"name",
"]",
")"
] | [
194,
4
] | [
201,
45
] | python | en | ['en', 'en', 'en'] | True |
MockEntityValues.__iter__ | (self) | Allow iteration over all values. | Allow iteration over all values. | def __iter__(self):
"""Allow iteration over all values."""
return iter(self.__dict__.values()) | [
"def",
"__iter__",
"(",
"self",
")",
":",
"return",
"iter",
"(",
"self",
".",
"__dict__",
".",
"values",
"(",
")",
")"
] | [
203,
4
] | [
205,
43
] | python | en | ['en', 'en', 'en'] | True |
mock_client | () | Mock APIClient. | Mock APIClient. | def mock_client():
"""Mock APIClient."""
with patch("homeassistant.components.esphome.config_flow.APIClient") as mock_client:
def mock_constructor(loop, host, port, password, zeroconf_instance=None):
"""Fake the client constructor."""
mock_client.host = host
mock_client.port = port
mock_client.password = password
mock_client.zeroconf_instance = zeroconf_instance
return mock_client
mock_client.side_effect = mock_constructor
mock_client.connect = AsyncMock()
mock_client.disconnect = AsyncMock()
yield mock_client | [
"def",
"mock_client",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.esphome.config_flow.APIClient\"",
")",
"as",
"mock_client",
":",
"def",
"mock_constructor",
"(",
"loop",
",",
"host",
",",
"port",
",",
"password",
",",
"zeroconf_instance",
"=",
"None",
")",
":",
"\"\"\"Fake the client constructor.\"\"\"",
"mock_client",
".",
"host",
"=",
"host",
"mock_client",
".",
"port",
"=",
"port",
"mock_client",
".",
"password",
"=",
"password",
"mock_client",
".",
"zeroconf_instance",
"=",
"zeroconf_instance",
"return",
"mock_client",
"mock_client",
".",
"side_effect",
"=",
"mock_constructor",
"mock_client",
".",
"connect",
"=",
"AsyncMock",
"(",
")",
"mock_client",
".",
"disconnect",
"=",
"AsyncMock",
"(",
")",
"yield",
"mock_client"
] | [
20,
0
] | [
36,
25
] | python | en | ['en', 'fr', 'en'] | False |
mock_api_connection_error | () | Mock out the try login method. | Mock out the try login method. | def mock_api_connection_error():
"""Mock out the try login method."""
with patch(
"homeassistant.components.esphome.config_flow.APIConnectionError",
new_callable=lambda: OSError,
) as mock_error:
yield mock_error | [
"def",
"mock_api_connection_error",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.esphome.config_flow.APIConnectionError\"",
",",
"new_callable",
"=",
"lambda",
":",
"OSError",
",",
")",
"as",
"mock_error",
":",
"yield",
"mock_error"
] | [
40,
0
] | [
46,
24
] | python | en | ['en', 'en', 'en'] | True |
test_user_connection_works | (hass, mock_client) | Test we can finish a config flow. | Test we can finish a config flow. | async def test_user_connection_works(hass, mock_client):
"""Test we can finish a config flow."""
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data=None,
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test"))
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 80},
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["data"] == {CONF_HOST: "127.0.0.1", CONF_PORT: 80, CONF_PASSWORD: ""}
assert result["title"] == "test"
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1
assert mock_client.host == "127.0.0.1"
assert mock_client.port == 80
assert mock_client.password == "" | [
"async",
"def",
"test_user_connection_works",
"(",
"hass",
",",
"mock_client",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"None",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"mock_client",
".",
"device_info",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"MockDeviceInfo",
"(",
"False",
",",
"\"test\"",
")",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"80",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"80",
",",
"CONF_PASSWORD",
":",
"\"\"",
"}",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"test\"",
"assert",
"len",
"(",
"mock_client",
".",
"connect",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"device_info",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"disconnect",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"mock_client",
".",
"host",
"==",
"\"127.0.0.1\"",
"assert",
"mock_client",
".",
"port",
"==",
"80",
"assert",
"mock_client",
".",
"password",
"==",
"\"\""
] | [
49,
0
] | [
77,
37
] | python | en | ['en', 'en', 'en'] | True |
test_user_resolve_error | (hass, mock_api_connection_error, mock_client) | Test user step with IP resolve error. | Test user step with IP resolve error. | async def test_user_resolve_error(hass, mock_api_connection_error, mock_client):
"""Test user step with IP resolve error."""
class MockResolveError(mock_api_connection_error):
"""Create an exception with a specific error message."""
def __init__(self):
"""Initialize."""
super().__init__("Error resolving IP address")
with patch(
"homeassistant.components.esphome.config_flow.APIConnectionError",
new_callable=lambda: MockResolveError,
) as exc:
mock_client.device_info.side_effect = exc
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "resolve_error"}
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1 | [
"async",
"def",
"test_user_resolve_error",
"(",
"hass",
",",
"mock_api_connection_error",
",",
"mock_client",
")",
":",
"class",
"MockResolveError",
"(",
"mock_api_connection_error",
")",
":",
"\"\"\"Create an exception with a specific error message.\"\"\"",
"def",
"__init__",
"(",
"self",
")",
":",
"\"\"\"Initialize.\"\"\"",
"super",
"(",
")",
".",
"__init__",
"(",
"\"Error resolving IP address\"",
")",
"with",
"patch",
"(",
"\"homeassistant.components.esphome.config_flow.APIConnectionError\"",
",",
"new_callable",
"=",
"lambda",
":",
"MockResolveError",
",",
")",
"as",
"exc",
":",
"mock_client",
".",
"device_info",
".",
"side_effect",
"=",
"exc",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"6053",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"resolve_error\"",
"}",
"assert",
"len",
"(",
"mock_client",
".",
"connect",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"device_info",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"disconnect",
".",
"mock_calls",
")",
"==",
"1"
] | [
80,
0
] | [
107,
54
] | python | en | ['en', 'de', 'en'] | True |
test_user_connection_error | (hass, mock_api_connection_error, mock_client) | Test user step with connection error. | Test user step with connection error. | async def test_user_connection_error(hass, mock_api_connection_error, mock_client):
"""Test user step with connection error."""
mock_client.device_info.side_effect = mock_api_connection_error
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user"
assert result["errors"] == {"base": "connection_error"}
assert len(mock_client.connect.mock_calls) == 1
assert len(mock_client.device_info.mock_calls) == 1
assert len(mock_client.disconnect.mock_calls) == 1 | [
"async",
"def",
"test_user_connection_error",
"(",
"hass",
",",
"mock_api_connection_error",
",",
"mock_client",
")",
":",
"mock_client",
".",
"device_info",
".",
"side_effect",
"=",
"mock_api_connection_error",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"6053",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"connection_error\"",
"}",
"assert",
"len",
"(",
"mock_client",
".",
"connect",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"device_info",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_client",
".",
"disconnect",
".",
"mock_calls",
")",
"==",
"1"
] | [
110,
0
] | [
126,
54
] | python | en | ['en', 'en', 'en'] | True |
test_user_with_password | (hass, mock_client) | Test user step with password. | Test user step with password. | async def test_user_with_password(hass, mock_client):
"""Test user step with password."""
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(True, "test"))
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "authenticate"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PASSWORD: "password1"}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["data"] == {
CONF_HOST: "127.0.0.1",
CONF_PORT: 6053,
CONF_PASSWORD: "password1",
}
assert mock_client.password == "password1" | [
"async",
"def",
"test_user_with_password",
"(",
"hass",
",",
"mock_client",
")",
":",
"mock_client",
".",
"device_info",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"MockDeviceInfo",
"(",
"True",
",",
"\"test\"",
")",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"6053",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"authenticate\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"CONF_PASSWORD",
":",
"\"password1\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"data\"",
"]",
"==",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"6053",
",",
"CONF_PASSWORD",
":",
"\"password1\"",
",",
"}",
"assert",
"mock_client",
".",
"password",
"==",
"\"password1\""
] | [
129,
0
] | [
152,
46
] | python | en | ['en', 'en', 'en'] | True |
test_user_invalid_password | (hass, mock_api_connection_error, mock_client) | Test user step with invalid password. | Test user step with invalid password. | async def test_user_invalid_password(hass, mock_api_connection_error, mock_client):
"""Test user step with invalid password."""
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(True, "test"))
result = await hass.config_entries.flow.async_init(
"esphome",
context={"source": "user"},
data={CONF_HOST: "127.0.0.1", CONF_PORT: 6053},
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "authenticate"
mock_client.connect.side_effect = mock_api_connection_error
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={CONF_PASSWORD: "invalid"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "authenticate"
assert result["errors"] == {"base": "invalid_auth"} | [
"async",
"def",
"test_user_invalid_password",
"(",
"hass",
",",
"mock_api_connection_error",
",",
"mock_client",
")",
":",
"mock_client",
".",
"device_info",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"MockDeviceInfo",
"(",
"True",
",",
"\"test\"",
")",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"127.0.0.1\"",
",",
"CONF_PORT",
":",
"6053",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"authenticate\"",
"mock_client",
".",
"connect",
".",
"side_effect",
"=",
"mock_api_connection_error",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"CONF_PASSWORD",
":",
"\"invalid\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"authenticate\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"invalid_auth\"",
"}"
] | [
155,
0
] | [
176,
55
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_initiation | (hass, mock_client) | Test discovery importing works. | Test discovery importing works. | async def test_discovery_initiation(hass, mock_client):
"""Test discovery importing works."""
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266"))
service_info = {
"host": "192.168.43.183",
"port": 6053,
"hostname": "test8266.local.",
"properties": {},
}
flow = await hass.config_entries.flow.async_init(
"esphome", context={"source": "zeroconf"}, data=service_info
)
result = await hass.config_entries.flow.async_configure(
flow["flow_id"], user_input={}
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == "test8266"
assert result["data"][CONF_HOST] == "192.168.43.183"
assert result["data"][CONF_PORT] == 6053
assert result["result"]
assert result["result"].unique_id == "test8266" | [
"async",
"def",
"test_discovery_initiation",
"(",
"hass",
",",
"mock_client",
")",
":",
"mock_client",
".",
"device_info",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"MockDeviceInfo",
"(",
"False",
",",
"\"test8266\"",
")",
")",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.183\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"}",
",",
"}",
"flow",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
",",
"data",
"=",
"service_info",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"flow",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"test8266\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"192.168.43.183\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_PORT",
"]",
"==",
"6053",
"assert",
"result",
"[",
"\"result\"",
"]",
"assert",
"result",
"[",
"\"result\"",
"]",
".",
"unique_id",
"==",
"\"test8266\""
] | [
179,
0
] | [
203,
51
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_already_configured_hostname | (hass, mock_client) | Test discovery aborts if already configured via hostname. | Test discovery aborts if already configured via hostname. | async def test_discovery_already_configured_hostname(hass, mock_client):
"""Test discovery aborts if already configured via hostname."""
entry = MockConfigEntry(
domain="esphome",
data={CONF_HOST: "test8266.local", CONF_PORT: 6053, CONF_PASSWORD: ""},
)
entry.add_to_hass(hass)
service_info = {
"host": "192.168.43.183",
"port": 6053,
"hostname": "test8266.local.",
"properties": {},
}
result = await hass.config_entries.flow.async_init(
"esphome", context={"source": "zeroconf"}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266" | [
"async",
"def",
"test_discovery_already_configured_hostname",
"(",
"hass",
",",
"mock_client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"esphome\"",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"test8266.local\"",
",",
"CONF_PORT",
":",
"6053",
",",
"CONF_PASSWORD",
":",
"\"\"",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.183\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"}",
",",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
",",
"data",
"=",
"service_info",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"assert",
"entry",
".",
"unique_id",
"==",
"\"test8266\""
] | [
206,
0
] | [
228,
40
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_already_configured_ip | (hass, mock_client) | Test discovery aborts if already configured via static IP. | Test discovery aborts if already configured via static IP. | async def test_discovery_already_configured_ip(hass, mock_client):
"""Test discovery aborts if already configured via static IP."""
entry = MockConfigEntry(
domain="esphome",
data={CONF_HOST: "192.168.43.183", CONF_PORT: 6053, CONF_PASSWORD: ""},
)
entry.add_to_hass(hass)
service_info = {
"host": "192.168.43.183",
"port": 6053,
"hostname": "test8266.local.",
"properties": {"address": "192.168.43.183"},
}
result = await hass.config_entries.flow.async_init(
"esphome", context={"source": "zeroconf"}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266" | [
"async",
"def",
"test_discovery_already_configured_ip",
"(",
"hass",
",",
"mock_client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"esphome\"",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"192.168.43.183\"",
",",
"CONF_PORT",
":",
"6053",
",",
"CONF_PASSWORD",
":",
"\"\"",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.183\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"\"address\"",
":",
"\"192.168.43.183\"",
"}",
",",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
",",
"data",
"=",
"service_info",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"assert",
"entry",
".",
"unique_id",
"==",
"\"test8266\""
] | [
231,
0
] | [
253,
40
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_already_configured_name | (hass, mock_client) | Test discovery aborts if already configured via name. | Test discovery aborts if already configured via name. | async def test_discovery_already_configured_name(hass, mock_client):
"""Test discovery aborts if already configured via name."""
entry = MockConfigEntry(
domain="esphome",
data={CONF_HOST: "192.168.43.183", CONF_PORT: 6053, CONF_PASSWORD: ""},
)
entry.add_to_hass(hass)
mock_entry_data = MagicMock()
mock_entry_data.device_info.name = "test8266"
hass.data[DATA_KEY] = {entry.entry_id: mock_entry_data}
service_info = {
"host": "192.168.43.184",
"port": 6053,
"hostname": "test8266.local.",
"properties": {"address": "test8266.local"},
}
result = await hass.config_entries.flow.async_init(
"esphome", context={"source": "zeroconf"}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266"
assert entry.data[CONF_HOST] == "192.168.43.184" | [
"async",
"def",
"test_discovery_already_configured_name",
"(",
"hass",
",",
"mock_client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"esphome\"",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"192.168.43.183\"",
",",
"CONF_PORT",
":",
"6053",
",",
"CONF_PASSWORD",
":",
"\"\"",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"mock_entry_data",
"=",
"MagicMock",
"(",
")",
"mock_entry_data",
".",
"device_info",
".",
"name",
"=",
"\"test8266\"",
"hass",
".",
"data",
"[",
"DATA_KEY",
"]",
"=",
"{",
"entry",
".",
"entry_id",
":",
"mock_entry_data",
"}",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.184\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"\"address\"",
":",
"\"test8266.local\"",
"}",
",",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
",",
"data",
"=",
"service_info",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"assert",
"entry",
".",
"unique_id",
"==",
"\"test8266\"",
"assert",
"entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"==",
"\"192.168.43.184\""
] | [
256,
0
] | [
282,
52
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_duplicate_data | (hass, mock_client) | Test discovery aborts if same mDNS packet arrives. | Test discovery aborts if same mDNS packet arrives. | async def test_discovery_duplicate_data(hass, mock_client):
"""Test discovery aborts if same mDNS packet arrives."""
service_info = {
"host": "192.168.43.183",
"port": 6053,
"hostname": "test8266.local.",
"properties": {"address": "test8266.local"},
}
mock_client.device_info = AsyncMock(return_value=MockDeviceInfo(False, "test8266"))
result = await hass.config_entries.flow.async_init(
"esphome", data=service_info, context={"source": "zeroconf"}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "discovery_confirm"
result = await hass.config_entries.flow.async_init(
"esphome", data=service_info, context={"source": "zeroconf"}
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_in_progress" | [
"async",
"def",
"test_discovery_duplicate_data",
"(",
"hass",
",",
"mock_client",
")",
":",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.183\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"\"address\"",
":",
"\"test8266.local\"",
"}",
",",
"}",
"mock_client",
".",
"device_info",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"MockDeviceInfo",
"(",
"False",
",",
"\"test8266\"",
")",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"data",
"=",
"service_info",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"discovery_confirm\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"data",
"=",
"service_info",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_in_progress\""
] | [
285,
0
] | [
306,
52
] | python | en | ['en', 'en', 'en'] | True |
test_discovery_updates_unique_id | (hass, mock_client) | Test a duplicate discovery host aborts and updates existing entry. | Test a duplicate discovery host aborts and updates existing entry. | async def test_discovery_updates_unique_id(hass, mock_client):
"""Test a duplicate discovery host aborts and updates existing entry."""
entry = MockConfigEntry(
domain="esphome",
data={CONF_HOST: "192.168.43.183", CONF_PORT: 6053, CONF_PASSWORD: ""},
)
entry.add_to_hass(hass)
service_info = {
"host": "192.168.43.183",
"port": 6053,
"hostname": "test8266.local.",
"properties": {"address": "test8266.local"},
}
result = await hass.config_entries.flow.async_init(
"esphome", context={"source": "zeroconf"}, data=service_info
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured"
assert entry.unique_id == "test8266" | [
"async",
"def",
"test_discovery_updates_unique_id",
"(",
"hass",
",",
"mock_client",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"esphome\"",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"\"192.168.43.183\"",
",",
"CONF_PORT",
":",
"6053",
",",
"CONF_PASSWORD",
":",
"\"\"",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"service_info",
"=",
"{",
"\"host\"",
":",
"\"192.168.43.183\"",
",",
"\"port\"",
":",
"6053",
",",
"\"hostname\"",
":",
"\"test8266.local.\"",
",",
"\"properties\"",
":",
"{",
"\"address\"",
":",
"\"test8266.local\"",
"}",
",",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"esphome\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"zeroconf\"",
"}",
",",
"data",
"=",
"service_info",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"assert",
"entry",
".",
"unique_id",
"==",
"\"test8266\""
] | [
309,
0
] | [
331,
40
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the IOTA component. | Set up the IOTA component. | def setup(hass, config):
"""Set up the IOTA component."""
iota_config = config[DOMAIN]
for platform in IOTA_PLATFORMS:
load_platform(hass, platform, DOMAIN, iota_config, config)
return True | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"iota_config",
"=",
"config",
"[",
"DOMAIN",
"]",
"for",
"platform",
"in",
"IOTA_PLATFORMS",
":",
"load_platform",
"(",
"hass",
",",
"platform",
",",
"DOMAIN",
",",
"iota_config",
",",
"config",
")",
"return",
"True"
] | [
43,
0
] | [
50,
15
] | python | en | ['en', 'sr', 'en'] | True |
IotaDevice.__init__ | (self, name, seed, iri, is_testnet=False) | Initialise the IOTA device. | Initialise the IOTA device. | def __init__(self, name, seed, iri, is_testnet=False):
"""Initialise the IOTA device."""
self._name = name
self._seed = seed
self.iri = iri
self.is_testnet = is_testnet | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"seed",
",",
"iri",
",",
"is_testnet",
"=",
"False",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_seed",
"=",
"seed",
"self",
".",
"iri",
"=",
"iri",
"self",
".",
"is_testnet",
"=",
"is_testnet"
] | [
56,
4
] | [
61,
36
] | python | en | ['en', 'sr', 'en'] | True |
IotaDevice.name | (self) | Return the default name of the device. | Return the default name of the device. | def name(self):
"""Return the default name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
64,
4
] | [
66,
25
] | python | en | ['en', 'en', 'en'] | True |
IotaDevice.device_state_attributes | (self) | Return the state attributes of the device. | Return the state attributes of the device. | def device_state_attributes(self):
"""Return the state attributes of the device."""
return {CONF_WALLET_NAME: self._name} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"CONF_WALLET_NAME",
":",
"self",
".",
"_name",
"}"
] | [
69,
4
] | [
71,
45
] | python | en | ['en', 'en', 'en'] | True |
IotaDevice.api | (self) | Construct API object for interaction with the IRI node. | Construct API object for interaction with the IRI node. | def api(self):
"""Construct API object for interaction with the IRI node."""
return Iota(adapter=self.iri, seed=self._seed) | [
"def",
"api",
"(",
"self",
")",
":",
"return",
"Iota",
"(",
"adapter",
"=",
"self",
".",
"iri",
",",
"seed",
"=",
"self",
".",
"_seed",
")"
] | [
74,
4
] | [
77,
54
] | python | en | ['en', 'en', 'en'] | True |
FlowHandler._create_entry | (self, username: str, token: str) | Register new entry. | Register new entry. | async def _create_entry(self, username: str, token: str):
"""Register new entry."""
await self.async_set_unique_id(username)
self._abort_if_unique_id_configured({CONF_TOKEN: token})
return self.async_create_entry(
title=username, data={CONF_USERNAME: username, CONF_TOKEN: token}
) | [
"async",
"def",
"_create_entry",
"(",
"self",
",",
"username",
":",
"str",
",",
"token",
":",
"str",
")",
":",
"await",
"self",
".",
"async_set_unique_id",
"(",
"username",
")",
"self",
".",
"_abort_if_unique_id_configured",
"(",
"{",
"CONF_TOKEN",
":",
"token",
"}",
")",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"username",
",",
"data",
"=",
"{",
"CONF_USERNAME",
":",
"username",
",",
"CONF_TOKEN",
":",
"token",
"}",
")"
] | [
27,
4
] | [
33,
9
] | python | en | ['en', 'no', 'en'] | True |
FlowHandler._create_client | (
self,
username: str,
*,
password: Optional[str] = None,
token: Optional[str] = None,
) | Create client. | Create client. | async def _create_client(
self,
username: str,
*,
password: Optional[str] = None,
token: Optional[str] = None,
):
"""Create client."""
if password is None and token is None:
raise ValueError(
"Invalid internal state. Called without either password or token"
)
try:
with timeout(10):
acquired_token = token
if acquired_token is None:
acquired_token = await pymelcloud.login(
username,
password,
self.hass.helpers.aiohttp_client.async_get_clientsession(),
)
await pymelcloud.get_devices(
acquired_token,
self.hass.helpers.aiohttp_client.async_get_clientsession(),
)
except ClientResponseError as err:
if err.status == HTTP_UNAUTHORIZED or err.status == HTTP_FORBIDDEN:
return self.async_abort(reason="invalid_auth")
return self.async_abort(reason="cannot_connect")
except (asyncio.TimeoutError, ClientError):
return self.async_abort(reason="cannot_connect")
return await self._create_entry(username, acquired_token) | [
"async",
"def",
"_create_client",
"(",
"self",
",",
"username",
":",
"str",
",",
"*",
",",
"password",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"token",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
")",
":",
"if",
"password",
"is",
"None",
"and",
"token",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"Invalid internal state. Called without either password or token\"",
")",
"try",
":",
"with",
"timeout",
"(",
"10",
")",
":",
"acquired_token",
"=",
"token",
"if",
"acquired_token",
"is",
"None",
":",
"acquired_token",
"=",
"await",
"pymelcloud",
".",
"login",
"(",
"username",
",",
"password",
",",
"self",
".",
"hass",
".",
"helpers",
".",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
")",
",",
")",
"await",
"pymelcloud",
".",
"get_devices",
"(",
"acquired_token",
",",
"self",
".",
"hass",
".",
"helpers",
".",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
")",
",",
")",
"except",
"ClientResponseError",
"as",
"err",
":",
"if",
"err",
".",
"status",
"==",
"HTTP_UNAUTHORIZED",
"or",
"err",
".",
"status",
"==",
"HTTP_FORBIDDEN",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"invalid_auth\"",
")",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"cannot_connect\"",
")",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"ClientError",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"cannot_connect\"",
")",
"return",
"await",
"self",
".",
"_create_entry",
"(",
"username",
",",
"acquired_token",
")"
] | [
35,
4
] | [
68,
65
] | python | en | ['en', 'la', 'en'] | False |
FlowHandler.async_step_user | (self, user_input=None) | User initiated config flow. | User initiated config flow. | async def async_step_user(self, user_input=None):
"""User initiated config flow."""
if user_input is None:
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{vol.Required(CONF_USERNAME): str, vol.Required(CONF_PASSWORD): str}
),
)
username = user_input[CONF_USERNAME]
return await self._create_client(username, password=user_input[CONF_PASSWORD]) | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"None",
":",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_USERNAME",
")",
":",
"str",
",",
"vol",
".",
"Required",
"(",
"CONF_PASSWORD",
")",
":",
"str",
"}",
")",
",",
")",
"username",
"=",
"user_input",
"[",
"CONF_USERNAME",
"]",
"return",
"await",
"self",
".",
"_create_client",
"(",
"username",
",",
"password",
"=",
"user_input",
"[",
"CONF_PASSWORD",
"]",
")"
] | [
70,
4
] | [
80,
86
] | python | en | ['en', 'en', 'en'] | True |
FlowHandler.async_step_import | (self, user_input) | Import a config entry. | Import a config entry. | async def async_step_import(self, user_input):
"""Import a config entry."""
return await self._create_client(
user_input[CONF_USERNAME], token=user_input[CONF_TOKEN]
) | [
"async",
"def",
"async_step_import",
"(",
"self",
",",
"user_input",
")",
":",
"return",
"await",
"self",
".",
"_create_client",
"(",
"user_input",
"[",
"CONF_USERNAME",
"]",
",",
"token",
"=",
"user_input",
"[",
"CONF_TOKEN",
"]",
")"
] | [
82,
4
] | [
86,
9
] | python | en | ['en', 'en', 'en'] | True |
get_split | (split_name, dataset_dir, file_pattern=None, reader=None) | Gets a dataset tuple with instructions for reading ImageNet.
Args:
split_name: A train/test split name.
dataset_dir: The base directory of the dataset sources.
file_pattern: The file pattern to use when matching the dataset sources. It
is assumed that the pattern contains a '%s' string so that the split name
can be inserted.
reader: The TensorFlow reader type.
Returns:
A `Dataset` namedtuple.
Raises:
ValueError: if `split_name` is not a valid train/test split.
| Gets a dataset tuple with instructions for reading ImageNet. | def get_split(split_name, dataset_dir, file_pattern=None, reader=None):
"""Gets a dataset tuple with instructions for reading ImageNet.
Args:
split_name: A train/test split name.
dataset_dir: The base directory of the dataset sources.
file_pattern: The file pattern to use when matching the dataset sources. It
is assumed that the pattern contains a '%s' string so that the split name
can be inserted.
reader: The TensorFlow reader type.
Returns:
A `Dataset` namedtuple.
Raises:
ValueError: if `split_name` is not a valid train/test split.
"""
if split_name not in _SPLITS_TO_SIZES:
raise ValueError('split name %s was not recognized.' % split_name)
if not file_pattern:
file_pattern = _FILE_PATTERN
file_pattern = os.path.join(dataset_dir, file_pattern % split_name)
# Allowing None in the signature so that dataset_factory can use the default.
if reader is None:
reader = tf.TFRecordReader
keys_to_features = {
'image/encoded':
tf.FixedLenFeature((), tf.string, default_value=''),
'image/format':
tf.FixedLenFeature((), tf.string, default_value='jpeg'),
'image/class/label':
tf.FixedLenFeature([], dtype=tf.int64, default_value=-1),
'image/object/bbox/xmin':
tf.VarLenFeature(dtype=tf.float32),
'image/object/bbox/ymin':
tf.VarLenFeature(dtype=tf.float32),
'image/object/bbox/xmax':
tf.VarLenFeature(dtype=tf.float32),
'image/object/bbox/ymax':
tf.VarLenFeature(dtype=tf.float32),
}
items_to_handlers = {
'image':
slim.tfexample_decoder.Image('image/encoded', 'image/format'),
'label':
slim.tfexample_decoder.Tensor('image/class/label'),
'object/bbox':
slim.tfexample_decoder.BoundingBox(['ymin', 'xmin', 'ymax', 'xmax'],
'image/object/bbox/'),
}
decoder = slim.tfexample_decoder.TFExampleDecoder(keys_to_features,
items_to_handlers)
labels_to_names = None
labels_file = os.path.join(dataset_dir, LABELS_FILENAME)
if tf.gfile.Exists(labels_file):
labels_to_names = dataset_utils.read_label_file(dataset_dir)
return slim.dataset.Dataset(
data_sources=file_pattern,
reader=reader,
decoder=decoder,
num_samples=_SPLITS_TO_SIZES[split_name],
items_to_descriptions=_ITEMS_TO_DESCRIPTIONS,
num_classes=_NUM_CLASSES,
labels_to_names=labels_to_names) | [
"def",
"get_split",
"(",
"split_name",
",",
"dataset_dir",
",",
"file_pattern",
"=",
"None",
",",
"reader",
"=",
"None",
")",
":",
"if",
"split_name",
"not",
"in",
"_SPLITS_TO_SIZES",
":",
"raise",
"ValueError",
"(",
"'split name %s was not recognized.'",
"%",
"split_name",
")",
"if",
"not",
"file_pattern",
":",
"file_pattern",
"=",
"_FILE_PATTERN",
"file_pattern",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dataset_dir",
",",
"file_pattern",
"%",
"split_name",
")",
"# Allowing None in the signature so that dataset_factory can use the default.",
"if",
"reader",
"is",
"None",
":",
"reader",
"=",
"tf",
".",
"TFRecordReader",
"keys_to_features",
"=",
"{",
"'image/encoded'",
":",
"tf",
".",
"FixedLenFeature",
"(",
"(",
")",
",",
"tf",
".",
"string",
",",
"default_value",
"=",
"''",
")",
",",
"'image/format'",
":",
"tf",
".",
"FixedLenFeature",
"(",
"(",
")",
",",
"tf",
".",
"string",
",",
"default_value",
"=",
"'jpeg'",
")",
",",
"'image/class/label'",
":",
"tf",
".",
"FixedLenFeature",
"(",
"[",
"]",
",",
"dtype",
"=",
"tf",
".",
"int64",
",",
"default_value",
"=",
"-",
"1",
")",
",",
"'image/object/bbox/xmin'",
":",
"tf",
".",
"VarLenFeature",
"(",
"dtype",
"=",
"tf",
".",
"float32",
")",
",",
"'image/object/bbox/ymin'",
":",
"tf",
".",
"VarLenFeature",
"(",
"dtype",
"=",
"tf",
".",
"float32",
")",
",",
"'image/object/bbox/xmax'",
":",
"tf",
".",
"VarLenFeature",
"(",
"dtype",
"=",
"tf",
".",
"float32",
")",
",",
"'image/object/bbox/ymax'",
":",
"tf",
".",
"VarLenFeature",
"(",
"dtype",
"=",
"tf",
".",
"float32",
")",
",",
"}",
"items_to_handlers",
"=",
"{",
"'image'",
":",
"slim",
".",
"tfexample_decoder",
".",
"Image",
"(",
"'image/encoded'",
",",
"'image/format'",
")",
",",
"'label'",
":",
"slim",
".",
"tfexample_decoder",
".",
"Tensor",
"(",
"'image/class/label'",
")",
",",
"'object/bbox'",
":",
"slim",
".",
"tfexample_decoder",
".",
"BoundingBox",
"(",
"[",
"'ymin'",
",",
"'xmin'",
",",
"'ymax'",
",",
"'xmax'",
"]",
",",
"'image/object/bbox/'",
")",
",",
"}",
"decoder",
"=",
"slim",
".",
"tfexample_decoder",
".",
"TFExampleDecoder",
"(",
"keys_to_features",
",",
"items_to_handlers",
")",
"labels_to_names",
"=",
"None",
"labels_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"dataset_dir",
",",
"LABELS_FILENAME",
")",
"if",
"tf",
".",
"gfile",
".",
"Exists",
"(",
"labels_file",
")",
":",
"labels_to_names",
"=",
"dataset_utils",
".",
"read_label_file",
"(",
"dataset_dir",
")",
"return",
"slim",
".",
"dataset",
".",
"Dataset",
"(",
"data_sources",
"=",
"file_pattern",
",",
"reader",
"=",
"reader",
",",
"decoder",
"=",
"decoder",
",",
"num_samples",
"=",
"_SPLITS_TO_SIZES",
"[",
"split_name",
"]",
",",
"items_to_descriptions",
"=",
"_ITEMS_TO_DESCRIPTIONS",
",",
"num_classes",
"=",
"_NUM_CLASSES",
",",
"labels_to_names",
"=",
"labels_to_names",
")"
] | [
58,
0
] | [
128,
38
] | python | en | ['en', 'en', 'en'] | True |
mock_finish_setup | () | Mock out the finish setup method. | Mock out the finish setup method. | def mock_finish_setup():
"""Mock out the finish setup method."""
with patch(
"homeassistant.components.mqtt.MQTT.async_connect", return_value=True
) as mock_finish:
yield mock_finish | [
"def",
"mock_finish_setup",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.mqtt.MQTT.async_connect\"",
",",
"return_value",
"=",
"True",
")",
"as",
"mock_finish",
":",
"yield",
"mock_finish"
] | [
14,
0
] | [
19,
25
] | python | en | ['en', 'zu', 'en'] | True |
mock_try_connection | () | Mock the try connection method. | Mock the try connection method. | def mock_try_connection():
"""Mock the try connection method."""
with patch("homeassistant.components.mqtt.config_flow.try_connection") as mock_try:
yield mock_try | [
"def",
"mock_try_connection",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.mqtt.config_flow.try_connection\"",
")",
"as",
"mock_try",
":",
"yield",
"mock_try"
] | [
23,
0
] | [
26,
22
] | python | en | ['en', 'en', 'en'] | True |
test_user_connection_works | (hass, mock_try_connection, mock_finish_setup) | Test we can finish a config flow. | Test we can finish a config flow. | async def test_user_connection_works(hass, mock_try_connection, mock_finish_setup):
"""Test we can finish a config flow."""
mock_try_connection.return_value = True
result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": "user"}
)
assert result["type"] == "form"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"broker": "127.0.0.1"}
)
assert result["type"] == "create_entry"
assert result["result"].data == {
"broker": "127.0.0.1",
"port": 1883,
"discovery": True,
}
# Check we tried the connection
assert len(mock_try_connection.mock_calls) == 1
# Check config entry got setup
assert len(mock_finish_setup.mock_calls) == 1 | [
"async",
"def",
"test_user_connection_works",
"(",
"hass",
",",
"mock_try_connection",
",",
"mock_finish_setup",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"\"broker\"",
":",
"\"127.0.0.1\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result",
"[",
"\"result\"",
"]",
".",
"data",
"==",
"{",
"\"broker\"",
":",
"\"127.0.0.1\"",
",",
"\"port\"",
":",
"1883",
",",
"\"discovery\"",
":",
"True",
",",
"}",
"# Check we tried the connection",
"assert",
"len",
"(",
"mock_try_connection",
".",
"mock_calls",
")",
"==",
"1",
"# Check config entry got setup",
"assert",
"len",
"(",
"mock_finish_setup",
".",
"mock_calls",
")",
"==",
"1"
] | [
29,
0
] | [
51,
49
] | python | en | ['en', 'en', 'en'] | True |
test_user_connection_fails | (hass, mock_try_connection, mock_finish_setup) | Test if connection cannot be made. | Test if connection cannot be made. | async def test_user_connection_fails(hass, mock_try_connection, mock_finish_setup):
"""Test if connection cannot be made."""
mock_try_connection.return_value = False
result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": "user"}
)
assert result["type"] == "form"
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"broker": "127.0.0.1"}
)
assert result["type"] == "form"
assert result["errors"]["base"] == "cannot_connect"
# Check we tried the connection
assert len(mock_try_connection.mock_calls) == 1
# Check config entry did not setup
assert len(mock_finish_setup.mock_calls) == 0 | [
"async",
"def",
"test_user_connection_fails",
"(",
"hass",
",",
"mock_try_connection",
",",
"mock_finish_setup",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"False",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"\"broker\"",
":",
"\"127.0.0.1\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"[",
"\"base\"",
"]",
"==",
"\"cannot_connect\"",
"# Check we tried the connection",
"assert",
"len",
"(",
"mock_try_connection",
".",
"mock_calls",
")",
"==",
"1",
"# Check config entry did not setup",
"assert",
"len",
"(",
"mock_finish_setup",
".",
"mock_calls",
")",
"==",
"0"
] | [
54,
0
] | [
73,
49
] | python | en | ['en', 'en', 'en'] | True |
test_manual_config_set | (hass, mock_try_connection, mock_finish_setup) | Test we ignore entry if manual config available. | Test we ignore entry if manual config available. | async def test_manual_config_set(hass, mock_try_connection, mock_finish_setup):
"""Test we ignore entry if manual config available."""
assert await async_setup_component(hass, "mqtt", {"mqtt": {"broker": "bla"}})
await hass.async_block_till_done()
assert len(mock_finish_setup.mock_calls) == 1
mock_try_connection.return_value = True
result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": "user"}
)
assert result["type"] == "abort" | [
"async",
"def",
"test_manual_config_set",
"(",
"hass",
",",
"mock_try_connection",
",",
"mock_finish_setup",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"mqtt\"",
",",
"{",
"\"mqtt\"",
":",
"{",
"\"broker\"",
":",
"\"bla\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_finish_setup",
".",
"mock_calls",
")",
"==",
"1",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"abort\""
] | [
76,
0
] | [
87,
36
] | python | en | ['en', 'en', 'en'] | True |
test_user_single_instance | (hass) | Test we only allow a single config flow. | Test we only allow a single config flow. | async def test_user_single_instance(hass):
"""Test we only allow a single config flow."""
MockConfigEntry(domain="mqtt").add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": "user"}
)
assert result["type"] == "abort"
assert result["reason"] == "single_instance_allowed" | [
"async",
"def",
"test_user_single_instance",
"(",
"hass",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"\"mqtt\"",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"abort\"",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"single_instance_allowed\""
] | [
90,
0
] | [
98,
56
] | python | en | ['en', 'en', 'en'] | True |
test_hassio_single_instance | (hass) | Test we only allow a single config flow. | Test we only allow a single config flow. | async def test_hassio_single_instance(hass):
"""Test we only allow a single config flow."""
MockConfigEntry(domain="mqtt").add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
"mqtt", context={"source": "hassio"}
)
assert result["type"] == "abort"
assert result["reason"] == "single_instance_allowed" | [
"async",
"def",
"test_hassio_single_instance",
"(",
"hass",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"\"mqtt\"",
")",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"hassio\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"abort\"",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"single_instance_allowed\""
] | [
101,
0
] | [
109,
56
] | python | en | ['en', 'en', 'en'] | True |
test_hassio_confirm | (hass, mock_try_connection, mock_finish_setup) | Test we can finish a config flow. | Test we can finish a config flow. | async def test_hassio_confirm(hass, mock_try_connection, mock_finish_setup):
"""Test we can finish a config flow."""
mock_try_connection.return_value = True
result = await hass.config_entries.flow.async_init(
"mqtt",
data={
"addon": "Mock Addon",
"host": "mock-broker",
"port": 1883,
"username": "mock-user",
"password": "mock-pass",
"protocol": "3.1.1",
},
context={"source": "hassio"},
)
assert result["type"] == "form"
assert result["step_id"] == "hassio_confirm"
assert result["description_placeholders"] == {"addon": "Mock Addon"}
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {"discovery": True}
)
assert result["type"] == "create_entry"
assert result["result"].data == {
"broker": "mock-broker",
"port": 1883,
"username": "mock-user",
"password": "mock-pass",
"protocol": "3.1.1",
"discovery": True,
}
# Check we tried the connection
assert len(mock_try_connection.mock_calls) == 1
# Check config entry got setup
assert len(mock_finish_setup.mock_calls) == 1 | [
"async",
"def",
"test_hassio_confirm",
"(",
"hass",
",",
"mock_try_connection",
",",
"mock_finish_setup",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"\"mqtt\"",
",",
"data",
"=",
"{",
"\"addon\"",
":",
"\"Mock Addon\"",
",",
"\"host\"",
":",
"\"mock-broker\"",
",",
"\"port\"",
":",
"1883",
",",
"\"username\"",
":",
"\"mock-user\"",
",",
"\"password\"",
":",
"\"mock-pass\"",
",",
"\"protocol\"",
":",
"\"3.1.1\"",
",",
"}",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"hassio\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"hassio_confirm\"",
"assert",
"result",
"[",
"\"description_placeholders\"",
"]",
"==",
"{",
"\"addon\"",
":",
"\"Mock Addon\"",
"}",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"\"discovery\"",
":",
"True",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result",
"[",
"\"result\"",
"]",
".",
"data",
"==",
"{",
"\"broker\"",
":",
"\"mock-broker\"",
",",
"\"port\"",
":",
"1883",
",",
"\"username\"",
":",
"\"mock-user\"",
",",
"\"password\"",
":",
"\"mock-pass\"",
",",
"\"protocol\"",
":",
"\"3.1.1\"",
",",
"\"discovery\"",
":",
"True",
",",
"}",
"# Check we tried the connection",
"assert",
"len",
"(",
"mock_try_connection",
".",
"mock_calls",
")",
"==",
"1",
"# Check config entry got setup",
"assert",
"len",
"(",
"mock_finish_setup",
".",
"mock_calls",
")",
"==",
"1"
] | [
112,
0
] | [
148,
49
] | python | en | ['en', 'en', 'en'] | True |
test_option_flow | (hass, mqtt_mock, mock_try_connection) | Test config flow options. | Test config flow options. | async def test_option_flow(hass, mqtt_mock, mock_try_connection):
"""Test config flow options."""
mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
mqtt_mock.async_connect.reset_mock()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "broker"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "options"
await hass.async_block_till_done()
assert mqtt_mock.async_connect.call_count == 0
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_DISCOVERY: True,
"birth_enable": True,
"birth_topic": "ha_state/online",
"birth_payload": "online",
"birth_qos": 1,
"birth_retain": True,
"will_enable": True,
"will_topic": "ha_state/offline",
"will_payload": "offline",
"will_qos": 2,
"will_retain": True,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] is None
assert config_entry.data == {
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
mqtt.CONF_DISCOVERY: True,
mqtt.CONF_BIRTH_MESSAGE: {
mqtt.ATTR_TOPIC: "ha_state/online",
mqtt.ATTR_PAYLOAD: "online",
mqtt.ATTR_QOS: 1,
mqtt.ATTR_RETAIN: True,
},
mqtt.CONF_WILL_MESSAGE: {
mqtt.ATTR_TOPIC: "ha_state/offline",
mqtt.ATTR_PAYLOAD: "offline",
mqtt.ATTR_QOS: 2,
mqtt.ATTR_RETAIN: True,
},
}
await hass.async_block_till_done()
assert mqtt_mock.async_connect.call_count == 1 | [
"async",
"def",
"test_option_flow",
"(",
"hass",
",",
"mqtt_mock",
",",
"mock_try_connection",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"config_entry",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"mqtt",
".",
"DOMAIN",
")",
"[",
"0",
"]",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"mqtt_mock",
".",
"async_connect",
".",
"reset_mock",
"(",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"broker\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"mqtt_mock",
".",
"async_connect",
".",
"call_count",
"==",
"0",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"\"birth_enable\"",
":",
"True",
",",
"\"birth_topic\"",
":",
"\"ha_state/online\"",
",",
"\"birth_payload\"",
":",
"\"online\"",
",",
"\"birth_qos\"",
":",
"1",
",",
"\"birth_retain\"",
":",
"True",
",",
"\"will_enable\"",
":",
"True",
",",
"\"will_topic\"",
":",
"\"ha_state/offline\"",
",",
"\"will_payload\"",
":",
"\"offline\"",
",",
"\"will_qos\"",
":",
"2",
",",
"\"will_retain\"",
":",
"True",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"data\"",
"]",
"is",
"None",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"mqtt",
".",
"CONF_BIRTH_MESSAGE",
":",
"{",
"mqtt",
".",
"ATTR_TOPIC",
":",
"\"ha_state/online\"",
",",
"mqtt",
".",
"ATTR_PAYLOAD",
":",
"\"online\"",
",",
"mqtt",
".",
"ATTR_QOS",
":",
"1",
",",
"mqtt",
".",
"ATTR_RETAIN",
":",
"True",
",",
"}",
",",
"mqtt",
".",
"CONF_WILL_MESSAGE",
":",
"{",
"mqtt",
".",
"ATTR_TOPIC",
":",
"\"ha_state/offline\"",
",",
"mqtt",
".",
"ATTR_PAYLOAD",
":",
"\"offline\"",
",",
"mqtt",
".",
"ATTR_QOS",
":",
"2",
",",
"mqtt",
".",
"ATTR_RETAIN",
":",
"True",
",",
"}",
",",
"}",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"mqtt_mock",
".",
"async_connect",
".",
"call_count",
"==",
"1"
] | [
151,
0
] | [
220,
50
] | python | en | ['en', 'fr', 'en'] | True |
test_disable_birth_will | (hass, mqtt_mock, mock_try_connection) | Test disabling birth and will. | Test disabling birth and will. | async def test_disable_birth_will(hass, mqtt_mock, mock_try_connection):
"""Test disabling birth and will."""
mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
mqtt_mock.async_connect.reset_mock()
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "broker"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "options"
await hass.async_block_till_done()
assert mqtt_mock.async_connect.call_count == 0
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_DISCOVERY: True,
"birth_enable": False,
"birth_topic": "ha_state/online",
"birth_payload": "online",
"birth_qos": 1,
"birth_retain": True,
"will_enable": False,
"will_topic": "ha_state/offline",
"will_payload": "offline",
"will_qos": 2,
"will_retain": True,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["data"] is None
assert config_entry.data == {
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
mqtt.CONF_DISCOVERY: True,
mqtt.CONF_BIRTH_MESSAGE: {},
mqtt.CONF_WILL_MESSAGE: {},
}
await hass.async_block_till_done()
assert mqtt_mock.async_connect.call_count == 1 | [
"async",
"def",
"test_disable_birth_will",
"(",
"hass",
",",
"mqtt_mock",
",",
"mock_try_connection",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"config_entry",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"mqtt",
".",
"DOMAIN",
")",
"[",
"0",
"]",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"mqtt_mock",
".",
"async_connect",
".",
"reset_mock",
"(",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"broker\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"mqtt_mock",
".",
"async_connect",
".",
"call_count",
"==",
"0",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"\"birth_enable\"",
":",
"False",
",",
"\"birth_topic\"",
":",
"\"ha_state/online\"",
",",
"\"birth_payload\"",
":",
"\"online\"",
",",
"\"birth_qos\"",
":",
"1",
",",
"\"birth_retain\"",
":",
"True",
",",
"\"will_enable\"",
":",
"False",
",",
"\"will_topic\"",
":",
"\"ha_state/offline\"",
",",
"\"will_payload\"",
":",
"\"offline\"",
",",
"\"will_qos\"",
":",
"2",
",",
"\"will_retain\"",
":",
"True",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"data\"",
"]",
"is",
"None",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"mqtt",
".",
"CONF_BIRTH_MESSAGE",
":",
"{",
"}",
",",
"mqtt",
".",
"CONF_WILL_MESSAGE",
":",
"{",
"}",
",",
"}",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"mqtt_mock",
".",
"async_connect",
".",
"call_count",
"==",
"1"
] | [
223,
0
] | [
282,
50
] | python | en | ['en', 'en', 'en'] | True |
get_default | (schema, key) | Get default value for key in voluptuous schema. | Get default value for key in voluptuous schema. | def get_default(schema, key):
"""Get default value for key in voluptuous schema."""
for k in schema.keys():
if k == key:
if k.default == vol.UNDEFINED:
return None
return k.default() | [
"def",
"get_default",
"(",
"schema",
",",
"key",
")",
":",
"for",
"k",
"in",
"schema",
".",
"keys",
"(",
")",
":",
"if",
"k",
"==",
"key",
":",
"if",
"k",
".",
"default",
"==",
"vol",
".",
"UNDEFINED",
":",
"return",
"None",
"return",
"k",
".",
"default",
"(",
")"
] | [
285,
0
] | [
291,
30
] | python | de | ['nl', 'de', 'en'] | False |
get_suggested | (schema, key) | Get suggested value for key in voluptuous schema. | Get suggested value for key in voluptuous schema. | def get_suggested(schema, key):
"""Get suggested value for key in voluptuous schema."""
for k in schema.keys():
if k == key:
if k.description is None or "suggested_value" not in k.description:
return None
return k.description["suggested_value"] | [
"def",
"get_suggested",
"(",
"schema",
",",
"key",
")",
":",
"for",
"k",
"in",
"schema",
".",
"keys",
"(",
")",
":",
"if",
"k",
"==",
"key",
":",
"if",
"k",
".",
"description",
"is",
"None",
"or",
"\"suggested_value\"",
"not",
"in",
"k",
".",
"description",
":",
"return",
"None",
"return",
"k",
".",
"description",
"[",
"\"suggested_value\"",
"]"
] | [
294,
0
] | [
300,
51
] | python | en | ['en', 'en', 'en'] | True |
test_option_flow_default_suggested_values | (
hass, mqtt_mock, mock_try_connection
) | Test config flow options has default/suggested values. | Test config flow options has default/suggested values. | async def test_option_flow_default_suggested_values(
hass, mqtt_mock, mock_try_connection
):
"""Test config flow options has default/suggested values."""
mock_try_connection.return_value = True
config_entry = hass.config_entries.async_entries(mqtt.DOMAIN)[0]
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
mqtt.CONF_DISCOVERY: True,
mqtt.CONF_BIRTH_MESSAGE: {
mqtt.ATTR_TOPIC: "ha_state/online",
mqtt.ATTR_PAYLOAD: "online",
mqtt.ATTR_QOS: 1,
mqtt.ATTR_RETAIN: True,
},
mqtt.CONF_WILL_MESSAGE: {
mqtt.ATTR_TOPIC: "ha_state/offline",
mqtt.ATTR_PAYLOAD: "offline",
mqtt.ATTR_QOS: 2,
mqtt.ATTR_RETAIN: False,
},
}
# Test default/suggested values from config
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "broker"
defaults = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
suggested = {
mqtt.CONF_USERNAME: "user",
mqtt.CONF_PASSWORD: "pass",
}
for k, v in defaults.items():
assert get_default(result["data_schema"].schema, k) == v
for k, v in suggested.items():
assert get_suggested(result["data_schema"].schema, k) == v
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
mqtt.CONF_USERNAME: "us3r",
mqtt.CONF_PASSWORD: "p4ss",
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "options"
defaults = {
mqtt.CONF_DISCOVERY: True,
"birth_qos": 1,
"birth_retain": True,
"will_qos": 2,
"will_retain": False,
}
suggested = {
"birth_topic": "ha_state/online",
"birth_payload": "online",
"will_topic": "ha_state/offline",
"will_payload": "offline",
}
for k, v in defaults.items():
assert get_default(result["data_schema"].schema, k) == v
for k, v in suggested.items():
assert get_suggested(result["data_schema"].schema, k) == v
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_DISCOVERY: False,
"birth_topic": "ha_state/onl1ne",
"birth_payload": "onl1ne",
"birth_qos": 2,
"birth_retain": False,
"will_topic": "ha_state/offl1ne",
"will_payload": "offl1ne",
"will_qos": 1,
"will_retain": True,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
# Test updated default/suggested values from config
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "broker"
defaults = {
mqtt.CONF_BROKER: "another-broker",
mqtt.CONF_PORT: 2345,
}
suggested = {
mqtt.CONF_USERNAME: "us3r",
mqtt.CONF_PASSWORD: "p4ss",
}
for k, v in defaults.items():
assert get_default(result["data_schema"].schema, k) == v
for k, v in suggested.items():
assert get_suggested(result["data_schema"].schema, k) == v
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={mqtt.CONF_BROKER: "another-broker", mqtt.CONF_PORT: 2345},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "options"
defaults = {
mqtt.CONF_DISCOVERY: False,
"birth_qos": 2,
"birth_retain": False,
"will_qos": 1,
"will_retain": True,
}
suggested = {
"birth_topic": "ha_state/onl1ne",
"birth_payload": "onl1ne",
"will_topic": "ha_state/offl1ne",
"will_payload": "offl1ne",
}
for k, v in defaults.items():
assert get_default(result["data_schema"].schema, k) == v
for k, v in suggested.items():
assert get_suggested(result["data_schema"].schema, k) == v
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={
mqtt.CONF_DISCOVERY: True,
"birth_topic": "ha_state/onl1ne",
"birth_payload": "onl1ne",
"birth_qos": 2,
"birth_retain": False,
"will_topic": "ha_state/offl1ne",
"will_payload": "offl1ne",
"will_qos": 1,
"will_retain": True,
},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY | [
"async",
"def",
"test_option_flow_default_suggested_values",
"(",
"hass",
",",
"mqtt_mock",
",",
"mock_try_connection",
")",
":",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"config_entry",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"mqtt",
".",
"DOMAIN",
")",
"[",
"0",
"]",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"mqtt",
".",
"CONF_BIRTH_MESSAGE",
":",
"{",
"mqtt",
".",
"ATTR_TOPIC",
":",
"\"ha_state/online\"",
",",
"mqtt",
".",
"ATTR_PAYLOAD",
":",
"\"online\"",
",",
"mqtt",
".",
"ATTR_QOS",
":",
"1",
",",
"mqtt",
".",
"ATTR_RETAIN",
":",
"True",
",",
"}",
",",
"mqtt",
".",
"CONF_WILL_MESSAGE",
":",
"{",
"mqtt",
".",
"ATTR_TOPIC",
":",
"\"ha_state/offline\"",
",",
"mqtt",
".",
"ATTR_PAYLOAD",
":",
"\"offline\"",
",",
"mqtt",
".",
"ATTR_QOS",
":",
"2",
",",
"mqtt",
".",
"ATTR_RETAIN",
":",
"False",
",",
"}",
",",
"}",
"# Test default/suggested values from config",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"broker\"",
"defaults",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"suggested",
"=",
"{",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"user\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"pass\"",
",",
"}",
"for",
"k",
",",
"v",
"in",
"defaults",
".",
"items",
"(",
")",
":",
"assert",
"get_default",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"for",
"k",
",",
"v",
"in",
"suggested",
".",
"items",
"(",
")",
":",
"assert",
"get_suggested",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"us3r\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"p4ss\"",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"defaults",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"\"birth_qos\"",
":",
"1",
",",
"\"birth_retain\"",
":",
"True",
",",
"\"will_qos\"",
":",
"2",
",",
"\"will_retain\"",
":",
"False",
",",
"}",
"suggested",
"=",
"{",
"\"birth_topic\"",
":",
"\"ha_state/online\"",
",",
"\"birth_payload\"",
":",
"\"online\"",
",",
"\"will_topic\"",
":",
"\"ha_state/offline\"",
",",
"\"will_payload\"",
":",
"\"offline\"",
",",
"}",
"for",
"k",
",",
"v",
"in",
"defaults",
".",
"items",
"(",
")",
":",
"assert",
"get_default",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"for",
"k",
",",
"v",
"in",
"suggested",
".",
"items",
"(",
")",
":",
"assert",
"get_suggested",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"False",
",",
"\"birth_topic\"",
":",
"\"ha_state/onl1ne\"",
",",
"\"birth_payload\"",
":",
"\"onl1ne\"",
",",
"\"birth_qos\"",
":",
"2",
",",
"\"birth_retain\"",
":",
"False",
",",
"\"will_topic\"",
":",
"\"ha_state/offl1ne\"",
",",
"\"will_payload\"",
":",
"\"offl1ne\"",
",",
"\"will_qos\"",
":",
"1",
",",
"\"will_retain\"",
":",
"True",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"# Test updated default/suggested values from config",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"broker\"",
"defaults",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
",",
"}",
"suggested",
"=",
"{",
"mqtt",
".",
"CONF_USERNAME",
":",
"\"us3r\"",
",",
"mqtt",
".",
"CONF_PASSWORD",
":",
"\"p4ss\"",
",",
"}",
"for",
"k",
",",
"v",
"in",
"defaults",
".",
"items",
"(",
")",
":",
"assert",
"get_default",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"for",
"k",
",",
"v",
"in",
"suggested",
".",
"items",
"(",
")",
":",
"assert",
"get_suggested",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"defaults",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"False",
",",
"\"birth_qos\"",
":",
"2",
",",
"\"birth_retain\"",
":",
"False",
",",
"\"will_qos\"",
":",
"1",
",",
"\"will_retain\"",
":",
"True",
",",
"}",
"suggested",
"=",
"{",
"\"birth_topic\"",
":",
"\"ha_state/onl1ne\"",
",",
"\"birth_payload\"",
":",
"\"onl1ne\"",
",",
"\"will_topic\"",
":",
"\"ha_state/offl1ne\"",
",",
"\"will_payload\"",
":",
"\"offl1ne\"",
",",
"}",
"for",
"k",
",",
"v",
"in",
"defaults",
".",
"items",
"(",
")",
":",
"assert",
"get_default",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"for",
"k",
",",
"v",
"in",
"suggested",
".",
"items",
"(",
")",
":",
"assert",
"get_suggested",
"(",
"result",
"[",
"\"data_schema\"",
"]",
".",
"schema",
",",
"k",
")",
"==",
"v",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_DISCOVERY",
":",
"True",
",",
"\"birth_topic\"",
":",
"\"ha_state/onl1ne\"",
",",
"\"birth_payload\"",
":",
"\"onl1ne\"",
",",
"\"birth_qos\"",
":",
"2",
",",
"\"birth_retain\"",
":",
"False",
",",
"\"will_topic\"",
":",
"\"ha_state/offl1ne\"",
",",
"\"will_payload\"",
":",
"\"offl1ne\"",
",",
"\"will_qos\"",
":",
"1",
",",
"\"will_retain\"",
":",
"True",
",",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY"
] | [
303,
0
] | [
446,
69
] | python | en | ['en', 'en', 'en'] | True |
test_options_user_connection_fails | (hass, mock_try_connection) | Test if connection cannot be made. | Test if connection cannot be made. | async def test_options_user_connection_fails(hass, mock_try_connection):
"""Test if connection cannot be made."""
config_entry = MockConfigEntry(domain=mqtt.DOMAIN)
config_entry.add_to_hass(hass)
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
mock_try_connection.return_value = False
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == "form"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={mqtt.CONF_BROKER: "bad-broker", mqtt.CONF_PORT: 2345},
)
assert result["type"] == "form"
assert result["errors"]["base"] == "cannot_connect"
# Check we tried the connection
assert len(mock_try_connection.mock_calls) == 1
# Check config entry did not update
assert config_entry.data == {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
} | [
"async",
"def",
"test_options_user_connection_fails",
"(",
"hass",
",",
"mock_try_connection",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"mqtt",
".",
"DOMAIN",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"mock_try_connection",
".",
"return_value",
"=",
"False",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"bad-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"[",
"\"base\"",
"]",
"==",
"\"cannot_connect\"",
"# Check we tried the connection",
"assert",
"len",
"(",
"mock_try_connection",
".",
"mock_calls",
")",
"==",
"1",
"# Check config entry did not update",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}"
] | [
449,
0
] | [
477,
5
] | python | en | ['en', 'en', 'en'] | True |
test_options_bad_birth_message_fails | (hass, mock_try_connection) | Test bad birth message. | Test bad birth message. | async def test_options_bad_birth_message_fails(hass, mock_try_connection):
"""Test bad birth message."""
config_entry = MockConfigEntry(domain=mqtt.DOMAIN)
config_entry.add_to_hass(hass)
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
mock_try_connection.return_value = True
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == "form"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={mqtt.CONF_BROKER: "another-broker", mqtt.CONF_PORT: 2345},
)
assert result["type"] == "form"
assert result["step_id"] == "options"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"birth_topic": "ha_state/online/#"},
)
assert result["type"] == "form"
assert result["errors"]["base"] == "bad_birth"
# Check config entry did not update
assert config_entry.data == {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
} | [
"async",
"def",
"test_options_bad_birth_message_fails",
"(",
"hass",
",",
"mock_try_connection",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"mqtt",
".",
"DOMAIN",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"\"birth_topic\"",
":",
"\"ha_state/online/#\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"[",
"\"base\"",
"]",
"==",
"\"bad_birth\"",
"# Check config entry did not update",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}"
] | [
480,
0
] | [
513,
5
] | python | en | ['en', 'de', 'en'] | True |
test_options_bad_will_message_fails | (hass, mock_try_connection) | Test bad will message. | Test bad will message. | async def test_options_bad_will_message_fails(hass, mock_try_connection):
"""Test bad will message."""
config_entry = MockConfigEntry(domain=mqtt.DOMAIN)
config_entry.add_to_hass(hass)
config_entry.data = {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
}
mock_try_connection.return_value = True
result = await hass.config_entries.options.async_init(config_entry.entry_id)
assert result["type"] == "form"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={mqtt.CONF_BROKER: "another-broker", mqtt.CONF_PORT: 2345},
)
assert result["type"] == "form"
assert result["step_id"] == "options"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"will_topic": "ha_state/offline/#"},
)
assert result["type"] == "form"
assert result["errors"]["base"] == "bad_will"
# Check config entry did not update
assert config_entry.data == {
mqtt.CONF_BROKER: "test-broker",
mqtt.CONF_PORT: 1234,
} | [
"async",
"def",
"test_options_bad_will_message_fails",
"(",
"hass",
",",
"mock_try_connection",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"mqtt",
".",
"DOMAIN",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"config_entry",
".",
"data",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}",
"mock_try_connection",
".",
"return_value",
"=",
"True",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"another-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"2345",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"options\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"\"will_topic\"",
":",
"\"ha_state/offline/#\"",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"[",
"\"base\"",
"]",
"==",
"\"bad_will\"",
"# Check config entry did not update",
"assert",
"config_entry",
".",
"data",
"==",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"test-broker\"",
",",
"mqtt",
".",
"CONF_PORT",
":",
"1234",
",",
"}"
] | [
516,
0
] | [
549,
5
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Greenwave Reality Platform. | Set up the Greenwave Reality Platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Greenwave Reality Platform."""
host = config.get(CONF_HOST)
tokenfile = hass.config.path(".greenwave")
if config.get(CONF_VERSION) == 3:
if os.path.exists(tokenfile):
with open(tokenfile) as tokenfile:
token = tokenfile.read()
else:
try:
token = greenwave.grab_token(host, "hass", "homeassistant")
except PermissionError:
_LOGGER.error("The Gateway Is Not In Sync Mode")
raise
with open(tokenfile, "w+") as tokenfile:
tokenfile.write(token)
else:
token = None
bulbs = greenwave.grab_bulbs(host, token)
add_entities(
GreenwaveLight(device, host, token, GatewayData(host, token))
for device in bulbs.values()
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"tokenfile",
"=",
"hass",
".",
"config",
".",
"path",
"(",
"\".greenwave\"",
")",
"if",
"config",
".",
"get",
"(",
"CONF_VERSION",
")",
"==",
"3",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"tokenfile",
")",
":",
"with",
"open",
"(",
"tokenfile",
")",
"as",
"tokenfile",
":",
"token",
"=",
"tokenfile",
".",
"read",
"(",
")",
"else",
":",
"try",
":",
"token",
"=",
"greenwave",
".",
"grab_token",
"(",
"host",
",",
"\"hass\"",
",",
"\"homeassistant\"",
")",
"except",
"PermissionError",
":",
"_LOGGER",
".",
"error",
"(",
"\"The Gateway Is Not In Sync Mode\"",
")",
"raise",
"with",
"open",
"(",
"tokenfile",
",",
"\"w+\"",
")",
"as",
"tokenfile",
":",
"tokenfile",
".",
"write",
"(",
"token",
")",
"else",
":",
"token",
"=",
"None",
"bulbs",
"=",
"greenwave",
".",
"grab_bulbs",
"(",
"host",
",",
"token",
")",
"add_entities",
"(",
"GreenwaveLight",
"(",
"device",
",",
"host",
",",
"token",
",",
"GatewayData",
"(",
"host",
",",
"token",
")",
")",
"for",
"device",
"in",
"bulbs",
".",
"values",
"(",
")",
")"
] | [
31,
0
] | [
53,
5
] | python | en | ['en', 'da', 'en'] | True |
GreenwaveLight.__init__ | (self, light, host, token, gatewaydata) | Initialize a Greenwave Reality Light. | Initialize a Greenwave Reality Light. | def __init__(self, light, host, token, gatewaydata):
"""Initialize a Greenwave Reality Light."""
self._did = int(light["did"])
self._name = light["name"]
self._state = int(light["state"])
self._brightness = greenwave.hass_brightness(light)
self._host = host
self._online = greenwave.check_online(light)
self._token = token
self._gatewaydata = gatewaydata | [
"def",
"__init__",
"(",
"self",
",",
"light",
",",
"host",
",",
"token",
",",
"gatewaydata",
")",
":",
"self",
".",
"_did",
"=",
"int",
"(",
"light",
"[",
"\"did\"",
"]",
")",
"self",
".",
"_name",
"=",
"light",
"[",
"\"name\"",
"]",
"self",
".",
"_state",
"=",
"int",
"(",
"light",
"[",
"\"state\"",
"]",
")",
"self",
".",
"_brightness",
"=",
"greenwave",
".",
"hass_brightness",
"(",
"light",
")",
"self",
".",
"_host",
"=",
"host",
"self",
".",
"_online",
"=",
"greenwave",
".",
"check_online",
"(",
"light",
")",
"self",
".",
"_token",
"=",
"token",
"self",
".",
"_gatewaydata",
"=",
"gatewaydata"
] | [
59,
4
] | [
68,
39
] | python | en | ['en', 'en', 'en'] | True |
GreenwaveLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORTED_FEATURES | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORTED_FEATURES"
] | [
71,
4
] | [
73,
33
] | python | en | ['da', 'en', 'en'] | True |
GreenwaveLight.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return self._online | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_online"
] | [
76,
4
] | [
78,
27
] | python | en | ['en', 'en', 'en'] | True |
GreenwaveLight.name | (self) | Return the display name of this light. | Return the display name of this light. | def name(self):
"""Return the display name of this light."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
81,
4
] | [
83,
25
] | python | en | ['en', 'en', 'en'] | True |
GreenwaveLight.brightness | (self) | Return the brightness of the light. | Return the brightness of the light. | def brightness(self):
"""Return the brightness of the light."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
86,
4
] | [
88,
31
] | python | en | ['en', 'no', 'en'] | True |
GreenwaveLight.is_on | (self) | Return true if light is on. | Return true if light is on. | def is_on(self):
"""Return true if light is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
91,
4
] | [
93,
26
] | python | en | ['en', 'et', 'en'] | True |
GreenwaveLight.turn_on | (self, **kwargs) | Instruct the light to turn on. | Instruct the light to turn on. | def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
temp_brightness = int((kwargs.get(ATTR_BRIGHTNESS, 255) / 255) * 100)
greenwave.set_brightness(self._host, self._did, temp_brightness, self._token)
greenwave.turn_on(self._host, self._did, self._token) | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"temp_brightness",
"=",
"int",
"(",
"(",
"kwargs",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
",",
"255",
")",
"/",
"255",
")",
"*",
"100",
")",
"greenwave",
".",
"set_brightness",
"(",
"self",
".",
"_host",
",",
"self",
".",
"_did",
",",
"temp_brightness",
",",
"self",
".",
"_token",
")",
"greenwave",
".",
"turn_on",
"(",
"self",
".",
"_host",
",",
"self",
".",
"_did",
",",
"self",
".",
"_token",
")"
] | [
95,
4
] | [
99,
61
] | python | en | ['en', 'en', 'en'] | True |
GreenwaveLight.turn_off | (self, **kwargs) | Instruct the light to turn off. | Instruct the light to turn off. | def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
greenwave.turn_off(self._host, self._did, self._token) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"greenwave",
".",
"turn_off",
"(",
"self",
".",
"_host",
",",
"self",
".",
"_did",
",",
"self",
".",
"_token",
")"
] | [
101,
4
] | [
103,
62
] | python | en | ['en', 'en', 'en'] | True |
GreenwaveLight.update | (self) | Fetch new state data for this light. | Fetch new state data for this light. | def update(self):
"""Fetch new state data for this light."""
self._gatewaydata.update()
bulbs = self._gatewaydata.greenwave
self._state = int(bulbs[self._did]["state"])
self._brightness = greenwave.hass_brightness(bulbs[self._did])
self._online = greenwave.check_online(bulbs[self._did])
self._name = bulbs[self._did]["name"] | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_gatewaydata",
".",
"update",
"(",
")",
"bulbs",
"=",
"self",
".",
"_gatewaydata",
".",
"greenwave",
"self",
".",
"_state",
"=",
"int",
"(",
"bulbs",
"[",
"self",
".",
"_did",
"]",
"[",
"\"state\"",
"]",
")",
"self",
".",
"_brightness",
"=",
"greenwave",
".",
"hass_brightness",
"(",
"bulbs",
"[",
"self",
".",
"_did",
"]",
")",
"self",
".",
"_online",
"=",
"greenwave",
".",
"check_online",
"(",
"bulbs",
"[",
"self",
".",
"_did",
"]",
")",
"self",
".",
"_name",
"=",
"bulbs",
"[",
"self",
".",
"_did",
"]",
"[",
"\"name\"",
"]"
] | [
105,
4
] | [
113,
45
] | python | en | ['en', 'en', 'en'] | True |
GatewayData.__init__ | (self, host, token) | Initialize the data object. | Initialize the data object. | def __init__(self, host, token):
"""Initialize the data object."""
self._host = host
self._token = token
self._greenwave = greenwave.grab_bulbs(host, token) | [
"def",
"__init__",
"(",
"self",
",",
"host",
",",
"token",
")",
":",
"self",
".",
"_host",
"=",
"host",
"self",
".",
"_token",
"=",
"token",
"self",
".",
"_greenwave",
"=",
"greenwave",
".",
"grab_bulbs",
"(",
"host",
",",
"token",
")"
] | [
119,
4
] | [
123,
59
] | python | en | ['en', 'en', 'en'] | True |
GatewayData.greenwave | (self) | Return Gateway API object. | Return Gateway API object. | def greenwave(self):
"""Return Gateway API object."""
return self._greenwave | [
"def",
"greenwave",
"(",
"self",
")",
":",
"return",
"self",
".",
"_greenwave"
] | [
126,
4
] | [
128,
30
] | python | en | ['en', 'pl', 'en'] | True |
GatewayData.update | (self) | Get the latest data from the gateway. | Get the latest data from the gateway. | def update(self):
"""Get the latest data from the gateway."""
self._greenwave = greenwave.grab_bulbs(self._host, self._token)
return self._greenwave | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_greenwave",
"=",
"greenwave",
".",
"grab_bulbs",
"(",
"self",
".",
"_host",
",",
"self",
".",
"_token",
")",
"return",
"self",
".",
"_greenwave"
] | [
131,
4
] | [
134,
30
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Add binary sensors for a config entry. | Add binary sensors for a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add binary sensors for a config entry."""
broker = hass.data[DOMAIN][DATA_BROKERS][config_entry.entry_id]
sensors = []
for device in broker.devices.values():
for capability in broker.get_assigned(device.device_id, "binary_sensor"):
attrib = CAPABILITY_TO_ATTRIB[capability]
sensors.append(SmartThingsBinarySensor(device, attrib))
async_add_entities(sensors) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"broker",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"DATA_BROKERS",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"sensors",
"=",
"[",
"]",
"for",
"device",
"in",
"broker",
".",
"devices",
".",
"values",
"(",
")",
":",
"for",
"capability",
"in",
"broker",
".",
"get_assigned",
"(",
"device",
".",
"device_id",
",",
"\"binary_sensor\"",
")",
":",
"attrib",
"=",
"CAPABILITY_TO_ATTRIB",
"[",
"capability",
"]",
"sensors",
".",
"append",
"(",
"SmartThingsBinarySensor",
"(",
"device",
",",
"attrib",
")",
")",
"async_add_entities",
"(",
"sensors",
")"
] | [
43,
0
] | [
51,
31
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.