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_if_action_after_sunset_no_offset_kotzebue | (hass, calls) |
Test if action was after sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
After sunset is true from sunset until midnight, local time.
|
Test if action was after sunrise. | async def test_if_action_after_sunset_no_offset_kotzebue(hass, calls):
"""
Test if action was after sunrise.
Local timezone: Alaska time
Location: Kotzebue, which has a very skewed local timezone with sunrise
at 7 AM and sunset at 3AM during summer
After sunset is true from sunset until midnight, local time.
"""
tz = dt_util.get_time_zone("America/Anchorage")
dt_util.set_default_time_zone(tz)
hass.config.latitude = 66.5
hass.config.longitude = 162.4
await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": {"condition": "sun", "after": SUN_EVENT_SUNSET},
"action": {"service": "test.automation"},
}
},
)
# sunrise: 2015-07-24 07:17:24 local, sunset: 2015-07-25 03:16:27 local
# sunrise: 2015-07-24 15:17:24 UTC, sunset: 2015-07-25 11:16:27 UTC
# now = sunset -> 'after sunset' true
now = datetime(2015, 7, 25, 11, 16, 27, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = sunset - 1s -> 'after sunset' not true
now = datetime(2015, 7, 25, 11, 16, 26, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight -> 'after sunset' not true
now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1
# now = local midnight - 1s -> 'after sunset' true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_action_after_sunset_no_offset_kotzebue",
"(",
"hass",
",",
"calls",
")",
":",
"tz",
"=",
"dt_util",
".",
"get_time_zone",
"(",
"\"America/Anchorage\"",
")",
"dt_util",
".",
"set_default_time_zone",
"(",
"tz",
")",
"hass",
".",
"config",
".",
"latitude",
"=",
"66.5",
"hass",
".",
"config",
".",
"longitude",
"=",
"162.4",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event\"",
"}",
",",
"\"condition\"",
":",
"{",
"\"condition\"",
":",
"\"sun\"",
",",
"\"after\"",
":",
"SUN_EVENT_SUNSET",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"# sunrise: 2015-07-24 07:17:24 local, sunset: 2015-07-25 03:16:27 local",
"# sunrise: 2015-07-24 15:17:24 UTC, sunset: 2015-07-25 11:16:27 UTC",
"# now = sunset -> 'after sunset' true",
"now",
"=",
"datetime",
"(",
"2015",
",",
"7",
",",
"25",
",",
"11",
",",
"16",
",",
"27",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"now",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"# now = sunset - 1s -> 'after sunset' not true",
"now",
"=",
"datetime",
"(",
"2015",
",",
"7",
",",
"25",
",",
"11",
",",
"16",
",",
"26",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"now",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"# now = local midnight -> 'after sunset' not true",
"now",
"=",
"datetime",
"(",
"2015",
",",
"7",
",",
"24",
",",
"8",
",",
"0",
",",
"1",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"now",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"# now = local midnight - 1s -> 'after sunset' true",
"now",
"=",
"datetime",
"(",
"2015",
",",
"7",
",",
"24",
",",
"7",
",",
"59",
",",
"59",
",",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"now",
")",
":",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2"
] | [
803,
0
] | [
856,
30
] | python | en | ['en', 'error', 'th'] | False |
test_setup_entry_account_error | (hass) | Test entry setup failed due to account error. | Test entry setup failed due to account error. | async def test_setup_entry_account_error(hass):
"""Test entry setup failed due to account error."""
entry = MockConfigEntry(
domain=DOMAIN,
title="test_username",
unique_id="test_username",
data=CONFIG,
options=None,
)
with patch(
"homeassistant.components.dexcom.Dexcom",
side_effect=AccountError,
):
entry.add_to_hass(hass)
result = await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert result is False | [
"async",
"def",
"test_setup_entry_account_error",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"\"test_username\"",
",",
"unique_id",
"=",
"\"test_username\"",
",",
"data",
"=",
"CONFIG",
",",
"options",
"=",
"None",
",",
")",
"with",
"patch",
"(",
"\"homeassistant.components.dexcom.Dexcom\"",
",",
"side_effect",
"=",
"AccountError",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result",
"is",
"False"
] | [
11,
0
] | [
28,
26
] | python | en | ['en', 'en', 'en'] | True |
test_setup_entry_session_error | (hass) | Test entry setup failed due to session error. | Test entry setup failed due to session error. | async def test_setup_entry_session_error(hass):
"""Test entry setup failed due to session error."""
entry = MockConfigEntry(
domain=DOMAIN,
title="test_username",
unique_id="test_username",
data=CONFIG,
options=None,
)
with patch(
"homeassistant.components.dexcom.Dexcom",
side_effect=SessionError,
):
entry.add_to_hass(hass)
result = await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert result is False | [
"async",
"def",
"test_setup_entry_session_error",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"\"test_username\"",
",",
"unique_id",
"=",
"\"test_username\"",
",",
"data",
"=",
"CONFIG",
",",
"options",
"=",
"None",
",",
")",
"with",
"patch",
"(",
"\"homeassistant.components.dexcom.Dexcom\"",
",",
"side_effect",
"=",
"SessionError",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result",
"is",
"False"
] | [
31,
0
] | [
48,
26
] | python | en | ['en', 'en', 'en'] | True |
test_unload_entry | (hass) | Test successful unload of entry. | Test successful unload of entry. | async def test_unload_entry(hass):
"""Test successful unload of entry."""
entry = await init_integration(hass)
assert len(hass.config_entries.async_entries(DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED
assert await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ENTRY_STATE_NOT_LOADED
assert not hass.data.get(DOMAIN) | [
"async",
"def",
"test_unload_entry",
"(",
"hass",
")",
":",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_NOT_LOADED",
"assert",
"not",
"hass",
".",
"data",
".",
"get",
"(",
"DOMAIN",
")"
] | [
51,
0
] | [
62,
36
] | python | en | ['en', 'en', 'en'] | True |
get_layers_to_supervise | (n_student, n_teacher) | Used or the --supervise_forward kwarg | Used or the --supervise_forward kwarg | def get_layers_to_supervise(n_student, n_teacher) -> List[int]:
"""Used or the --supervise_forward kwarg"""
if n_student > n_teacher:
raise ValueError(f"Cannot perform intermediate supervision for student {n_student} > teacher {n_teacher}")
elif n_teacher == n_student:
return list(range(n_teacher))
elif n_student == 1:
return [n_teacher - 1]
else:
return LAYERS_TO_SUPERVISE[n_teacher][n_student] | [
"def",
"get_layers_to_supervise",
"(",
"n_student",
",",
"n_teacher",
")",
"->",
"List",
"[",
"int",
"]",
":",
"if",
"n_student",
">",
"n_teacher",
":",
"raise",
"ValueError",
"(",
"f\"Cannot perform intermediate supervision for student {n_student} > teacher {n_teacher}\"",
")",
"elif",
"n_teacher",
"==",
"n_student",
":",
"return",
"list",
"(",
"range",
"(",
"n_teacher",
")",
")",
"elif",
"n_student",
"==",
"1",
":",
"return",
"[",
"n_teacher",
"-",
"1",
"]",
"else",
":",
"return",
"LAYERS_TO_SUPERVISE",
"[",
"n_teacher",
"]",
"[",
"n_student",
"]"
] | [
65,
0
] | [
74,
56
] | python | en | ['en', 'en', 'sw'] | True |
create_student_by_copying_alternating_layers | (
teacher: Union[str, PreTrainedModel],
save_path: Union[str, Path] = "student",
e: Union[int, None] = None,
d: Union[int, None] = None,
copy_first_teacher_layers=False,
e_layers_to_copy=None,
d_layers_to_copy=None,
**extra_config_kwargs
) | Make a student by copying alternating layers from a teacher, save it to save_path.
Args:
teacher: str or PreTrainedModel if str, this will call AutoModelForSeq2SeqLM.from_pretrained(teacher) before
copying layers
save_path: where to save the student, defaults to student directory.
e: how many Encoder layers should the student have, default is fully copy of teacher
d: how many Decoder layers should the student have, default is fully copy of teacher
copy_first_teacher_layers: [bool] dont copy alternating layers, just the first e/d.
**extra_config_kwargs: extra kwargs to pass to the student, by default the teacher config is used.
Returns:
student: new, smaller model. (Also saves it to save_path)
e_layers_to_copy: list of which teacher encoder layers were used
d_layers_to_copy: list of which teacher decoder layers were used
| Make a student by copying alternating layers from a teacher, save it to save_path.
Args:
teacher: str or PreTrainedModel if str, this will call AutoModelForSeq2SeqLM.from_pretrained(teacher) before
copying layers
save_path: where to save the student, defaults to student directory.
e: how many Encoder layers should the student have, default is fully copy of teacher
d: how many Decoder layers should the student have, default is fully copy of teacher
copy_first_teacher_layers: [bool] dont copy alternating layers, just the first e/d.
**extra_config_kwargs: extra kwargs to pass to the student, by default the teacher config is used. | def create_student_by_copying_alternating_layers(
teacher: Union[str, PreTrainedModel],
save_path: Union[str, Path] = "student",
e: Union[int, None] = None,
d: Union[int, None] = None,
copy_first_teacher_layers=False,
e_layers_to_copy=None,
d_layers_to_copy=None,
**extra_config_kwargs
) -> Tuple[PreTrainedModel, List[int], List[int]]:
"""Make a student by copying alternating layers from a teacher, save it to save_path.
Args:
teacher: str or PreTrainedModel if str, this will call AutoModelForSeq2SeqLM.from_pretrained(teacher) before
copying layers
save_path: where to save the student, defaults to student directory.
e: how many Encoder layers should the student have, default is fully copy of teacher
d: how many Decoder layers should the student have, default is fully copy of teacher
copy_first_teacher_layers: [bool] dont copy alternating layers, just the first e/d.
**extra_config_kwargs: extra kwargs to pass to the student, by default the teacher config is used.
Returns:
student: new, smaller model. (Also saves it to save_path)
e_layers_to_copy: list of which teacher encoder layers were used
d_layers_to_copy: list of which teacher decoder layers were used
"""
_msg = "encoder_layers and decoder_layers cannot be both None-- you would just have an identical teacher."
assert (e is not None) or (d is not None), _msg
if isinstance(teacher, str):
AutoTokenizer.from_pretrained(teacher).save_pretrained(save_path) # purely for convenience
teacher = AutoModelForSeq2SeqLM.from_pretrained(teacher).eval()
else:
assert isinstance(teacher, PreTrainedModel), f"teacher must be a model or string got type {type(teacher)}"
init_kwargs = teacher.config.to_diff_dict()
try:
teacher_e, teacher_d = teacher.config.encoder_layers, teacher.config.decoder_layers
if e is None:
e = teacher_e
if d is None:
d = teacher_d
init_kwargs.update({"encoder_layers": e, "decoder_layers": d})
except AttributeError: # T5
teacher_e, teacher_d = teacher.config.num_layers, teacher.config.num_decoder_layers
if e is None:
e = teacher_e
if d is None:
d = teacher_d
init_kwargs.update({"num_layers": e, "num_decoder_layers": d})
# Kwargs to instantiate student: teacher kwargs with updated layer numbers + **extra_config_kwargs
init_kwargs.update(extra_config_kwargs)
# Copy weights
student_cfg = teacher.config_class(**init_kwargs)
student = AutoModelForSeq2SeqLM.from_config(student_cfg)
# Start by copying the full teacher state dict this will copy the first N teacher layers to the student.
info = student.load_state_dict(teacher.state_dict(), strict=False)
assert info.missing_keys == [], info.missing_keys # every student key should have a teacher keys.
if copy_first_teacher_layers: # Our copying is done. We just log and save
e_layers_to_copy, d_layers_to_copy = list(range(e)), list(range(d))
logger.info(
f"Copied encoder layers {e_layers_to_copy} and decoder layers {d_layers_to_copy}. Saving them to {save_path}"
)
student.save_pretrained(save_path)
return student, e_layers_to_copy, d_layers_to_copy
# Decide which layers of the teacher to copy. Not exactly alternating -- we try to keep first and last layer.
if e_layers_to_copy is None:
e_layers_to_copy: List[int] = pick_layers_to_copy(e, teacher_e)
if d_layers_to_copy is None:
d_layers_to_copy: List[int] = pick_layers_to_copy(d, teacher_d)
try:
copy_layers(teacher.model.encoder.layers, student.model.encoder.layers, e_layers_to_copy)
copy_layers(teacher.model.decoder.layers, student.model.decoder.layers, d_layers_to_copy)
except AttributeError: # For t5, student.model.encoder.layers is called student.encoder.block
copy_layers(teacher.encoder.block, student.encoder.block, e_layers_to_copy)
copy_layers(teacher.decoder.block, student.decoder.block, d_layers_to_copy)
logger.info(
f"Copied encoder layers {e_layers_to_copy} and decoder layers {d_layers_to_copy}. Saving them to {save_path}"
)
student.config.init_metadata = dict(
teacher_type=teacher.config.model_type,
copied_encoder_layers=e_layers_to_copy,
copied_decoder_layers=d_layers_to_copy,
)
student.save_pretrained(save_path)
# Save information about copying for easier reproducibility
return student, e_layers_to_copy, d_layers_to_copy | [
"def",
"create_student_by_copying_alternating_layers",
"(",
"teacher",
":",
"Union",
"[",
"str",
",",
"PreTrainedModel",
"]",
",",
"save_path",
":",
"Union",
"[",
"str",
",",
"Path",
"]",
"=",
"\"student\"",
",",
"e",
":",
"Union",
"[",
"int",
",",
"None",
"]",
"=",
"None",
",",
"d",
":",
"Union",
"[",
"int",
",",
"None",
"]",
"=",
"None",
",",
"copy_first_teacher_layers",
"=",
"False",
",",
"e_layers_to_copy",
"=",
"None",
",",
"d_layers_to_copy",
"=",
"None",
",",
"*",
"*",
"extra_config_kwargs",
")",
"->",
"Tuple",
"[",
"PreTrainedModel",
",",
"List",
"[",
"int",
"]",
",",
"List",
"[",
"int",
"]",
"]",
":",
"_msg",
"=",
"\"encoder_layers and decoder_layers cannot be both None-- you would just have an identical teacher.\"",
"assert",
"(",
"e",
"is",
"not",
"None",
")",
"or",
"(",
"d",
"is",
"not",
"None",
")",
",",
"_msg",
"if",
"isinstance",
"(",
"teacher",
",",
"str",
")",
":",
"AutoTokenizer",
".",
"from_pretrained",
"(",
"teacher",
")",
".",
"save_pretrained",
"(",
"save_path",
")",
"# purely for convenience",
"teacher",
"=",
"AutoModelForSeq2SeqLM",
".",
"from_pretrained",
"(",
"teacher",
")",
".",
"eval",
"(",
")",
"else",
":",
"assert",
"isinstance",
"(",
"teacher",
",",
"PreTrainedModel",
")",
",",
"f\"teacher must be a model or string got type {type(teacher)}\"",
"init_kwargs",
"=",
"teacher",
".",
"config",
".",
"to_diff_dict",
"(",
")",
"try",
":",
"teacher_e",
",",
"teacher_d",
"=",
"teacher",
".",
"config",
".",
"encoder_layers",
",",
"teacher",
".",
"config",
".",
"decoder_layers",
"if",
"e",
"is",
"None",
":",
"e",
"=",
"teacher_e",
"if",
"d",
"is",
"None",
":",
"d",
"=",
"teacher_d",
"init_kwargs",
".",
"update",
"(",
"{",
"\"encoder_layers\"",
":",
"e",
",",
"\"decoder_layers\"",
":",
"d",
"}",
")",
"except",
"AttributeError",
":",
"# T5",
"teacher_e",
",",
"teacher_d",
"=",
"teacher",
".",
"config",
".",
"num_layers",
",",
"teacher",
".",
"config",
".",
"num_decoder_layers",
"if",
"e",
"is",
"None",
":",
"e",
"=",
"teacher_e",
"if",
"d",
"is",
"None",
":",
"d",
"=",
"teacher_d",
"init_kwargs",
".",
"update",
"(",
"{",
"\"num_layers\"",
":",
"e",
",",
"\"num_decoder_layers\"",
":",
"d",
"}",
")",
"# Kwargs to instantiate student: teacher kwargs with updated layer numbers + **extra_config_kwargs",
"init_kwargs",
".",
"update",
"(",
"extra_config_kwargs",
")",
"# Copy weights",
"student_cfg",
"=",
"teacher",
".",
"config_class",
"(",
"*",
"*",
"init_kwargs",
")",
"student",
"=",
"AutoModelForSeq2SeqLM",
".",
"from_config",
"(",
"student_cfg",
")",
"# Start by copying the full teacher state dict this will copy the first N teacher layers to the student.",
"info",
"=",
"student",
".",
"load_state_dict",
"(",
"teacher",
".",
"state_dict",
"(",
")",
",",
"strict",
"=",
"False",
")",
"assert",
"info",
".",
"missing_keys",
"==",
"[",
"]",
",",
"info",
".",
"missing_keys",
"# every student key should have a teacher keys.",
"if",
"copy_first_teacher_layers",
":",
"# Our copying is done. We just log and save",
"e_layers_to_copy",
",",
"d_layers_to_copy",
"=",
"list",
"(",
"range",
"(",
"e",
")",
")",
",",
"list",
"(",
"range",
"(",
"d",
")",
")",
"logger",
".",
"info",
"(",
"f\"Copied encoder layers {e_layers_to_copy} and decoder layers {d_layers_to_copy}. Saving them to {save_path}\"",
")",
"student",
".",
"save_pretrained",
"(",
"save_path",
")",
"return",
"student",
",",
"e_layers_to_copy",
",",
"d_layers_to_copy",
"# Decide which layers of the teacher to copy. Not exactly alternating -- we try to keep first and last layer.",
"if",
"e_layers_to_copy",
"is",
"None",
":",
"e_layers_to_copy",
":",
"List",
"[",
"int",
"]",
"=",
"pick_layers_to_copy",
"(",
"e",
",",
"teacher_e",
")",
"if",
"d_layers_to_copy",
"is",
"None",
":",
"d_layers_to_copy",
":",
"List",
"[",
"int",
"]",
"=",
"pick_layers_to_copy",
"(",
"d",
",",
"teacher_d",
")",
"try",
":",
"copy_layers",
"(",
"teacher",
".",
"model",
".",
"encoder",
".",
"layers",
",",
"student",
".",
"model",
".",
"encoder",
".",
"layers",
",",
"e_layers_to_copy",
")",
"copy_layers",
"(",
"teacher",
".",
"model",
".",
"decoder",
".",
"layers",
",",
"student",
".",
"model",
".",
"decoder",
".",
"layers",
",",
"d_layers_to_copy",
")",
"except",
"AttributeError",
":",
"# For t5, student.model.encoder.layers is called student.encoder.block",
"copy_layers",
"(",
"teacher",
".",
"encoder",
".",
"block",
",",
"student",
".",
"encoder",
".",
"block",
",",
"e_layers_to_copy",
")",
"copy_layers",
"(",
"teacher",
".",
"decoder",
".",
"block",
",",
"student",
".",
"decoder",
".",
"block",
",",
"d_layers_to_copy",
")",
"logger",
".",
"info",
"(",
"f\"Copied encoder layers {e_layers_to_copy} and decoder layers {d_layers_to_copy}. Saving them to {save_path}\"",
")",
"student",
".",
"config",
".",
"init_metadata",
"=",
"dict",
"(",
"teacher_type",
"=",
"teacher",
".",
"config",
".",
"model_type",
",",
"copied_encoder_layers",
"=",
"e_layers_to_copy",
",",
"copied_decoder_layers",
"=",
"d_layers_to_copy",
",",
")",
"student",
".",
"save_pretrained",
"(",
"save_path",
")",
"# Save information about copying for easier reproducibility",
"return",
"student",
",",
"e_layers_to_copy",
",",
"d_layers_to_copy"
] | [
77,
0
] | [
168,
54
] | python | en | ['en', 'en', 'en'] | True |
determine_zones | (receiver) | Determine what zones are available for the receiver. | Determine what zones are available for the receiver. | def determine_zones(receiver):
"""Determine what zones are available for the receiver."""
out = {"zone2": False, "zone3": False}
try:
_LOGGER.debug("Checking for zone 2 capability")
receiver.raw("ZPWQSTN")
out["zone2"] = True
except ValueError as error:
if str(error) != TIMEOUT_MESSAGE:
raise error
_LOGGER.debug("Zone 2 timed out, assuming no functionality")
try:
_LOGGER.debug("Checking for zone 3 capability")
receiver.raw("PW3QSTN")
out["zone3"] = True
except ValueError as error:
if str(error) != TIMEOUT_MESSAGE:
raise error
_LOGGER.debug("Zone 3 timed out, assuming no functionality")
except AssertionError:
_LOGGER.error("Zone 3 detection failed")
return out | [
"def",
"determine_zones",
"(",
"receiver",
")",
":",
"out",
"=",
"{",
"\"zone2\"",
":",
"False",
",",
"\"zone3\"",
":",
"False",
"}",
"try",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Checking for zone 2 capability\"",
")",
"receiver",
".",
"raw",
"(",
"\"ZPWQSTN\"",
")",
"out",
"[",
"\"zone2\"",
"]",
"=",
"True",
"except",
"ValueError",
"as",
"error",
":",
"if",
"str",
"(",
"error",
")",
"!=",
"TIMEOUT_MESSAGE",
":",
"raise",
"error",
"_LOGGER",
".",
"debug",
"(",
"\"Zone 2 timed out, assuming no functionality\"",
")",
"try",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Checking for zone 3 capability\"",
")",
"receiver",
".",
"raw",
"(",
"\"PW3QSTN\"",
")",
"out",
"[",
"\"zone3\"",
"]",
"=",
"True",
"except",
"ValueError",
"as",
"error",
":",
"if",
"str",
"(",
"error",
")",
"!=",
"TIMEOUT_MESSAGE",
":",
"raise",
"error",
"_LOGGER",
".",
"debug",
"(",
"\"Zone 3 timed out, assuming no functionality\"",
")",
"except",
"AssertionError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Zone 3 detection failed\"",
")",
"return",
"out"
] | [
117,
0
] | [
139,
14
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Onkyo platform. | Set up the Onkyo platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Onkyo platform."""
host = config.get(CONF_HOST)
hosts = []
def service_handle(service):
"""Handle for services."""
entity_ids = service.data.get(ATTR_ENTITY_ID)
devices = [d for d in hosts if d.entity_id in entity_ids]
for device in devices:
if service.service == SERVICE_SELECT_HDMI_OUTPUT:
device.select_output(service.data.get(ATTR_HDMI_OUTPUT))
hass.services.register(
DOMAIN,
SERVICE_SELECT_HDMI_OUTPUT,
service_handle,
schema=ONKYO_SELECT_OUTPUT_SCHEMA,
)
if CONF_HOST in config and host not in KNOWN_HOSTS:
try:
receiver = eiscp.eISCP(host)
hosts.append(
OnkyoDevice(
receiver,
config.get(CONF_SOURCES),
name=config.get(CONF_NAME),
max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
)
)
KNOWN_HOSTS.append(host)
zones = determine_zones(receiver)
# Add Zone2 if available
if zones["zone2"]:
_LOGGER.debug("Setting up zone 2")
hosts.append(
OnkyoDeviceZone(
"2",
receiver,
config.get(CONF_SOURCES),
name=f"{config[CONF_NAME]} Zone 2",
max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
)
)
# Add Zone3 if available
if zones["zone3"]:
_LOGGER.debug("Setting up zone 3")
hosts.append(
OnkyoDeviceZone(
"3",
receiver,
config.get(CONF_SOURCES),
name=f"{config[CONF_NAME]} Zone 3",
max_volume=config.get(CONF_MAX_VOLUME),
receiver_max_volume=config.get(CONF_RECEIVER_MAX_VOLUME),
)
)
except OSError:
_LOGGER.error("Unable to connect to receiver at %s", host)
else:
for receiver in eISCP.discover():
if receiver.host not in KNOWN_HOSTS:
hosts.append(OnkyoDevice(receiver, config.get(CONF_SOURCES)))
KNOWN_HOSTS.append(receiver.host)
add_entities(hosts, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"hosts",
"=",
"[",
"]",
"def",
"service_handle",
"(",
"service",
")",
":",
"\"\"\"Handle for services.\"\"\"",
"entity_ids",
"=",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_ENTITY_ID",
")",
"devices",
"=",
"[",
"d",
"for",
"d",
"in",
"hosts",
"if",
"d",
".",
"entity_id",
"in",
"entity_ids",
"]",
"for",
"device",
"in",
"devices",
":",
"if",
"service",
".",
"service",
"==",
"SERVICE_SELECT_HDMI_OUTPUT",
":",
"device",
".",
"select_output",
"(",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_HDMI_OUTPUT",
")",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"SERVICE_SELECT_HDMI_OUTPUT",
",",
"service_handle",
",",
"schema",
"=",
"ONKYO_SELECT_OUTPUT_SCHEMA",
",",
")",
"if",
"CONF_HOST",
"in",
"config",
"and",
"host",
"not",
"in",
"KNOWN_HOSTS",
":",
"try",
":",
"receiver",
"=",
"eiscp",
".",
"eISCP",
"(",
"host",
")",
"hosts",
".",
"append",
"(",
"OnkyoDevice",
"(",
"receiver",
",",
"config",
".",
"get",
"(",
"CONF_SOURCES",
")",
",",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
",",
"max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_MAX_VOLUME",
")",
",",
"receiver_max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_RECEIVER_MAX_VOLUME",
")",
",",
")",
")",
"KNOWN_HOSTS",
".",
"append",
"(",
"host",
")",
"zones",
"=",
"determine_zones",
"(",
"receiver",
")",
"# Add Zone2 if available",
"if",
"zones",
"[",
"\"zone2\"",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting up zone 2\"",
")",
"hosts",
".",
"append",
"(",
"OnkyoDeviceZone",
"(",
"\"2\"",
",",
"receiver",
",",
"config",
".",
"get",
"(",
"CONF_SOURCES",
")",
",",
"name",
"=",
"f\"{config[CONF_NAME]} Zone 2\"",
",",
"max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_MAX_VOLUME",
")",
",",
"receiver_max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_RECEIVER_MAX_VOLUME",
")",
",",
")",
")",
"# Add Zone3 if available",
"if",
"zones",
"[",
"\"zone3\"",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting up zone 3\"",
")",
"hosts",
".",
"append",
"(",
"OnkyoDeviceZone",
"(",
"\"3\"",
",",
"receiver",
",",
"config",
".",
"get",
"(",
"CONF_SOURCES",
")",
",",
"name",
"=",
"f\"{config[CONF_NAME]} Zone 3\"",
",",
"max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_MAX_VOLUME",
")",
",",
"receiver_max_volume",
"=",
"config",
".",
"get",
"(",
"CONF_RECEIVER_MAX_VOLUME",
")",
",",
")",
")",
"except",
"OSError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to connect to receiver at %s\"",
",",
"host",
")",
"else",
":",
"for",
"receiver",
"in",
"eISCP",
".",
"discover",
"(",
")",
":",
"if",
"receiver",
".",
"host",
"not",
"in",
"KNOWN_HOSTS",
":",
"hosts",
".",
"append",
"(",
"OnkyoDevice",
"(",
"receiver",
",",
"config",
".",
"get",
"(",
"CONF_SOURCES",
")",
")",
")",
"KNOWN_HOSTS",
".",
"append",
"(",
"receiver",
".",
"host",
")",
"add_entities",
"(",
"hosts",
",",
"True",
")"
] | [
142,
0
] | [
212,
29
] | python | en | ['en', 'lv', 'en'] | True |
OnkyoDevice.__init__ | (
self,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
) | Initialize the Onkyo Receiver. | Initialize the Onkyo Receiver. | def __init__(
self,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
):
"""Initialize the Onkyo Receiver."""
self._receiver = receiver
self._muted = False
self._volume = 0
self._pwstate = STATE_OFF
self._name = (
name or f"{receiver.info['model_name']}_{receiver.info['identifier']}"
)
self._max_volume = max_volume
self._receiver_max_volume = receiver_max_volume
self._current_source = None
self._source_list = list(sources.values())
self._source_mapping = sources
self._reverse_mapping = {value: key for key, value in sources.items()}
self._attributes = {}
self._hdmi_out_supported = True | [
"def",
"__init__",
"(",
"self",
",",
"receiver",
",",
"sources",
",",
"name",
"=",
"None",
",",
"max_volume",
"=",
"SUPPORTED_MAX_VOLUME",
",",
"receiver_max_volume",
"=",
"DEFAULT_RECEIVER_MAX_VOLUME",
",",
")",
":",
"self",
".",
"_receiver",
"=",
"receiver",
"self",
".",
"_muted",
"=",
"False",
"self",
".",
"_volume",
"=",
"0",
"self",
".",
"_pwstate",
"=",
"STATE_OFF",
"self",
".",
"_name",
"=",
"(",
"name",
"or",
"f\"{receiver.info['model_name']}_{receiver.info['identifier']}\"",
")",
"self",
".",
"_max_volume",
"=",
"max_volume",
"self",
".",
"_receiver_max_volume",
"=",
"receiver_max_volume",
"self",
".",
"_current_source",
"=",
"None",
"self",
".",
"_source_list",
"=",
"list",
"(",
"sources",
".",
"values",
"(",
")",
")",
"self",
".",
"_source_mapping",
"=",
"sources",
"self",
".",
"_reverse_mapping",
"=",
"{",
"value",
":",
"key",
"for",
"key",
",",
"value",
"in",
"sources",
".",
"items",
"(",
")",
"}",
"self",
".",
"_attributes",
"=",
"{",
"}",
"self",
".",
"_hdmi_out_supported",
"=",
"True"
] | [
218,
4
] | [
241,
39
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.command | (self, command) | Run an eiscp command and catch connection errors. | Run an eiscp command and catch connection errors. | def command(self, command):
"""Run an eiscp command and catch connection errors."""
try:
result = self._receiver.command(command)
except (ValueError, OSError, AttributeError, AssertionError):
if self._receiver.command_socket:
self._receiver.command_socket = None
_LOGGER.debug("Resetting connection to %s", self._name)
else:
_LOGGER.info("%s is disconnected. Attempting to reconnect", self._name)
return False
_LOGGER.debug("Result for %s: %s", command, result)
return result | [
"def",
"command",
"(",
"self",
",",
"command",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"_receiver",
".",
"command",
"(",
"command",
")",
"except",
"(",
"ValueError",
",",
"OSError",
",",
"AttributeError",
",",
"AssertionError",
")",
":",
"if",
"self",
".",
"_receiver",
".",
"command_socket",
":",
"self",
".",
"_receiver",
".",
"command_socket",
"=",
"None",
"_LOGGER",
".",
"debug",
"(",
"\"Resetting connection to %s\"",
",",
"self",
".",
"_name",
")",
"else",
":",
"_LOGGER",
".",
"info",
"(",
"\"%s is disconnected. Attempting to reconnect\"",
",",
"self",
".",
"_name",
")",
"return",
"False",
"_LOGGER",
".",
"debug",
"(",
"\"Result for %s: %s\"",
",",
"command",
",",
"result",
")",
"return",
"result"
] | [
243,
4
] | [
255,
21
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.update | (self) | Get the latest state from the device. | Get the latest state from the device. | def update(self):
"""Get the latest state from the device."""
status = self.command("system-power query")
if not status:
return
if status[1] == "on":
self._pwstate = STATE_ON
else:
self._pwstate = STATE_OFF
return
volume_raw = self.command("volume query")
mute_raw = self.command("audio-muting query")
current_source_raw = self.command("input-selector query")
# If the following command is sent to a device with only one HDMI out,
# the display shows 'Not Available'.
# We avoid this by checking if HDMI out is supported
if self._hdmi_out_supported:
hdmi_out_raw = self.command("hdmi-output-selector query")
else:
hdmi_out_raw = []
preset_raw = self.command("preset query")
if not (volume_raw and mute_raw and current_source_raw):
return
# eiscp can return string or tuple. Make everything tuples.
if isinstance(current_source_raw[1], str):
current_source_tuples = (current_source_raw[0], (current_source_raw[1],))
else:
current_source_tuples = current_source_raw
for source in current_source_tuples[1]:
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
self._current_source = "_".join(current_source_tuples[1])
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]
elif ATTR_PRESET in self._attributes:
del self._attributes[ATTR_PRESET]
self._muted = bool(mute_raw[1] == "on")
# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
self._volume = volume_raw[1] / (
self._receiver_max_volume * self._max_volume / 100
)
if not hdmi_out_raw:
return
self._attributes["video_out"] = ",".join(hdmi_out_raw[1])
if hdmi_out_raw[1] == "N/A":
self._hdmi_out_supported = False | [
"def",
"update",
"(",
"self",
")",
":",
"status",
"=",
"self",
".",
"command",
"(",
"\"system-power query\"",
")",
"if",
"not",
"status",
":",
"return",
"if",
"status",
"[",
"1",
"]",
"==",
"\"on\"",
":",
"self",
".",
"_pwstate",
"=",
"STATE_ON",
"else",
":",
"self",
".",
"_pwstate",
"=",
"STATE_OFF",
"return",
"volume_raw",
"=",
"self",
".",
"command",
"(",
"\"volume query\"",
")",
"mute_raw",
"=",
"self",
".",
"command",
"(",
"\"audio-muting query\"",
")",
"current_source_raw",
"=",
"self",
".",
"command",
"(",
"\"input-selector query\"",
")",
"# If the following command is sent to a device with only one HDMI out,",
"# the display shows 'Not Available'.",
"# We avoid this by checking if HDMI out is supported",
"if",
"self",
".",
"_hdmi_out_supported",
":",
"hdmi_out_raw",
"=",
"self",
".",
"command",
"(",
"\"hdmi-output-selector query\"",
")",
"else",
":",
"hdmi_out_raw",
"=",
"[",
"]",
"preset_raw",
"=",
"self",
".",
"command",
"(",
"\"preset query\"",
")",
"if",
"not",
"(",
"volume_raw",
"and",
"mute_raw",
"and",
"current_source_raw",
")",
":",
"return",
"# eiscp can return string or tuple. Make everything tuples.",
"if",
"isinstance",
"(",
"current_source_raw",
"[",
"1",
"]",
",",
"str",
")",
":",
"current_source_tuples",
"=",
"(",
"current_source_raw",
"[",
"0",
"]",
",",
"(",
"current_source_raw",
"[",
"1",
"]",
",",
")",
")",
"else",
":",
"current_source_tuples",
"=",
"current_source_raw",
"for",
"source",
"in",
"current_source_tuples",
"[",
"1",
"]",
":",
"if",
"source",
"in",
"self",
".",
"_source_mapping",
":",
"self",
".",
"_current_source",
"=",
"self",
".",
"_source_mapping",
"[",
"source",
"]",
"break",
"self",
".",
"_current_source",
"=",
"\"_\"",
".",
"join",
"(",
"current_source_tuples",
"[",
"1",
"]",
")",
"if",
"preset_raw",
"and",
"self",
".",
"_current_source",
".",
"lower",
"(",
")",
"==",
"\"radio\"",
":",
"self",
".",
"_attributes",
"[",
"ATTR_PRESET",
"]",
"=",
"preset_raw",
"[",
"1",
"]",
"elif",
"ATTR_PRESET",
"in",
"self",
".",
"_attributes",
":",
"del",
"self",
".",
"_attributes",
"[",
"ATTR_PRESET",
"]",
"self",
".",
"_muted",
"=",
"bool",
"(",
"mute_raw",
"[",
"1",
"]",
"==",
"\"on\"",
")",
"# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)",
"self",
".",
"_volume",
"=",
"volume_raw",
"[",
"1",
"]",
"/",
"(",
"self",
".",
"_receiver_max_volume",
"*",
"self",
".",
"_max_volume",
"/",
"100",
")",
"if",
"not",
"hdmi_out_raw",
":",
"return",
"self",
".",
"_attributes",
"[",
"\"video_out\"",
"]",
"=",
"\",\"",
".",
"join",
"(",
"hdmi_out_raw",
"[",
"1",
"]",
")",
"if",
"hdmi_out_raw",
"[",
"1",
"]",
"==",
"\"N/A\"",
":",
"self",
".",
"_hdmi_out_supported",
"=",
"False"
] | [
257,
4
] | [
309,
44
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
312,
4
] | [
314,
25
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._pwstate | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_pwstate"
] | [
317,
4
] | [
319,
28
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.volume_level | (self) | Return the volume level of the media player (0..1). | Return the volume level of the media player (0..1). | def volume_level(self):
"""Return the volume level of the media player (0..1)."""
return self._volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_volume"
] | [
322,
4
] | [
324,
27
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.is_volume_muted | (self) | Return boolean indicating mute status. | Return boolean indicating mute status. | def is_volume_muted(self):
"""Return boolean indicating mute status."""
return self._muted | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"_muted"
] | [
327,
4
] | [
329,
26
] | python | en | ['en', 'id', 'en'] | True |
OnkyoDevice.supported_features | (self) | Return media player features that are supported. | Return media player features that are supported. | def supported_features(self):
"""Return media player features that are supported."""
return SUPPORT_ONKYO | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_ONKYO"
] | [
332,
4
] | [
334,
28
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.source | (self) | Return the current input source of the device. | Return the current input source of the device. | def source(self):
"""Return the current input source of the device."""
return self._current_source | [
"def",
"source",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_source"
] | [
337,
4
] | [
339,
35
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.source_list | (self) | List of available input sources. | List of available input sources. | def source_list(self):
"""List of available input sources."""
return self._source_list | [
"def",
"source_list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_source_list"
] | [
342,
4
] | [
344,
32
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.device_state_attributes | (self) | Return device specific state attributes. | Return device specific state attributes. | def device_state_attributes(self):
"""Return device specific state attributes."""
return self._attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attributes"
] | [
347,
4
] | [
349,
31
] | python | en | ['fr', 'en', 'en'] | True |
OnkyoDevice.turn_off | (self) | Turn the media player off. | Turn the media player off. | def turn_off(self):
"""Turn the media player off."""
self.command("system-power standby") | [
"def",
"turn_off",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"\"system-power standby\"",
")"
] | [
351,
4
] | [
353,
44
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.set_volume_level | (self, volume) |
Set volume level, input is range 0..1.
However full volume on the amp is usually far too loud so allow the user to specify the upper range
with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
|
Set volume level, input is range 0..1. | def set_volume_level(self, volume):
"""
Set volume level, input is range 0..1.
However full volume on the amp is usually far too loud so allow the user to specify the upper range
with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
"""
# HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL
self.command(
f"volume {int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
) | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"# HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL",
"self",
".",
"command",
"(",
"f\"volume {int(volume * (self._max_volume / 100) * self._receiver_max_volume)}\"",
")"
] | [
355,
4
] | [
367,
9
] | python | en | ['en', 'error', 'th'] | False |
OnkyoDevice.volume_up | (self) | Increase volume by 1 step. | Increase volume by 1 step. | def volume_up(self):
"""Increase volume by 1 step."""
self.command("volume level-up") | [
"def",
"volume_up",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"\"volume level-up\"",
")"
] | [
369,
4
] | [
371,
39
] | python | en | ['en', 'af', 'en'] | True |
OnkyoDevice.volume_down | (self) | Decrease volume by 1 step. | Decrease volume by 1 step. | def volume_down(self):
"""Decrease volume by 1 step."""
self.command("volume level-down") | [
"def",
"volume_down",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"\"volume level-down\"",
")"
] | [
373,
4
] | [
375,
41
] | python | en | ['en', 'af', 'en'] | True |
OnkyoDevice.mute_volume | (self, mute) | Mute (true) or unmute (false) media player. | Mute (true) or unmute (false) media player. | def mute_volume(self, mute):
"""Mute (true) or unmute (false) media player."""
if mute:
self.command("audio-muting on")
else:
self.command("audio-muting off") | [
"def",
"mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"self",
".",
"command",
"(",
"\"audio-muting on\"",
")",
"else",
":",
"self",
".",
"command",
"(",
"\"audio-muting off\"",
")"
] | [
377,
4
] | [
382,
44
] | python | en | ['en', 'la', 'it'] | False |
OnkyoDevice.turn_on | (self) | Turn the media player on. | Turn the media player on. | def turn_on(self):
"""Turn the media player on."""
self.command("system-power on") | [
"def",
"turn_on",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"\"system-power on\"",
")"
] | [
384,
4
] | [
386,
39
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.select_source | (self, source) | Set the input source. | Set the input source. | def select_source(self, source):
"""Set the input source."""
if source in self._source_list:
source = self._reverse_mapping[source]
self.command(f"input-selector {source}") | [
"def",
"select_source",
"(",
"self",
",",
"source",
")",
":",
"if",
"source",
"in",
"self",
".",
"_source_list",
":",
"source",
"=",
"self",
".",
"_reverse_mapping",
"[",
"source",
"]",
"self",
".",
"command",
"(",
"f\"input-selector {source}\"",
")"
] | [
388,
4
] | [
392,
48
] | python | en | ['en', 'su', 'en'] | True |
OnkyoDevice.play_media | (self, media_type, media_id, **kwargs) | Play radio station by preset number. | Play radio station by preset number. | def play_media(self, media_type, media_id, **kwargs):
"""Play radio station by preset number."""
source = self._reverse_mapping[self._current_source]
if media_type.lower() == "radio" and source in DEFAULT_PLAYABLE_SOURCES:
self.command(f"preset {media_id}") | [
"def",
"play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"source",
"=",
"self",
".",
"_reverse_mapping",
"[",
"self",
".",
"_current_source",
"]",
"if",
"media_type",
".",
"lower",
"(",
")",
"==",
"\"radio\"",
"and",
"source",
"in",
"DEFAULT_PLAYABLE_SOURCES",
":",
"self",
".",
"command",
"(",
"f\"preset {media_id}\"",
")"
] | [
394,
4
] | [
398,
46
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDevice.select_output | (self, output) | Set hdmi-out. | Set hdmi-out. | def select_output(self, output):
"""Set hdmi-out."""
self.command(f"hdmi-output-selector={output}") | [
"def",
"select_output",
"(",
"self",
",",
"output",
")",
":",
"self",
".",
"command",
"(",
"f\"hdmi-output-selector={output}\"",
")"
] | [
400,
4
] | [
402,
54
] | python | en | ['nl', 'ht', 'en'] | False |
OnkyoDeviceZone.__init__ | (
self,
zone,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
) | Initialize the Zone with the zone identifier. | Initialize the Zone with the zone identifier. | def __init__(
self,
zone,
receiver,
sources,
name=None,
max_volume=SUPPORTED_MAX_VOLUME,
receiver_max_volume=DEFAULT_RECEIVER_MAX_VOLUME,
):
"""Initialize the Zone with the zone identifier."""
self._zone = zone
self._supports_volume = True
super().__init__(receiver, sources, name, max_volume, receiver_max_volume) | [
"def",
"__init__",
"(",
"self",
",",
"zone",
",",
"receiver",
",",
"sources",
",",
"name",
"=",
"None",
",",
"max_volume",
"=",
"SUPPORTED_MAX_VOLUME",
",",
"receiver_max_volume",
"=",
"DEFAULT_RECEIVER_MAX_VOLUME",
",",
")",
":",
"self",
".",
"_zone",
"=",
"zone",
"self",
".",
"_supports_volume",
"=",
"True",
"super",
"(",
")",
".",
"__init__",
"(",
"receiver",
",",
"sources",
",",
"name",
",",
"max_volume",
",",
"receiver_max_volume",
")"
] | [
408,
4
] | [
420,
82
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDeviceZone.update | (self) | Get the latest state from the device. | Get the latest state from the device. | def update(self):
"""Get the latest state from the device."""
status = self.command(f"zone{self._zone}.power=query")
if not status:
return
if status[1] == "on":
self._pwstate = STATE_ON
else:
self._pwstate = STATE_OFF
return
volume_raw = self.command(f"zone{self._zone}.volume=query")
mute_raw = self.command(f"zone{self._zone}.muting=query")
current_source_raw = self.command(f"zone{self._zone}.selector=query")
preset_raw = self.command(f"zone{self._zone}.preset=query")
# If we received a source value, but not a volume value
# it's likely this zone permanently does not support volume.
if current_source_raw and not volume_raw:
self._supports_volume = False
if not (volume_raw and mute_raw and current_source_raw):
return
# It's possible for some players to have zones set to HDMI with
# no sound control. In this case, the string `N/A` is returned.
self._supports_volume = isinstance(volume_raw[1], (float, int))
# eiscp can return string or tuple. Make everything tuples.
if isinstance(current_source_raw[1], str):
current_source_tuples = (current_source_raw[0], (current_source_raw[1],))
else:
current_source_tuples = current_source_raw
for source in current_source_tuples[1]:
if source in self._source_mapping:
self._current_source = self._source_mapping[source]
break
self._current_source = "_".join(current_source_tuples[1])
self._muted = bool(mute_raw[1] == "on")
if preset_raw and self._current_source.lower() == "radio":
self._attributes[ATTR_PRESET] = preset_raw[1]
elif ATTR_PRESET in self._attributes:
del self._attributes[ATTR_PRESET]
if self._supports_volume:
# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
self._volume = (
volume_raw[1] / self._receiver_max_volume * (self._max_volume / 100)
) | [
"def",
"update",
"(",
"self",
")",
":",
"status",
"=",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.power=query\"",
")",
"if",
"not",
"status",
":",
"return",
"if",
"status",
"[",
"1",
"]",
"==",
"\"on\"",
":",
"self",
".",
"_pwstate",
"=",
"STATE_ON",
"else",
":",
"self",
".",
"_pwstate",
"=",
"STATE_OFF",
"return",
"volume_raw",
"=",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.volume=query\"",
")",
"mute_raw",
"=",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.muting=query\"",
")",
"current_source_raw",
"=",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.selector=query\"",
")",
"preset_raw",
"=",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.preset=query\"",
")",
"# If we received a source value, but not a volume value",
"# it's likely this zone permanently does not support volume.",
"if",
"current_source_raw",
"and",
"not",
"volume_raw",
":",
"self",
".",
"_supports_volume",
"=",
"False",
"if",
"not",
"(",
"volume_raw",
"and",
"mute_raw",
"and",
"current_source_raw",
")",
":",
"return",
"# It's possible for some players to have zones set to HDMI with",
"# no sound control. In this case, the string `N/A` is returned.",
"self",
".",
"_supports_volume",
"=",
"isinstance",
"(",
"volume_raw",
"[",
"1",
"]",
",",
"(",
"float",
",",
"int",
")",
")",
"# eiscp can return string or tuple. Make everything tuples.",
"if",
"isinstance",
"(",
"current_source_raw",
"[",
"1",
"]",
",",
"str",
")",
":",
"current_source_tuples",
"=",
"(",
"current_source_raw",
"[",
"0",
"]",
",",
"(",
"current_source_raw",
"[",
"1",
"]",
",",
")",
")",
"else",
":",
"current_source_tuples",
"=",
"current_source_raw",
"for",
"source",
"in",
"current_source_tuples",
"[",
"1",
"]",
":",
"if",
"source",
"in",
"self",
".",
"_source_mapping",
":",
"self",
".",
"_current_source",
"=",
"self",
".",
"_source_mapping",
"[",
"source",
"]",
"break",
"self",
".",
"_current_source",
"=",
"\"_\"",
".",
"join",
"(",
"current_source_tuples",
"[",
"1",
"]",
")",
"self",
".",
"_muted",
"=",
"bool",
"(",
"mute_raw",
"[",
"1",
"]",
"==",
"\"on\"",
")",
"if",
"preset_raw",
"and",
"self",
".",
"_current_source",
".",
"lower",
"(",
")",
"==",
"\"radio\"",
":",
"self",
".",
"_attributes",
"[",
"ATTR_PRESET",
"]",
"=",
"preset_raw",
"[",
"1",
"]",
"elif",
"ATTR_PRESET",
"in",
"self",
".",
"_attributes",
":",
"del",
"self",
".",
"_attributes",
"[",
"ATTR_PRESET",
"]",
"if",
"self",
".",
"_supports_volume",
":",
"# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)",
"self",
".",
"_volume",
"=",
"(",
"volume_raw",
"[",
"1",
"]",
"/",
"self",
".",
"_receiver_max_volume",
"*",
"(",
"self",
".",
"_max_volume",
"/",
"100",
")",
")"
] | [
422,
4
] | [
470,
13
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDeviceZone.supported_features | (self) | Return media player features that are supported. | Return media player features that are supported. | def supported_features(self):
"""Return media player features that are supported."""
if self._supports_volume:
return SUPPORT_ONKYO
return SUPPORT_ONKYO_WO_VOLUME | [
"def",
"supported_features",
"(",
"self",
")",
":",
"if",
"self",
".",
"_supports_volume",
":",
"return",
"SUPPORT_ONKYO",
"return",
"SUPPORT_ONKYO_WO_VOLUME"
] | [
473,
4
] | [
477,
38
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDeviceZone.turn_off | (self) | Turn the media player off. | Turn the media player off. | def turn_off(self):
"""Turn the media player off."""
self.command(f"zone{self._zone}.power=standby") | [
"def",
"turn_off",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.power=standby\"",
")"
] | [
479,
4
] | [
481,
55
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDeviceZone.set_volume_level | (self, volume) |
Set volume level, input is range 0..1.
However full volume on the amp is usually far too loud so allow the user to specify the upper range
with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
|
Set volume level, input is range 0..1. | def set_volume_level(self, volume):
"""
Set volume level, input is range 0..1.
However full volume on the amp is usually far too loud so allow the user to specify the upper range
with CONF_MAX_VOLUME. we change as per max_volume set by user. This means that if max volume is 80 then full
volume in HA will give 80% volume on the receiver. Then we convert
that to the correct scale for the receiver.
"""
# HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL
self.command(
f"zone{self._zone}.volume={int(volume * (self._max_volume / 100) * self._receiver_max_volume)}"
) | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"# HA_VOL * (MAX VOL / 100) * MAX_RECEIVER_VOL",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.volume={int(volume * (self._max_volume / 100) * self._receiver_max_volume)}\"",
")"
] | [
483,
4
] | [
495,
9
] | python | en | ['en', 'error', 'th'] | False |
OnkyoDeviceZone.volume_up | (self) | Increase volume by 1 step. | Increase volume by 1 step. | def volume_up(self):
"""Increase volume by 1 step."""
self.command(f"zone{self._zone}.volume=level-up") | [
"def",
"volume_up",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.volume=level-up\"",
")"
] | [
497,
4
] | [
499,
57
] | python | en | ['en', 'af', 'en'] | True |
OnkyoDeviceZone.volume_down | (self) | Decrease volume by 1 step. | Decrease volume by 1 step. | def volume_down(self):
"""Decrease volume by 1 step."""
self.command(f"zone{self._zone}.volume=level-down") | [
"def",
"volume_down",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.volume=level-down\"",
")"
] | [
501,
4
] | [
503,
59
] | python | en | ['en', 'af', 'en'] | True |
OnkyoDeviceZone.mute_volume | (self, mute) | Mute (true) or unmute (false) media player. | Mute (true) or unmute (false) media player. | def mute_volume(self, mute):
"""Mute (true) or unmute (false) media player."""
if mute:
self.command(f"zone{self._zone}.muting=on")
else:
self.command(f"zone{self._zone}.muting=off") | [
"def",
"mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.muting=on\"",
")",
"else",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.muting=off\"",
")"
] | [
505,
4
] | [
510,
56
] | python | en | ['en', 'la', 'it'] | False |
OnkyoDeviceZone.turn_on | (self) | Turn the media player on. | Turn the media player on. | def turn_on(self):
"""Turn the media player on."""
self.command(f"zone{self._zone}.power=on") | [
"def",
"turn_on",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.power=on\"",
")"
] | [
512,
4
] | [
514,
50
] | python | en | ['en', 'en', 'en'] | True |
OnkyoDeviceZone.select_source | (self, source) | Set the input source. | Set the input source. | def select_source(self, source):
"""Set the input source."""
if source in self._source_list:
source = self._reverse_mapping[source]
self.command(f"zone{self._zone}.selector={source}") | [
"def",
"select_source",
"(",
"self",
",",
"source",
")",
":",
"if",
"source",
"in",
"self",
".",
"_source_list",
":",
"source",
"=",
"self",
".",
"_reverse_mapping",
"[",
"source",
"]",
"self",
".",
"command",
"(",
"f\"zone{self._zone}.selector={source}\"",
")"
] | [
516,
4
] | [
520,
59
] | python | en | ['en', 'su', 'en'] | True |
test_is_loopback | () | Test loopback addresses. | Test loopback addresses. | def test_is_loopback():
"""Test loopback addresses."""
assert network_util.is_loopback(ip_address("127.0.0.2"))
assert network_util.is_loopback(ip_address("127.0.0.1"))
assert network_util.is_loopback(ip_address("::1"))
assert network_util.is_loopback(ip_address("::ffff:127.0.0.0"))
assert network_util.is_loopback(ip_address("0:0:0:0:0:0:0:1"))
assert network_util.is_loopback(ip_address("0:0:0:0:0:ffff:7f00:1"))
assert not network_util.is_loopback(ip_address("104.26.5.238"))
assert not network_util.is_loopback(ip_address("2600:1404:400:1a4::356e")) | [
"def",
"test_is_loopback",
"(",
")",
":",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"127.0.0.2\"",
")",
")",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
")",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"::1\"",
")",
")",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"::ffff:127.0.0.0\"",
")",
")",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"0:0:0:0:0:0:0:1\"",
")",
")",
"assert",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"0:0:0:0:0:ffff:7f00:1\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"104.26.5.238\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_loopback",
"(",
"ip_address",
"(",
"\"2600:1404:400:1a4::356e\"",
")",
")"
] | [
7,
0
] | [
16,
78
] | python | en | ['en', 'et', 'en'] | True |
test_is_private | () | Test private addresses. | Test private addresses. | def test_is_private():
"""Test private addresses."""
assert network_util.is_private(ip_address("192.168.0.1"))
assert network_util.is_private(ip_address("172.16.12.0"))
assert network_util.is_private(ip_address("10.5.43.3"))
assert network_util.is_private(ip_address("fd12:3456:789a:1::1"))
assert not network_util.is_private(ip_address("127.0.0.1"))
assert not network_util.is_private(ip_address("::1")) | [
"def",
"test_is_private",
"(",
")",
":",
"assert",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"192.168.0.1\"",
")",
")",
"assert",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"172.16.12.0\"",
")",
")",
"assert",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"10.5.43.3\"",
")",
")",
"assert",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"fd12:3456:789a:1::1\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_private",
"(",
"ip_address",
"(",
"\"::1\"",
")",
")"
] | [
19,
0
] | [
26,
57
] | python | en | ['en', 'en', 'en'] | True |
test_is_link_local | () | Test link local addresses. | Test link local addresses. | def test_is_link_local():
"""Test link local addresses."""
assert network_util.is_link_local(ip_address("169.254.12.3"))
assert not network_util.is_link_local(ip_address("127.0.0.1")) | [
"def",
"test_is_link_local",
"(",
")",
":",
"assert",
"network_util",
".",
"is_link_local",
"(",
"ip_address",
"(",
"\"169.254.12.3\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_link_local",
"(",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
")"
] | [
29,
0
] | [
32,
66
] | python | en | ['en', 'da', 'en'] | True |
test_is_local | () | Test local addresses. | Test local addresses. | def test_is_local():
"""Test local addresses."""
assert network_util.is_local(ip_address("192.168.0.1"))
assert network_util.is_local(ip_address("127.0.0.1"))
assert not network_util.is_local(ip_address("208.5.4.2")) | [
"def",
"test_is_local",
"(",
")",
":",
"assert",
"network_util",
".",
"is_local",
"(",
"ip_address",
"(",
"\"192.168.0.1\"",
")",
")",
"assert",
"network_util",
".",
"is_local",
"(",
"ip_address",
"(",
"\"127.0.0.1\"",
")",
")",
"assert",
"not",
"network_util",
".",
"is_local",
"(",
"ip_address",
"(",
"\"208.5.4.2\"",
")",
")"
] | [
35,
0
] | [
39,
61
] | python | en | ['en', 'la', 'en'] | True |
test_is_ip_address | () | Test if strings are IP addresses. | Test if strings are IP addresses. | def test_is_ip_address():
"""Test if strings are IP addresses."""
assert network_util.is_ip_address("192.168.0.1")
assert network_util.is_ip_address("8.8.8.8")
assert network_util.is_ip_address("::ffff:127.0.0.0")
assert not network_util.is_ip_address("192.168.0.999")
assert not network_util.is_ip_address("192.168.0.0/24")
assert not network_util.is_ip_address("example.com") | [
"def",
"test_is_ip_address",
"(",
")",
":",
"assert",
"network_util",
".",
"is_ip_address",
"(",
"\"192.168.0.1\"",
")",
"assert",
"network_util",
".",
"is_ip_address",
"(",
"\"8.8.8.8\"",
")",
"assert",
"network_util",
".",
"is_ip_address",
"(",
"\"::ffff:127.0.0.0\"",
")",
"assert",
"not",
"network_util",
".",
"is_ip_address",
"(",
"\"192.168.0.999\"",
")",
"assert",
"not",
"network_util",
".",
"is_ip_address",
"(",
"\"192.168.0.0/24\"",
")",
"assert",
"not",
"network_util",
".",
"is_ip_address",
"(",
"\"example.com\"",
")"
] | [
42,
0
] | [
49,
56
] | python | en | ['en', 'en', 'en'] | True |
test_normalize_url | () | Test the normalizing of URLs. | Test the normalizing of URLs. | def test_normalize_url():
"""Test the normalizing of URLs."""
assert network_util.normalize_url("http://example.com") == "http://example.com"
assert network_util.normalize_url("https://example.com") == "https://example.com"
assert network_util.normalize_url("https://example.com/") == "https://example.com"
assert (
network_util.normalize_url("https://example.com:443") == "https://example.com"
)
assert network_util.normalize_url("http://example.com:80") == "http://example.com"
assert (
network_util.normalize_url("https://example.com:80") == "https://example.com:80"
)
assert (
network_util.normalize_url("http://example.com:443") == "http://example.com:443"
)
assert (
network_util.normalize_url("https://example.com:443/test/")
== "https://example.com/test"
) | [
"def",
"test_normalize_url",
"(",
")",
":",
"assert",
"network_util",
".",
"normalize_url",
"(",
"\"http://example.com\"",
")",
"==",
"\"http://example.com\"",
"assert",
"network_util",
".",
"normalize_url",
"(",
"\"https://example.com\"",
")",
"==",
"\"https://example.com\"",
"assert",
"network_util",
".",
"normalize_url",
"(",
"\"https://example.com/\"",
")",
"==",
"\"https://example.com\"",
"assert",
"(",
"network_util",
".",
"normalize_url",
"(",
"\"https://example.com:443\"",
")",
"==",
"\"https://example.com\"",
")",
"assert",
"network_util",
".",
"normalize_url",
"(",
"\"http://example.com:80\"",
")",
"==",
"\"http://example.com\"",
"assert",
"(",
"network_util",
".",
"normalize_url",
"(",
"\"https://example.com:80\"",
")",
"==",
"\"https://example.com:80\"",
")",
"assert",
"(",
"network_util",
".",
"normalize_url",
"(",
"\"http://example.com:443\"",
")",
"==",
"\"http://example.com:443\"",
")",
"assert",
"(",
"network_util",
".",
"normalize_url",
"(",
"\"https://example.com:443/test/\"",
")",
"==",
"\"https://example.com/test\"",
")"
] | [
52,
0
] | [
70,
5
] | python | en | ['en', 'en', 'en'] | True |
_async_create_entities | (hass, config) | Create the Template lock. | Create the Template lock. | async def _async_create_entities(hass, config):
"""Create the Template lock."""
device = config.get(CONF_NAME)
value_template = config.get(CONF_VALUE_TEMPLATE)
availability_template = config.get(CONF_AVAILABILITY_TEMPLATE)
return [
TemplateLock(
hass,
device,
value_template,
availability_template,
config.get(CONF_LOCK),
config.get(CONF_UNLOCK),
config.get(CONF_OPTIMISTIC),
config.get(CONF_UNIQUE_ID),
)
] | [
"async",
"def",
"_async_create_entities",
"(",
"hass",
",",
"config",
")",
":",
"device",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"value_template",
"=",
"config",
".",
"get",
"(",
"CONF_VALUE_TEMPLATE",
")",
"availability_template",
"=",
"config",
".",
"get",
"(",
"CONF_AVAILABILITY_TEMPLATE",
")",
"return",
"[",
"TemplateLock",
"(",
"hass",
",",
"device",
",",
"value_template",
",",
"availability_template",
",",
"config",
".",
"get",
"(",
"CONF_LOCK",
")",
",",
"config",
".",
"get",
"(",
"CONF_UNLOCK",
")",
",",
"config",
".",
"get",
"(",
"CONF_OPTIMISTIC",
")",
",",
"config",
".",
"get",
"(",
"CONF_UNIQUE_ID",
")",
",",
")",
"]"
] | [
40,
0
] | [
57,
5
] | python | en | ['en', 'ro', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the template lock. | Set up the template lock. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the template lock."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
async_add_entities(await _async_create_entities(hass, config)) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"async_add_entities",
"(",
"await",
"_async_create_entities",
"(",
"hass",
",",
"config",
")",
")"
] | [
60,
0
] | [
64,
66
] | python | en | ['en', 'en', 'en'] | True |
TemplateLock.__init__ | (
self,
hass,
name,
value_template,
availability_template,
command_lock,
command_unlock,
optimistic,
unique_id,
) | Initialize the lock. | Initialize the lock. | def __init__(
self,
hass,
name,
value_template,
availability_template,
command_lock,
command_unlock,
optimistic,
unique_id,
):
"""Initialize the lock."""
super().__init__(availability_template=availability_template)
self._state = None
self._name = name
self._state_template = value_template
domain = __name__.split(".")[-2]
self._command_lock = Script(hass, command_lock, name, domain)
self._command_unlock = Script(hass, command_unlock, name, domain)
self._optimistic = optimistic
self._unique_id = unique_id | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"name",
",",
"value_template",
",",
"availability_template",
",",
"command_lock",
",",
"command_unlock",
",",
"optimistic",
",",
"unique_id",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"availability_template",
"=",
"availability_template",
")",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state_template",
"=",
"value_template",
"domain",
"=",
"__name__",
".",
"split",
"(",
"\".\"",
")",
"[",
"-",
"2",
"]",
"self",
".",
"_command_lock",
"=",
"Script",
"(",
"hass",
",",
"command_lock",
",",
"name",
",",
"domain",
")",
"self",
".",
"_command_unlock",
"=",
"Script",
"(",
"hass",
",",
"command_unlock",
",",
"name",
",",
"domain",
")",
"self",
".",
"_optimistic",
"=",
"optimistic",
"self",
".",
"_unique_id",
"=",
"unique_id"
] | [
70,
4
] | [
90,
35
] | python | en | ['en', 'en', 'en'] | True |
TemplateLock.assumed_state | (self) | Return true if we do optimistic updates. | Return true if we do optimistic updates. | def assumed_state(self):
"""Return true if we do optimistic updates."""
return self._optimistic | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_optimistic"
] | [
93,
4
] | [
95,
31
] | python | en | ['pt', 'la', 'en'] | False |
TemplateLock.name | (self) | Return the name of the lock. | Return the name of the lock. | def name(self):
"""Return the name of the lock."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
98,
4
] | [
100,
25
] | python | en | ['en', 'en', 'en'] | True |
TemplateLock.unique_id | (self) | Return the unique id of this lock. | Return the unique id of this lock. | def unique_id(self):
"""Return the unique id of this lock."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
103,
4
] | [
105,
30
] | python | en | ['en', 'la', 'en'] | True |
TemplateLock.is_locked | (self) | Return true if lock is locked. | Return true if lock is locked. | def is_locked(self):
"""Return true if lock is locked."""
return self._state | [
"def",
"is_locked",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
108,
4
] | [
110,
26
] | python | en | ['en', 'mt', 'en'] | True |
TemplateLock.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
self.add_template_attribute(
"_state", self._state_template, None, self._update_state
)
await super().async_added_to_hass() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"add_template_attribute",
"(",
"\"_state\"",
",",
"self",
".",
"_state_template",
",",
"None",
",",
"self",
".",
"_update_state",
")",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")"
] | [
129,
4
] | [
135,
43
] | python | en | ['en', 'no', 'en'] | False |
TemplateLock.async_lock | (self, **kwargs) | Lock the device. | Lock the device. | async def async_lock(self, **kwargs):
"""Lock the device."""
if self._optimistic:
self._state = True
self.async_write_ha_state()
await self._command_lock.async_run(context=self._context) | [
"async",
"def",
"async_lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_optimistic",
":",
"self",
".",
"_state",
"=",
"True",
"self",
".",
"async_write_ha_state",
"(",
")",
"await",
"self",
".",
"_command_lock",
".",
"async_run",
"(",
"context",
"=",
"self",
".",
"_context",
")"
] | [
137,
4
] | [
142,
65
] | python | en | ['en', 'en', 'en'] | True |
TemplateLock.async_unlock | (self, **kwargs) | Unlock the device. | Unlock the device. | async def async_unlock(self, **kwargs):
"""Unlock the device."""
if self._optimistic:
self._state = False
self.async_write_ha_state()
await self._command_unlock.async_run(context=self._context) | [
"async",
"def",
"async_unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_optimistic",
":",
"self",
".",
"_state",
"=",
"False",
"self",
".",
"async_write_ha_state",
"(",
")",
"await",
"self",
".",
"_command_unlock",
".",
"async_run",
"(",
"context",
"=",
"self",
".",
"_context",
")"
] | [
144,
4
] | [
149,
67
] | python | en | ['en', 'zh', 'en'] | True |
update_members_dict | () | Update members dictionary | Update members dictionary | def update_members_dict():
"""Update members dictionary"""
global MEMBERS_DICT
MEMBERS_DICT.clear()
with app.app_context():
from .admin import get_members_dict
new_dict = get_members_dict()
MEMBERS_DICT.update(new_dict) | [
"def",
"update_members_dict",
"(",
")",
":",
"global",
"MEMBERS_DICT",
"MEMBERS_DICT",
".",
"clear",
"(",
")",
"with",
"app",
".",
"app_context",
"(",
")",
":",
"from",
".",
"admin",
"import",
"get_members_dict",
"new_dict",
"=",
"get_members_dict",
"(",
")",
"MEMBERS_DICT",
".",
"update",
"(",
"new_dict",
")"
] | [
60,
0
] | [
67,
33
] | python | en | ['es', 'id', 'en'] | False |
_load_name_dict | () | Load email: name dictionary from local file. | Load email: name dictionary from local file. | def _load_name_dict():
"""Load email: name dictionary from local file."""
email_names = pd.read_table(os.path.join(DATA_DIR, 'email_names.tsv'), sep='\t',
header=None, names=['email', 'full_name'])
name_dict = email_names.set_index('email')['full_name'].to_dict()
return name_dict | [
"def",
"_load_name_dict",
"(",
")",
":",
"email_names",
"=",
"pd",
".",
"read_table",
"(",
"os",
".",
"path",
".",
"join",
"(",
"DATA_DIR",
",",
"'email_names.tsv'",
")",
",",
"sep",
"=",
"'\\t'",
",",
"header",
"=",
"None",
",",
"names",
"=",
"[",
"'email'",
",",
"'full_name'",
"]",
")",
"name_dict",
"=",
"email_names",
".",
"set_index",
"(",
"'email'",
")",
"[",
"'full_name'",
"]",
".",
"to_dict",
"(",
")",
"return",
"name_dict"
] | [
82,
0
] | [
87,
20
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the MVGLive sensor. | Set up the MVGLive sensor. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the MVGLive sensor."""
sensors = []
for nextdeparture in config.get(CONF_NEXT_DEPARTURE):
sensors.append(
MVGLiveSensor(
nextdeparture.get(CONF_STATION),
nextdeparture.get(CONF_DESTINATIONS),
nextdeparture.get(CONF_DIRECTIONS),
nextdeparture.get(CONF_LINES),
nextdeparture.get(CONF_PRODUCTS),
nextdeparture.get(CONF_TIMEOFFSET),
nextdeparture.get(CONF_NUMBER),
nextdeparture.get(CONF_NAME),
)
)
add_entities(sensors, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"sensors",
"=",
"[",
"]",
"for",
"nextdeparture",
"in",
"config",
".",
"get",
"(",
"CONF_NEXT_DEPARTURE",
")",
":",
"sensors",
".",
"append",
"(",
"MVGLiveSensor",
"(",
"nextdeparture",
".",
"get",
"(",
"CONF_STATION",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_DESTINATIONS",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_DIRECTIONS",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_LINES",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_PRODUCTS",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_TIMEOFFSET",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_NUMBER",
")",
",",
"nextdeparture",
".",
"get",
"(",
"CONF_NAME",
")",
",",
")",
")",
"add_entities",
"(",
"sensors",
",",
"True",
")"
] | [
61,
0
] | [
77,
31
] | python | en | ['en', 'bs', 'en'] | True |
MVGLiveSensor.__init__ | (
self,
station,
destinations,
directions,
lines,
products,
timeoffset,
number,
name,
) | Initialize the sensor. | Initialize the sensor. | def __init__(
self,
station,
destinations,
directions,
lines,
products,
timeoffset,
number,
name,
):
"""Initialize the sensor."""
self._station = station
self._name = name
self.data = MVGLiveData(
station, destinations, directions, lines, products, timeoffset, number
)
self._state = None
self._icon = ICONS["-"] | [
"def",
"__init__",
"(",
"self",
",",
"station",
",",
"destinations",
",",
"directions",
",",
"lines",
",",
"products",
",",
"timeoffset",
",",
"number",
",",
"name",
",",
")",
":",
"self",
".",
"_station",
"=",
"station",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"data",
"=",
"MVGLiveData",
"(",
"station",
",",
"destinations",
",",
"directions",
",",
"lines",
",",
"products",
",",
"timeoffset",
",",
"number",
")",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_icon",
"=",
"ICONS",
"[",
"\"-\"",
"]"
] | [
83,
4
] | [
101,
31
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
if self._name:
return self._name
return self._station | [
"def",
"name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_name",
":",
"return",
"self",
".",
"_name",
"return",
"self",
".",
"_station"
] | [
104,
4
] | [
108,
28
] | python | en | ['en', 'mi', 'en'] | True |
MVGLiveSensor.state | (self) | Return the next departure time. | Return the next departure time. | def state(self):
"""Return the next departure time."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
111,
4
] | [
113,
26
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
dep = self.data.departures
if not dep:
return None
attr = dep[0] # next depature attributes
attr["departures"] = deepcopy(dep) # all departures dictionary
return attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"dep",
"=",
"self",
".",
"data",
".",
"departures",
"if",
"not",
"dep",
":",
"return",
"None",
"attr",
"=",
"dep",
"[",
"0",
"]",
"# next depature attributes",
"attr",
"[",
"\"departures\"",
"]",
"=",
"deepcopy",
"(",
"dep",
")",
"# all departures dictionary",
"return",
"attr"
] | [
116,
4
] | [
123,
19
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
126,
4
] | [
128,
25
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveSensor.unit_of_measurement | (self) | Return the unit this state is expressed in. | Return the unit this state is expressed in. | def unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return TIME_MINUTES | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"TIME_MINUTES"
] | [
131,
4
] | [
133,
27
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveSensor.update | (self) | Get the latest data and update the state. | Get the latest data and update the state. | def update(self):
"""Get the latest data and update the state."""
self.data.update()
if not self.data.departures:
self._state = "-"
self._icon = ICONS["-"]
else:
self._state = self.data.departures[0].get("time", "-")
self._icon = ICONS[self.data.departures[0].get("product", "-")] | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"data",
".",
"update",
"(",
")",
"if",
"not",
"self",
".",
"data",
".",
"departures",
":",
"self",
".",
"_state",
"=",
"\"-\"",
"self",
".",
"_icon",
"=",
"ICONS",
"[",
"\"-\"",
"]",
"else",
":",
"self",
".",
"_state",
"=",
"self",
".",
"data",
".",
"departures",
"[",
"0",
"]",
".",
"get",
"(",
"\"time\"",
",",
"\"-\"",
")",
"self",
".",
"_icon",
"=",
"ICONS",
"[",
"self",
".",
"data",
".",
"departures",
"[",
"0",
"]",
".",
"get",
"(",
"\"product\"",
",",
"\"-\"",
")",
"]"
] | [
135,
4
] | [
143,
75
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveData.__init__ | (
self, station, destinations, directions, lines, products, timeoffset, number
) | Initialize the sensor. | Initialize the sensor. | def __init__(
self, station, destinations, directions, lines, products, timeoffset, number
):
"""Initialize the sensor."""
self._station = station
self._destinations = destinations
self._directions = directions
self._lines = lines
self._products = products
self._timeoffset = timeoffset
self._number = number
self._include_ubahn = "U-Bahn" in self._products
self._include_tram = "Tram" in self._products
self._include_bus = "Bus" in self._products
self._include_sbahn = "S-Bahn" in self._products
self.mvg = MVGLive.MVGLive()
self.departures = [] | [
"def",
"__init__",
"(",
"self",
",",
"station",
",",
"destinations",
",",
"directions",
",",
"lines",
",",
"products",
",",
"timeoffset",
",",
"number",
")",
":",
"self",
".",
"_station",
"=",
"station",
"self",
".",
"_destinations",
"=",
"destinations",
"self",
".",
"_directions",
"=",
"directions",
"self",
".",
"_lines",
"=",
"lines",
"self",
".",
"_products",
"=",
"products",
"self",
".",
"_timeoffset",
"=",
"timeoffset",
"self",
".",
"_number",
"=",
"number",
"self",
".",
"_include_ubahn",
"=",
"\"U-Bahn\"",
"in",
"self",
".",
"_products",
"self",
".",
"_include_tram",
"=",
"\"Tram\"",
"in",
"self",
".",
"_products",
"self",
".",
"_include_bus",
"=",
"\"Bus\"",
"in",
"self",
".",
"_products",
"self",
".",
"_include_sbahn",
"=",
"\"S-Bahn\"",
"in",
"self",
".",
"_products",
"self",
".",
"mvg",
"=",
"MVGLive",
".",
"MVGLive",
"(",
")",
"self",
".",
"departures",
"=",
"[",
"]"
] | [
149,
4
] | [
165,
28
] | python | en | ['en', 'en', 'en'] | True |
MVGLiveData.update | (self) | Update the connection data. | Update the connection data. | def update(self):
"""Update the connection data."""
try:
_departures = self.mvg.getlivedata(
station=self._station,
timeoffset=self._timeoffset,
ubahn=self._include_ubahn,
tram=self._include_tram,
bus=self._include_bus,
sbahn=self._include_sbahn,
)
except ValueError:
self.departures = []
_LOGGER.warning("Returned data not understood")
return
self.departures = []
for i, _departure in enumerate(_departures):
# find the first departure meeting the criteria
if (
"" not in self._destinations[:1]
and _departure["destination"] not in self._destinations
):
continue
if (
"" not in self._directions[:1]
and _departure["direction"] not in self._directions
):
continue
if "" not in self._lines[:1] and _departure["linename"] not in self._lines:
continue
if _departure["time"] < self._timeoffset:
continue
# now select the relevant data
_nextdep = {ATTR_ATTRIBUTION: ATTRIBUTION}
for k in ["destination", "linename", "time", "direction", "product"]:
_nextdep[k] = _departure.get(k, "")
_nextdep["time"] = int(_nextdep["time"])
self.departures.append(_nextdep)
if i == self._number - 1:
break | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"_departures",
"=",
"self",
".",
"mvg",
".",
"getlivedata",
"(",
"station",
"=",
"self",
".",
"_station",
",",
"timeoffset",
"=",
"self",
".",
"_timeoffset",
",",
"ubahn",
"=",
"self",
".",
"_include_ubahn",
",",
"tram",
"=",
"self",
".",
"_include_tram",
",",
"bus",
"=",
"self",
".",
"_include_bus",
",",
"sbahn",
"=",
"self",
".",
"_include_sbahn",
",",
")",
"except",
"ValueError",
":",
"self",
".",
"departures",
"=",
"[",
"]",
"_LOGGER",
".",
"warning",
"(",
"\"Returned data not understood\"",
")",
"return",
"self",
".",
"departures",
"=",
"[",
"]",
"for",
"i",
",",
"_departure",
"in",
"enumerate",
"(",
"_departures",
")",
":",
"# find the first departure meeting the criteria",
"if",
"(",
"\"\"",
"not",
"in",
"self",
".",
"_destinations",
"[",
":",
"1",
"]",
"and",
"_departure",
"[",
"\"destination\"",
"]",
"not",
"in",
"self",
".",
"_destinations",
")",
":",
"continue",
"if",
"(",
"\"\"",
"not",
"in",
"self",
".",
"_directions",
"[",
":",
"1",
"]",
"and",
"_departure",
"[",
"\"direction\"",
"]",
"not",
"in",
"self",
".",
"_directions",
")",
":",
"continue",
"if",
"\"\"",
"not",
"in",
"self",
".",
"_lines",
"[",
":",
"1",
"]",
"and",
"_departure",
"[",
"\"linename\"",
"]",
"not",
"in",
"self",
".",
"_lines",
":",
"continue",
"if",
"_departure",
"[",
"\"time\"",
"]",
"<",
"self",
".",
"_timeoffset",
":",
"continue",
"# now select the relevant data",
"_nextdep",
"=",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
"}",
"for",
"k",
"in",
"[",
"\"destination\"",
",",
"\"linename\"",
",",
"\"time\"",
",",
"\"direction\"",
",",
"\"product\"",
"]",
":",
"_nextdep",
"[",
"k",
"]",
"=",
"_departure",
".",
"get",
"(",
"k",
",",
"\"\"",
")",
"_nextdep",
"[",
"\"time\"",
"]",
"=",
"int",
"(",
"_nextdep",
"[",
"\"time\"",
"]",
")",
"self",
".",
"departures",
".",
"append",
"(",
"_nextdep",
")",
"if",
"i",
"==",
"self",
".",
"_number",
"-",
"1",
":",
"break"
] | [
167,
4
] | [
210,
21
] | python | en | ['en', 'en', 'en'] | True |
get_dataset | (name, split_name, dataset_dir, file_pattern=None, reader=None) | Given a dataset name and a split_name returns a Dataset.
Args:
name: String, the name of the dataset.
split_name: A train/test split name.
dataset_dir: The directory where the dataset files are stored.
file_pattern: The file pattern to use for matching the dataset source files.
reader: The subclass of tf.ReaderBase. If left as `None`, then the default
reader defined by each dataset is used.
Returns:
A `Dataset` class.
Raises:
ValueError: If the dataset `name` is unknown.
| Given a dataset name and a split_name returns a Dataset. | def get_dataset(name, split_name, dataset_dir, file_pattern=None, reader=None):
"""Given a dataset name and a split_name returns a Dataset.
Args:
name: String, the name of the dataset.
split_name: A train/test split name.
dataset_dir: The directory where the dataset files are stored.
file_pattern: The file pattern to use for matching the dataset source files.
reader: The subclass of tf.ReaderBase. If left as `None`, then the default
reader defined by each dataset is used.
Returns:
A `Dataset` class.
Raises:
ValueError: If the dataset `name` is unknown.
"""
if name not in datasets_map:
raise ValueError('Name of dataset unknown %s' % name)
return datasets_map[name].get_split(
split_name,
dataset_dir,
file_pattern,
reader) | [
"def",
"get_dataset",
"(",
"name",
",",
"split_name",
",",
"dataset_dir",
",",
"file_pattern",
"=",
"None",
",",
"reader",
"=",
"None",
")",
":",
"if",
"name",
"not",
"in",
"datasets_map",
":",
"raise",
"ValueError",
"(",
"'Name of dataset unknown %s'",
"%",
"name",
")",
"return",
"datasets_map",
"[",
"name",
"]",
".",
"get_split",
"(",
"split_name",
",",
"dataset_dir",
",",
"file_pattern",
",",
"reader",
")"
] | [
35,
0
] | [
58,
13
] | python | en | ['en', 'en', 'en'] | True |
_config_info | (mode, config) | Generate info about the config. | Generate info about the config. | def _config_info(mode, config):
"""Generate info about the config."""
return {
"mode": mode,
"views": len(config.get("views", [])),
} | [
"def",
"_config_info",
"(",
"mode",
",",
"config",
")",
":",
"return",
"{",
"\"mode\"",
":",
"mode",
",",
"\"views\"",
":",
"len",
"(",
"config",
".",
"get",
"(",
"\"views\"",
",",
"[",
"]",
")",
")",
",",
"}"
] | [
211,
0
] | [
216,
5
] | python | en | ['en', 'en', 'en'] | True |
LovelaceConfig.__init__ | (self, hass, url_path, config) | Initialize Lovelace config. | Initialize Lovelace config. | def __init__(self, hass, url_path, config):
"""Initialize Lovelace config."""
self.hass = hass
if config:
self.config = {**config, CONF_URL_PATH: url_path}
else:
self.config = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"url_path",
",",
"config",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"if",
"config",
":",
"self",
".",
"config",
"=",
"{",
"*",
"*",
"config",
",",
"CONF_URL_PATH",
":",
"url_path",
"}",
"else",
":",
"self",
".",
"config",
"=",
"None"
] | [
40,
4
] | [
46,
30
] | python | en | ['en', 'en', 'en'] | True |
LovelaceConfig.url_path | (self) | Return url path. | Return url path. | def url_path(self) -> str:
"""Return url path."""
return self.config[CONF_URL_PATH] if self.config else None | [
"def",
"url_path",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"config",
"[",
"CONF_URL_PATH",
"]",
"if",
"self",
".",
"config",
"else",
"None"
] | [
49,
4
] | [
51,
66
] | python | cy | ['de', 'cy', 'en'] | False |
LovelaceConfig.mode | (self) | Return mode of the lovelace config. | Return mode of the lovelace config. | def mode(self) -> str:
"""Return mode of the lovelace config.""" | [
"def",
"mode",
"(",
"self",
")",
"->",
"str",
":"
] | [
55,
4
] | [
56,
49
] | python | en | ['en', 'en', 'en'] | True |
LovelaceConfig.async_get_info | (self) | Return the config info. | Return the config info. | async def async_get_info(self):
"""Return the config info.""" | [
"async",
"def",
"async_get_info",
"(",
"self",
")",
":"
] | [
59,
4
] | [
60,
37
] | python | en | ['en', 'en', 'en'] | True |
LovelaceConfig.async_load | (self, force) | Load config. | Load config. | async def async_load(self, force):
"""Load config.""" | [
"async",
"def",
"async_load",
"(",
"self",
",",
"force",
")",
":"
] | [
63,
4
] | [
64,
26
] | python | en | ['en', 'es', 'en'] | False |
LovelaceConfig.async_save | (self, config) | Save config. | Save config. | async def async_save(self, config):
"""Save config."""
raise HomeAssistantError("Not supported") | [
"async",
"def",
"async_save",
"(",
"self",
",",
"config",
")",
":",
"raise",
"HomeAssistantError",
"(",
"\"Not supported\"",
")"
] | [
66,
4
] | [
68,
49
] | python | en | ['en', 'en', 'en'] | False |
LovelaceConfig.async_delete | (self) | Delete config. | Delete config. | async def async_delete(self):
"""Delete config."""
raise HomeAssistantError("Not supported") | [
"async",
"def",
"async_delete",
"(",
"self",
")",
":",
"raise",
"HomeAssistantError",
"(",
"\"Not supported\"",
")"
] | [
70,
4
] | [
72,
49
] | python | en | ['en', 'es', 'en'] | False |
LovelaceConfig._config_updated | (self) | Fire config updated event. | Fire config updated event. | def _config_updated(self):
"""Fire config updated event."""
self.hass.bus.async_fire(EVENT_LOVELACE_UPDATED, {"url_path": self.url_path}) | [
"def",
"_config_updated",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_LOVELACE_UPDATED",
",",
"{",
"\"url_path\"",
":",
"self",
".",
"url_path",
"}",
")"
] | [
75,
4
] | [
77,
85
] | python | en | ['en', 'en', 'en'] | True |
LovelaceStorage.__init__ | (self, hass, config) | Initialize Lovelace config based on storage helper. | Initialize Lovelace config based on storage helper. | def __init__(self, hass, config):
"""Initialize Lovelace config based on storage helper."""
if config is None:
url_path = None
storage_key = CONFIG_STORAGE_KEY_DEFAULT
else:
url_path = config[CONF_URL_PATH]
storage_key = CONFIG_STORAGE_KEY.format(config["id"])
super().__init__(hass, url_path, config)
self._store = storage.Store(hass, CONFIG_STORAGE_VERSION, storage_key)
self._data = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config",
")",
":",
"if",
"config",
"is",
"None",
":",
"url_path",
"=",
"None",
"storage_key",
"=",
"CONFIG_STORAGE_KEY_DEFAULT",
"else",
":",
"url_path",
"=",
"config",
"[",
"CONF_URL_PATH",
"]",
"storage_key",
"=",
"CONFIG_STORAGE_KEY",
".",
"format",
"(",
"config",
"[",
"\"id\"",
"]",
")",
"super",
"(",
")",
".",
"__init__",
"(",
"hass",
",",
"url_path",
",",
"config",
")",
"self",
".",
"_store",
"=",
"storage",
".",
"Store",
"(",
"hass",
",",
"CONFIG_STORAGE_VERSION",
",",
"storage_key",
")",
"self",
".",
"_data",
"=",
"None"
] | [
83,
4
] | [
95,
25
] | python | en | ['en', 'en', 'en'] | True |
LovelaceStorage.mode | (self) | Return mode of the lovelace config. | Return mode of the lovelace config. | def mode(self) -> str:
"""Return mode of the lovelace config."""
return MODE_STORAGE | [
"def",
"mode",
"(",
"self",
")",
"->",
"str",
":",
"return",
"MODE_STORAGE"
] | [
98,
4
] | [
100,
27
] | python | en | ['en', 'en', 'en'] | True |
LovelaceStorage.async_get_info | (self) | Return the Lovelace storage info. | Return the Lovelace storage info. | async def async_get_info(self):
"""Return the Lovelace storage info."""
if self._data is None:
await self._load()
if self._data["config"] is None:
return {"mode": "auto-gen"}
return _config_info(self.mode, self._data["config"]) | [
"async",
"def",
"async_get_info",
"(",
"self",
")",
":",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"await",
"self",
".",
"_load",
"(",
")",
"if",
"self",
".",
"_data",
"[",
"\"config\"",
"]",
"is",
"None",
":",
"return",
"{",
"\"mode\"",
":",
"\"auto-gen\"",
"}",
"return",
"_config_info",
"(",
"self",
".",
"mode",
",",
"self",
".",
"_data",
"[",
"\"config\"",
"]",
")"
] | [
102,
4
] | [
110,
60
] | python | en | ['en', 'no', 'en'] | True |
LovelaceStorage.async_load | (self, force) | Load config. | Load config. | async def async_load(self, force):
"""Load config."""
if self.hass.config.safe_mode:
raise ConfigNotFound
if self._data is None:
await self._load()
config = self._data["config"]
if config is None:
raise ConfigNotFound
return config | [
"async",
"def",
"async_load",
"(",
"self",
",",
"force",
")",
":",
"if",
"self",
".",
"hass",
".",
"config",
".",
"safe_mode",
":",
"raise",
"ConfigNotFound",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"await",
"self",
".",
"_load",
"(",
")",
"config",
"=",
"self",
".",
"_data",
"[",
"\"config\"",
"]",
"if",
"config",
"is",
"None",
":",
"raise",
"ConfigNotFound",
"return",
"config"
] | [
112,
4
] | [
125,
21
] | python | en | ['en', 'es', 'en'] | False |
LovelaceStorage.async_save | (self, config) | Save config. | Save config. | async def async_save(self, config):
"""Save config."""
if self.hass.config.safe_mode:
raise HomeAssistantError("Saving not supported in safe mode")
if self._data is None:
await self._load()
self._data["config"] = config
self._config_updated()
await self._store.async_save(self._data) | [
"async",
"def",
"async_save",
"(",
"self",
",",
"config",
")",
":",
"if",
"self",
".",
"hass",
".",
"config",
".",
"safe_mode",
":",
"raise",
"HomeAssistantError",
"(",
"\"Saving not supported in safe mode\"",
")",
"if",
"self",
".",
"_data",
"is",
"None",
":",
"await",
"self",
".",
"_load",
"(",
")",
"self",
".",
"_data",
"[",
"\"config\"",
"]",
"=",
"config",
"self",
".",
"_config_updated",
"(",
")",
"await",
"self",
".",
"_store",
".",
"async_save",
"(",
"self",
".",
"_data",
")"
] | [
127,
4
] | [
136,
48
] | python | en | ['en', 'en', 'en'] | False |
LovelaceStorage.async_delete | (self) | Delete config. | Delete config. | async def async_delete(self):
"""Delete config."""
if self.hass.config.safe_mode:
raise HomeAssistantError("Deleting not supported in safe mode")
await self._store.async_remove()
self._data = None
self._config_updated() | [
"async",
"def",
"async_delete",
"(",
"self",
")",
":",
"if",
"self",
".",
"hass",
".",
"config",
".",
"safe_mode",
":",
"raise",
"HomeAssistantError",
"(",
"\"Deleting not supported in safe mode\"",
")",
"await",
"self",
".",
"_store",
".",
"async_remove",
"(",
")",
"self",
".",
"_data",
"=",
"None",
"self",
".",
"_config_updated",
"(",
")"
] | [
138,
4
] | [
145,
30
] | python | en | ['en', 'es', 'en'] | False |
LovelaceStorage._load | (self) | Load the config. | Load the config. | async def _load(self):
"""Load the config."""
data = await self._store.async_load()
self._data = data if data else {"config": None} | [
"async",
"def",
"_load",
"(",
"self",
")",
":",
"data",
"=",
"await",
"self",
".",
"_store",
".",
"async_load",
"(",
")",
"self",
".",
"_data",
"=",
"data",
"if",
"data",
"else",
"{",
"\"config\"",
":",
"None",
"}"
] | [
147,
4
] | [
150,
55
] | python | en | ['en', 'en', 'en'] | True |
LovelaceYAML.__init__ | (self, hass, url_path, config) | Initialize the YAML config. | Initialize the YAML config. | def __init__(self, hass, url_path, config):
"""Initialize the YAML config."""
super().__init__(hass, url_path, config)
self.path = hass.config.path(
config[CONF_FILENAME] if config else LOVELACE_CONFIG_FILE
)
self._cache = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"url_path",
",",
"config",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hass",
",",
"url_path",
",",
"config",
")",
"self",
".",
"path",
"=",
"hass",
".",
"config",
".",
"path",
"(",
"config",
"[",
"CONF_FILENAME",
"]",
"if",
"config",
"else",
"LOVELACE_CONFIG_FILE",
")",
"self",
".",
"_cache",
"=",
"None"
] | [
156,
4
] | [
163,
26
] | python | en | ['en', 'en', 'en'] | True |
LovelaceYAML.mode | (self) | Return mode of the lovelace config. | Return mode of the lovelace config. | def mode(self) -> str:
"""Return mode of the lovelace config."""
return MODE_YAML | [
"def",
"mode",
"(",
"self",
")",
"->",
"str",
":",
"return",
"MODE_YAML"
] | [
166,
4
] | [
168,
24
] | python | en | ['en', 'en', 'en'] | True |
LovelaceYAML.async_get_info | (self) | Return the YAML storage mode. | Return the YAML storage mode. | async def async_get_info(self):
"""Return the YAML storage mode."""
try:
config = await self.async_load(False)
except ConfigNotFound:
return {
"mode": self.mode,
"error": f"{self.path} not found",
}
return _config_info(self.mode, config) | [
"async",
"def",
"async_get_info",
"(",
"self",
")",
":",
"try",
":",
"config",
"=",
"await",
"self",
".",
"async_load",
"(",
"False",
")",
"except",
"ConfigNotFound",
":",
"return",
"{",
"\"mode\"",
":",
"self",
".",
"mode",
",",
"\"error\"",
":",
"f\"{self.path} not found\"",
",",
"}",
"return",
"_config_info",
"(",
"self",
".",
"mode",
",",
"config",
")"
] | [
170,
4
] | [
180,
46
] | python | en | ['en', 'sn', 'en'] | True |
LovelaceYAML.async_load | (self, force) | Load config. | Load config. | async def async_load(self, force):
"""Load config."""
is_updated, config = await self.hass.async_add_executor_job(
self._load_config, force
)
if is_updated:
self._config_updated()
return config | [
"async",
"def",
"async_load",
"(",
"self",
",",
"force",
")",
":",
"is_updated",
",",
"config",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_load_config",
",",
"force",
")",
"if",
"is_updated",
":",
"self",
".",
"_config_updated",
"(",
")",
"return",
"config"
] | [
182,
4
] | [
189,
21
] | python | en | ['en', 'es', 'en'] | False |
LovelaceYAML._load_config | (self, force) | Load the actual config. | Load the actual config. | def _load_config(self, force):
"""Load the actual config."""
# Check for a cached version of the config
if not force and self._cache is not None:
config, last_update = self._cache
modtime = os.path.getmtime(self.path)
if config and last_update > modtime:
return False, config
is_updated = self._cache is not None
try:
config = load_yaml(self.path)
except FileNotFoundError:
raise ConfigNotFound from None
self._cache = (config, time.time())
return is_updated, config | [
"def",
"_load_config",
"(",
"self",
",",
"force",
")",
":",
"# Check for a cached version of the config",
"if",
"not",
"force",
"and",
"self",
".",
"_cache",
"is",
"not",
"None",
":",
"config",
",",
"last_update",
"=",
"self",
".",
"_cache",
"modtime",
"=",
"os",
".",
"path",
".",
"getmtime",
"(",
"self",
".",
"path",
")",
"if",
"config",
"and",
"last_update",
">",
"modtime",
":",
"return",
"False",
",",
"config",
"is_updated",
"=",
"self",
".",
"_cache",
"is",
"not",
"None",
"try",
":",
"config",
"=",
"load_yaml",
"(",
"self",
".",
"path",
")",
"except",
"FileNotFoundError",
":",
"raise",
"ConfigNotFound",
"from",
"None",
"self",
".",
"_cache",
"=",
"(",
"config",
",",
"time",
".",
"time",
"(",
")",
")",
"return",
"is_updated",
",",
"config"
] | [
191,
4
] | [
208,
33
] | python | en | ['en', 'en', 'en'] | True |
DashboardsCollection.__init__ | (self, hass) | Initialize the dashboards collection. | Initialize the dashboards collection. | def __init__(self, hass):
"""Initialize the dashboards collection."""
super().__init__(
storage.Store(hass, DASHBOARDS_STORAGE_VERSION, DASHBOARDS_STORAGE_KEY),
_LOGGER,
) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"storage",
".",
"Store",
"(",
"hass",
",",
"DASHBOARDS_STORAGE_VERSION",
",",
"DASHBOARDS_STORAGE_KEY",
")",
",",
"_LOGGER",
",",
")"
] | [
225,
4
] | [
230,
9
] | python | en | ['en', 'en', 'en'] | True |
DashboardsCollection._async_load_data | (self) | Load the data. | Load the data. | async def _async_load_data(self) -> Optional[dict]:
"""Load the data."""
data = await self.store.async_load()
if data is None:
return cast(Optional[dict], data)
updated = False
for item in data["items"] or []:
if "-" not in item[CONF_URL_PATH]:
updated = True
item[CONF_URL_PATH] = f"lovelace-{item[CONF_URL_PATH]}"
if updated:
await self.store.async_save(data)
return cast(Optional[dict], data) | [
"async",
"def",
"_async_load_data",
"(",
"self",
")",
"->",
"Optional",
"[",
"dict",
"]",
":",
"data",
"=",
"await",
"self",
".",
"store",
".",
"async_load",
"(",
")",
"if",
"data",
"is",
"None",
":",
"return",
"cast",
"(",
"Optional",
"[",
"dict",
"]",
",",
"data",
")",
"updated",
"=",
"False",
"for",
"item",
"in",
"data",
"[",
"\"items\"",
"]",
"or",
"[",
"]",
":",
"if",
"\"-\"",
"not",
"in",
"item",
"[",
"CONF_URL_PATH",
"]",
":",
"updated",
"=",
"True",
"item",
"[",
"CONF_URL_PATH",
"]",
"=",
"f\"lovelace-{item[CONF_URL_PATH]}\"",
"if",
"updated",
":",
"await",
"self",
".",
"store",
".",
"async_save",
"(",
"data",
")",
"return",
"cast",
"(",
"Optional",
"[",
"dict",
"]",
",",
"data",
")"
] | [
232,
4
] | [
249,
41
] | python | en | ['en', 'en', 'en'] | True |
DashboardsCollection._process_create_data | (self, data: dict) | Validate the config is valid. | Validate the config is valid. | async def _process_create_data(self, data: dict) -> dict:
"""Validate the config is valid."""
if "-" not in data[CONF_URL_PATH]:
raise vol.Invalid("Url path needs to contain a hyphen (-)")
if data[CONF_URL_PATH] in self.hass.data[DATA_PANELS]:
raise vol.Invalid("Panel url path needs to be unique")
return self.CREATE_SCHEMA(data) | [
"async",
"def",
"_process_create_data",
"(",
"self",
",",
"data",
":",
"dict",
")",
"->",
"dict",
":",
"if",
"\"-\"",
"not",
"in",
"data",
"[",
"CONF_URL_PATH",
"]",
":",
"raise",
"vol",
".",
"Invalid",
"(",
"\"Url path needs to contain a hyphen (-)\"",
")",
"if",
"data",
"[",
"CONF_URL_PATH",
"]",
"in",
"self",
".",
"hass",
".",
"data",
"[",
"DATA_PANELS",
"]",
":",
"raise",
"vol",
".",
"Invalid",
"(",
"\"Panel url path needs to be unique\"",
")",
"return",
"self",
".",
"CREATE_SCHEMA",
"(",
"data",
")"
] | [
251,
4
] | [
259,
39
] | python | en | ['en', 'en', 'en'] | True |
DashboardsCollection._get_suggested_id | (self, info: dict) | Suggest an ID based on the config. | Suggest an ID based on the config. | def _get_suggested_id(self, info: dict) -> str:
"""Suggest an ID based on the config."""
return info[CONF_URL_PATH] | [
"def",
"_get_suggested_id",
"(",
"self",
",",
"info",
":",
"dict",
")",
"->",
"str",
":",
"return",
"info",
"[",
"CONF_URL_PATH",
"]"
] | [
262,
4
] | [
264,
34
] | python | en | ['en', 'en', 'en'] | True |
DashboardsCollection._update_data | (self, data: dict, update_data: dict) | Return a new updated data object. | Return a new updated data object. | async def _update_data(self, data: dict, update_data: dict) -> dict:
"""Return a new updated data object."""
update_data = self.UPDATE_SCHEMA(update_data)
updated = {**data, **update_data}
if CONF_ICON in updated and updated[CONF_ICON] is None:
updated.pop(CONF_ICON)
return updated | [
"async",
"def",
"_update_data",
"(",
"self",
",",
"data",
":",
"dict",
",",
"update_data",
":",
"dict",
")",
"->",
"dict",
":",
"update_data",
"=",
"self",
".",
"UPDATE_SCHEMA",
"(",
"update_data",
")",
"updated",
"=",
"{",
"*",
"*",
"data",
",",
"*",
"*",
"update_data",
"}",
"if",
"CONF_ICON",
"in",
"updated",
"and",
"updated",
"[",
"CONF_ICON",
"]",
"is",
"None",
":",
"updated",
".",
"pop",
"(",
"CONF_ICON",
")",
"return",
"updated"
] | [
266,
4
] | [
274,
22
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up an OpenUV sensor based on a config entry. | Set up an OpenUV sensor based on a config entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up an OpenUV sensor based on a config entry."""
openuv = hass.data[DOMAIN][DATA_OPENUV_CLIENT][entry.entry_id]
binary_sensors = []
for kind, attrs in BINARY_SENSORS.items():
name, icon = attrs
binary_sensors.append(
OpenUvBinarySensor(openuv, kind, name, icon, entry.entry_id)
)
async_add_entities(binary_sensors, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"openuv",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"DATA_OPENUV_CLIENT",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"binary_sensors",
"=",
"[",
"]",
"for",
"kind",
",",
"attrs",
"in",
"BINARY_SENSORS",
".",
"items",
"(",
")",
":",
"name",
",",
"icon",
"=",
"attrs",
"binary_sensors",
".",
"append",
"(",
"OpenUvBinarySensor",
"(",
"openuv",
",",
"kind",
",",
"name",
",",
"icon",
",",
"entry",
".",
"entry_id",
")",
")",
"async_add_entities",
"(",
"binary_sensors",
",",
"True",
")"
] | [
25,
0
] | [
36,
44
] | python | en | ['en', 'en', 'en'] | True |
OpenUvBinarySensor.__init__ | (self, openuv, sensor_type, name, icon, entry_id) | Initialize the sensor. | Initialize the sensor. | def __init__(self, openuv, sensor_type, name, icon, entry_id):
"""Initialize the sensor."""
super().__init__(openuv)
self._async_unsub_dispatcher_connect = None
self._entry_id = entry_id
self._icon = icon
self._latitude = openuv.client.latitude
self._longitude = openuv.client.longitude
self._name = name
self._sensor_type = sensor_type
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"openuv",
",",
"sensor_type",
",",
"name",
",",
"icon",
",",
"entry_id",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"openuv",
")",
"self",
".",
"_async_unsub_dispatcher_connect",
"=",
"None",
"self",
".",
"_entry_id",
"=",
"entry_id",
"self",
".",
"_icon",
"=",
"icon",
"self",
".",
"_latitude",
"=",
"openuv",
".",
"client",
".",
"latitude",
"self",
".",
"_longitude",
"=",
"openuv",
".",
"client",
".",
"longitude",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_sensor_type",
"=",
"sensor_type",
"self",
".",
"_state",
"=",
"None"
] | [
42,
4
] | [
53,
26
] | python | en | ['en', 'en', 'en'] | True |
OpenUvBinarySensor.icon | (self) | Return the icon. | Return the icon. | def icon(self):
"""Return the icon."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
56,
4
] | [
58,
25
] | python | en | ['en', 'sr', 'en'] | True |
OpenUvBinarySensor.is_on | (self) | Return the status of the sensor. | Return the status of the sensor. | def is_on(self):
"""Return the status of the sensor."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
61,
4
] | [
63,
26
] | python | en | ['en', 'id', 'en'] | True |
OpenUvBinarySensor.should_poll | (self) | Disable polling. | Disable polling. | def should_poll(self):
"""Disable polling."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
66,
4
] | [
68,
20
] | python | en | ['fr', 'en', 'en'] | False |
OpenUvBinarySensor.unique_id | (self) | Return a unique, Home Assistant friendly identifier for this entity. | Return a unique, Home Assistant friendly identifier for this entity. | def unique_id(self) -> str:
"""Return a unique, Home Assistant friendly identifier for this entity."""
return f"{self._latitude}_{self._longitude}_{self._sensor_type}" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{self._latitude}_{self._longitude}_{self._sensor_type}\""
] | [
71,
4
] | [
73,
72
] | python | en | ['en', 'en', 'en'] | True |
OpenUvBinarySensor.update_from_latest_data | (self) | Update the state. | Update the state. | def update_from_latest_data(self):
"""Update the state."""
data = self.openuv.data[DATA_PROTECTION_WINDOW]
if not data:
self._available = False
return
self._available = True
for key in ("from_time", "to_time", "from_uv", "to_uv"):
if not data.get(key):
_LOGGER.info("Skipping update due to missing data: %s", key)
return
if self._sensor_type == TYPE_PROTECTION_WINDOW:
self._state = (
parse_datetime(data["from_time"])
<= utcnow()
<= parse_datetime(data["to_time"])
)
self._attrs.update(
{
ATTR_PROTECTION_WINDOW_ENDING_TIME: as_local(
parse_datetime(data["to_time"])
),
ATTR_PROTECTION_WINDOW_ENDING_UV: data["to_uv"],
ATTR_PROTECTION_WINDOW_STARTING_UV: data["from_uv"],
ATTR_PROTECTION_WINDOW_STARTING_TIME: as_local(
parse_datetime(data["from_time"])
),
}
) | [
"def",
"update_from_latest_data",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"openuv",
".",
"data",
"[",
"DATA_PROTECTION_WINDOW",
"]",
"if",
"not",
"data",
":",
"self",
".",
"_available",
"=",
"False",
"return",
"self",
".",
"_available",
"=",
"True",
"for",
"key",
"in",
"(",
"\"from_time\"",
",",
"\"to_time\"",
",",
"\"from_uv\"",
",",
"\"to_uv\"",
")",
":",
"if",
"not",
"data",
".",
"get",
"(",
"key",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Skipping update due to missing data: %s\"",
",",
"key",
")",
"return",
"if",
"self",
".",
"_sensor_type",
"==",
"TYPE_PROTECTION_WINDOW",
":",
"self",
".",
"_state",
"=",
"(",
"parse_datetime",
"(",
"data",
"[",
"\"from_time\"",
"]",
")",
"<=",
"utcnow",
"(",
")",
"<=",
"parse_datetime",
"(",
"data",
"[",
"\"to_time\"",
"]",
")",
")",
"self",
".",
"_attrs",
".",
"update",
"(",
"{",
"ATTR_PROTECTION_WINDOW_ENDING_TIME",
":",
"as_local",
"(",
"parse_datetime",
"(",
"data",
"[",
"\"to_time\"",
"]",
")",
")",
",",
"ATTR_PROTECTION_WINDOW_ENDING_UV",
":",
"data",
"[",
"\"to_uv\"",
"]",
",",
"ATTR_PROTECTION_WINDOW_STARTING_UV",
":",
"data",
"[",
"\"from_uv\"",
"]",
",",
"ATTR_PROTECTION_WINDOW_STARTING_TIME",
":",
"as_local",
"(",
"parse_datetime",
"(",
"data",
"[",
"\"from_time\"",
"]",
")",
")",
",",
"}",
")"
] | [
76,
4
] | [
108,
13
] | 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.