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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
async_get_service | (hass, config, discovery_info=None) | Set up the Slack notification service. | Set up the Slack notification service. | async def async_get_service(hass, config, discovery_info=None):
"""Set up the Slack notification service."""
session = aiohttp_client.async_get_clientsession(hass)
client = WebClient(token=config[CONF_API_KEY], run_async=True, session=session)
try:
await client.auth_test()
except SlackApiEr... | [
"async",
"def",
"async_get_service",
"(",
"hass",
",",
"config",
",",
"discovery_info",
"=",
"None",
")",
":",
"session",
"=",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
"hass",
")",
"client",
"=",
"WebClient",
"(",
"token",
"=",
"config",
"[",
"... | [
76,
0
] | [
93,
5
] | python | en | ['en', 'cs', 'en'] | True |
_async_get_filename_from_url | (url) | Return the filename of a passed URL. | Return the filename of a passed URL. | def _async_get_filename_from_url(url):
"""Return the filename of a passed URL."""
parsed_url = urlparse(url)
return os.path.basename(parsed_url.path) | [
"def",
"_async_get_filename_from_url",
"(",
"url",
")",
":",
"parsed_url",
"=",
"urlparse",
"(",
"url",
")",
"return",
"os",
".",
"path",
".",
"basename",
"(",
"parsed_url",
".",
"path",
")"
] | [
97,
0
] | [
100,
44
] | python | en | ['en', 'en', 'en'] | True |
_async_sanitize_channel_names | (channel_list) | Remove any # symbols from a channel list. | Remove any # symbols from a channel list. | def _async_sanitize_channel_names(channel_list):
"""Remove any # symbols from a channel list."""
return [channel.lstrip("#") for channel in channel_list] | [
"def",
"_async_sanitize_channel_names",
"(",
"channel_list",
")",
":",
"return",
"[",
"channel",
".",
"lstrip",
"(",
"\"#\"",
")",
"for",
"channel",
"in",
"channel_list",
"]"
] | [
104,
0
] | [
106,
60
] | python | en | ['en', 'en', 'en'] | True |
_async_templatize_blocks | (hass, value) | Recursive template creator helper function. | Recursive template creator helper function. | def _async_templatize_blocks(hass, value):
"""Recursive template creator helper function."""
if isinstance(value, list):
return [_async_templatize_blocks(hass, item) for item in value]
if isinstance(value, dict):
return {
key: _async_templatize_blocks(hass, item) for key, item in... | [
"def",
"_async_templatize_blocks",
"(",
"hass",
",",
"value",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"return",
"[",
"_async_templatize_blocks",
"(",
"hass",
",",
"item",
")",
"for",
"item",
"in",
"value",
"]",
"if",
"isinstance"... | [
110,
0
] | [
120,
48
] | python | en | ['en', 'nl', 'en'] | True |
SlackNotificationService.__init__ | (self, hass, client, default_channel, username, icon) | Initialize. | Initialize. | def __init__(self, hass, client, default_channel, username, icon):
"""Initialize."""
self._client = client
self._default_channel = default_channel
self._hass = hass
self._icon = icon
self._username = username | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"client",
",",
"default_channel",
",",
"username",
",",
"icon",
")",
":",
"self",
".",
"_client",
"=",
"client",
"self",
".",
"_default_channel",
"=",
"default_channel",
"self",
".",
"_hass",
"=",
"hass",
... | [
126,
4
] | [
132,
33
] | python | en | ['en', 'en', 'it'] | False |
SlackNotificationService._async_send_local_file_message | (self, path, targets, message, title) | Upload a local file (with message) to Slack. | Upload a local file (with message) to Slack. | async def _async_send_local_file_message(self, path, targets, message, title):
"""Upload a local file (with message) to Slack."""
if not self._hass.config.is_allowed_path(path):
_LOGGER.error("Path does not exist or is not allowed: %s", path)
return
parsed_url = urlparse... | [
"async",
"def",
"_async_send_local_file_message",
"(",
"self",
",",
"path",
",",
"targets",
",",
"message",
",",
"title",
")",
":",
"if",
"not",
"self",
".",
"_hass",
".",
"config",
".",
"is_allowed_path",
"(",
"path",
")",
":",
"_LOGGER",
".",
"error",
... | [
134,
4
] | [
152,
78
] | python | en | ['en', 'en', 'en'] | True |
SlackNotificationService._async_send_remote_file_message | (
self, url, targets, message, title, *, username=None, password=None
) | Upload a remote file (with message) to Slack.
Note that we bypass the python-slackclient WebClient and use aiohttp directly,
as the former would require us to download the entire remote file into memory
first before uploading it to Slack.
| Upload a remote file (with message) to Slack. | async def _async_send_remote_file_message(
self, url, targets, message, title, *, username=None, password=None
):
"""Upload a remote file (with message) to Slack.
Note that we bypass the python-slackclient WebClient and use aiohttp directly,
as the former would require us to downloa... | [
"async",
"def",
"_async_send_remote_file_message",
"(",
"self",
",",
"url",
",",
"targets",
",",
"message",
",",
"title",
",",
"*",
",",
"username",
"=",
"None",
",",
"password",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_hass",
".",
"config",
... | [
154,
4
] | [
197,
72
] | python | en | ['en', 'en', 'en'] | True |
SlackNotificationService._async_send_text_only_message | (
self, targets, message, title, blocks, username, icon
) | Send a text-only message. | Send a text-only message. | async def _async_send_text_only_message(
self, targets, message, title, blocks, username, icon
):
"""Send a text-only message."""
message_dict = {
"blocks": blocks,
"link_names": True,
"text": message,
"username": username,
}
i... | [
"async",
"def",
"_async_send_text_only_message",
"(",
"self",
",",
"targets",
",",
"message",
",",
"title",
",",
"blocks",
",",
"username",
",",
"icon",
")",
":",
"message_dict",
"=",
"{",
"\"blocks\"",
":",
"blocks",
",",
"\"link_names\"",
":",
"True",
",",... | [
199,
4
] | [
231,
17
] | python | en | ['en', 'en', 'en'] | True |
SlackNotificationService.async_send_message | (self, message, **kwargs) | Send a message to Slack. | Send a message to Slack. | async def async_send_message(self, message, **kwargs):
"""Send a message to Slack."""
data = kwargs.get(ATTR_DATA)
if data is None:
data = {}
try:
DATA_SCHEMA(data)
except vol.Invalid as err:
_LOGGER.error("Invalid message data: %s", err)
... | [
"async",
"def",
"async_send_message",
"(",
"self",
",",
"message",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_DATA",
")",
"if",
"data",
"is",
"None",
":",
"data",
"=",
"{",
"}",
"try",
":",
"DATA_SCHEMA",
"(",
... | [
233,
4
] | [
283,
9
] | python | en | ['en', 'fr', 'en'] | True |
due_in_minutes | (timestamp: datetime) | Get the time in minutes from a timestamp. | Get the time in minutes from a timestamp. | def due_in_minutes(timestamp: datetime) -> int:
"""Get the time in minutes from a timestamp."""
if timestamp is None:
return None
diff = timestamp - dt_util.now()
return int(diff.total_seconds() / 60) | [
"def",
"due_in_minutes",
"(",
"timestamp",
":",
"datetime",
")",
"->",
"int",
":",
"if",
"timestamp",
"is",
"None",
":",
"return",
"None",
"diff",
"=",
"timestamp",
"-",
"dt_util",
".",
"now",
"(",
")",
"return",
"int",
"(",
"diff",
".",
"total_seconds",... | [
78,
0
] | [
83,
41
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Entur public transport sensor. | Set up the Entur public transport sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Entur public transport sensor."""
expand = config.get(CONF_EXPAND_PLATFORMS)
line_whitelist = config.get(CONF_WHITELIST_LINES)
name = config.get(CONF_NAME)
show_on_map = config.get(CONF_SHOW_ON_MAP)... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"expand",
"=",
"config",
".",
"get",
"(",
"CONF_EXPAND_PLATFORMS",
")",
"line_whitelist",
"=",
"config",
".",
"get",
"(... | [
86,
0
] | [
127,
38
] | python | en | ['en', 'fr', 'en'] | True |
EnturProxy.__init__ | (self, api) | Initialize the proxy. | Initialize the proxy. | def __init__(self, api):
"""Initialize the proxy."""
self._api = api | [
"def",
"__init__",
"(",
"self",
",",
"api",
")",
":",
"self",
".",
"_api",
"=",
"api"
] | [
136,
4
] | [
138,
23
] | python | en | ['en', 'en', 'en'] | True |
EnturProxy.async_update | (self) | Update data in client. | Update data in client. | async def async_update(self) -> None:
"""Update data in client."""
await self._api.update() | [
"async",
"def",
"async_update",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"_api",
".",
"update",
"(",
")"
] | [
141,
4
] | [
143,
32
] | python | co | ['it', 'co', 'en'] | False |
EnturProxy.get_stop_info | (self, stop_id: str) | Get info about specific stop place. | Get info about specific stop place. | def get_stop_info(self, stop_id: str) -> dict:
"""Get info about specific stop place."""
return self._api.get_stop_info(stop_id) | [
"def",
"get_stop_info",
"(",
"self",
",",
"stop_id",
":",
"str",
")",
"->",
"dict",
":",
"return",
"self",
".",
"_api",
".",
"get_stop_info",
"(",
"stop_id",
")"
] | [
145,
4
] | [
147,
47
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.__init__ | (self, api: EnturProxy, name: str, stop: str, show_on_map: bool) | Initialize the sensor. | Initialize the sensor. | def __init__(self, api: EnturProxy, name: str, stop: str, show_on_map: bool):
"""Initialize the sensor."""
self.api = api
self._stop = stop
self._show_on_map = show_on_map
self._name = name
self._state = None
self._icon = ICONS[DEFAULT_ICON_KEY]
self._attr... | [
"def",
"__init__",
"(",
"self",
",",
"api",
":",
"EnturProxy",
",",
"name",
":",
"str",
",",
"stop",
":",
"str",
",",
"show_on_map",
":",
"bool",
")",
":",
"self",
".",
"api",
"=",
"api",
"self",
".",
"_stop",
"=",
"stop",
"self",
".",
"_show_on_ma... | [
153,
4
] | [
161,
29
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self) -> str:
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] | [
164,
4
] | [
166,
25
] | python | en | ['en', 'mi', 'en'] | True |
EnturPublicTransportSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self) -> str:
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_state"
] | [
169,
4
] | [
171,
26
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self) -> dict:
"""Return the state attributes."""
self._attributes[ATTR_ATTRIBUTION] = ATTRIBUTION
self._attributes[ATTR_STOP_ID] = self._stop
return self._attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"dict",
":",
"self",
".",
"_attributes",
"[",
"ATTR_ATTRIBUTION",
"]",
"=",
"ATTRIBUTION",
"self",
".",
"_attributes",
"[",
"ATTR_STOP_ID",
"]",
"=",
"self",
".",
"_stop",
"return",
"self",
".",
"_att... | [
174,
4
] | [
178,
31
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.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) -> str:
"""Return the unit this state is expressed in."""
return TIME_MINUTES | [
"def",
"unit_of_measurement",
"(",
"self",
")",
"->",
"str",
":",
"return",
"TIME_MINUTES"
] | [
181,
4
] | [
183,
27
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.icon | (self) | Icon to use in the frontend. | Icon to use in the frontend. | def icon(self) -> str:
"""Icon to use in the frontend."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_icon"
] | [
186,
4
] | [
188,
25
] | python | en | ['en', 'en', 'en'] | True |
EnturPublicTransportSensor.async_update | (self) | Get the latest data and update the states. | Get the latest data and update the states. | async def async_update(self) -> None:
"""Get the latest data and update the states."""
await self.api.async_update()
self._attributes = {}
data = self.api.get_stop_info(self._stop)
if data is None:
self._state = None
return
if self._show_on_map ... | [
"async",
"def",
"async_update",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"api",
".",
"async_update",
"(",
")",
"self",
".",
"_attributes",
"=",
"{",
"}",
"data",
"=",
"self",
".",
"api",
".",
"get_stop_info",
"(",
"self",
".",
"_sto... | [
190,
4
] | [
244,
13
] | python | en | ['en', 'en', 'en'] | True |
smhi_locations | (hass: HomeAssistant) | Return configurations of SMHI component. | Return configurations of SMHI component. | def smhi_locations(hass: HomeAssistant):
"""Return configurations of SMHI component."""
return {
(slugify(entry.data[CONF_NAME]))
for entry in hass.config_entries.async_entries(DOMAIN)
} | [
"def",
"smhi_locations",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"return",
"{",
"(",
"slugify",
"(",
"entry",
".",
"data",
"[",
"CONF_NAME",
"]",
")",
")",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")"... | [
15,
0
] | [
20,
5
] | python | en | ['en', 'en', 'en'] | True |
remove_devices | (bridge, api_ids, current) | Get items that are removed from api. | Get items that are removed from api. | async def remove_devices(bridge, api_ids, current):
"""Get items that are removed from api."""
removed_items = []
for item_id in current:
if item_id in api_ids:
continue
# Device is removed from Hue, so we remove it from Home Assistant
entity = current[item_id]
... | [
"async",
"def",
"remove_devices",
"(",
"bridge",
",",
"api_ids",
",",
"current",
")",
":",
"removed_items",
"=",
"[",
"]",
"for",
"item_id",
"in",
"current",
":",
"if",
"item_id",
"in",
"api_ids",
":",
"continue",
"# Device is removed from Hue, so we remove it fro... | [
8,
0
] | [
33,
28
] | python | en | ['en', 'en', 'en'] | True |
create_config_flow | (hass, host) | Start a config flow. | Start a config flow. | def create_config_flow(hass, host):
"""Start a config flow."""
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={"host": host},
)
) | [
"def",
"create_config_flow",
"(",
"hass",
",",
"host",
")",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_... | [
36,
0
] | [
44,
5
] | python | en | ['en', 'lb', 'en'] | True |
CurvefittingAssessor.trial_end | (self, trial_job_id, success) | update the best performance of completed trial job
Parameters
----------
trial_job_id : int
trial job id
success : bool
True if succssfully finish the experiment, False otherwise
| update the best performance of completed trial job | def trial_end(self, trial_job_id, success):
"""update the best performance of completed trial job
Parameters
----------
trial_job_id : int
trial job id
success : bool
True if succssfully finish the experiment, False otherwise
"""
if succes... | [
"def",
"trial_end",
"(",
"self",
",",
"trial_job_id",
",",
"success",
")",
":",
"if",
"success",
":",
"if",
"self",
".",
"set_best_performance",
":",
"self",
".",
"completed_best_performance",
"=",
"max",
"(",
"self",
".",
"completed_best_performance",
",",
"s... | [
57,
4
] | [
75,
76
] | python | en | ['en', 'en', 'en'] | True |
CurvefittingAssessor.assess_trial | (self, trial_job_id, trial_history) | assess whether a trial should be early stop by curve fitting algorithm
Parameters
----------
trial_job_id : int
trial job id
trial_history : list
The history performance matrix of each trial
Returns
-------
bool
AssessResult.G... | assess whether a trial should be early stop by curve fitting algorithm | def assess_trial(self, trial_job_id, trial_history):
"""assess whether a trial should be early stop by curve fitting algorithm
Parameters
----------
trial_job_id : int
trial job id
trial_history : list
The history performance matrix of each trial
... | [
"def",
"assess_trial",
"(",
"self",
",",
"trial_job_id",
",",
"trial_history",
")",
":",
"scalar_trial_history",
"=",
"extract_scalar_history",
"(",
"trial_history",
")",
"self",
".",
"trial_history",
"=",
"scalar_trial_history",
"if",
"not",
"self",
".",
"set_best_... | [
77,
4
] | [
134,
92
] | python | en | ['en', 'en', 'en'] | True |
get_masks | (slen, lengths, causal, padding_mask=None) |
Generate hidden states mask, and optionally an attention mask.
|
Generate hidden states mask, and optionally an attention mask.
| def get_masks(slen, lengths, causal, padding_mask=None):
"""
Generate hidden states mask, and optionally an attention mask.
"""
alen = torch.arange(slen, dtype=torch.long, device=lengths.device)
if padding_mask is not None:
mask = padding_mask
else:
assert lengths.max().item() <=... | [
"def",
"get_masks",
"(",
"slen",
",",
"lengths",
",",
"causal",
",",
"padding_mask",
"=",
"None",
")",
":",
"alen",
"=",
"torch",
".",
"arange",
"(",
"slen",
",",
"dtype",
"=",
"torch",
".",
"long",
",",
"device",
"=",
"lengths",
".",
"device",
")",
... | [
86,
0
] | [
108,
26
] | python | en | ['en', 'error', 'th'] | False |
MultiHeadAttention.forward | (self, input, mask, kv=None, cache=None, head_mask=None, output_attentions=False) |
Self-attention (if kv is None) or attention over source sentence (provided by kv).
|
Self-attention (if kv is None) or attention over source sentence (provided by kv).
| def forward(self, input, mask, kv=None, cache=None, head_mask=None, output_attentions=False):
"""
Self-attention (if kv is None) or attention over source sentence (provided by kv).
"""
# Input is (bs, qlen, dim)
# Mask is (bs, klen) (non-causal) or (bs, klen, klen)
bs, ql... | [
"def",
"forward",
"(",
"self",
",",
"input",
",",
"mask",
",",
"kv",
"=",
"None",
",",
"cache",
"=",
"None",
",",
"head_mask",
"=",
"None",
",",
"output_attentions",
"=",
"False",
")",
":",
"# Input is (bs, qlen, dim)",
"# Mask is (bs, klen) (non-causal) or (bs,... | [
144,
4
] | [
205,
22
] | python | en | ['en', 'error', 'th'] | False |
XLMPreTrainedModel._init_weights | (self, module) | Initialize the weights. | Initialize the weights. | def _init_weights(self, module):
""" Initialize the weights. """
if isinstance(module, nn.Embedding):
if self.config is not None and self.config.embed_init_std is not None:
nn.init.normal_(module.weight, mean=0, std=self.config.embed_init_std)
if module.padding_id... | [
"def",
"_init_weights",
"(",
"self",
",",
"module",
")",
":",
"if",
"isinstance",
"(",
"module",
",",
"nn",
".",
"Embedding",
")",
":",
"if",
"self",
".",
"config",
"is",
"not",
"None",
"and",
"self",
".",
"config",
".",
"embed_init_std",
"is",
"not",
... | [
252,
4
] | [
266,
41
] | python | en | ['en', 'en', 'en'] | True |
XLMPredLayer.forward | (self, x, y=None) | Compute the loss, and optionally the scores. | Compute the loss, and optionally the scores. | def forward(self, x, y=None):
"""Compute the loss, and optionally the scores."""
outputs = ()
if self.asm is False:
scores = self.proj(x)
outputs = (scores,) + outputs
if y is not None:
loss = F.cross_entropy(scores.view(-1, self.n_words), y.vi... | [
"def",
"forward",
"(",
"self",
",",
"x",
",",
"y",
"=",
"None",
")",
":",
"outputs",
"=",
"(",
")",
"if",
"self",
".",
"asm",
"is",
"False",
":",
"scores",
"=",
"self",
".",
"proj",
"(",
"x",
")",
"outputs",
"=",
"(",
"scores",
",",
")",
"+",... | [
656,
4
] | [
672,
22
] | python | en | ['en', 'en', 'en'] | True |
build_device_info_mock | (
name="fake-device-1", ipAddress="1.1.1.1", mac="aabbcc112233"
) | Build mock device info structure. | Build mock device info structure. | def build_device_info_mock(
name="fake-device-1", ipAddress="1.1.1.1", mac="aabbcc112233"
):
"""Build mock device info structure."""
mock = Mock(ip=ipAddress, port=7000, mac=mac)
mock.name = name
return mock | [
"def",
"build_device_info_mock",
"(",
"name",
"=",
"\"fake-device-1\"",
",",
"ipAddress",
"=",
"\"1.1.1.1\"",
",",
"mac",
"=",
"\"aabbcc112233\"",
")",
":",
"mock",
"=",
"Mock",
"(",
"ip",
"=",
"ipAddress",
",",
"port",
"=",
"7000",
",",
"mac",
"=",
"mac",... | [
4,
0
] | [
10,
15
] | python | en | ['en', 'en', 'en'] | True |
build_device_mock | (name="fake-device-1", ipAddress="1.1.1.1", mac="aabbcc112233") | Build mock device object. | Build mock device object. | def build_device_mock(name="fake-device-1", ipAddress="1.1.1.1", mac="aabbcc112233"):
"""Build mock device object."""
mock = Mock(
device_info=build_device_info_mock(name, ipAddress, mac),
name=name,
bind=AsyncMock(),
update_state=AsyncMock(),
push_state_update=AsyncMock(... | [
"def",
"build_device_mock",
"(",
"name",
"=",
"\"fake-device-1\"",
",",
"ipAddress",
"=",
"\"1.1.1.1\"",
",",
"mac",
"=",
"\"aabbcc112233\"",
")",
":",
"mock",
"=",
"Mock",
"(",
"device_info",
"=",
"build_device_info_mock",
"(",
"name",
",",
"ipAddress",
",",
... | [
13,
0
] | [
34,
15
] | python | en | ['en', 'fy', 'en'] | True |
load_tf_weights_in_bert | (model, config, tf_checkpoint_path) | Load tf checkpoints in a pytorch model. | Load tf checkpoints in a pytorch model. | def load_tf_weights_in_bert(model, config, tf_checkpoint_path):
"""Load tf checkpoints in a pytorch model."""
try:
import re
import numpy as np
import tensorflow as tf
except ImportError:
logger.error(
"Loading a TensorFlow model in PyTorch, requires TensorFlow t... | [
"def",
"load_tf_weights_in_bert",
"(",
"model",
",",
"config",
",",
"tf_checkpoint_path",
")",
":",
"try",
":",
"import",
"re",
"import",
"numpy",
"as",
"np",
"import",
"tensorflow",
"as",
"tf",
"except",
"ImportError",
":",
"logger",
".",
"error",
"(",
"\"L... | [
91,
0
] | [
162,
16
] | python | en | ['en', 'en', 'en'] | True |
BertPreTrainedModel._init_weights | (self, module) | Initialize the weights | Initialize the weights | def _init_weights(self, module):
""" Initialize the weights """
if isinstance(module, nn.Linear):
# Slightly different from the TF version which uses truncated_normal for initialization
# cf https://github.com/pytorch/pytorch/pull/5617
module.weight.data.normal_(mean=... | [
"def",
"_init_weights",
"(",
"self",
",",
"module",
")",
":",
"if",
"isinstance",
"(",
"module",
",",
"nn",
".",
"Linear",
")",
":",
"# Slightly different from the TF version which uses truncated_normal for initialization",
"# cf https://github.com/pytorch/pytorch/pull/5617",
... | [
704,
4
] | [
718,
41
] | python | en | ['en', 'en', 'en'] | True |
validate_input | (hass: core.HomeAssistant, host, data) | Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
| Validate the user input allows us to connect. | async def validate_input(hass: core.HomeAssistant, host, data):
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
ip_address = await hass.async_add_executor_job(gethostbyname, host)
options = aioshelly.ConnectionOptions(
... | [
"async",
"def",
"validate_input",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"host",
",",
"data",
")",
":",
"ip_address",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"gethostbyname",
",",
"host",
")",
"options",
"=",
"aioshelly",
".",... | [
35,
0
] | [
60,
5
] | python | en | ['en', 'en', 'en'] | True |
ConfigFlow.async_step_user | (self, user_input=None) | Handle the initial step. | Handle the initial step. | async def async_step_user(self, user_input=None):
"""Handle the initial step."""
errors = {}
if user_input is not None:
host = user_input[CONF_HOST]
try:
info = await self._async_get_info(host)
except HTTP_CONNECT_ERRORS:
errors... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"host",
"=",
"user_input",
"[",
"CONF_HOST",
"]",
"try",
":",
"info",
"=",
"await",
"self",... | [
71,
4
] | [
107,
9
] | python | en | ['en', 'en', 'en'] | True |
ConfigFlow.async_step_credentials | (self, user_input=None) | Handle the credentials step. | Handle the credentials step. | async def async_step_credentials(self, user_input=None):
"""Handle the credentials step."""
errors = {}
if user_input is not None:
try:
device_info = await validate_input(self.hass, self.host, user_input)
except aiohttp.ClientResponseError as error:
... | [
"async",
"def",
"async_step_credentials",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"try",
":",
"device_info",
"=",
"await",
"validate_input",
"(",
"self",
".",
"hass",
"... | [
109,
4
] | [
142,
9
] | python | en | ['en', 'en', 'en'] | True |
ConfigFlow.async_step_zeroconf | (self, zeroconf_info) | Handle zeroconf discovery. | Handle zeroconf discovery. | async def async_step_zeroconf(self, zeroconf_info):
"""Handle zeroconf discovery."""
if not zeroconf_info.get("name", "").startswith("shelly"):
return self.async_abort(reason="not_shelly")
try:
self.info = info = await self._async_get_info(zeroconf_info["host"])
... | [
"async",
"def",
"async_step_zeroconf",
"(",
"self",
",",
"zeroconf_info",
")",
":",
"if",
"not",
"zeroconf_info",
".",
"get",
"(",
"\"name\"",
",",
"\"\"",
")",
".",
"startswith",
"(",
"\"shelly\"",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"rea... | [
144,
4
] | [
163,
56
] | python | de | ['de', 'sr', 'en'] | False |
ConfigFlow.async_step_confirm_discovery | (self, user_input=None) | Handle discovery confirm. | Handle discovery confirm. | async def async_step_confirm_discovery(self, user_input=None):
"""Handle discovery confirm."""
errors = {}
if user_input is not None:
if self.info["auth"]:
return await self.async_step_credentials()
try:
device_info = await validate_input(... | [
"async",
"def",
"async_step_confirm_discovery",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"if",
"self",
".",
"info",
"[",
"\"auth\"",
"]",
":",
"return",
"await",
"self",... | [
165,
4
] | [
194,
9
] | python | en | ['it', 'en', 'en'] | True |
ConfigFlow._async_get_info | (self, host) | Get info from shelly device. | Get info from shelly device. | async def _async_get_info(self, host):
"""Get info from shelly device."""
async with async_timeout.timeout(5):
return await aioshelly.get_info(
aiohttp_client.async_get_clientsession(self.hass),
host,
) | [
"async",
"def",
"_async_get_info",
"(",
"self",
",",
"host",
")",
":",
"async",
"with",
"async_timeout",
".",
"timeout",
"(",
"5",
")",
":",
"return",
"await",
"aioshelly",
".",
"get_info",
"(",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
"self",
... | [
196,
4
] | [
202,
13
] | python | en | ['en', 'en', 'en'] | True |
Wav2Vec2Processor.save_pretrained | (self, save_directory) |
Save a Wav2Vec2 feature_extractor object and Wav2Vec2 tokenizer object to the directory ``save_directory``, so
that it can be re-loaded using the :func:`~transformers.Wav2Vec2Processor.from_pretrained` class method.
.. note::
This class method is simply calling
:meth:`... |
Save a Wav2Vec2 feature_extractor object and Wav2Vec2 tokenizer object to the directory ``save_directory``, so
that it can be re-loaded using the :func:`~transformers.Wav2Vec2Processor.from_pretrained` class method. | def save_pretrained(self, save_directory):
"""
Save a Wav2Vec2 feature_extractor object and Wav2Vec2 tokenizer object to the directory ``save_directory``, so
that it can be re-loaded using the :func:`~transformers.Wav2Vec2Processor.from_pretrained` class method.
.. note::
T... | [
"def",
"save_pretrained",
"(",
"self",
",",
"save_directory",
")",
":",
"self",
".",
"feature_extractor",
".",
"save_pretrained",
"(",
"save_directory",
")",
"self",
".",
"tokenizer",
".",
"save_pretrained",
"(",
"save_directory",
")"
] | [
54,
4
] | [
73,
54
] | python | en | ['en', 'error', 'th'] | False |
Wav2Vec2Processor.from_pretrained | (cls, pretrained_model_name_or_path, **kwargs) | r"""
Instantiate a :class:`~transformers.Wav2Vec2Processor` from a pretrained Wav2Vec2 processor.
.. note::
This class method is simply calling Wav2Vec2FeatureExtractor's
:meth:`~transformers.feature_extraction_utils.FeatureExtractionMixin.from_pretrained` and
Wav2V... | r"""
Instantiate a :class:`~transformers.Wav2Vec2Processor` from a pretrained Wav2Vec2 processor. | def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
r"""
Instantiate a :class:`~transformers.Wav2Vec2Processor` from a pretrained Wav2Vec2 processor.
.. note::
This class method is simply calling Wav2Vec2FeatureExtractor's
:meth:`~transformers.feature_ext... | [
"def",
"from_pretrained",
"(",
"cls",
",",
"pretrained_model_name_or_path",
",",
"*",
"*",
"kwargs",
")",
":",
"feature_extractor",
"=",
"Wav2Vec2FeatureExtractor",
".",
"from_pretrained",
"(",
"pretrained_model_name_or_path",
",",
"*",
"*",
"kwargs",
")",
"tokenizer"... | [
76,
4
] | [
106,
76
] | python | cy | ['en', 'cy', 'hi'] | False |
Wav2Vec2Processor.__call__ | (self, *args, **kwargs) |
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.__call__` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_processor` this method forwards all its argument... |
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.__call__` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_processor` this method forwards all its argument... | def __call__(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.__call__` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_... | [
"def",
"__call__",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"current_processor",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
108,
4
] | [
116,
54
] | python | en | ['en', 'error', 'th'] | False |
Wav2Vec2Processor.pad | (self, *args, **kwargs) |
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.pad` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_processor` this method forwards all its arguments to
... |
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.pad` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_processor` this method forwards all its arguments to
... | def pad(self, *args, **kwargs):
"""
When used in normal mode, this method forwards all its arguments to Wav2Vec2FeatureExtractor's
:meth:`~transformers.Wav2Vec2FeatureExtractor.pad` and returns its output. If used in the context
:meth:`~transformers.Wav2Vec2Processor.as_target_processor`... | [
"def",
"pad",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"current_processor",
".",
"pad",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
118,
4
] | [
126,
58
] | python | en | ['en', 'error', 'th'] | False |
Wav2Vec2Processor.batch_decode | (self, *args, **kwargs) |
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.batch_decode`. Please refer to the docstring of this method for more
information.
|
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.batch_decode`. Please refer to the docstring of this method for more
information.
| def batch_decode(self, *args, **kwargs):
"""
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.batch_decode`. Please refer to the docstring of this method for more
information.
"""
return self.tokenizer.batch_decode(... | [
"def",
"batch_decode",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"tokenizer",
".",
"batch_decode",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
128,
4
] | [
134,
59
] | python | en | ['en', 'error', 'th'] | False |
Wav2Vec2Processor.decode | (self, *args, **kwargs) |
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.decode`. Please refer to the docstring of this method for more
information.
|
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.decode`. Please refer to the docstring of this method for more
information.
| def decode(self, *args, **kwargs):
"""
This method forwards all its arguments to Wav2Vec2CTCTokenizer's
:meth:`~transformers.PreTrainedTokenizer.decode`. Please refer to the docstring of this method for more
information.
"""
return self.tokenizer.decode(*args, **kwargs) | [
"def",
"decode",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"tokenizer",
".",
"decode",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
136,
4
] | [
142,
53
] | python | en | ['en', 'error', 'th'] | False |
Wav2Vec2Processor.as_target_processor | (self) |
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning
Wav2Vec2.
|
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning
Wav2Vec2.
| def as_target_processor(self):
"""
Temporarily sets the tokenizer for processing the input. Useful for encoding the labels when fine-tuning
Wav2Vec2.
"""
self.current_processor = self.tokenizer
yield
self.current_processor = self.feature_extractor | [
"def",
"as_target_processor",
"(",
"self",
")",
":",
"self",
".",
"current_processor",
"=",
"self",
".",
"tokenizer",
"yield",
"self",
".",
"current_processor",
"=",
"self",
".",
"feature_extractor"
] | [
145,
4
] | [
152,
55
] | python | en | ['en', 'error', 'th'] | False |
CamembertTokenizer.build_inputs_with_special_tokens | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An CamemBERT sequence has the following format:
- single sequence: ``<s> X </s>``
- pair of sequences: ``<s> A </s></s> B </s>``
Args:
... |
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An CamemBERT sequence has the following format: | def build_inputs_with_special_tokens(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and
adding special tokens. An CamemBERT sequence... | [
"def",
"build_inputs_with_special_tokens",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"if",
"token_ids_1",
... | [
135,
4
] | [
159,
64
] | python | en | ['en', 'error', 'th'] | False |
CamembertTokenizer.get_special_tokens_mask | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) |
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer ``prepare_for_model`` method.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token_ids_1 (:obj:`List[int]`,... |
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens using the tokenizer ``prepare_for_model`` method. | def get_special_tokens_mask(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
) -> List[int]:
"""
Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
special tokens ... | [
"def",
"get_special_tokens_mask",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
",",
"already_has_special_tokens",
":",
"bool",
"=",
"False",
")",
"->",
... | [
161,
4
] | [
189,
87
] | python | en | ['en', 'error', 'th'] | False |
CamembertTokenizer.create_token_type_ids_from_sequences | (
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. CamemBERT, like
RoBERTa, does not make use of token type ids, therefore a list of zeros is returned.
Args:
token_ids_0 (:obj:`List[int]`):
List of IDs.
token_i... |
Create a mask from the two sequences passed to be used in a sequence-pair classification task. CamemBERT, like
RoBERTa, does not make use of token type ids, therefore a list of zeros is returned. | def create_token_type_ids_from_sequences(
self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
) -> List[int]:
"""
Create a mask from the two sequences passed to be used in a sequence-pair classification task. CamemBERT, like
RoBERTa, does not make use of token type ... | [
"def",
"create_token_type_ids_from_sequences",
"(",
"self",
",",
"token_ids_0",
":",
"List",
"[",
"int",
"]",
",",
"token_ids_1",
":",
"Optional",
"[",
"List",
"[",
"int",
"]",
"]",
"=",
"None",
")",
"->",
"List",
"[",
"int",
"]",
":",
"sep",
"=",
"[",... | [
191,
4
] | [
212,
75
] | python | en | ['en', 'error', 'th'] | False |
CamembertTokenizer._convert_token_to_id | (self, token) | Converts a token (str) in an id using the vocab. | Converts a token (str) in an id using the vocab. | def _convert_token_to_id(self, token):
""" Converts a token (str) in an id using the vocab. """
if token in self.fairseq_tokens_to_ids:
return self.fairseq_tokens_to_ids[token]
elif self.sp_model.PieceToId(token) == 0:
# Convert sentence piece unk token to fairseq unk tok... | [
"def",
"_convert_token_to_id",
"(",
"self",
",",
"token",
")",
":",
"if",
"token",
"in",
"self",
".",
"fairseq_tokens_to_ids",
":",
"return",
"self",
".",
"fairseq_tokens_to_ids",
"[",
"token",
"]",
"elif",
"self",
".",
"sp_model",
".",
"PieceToId",
"(",
"to... | [
226,
4
] | [
233,
67
] | python | en | ['en', 'en', 'en'] | True |
CamembertTokenizer._convert_id_to_token | (self, index) | Converts an index (integer) in a token (str) using the vocab. | Converts an index (integer) in a token (str) using the vocab. | def _convert_id_to_token(self, index):
"""Converts an index (integer) in a token (str) using the vocab."""
if index in self.fairseq_ids_to_tokens:
return self.fairseq_ids_to_tokens[index]
return self.sp_model.IdToPiece(index - self.fairseq_offset) | [
"def",
"_convert_id_to_token",
"(",
"self",
",",
"index",
")",
":",
"if",
"index",
"in",
"self",
".",
"fairseq_ids_to_tokens",
":",
"return",
"self",
".",
"fairseq_ids_to_tokens",
"[",
"index",
"]",
"return",
"self",
".",
"sp_model",
".",
"IdToPiece",
"(",
"... | [
235,
4
] | [
239,
67
] | python | en | ['en', 'en', 'en'] | True |
CamembertTokenizer.convert_tokens_to_string | (self, tokens) | Converts a sequence of tokens (strings for sub-words) in a single string. | Converts a sequence of tokens (strings for sub-words) in a single string. | def convert_tokens_to_string(self, tokens):
"""Converts a sequence of tokens (strings for sub-words) in a single string."""
out_string = "".join(tokens).replace(SPIECE_UNDERLINE, " ").strip()
return out_string | [
"def",
"convert_tokens_to_string",
"(",
"self",
",",
"tokens",
")",
":",
"out_string",
"=",
"\"\"",
".",
"join",
"(",
"tokens",
")",
".",
"replace",
"(",
"SPIECE_UNDERLINE",
",",
"\" \"",
")",
".",
"strip",
"(",
")",
"return",
"out_string"
] | [
251,
4
] | [
254,
25
] | python | en | ['en', 'en', 'en'] | True |
TransmissionFlowHandler.async_get_options_flow | (config_entry) | Get the options flow for this handler. | Get the options flow for this handler. | def async_get_options_flow(config_entry):
"""Get the options flow for this handler."""
return TransmissionOptionsFlowHandler(config_entry) | [
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"return",
"TransmissionOptionsFlowHandler",
"(",
"config_entry",
")"
] | [
47,
4
] | [
49,
59
] | python | en | ['en', 'en', 'en'] | True |
TransmissionFlowHandler.async_step_user | (self, user_input=None) | Handle a flow initialized by the user. | Handle a flow initialized by the user. | async def async_step_user(self, user_input=None):
"""Handle a flow initialized by the user."""
errors = {}
if user_input is not None:
for entry in self.hass.config_entries.async_entries(DOMAIN):
if (
entry.data[CONF_HOST] == user_input[CONF_HOST]... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"if",
"user_input",
"is",
"not",
"None",
":",
"for",
"entry",
"in",
"self",
".",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
... | [
51,
4
] | [
84,
9
] | python | en | ['en', 'en', 'en'] | True |
TransmissionFlowHandler.async_step_import | (self, import_config) | Import from Transmission client config. | Import from Transmission client config. | async def async_step_import(self, import_config):
"""Import from Transmission client config."""
import_config[CONF_SCAN_INTERVAL] = import_config[CONF_SCAN_INTERVAL].seconds
return await self.async_step_user(user_input=import_config) | [
"async",
"def",
"async_step_import",
"(",
"self",
",",
"import_config",
")",
":",
"import_config",
"[",
"CONF_SCAN_INTERVAL",
"]",
"=",
"import_config",
"[",
"CONF_SCAN_INTERVAL",
"]",
".",
"seconds",
"return",
"await",
"self",
".",
"async_step_user",
"(",
"user_i... | [
86,
4
] | [
89,
67
] | python | en | ['en', 'en', 'en'] | True |
TransmissionOptionsFlowHandler.__init__ | (self, config_entry) | Initialize Transmission options flow. | Initialize Transmission options flow. | def __init__(self, config_entry):
"""Initialize Transmission options flow."""
self.config_entry = config_entry | [
"def",
"__init__",
"(",
"self",
",",
"config_entry",
")",
":",
"self",
".",
"config_entry",
"=",
"config_entry"
] | [
95,
4
] | [
97,
40
] | python | en | ['en', 'en', 'en'] | True |
TransmissionOptionsFlowHandler.async_step_init | (self, user_input=None) | Manage the Transmission options. | Manage the Transmission options. | async def async_step_init(self, user_input=None):
"""Manage the Transmission options."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
options = {
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config... | [
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"\"",
",",
"data",
"=",
"user_input",
")",
"options",
... | [
99,
4
] | [
121,
84
] | python | en | ['en', 'en', 'en'] | True |
test_show_form | (hass) | Test that the form is served with no input. | Test that the form is served with no input. | async def test_show_form(hass):
"""Test that the form is served with no input."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == SOURCE_USER | [
"async",
"def",
"test_show_form",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
... | [
21,
0
] | [
28,
43
] | python | en | ['en', 'en', 'en'] | True |
test_api_key_too_short | (hass) | Test that errors are shown when API key is too short. | Test that errors are shown when API key is too short. | async def test_api_key_too_short(hass):
"""Test that errors are shown when API key is too short."""
# The API key length check is done by the library without polling the AccuWeather
# server so we don't need to patch the library method.
result = await hass.config_entries.flow.async_init(
DOMAIN,... | [
"async",
"def",
"test_api_key_too_short",
"(",
"hass",
")",
":",
"# The API key length check is done by the library without polling the AccuWeather",
"# server so we don't need to patch the library method.",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
... | [
31,
0
] | [
46,
64
] | python | en | ['en', 'en', 'en'] | True |
test_invalid_api_key | (hass) | Test that errors are shown when API key is invalid. | Test that errors are shown when API key is invalid. | async def test_invalid_api_key(hass):
"""Test that errors are shown when API key is invalid."""
with patch(
"accuweather.AccuWeather._async_get_data",
side_effect=InvalidApiKeyError("Invalid API key"),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
... | [
"async",
"def",
"test_invalid_api_key",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"accuweather.AccuWeather._async_get_data\"",
",",
"side_effect",
"=",
"InvalidApiKeyError",
"(",
"\"Invalid API key\"",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
... | [
49,
0
] | [
62,
68
] | python | en | ['en', 'en', 'en'] | True |
test_api_error | (hass) | Test API error. | Test API error. | async def test_api_error(hass):
"""Test API error."""
with patch(
"accuweather.AccuWeather._async_get_data",
side_effect=ApiError("Invalid response from AccuWeather API"),
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURC... | [
"async",
"def",
"test_api_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"accuweather.AccuWeather._async_get_data\"",
",",
"side_effect",
"=",
"ApiError",
"(",
"\"Invalid response from AccuWeather API\"",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
"... | [
65,
0
] | [
78,
61
] | python | de | ['de', 'la', 'en'] | False |
test_requests_exceeded_error | (hass) | Test requests exceeded error. | Test requests exceeded error. | async def test_requests_exceeded_error(hass):
"""Test requests exceeded error."""
with patch(
"accuweather.AccuWeather._async_get_data",
side_effect=RequestsExceededError(
"The allowed number of requests has been exceeded"
),
):
result = await hass.config_entries... | [
"async",
"def",
"test_requests_exceeded_error",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"accuweather.AccuWeather._async_get_data\"",
",",
"side_effect",
"=",
"RequestsExceededError",
"(",
"\"The allowed number of requests has been exceeded\"",
")",
",",
")",
":",
"re... | [
81,
0
] | [
96,
70
] | python | en | ['en', 'nl', 'en'] | True |
test_integration_already_exists | (hass) | Test we only allow a single config flow. | Test we only allow a single config flow. | async def test_integration_already_exists(hass):
"""Test we only allow a single config flow."""
with patch(
"accuweather.AccuWeather._async_get_data",
return_value=json.loads(load_fixture("accuweather/location_data.json")),
):
MockConfigEntry(
domain=DOMAIN,
u... | [
"async",
"def",
"test_integration_already_exists",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"accuweather.AccuWeather._async_get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"accuweather/location_data.json\"",
")",
")",
",",
... | [
99,
0
] | [
118,
60
] | python | en | ['en', 'en', 'en'] | True |
test_create_entry | (hass) | Test that the user step works. | Test that the user step works. | async def test_create_entry(hass):
"""Test that the user step works."""
with patch(
"accuweather.AccuWeather._async_get_data",
return_value=json.loads(load_fixture("accuweather/location_data.json")),
), patch(
"homeassistant.components.accuweather.async_setup_entry", return_value=Tru... | [
"async",
"def",
"test_create_entry",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"accuweather.AccuWeather._async_get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"accuweather/location_data.json\"",
")",
")",
",",
")",
",",
... | [
121,
0
] | [
141,
81
] | python | en | ['en', 'en', 'en'] | True |
test_options_flow | (hass) | Test config flow options. | Test config flow options. | async def test_options_flow(hass):
"""Test config flow options."""
config_entry = MockConfigEntry(
domain=DOMAIN,
unique_id="123456",
data=VALID_CONFIG,
)
config_entry.add_to_hass(hass)
with patch(
"accuweather.AccuWeather._async_get_data",
return_value=json.... | [
"async",
"def",
"test_options_flow",
"(",
"hass",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"unique_id",
"=",
"\"123456\"",
",",
"data",
"=",
"VALID_CONFIG",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
... | [
144,
0
] | [
181,
42
] | python | en | ['en', 'fr', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Crime Reports platform. | Set up the Crime Reports platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Crime Reports platform."""
latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
name = config[CONF_NAME]
radius = config[CONF_RADIUS]
include = c... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"latitude",
"=",
"config",
".",
"get",
"(",
"CONF_LATITUDE",
",",
"hass",
".",
"config",
".",
"latitude",
")",
"longitude",
"=",
"config... | [
45,
0
] | [
57,
5
] | python | en | ['en', 'da', 'en'] | True |
CrimeReportsSensor.__init__ | (self, hass, name, latitude, longitude, radius, include, exclude) | Initialize the Crime Reports sensor. | Initialize the Crime Reports sensor. | def __init__(self, hass, name, latitude, longitude, radius, include, exclude):
"""Initialize the Crime Reports sensor."""
self._hass = hass
self._name = name
self._include = include
self._exclude = exclude
radius_kilometers = convert(radius, LENGTH_METERS, LENGTH_KILOMETE... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"name",
",",
"latitude",
",",
"longitude",
",",
"radius",
",",
"include",
",",
"exclude",
")",
":",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_include",
"=",
... | [
63,
4
] | [
75,
40
] | python | en | ['en', 'en', 'en'] | True |
CrimeReportsSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
78,
4
] | [
80,
25
] | python | en | ['en', 'mi', 'en'] | True |
CrimeReportsSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
83,
4
] | [
85,
26
] | python | en | ['en', 'en', 'en'] | True |
CrimeReportsSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
return self._attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attributes"
] | [
88,
4
] | [
90,
31
] | python | en | ['en', 'en', 'en'] | True |
CrimeReportsSensor._incident_event | (self, incident) | Fire if an event occurs. | Fire if an event occurs. | def _incident_event(self, incident):
"""Fire if an event occurs."""
data = {
"type": incident.get("type"),
"description": incident.get("friendly_description"),
"timestamp": incident.get("timestamp"),
"location": incident.get("location"),
}
... | [
"def",
"_incident_event",
"(",
"self",
",",
"incident",
")",
":",
"data",
"=",
"{",
"\"type\"",
":",
"incident",
".",
"get",
"(",
"\"type\"",
")",
",",
"\"description\"",
":",
"incident",
".",
"get",
"(",
"\"friendly_description\"",
")",
",",
"\"timestamp\""... | [
92,
4
] | [
107,
49
] | python | en | ['en', 'en', 'en'] | True |
CrimeReportsSensor.update | (self) | Update device state. | Update device state. | def update(self):
"""Update device state."""
incident_counts = defaultdict(int)
incidents = self._crimereports.get_incidents(
now().date(), include=self._include, exclude=self._exclude
)
fire_events = len(self._previous_incidents) > 0
if len(incidents) < len(s... | [
"def",
"update",
"(",
"self",
")",
":",
"incident_counts",
"=",
"defaultdict",
"(",
"int",
")",
"incidents",
"=",
"self",
".",
"_crimereports",
".",
"get_incidents",
"(",
"now",
"(",
")",
".",
"date",
"(",
")",
",",
"include",
"=",
"self",
".",
"_inclu... | [
109,
4
] | [
126,
36
] | python | en | ['fr', 'en', 'en'] | True |
async_setup | (hass, config) | Activate Alexa component. | Activate Alexa component. | async def async_setup(hass, config):
"""Activate Alexa component."""
intents = copy.deepcopy(config[DOMAIN])
template.attach(hass, intents)
for intent_type, conf in intents.items():
if CONF_ACTION in conf:
conf[CONF_ACTION] = script.Script(
hass, conf[CONF_ACTION], f... | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"intents",
"=",
"copy",
".",
"deepcopy",
"(",
"config",
"[",
"DOMAIN",
"]",
")",
"template",
".",
"attach",
"(",
"hass",
",",
"intents",
")",
"for",
"intent_type",
",",
"conf",
"in",
... | [
46,
0
] | [
58,
15
] | python | ca | ['ro', 'ca', 'en'] | False |
ScriptIntentHandler.__init__ | (self, intent_type, config) | Initialize the script intent handler. | Initialize the script intent handler. | def __init__(self, intent_type, config):
"""Initialize the script intent handler."""
self.intent_type = intent_type
self.config = config | [
"def",
"__init__",
"(",
"self",
",",
"intent_type",
",",
"config",
")",
":",
"self",
".",
"intent_type",
"=",
"intent_type",
"self",
".",
"config",
"=",
"config"
] | [
64,
4
] | [
67,
28
] | python | en | ['en', 'en', 'en'] | True |
ScriptIntentHandler.async_handle | (self, intent_obj) | Handle the intent. | Handle the intent. | async def async_handle(self, intent_obj):
"""Handle the intent."""
speech = self.config.get(CONF_SPEECH)
card = self.config.get(CONF_CARD)
action = self.config.get(CONF_ACTION)
is_async_action = self.config.get(CONF_ASYNC_ACTION)
slots = {key: value["value"] for key, valu... | [
"async",
"def",
"async_handle",
"(",
"self",
",",
"intent_obj",
")",
":",
"speech",
"=",
"self",
".",
"config",
".",
"get",
"(",
"CONF_SPEECH",
")",
"card",
"=",
"self",
".",
"config",
".",
"get",
"(",
"CONF_CARD",
")",
"action",
"=",
"self",
".",
"c... | [
69,
4
] | [
100,
23
] | python | en | ['en', 'en', 'en'] | True |
events | (hass) | Fixture that catches notify events. | Fixture that catches notify events. | def events(hass):
"""Fixture that catches notify events."""
events = []
hass.bus.async_listen(demo.EVENT_NOTIFY, callback(lambda e: events.append(e)))
yield events | [
"def",
"events",
"(",
"hass",
")",
":",
"events",
"=",
"[",
"]",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"demo",
".",
"EVENT_NOTIFY",
",",
"callback",
"(",
"lambda",
"e",
":",
"events",
".",
"append",
"(",
"e",
")",
")",
")",
"yield",
"events... | [
20,
0
] | [
24,
16
] | python | en | ['en', 'en', 'en'] | True |
calls | () | Fixture to calls. | Fixture to calls. | def calls():
"""Fixture to calls."""
return [] | [
"def",
"calls",
"(",
")",
":",
"return",
"[",
"]"
] | [
28,
0
] | [
30,
13
] | python | en | ['en', 'nl', 'en'] | True |
record_calls | (calls) | Fixture to record calls. | Fixture to record calls. | def record_calls(calls):
"""Fixture to record calls."""
@callback
def record_calls(*args):
"""Record calls."""
calls.append(args)
return record_calls | [
"def",
"record_calls",
"(",
"calls",
")",
":",
"@",
"callback",
"def",
"record_calls",
"(",
"*",
"args",
")",
":",
"\"\"\"Record calls.\"\"\"",
"calls",
".",
"append",
"(",
"args",
")",
"return",
"record_calls"
] | [
34,
0
] | [
42,
23
] | python | en | ['en', 'ca', 'en'] | True |
mock_demo_notify_fixture | () | Mock demo notify service. | Mock demo notify service. | def mock_demo_notify_fixture():
"""Mock demo notify service."""
with patch("homeassistant.components.demo.notify.get_service", autospec=True) as ns:
yield ns | [
"def",
"mock_demo_notify_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.demo.notify.get_service\"",
",",
"autospec",
"=",
"True",
")",
"as",
"ns",
":",
"yield",
"ns"
] | [
46,
0
] | [
49,
16
] | python | es | ['es', 'es', 'en'] | True |
setup_notify | (hass) | Test setup. | Test setup. | async def setup_notify(hass):
"""Test setup."""
with assert_setup_component(1, notify.DOMAIN) as config:
assert await async_setup_component(hass, notify.DOMAIN, CONFIG)
assert config[notify.DOMAIN]
await hass.async_block_till_done() | [
"async",
"def",
"setup_notify",
"(",
"hass",
")",
":",
"with",
"assert_setup_component",
"(",
"1",
",",
"notify",
".",
"DOMAIN",
")",
"as",
"config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"CONFIG",
... | [
52,
0
] | [
57,
38
] | python | en | ['en', 'haw', 'en'] | False |
test_no_notify_service | (hass, mock_demo_notify, caplog) | Test missing platform notify service instance. | Test missing platform notify service instance. | async def test_no_notify_service(hass, mock_demo_notify, caplog):
"""Test missing platform notify service instance."""
caplog.set_level(logging.ERROR)
mock_demo_notify.return_value = None
await setup_notify(hass)
await hass.async_block_till_done()
assert mock_demo_notify.called
assert "Faile... | [
"async",
"def",
"test_no_notify_service",
"(",
"hass",
",",
"mock_demo_notify",
",",
"caplog",
")",
":",
"caplog",
".",
"set_level",
"(",
"logging",
".",
"ERROR",
")",
"mock_demo_notify",
".",
"return_value",
"=",
"None",
"await",
"setup_notify",
"(",
"hass",
... | [
60,
0
] | [
67,
74
] | python | da | ['mt', 'da', 'en'] | False |
test_discover_notify | (hass, mock_demo_notify) | Test discovery of notify demo platform. | Test discovery of notify demo platform. | async def test_discover_notify(hass, mock_demo_notify):
"""Test discovery of notify demo platform."""
assert notify.DOMAIN not in hass.config.components
mock_demo_notify.return_value = None
await discovery.async_load_platform(
hass, "notify", "demo", {"test_key": "test_val"}, {"notify": {}}
... | [
"async",
"def",
"test_discover_notify",
"(",
"hass",
",",
"mock_demo_notify",
")",
":",
"assert",
"notify",
".",
"DOMAIN",
"not",
"in",
"hass",
".",
"config",
".",
"components",
"mock_demo_notify",
".",
"return_value",
"=",
"None",
"await",
"discovery",
".",
"... | [
70,
0
] | [
84,
5
] | python | en | ['en', 'en', 'en'] | True |
test_sending_none_message | (hass, events) | Test send with None as message. | Test send with None as message. | async def test_sending_none_message(hass, events):
"""Test send with None as message."""
await setup_notify(hass)
with pytest.raises(vol.Invalid):
await hass.services.async_call(
notify.DOMAIN, notify.SERVICE_NOTIFY, {notify.ATTR_MESSAGE: None}
)
await hass.async_block_till_d... | [
"async",
"def",
"test_sending_none_message",
"(",
"hass",
",",
"events",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"with",
"pytest",
".",
"raises",
"(",
"vol",
".",
"Invalid",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
... | [
87,
0
] | [
95,
27
] | python | en | ['en', 'en', 'en'] | True |
test_sending_templated_message | (hass, events) | Send a templated message. | Send a templated message. | async def test_sending_templated_message(hass, events):
"""Send a templated message."""
await setup_notify(hass)
hass.states.async_set("sensor.temperature", 10)
data = {
notify.ATTR_MESSAGE: "{{states.sensor.temperature.state}}",
notify.ATTR_TITLE: "{{ states.sensor.temperature.name }}",... | [
"async",
"def",
"test_sending_templated_message",
"(",
"hass",
",",
"events",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"sensor.temperature\"",
",",
"10",
")",
"data",
"=",
"{",
"notify",
".",
"ATTR_... | [
98,
0
] | [
110,
55
] | python | en | ['en', 'en', 'en'] | True |
test_method_forwards_correct_data | (hass, events) | Test that all data from the service gets forwarded to service. | Test that all data from the service gets forwarded to service. | async def test_method_forwards_correct_data(hass, events):
"""Test that all data from the service gets forwarded to service."""
await setup_notify(hass)
data = {
notify.ATTR_MESSAGE: "my message",
notify.ATTR_TITLE: "my title",
notify.ATTR_DATA: {"hello": "world"},
}
await ha... | [
"async",
"def",
"test_method_forwards_correct_data",
"(",
"hass",
",",
"events",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"data",
"=",
"{",
"notify",
".",
"ATTR_MESSAGE",
":",
"\"my message\"",
",",
"notify",
".",
"ATTR_TITLE",
":",
"\"my title\"",
... | [
113,
0
] | [
129,
13
] | python | en | ['en', 'en', 'en'] | True |
test_calling_notify_from_script_loaded_from_yaml_without_title | (hass, events) | Test if we can call a notify from a script. | Test if we can call a notify from a script. | async def test_calling_notify_from_script_loaded_from_yaml_without_title(hass, events):
"""Test if we can call a notify from a script."""
await setup_notify(hass)
step = {
"service": "notify.notify",
"data": {
"data": {"push": {"sound": "US-EN-Morgan-Freeman-Roommate-Is-Arriving.... | [
"async",
"def",
"test_calling_notify_from_script_loaded_from_yaml_without_title",
"(",
"hass",
",",
"events",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"step",
"=",
"{",
"\"service\"",
":",
"\"notify.notify\"",
",",
"\"data\"",
":",
"{",
"\"data\"",
":",
... | [
132,
0
] | [
151,
23
] | python | en | ['en', 'en', 'en'] | True |
test_calling_notify_from_script_loaded_from_yaml_with_title | (hass, events) | Test if we can call a notify from a script. | Test if we can call a notify from a script. | async def test_calling_notify_from_script_loaded_from_yaml_with_title(hass, events):
"""Test if we can call a notify from a script."""
await setup_notify(hass)
step = {
"service": "notify.notify",
"data": {
"data": {"push": {"sound": "US-EN-Morgan-Freeman-Roommate-Is-Arriving.wav... | [
"async",
"def",
"test_calling_notify_from_script_loaded_from_yaml_with_title",
"(",
"hass",
",",
"events",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"step",
"=",
"{",
"\"service\"",
":",
"\"notify.notify\"",
",",
"\"data\"",
":",
"{",
"\"data\"",
":",
"... | [
154,
0
] | [
174,
23
] | python | en | ['en', 'en', 'en'] | True |
test_targets_are_services | (hass) | Test that all targets are exposed as individual services. | Test that all targets are exposed as individual services. | async def test_targets_are_services(hass):
"""Test that all targets are exposed as individual services."""
await setup_notify(hass)
assert hass.services.has_service("notify", "demo") is not None
service = "demo_test_target_name"
assert hass.services.has_service("notify", service) is not None | [
"async",
"def",
"test_targets_are_services",
"(",
"hass",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"assert",
"hass",
".",
"services",
".",
"has_service",
"(",
"\"notify\"",
",",
"\"demo\"",
")",
"is",
"not",
"None",
"service",
"=",
"\"demo_test_tar... | [
177,
0
] | [
182,
67
] | python | en | ['en', 'en', 'en'] | True |
test_messages_to_targets_route | (hass, calls, record_calls) | Test message routing to specific target services. | Test message routing to specific target services. | async def test_messages_to_targets_route(hass, calls, record_calls):
"""Test message routing to specific target services."""
await setup_notify(hass)
hass.bus.async_listen_once("notify", record_calls)
await hass.services.async_call(
"notify",
"demo_test_target_name",
{"message":... | [
"async",
"def",
"test_messages_to_targets_route",
"(",
"hass",
",",
"calls",
",",
"record_calls",
")",
":",
"await",
"setup_notify",
"(",
"hass",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"\"notify\"",
",",
"record_calls",
")",
"await",
"hass",
"... | [
185,
0
] | [
205,
13
] | python | en | ['en', 'en', 'en'] | True |
load_codes | (path) | Load KIRA codes from specified file. | Load KIRA codes from specified file. | def load_codes(path):
"""Load KIRA codes from specified file."""
codes = []
if os.path.exists(path):
with open(path) as code_file:
data = yaml.safe_load(code_file) or []
for code in data:
try:
codes.append(CODE_SCHEMA(code))
except Voluptuo... | [
"def",
"load_codes",
"(",
"path",
")",
":",
"codes",
"=",
"[",
"]",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"with",
"open",
"(",
"path",
")",
"as",
"code_file",
":",
"data",
"=",
"yaml",
".",
"safe_load",
"(",
"code_file",
... | [
76,
0
] | [
91,
16
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the KIRA component. | Set up the KIRA component. | def setup(hass, config):
"""Set up the KIRA component."""
sensors = config.get(DOMAIN, {}).get(CONF_SENSORS, [])
remotes = config.get(DOMAIN, {}).get(CONF_REMOTES, [])
# If no sensors or remotes were specified, add a sensor
if not (sensors or remotes):
sensors.append({})
codes = load_co... | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"sensors",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
",",
"{",
"}",
")",
".",
"get",
"(",
"CONF_SENSORS",
",",
"[",
"]",
")",
"remotes",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
",",
"{",
"... | [
94,
0
] | [
144,
15
] | python | en | ['en', 'en', 'en'] | True |
get_significant_states | (hass, *args, **kwargs) | Wrap _get_significant_states with a sql session. | Wrap _get_significant_states with a sql session. | def get_significant_states(hass, *args, **kwargs):
"""Wrap _get_significant_states with a sql session."""
with session_scope(hass=hass) as session:
return _get_significant_states(hass, session, *args, **kwargs) | [
"def",
"get_significant_states",
"(",
"hass",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"with",
"session_scope",
"(",
"hass",
"=",
"hass",
")",
"as",
"session",
":",
"return",
"_get_significant_states",
"(",
"hass",
",",
"session",
",",
"*",
"... | [
89,
0
] | [
92,
70
] | python | en | ['en', 'en', 'en'] | True |
_get_significant_states | (
hass,
session,
start_time,
end_time=None,
entity_ids=None,
filters=None,
include_start_time_state=True,
significant_changes_only=True,
minimal_response=False,
) |
Return states changes during UTC period start_time - end_time.
Significant states are all states where there is a state change,
as well as all states from certain domains (for instance
thermostat so that we get current temperature in our graphs).
|
Return states changes during UTC period start_time - end_time. | def _get_significant_states(
hass,
session,
start_time,
end_time=None,
entity_ids=None,
filters=None,
include_start_time_state=True,
significant_changes_only=True,
minimal_response=False,
):
"""
Return states changes during UTC period start_time - end_time.
Significant s... | [
"def",
"_get_significant_states",
"(",
"hass",
",",
"session",
",",
"start_time",
",",
"end_time",
"=",
"None",
",",
"entity_ids",
"=",
"None",
",",
"filters",
"=",
"None",
",",
"include_start_time_state",
"=",
"True",
",",
"significant_changes_only",
"=",
"True... | [
95,
0
] | [
163,
5
] | python | en | ['en', 'error', 'th'] | False |
state_changes_during_period | (hass, start_time, end_time=None, entity_id=None) | Return states changes during UTC period start_time - end_time. | Return states changes during UTC period start_time - end_time. | def state_changes_during_period(hass, start_time, end_time=None, entity_id=None):
"""Return states changes during UTC period start_time - end_time."""
with session_scope(hass=hass) as session:
baked_query = hass.data[HISTORY_BAKERY](
lambda session: session.query(*QUERY_STATES)
)
... | [
"def",
"state_changes_during_period",
"(",
"hass",
",",
"start_time",
",",
"end_time",
"=",
"None",
",",
"entity_id",
"=",
"None",
")",
":",
"with",
"session_scope",
"(",
"hass",
"=",
"hass",
")",
"as",
"session",
":",
"baked_query",
"=",
"hass",
".",
"dat... | [
166,
0
] | [
197,
84
] | python | en | ['fr', 'en', 'en'] | True |
get_last_state_changes | (hass, number_of_states, entity_id) | Return the last number_of_states. | Return the last number_of_states. | def get_last_state_changes(hass, number_of_states, entity_id):
"""Return the last number_of_states."""
start_time = dt_util.utcnow()
with session_scope(hass=hass) as session:
baked_query = hass.data[HISTORY_BAKERY](
lambda session: session.query(*QUERY_STATES)
)
baked_qu... | [
"def",
"get_last_state_changes",
"(",
"hass",
",",
"number_of_states",
",",
"entity_id",
")",
":",
"start_time",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"with",
"session_scope",
"(",
"hass",
"=",
"hass",
")",
"as",
"session",
":",
"baked_query",
"=",
"hass"... | [
200,
0
] | [
235,
9
] | python | en | ['en', 'en', 'en'] | True |
get_states | (hass, utc_point_in_time, entity_ids=None, run=None, filters=None) | Return the states at a specific point in time. | Return the states at a specific point in time. | def get_states(hass, utc_point_in_time, entity_ids=None, run=None, filters=None):
"""Return the states at a specific point in time."""
if run is None:
run = recorder.run_information_from_instance(hass, utc_point_in_time)
# History did not run before utc_point_in_time
if run is None:
... | [
"def",
"get_states",
"(",
"hass",
",",
"utc_point_in_time",
",",
"entity_ids",
"=",
"None",
",",
"run",
"=",
"None",
",",
"filters",
"=",
"None",
")",
":",
"if",
"run",
"is",
"None",
":",
"run",
"=",
"recorder",
".",
"run_information_from_instance",
"(",
... | [
238,
0
] | [
250,
9
] | python | en | ['en', 'en', 'en'] | True |
_get_states_with_session | (
hass, session, utc_point_in_time, entity_ids=None, run=None, filters=None
) | Return the states at a specific point in time. | Return the states at a specific point in time. | def _get_states_with_session(
hass, session, utc_point_in_time, entity_ids=None, run=None, filters=None
):
"""Return the states at a specific point in time."""
if entity_ids and len(entity_ids) == 1:
return _get_single_entity_states_with_session(
hass, session, utc_point_in_time, entity_... | [
"def",
"_get_states_with_session",
"(",
"hass",
",",
"session",
",",
"utc_point_in_time",
",",
"entity_ids",
"=",
"None",
",",
"run",
"=",
"None",
",",
"filters",
"=",
"None",
")",
":",
"if",
"entity_ids",
"and",
"len",
"(",
"entity_ids",
")",
"==",
"1",
... | [
253,
0
] | [
314,
53
] | python | en | ['en', 'en', 'en'] | True |
_sorted_states_to_json | (
hass,
session,
states,
start_time,
entity_ids,
filters=None,
include_start_time_state=True,
minimal_response=False,
) | Convert SQL results into JSON friendly data structure.
This takes our state list and turns it into a JSON friendly data
structure {'entity_id': [list of states], 'entity_id2': [list of states]}
States must be sorted by entity_id and last_updated
We also need to go back and create a synthetic zero dat... | Convert SQL results into JSON friendly data structure. | def _sorted_states_to_json(
hass,
session,
states,
start_time,
entity_ids,
filters=None,
include_start_time_state=True,
minimal_response=False,
):
"""Convert SQL results into JSON friendly data structure.
This takes our state list and turns it into a JSON friendly data
struc... | [
"def",
"_sorted_states_to_json",
"(",
"hass",
",",
"session",
",",
"states",
",",
"start_time",
",",
"entity_ids",
",",
"filters",
"=",
"None",
",",
"include_start_time_state",
"=",
"True",
",",
"minimal_response",
"=",
"False",
",",
")",
":",
"result",
"=",
... | [
337,
0
] | [
423,
59
] | python | en | ['en', 'en', 'en'] | True |
get_state | (hass, utc_point_in_time, entity_id, run=None) | Return a state at a specific point in time. | Return a state at a specific point in time. | def get_state(hass, utc_point_in_time, entity_id, run=None):
"""Return a state at a specific point in time."""
states = get_states(hass, utc_point_in_time, (entity_id,), run)
return states[0] if states else None | [
"def",
"get_state",
"(",
"hass",
",",
"utc_point_in_time",
",",
"entity_id",
",",
"run",
"=",
"None",
")",
":",
"states",
"=",
"get_states",
"(",
"hass",
",",
"utc_point_in_time",
",",
"(",
"entity_id",
",",
")",
",",
"run",
")",
"return",
"states",
"[",... | [
426,
0
] | [
429,
40
] | 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.