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 list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
RflinkCover.assumed_state | (self) | Return True because covers can be stopped midway. | Return True because covers can be stopped midway. | def assumed_state(self):
"""Return True because covers can be stopped midway."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"True"
] | [
146,
4
] | [
148,
19
] | python | en | ['en', 'en', 'en'] | True |
RflinkCover.async_close_cover | (self, **kwargs) | Turn the device close. | Turn the device close. | async def async_close_cover(self, **kwargs):
"""Turn the device close."""
await self._async_handle_command("close_cover") | [
"async",
"def",
"async_close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_async_handle_command",
"(",
"\"close_cover\"",
")"
] | [
150,
4
] | [
152,
55
] | python | en | ['en', 'en', 'en'] | True |
RflinkCover.async_open_cover | (self, **kwargs) | Turn the device open. | Turn the device open. | async def async_open_cover(self, **kwargs):
"""Turn the device open."""
await self._async_handle_command("open_cover") | [
"async",
"def",
"async_open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_async_handle_command",
"(",
"\"open_cover\"",
")"
] | [
154,
4
] | [
156,
54
] | python | en | ['en', 'en', 'en'] | True |
RflinkCover.async_stop_cover | (self, **kwargs) | Turn the device stop. | Turn the device stop. | async def async_stop_cover(self, **kwargs):
"""Turn the device stop."""
await self._async_handle_command("stop_cover") | [
"async",
"def",
"async_stop_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_async_handle_command",
"(",
"\"stop_cover\"",
")"
] | [
158,
4
] | [
160,
54
] | python | en | ['en', 'en', 'en'] | True |
InvertedRflinkCover._async_send_command | (self, cmd, repetitions) | Will invert only the UP/DOWN commands. | Will invert only the UP/DOWN commands. | async def _async_send_command(self, cmd, repetitions):
"""Will invert only the UP/DOWN commands."""
_LOGGER.debug("Getting command: %s for Rflink device: %s", cmd, self._device_id)
cmd_inv = {"UP": "DOWN", "DOWN": "UP"}
await super()._async_send_command(cmd_inv.get(cmd, cmd), repetitions... | [
"async",
"def",
"_async_send_command",
"(",
"self",
",",
"cmd",
",",
"repetitions",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Getting command: %s for Rflink device: %s\"",
",",
"cmd",
",",
"self",
".",
"_device_id",
")",
"cmd_inv",
"=",
"{",
"\"UP\"",
":",
"\... | [
166,
4
] | [
170,
77
] | python | en | ['en', 'en', 'en'] | True |
OpEvo.update_search_space | (self, search_space) | Update the self.bounds and self.types by the search_space.json file.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
| Update the self.bounds and self.types by the search_space.json file. | def update_search_space(self, search_space):
"""Update the self.bounds and self.types by the search_space.json file.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
"""
if not isinstance(search_space, dict):
self.logger.info("The format of search space is not a... | [
"def",
"update_search_space",
"(",
"self",
",",
"search_space",
")",
":",
"if",
"not",
"isinstance",
"(",
"search_space",
",",
"dict",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"The format of search space is not a dict.\"",
")",
"raise",
"RuntimeError",... | [
377,
4
] | [
393,
55
] | python | en | ['en', 'en', 'en'] | True |
OpEvo.generate_multiple_parameters | (self, parameter_id_list, **kwargs) | Returns multiple sets of trial (hyper-)parameters,
as iterable of serializable objects.
| Returns multiple sets of trial (hyper-)parameters,
as iterable of serializable objects.
| def generate_multiple_parameters(self, parameter_id_list, **kwargs):
"""Returns multiple sets of trial (hyper-)parameters,
as iterable of serializable objects.
"""
result = []
self.send_trial_callback = kwargs['st_callback']
for parameter_id in parameter_id_list:
... | [
"def",
"generate_multiple_parameters",
"(",
"self",
",",
"parameter_id_list",
",",
"*",
"*",
"kwargs",
")",
":",
"result",
"=",
"[",
"]",
"self",
".",
"send_trial_callback",
"=",
"kwargs",
"[",
"'st_callback'",
"]",
"for",
"parameter_id",
"in",
"parameter_id_lis... | [
395,
4
] | [
410,
21
] | python | en | ['en', 'af', 'en'] | True |
OpEvo.generate_parameters | (self, parameter_id, **kwargs) | Method which provides one set of hyper-parameters.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
| Method which provides one set of hyper-parameters. | def generate_parameters(self, parameter_id, **kwargs):
"""Method which provides one set of hyper-parameters.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
"""
if self.serve_list:
self.wait_dict[parameter_id] = self.serve_list.pop()
return self.wai... | [
"def",
"generate_parameters",
"(",
"self",
",",
"parameter_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"serve_list",
":",
"self",
".",
"wait_dict",
"[",
"parameter_id",
"]",
"=",
"self",
".",
"serve_list",
".",
"pop",
"(",
")",
"return",
... | [
412,
4
] | [
422,
65
] | python | en | ['en', 'en', 'en'] | True |
OpEvo.receive_trial_result | (self, parameter_id, parameters, value, **kwargs) | Method invoked when a trial reports its final result.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
| Method invoked when a trial reports its final result. | def receive_trial_result(self, parameter_id, parameters, value, **kwargs):
"""Method invoked when a trial reports its final result.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
"""
if isinstance(value, dict):
value = value['default']
self.population... | [
"def",
"receive_trial_result",
"(",
"self",
",",
"parameter_id",
",",
"parameters",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"value",
"=",
"value",
"[",
"'default'",
"]",
"self",
".",
"po... | [
424,
4
] | [
444,
36
] | python | en | ['en', 'en', 'en'] | True |
OpEvo.trial_end | (self, parameter_id, success, **kwargs) | Method invoked when a trial is completed or terminated.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
| Method invoked when a trial is completed or terminated. | def trial_end(self, parameter_id, success, **kwargs):
"""Method invoked when a trial is completed or terminated.
Override of the abstract method in :class:`~nni.tuner.Tuner`.
"""
if not success:
self.population.append(self.wait_dict[parameter_id], 0.0)
del self.w... | [
"def",
"trial_end",
"(",
"self",
",",
"parameter_id",
",",
"success",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"success",
":",
"self",
".",
"population",
".",
"append",
"(",
"self",
".",
"wait_dict",
"[",
"parameter_id",
"]",
",",
"0.0",
")",
... | [
446,
4
] | [
453,
44
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the EDL21 sensor. | Set up the EDL21 sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the EDL21 sensor."""
hass.data[DOMAIN] = EDL21(hass, config, async_add_entities)
await hass.data[DOMAIN].connect() | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"EDL21",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")",
... | [
38,
0
] | [
41,
37
] | python | en | ['en', 'da', 'en'] | True |
EDL21.__init__ | (self, hass, config, async_add_entities) | Initialize an EDL21 object. | Initialize an EDL21 object. | def __init__(self, hass, config, async_add_entities) -> None:
"""Initialize an EDL21 object."""
self._registered_obis = set()
self._hass = hass
self._async_add_entities = async_add_entities
self._name = config[CONF_NAME]
self._proto = SmlProtocol(config[CONF_SERIAL_PORT])... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config",
",",
"async_add_entities",
")",
"->",
"None",
":",
"self",
".",
"_registered_obis",
"=",
"set",
"(",
")",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_async_add_entities",
"=",
"async_add_ent... | [
98,
4
] | [
105,
68
] | python | en | ['en', 'en', 'it'] | True |
EDL21.connect | (self) | Connect to an EDL21 reader. | Connect to an EDL21 reader. | async def connect(self):
"""Connect to an EDL21 reader."""
await self._proto.connect(self._hass.loop) | [
"async",
"def",
"connect",
"(",
"self",
")",
":",
"await",
"self",
".",
"_proto",
".",
"connect",
"(",
"self",
".",
"_hass",
".",
"loop",
")"
] | [
107,
4
] | [
109,
50
] | python | en | ['en', 'en', 'en'] | True |
EDL21.event | (self, message_body) | Handle events from pysml. | Handle events from pysml. | def event(self, message_body) -> None:
"""Handle events from pysml."""
assert isinstance(message_body, SmlGetListResponse)
electricity_id = None
for telegram in message_body.get("valList", []):
if telegram.get("objName") == "1-0:0.0.9*255":
electricity_id = t... | [
"def",
"event",
"(",
"self",
",",
"message_body",
")",
"->",
"None",
":",
"assert",
"isinstance",
"(",
"message_body",
",",
"SmlGetListResponse",
")",
"electricity_id",
"=",
"None",
"for",
"telegram",
"in",
"message_body",
".",
"get",
"(",
"\"valList\"",
",",
... | [
111,
4
] | [
153,
72
] | python | en | ['en', 'en', 'en'] | True |
EDL21.add_entities | (self, new_entities) | Migrate old unique IDs, then add entities to hass. | Migrate old unique IDs, then add entities to hass. | async def add_entities(self, new_entities) -> None:
"""Migrate old unique IDs, then add entities to hass."""
registry = await async_get_registry(self._hass)
for entity in new_entities:
old_entity_id = registry.async_get_entity_id(
"sensor", DOMAIN, entity.old_unique_... | [
"async",
"def",
"add_entities",
"(",
"self",
",",
"new_entities",
")",
"->",
"None",
":",
"registry",
"=",
"await",
"async_get_registry",
"(",
"self",
".",
"_hass",
")",
"for",
"entity",
"in",
"new_entities",
":",
"old_entity_id",
"=",
"registry",
".",
"asyn... | [
155,
4
] | [
176,
70
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.__init__ | (self, electricity_id, obis, name, telegram) | Initialize an EDL21Entity. | Initialize an EDL21Entity. | def __init__(self, electricity_id, obis, name, telegram):
"""Initialize an EDL21Entity."""
self._electricity_id = electricity_id
self._obis = obis
self._name = name
self._unique_id = f"{electricity_id}_{obis}"
self._telegram = telegram
self._min_time = MIN_TIME_BE... | [
"def",
"__init__",
"(",
"self",
",",
"electricity_id",
",",
"obis",
",",
"name",
",",
"telegram",
")",
":",
"self",
".",
"_electricity_id",
"=",
"electricity_id",
"self",
".",
"_obis",
"=",
"obis",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_unique... | [
182,
4
] | [
197,
44
] | python | en | ['en', 'en', 'it'] | True |
EDL21Entity.async_added_to_hass | (self) | Run when entity about to be added to hass. | Run when entity about to be added to hass. | async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
@callback
def handle_telegram(electricity_id, telegram):
"""Update attributes from last received telegram for this object."""
if self._electricity_id != electricity_id:
... | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"@",
"callback",
"def",
"handle_telegram",
"(",
"electricity_id",
",",
"telegram",
")",
":",
"\"\"\"Update attributes from last received telegram for this object.\"\"\"",
"if",
"self",
".",
"_electricity_id",
"... | [
199,
4
] | [
222,
9
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.async_will_remove_from_hass | (self) | Run when entity will be removed from hass. | Run when entity will be removed from hass. | async def async_will_remove_from_hass(self):
"""Run when entity will be removed from hass."""
if self._async_remove_dispatcher:
self._async_remove_dispatcher() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"if",
"self",
".",
"_async_remove_dispatcher",
":",
"self",
".",
"_async_remove_dispatcher",
"(",
")"
] | [
224,
4
] | [
227,
43
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.should_poll | (self) | Do not poll. | Do not poll. | def should_poll(self) -> bool:
"""Do not poll."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
230,
4
] | [
232,
20
] | python | en | ['en', 'lb', 'en'] | True |
EDL21Entity.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_unique_id"
] | [
235,
4
] | [
237,
30
] | python | ca | ['fr', 'ca', 'en'] | False |
EDL21Entity.old_unique_id | (self) | Return a less unique ID as used in the first version of edl21. | Return a less unique ID as used in the first version of edl21. | def old_unique_id(self) -> str:
"""Return a less unique ID as used in the first version of edl21."""
return self._obis | [
"def",
"old_unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_obis"
] | [
240,
4
] | [
242,
25
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.name | (self) | Return a name. | Return a name. | def name(self) -> Optional[str]:
"""Return a name."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_name"
] | [
245,
4
] | [
247,
25
] | python | en | ['en', 'ig', 'en'] | True |
EDL21Entity.state | (self) | Return the value of the last received telegram. | Return the value of the last received telegram. | def state(self) -> str:
"""Return the value of the last received telegram."""
return self._telegram.get("value") | [
"def",
"state",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_telegram",
".",
"get",
"(",
"\"value\"",
")"
] | [
250,
4
] | [
252,
42
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.device_state_attributes | (self) | Enumerate supported attributes. | Enumerate supported attributes. | def device_state_attributes(self):
"""Enumerate supported attributes."""
return {
self._state_attrs[k]: v
for k, v in self._telegram.items()
if k in self._state_attrs
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"self",
".",
"_state_attrs",
"[",
"k",
"]",
":",
"v",
"for",
"k",
",",
"v",
"in",
"self",
".",
"_telegram",
".",
"items",
"(",
")",
"if",
"k",
"in",
"self",
".",
"_state_attrs",
... | [
255,
4
] | [
261,
9
] | python | en | ['en', 'en', 'en'] | True |
EDL21Entity.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._telegram.get("unit") | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_telegram",
".",
"get",
"(",
"\"unit\"",
")"
] | [
264,
4
] | [
266,
41
] | python | en | ['en', 'la', 'en'] | True |
EDL21Entity.icon | (self) | Return an icon. | Return an icon. | def icon(self):
"""Return an icon."""
return ICON_POWER | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON_POWER"
] | [
269,
4
] | [
271,
25
] | python | en | ['en', 'gd', 'en'] | True |
async_setup_platform | (hass, config, add_entities, discovery_info=None) | Set up a single Sisyphus table. | Set up a single Sisyphus table. | async def async_setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a single Sisyphus table."""
host = discovery_info[CONF_HOST]
try:
table_holder = hass.data[DATA_SISYPHUS][host]
table = await table_holder.get_table()
except aiohttp.ClientError as err:
rai... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"discovery_info",
"[",
"CONF_HOST",
"]",
"try",
":",
"table_holder",
"=",
"hass",
".",
"data",
"[",
"DATA_SISY... | [
16,
0
] | [
25,
83
] | python | en | ['en', 'st', 'en'] | True |
SisyphusLight.__init__ | (self, name, table) | Initialize the Sisyphus table. | Initialize the Sisyphus table. | def __init__(self, name, table):
"""Initialize the Sisyphus table."""
self._name = name
self._table = table | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"table",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_table",
"=",
"table"
] | [
31,
4
] | [
34,
27
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.async_added_to_hass | (self) | Add listeners after this object has been initialized. | Add listeners after this object has been initialized. | async def async_added_to_hass(self):
"""Add listeners after this object has been initialized."""
self._table.add_listener(self.async_write_ha_state) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"_table",
".",
"add_listener",
"(",
"self",
".",
"async_write_ha_state",
")"
] | [
36,
4
] | [
38,
59
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.async_update | (self) | Force update the table state. | Force update the table state. | async def async_update(self):
"""Force update the table state."""
await self._table.refresh() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"self",
".",
"_table",
".",
"refresh",
"(",
")"
] | [
40,
4
] | [
42,
35
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.available | (self) | Return true if the table is responding to heartbeats. | Return true if the table is responding to heartbeats. | def available(self):
"""Return true if the table is responding to heartbeats."""
return self._table.is_connected | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_table",
".",
"is_connected"
] | [
45,
4
] | [
47,
39
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.unique_id | (self) | Return the UUID of the table. | Return the UUID of the table. | def unique_id(self):
"""Return the UUID of the table."""
return self._table.id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_table",
".",
"id"
] | [
50,
4
] | [
52,
29
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.name | (self) | Return the ame of the table. | Return the ame of the table. | def name(self):
"""Return the ame of the table."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
55,
4
] | [
57,
25
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.is_on | (self) | Return True if the table is on. | Return True if the table is on. | def is_on(self):
"""Return True if the table is on."""
return not self._table.is_sleeping | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"not",
"self",
".",
"_table",
".",
"is_sleeping"
] | [
60,
4
] | [
62,
42
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.brightness | (self) | Return the current brightness of the table's ring light. | Return the current brightness of the table's ring light. | def brightness(self):
"""Return the current brightness of the table's ring light."""
return self._table.brightness * 255 | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_table",
".",
"brightness",
"*",
"255"
] | [
65,
4
] | [
67,
43
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.supported_features | (self) | Return the features supported by the table; i.e. brightness. | Return the features supported by the table; i.e. brightness. | def supported_features(self):
"""Return the features supported by the table; i.e. brightness."""
return SUPPORTED_FEATURES | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORTED_FEATURES"
] | [
70,
4
] | [
72,
33
] | python | en | ['en', 'en', 'en'] | True |
SisyphusLight.async_turn_off | (self, **kwargs) | Put the table to sleep. | Put the table to sleep. | async def async_turn_off(self, **kwargs):
"""Put the table to sleep."""
await self._table.sleep()
_LOGGER.debug("Sisyphus table %s: sleep") | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_table",
".",
"sleep",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Sisyphus table %s: sleep\"",
")"
] | [
74,
4
] | [
77,
49
] | python | en | ['en', 'ceb', 'en'] | True |
SisyphusLight.async_turn_on | (self, **kwargs) | Wake up the table if necessary, optionally changes brightness. | Wake up the table if necessary, optionally changes brightness. | async def async_turn_on(self, **kwargs):
"""Wake up the table if necessary, optionally changes brightness."""
if not self.is_on:
await self._table.wakeup()
_LOGGER.debug("Sisyphus table %s: wakeup")
if "brightness" in kwargs:
await self._table.set_brightness(... | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"is_on",
":",
"await",
"self",
".",
"_table",
".",
"wakeup",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Sisyphus table %s: wakeup\"",
")",
"if",
... | [
79,
4
] | [
86,
74
] | python | en | ['en', 'en', 'en'] | True |
mock_controller_service | () | Mock a successful service. | Mock a successful service. | def mock_controller_service():
"""Mock a successful service."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService"
) as service_mock:
service_mock.return_value.requires_2sa = True
service_mock.return_value.trusted_devices = TRUSTED_DEVICES
service_mock.... | [
"def",
"mock_controller_service",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService\"",
")",
"as",
"service_mock",
":",
"service_mock",
".",
"return_value",
".",
"requires_2sa",
"=",
"True",
"service_mock",
".",
"return_va... | [
47,
0
] | [
56,
26
] | python | en | ['en', 'ro', 'en'] | True |
mock_controller_service_authenticated | () | Mock a successful service while already authenticate. | Mock a successful service while already authenticate. | def mock_controller_service_authenticated():
"""Mock a successful service while already authenticate."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService"
) as service_mock:
service_mock.return_value.requires_2sa = False
service_mock.return_value.trusted_devic... | [
"def",
"mock_controller_service_authenticated",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService\"",
")",
"as",
"service_mock",
":",
"service_mock",
".",
"return_value",
".",
"requires_2sa",
"=",
"False",
"service_mock",
".... | [
60,
0
] | [
69,
26
] | python | en | ['en', 'en', 'en'] | True |
mock_controller_service_authenticated_no_device | () | Mock a successful service while already authenticate, but without device. | Mock a successful service while already authenticate, but without device. | def mock_controller_service_authenticated_no_device():
"""Mock a successful service while already authenticate, but without device."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService"
) as service_mock:
service_mock.return_value.requires_2sa = False
service_m... | [
"def",
"mock_controller_service_authenticated_no_device",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService\"",
")",
"as",
"service_mock",
":",
"service_mock",
".",
"return_value",
".",
"requires_2sa",
"=",
"False",
"service_m... | [
73,
0
] | [
83,
26
] | python | en | ['en', 'en', 'en'] | True |
mock_controller_service_send_verification_code_failed | () | Mock a failed service during sending verification code step. | Mock a failed service during sending verification code step. | def mock_controller_service_send_verification_code_failed():
"""Mock a failed service during sending verification code step."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService"
) as service_mock:
service_mock.return_value.requires_2sa = True
service_mock.retu... | [
"def",
"mock_controller_service_send_verification_code_failed",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService\"",
")",
"as",
"service_mock",
":",
"service_mock",
".",
"return_value",
".",
"requires_2sa",
"=",
"True",
"serv... | [
87,
0
] | [
95,
26
] | python | en | ['af', 'en', 'en'] | True |
mock_controller_service_validate_verification_code_failed | () | Mock a failed service during validation of verification code step. | Mock a failed service during validation of verification code step. | def mock_controller_service_validate_verification_code_failed():
"""Mock a failed service during validation of verification code step."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService"
) as service_mock:
service_mock.return_value.requires_2sa = True
service... | [
"def",
"mock_controller_service_validate_verification_code_failed",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService\"",
")",
"as",
"service_mock",
":",
"service_mock",
".",
"return_value",
".",
"requires_2sa",
"=",
"True",
"... | [
99,
0
] | [
108,
26
] | python | en | ['en', 'en', 'en'] | True |
test_user | (hass: HomeAssistantType, service: MagicMock) | Test user config. | Test user config. | async def test_user(hass: HomeAssistantType, service: MagicMock):
"""Test user config."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=None
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "user"
... | [
"async",
"def",
"test_user",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":... | [
111,
0
] | [
126,
51
] | python | en | ['en', 'da', 'en'] | True |
test_user_with_cookie | (
hass: HomeAssistantType, service_authenticated: MagicMock
) | Test user config with presence of a cookie. | Test user config with presence of a cookie. | async def test_user_with_cookie(
hass: HomeAssistantType, service_authenticated: MagicMock
):
"""Test user config with presence of a cookie."""
# test with all provided
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={
... | [
"async",
"def",
"test_user_with_cookie",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_authenticated",
":",
"MagicMock",
")",
":",
"# test with all provided",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN"... | [
129,
0
] | [
150,
88
] | python | en | ['en', 'en', 'en'] | True |
test_import | (hass: HomeAssistantType, service: MagicMock) | Test import step. | Test import step. | async def test_import(hass: HomeAssistantType, service: MagicMock):
"""Test import step."""
# import with required
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
)
assert ... | [
"async",
"def",
"test_import",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"# import with required",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=... | [
153,
0
] | [
177,
48
] | python | de | ['de', 'sd', 'en'] | False |
test_import_with_cookie | (
hass: HomeAssistantType, service_authenticated: MagicMock
) | Test import step with presence of a cookie. | Test import step with presence of a cookie. | async def test_import_with_cookie(
hass: HomeAssistantType, service_authenticated: MagicMock
):
"""Test import step with presence of a cookie."""
# import with required
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_USERN... | [
"async",
"def",
"test_import_with_cookie",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_authenticated",
":",
"MagicMock",
")",
":",
"# import with required",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN"... | [
180,
0
] | [
218,
80
] | python | en | ['en', 'en', 'en'] | True |
test_two_accounts_setup | (
hass: HomeAssistantType, service_authenticated: MagicMock
) | Test to setup two accounts. | Test to setup two accounts. | async def test_two_accounts_setup(
hass: HomeAssistantType, service_authenticated: MagicMock
):
"""Test to setup two accounts."""
MockConfigEntry(
domain=DOMAIN,
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
unique_id=USERNAME,
).add_to_hass(hass)
# import with re... | [
"async",
"def",
"test_two_accounts_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_authenticated",
":",
"MagicMock",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"CONF_USERNAME",
":",
"USERNAME",
",",
"CONF_PASSWOR... | [
221,
0
] | [
244,
88
] | python | en | ['en', 'en', 'en'] | True |
test_already_setup | (hass: HomeAssistantType) | Test we abort if the account is already setup. | Test we abort if the account is already setup. | async def test_already_setup(hass: HomeAssistantType):
"""Test we abort if the account is already setup."""
MockConfigEntry(
domain=DOMAIN,
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
unique_id=USERNAME,
).add_to_hass(hass)
# Should fail, same USERNAME (import)
... | [
"async",
"def",
"test_already_setup",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"CONF_USERNAME",
":",
"USERNAME",
",",
"CONF_PASSWORD",
":",
"PASSWORD",
"}",
",",
"unique_id",
"=",
... | [
247,
0
] | [
271,
51
] | python | en | ['en', 'en', 'en'] | True |
test_login_failed | (hass: HomeAssistantType) | Test when we have errors during login. | Test when we have errors during login. | async def test_login_failed(hass: HomeAssistantType):
"""Test when we have errors during login."""
with patch(
"homeassistant.components.icloud.config_flow.PyiCloudService.authenticate",
side_effect=PyiCloudFailedLoginException(),
):
result = await hass.config_entries.flow.async_init... | [
"async",
"def",
"test_login_failed",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.icloud.config_flow.PyiCloudService.authenticate\"",
",",
"side_effect",
"=",
"PyiCloudFailedLoginException",
"(",
")",
",",
")",
":",
"r... | [
274,
0
] | [
286,
66
] | python | en | ['en', 'en', 'en'] | True |
test_no_device | (
hass: HomeAssistantType, service_authenticated_no_device: MagicMock
) | Test when we have no devices. | Test when we have no devices. | async def test_no_device(
hass: HomeAssistantType, service_authenticated_no_device: MagicMock
):
"""Test when we have no devices."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
... | [
"async",
"def",
"test_no_device",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_authenticated_no_device",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"="... | [
289,
0
] | [
299,
42
] | python | en | ['en', 'en', 'en'] | True |
test_trusted_device | (hass: HomeAssistantType, service: MagicMock) | Test trusted_device step. | Test trusted_device step. | async def test_trusted_device(hass: HomeAssistantType, service: MagicMock):
"""Test trusted_device step."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
)
result = await hass... | [
"async",
"def",
"test_trusted_device",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"sourc... | [
302,
0
] | [
312,
51
] | python | en | ['en', 'en', 'en'] | True |
test_trusted_device_success | (hass: HomeAssistantType, service: MagicMock) | Test trusted_device step success. | Test trusted_device step success. | async def test_trusted_device_success(hass: HomeAssistantType, service: MagicMock):
"""Test trusted_device step success."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
)
res... | [
"async",
"def",
"test_trusted_device_success",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
... | [
315,
0
] | [
327,
54
] | python | en | ['en', 'en', 'en'] | True |
test_send_verification_code_failed | (
hass: HomeAssistantType, service_send_verification_code_failed: MagicMock
) | Test when we have errors during send_verification_code. | Test when we have errors during send_verification_code. | async def test_send_verification_code_failed(
hass: HomeAssistantType, service_send_verification_code_failed: MagicMock
):
"""Test when we have errors during send_verification_code."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={... | [
"async",
"def",
"test_send_verification_code_failed",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_send_verification_code_failed",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",... | [
330,
0
] | [
345,
78
] | python | en | ['en', 'en', 'en'] | True |
test_verification_code | (hass: HomeAssistantType, service: MagicMock) | Test verification_code step. | Test verification_code step. | async def test_verification_code(hass: HomeAssistantType, service: MagicMock):
"""Test verification_code step."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
)
result = await... | [
"async",
"def",
"test_verification_code",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"so... | [
348,
0
] | [
361,
54
] | python | en | ['en', 'sd', 'en'] | True |
test_verification_code_success | (hass: HomeAssistantType, service: MagicMock) | Test verification_code step success. | Test verification_code step success. | async def test_verification_code_success(hass: HomeAssistantType, service: MagicMock):
"""Test verification_code step success."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
data={CONF_USERNAME: USERNAME, CONF_PASSWORD: PASSWORD},
)
... | [
"async",
"def",
"test_verification_code_success",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",... | [
364,
0
] | [
386,
88
] | python | en | ['en', 'fr', 'en'] | True |
test_validate_verification_code_failed | (
hass: HomeAssistantType, service_validate_verification_code_failed: MagicMock
) | Test when we have errors during validate_verification_code. | Test when we have errors during validate_verification_code. | async def test_validate_verification_code_failed(
hass: HomeAssistantType, service_validate_verification_code_failed: MagicMock
):
"""Test when we have errors during validate_verification_code."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_USER},
... | [
"async",
"def",
"test_validate_verification_code_failed",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_validate_verification_code_failed",
":",
"MagicMock",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"... | [
389,
0
] | [
407,
69
] | python | en | ['en', 'en', 'en'] | True |
test_password_update | (
hass: HomeAssistantType, service_authenticated: MagicMock
) | Test that password reauthentication works successfully. | Test that password reauthentication works successfully. | async def test_password_update(
hass: HomeAssistantType, service_authenticated: MagicMock
):
"""Test that password reauthentication works successfully."""
config_entry = MockConfigEntry(
domain=DOMAIN, data=MOCK_CONFIG, entry_id="test", unique_id=USERNAME
)
config_entry.add_to_hass(hass)
... | [
"async",
"def",
"test_password_update",
"(",
"hass",
":",
"HomeAssistantType",
",",
"service_authenticated",
":",
"MagicMock",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"MOCK_CONFIG",
",",
"entry_id",
"=",
... | [
410,
0
] | [
433,
57
] | python | en | ['en', 'en', 'en'] | True |
test_password_update_wrong_password | (hass: HomeAssistantType) | Test that during password reauthentication wrong password returns correct error. | Test that during password reauthentication wrong password returns correct error. | async def test_password_update_wrong_password(hass: HomeAssistantType):
"""Test that during password reauthentication wrong password returns correct error."""
config_entry = MockConfigEntry(
domain=DOMAIN, data=MOCK_CONFIG, entry_id="test", unique_id=USERNAME
)
config_entry.add_to_hass(hass)
... | [
"async",
"def",
"test_password_update_wrong_password",
"(",
"hass",
":",
"HomeAssistantType",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"MOCK_CONFIG",
",",
"entry_id",
"=",
"\"test\"",
",",
"unique_id",
"=",
... | [
436,
0
] | [
460,
66
] | python | en | ['en', 'en', 'en'] | True |
test_reproducing_states | (hass, caplog) | Test reproducing Vacuum states. | Test reproducing Vacuum states. | async def test_reproducing_states(hass, caplog):
"""Test reproducing Vacuum states."""
hass.states.async_set("vacuum.entity_off", STATE_OFF, {})
hass.states.async_set("vacuum.entity_on", STATE_ON, {})
hass.states.async_set(
"vacuum.entity_on_fan", STATE_ON, {ATTR_FAN_SPEED: FAN_SPEED_LOW}
)
... | [
"async",
"def",
"test_reproducing_states",
"(",
"hass",
",",
"caplog",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"vacuum.entity_off\"",
",",
"STATE_OFF",
",",
"{",
"}",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"vacuum.entity_on\"",
... | [
28,
0
] | [
136,
5
] | python | de | ['de', 'la', 'en'] | False |
remote_fixture | () | Patch the samsungctl Remote. | Patch the samsungctl Remote. | def remote_fixture():
"""Patch the samsungctl Remote."""
with patch(
"homeassistant.components.samsungtv.bridge.Remote"
) as remote_class, patch(
"homeassistant.components.samsungtv.config_flow.socket"
) as socket1, patch(
"homeassistant.components.samsungtv.socket"
) as sock... | [
"def",
"remote_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.samsungtv.bridge.Remote\"",
")",
"as",
"remote_class",
",",
"patch",
"(",
"\"homeassistant.components.samsungtv.config_flow.socket\"",
")",
"as",
"socket1",
",",
"patch",
"(",
"\"hom... | [
42,
0
] | [
57,
20
] | python | en | ['en', 'en', 'en'] | True |
test_setup | (hass, remote) | Test Samsung TV integration is setup. | Test Samsung TV integration is setup. | async def test_setup(hass, remote):
"""Test Samsung TV integration is setup."""
with patch("homeassistant.components.samsungtv.bridge.Remote") as remote:
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
state = hass.states.get(ENTITY_ID)... | [
"async",
"def",
"test_setup",
"(",
"hass",
",",
"remote",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.samsungtv.bridge.Remote\"",
")",
"as",
"remote",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"SAMSUNGTV_DOMAIN",
",",
"MOCK_CONFIG",
")... | [
60,
0
] | [
79,
52
] | python | en | ['en', 'da', 'en'] | True |
test_setup_duplicate_config | (hass, remote, caplog) | Test duplicate setup of platform. | Test duplicate setup of platform. | async def test_setup_duplicate_config(hass, remote, caplog):
"""Test duplicate setup of platform."""
DUPLICATE = {
SAMSUNGTV_DOMAIN: [
MOCK_CONFIG[SAMSUNGTV_DOMAIN][0],
MOCK_CONFIG[SAMSUNGTV_DOMAIN][0],
]
}
await async_setup_component(hass, SAMSUNGTV_DOMAIN, DUPLI... | [
"async",
"def",
"test_setup_duplicate_config",
"(",
"hass",
",",
"remote",
",",
"caplog",
")",
":",
"DUPLICATE",
"=",
"{",
"SAMSUNGTV_DOMAIN",
":",
"[",
"MOCK_CONFIG",
"[",
"SAMSUNGTV_DOMAIN",
"]",
"[",
"0",
"]",
",",
"MOCK_CONFIG",
"[",
"SAMSUNGTV_DOMAIN",
"]... | [
82,
0
] | [
94,
56
] | python | en | ['en', 'da', 'en'] | True |
test_setup_duplicate_entries | (hass, remote, caplog) | Test duplicate setup of platform. | Test duplicate setup of platform. | async def test_setup_duplicate_entries(hass, remote, caplog):
"""Test duplicate setup of platform."""
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
await hass.async_block_till_done()
assert hass.states.get(ENTITY_ID)
assert len(hass.states.async_all()) == 1
await async_setup_c... | [
"async",
"def",
"test_setup_duplicate_entries",
"(",
"hass",
",",
"remote",
",",
"caplog",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"SAMSUNGTV_DOMAIN",
",",
"MOCK_CONFIG",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",... | [
97,
0
] | [
104,
44
] | python | en | ['en', 'da', 'en'] | True |
PortsParser.parse | (self, conf: dict, total_container: int) | Parse specified port configurations.
Args:
conf (dict): Configuration to parse.
total_container (int): Total container in current environment, used to calculate initial empty.
Returns:
(Dict[str, int], List[PortSetting]): Port mapping (name to index), list of port s... | Parse specified port configurations. | def parse(self, conf: dict, total_container: int) -> (Dict[str, int], List[PortSetting]):
"""Parse specified port configurations.
Args:
conf (dict): Configuration to parse.
total_container (int): Total container in current environment, used to calculate initial empty.
R... | [
"def",
"parse",
"(",
"self",
",",
"conf",
":",
"dict",
",",
"total_container",
":",
"int",
")",
"->",
"(",
"Dict",
"[",
"str",
",",
"int",
"]",
",",
"List",
"[",
"PortSetting",
"]",
")",
":",
"# sum of ratio cannot large than 1",
"total_ratio",
"=",
"sum... | [
12,
4
] | [
84,
44
] | python | en | ['en', 'en', 'en'] | True |
Device.__init__ | (self, igd_device) | Initialize UPnP/IGD device. | Initialize UPnP/IGD device. | def __init__(self, igd_device):
"""Initialize UPnP/IGD device."""
self._igd_device: IgdDevice = igd_device
self._mapped_ports = [] | [
"def",
"__init__",
"(",
"self",
",",
"igd_device",
")",
":",
"self",
".",
"_igd_device",
":",
"IgdDevice",
"=",
"igd_device",
"self",
".",
"_mapped_ports",
"=",
"[",
"]"
] | [
33,
4
] | [
36,
31
] | python | en | ['es', 'zu', 'en'] | False |
Device.async_discover | (cls, hass: HomeAssistantType) | Discover UPnP/IGD devices. | Discover UPnP/IGD devices. | async def async_discover(cls, hass: HomeAssistantType) -> List[Mapping]:
"""Discover UPnP/IGD devices."""
_LOGGER.debug("Discovering UPnP/IGD devices")
local_ip = None
if DOMAIN in hass.data and DOMAIN_CONFIG in hass.data[DOMAIN]:
local_ip = hass.data[DOMAIN][DOMAIN_CONFIG].g... | [
"async",
"def",
"async_discover",
"(",
"cls",
",",
"hass",
":",
"HomeAssistantType",
")",
"->",
"List",
"[",
"Mapping",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Discovering UPnP/IGD devices\"",
")",
"local_ip",
"=",
"None",
"if",
"DOMAIN",
"in",
"hass",
".... | [
39,
4
] | [
62,
22
] | python | en | ['es', 'en', 'en'] | True |
Device.async_create_device | (cls, hass: HomeAssistantType, ssdp_location: str) | Create UPnP/IGD device. | Create UPnP/IGD device. | async def async_create_device(cls, hass: HomeAssistantType, ssdp_location: str):
"""Create UPnP/IGD device."""
# build async_upnp_client requester
session = async_get_clientsession(hass)
requester = AiohttpSessionRequester(session, True, 10)
# create async_upnp_client device
... | [
"async",
"def",
"async_create_device",
"(",
"cls",
",",
"hass",
":",
"HomeAssistantType",
",",
"ssdp_location",
":",
"str",
")",
":",
"# build async_upnp_client requester",
"session",
"=",
"async_get_clientsession",
"(",
"hass",
")",
"requester",
"=",
"AiohttpSessionR... | [
65,
4
] | [
77,
30
] | python | bs | ['es', 'bs', 'en'] | False |
Device.udn | (self) | Get the UDN. | Get the UDN. | def udn(self) -> str:
"""Get the UDN."""
return self._igd_device.udn | [
"def",
"udn",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_igd_device",
".",
"udn"
] | [
80,
4
] | [
82,
35
] | python | en | ['en', 'en', 'en'] | True |
Device.name | (self) | Get the name. | Get the name. | def name(self) -> str:
"""Get the name."""
return self._igd_device.name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_igd_device",
".",
"name"
] | [
85,
4
] | [
87,
36
] | python | en | ['en', 'en', 'en'] | True |
Device.manufacturer | (self) | Get the manufacturer. | Get the manufacturer. | def manufacturer(self) -> str:
"""Get the manufacturer."""
return self._igd_device.manufacturer | [
"def",
"manufacturer",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_igd_device",
".",
"manufacturer"
] | [
90,
4
] | [
92,
44
] | python | en | ['en', 'da', 'en'] | True |
Device.model_name | (self) | Get the model name. | Get the model name. | def model_name(self) -> str:
"""Get the model name."""
return self._igd_device.model_name | [
"def",
"model_name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_igd_device",
".",
"model_name"
] | [
95,
4
] | [
97,
42
] | python | en | ['en', 'en', 'en'] | True |
Device.device_type | (self) | Get the device type. | Get the device type. | def device_type(self) -> str:
"""Get the device type."""
return self._igd_device.device_type | [
"def",
"device_type",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_igd_device",
".",
"device_type"
] | [
100,
4
] | [
102,
43
] | python | en | ['en', 'en', 'en'] | True |
Device.unique_id | (self) | Get the unique id. | Get the unique id. | def unique_id(self) -> str:
"""Get the unique id."""
return f"{self.udn}::{self.device_type}" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{self.udn}::{self.device_type}\""
] | [
105,
4
] | [
107,
48
] | python | en | ['en', 'la', 'en'] | True |
Device.__str__ | (self) | Get string representation. | Get string representation. | def __str__(self) -> str:
"""Get string representation."""
return f"IGD Device: {self.name}/{self.udn}" | [
"def",
"__str__",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"IGD Device: {self.name}/{self.udn}\""
] | [
109,
4
] | [
111,
52
] | python | en | ['en', 'kk', 'en'] | True |
Device.async_get_traffic_data | (self) |
Get all traffic data in one go.
Traffic data consists of:
- total bytes sent
- total bytes received
- total packets sent
- total packats received
Data is timestamped.
|
Get all traffic data in one go. | async def async_get_traffic_data(self) -> Mapping[str, any]:
"""
Get all traffic data in one go.
Traffic data consists of:
- total bytes sent
- total bytes received
- total packets sent
- total packats received
Data is timestamped.
"""
_L... | [
"async",
"def",
"async_get_traffic_data",
"(",
"self",
")",
"->",
"Mapping",
"[",
"str",
",",
"any",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Getting traffic statistics from device: %s\"",
",",
"self",
")",
"values",
"=",
"await",
"asyncio",
".",
"gather",
"... | [
113,
4
] | [
140,
9
] | python | en | ['en', 'error', 'th'] | False |
torch_pad_and_concatenate | (tensor1, tensor2, padding_index=-100) | Concatenates `tensor1` and `tensor2` on first axis, applying padding on the second if necessary. | Concatenates `tensor1` and `tensor2` on first axis, applying padding on the second if necessary. | def torch_pad_and_concatenate(tensor1, tensor2, padding_index=-100):
"""Concatenates `tensor1` and `tensor2` on first axis, applying padding on the second if necessary."""
if len(tensor1.shape) == 1 or tensor1.shape[1] == tensor2.shape[1]:
return torch.cat((tensor1, tensor2), dim=0)
# Let's figure ... | [
"def",
"torch_pad_and_concatenate",
"(",
"tensor1",
",",
"tensor2",
",",
"padding_index",
"=",
"-",
"100",
")",
":",
"if",
"len",
"(",
"tensor1",
".",
"shape",
")",
"==",
"1",
"or",
"tensor1",
".",
"shape",
"[",
"1",
"]",
"==",
"tensor2",
".",
"shape",... | [
56,
0
] | [
68,
17
] | python | en | ['en', 'en', 'en'] | True |
numpy_pad_and_concatenate | (array1, array2, padding_index=-100) | Concatenates `array1` and `array2` on first axis, applying padding on the second if necessary. | Concatenates `array1` and `array2` on first axis, applying padding on the second if necessary. | def numpy_pad_and_concatenate(array1, array2, padding_index=-100):
"""Concatenates `array1` and `array2` on first axis, applying padding on the second if necessary."""
if len(array1.shape) == 1 or array1.shape[1] == array2.shape[1]:
return np.concatenate((array1, array2), dim=0)
# Let's figure out ... | [
"def",
"numpy_pad_and_concatenate",
"(",
"array1",
",",
"array2",
",",
"padding_index",
"=",
"-",
"100",
")",
":",
"if",
"len",
"(",
"array1",
".",
"shape",
")",
"==",
"1",
"or",
"array1",
".",
"shape",
"[",
"1",
"]",
"==",
"array2",
".",
"shape",
"[... | [
71,
0
] | [
83,
17
] | python | en | ['en', 'en', 'en'] | True |
nested_concat | (tensors, new_tensors, padding_index=-100) |
Concat the `new_tensors` to `tensors` on the first dim and pad them on the second if needed. Works for tensors or
nested list/tuples of tensors.
|
Concat the `new_tensors` to `tensors` on the first dim and pad them on the second if needed. Works for tensors or
nested list/tuples of tensors.
| def nested_concat(tensors, new_tensors, padding_index=-100):
"""
Concat the `new_tensors` to `tensors` on the first dim and pad them on the second if needed. Works for tensors or
nested list/tuples of tensors.
"""
assert type(tensors) == type(
new_tensors
), f"Expected `tensors` and `new... | [
"def",
"nested_concat",
"(",
"tensors",
",",
"new_tensors",
",",
"padding_index",
"=",
"-",
"100",
")",
":",
"assert",
"type",
"(",
"tensors",
")",
"==",
"type",
"(",
"new_tensors",
")",
",",
"f\"Expected `tensors` and `new_tensors` to have the same type but found {ty... | [
86,
0
] | [
101,
83
] | python | en | ['en', 'error', 'th'] | False |
nested_numpify | (tensors) | Numpify `tensors` (even if it's a nested list/tuple of tensors). | Numpify `tensors` (even if it's a nested list/tuple of tensors). | def nested_numpify(tensors):
"Numpify `tensors` (even if it's a nested list/tuple of tensors)."
if isinstance(tensors, (list, tuple)):
return type(tensors)(nested_numpify(t) for t in tensors)
return tensors.cpu().numpy() | [
"def",
"nested_numpify",
"(",
"tensors",
")",
":",
"if",
"isinstance",
"(",
"tensors",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"tensors",
")",
"(",
"nested_numpify",
"(",
"t",
")",
"for",
"t",
"in",
"tensors",
")",
"retu... | [
104,
0
] | [
108,
32
] | python | en | ['en', 'en', 'en'] | True |
nested_detach | (tensors) | Detach `tensors` (even if it's a nested list/tuple of tensors). | Detach `tensors` (even if it's a nested list/tuple of tensors). | def nested_detach(tensors):
"Detach `tensors` (even if it's a nested list/tuple of tensors)."
if isinstance(tensors, (list, tuple)):
return type(tensors)(nested_detach(t) for t in tensors)
return tensors.detach() | [
"def",
"nested_detach",
"(",
"tensors",
")",
":",
"if",
"isinstance",
"(",
"tensors",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"tensors",
")",
"(",
"nested_detach",
"(",
"t",
")",
"for",
"t",
"in",
"tensors",
")",
"return... | [
111,
0
] | [
115,
27
] | python | en | ['en', 'en', 'en'] | True |
torch_distributed_zero_first | (local_rank: int) |
Decorator to make all processes in distributed training wait for each local_master to do something.
Args:
local_rank (:obj:`int`): The rank of the local process.
|
Decorator to make all processes in distributed training wait for each local_master to do something. | def torch_distributed_zero_first(local_rank: int):
"""
Decorator to make all processes in distributed training wait for each local_master to do something.
Args:
local_rank (:obj:`int`): The rank of the local process.
"""
if local_rank not in [-1, 0]:
dist.barrier()
yield
if ... | [
"def",
"torch_distributed_zero_first",
"(",
"local_rank",
":",
"int",
")",
":",
"if",
"local_rank",
"not",
"in",
"[",
"-",
"1",
",",
"0",
"]",
":",
"dist",
".",
"barrier",
"(",
")",
"yield",
"if",
"local_rank",
"==",
"0",
":",
"dist",
".",
"barrier",
... | [
171,
0
] | [
182,
22
] | python | en | ['en', 'error', 'th'] | False |
nested_new_like | (arrays, num_samples, padding_index=-100) | Create the same nested structure as `arrays` with a first dimension always at `num_samples`. | Create the same nested structure as `arrays` with a first dimension always at `num_samples`. | def nested_new_like(arrays, num_samples, padding_index=-100):
""" Create the same nested structure as `arrays` with a first dimension always at `num_samples`."""
if isinstance(arrays, (list, tuple)):
return type(arrays)(nested_new_like(x, num_samples) for x in arrays)
return np.full_like(arrays, pad... | [
"def",
"nested_new_like",
"(",
"arrays",
",",
"num_samples",
",",
"padding_index",
"=",
"-",
"100",
")",
":",
"if",
"isinstance",
"(",
"arrays",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"arrays",
")",
"(",
"nested_new_like",
... | [
271,
0
] | [
275,
86
] | python | en | ['en', 'en', 'en'] | True |
nested_expand_like | (arrays, new_seq_length, padding_index=-100) | Expand the `arrays` so that the second dimension grows to `new_seq_length`. Uses `padding_index` for padding. | Expand the `arrays` so that the second dimension grows to `new_seq_length`. Uses `padding_index` for padding. | def nested_expand_like(arrays, new_seq_length, padding_index=-100):
""" Expand the `arrays` so that the second dimension grows to `new_seq_length`. Uses `padding_index` for padding."""
if isinstance(arrays, (list, tuple)):
return type(arrays)(nested_expand_like(x, new_seq_length, padding_index=padding_i... | [
"def",
"nested_expand_like",
"(",
"arrays",
",",
"new_seq_length",
",",
"padding_index",
"=",
"-",
"100",
")",
":",
"if",
"isinstance",
"(",
"arrays",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"arrays",
")",
"(",
"nested_expan... | [
278,
0
] | [
285,
17
] | python | en | ['en', 'en', 'en'] | True |
nested_truncate | (tensors, limit) | Truncate `tensors` at `limit` (even if it's a nested list/tuple of tensors). | Truncate `tensors` at `limit` (even if it's a nested list/tuple of tensors). | def nested_truncate(tensors, limit):
"Truncate `tensors` at `limit` (even if it's a nested list/tuple of tensors)."
if isinstance(tensors, (list, tuple)):
return type(tensors)(nested_truncate(t, limit) for t in tensors)
return tensors[:limit] | [
"def",
"nested_truncate",
"(",
"tensors",
",",
"limit",
")",
":",
"if",
"isinstance",
"(",
"tensors",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"type",
"(",
"tensors",
")",
"(",
"nested_truncate",
"(",
"t",
",",
"limit",
")",
"for",
"t... | [
288,
0
] | [
292,
26
] | python | en | ['en', 'en', 'en'] | True |
_get_first_shape | (arrays) | Return the shape of the first array found in the nested struct `arrays`. | Return the shape of the first array found in the nested struct `arrays`. | def _get_first_shape(arrays):
"""Return the shape of the first array found in the nested struct `arrays`."""
if isinstance(arrays, (list, tuple)):
return _get_first_shape(arrays[0])
return arrays.shape | [
"def",
"_get_first_shape",
"(",
"arrays",
")",
":",
"if",
"isinstance",
"(",
"arrays",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"return",
"_get_first_shape",
"(",
"arrays",
"[",
"0",
"]",
")",
"return",
"arrays",
".",
"shape"
] | [
295,
0
] | [
299,
23
] | python | en | ['en', 'en', 'en'] | True |
get_length_grouped_indices | (lengths, batch_size, mega_batch_mult=None, generator=None) |
Return a list of indices so that each slice of :obj:`batch_size` consecutive indices correspond to elements of
similar lengths. To do this, the indices are:
- randomly permuted
- grouped in mega-batches of size :obj:`mega_batch_mult * batch_size`
- sorted by length in each mega-batch
The resu... |
Return a list of indices so that each slice of :obj:`batch_size` consecutive indices correspond to elements of
similar lengths. To do this, the indices are: | def get_length_grouped_indices(lengths, batch_size, mega_batch_mult=None, generator=None):
"""
Return a list of indices so that each slice of :obj:`batch_size` consecutive indices correspond to elements of
similar lengths. To do this, the indices are:
- randomly permuted
- grouped in mega-batches o... | [
"def",
"get_length_grouped_indices",
"(",
"lengths",
",",
"batch_size",
",",
"mega_batch_mult",
"=",
"None",
",",
"generator",
"=",
"None",
")",
":",
"# Default for mega_batch_mult: 50 or the number to get 4 megabatches, whichever is smaller.",
"if",
"mega_batch_mult",
"is",
... | [
449,
0
] | [
481,
31
] | python | en | ['en', 'error', 'th'] | False |
_secs2timedelta | (secs) |
convert seconds to hh:mm:ss.msec, msecs rounded to 2 decimals
|
convert seconds to hh:mm:ss.msec, msecs rounded to 2 decimals
| def _secs2timedelta(secs):
"""
convert seconds to hh:mm:ss.msec, msecs rounded to 2 decimals
"""
msec = int(abs(secs - int(secs)) * 100)
return f"{datetime.timedelta(seconds=int(secs))}.{msec:02d}" | [
"def",
"_secs2timedelta",
"(",
"secs",
")",
":",
"msec",
"=",
"int",
"(",
"abs",
"(",
"secs",
"-",
"int",
"(",
"secs",
")",
")",
"*",
"100",
")",
"return",
"f\"{datetime.timedelta(seconds=int(secs))}.{msec:02d}\""
] | [
618,
0
] | [
624,
64
] | python | en | ['en', 'error', 'th'] | False |
metrics_format | (self, metrics: Dict[str, float]) |
Reformat Trainer metrics values to a human-readable format
Args:
metrics (:obj:`Dict[str, float]`):
The metrics returned from train/evaluate/predict
Returns:
metrics (:obj:`Dict[str, float]`): The reformatted metrics
|
Reformat Trainer metrics values to a human-readable format | def metrics_format(self, metrics: Dict[str, float]) -> Dict[str, float]:
"""
Reformat Trainer metrics values to a human-readable format
Args:
metrics (:obj:`Dict[str, float]`):
The metrics returned from train/evaluate/predict
Returns:
metrics (:obj:`Dict[str, float]`): The ... | [
"def",
"metrics_format",
"(",
"self",
",",
"metrics",
":",
"Dict",
"[",
"str",
",",
"float",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"float",
"]",
":",
"metrics_copy",
"=",
"metrics",
".",
"copy",
"(",
")",
"for",
"k",
",",
"v",
"in",
"metrics_cop... | [
627,
0
] | [
650,
23
] | python | en | ['en', 'error', 'th'] | False |
log_metrics | (self, split, metrics) |
Log metrics in a specially formatted way
Under distributed environment this is done only for a process with rank 0.
Args:
split (:obj:`str`):
Mode/split name: one of ``train``, ``eval``, ``test``
metrics (:obj:`Dict[str, float]`):
The metrics returned from train/ev... |
Log metrics in a specially formatted way | def log_metrics(self, split, metrics):
"""
Log metrics in a specially formatted way
Under distributed environment this is done only for a process with rank 0.
Args:
split (:obj:`str`):
Mode/split name: one of ``train``, ``eval``, ``test``
metrics (:obj:`Dict[str, float]`):
... | [
"def",
"log_metrics",
"(",
"self",
",",
"split",
",",
"metrics",
")",
":",
"if",
"not",
"self",
".",
"is_world_process_zero",
"(",
")",
":",
"return",
"logger",
".",
"info",
"(",
"f\"***** {split} metrics *****\"",
")",
"metrics_formatted",
"=",
"self",
".",
... | [
653,
0
] | [
739,
81
] | python | en | ['en', 'error', 'th'] | False |
save_metrics | (self, split, metrics, combined=True) |
Save metrics into a json file for that split, e.g. ``train_results.json``.
Under distributed environment this is done only for a process with rank 0.
Args:
split (:obj:`str`):
Mode/split name: one of ``train``, ``eval``, ``test``, ``all``
metrics (:obj:`Dict[str, float]`):
... |
Save metrics into a json file for that split, e.g. ``train_results.json``. | def save_metrics(self, split, metrics, combined=True):
"""
Save metrics into a json file for that split, e.g. ``train_results.json``.
Under distributed environment this is done only for a process with rank 0.
Args:
split (:obj:`str`):
Mode/split name: one of ``train``, ``eval``, ``... | [
"def",
"save_metrics",
"(",
"self",
",",
"split",
",",
"metrics",
",",
"combined",
"=",
"True",
")",
":",
"if",
"not",
"self",
".",
"is_world_process_zero",
"(",
")",
":",
"return",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"args... | [
742,
0
] | [
777,
63
] | python | en | ['en', 'error', 'th'] | False |
save_state | (self) |
Saves the Trainer state, since Trainer.save_model saves only the tokenizer with the model
Under distributed environment this is done only for a process with rank 0.
|
Saves the Trainer state, since Trainer.save_model saves only the tokenizer with the model | def save_state(self):
"""
Saves the Trainer state, since Trainer.save_model saves only the tokenizer with the model
Under distributed environment this is done only for a process with rank 0.
"""
if not self.is_world_process_zero():
return
path = os.path.join(self.args.output_dir, "trai... | [
"def",
"save_state",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_world_process_zero",
"(",
")",
":",
"return",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"args",
".",
"output_dir",
",",
"\"trainer_state.json\"",
")",
"self",
... | [
780,
0
] | [
790,
33
] | python | en | ['en', 'error', 'th'] | False |
get_parameter_names | (model, forbidden_layer_types) |
Returns the names of the model parameters that are not inside a forbidden layer.
|
Returns the names of the model parameters that are not inside a forbidden layer.
| def get_parameter_names(model, forbidden_layer_types):
"""
Returns the names of the model parameters that are not inside a forbidden layer.
"""
result = []
for name, child in model.named_children():
result += [
f"{name}.{n}"
for n in get_parameter_names(child, forbidd... | [
"def",
"get_parameter_names",
"(",
"model",
",",
"forbidden_layer_types",
")",
":",
"result",
"=",
"[",
"]",
"for",
"name",
",",
"child",
"in",
"model",
".",
"named_children",
"(",
")",
":",
"result",
"+=",
"[",
"f\"{name}.{n}\"",
"for",
"n",
"in",
"get_pa... | [
793,
0
] | [
806,
17
] | python | en | ['en', 'error', 'th'] | False |
DistributedTensorGatherer.add_arrays | (self, arrays) |
Add :obj:`arrays` to the internal storage, Will initialize the storage to the full size at the first arrays
passed so that if we're bound to get an OOM, it happens at the beginning.
|
Add :obj:`arrays` to the internal storage, Will initialize the storage to the full size at the first arrays
passed so that if we're bound to get an OOM, it happens at the beginning.
| def add_arrays(self, arrays):
"""
Add :obj:`arrays` to the internal storage, Will initialize the storage to the full size at the first arrays
passed so that if we're bound to get an OOM, it happens at the beginning.
"""
if arrays is None:
return
if self._stora... | [
"def",
"add_arrays",
"(",
"self",
",",
"arrays",
")",
":",
"if",
"arrays",
"is",
"None",
":",
"return",
"if",
"self",
".",
"_storage",
"is",
"None",
":",
"self",
".",
"_storage",
"=",
"nested_new_like",
"(",
"arrays",
",",
"self",
".",
"total_samples",
... | [
359,
4
] | [
377,
41
] | python | en | ['en', 'error', 'th'] | False |
DistributedTensorGatherer.finalize | (self) |
Return the properly gathered arrays and truncate to the number of samples (since the sampler added some extras
to get each process a dataset of the same length).
|
Return the properly gathered arrays and truncate to the number of samples (since the sampler added some extras
to get each process a dataset of the same length).
| def finalize(self):
"""
Return the properly gathered arrays and truncate to the number of samples (since the sampler added some extras
to get each process a dataset of the same length).
"""
if self._storage is None:
return
if self._offsets[0] != self.process_l... | [
"def",
"finalize",
"(",
"self",
")",
":",
"if",
"self",
".",
"_storage",
"is",
"None",
":",
"return",
"if",
"self",
".",
"_offsets",
"[",
"0",
"]",
"!=",
"self",
".",
"process_length",
":",
"logger",
".",
"warn",
"(",
"\"Not all data has been set. Are you ... | [
398,
4
] | [
407,
63
] | python | en | ['en', 'error', 'th'] | False |
async_setup_entry | (
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
) | Set up Spotify based on a config entry. | Set up Spotify based on a config entry. | async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
) -> None:
"""Set up Spotify based on a config entry."""
spotify = SpotifyMediaPlayer(
hass.data[DOMAIN][entry.entry_id][DATA_SPOTIFY_SESSION],
hass.data[DO... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
",",
"async_add_entities",
":",
"Callable",
"[",
"[",
"List",
"[",
"Entity",
"]",
",",
"bool",
"]",
",",
"None",
"]",
",",
")",
"->",
"None",
":",
... | [
169,
0
] | [
182,
39
] | python | en | ['en', 'en', 'en'] | True |
spotify_exception_handler | (func) | Decorate Spotify calls to handle Spotify exception.
A decorator that wraps the passed in function, catches Spotify errors,
aiohttp exceptions and handles the availability of the media player.
| Decorate Spotify calls to handle Spotify exception. | def spotify_exception_handler(func):
"""Decorate Spotify calls to handle Spotify exception.
A decorator that wraps the passed in function, catches Spotify errors,
aiohttp exceptions and handles the availability of the media player.
"""
def wrapper(self, *args, **kwargs):
try:
r... | [
"def",
"spotify_exception_handler",
"(",
"func",
")",
":",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"result",
"=",
"func",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
... | [
185,
0
] | [
200,
18
] | python | en | ['en', 'en', 'en'] | True |
build_item_response | (spotify, user, payload) | Create response payload for the provided media query. | Create response payload for the provided media query. | def build_item_response(spotify, user, payload):
"""Create response payload for the provided media query."""
media_content_type = payload["media_content_type"]
media_content_id = payload["media_content_id"]
title = None
image = None
if media_content_type == "current_user_playlists":
medi... | [
"def",
"build_item_response",
"(",
"spotify",
",",
"user",
",",
"payload",
")",
":",
"media_content_type",
"=",
"payload",
"[",
"\"media_content_type\"",
"]",
"media_content_id",
"=",
"payload",
"[",
"\"media_content_id\"",
"]",
"title",
"=",
"None",
"image",
"=",... | [
500,
0
] | [
638,
32
] | python | en | ['en', 'en', 'en'] | True |
item_payload | (item) |
Create response payload for a single media item.
Used by async_browse_media.
|
Create response payload for a single media item. | def item_payload(item):
"""
Create response payload for a single media item.
Used by async_browse_media.
"""
try:
media_type = item["type"]
media_id = item["uri"]
except KeyError as err:
_LOGGER.debug("Missing type or uri for media item: %s", item)
raise MissingM... | [
"def",
"item_payload",
"(",
"item",
")",
":",
"try",
":",
"media_type",
"=",
"item",
"[",
"\"type\"",
"]",
"media_id",
"=",
"item",
"[",
"\"uri\"",
"]",
"except",
"KeyError",
"as",
"err",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Missing type or uri for media it... | [
641,
0
] | [
680,
33
] | python | en | ['en', 'error', 'th'] | False |
library_payload | () |
Create response payload to describe contents of a specific library.
Used by async_browse_media.
|
Create response payload to describe contents of a specific library. | def library_payload():
"""
Create response payload to describe contents of a specific library.
Used by async_browse_media.
"""
library_info = {
"title": "Media Library",
"media_class": MEDIA_CLASS_DIRECTORY,
"media_content_id": "library",
"media_content_type": "libra... | [
"def",
"library_payload",
"(",
")",
":",
"library_info",
"=",
"{",
"\"title\"",
":",
"\"Media Library\"",
",",
"\"media_class\"",
":",
"MEDIA_CLASS_DIRECTORY",
",",
"\"media_content_id\"",
":",
"\"library\"",
",",
"\"media_content_type\"",
":",
"\"library\"",
",",
"\"... | [
683,
0
] | [
707,
19
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.