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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test_download_switch | (hass, nzbget_api) | Test the creation and values of the download switch. | Test the creation and values of the download switch. | async def test_download_switch(hass, nzbget_api) -> None:
"""Test the creation and values of the download switch."""
instance = nzbget_api.return_value
entry = await init_integration(hass)
assert entry
registry = await hass.helpers.entity_registry.async_get_registry()
entity_id = "switch.nzbge... | [
"async",
"def",
"test_download_switch",
"(",
"hass",
",",
"nzbget_api",
")",
"->",
"None",
":",
"instance",
"=",
"nzbget_api",
".",
"return_value",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
")",
"assert",
"entry",
"registry",
"=",
"await",
"hass"... | [
13,
0
] | [
38,
35
] | python | en | ['en', 'en', 'en'] | True |
test_download_switch_services | (hass, nzbget_api) | Test download switch services. | Test download switch services. | async def test_download_switch_services(hass, nzbget_api) -> None:
"""Test download switch services."""
instance = nzbget_api.return_value
entry = await init_integration(hass)
entity_id = "switch.nzbgettest_download"
assert entry
await hass.services.async_call(
SWITCH_DOMAIN,
S... | [
"async",
"def",
"test_download_switch_services",
"(",
"hass",
",",
"nzbget_api",
")",
"->",
"None",
":",
"instance",
"=",
"nzbget_api",
".",
"return_value",
"entry",
"=",
"await",
"init_integration",
"(",
"hass",
")",
"entity_id",
"=",
"\"switch.nzbgettest_download\... | [
41,
0
] | [
63,
48
] | python | en | ['en', 'en', 'en'] | True |
num_string | (value: Union[int, str]) | Test if value is a string of digits, aka an integer. | Test if value is a string of digits, aka an integer. | def num_string(value: Union[int, str]) -> str:
"""Test if value is a string of digits, aka an integer."""
new_value = str(value)
if new_value.isdigit():
return new_value
raise vol.Invalid("Not a string with numbers") | [
"def",
"num_string",
"(",
"value",
":",
"Union",
"[",
"int",
",",
"str",
"]",
")",
"->",
"str",
":",
"new_value",
"=",
"str",
"(",
"value",
")",
"if",
"new_value",
".",
"isdigit",
"(",
")",
":",
"return",
"new_value",
"raise",
"vol",
".",
"Invalid",
... | [
57,
0
] | [
62,
50
] | python | en | ['en', 'en', 'en'] | True |
validate_area | (config: Dict[str, Any]) | Validate that template parameters are only used if area is using the relevant template. | Validate that template parameters are only used if area is using the relevant template. | def validate_area(config: Dict[str, Any]) -> Dict[str, Any]:
"""Validate that template parameters are only used if area is using the relevant template."""
conf_set = set()
for template in DEFAULT_TEMPLATES:
for conf in DEFAULT_TEMPLATES[template]:
conf_set.add(conf)
if config.get(CON... | [
"def",
"validate_area",
"(",
"config",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"conf_set",
"=",
"set",
"(",
")",
"for",
"template",
"in",
"DEFAULT_TEMPLATES",
":",
"for",
"conf",
"in",
"DEFAULT_T... | [
108,
0
] | [
122,
17
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistant, config: Dict[str, Any]) | Set up the Dynalite platform. | Set up the Dynalite platform. | async def async_setup(hass: HomeAssistant, config: Dict[str, Any]) -> bool:
"""Set up the Dynalite platform."""
conf = config.get(DOMAIN)
LOGGER.debug("Setting up dynalite component config = %s", conf)
if conf is None:
conf = {}
hass.data[DOMAIN] = {}
# User has configured bridges
... | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"bool",
":",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
")",
"LOGGER",
".",
"debug",
"(",
"\"Setting up dynalit... | [
181,
0
] | [
253,
15
] | python | en | ['en', 'cs', 'en'] | True |
async_entry_changed | (hass: HomeAssistant, entry: ConfigEntry) | Reload entry since the data has changed. | Reload entry since the data has changed. | async def async_entry_changed(hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Reload entry since the data has changed."""
LOGGER.debug("Reconfiguring entry %s", entry.data)
bridge = hass.data[DOMAIN][entry.entry_id]
bridge.reload_config(entry.data)
LOGGER.debug("Reconfiguring entry finished %s"... | [
"async",
"def",
"async_entry_changed",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"None",
":",
"LOGGER",
".",
"debug",
"(",
"\"Reconfiguring entry %s\"",
",",
"entry",
".",
"data",
")",
"bridge",
"=",
"hass",
".",
"data",... | [
256,
0
] | [
261,
63
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, entry: ConfigEntry) | Set up a bridge from a config entry. | Set up a bridge from a config entry. | async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up a bridge from a config entry."""
LOGGER.debug("Setting up entry %s", entry.data)
bridge = DynaliteBridge(hass, entry.data)
# need to do it before the listener
hass.data[DOMAIN][entry.entry_id] = bridge
entry.... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"LOGGER",
".",
"debug",
"(",
"\"Setting up entry %s\"",
",",
"entry",
".",
"data",
")",
"bridge",
"=",
"DynaliteBridge",
"(",
"h... | [
264,
0
] | [
279,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
LOGGER.debug("Unloading entry %s", entry.data)
hass.data[DOMAIN].pop(entry.entry_id)
tasks = [
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in ENTIT... | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"LOGGER",
".",
"debug",
"(",
"\"Unloading entry %s\"",
",",
"entry",
".",
"data",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]... | [
282,
0
] | [
291,
31
] | python | en | ['en', 'es', 'en'] | True |
ConfigEntryNetatmoAuth.__init__ | (
self,
hass: core.HomeAssistant,
config_entry: config_entries.ConfigEntry,
implementation: config_entry_oauth2_flow.AbstractOAuth2Implementation,
) | Initialize Netatmo Auth. | Initialize Netatmo Auth. | def __init__(
self,
hass: core.HomeAssistant,
config_entry: config_entries.ConfigEntry,
implementation: config_entry_oauth2_flow.AbstractOAuth2Implementation,
):
"""Initialize Netatmo Auth."""
self.hass = hass
self.session = config_entry_oauth2_flow.OAuth2Sess... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"config_entry",
":",
"config_entries",
".",
"ConfigEntry",
",",
"implementation",
":",
"config_entry_oauth2_flow",
".",
"AbstractOAuth2Implementation",
",",
")",
":",
"self",
".",... | [
12,
4
] | [
23,
50
] | python | es | ['es', 'pl', 'it'] | False |
ConfigEntryNetatmoAuth.refresh_tokens | (
self,
) | Refresh and return new Netatmo tokens using Home Assistant OAuth2 session. | Refresh and return new Netatmo tokens using Home Assistant OAuth2 session. | def refresh_tokens(
self,
) -> dict:
"""Refresh and return new Netatmo tokens using Home Assistant OAuth2 session."""
run_coroutine_threadsafe(
self.session.async_ensure_token_valid(), self.hass.loop
).result()
return self.session.token | [
"def",
"refresh_tokens",
"(",
"self",
",",
")",
"->",
"dict",
":",
"run_coroutine_threadsafe",
"(",
"self",
".",
"session",
".",
"async_ensure_token_valid",
"(",
")",
",",
"self",
".",
"hass",
".",
"loop",
")",
".",
"result",
"(",
")",
"return",
"self",
... | [
25,
4
] | [
33,
33
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config) | Set up the EnOcean component. | Set up the EnOcean component. | async def async_setup(hass, config):
"""Set up the EnOcean component."""
# support for text-based configuration (legacy)
if DOMAIN not in config:
return True
if hass.config_entries.async_entries(DOMAIN):
# We can only have one dongle. If there is already one in the config,
# the... | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"# support for text-based configuration (legacy)",
"if",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"True",
"if",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"... | [
17,
0
] | [
34,
15
] | python | en | ['en', 'fr', 'en'] | True |
async_setup_entry | (
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
) | Set up an EnOcean dongle for the given entry. | Set up an EnOcean dongle for the given entry. | async def async_setup_entry(
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
):
"""Set up an EnOcean dongle for the given entry."""
enocean_data = hass.data.setdefault(DATA_ENOCEAN, {})
usb_dongle = EnOceanDongle(hass, config_entry.data[CONF_DEVICE])
await usb_dongle.async_setup()... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"config_entry",
":",
"config_entries",
".",
"ConfigEntry",
")",
":",
"enocean_data",
"=",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DATA_ENOCEAN",
",",
"{",
"}",
")... | [
37,
0
] | [
46,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, config_entry) | Unload ENOcean config entry. | Unload ENOcean config entry. | async def async_unload_entry(hass, config_entry):
"""Unload ENOcean config entry."""
enocean_dongle = hass.data[DATA_ENOCEAN][ENOCEAN_DONGLE]
enocean_dongle.unload()
hass.data.pop(DATA_ENOCEAN)
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"enocean_dongle",
"=",
"hass",
".",
"data",
"[",
"DATA_ENOCEAN",
"]",
"[",
"ENOCEAN_DONGLE",
"]",
"enocean_dongle",
".",
"unload",
"(",
")",
"hass",
".",
"data",
".",
"pop",
... | [
49,
0
] | [
56,
15
] | python | en | ['nb', 'es', 'en'] | False |
test_sensor_setup | (hass, requests_mock) | Test for successfully setting up the SleepIQ platform. | Test for successfully setting up the SleepIQ platform. | async def test_sensor_setup(hass, requests_mock):
"""Test for successfully setting up the SleepIQ platform."""
mock_responses(requests_mock)
await async_setup_component(hass, "sleepiq", {"sleepiq": CONFIG})
device_mock = MagicMock()
sleepiq.setup_platform(hass, CONFIG, device_mock, MagicMock())
... | [
"async",
"def",
"test_sensor_setup",
"(",
"hass",
",",
"requests_mock",
")",
":",
"mock_responses",
"(",
"requests_mock",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sleepiq\"",
",",
"{",
"\"sleepiq\"",
":",
"CONFIG",
"}",
")",
"device_mock",
"="... | [
10,
0
] | [
27,
36
] | python | en | ['en', 'en', 'en'] | True |
test_setup_single | (hass, requests_mock) | Test for successfully setting up the SleepIQ platform. | Test for successfully setting up the SleepIQ platform. | async def test_setup_single(hass, requests_mock):
"""Test for successfully setting up the SleepIQ platform."""
mock_responses(requests_mock, single=True)
await async_setup_component(hass, "sleepiq", {"sleepiq": CONFIG})
device_mock = MagicMock()
sleepiq.setup_platform(hass, CONFIG, device_mock, Ma... | [
"async",
"def",
"test_setup_single",
"(",
"hass",
",",
"requests_mock",
")",
":",
"mock_responses",
"(",
"requests_mock",
",",
"single",
"=",
"True",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sleepiq\"",
",",
"{",
"\"sleepiq\"",
":",
"CONFIG",
... | [
30,
0
] | [
43,
35
] | python | en | ['en', 'en', 'en'] | True |
convert_dt_to_timestamp | (dt_list) |
returns a list with the timesince unix time for a given list of datetimes
:param dt_list:
:return:
|
returns a list with the timesince unix time for a given list of datetimes
:param dt_list:
:return:
| def convert_dt_to_timestamp(dt_list):
"""
returns a list with the timesince unix time for a given list of datetimes
:param dt_list:
:return:
"""
timestamp= [(dt - datetime.datetime(1970, 1, 1)).total_seconds() for dt in dt_list]
return timestamp | [
"def",
"convert_dt_to_timestamp",
"(",
"dt_list",
")",
":",
"timestamp",
"=",
"[",
"(",
"dt",
"-",
"datetime",
".",
"datetime",
"(",
"1970",
",",
"1",
",",
"1",
")",
")",
".",
"total_seconds",
"(",
")",
"for",
"dt",
"in",
"dt_list",
"]",
"return",
"t... | [
16,
0
] | [
23,
20
] | python | en | ['en', 'error', 'th'] | False |
convert_datetime_julian_day | (dt_list) | returns the day number for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: list of the julian day for each date
| returns the day number for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: list of the julian day for each date
| def convert_datetime_julian_day(dt_list):
""" returns the day number for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: list of the julian day for each date
"""
day = [(d - datetime.datetime(d.year, 1, 1)).days + 1 for d in dt_list]
return day | [
"def",
"convert_datetime_julian_day",
"(",
"dt_list",
")",
":",
"day",
"=",
"[",
"(",
"d",
"-",
"datetime",
".",
"datetime",
"(",
"d",
".",
"year",
",",
"1",
",",
"1",
")",
")",
".",
"days",
"+",
"1",
"for",
"d",
"in",
"dt_list",
"]",
"return",
"... | [
25,
0
] | [
31,
14
] | python | en | ['en', 'en', 'en'] | True |
convert_unix_time_seconds_to_dt | (uts_list) | converts list of timestamps of seconds since the start of unix time to datetime objects
:param uts_list: a list of times in seconds since the start of unix time
:return: dt_list: list of datetime objects
| converts list of timestamps of seconds since the start of unix time to datetime objects
:param uts_list: a list of times in seconds since the start of unix time
:return: dt_list: list of datetime objects
| def convert_unix_time_seconds_to_dt(uts_list):
""" converts list of timestamps of seconds since the start of unix time to datetime objects
:param uts_list: a list of times in seconds since the start of unix time
:return: dt_list: list of datetime objects
"""
dt_list = []
for i in range(len(uts_l... | [
"def",
"convert_unix_time_seconds_to_dt",
"(",
"uts_list",
")",
":",
"dt_list",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"uts_list",
")",
")",
":",
"dt_list",
".",
"append",
"(",
"datetime",
".",
"datetime",
".",
"utcfromtimestamp",
"(",
... | [
34,
0
] | [
42,
18
] | python | en | ['en', 'en', 'en'] | True |
make_regular_timeseries | (start_dt, stop_dt, num_secs) |
makes a regular timeseries between two points. The difference between the start and end points must be a multiple of the num_secs
:param start_dt: first datetime required
:param stop_dt: last datetime required
:param num_secs: number of seconds in timestep required
:return: list of datetime objects... |
makes a regular timeseries between two points. The difference between the start and end points must be a multiple of the num_secs
:param start_dt: first datetime required
:param stop_dt: last datetime required
:param num_secs: number of seconds in timestep required
:return: list of datetime objects... | def make_regular_timeseries(start_dt, stop_dt, num_secs):
"""
makes a regular timeseries between two points. The difference between the start and end points must be a multiple of the num_secs
:param start_dt: first datetime required
:param stop_dt: last datetime required
:param num_secs: number of s... | [
"def",
"make_regular_timeseries",
"(",
"start_dt",
",",
"stop_dt",
",",
"num_secs",
")",
":",
"epoch",
"=",
"datetime",
".",
"datetime",
".",
"utcfromtimestamp",
"(",
"0",
")",
"st",
"=",
"(",
"start_dt",
"-",
"epoch",
")",
".",
"total_seconds",
"(",
")",
... | [
45,
0
] | [
58,
57
] | python | en | ['en', 'error', 'th'] | False |
convert_dt_to_hourdec | (dt_list) |
convert datetime to decimal hour
:param dt_list:
:return:
|
convert datetime to decimal hour
:param dt_list:
:return:
| def convert_dt_to_hourdec(dt_list):
"""
convert datetime to decimal hour
:param dt_list:
:return:
"""
decimal_hour = [dt1.hour + dt1.minute / 60. + dt1.second / 3600. + dt1.microsecond / 3600000. for dt1 in dt_list]
return np.asarray(decimal_hour) | [
"def",
"convert_dt_to_hourdec",
"(",
"dt_list",
")",
":",
"decimal_hour",
"=",
"[",
"dt1",
".",
"hour",
"+",
"dt1",
".",
"minute",
"/",
"60.",
"+",
"dt1",
".",
"second",
"/",
"3600.",
"+",
"dt1",
".",
"microsecond",
"/",
"3600000.",
"for",
"dt1",
"in",... | [
61,
0
] | [
69,
35
] | python | en | ['en', 'error', 'th'] | False |
convert_datetime_decimal_day | (dt_list) | returns the decimal day number for each datetime object in dt_list
:param dt_list: list of datetime objects to evaluate
:return: numpy array of the decimal day for each datetime
| returns the decimal day number for each datetime object in dt_list
:param dt_list: list of datetime objects to evaluate
:return: numpy array of the decimal day for each datetime
| def convert_datetime_decimal_day(dt_list):
""" returns the decimal day number for each datetime object in dt_list
:param dt_list: list of datetime objects to evaluate
:return: numpy array of the decimal day for each datetime
"""
timestamp = np.zeros(len(dt_list))
for i in range(len(dt_list)):
... | [
"def",
"convert_datetime_decimal_day",
"(",
"dt_list",
")",
":",
"timestamp",
"=",
"np",
".",
"zeros",
"(",
"len",
"(",
"dt_list",
")",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"dt_list",
")",
")",
":",
"timestamp",
"[",
"i",
"]",
"=",
"(",
... | [
72,
0
] | [
80,
20
] | python | en | ['en', 'en', 'en'] | True |
convert_date_hydro_DOY | (d_list, hemis='south') | returns the day of the hydrological year for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: array containing the day of the hydological year for each date
| returns the day of the hydrological year for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: array containing the day of the hydological year for each date
| def convert_date_hydro_DOY(d_list, hemis='south'):
""" returns the day of the hydrological year for each date object in d_list
:param d_list: list of dateobjects to evaluate
:return: array containing the day of the hydological year for each date
"""
if hemis == 'south':
end_month = 3
el... | [
"def",
"convert_date_hydro_DOY",
"(",
"d_list",
",",
"hemis",
"=",
"'south'",
")",
":",
"if",
"hemis",
"==",
"'south'",
":",
"end_month",
"=",
"3",
"elif",
"hemis",
"==",
"'north'",
":",
"end_month",
"=",
"9",
"h_DOY",
"=",
"[",
"]",
"for",
"d",
"in",
... | [
83,
0
] | [
98,
28
] | python | en | ['en', 'en', 'en'] | True |
convert_hydro_DOY_to_date | (h_DOY, year, hemis='south') | converts day of the hydrological year into a datetime object
:param d_list: array containing day of the hydological year
:param year: the hydrological year the data is from . hydrological years are denoted by the year of the last day
of the HY i.e. 2011 is HY ending 31 March 2011 in the SH
:return: arr... | converts day of the hydrological year into a datetime object
:param d_list: array containing day of the hydological year
:param year: the hydrological year the data is from . hydrological years are denoted by the year of the last day
of the HY i.e. 2011 is HY ending 31 March 2011 in the SH
:return: arr... | def convert_hydro_DOY_to_date(h_DOY, year, hemis='south'):
""" converts day of the hydrological year into a datetime object
:param d_list: array containing day of the hydological year
:param year: the hydrological year the data is from . hydrological years are denoted by the year of the last day
of the ... | [
"def",
"convert_hydro_DOY_to_date",
"(",
"h_DOY",
",",
"year",
",",
"hemis",
"=",
"'south'",
")",
":",
"if",
"hemis",
"==",
"'south'",
":",
"epoch",
"=",
"datetime",
".",
"date",
"(",
"year",
"-",
"1",
",",
"4",
",",
"1",
")",
"elif",
"hemis",
"==",
... | [
101,
0
] | [
115,
24
] | python | en | ['en', 'en', 'en'] | True |
process_precip | (precip_daily, one_day=False) |
Generate hourly precip fields using a multiplicative cascade model
Described in Rupp et al 2009 (http://onlinelibrary.wiley.com/doi/10.1029/2008WR007321/pdf)
:param model:
:return:
|
Generate hourly precip fields using a multiplicative cascade model | def process_precip(precip_daily, one_day=False):
"""
Generate hourly precip fields using a multiplicative cascade model
Described in Rupp et al 2009 (http://onlinelibrary.wiley.com/doi/10.1029/2008WR007321/pdf)
:param model:
:return:
"""
if one_day == True: # assume is 2d and add a time ... | [
"def",
"process_precip",
"(",
"precip_daily",
",",
"one_day",
"=",
"False",
")",
":",
"if",
"one_day",
"==",
"True",
":",
"# assume is 2d and add a time dimension on the start",
"precip_daily",
"=",
"precip_daily",
".",
"reshape",
"(",
"[",
"1",
",",
"precip_daily",... | [
120,
0
] | [
148,
41
] | python | en | ['en', 'error', 'th'] | False |
random_cascade | (l) |
A recursive implementation of a Multiplicative Random Cascade (MRC)
:param l: The size of the resulting output. Must be divisible by 2
:return: Weights that sum to 1.0
|
A recursive implementation of a Multiplicative Random Cascade (MRC) | def random_cascade(l):
"""
A recursive implementation of a Multiplicative Random Cascade (MRC)
:param l: The size of the resulting output. Must be divisible by 2
:return: Weights that sum to 1.0
"""
res = np.ones(l)
if l <= 3:
res = np.random.random(l)
res /= res.sum()
... | [
"def",
"random_cascade",
"(",
"l",
")",
":",
"res",
"=",
"np",
".",
"ones",
"(",
"l",
")",
"if",
"l",
"<=",
"3",
":",
"res",
"=",
"np",
".",
"random",
".",
"random",
"(",
"l",
")",
"res",
"/=",
"res",
".",
"sum",
"(",
")",
"return",
"res",
... | [
151,
0
] | [
170,
14
] | python | en | ['en', 'error', 'th'] | False |
process_temp | (max_temp_daily, min_temp_daily) |
Generate hourly fields
Sine curve through max/min. 2pm/8am for max, min as a first gues
:param model:
:return:
|
Generate hourly fields | def process_temp(max_temp_daily, min_temp_daily):
"""
Generate hourly fields
Sine curve through max/min. 2pm/8am for max, min as a first gues
:param model:
:return:
"""
def hour_func(dec_hours):
"""
Piecewise fit to daily tmax and tmin using sine curves
"""
... | [
"def",
"process_temp",
"(",
"max_temp_daily",
",",
"min_temp_daily",
")",
":",
"def",
"hour_func",
"(",
"dec_hours",
")",
":",
"\"\"\"\n Piecewise fit to daily tmax and tmin using sine curves\n \"\"\"",
"f",
"=",
"np",
".",
"piecewise",
"(",
"dec_hours",
","... | [
173,
0
] | [
210,
22
] | python | en | ['en', 'error', 'th'] | False |
create_mask_from_shpfile | (lat, lon, shp_path, idx=0) |
Creates a mask for numpy array
creates a boolean array on the same grid as lat,long where all cells,
whose centroid is inside a line shapefile, are true. The shapefile must be
a line, in the same CRS as the data, and have only 1 feature (only the first
feature will be used as a mask)
:param l... |
Creates a mask for numpy array | def create_mask_from_shpfile(lat, lon, shp_path, idx=0):
"""
Creates a mask for numpy array
creates a boolean array on the same grid as lat,long where all cells,
whose centroid is inside a line shapefile, are true. The shapefile must be
a line, in the same CRS as the data, and have only 1 feature (... | [
"def",
"create_mask_from_shpfile",
"(",
"lat",
",",
"lon",
",",
"shp_path",
",",
"idx",
"=",
"0",
")",
":",
"lat",
"=",
"np",
".",
"asarray",
"(",
"lat",
")",
"lon",
"=",
"np",
".",
"asarray",
"(",
"lon",
")",
"# load shapefile",
"shp",
"=",
"shapefi... | [
223,
0
] | [
264,
15
] | python | en | ['en', 'error', 'th'] | False |
nztm_to_wgs84 | (in_y, in_x) | converts from NZTM to WGS84 Inputs and outputs can be arrays.
| converts from NZTM to WGS84 Inputs and outputs can be arrays.
| def nztm_to_wgs84(in_y, in_x):
"""converts from NZTM to WGS84 Inputs and outputs can be arrays.
"""
inProj = Proj(init='epsg:2193')
outProj = Proj(init='epsg:4326')
out_x, out_y = transform(inProj, outProj, in_x, in_y)
return out_y, out_x | [
"def",
"nztm_to_wgs84",
"(",
"in_y",
",",
"in_x",
")",
":",
"inProj",
"=",
"Proj",
"(",
"init",
"=",
"'epsg:2193'",
")",
"outProj",
"=",
"Proj",
"(",
"init",
"=",
"'epsg:4326'",
")",
"out_x",
",",
"out_y",
"=",
"transform",
"(",
"inProj",
",",
"outProj... | [
267,
0
] | [
273,
23
] | python | en | ['en', 'en', 'en'] | True |
resample_to_fsca | (snow_grid, rl) |
:param snow_grid: grid of fractional or binary (0/1 snow)
:param rl: resample length - the number of grid cells in each direction to include in new fsca. e.g. 5 = 25 grid points to fsca
:return: fcsa = fractional snow covered area for the same area as snow_grid, but may be smaller if grid size is not a m... | def resample_to_fsca(snow_grid, rl):
"""
:param snow_grid: grid of fractional or binary (0/1 snow)
:param rl: resample length - the number of grid cells in each direction to include in new fsca. e.g. 5 = 25 grid points to fsca
:return: fcsa = fractional snow covered area for the same area as snow_grid... | [
"def",
"resample_to_fsca",
"(",
"snow_grid",
",",
"rl",
")",
":",
"ny",
"=",
"snow_grid",
".",
"shape",
"[",
"0",
"]",
"nx",
"=",
"snow_grid",
".",
"shape",
"[",
"1",
"]",
"ny_out",
"=",
"ny",
"//",
"rl",
"# integer divide to ensure fits",
"nx_out",
"=",... | [
294,
0
] | [
313,
15
] | python | en | ['en', 'error', 'th'] | False | |
calc_toa | (lat_ref, lon_ref, hourly_dt) |
calculate top of atmopshere radiation for given lat, lon and datetime
:param lat_ref:
:param lon_ref:
:param hourly_dt:
:return:
|
calculate top of atmopshere radiation for given lat, lon and datetime
:param lat_ref:
:param lon_ref:
:param hourly_dt:
:return:
| def calc_toa(lat_ref, lon_ref, hourly_dt):
"""
calculate top of atmopshere radiation for given lat, lon and datetime
:param lat_ref:
:param lon_ref:
:param hourly_dt:
:return:
"""
dtstep = (hourly_dt[1] - hourly_dt[0]).total_seconds()
# compute at midpoint between timestep and previo... | [
"def",
"calc_toa",
"(",
"lat_ref",
",",
"lon_ref",
",",
"hourly_dt",
")",
":",
"dtstep",
"=",
"(",
"hourly_dt",
"[",
"1",
"]",
"-",
"hourly_dt",
"[",
"0",
"]",
")",
".",
"total_seconds",
"(",
")",
"# compute at midpoint between timestep and previous timestep",
... | [
318,
0
] | [
350,
16
] | python | en | ['en', 'error', 'th'] | False |
setup_nztm_dem | (dem_file, extent_w=1.2e6, extent_e=1.4e6, extent_n=5.13e6, extent_s=4.82e6, resolution=250, origin='bottomleft') |
load dem tif file. defaults to clutha 250 dem.
:param dem_file: string specifying path to dem
:param extent_w: extent in nztm
:param extent_e: extent in nztm
:param extent_n: extent in nztm
:param extent_s: extent in nztm
:param resolution: resolution in m
:param origin: option to speci... |
load dem tif file. defaults to clutha 250 dem.
:param dem_file: string specifying path to dem
:param extent_w: extent in nztm
:param extent_e: extent in nztm
:param extent_n: extent in nztm
:param extent_s: extent in nztm
:param resolution: resolution in m
:param origin: option to speci... | def setup_nztm_dem(dem_file, extent_w=1.2e6, extent_e=1.4e6, extent_n=5.13e6, extent_s=4.82e6, resolution=250, origin='bottomleft'):
"""
load dem tif file. defaults to clutha 250 dem.
:param dem_file: string specifying path to dem
:param extent_w: extent in nztm
:param extent_e: extent in nztm
:... | [
"def",
"setup_nztm_dem",
"(",
"dem_file",
",",
"extent_w",
"=",
"1.2e6",
",",
"extent_e",
"=",
"1.4e6",
",",
"extent_n",
"=",
"5.13e6",
",",
"extent_s",
"=",
"4.82e6",
",",
"resolution",
"=",
"250",
",",
"origin",
"=",
"'bottomleft'",
")",
":",
"if",
"de... | [
353,
0
] | [
390,
63
] | python | en | ['en', 'error', 'th'] | False |
trim_data_to_mask | (data, mask) |
# trim data to minimum box needed for mask
:param data: 2D (x,y) or 3D (time,x,y) array
:param mask: 2D boolean with same x,y dimensions as data
:return: data trimmed
|
# trim data to minimum box needed for mask
:param data: 2D (x,y) or 3D (time,x,y) array
:param mask: 2D boolean with same x,y dimensions as data
:return: data trimmed
| def trim_data_to_mask(data, mask):
"""
# trim data to minimum box needed for mask
:param data: 2D (x,y) or 3D (time,x,y) array
:param mask: 2D boolean with same x,y dimensions as data
:return: data trimmed
"""
valid_lat_bounds = np.nonzero(mask.sum(axis=1))[0]
lat_min_idx = valid_lat_bou... | [
"def",
"trim_data_to_mask",
"(",
"data",
",",
"mask",
")",
":",
"valid_lat_bounds",
"=",
"np",
".",
"nonzero",
"(",
"mask",
".",
"sum",
"(",
"axis",
"=",
"1",
")",
")",
"[",
"0",
"]",
"lat_min_idx",
"=",
"valid_lat_bounds",
".",
"min",
"(",
")",
"lat... | [
393,
0
] | [
414,
23
] | python | en | ['en', 'error', 'th'] | False |
nash_sut | (y_sim, y_obs) |
calculate the nash_sutcliffe efficiency criterion (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
|
calculate the nash_sutcliffe efficiency criterion (taken from Ayala, 2017, WRR) | def nash_sut(y_sim, y_obs):
"""
calculate the nash_sutcliffe efficiency criterion (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
"""
assert y_sim.ndim == 1 and y_obs.ndim == 1
ns = 1 - np.sum((y_sim - y_obs) ** 2)... | [
"def",
"nash_sut",
"(",
"y_sim",
",",
"y_obs",
")",
":",
"assert",
"y_sim",
".",
"ndim",
"==",
"1",
"and",
"y_obs",
".",
"ndim",
"==",
"1",
"ns",
"=",
"1",
"-",
"np",
".",
"sum",
"(",
"(",
"y_sim",
"-",
"y_obs",
")",
"**",
"2",
")",
"/",
"np"... | [
417,
0
] | [
429,
13
] | python | en | ['en', 'error', 'th'] | False |
mean_bias | (y_sim, y_obs) |
calculate the mean bias difference (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
|
calculate the mean bias difference (taken from Ayala, 2017, WRR) | def mean_bias(y_sim, y_obs):
"""
calculate the mean bias difference (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
"""
assert y_sim.ndim == 1 and y_obs.ndim == 1 and len(y_sim) == len(y_obs)
mbd = np.sum(y_sim - y... | [
"def",
"mean_bias",
"(",
"y_sim",
",",
"y_obs",
")",
":",
"assert",
"y_sim",
".",
"ndim",
"==",
"1",
"and",
"y_obs",
".",
"ndim",
"==",
"1",
"and",
"len",
"(",
"y_sim",
")",
"==",
"len",
"(",
"y_obs",
")",
"mbd",
"=",
"np",
".",
"sum",
"(",
"y_... | [
432,
0
] | [
444,
14
] | python | en | ['en', 'error', 'th'] | False |
rmsd | (y_sim, y_obs) |
calculate the mean bias difference (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
|
calculate the mean bias difference (taken from Ayala, 2017, WRR) | def rmsd(y_sim, y_obs):
"""
calculate the mean bias difference (taken from Ayala, 2017, WRR)
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
"""
assert y_sim.ndim == 1 and y_obs.ndim == 1 and len(y_sim) == len(y_obs)
rs = np.sqrt(np.mean((y_sim... | [
"def",
"rmsd",
"(",
"y_sim",
",",
"y_obs",
")",
":",
"assert",
"y_sim",
".",
"ndim",
"==",
"1",
"and",
"y_obs",
".",
"ndim",
"==",
"1",
"and",
"len",
"(",
"y_sim",
")",
"==",
"len",
"(",
"y_obs",
")",
"rs",
"=",
"np",
".",
"sqrt",
"(",
"np",
... | [
447,
0
] | [
459,
13
] | python | en | ['en', 'error', 'th'] | False |
mean_absolute_error | (y_sim, y_obs) |
calculate the mean absolute error
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
|
calculate the mean absolute error | def mean_absolute_error(y_sim, y_obs):
"""
calculate the mean absolute error
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
"""
assert y_sim.ndim == 1 and y_obs.ndim == 1 and len(y_sim) == len(y_obs)
mbd = np.sum(np.abs(y_sim - y_obs)) / len(y... | [
"def",
"mean_absolute_error",
"(",
"y_sim",
",",
"y_obs",
")",
":",
"assert",
"y_sim",
".",
"ndim",
"==",
"1",
"and",
"y_obs",
".",
"ndim",
"==",
"1",
"and",
"len",
"(",
"y_sim",
")",
"==",
"len",
"(",
"y_obs",
")",
"mbd",
"=",
"np",
".",
"sum",
... | [
462,
0
] | [
474,
14
] | python | en | ['en', 'error', 'th'] | False |
coef_determ | (y_sim, y_obs) |
calculate the coefficient of determination
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
|
calculate the coefficient of determination | def coef_determ(y_sim, y_obs):
"""
calculate the coefficient of determination
:param y_sim: series of simulated values
:param y_obs: series of observed values
:return:
"""
assert y_sim.ndim == 1 and y_obs.ndim == 1 and len(y_sim) == len(y_obs)
r = np.corrcoef(y_sim, y_obs)
r2 = r[0... | [
"def",
"coef_determ",
"(",
"y_sim",
",",
"y_obs",
")",
":",
"assert",
"y_sim",
".",
"ndim",
"==",
"1",
"and",
"y_obs",
".",
"ndim",
"==",
"1",
"and",
"len",
"(",
"y_sim",
")",
"==",
"len",
"(",
"y_obs",
")",
"r",
"=",
"np",
".",
"corrcoef",
"(",
... | [
477,
0
] | [
490,
13
] | python | en | ['en', 'error', 'th'] | False |
basemap_interp | (datain, xin, yin, xout, yout, interpolation='NearestNeighbour') |
Interpolates a 2D array onto a new grid (only works for linear grids),
with the Lat/Lon inputs of the old and new grid. Can perfom nearest
neighbour interpolation or bilinear interpolation (of order 1)'
This is an extract from the basemap module (truncated)
|
Interpolates a 2D array onto a new grid (only works for linear grids),
with the Lat/Lon inputs of the old and new grid. Can perfom nearest
neighbour interpolation or bilinear interpolation (of order 1)' | def basemap_interp(datain, xin, yin, xout, yout, interpolation='NearestNeighbour'):
"""
Interpolates a 2D array onto a new grid (only works for linear grids),
with the Lat/Lon inputs of the old and new grid. Can perfom nearest
neighbour interpolation or bilinear interpolation (of order 1)'
... | [
"def",
"basemap_interp",
"(",
"datain",
",",
"xin",
",",
"yin",
",",
"xout",
",",
"yout",
",",
"interpolation",
"=",
"'NearestNeighbour'",
")",
":",
"# Mesh Coordinates so that they are both 2D arrays",
"xout",
",",
"yout",
"=",
"np",
".",
"meshgrid",
"(",
"xout... | [
493,
0
] | [
536,
18
] | python | en | ['en', 'error', 'th'] | False |
fill_timeseries_dud | (inp_dt, inp_dat, tstep, max_gap=None) |
fill in gaps in a timeseries using linear interpolation between valid points (method doesn't work that well)
:param inp_dt: array or list of datetimes corresponding to your data
:param inp_dat: variable you wish to fill
:param tstep: timestep of data in seconds
:param max_gap: maximum gap to ... |
fill in gaps in a timeseries using linear interpolation between valid points (method doesn't work that well) | def fill_timeseries_dud(inp_dt, inp_dat, tstep, max_gap=None):
"""
fill in gaps in a timeseries using linear interpolation between valid points (method doesn't work that well)
:param inp_dt: array or list of datetimes corresponding to your data
:param inp_dat: variable you wish to fill
:param t... | [
"def",
"fill_timeseries_dud",
"(",
"inp_dt",
",",
"inp_dat",
",",
"tstep",
",",
"max_gap",
"=",
"None",
")",
":",
"assert",
"len",
"(",
"inp_dt",
")",
"==",
"len",
"(",
"inp_dat",
")",
"out_dt",
"=",
"[",
"]",
"out_dat",
"=",
"[",
"]",
"if",
"max_gap... | [
539,
0
] | [
571,
70
] | python | en | ['en', 'error', 'th'] | False |
fill_timeseries | (inp_dt, inp_dat, tstep) |
fill in gaps in a timeseries using linear interpolation between valid points
:param inp_dt: array or list of datetimes corresponding to your data
:param inp_dat: variable you wish to fill
:param tstep: timestep of data in seconds
:return: out_dt, out_dat (datetimes and data)
|
fill in gaps in a timeseries using linear interpolation between valid points | def fill_timeseries(inp_dt, inp_dat, tstep):
"""
fill in gaps in a timeseries using linear interpolation between valid points
:param inp_dt: array or list of datetimes corresponding to your data
:param inp_dat: variable you wish to fill
:param tstep: timestep of data in seconds
:return: out_dt,... | [
"def",
"fill_timeseries",
"(",
"inp_dt",
",",
"inp_dat",
",",
"tstep",
")",
":",
"assert",
"len",
"(",
"inp_dt",
")",
"==",
"len",
"(",
"inp_dat",
")",
"out_dt",
"=",
"make_regular_timeseries",
"(",
"inp_dt",
"[",
"0",
"]",
",",
"inp_dt",
"[",
"-",
"1"... | [
575,
0
] | [
589,
38
] | python | en | ['en', 'error', 'th'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up a D-Link Smart Plug. | Set up a D-Link Smart Plug. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up a D-Link Smart Plug."""
host = config[CONF_HOST]
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
use_legacy_protocol = config[CONF_USE_LEGACY_PROTOCOL]
name = config[CONF_NAME]
smartplug = Smar... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
"[",
"CONF_HOST",
"]",
"username",
"=",
"config",
"[",
"CONF_USERNAME",
"]",
"password",
"=",
"config",
"[",
"CON... | [
43,
0
] | [
55,
59
] | python | en | ['en', 'da', 'en'] | True |
SmartPlugSwitch.__init__ | (self, hass, data, name) | Initialize the switch. | Initialize the switch. | def __init__(self, hass, data, name):
"""Initialize the switch."""
self.units = hass.config.units
self.data = data
self._name = name | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"data",
",",
"name",
")",
":",
"self",
".",
"units",
"=",
"hass",
".",
"config",
".",
"units",
"self",
".",
"data",
"=",
"data",
"self",
".",
"_name",
"=",
"name"
] | [
61,
4
] | [
65,
25
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.name | (self) | Return the name of the Smart Plug. | Return the name of the Smart Plug. | def name(self):
"""Return the name of the Smart Plug."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
68,
4
] | [
70,
25
] | python | en | ['en', 'ceb', 'en'] | True |
SmartPlugSwitch.device_state_attributes | (self) | Return the state attributes of the device. | Return the state attributes of the device. | def device_state_attributes(self):
"""Return the state attributes of the device."""
try:
ui_temp = self.units.temperature(int(self.data.temperature), TEMP_CELSIUS)
temperature = ui_temp
except (ValueError, TypeError):
temperature = None
try:
... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"try",
":",
"ui_temp",
"=",
"self",
".",
"units",
".",
"temperature",
"(",
"int",
"(",
"self",
".",
"data",
".",
"temperature",
")",
",",
"TEMP_CELSIUS",
")",
"temperature",
"=",
"ui_temp",
"except",... | [
73,
4
] | [
91,
20
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.current_power_w | (self) | Return the current power usage in Watt. | Return the current power usage in Watt. | def current_power_w(self):
"""Return the current power usage in Watt."""
try:
return float(self.data.current_consumption)
except (ValueError, TypeError):
return None | [
"def",
"current_power_w",
"(",
"self",
")",
":",
"try",
":",
"return",
"float",
"(",
"self",
".",
"data",
".",
"current_consumption",
")",
"except",
"(",
"ValueError",
",",
"TypeError",
")",
":",
"return",
"None"
] | [
94,
4
] | [
99,
23
] | python | en | ['en', 'de', 'en'] | True |
SmartPlugSwitch.is_on | (self) | Return true if switch is on. | Return true if switch is on. | def is_on(self):
"""Return true if switch is on."""
return self.data.state == "ON" | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"state",
"==",
"\"ON\""
] | [
102,
4
] | [
104,
38
] | python | en | ['en', 'fy', 'en'] | True |
SmartPlugSwitch.turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | def turn_on(self, **kwargs):
"""Turn the switch on."""
self.data.smartplug.state = "ON" | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"data",
".",
"smartplug",
".",
"state",
"=",
"\"ON\""
] | [
106,
4
] | [
108,
40
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | def turn_off(self, **kwargs):
"""Turn the switch off."""
self.data.smartplug.state = "OFF" | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"data",
".",
"smartplug",
".",
"state",
"=",
"\"OFF\""
] | [
110,
4
] | [
112,
41
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.update | (self) | Get the latest data from the smart plug and updates the states. | Get the latest data from the smart plug and updates the states. | def update(self):
"""Get the latest data from the smart plug and updates the states."""
self.data.update() | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"data",
".",
"update",
"(",
")"
] | [
114,
4
] | [
116,
26
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
return self.data.available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"data",
".",
"available"
] | [
119,
4
] | [
121,
34
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugData.__init__ | (self, smartplug) | Initialize the data object. | Initialize the data object. | def __init__(self, smartplug):
"""Initialize the data object."""
self.smartplug = smartplug
self.state = None
self.temperature = None
self.current_consumption = None
self.total_consumption = None
self.available = False
self._n_tried = 0
self._last_... | [
"def",
"__init__",
"(",
"self",
",",
"smartplug",
")",
":",
"self",
".",
"smartplug",
"=",
"smartplug",
"self",
".",
"state",
"=",
"None",
"self",
".",
"temperature",
"=",
"None",
"self",
".",
"current_consumption",
"=",
"None",
"self",
".",
"total_consump... | [
127,
4
] | [
136,
31
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugData.update | (self) | Get the latest data from the smart plug. | Get the latest data from the smart plug. | def update(self):
"""Get the latest data from the smart plug."""
if self._last_tried is not None:
last_try_s = (dt_util.now() - self._last_tried).total_seconds() / 60
retry_seconds = min(self._n_tried * 2, 10) - last_try_s
if self._n_tried > 0 and retry_seconds > 0:
... | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"self",
".",
"_last_tried",
"is",
"not",
"None",
":",
"last_try_s",
"=",
"(",
"dt_util",
".",
"now",
"(",
")",
"-",
"self",
".",
"_last_tried",
")",
".",
"total_seconds",
"(",
")",
"/",
"60",
"retry_secon... | [
138,
4
] | [
166,
25
] | python | en | ['en', 'en', 'en'] | True |
async_register_webhook | (hass, webhook_id, entry_id) | Register a webhook. | Register a webhook. | def async_register_webhook(hass, webhook_id, entry_id):
"""Register a webhook."""
async def _async_handle_rachio_webhook(hass, webhook_id, request):
"""Handle webhook calls from the server."""
data = await request.json()
try:
auth = data.get(KEY_EXTERNAL_ID, "").split(":")[... | [
"def",
"async_register_webhook",
"(",
"hass",
",",
"webhook_id",
",",
"entry_id",
")",
":",
"async",
"def",
"_async_handle_rachio_webhook",
"(",
"hass",
",",
"webhook_id",
",",
"request",
")",
":",
"\"\"\"Handle webhook calls from the server.\"\"\"",
"data",
"=",
"awa... | [
86,
0
] | [
107,
5
] | python | en | ['en', 'lb', 'en'] | True |
async_get_or_create_registered_webhook_id_and_url | (hass, entry) | Generate webhook ID. | Generate webhook ID. | async def async_get_or_create_registered_webhook_id_and_url(hass, entry):
"""Generate webhook ID."""
config = entry.data.copy()
updated_config = False
webhook_url = None
webhook_id = config.get(CONF_WEBHOOK_ID)
if not webhook_id:
webhook_id = hass.components.webhook.async_generate_id()... | [
"async",
"def",
"async_get_or_create_registered_webhook_id_and_url",
"(",
"hass",
",",
"entry",
")",
":",
"config",
"=",
"entry",
".",
"data",
".",
"copy",
"(",
")",
"updated_config",
"=",
"False",
"webhook_url",
"=",
"None",
"webhook_id",
"=",
"config",
".",
... | [
110,
0
] | [
139,
34
] | python | en | ['en', 'zh', 'hi'] | False |
OneshotPruner.__init__ | (self, model, config_list, pruning_algorithm='level', dependency_aware=False, dummy_input=None,
**algo_kwargs) |
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
pruning_algorithm: str
algorithms being used to prune model
dependency_aware: bool
If prune the model in a dependen... |
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
pruning_algorithm: str
algorithms being used to prune model
dependency_aware: bool
If prune the model in a dependen... | def __init__(self, model, config_list, pruning_algorithm='level', dependency_aware=False, dummy_input=None,
**algo_kwargs):
"""
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"config_list",
",",
"pruning_algorithm",
"=",
"'level'",
",",
"dependency_aware",
"=",
"False",
",",
"dummy_input",
"=",
"None",
",",
"*",
"*",
"algo_kwargs",
")",
":",
"super",
"(",
")",
".",
"__init__",
... | [
20,
4
] | [
39,
115
] | python | en | ['en', 'error', 'th'] | False |
OneshotPruner.validate_config | (self, model, config_list) |
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
|
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
| def validate_config(self, model, config_list):
"""
Parameters
----------
model : torch.nn.Module
Model to be pruned
config_list : list
List on pruning configs
"""
schema = CompressorSchema([{
'sparsity': And(float, lambda n: 0 <... | [
"def",
"validate_config",
"(",
"self",
",",
"model",
",",
"config_list",
")",
":",
"schema",
"=",
"CompressorSchema",
"(",
"[",
"{",
"'sparsity'",
":",
"And",
"(",
"float",
",",
"lambda",
"n",
":",
"0",
"<",
"n",
"<",
"1",
")",
",",
"Optional",
"(",
... | [
41,
4
] | [
56,
36
] | python | en | ['en', 'error', 'th'] | False |
_improve_answer_span | (doc_tokens, input_start, input_end, tokenizer, orig_answer_text) | Returns tokenized answer spans that better match the annotated answer. | Returns tokenized answer spans that better match the annotated answer. | def _improve_answer_span(doc_tokens, input_start, input_end, tokenizer, orig_answer_text):
"""Returns tokenized answer spans that better match the annotated answer."""
tok_answer_text = " ".join(tokenizer.tokenize(orig_answer_text))
for new_start in range(input_start, input_end + 1):
for new_end in... | [
"def",
"_improve_answer_span",
"(",
"doc_tokens",
",",
"input_start",
",",
"input_end",
",",
"tokenizer",
",",
"orig_answer_text",
")",
":",
"tok_answer_text",
"=",
"\" \"",
".",
"join",
"(",
"tokenizer",
".",
"tokenize",
"(",
"orig_answer_text",
")",
")",
"for"... | [
43,
0
] | [
53,
35
] | python | en | ['en', 'en', 'en'] | True |
_check_is_max_context | (doc_spans, cur_span_index, position) | Check if this is the 'max context' doc span for the token. | Check if this is the 'max context' doc span for the token. | def _check_is_max_context(doc_spans, cur_span_index, position):
"""Check if this is the 'max context' doc span for the token."""
best_score = None
best_span_index = None
for (span_index, doc_span) in enumerate(doc_spans):
end = doc_span.start + doc_span.length - 1
if position < doc_span.... | [
"def",
"_check_is_max_context",
"(",
"doc_spans",
",",
"cur_span_index",
",",
"position",
")",
":",
"best_score",
"=",
"None",
"best_span_index",
"=",
"None",
"for",
"(",
"span_index",
",",
"doc_span",
")",
"in",
"enumerate",
"(",
"doc_spans",
")",
":",
"end",... | [
56,
0
] | [
73,
44
] | python | en | ['en', 'en', 'en'] | True |
_new_check_is_max_context | (doc_spans, cur_span_index, position) | Check if this is the 'max context' doc span for the token. | Check if this is the 'max context' doc span for the token. | def _new_check_is_max_context(doc_spans, cur_span_index, position):
"""Check if this is the 'max context' doc span for the token."""
# if len(doc_spans) == 1:
# return True
best_score = None
best_span_index = None
for (span_index, doc_span) in enumerate(doc_spans):
end = doc_span["start"... | [
"def",
"_new_check_is_max_context",
"(",
"doc_spans",
",",
"cur_span_index",
",",
"position",
")",
":",
"# if len(doc_spans) == 1:",
"# return True",
"best_score",
"=",
"None",
"best_span_index",
"=",
"None",
"for",
"(",
"span_index",
",",
"doc_span",
")",
"in",
"en... | [
76,
0
] | [
95,
44
] | python | en | ['en', 'en', 'en'] | True |
squad_convert_examples_to_features | (
examples,
tokenizer,
max_seq_length,
doc_stride,
max_query_length,
is_training,
padding_strategy="max_length",
return_dataset=False,
threads=1,
tqdm_enabled=True,
) |
Converts a list of examples into a list of features that can be directly given as input to a model. It is
model-dependant and takes advantage of many of the tokenizer's features to create the model's inputs.
Args:
examples: list of :class:`~transformers.data.processors.squad.SquadExample`
... |
Converts a list of examples into a list of features that can be directly given as input to a model. It is
model-dependant and takes advantage of many of the tokenizer's features to create the model's inputs. | def squad_convert_examples_to_features(
examples,
tokenizer,
max_seq_length,
doc_stride,
max_query_length,
is_training,
padding_strategy="max_length",
return_dataset=False,
threads=1,
tqdm_enabled=True,
):
"""
Converts a list of examples into a list of features that can b... | [
"def",
"squad_convert_examples_to_features",
"(",
"examples",
",",
"tokenizer",
",",
"max_seq_length",
",",
"doc_stride",
",",
"max_query_length",
",",
"is_training",
",",
"padding_strategy",
"=",
"\"max_length\"",
",",
"return_dataset",
"=",
"False",
",",
"threads",
... | [
317,
0
] | [
538,
23
] | python | en | ['en', 'error', 'th'] | False |
SquadProcessor.get_examples_from_dataset | (self, dataset, evaluate=False) |
Creates a list of :class:`~transformers.data.processors.squad.SquadExample` using a TFDS dataset.
Args:
dataset: The tfds dataset loaded from `tensorflow_datasets.load("squad")`
evaluate: Boolean specifying if in evaluation mode or in training mode
Returns:
... |
Creates a list of :class:`~transformers.data.processors.squad.SquadExample` using a TFDS dataset. | def get_examples_from_dataset(self, dataset, evaluate=False):
"""
Creates a list of :class:`~transformers.data.processors.squad.SquadExample` using a TFDS dataset.
Args:
dataset: The tfds dataset loaded from `tensorflow_datasets.load("squad")`
evaluate: Boolean specifyin... | [
"def",
"get_examples_from_dataset",
"(",
"self",
",",
"dataset",
",",
"evaluate",
"=",
"False",
")",
":",
"if",
"evaluate",
":",
"dataset",
"=",
"dataset",
"[",
"\"validation\"",
"]",
"else",
":",
"dataset",
"=",
"dataset",
"[",
"\"train\"",
"]",
"examples",... | [
574,
4
] | [
603,
23
] | python | en | ['en', 'error', 'th'] | False |
SquadProcessor.get_train_examples | (self, data_dir, filename=None) |
Returns the training examples from the data directory.
Args:
data_dir: Directory containing the data files used for training and evaluating.
filename: None by default, specify this if the training file has a different name than the original one
which is `train-v... |
Returns the training examples from the data directory. | def get_train_examples(self, data_dir, filename=None):
"""
Returns the training examples from the data directory.
Args:
data_dir: Directory containing the data files used for training and evaluating.
filename: None by default, specify this if the training file has a diff... | [
"def",
"get_train_examples",
"(",
"self",
",",
"data_dir",
",",
"filename",
"=",
"None",
")",
":",
"if",
"data_dir",
"is",
"None",
":",
"data_dir",
"=",
"\"\"",
"if",
"self",
".",
"train_file",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"SquadProcess... | [
605,
4
] | [
625,
57
] | python | en | ['en', 'error', 'th'] | False |
SquadProcessor.get_dev_examples | (self, data_dir, filename=None) |
Returns the evaluation example from the data directory.
Args:
data_dir: Directory containing the data files used for training and evaluating.
filename: None by default, specify this if the evaluation file has a different name than the original one
which is `dev-... |
Returns the evaluation example from the data directory. | def get_dev_examples(self, data_dir, filename=None):
"""
Returns the evaluation example from the data directory.
Args:
data_dir: Directory containing the data files used for training and evaluating.
filename: None by default, specify this if the evaluation file has a dif... | [
"def",
"get_dev_examples",
"(",
"self",
",",
"data_dir",
",",
"filename",
"=",
"None",
")",
":",
"if",
"data_dir",
"is",
"None",
":",
"data_dir",
"=",
"\"\"",
"if",
"self",
".",
"dev_file",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"SquadProcessor s... | [
627,
4
] | [
646,
55
] | python | en | ['en', 'error', 'th'] | False |
mock_panel_fixture | () | Mock a Konnected Panel bridge. | Mock a Konnected Panel bridge. | async def mock_panel_fixture():
"""Mock a Konnected Panel bridge."""
with patch("konnected.Client", autospec=True) as konn_client:
def mock_constructor(host, port, websession):
"""Fake the panel constructor."""
konn_client.host = host
konn_client.port = port
... | [
"async",
"def",
"mock_panel_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"konnected.Client\"",
",",
"autospec",
"=",
"True",
")",
"as",
"konn_client",
":",
"def",
"mock_constructor",
"(",
"host",
",",
"port",
",",
"websession",
")",
":",
"\"\"\"Fake the pa... | [
14,
0
] | [
40,
25
] | python | en | ['it', 'st', 'en'] | False |
test_config_schema | (hass) | Test that config schema is imported properly. | Test that config schema is imported properly. | async def test_config_schema(hass):
"""Test that config schema is imported properly."""
config = {
konnected.DOMAIN: {
konnected.CONF_API_HOST: "http://1.1.1.1:8888",
konnected.CONF_ACCESS_TOKEN: "abcdefgh",
konnected.CONF_DEVICES: [{konnected.CONF_ID: "aabbccddeeff"}... | [
"async",
"def",
"test_config_schema",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"konnected",
".",
"DOMAIN",
":",
"{",
"konnected",
".",
"CONF_API_HOST",
":",
"\"http://1.1.1.1:8888\"",
",",
"konnected",
".",
"CONF_ACCESS_TOKEN",
":",
"\"abcdefgh\"",
",",
"konne... | [
43,
0
] | [
217,
5
] | python | en | ['en', 'en', 'en'] | True |
test_setup_with_no_config | (hass) | Test that we do not discover anything or try to set up a Konnected panel. | Test that we do not discover anything or try to set up a Konnected panel. | async def test_setup_with_no_config(hass):
"""Test that we do not discover anything or try to set up a Konnected panel."""
assert await async_setup_component(hass, konnected.DOMAIN, {})
# No flows started
assert len(hass.config_entries.flow.async_progress()) == 0
# Nothing saved from configuration... | [
"async",
"def",
"test_setup_with_no_config",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"konnected",
".",
"DOMAIN",
",",
"{",
"}",
")",
"# No flows started",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"f... | [
220,
0
] | [
230,
68
] | python | en | ['en', 'en', 'en'] | True |
test_setup_defined_hosts_known_auth | (hass, mock_panel) | Test we don't initiate a config entry if configured panel is known. | Test we don't initiate a config entry if configured panel is known. | async def test_setup_defined_hosts_known_auth(hass, mock_panel):
"""Test we don't initiate a config entry if configured panel is known."""
MockConfigEntry(
domain="konnected",
unique_id="112233445566",
data={"host": "0.0.0.0", "id": "112233445566"},
).add_to_hass(hass)
MockConfig... | [
"async",
"def",
"test_setup_defined_hosts_known_auth",
"(",
"hass",
",",
"mock_panel",
")",
":",
"MockConfigEntry",
"(",
"domain",
"=",
"\"konnected\"",
",",
"unique_id",
"=",
"\"112233445566\"",
",",
"data",
"=",
"{",
"\"host\"",
":",
"\"0.0.0.0\"",
",",
"\"id\""... | [
233,
0
] | [
270,
62
] | python | en | ['en', 'en', 'en'] | True |
test_setup_defined_hosts_no_known_auth | (hass) | Test we initiate config entry if config panel is not known. | Test we initiate config entry if config panel is not known. | async def test_setup_defined_hosts_no_known_auth(hass):
"""Test we initiate config entry if config panel is not known."""
assert (
await async_setup_component(
hass,
konnected.DOMAIN,
{
konnected.DOMAIN: {
konnected.CONF_ACCESS_TOKE... | [
"async",
"def",
"test_setup_defined_hosts_no_known_auth",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"konnected",
".",
"DOMAIN",
",",
"{",
"konnected",
".",
"DOMAIN",
":",
"{",
"konnected",
".",
"CONF_ACCESS_TOKEN",
... | [
273,
0
] | [
290,
62
] | python | en | ['en', 'en', 'en'] | True |
test_setup_multiple | (hass) | Test we initiate config entry for multiple panels. | Test we initiate config entry for multiple panels. | async def test_setup_multiple(hass):
"""Test we initiate config entry for multiple panels."""
assert (
await async_setup_component(
hass,
konnected.DOMAIN,
{
konnected.DOMAIN: {
konnected.CONF_ACCESS_TOKEN: "arandomstringvalue",
... | [
"async",
"def",
"test_setup_multiple",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"konnected",
".",
"DOMAIN",
",",
"{",
"konnected",
".",
"DOMAIN",
":",
"{",
"konnected",
".",
"CONF_ACCESS_TOKEN",
":",
"\"arandoms... | [
293,
0
] | [
354,
5
] | python | en | ['en', 'en', 'en'] | True |
test_config_passed_to_config_entry | (hass) | Test that configured options for a host are loaded via config entry. | Test that configured options for a host are loaded via config entry. | async def test_config_passed_to_config_entry(hass):
"""Test that configured options for a host are loaded via config entry."""
entry = MockConfigEntry(
domain=konnected.DOMAIN,
data={config_flow.CONF_ID: "aabbccddeeff", config_flow.CONF_HOST: "0.0.0.0"},
)
entry.add_to_hass(hass)
wit... | [
"async",
"def",
"test_config_passed_to_config_entry",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"konnected",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"config_flow",
".",
"CONF_ID",
":",
"\"aabbccddeeff\"",
",",
"config_flow",
".",
... | [
357,
0
] | [
383,
27
] | python | en | ['en', 'en', 'en'] | True |
test_unload_entry | (hass, mock_panel) | Test being able to unload an entry. | Test being able to unload an entry. | async def test_unload_entry(hass, mock_panel):
"""Test being able to unload an entry."""
await async_process_ha_core_config(
hass,
{"internal_url": "http://example.local:8123"},
)
entry = MockConfigEntry(
domain=konnected.DOMAIN, data={konnected.CONF_ID: "aabbccddeeff"}
)
... | [
"async",
"def",
"test_unload_entry",
"(",
"hass",
",",
"mock_panel",
")",
":",
"await",
"async_process_ha_core_config",
"(",
"hass",
",",
"{",
"\"internal_url\"",
":",
"\"http://example.local:8123\"",
"}",
",",
")",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
... | [
386,
0
] | [
400,
55
] | python | en | ['en', 'en', 'en'] | True |
test_api | (hass, aiohttp_client, mock_panel) | Test callback view. | Test callback view. | async def test_api(hass, aiohttp_client, mock_panel):
"""Test callback view."""
await async_setup_component(hass, "http", {"http": {}})
device_config = config_flow.CONFIG_ENTRY_SCHEMA(
{
"host": "1.2.3.4",
"port": 1234,
"id": "112233445566",
"model": ... | [
"async",
"def",
"test_api",
"(",
"hass",
",",
"aiohttp_client",
",",
"mock_panel",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"http\"",
",",
"{",
"\"http\"",
":",
"{",
"}",
"}",
")",
"device_config",
"=",
"config_flow",
".",
"CONFIG_ENTR... | [
403,
0
] | [
567,
38
] | python | en | ['en', 'en', 'en'] | True |
test_state_updates_zone | (hass, aiohttp_client, mock_panel) | Test callback view. | Test callback view. | async def test_state_updates_zone(hass, aiohttp_client, mock_panel):
"""Test callback view."""
await async_process_ha_core_config(
hass,
{"internal_url": "http://example.local:8123"},
)
device_config = config_flow.CONFIG_ENTRY_SCHEMA(
{
"host": "1.2.3.4",
... | [
"async",
"def",
"test_state_updates_zone",
"(",
"hass",
",",
"aiohttp_client",
",",
"mock_panel",
")",
":",
"await",
"async_process_ha_core_config",
"(",
"hass",
",",
"{",
"\"internal_url\"",
":",
"\"http://example.local:8123\"",
"}",
",",
")",
"device_config",
"=",
... | [
570,
0
] | [
718,
71
] | python | en | ['en', 'en', 'en'] | True |
test_state_updates_pin | (hass, aiohttp_client, mock_panel) | Test callback view. | Test callback view. | async def test_state_updates_pin(hass, aiohttp_client, mock_panel):
"""Test callback view."""
await async_process_ha_core_config(
hass,
{"internal_url": "http://example.local:8123"},
)
device_config = config_flow.CONFIG_ENTRY_SCHEMA(
{
"host": "1.2.3.4",
... | [
"async",
"def",
"test_state_updates_pin",
"(",
"hass",
",",
"aiohttp_client",
",",
"mock_panel",
")",
":",
"await",
"async_process_ha_core_config",
"(",
"hass",
",",
"{",
"\"internal_url\"",
":",
"\"http://example.local:8123\"",
"}",
",",
")",
"device_config",
"=",
... | [
721,
0
] | [
873,
71
] | python | en | ['en', 'en', 'en'] | True |
_id | (value: str) | Coerce id by removing '-'. | Coerce id by removing '-'. | def _id(value: str) -> str:
"""Coerce id by removing '-'."""
return value.replace("-", "") | [
"def",
"_id",
"(",
"value",
":",
"str",
")",
"->",
"str",
":",
"return",
"value",
".",
"replace",
"(",
"\"-\"",
",",
"\"\"",
")"
] | [
30,
0
] | [
32,
33
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, hass_config) | Set up the Traccar component. | Set up the Traccar component. | async def async_setup(hass, hass_config):
"""Set up the Traccar component."""
hass.data[DOMAIN] = {"devices": set(), "unsub_device_tracker": {}}
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"hass_config",
")",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"{",
"\"devices\"",
":",
"set",
"(",
")",
",",
"\"unsub_device_tracker\"",
":",
"{",
"}",
"}",
"return",
"True"
] | [
50,
0
] | [
53,
15
] | python | en | ['en', 'en', 'en'] | True |
handle_webhook | (hass, webhook_id, request) | Handle incoming webhook with Traccar request. | Handle incoming webhook with Traccar request. | async def handle_webhook(hass, webhook_id, request):
"""Handle incoming webhook with Traccar request."""
try:
data = WEBHOOK_SCHEMA(dict(request.query))
except vol.MultipleInvalid as error:
return web.Response(text=error.error_message, status=HTTP_UNPROCESSABLE_ENTITY)
attrs = {
... | [
"async",
"def",
"handle_webhook",
"(",
"hass",
",",
"webhook_id",
",",
"request",
")",
":",
"try",
":",
"data",
"=",
"WEBHOOK_SCHEMA",
"(",
"dict",
"(",
"request",
".",
"query",
")",
")",
"except",
"vol",
".",
"MultipleInvalid",
"as",
"error",
":",
"retu... | [
56,
0
] | [
82,
78
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry) | Configure based on config entry. | Configure based on config entry. | async def async_setup_entry(hass, entry):
"""Configure based on config entry."""
hass.components.webhook.async_register(
DOMAIN, "Traccar", entry.data[CONF_WEBHOOK_ID], handle_webhook
)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, DEVICE_TRACKER)
)
... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
")",
":",
"hass",
".",
"components",
".",
"webhook",
".",
"async_register",
"(",
"DOMAIN",
",",
"\"Traccar\"",
",",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
",",
"handle_webhook",
")",... | [
85,
0
] | [
94,
15
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, entry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass, entry):
"""Unload a config entry."""
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
hass.data[DOMAIN]["unsub_device_tracker"].pop(entry.entry_id)()
await hass.config_entries.async_forward_entry_unload(entry, DEVICE_TRACKER)
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"entry",
")",
":",
"hass",
".",
"components",
".",
"webhook",
".",
"async_unregister",
"(",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"\"u... | [
97,
0
] | [
102,
15
] | python | en | ['en', 'es', 'en'] | True |
broadlink_setup_fixture | () | Mock broadlink entry setup. | Mock broadlink entry setup. | def broadlink_setup_fixture():
"""Mock broadlink entry setup."""
with patch(
"homeassistant.components.broadlink.async_setup", return_value=True
), patch("homeassistant.components.broadlink.async_setup_entry", return_value=True):
yield | [
"def",
"broadlink_setup_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.broadlink.async_setup\"",
",",
"return_value",
"=",
"True",
")",
",",
"patch",
"(",
"\"homeassistant.components.broadlink.async_setup_entry\"",
",",
"return_value",
"=",
"True... | [
19,
0
] | [
24,
13
] | python | en | ['en', 'da', 'en'] | True |
test_flow_user_works | (hass) | Test a config flow initiated by the user.
Best case scenario with no errors or locks.
| Test a config flow initiated by the user. | async def test_flow_user_works(hass):
"""Test a config flow initiated by the user.
Best case scenario with no errors or locks.
"""
device = get_device("Living Room")
mock_api = device.get_mock_api()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_e... | [
"async",
"def",
"test_flow_user_works",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async... | [
27,
0
] | [
63,
40
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_already_in_progress | (hass) | Test we do not accept more than one config flow per device. | Test we do not accept more than one config flow per device. | async def test_flow_user_already_in_progress(hass):
"""Test we do not accept more than one config flow per device."""
device = get_device("Living Room")
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY,... | [
"async",
"def",
"test_flow_user_already_in_progress",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{... | [
66,
0
] | [
91,
52
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_mac_already_configured | (hass) | Test we do not accept more than one config entry per device.
We need to abort the flow and update the existing entry.
| Test we do not accept more than one config entry per device. | async def test_flow_user_mac_already_configured(hass):
"""Test we do not accept more than one config entry per device.
We need to abort the flow and update the existing entry.
"""
device = get_device("Living Room")
mock_entry = device.get_mock_entry()
mock_entry.add_to_hass(hass)
result = ... | [
"async",
"def",
"test_flow_user_mac_already_configured",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_entry",
"=",
"device",
".",
"get_mock_entry",
"(",
")",
"mock_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
... | [
94,
0
] | [
121,
40
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_invalid_ip_address | (hass) | Test we handle an invalid IP address in the user step. | Test we handle an invalid IP address in the user step. | async def test_flow_user_invalid_ip_address(hass):
"""Test we handle an invalid IP address in the user step."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, side_effect=OSError(errno.EINVAL, None)):
... | [
"async",
"def",
"test_flow_user_invalid_ip_address",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
... | [
124,
0
] | [
138,
55
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_invalid_hostname | (hass) | Test we handle an invalid hostname in the user step. | Test we handle an invalid hostname in the user step. | async def test_flow_user_invalid_hostname(hass):
"""Test we handle an invalid hostname in the user step."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, side_effect=OSError(socket.EAI_NONAME, None)):
... | [
"async",
"def",
"test_flow_user_invalid_hostname",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"... | [
141,
0
] | [
155,
55
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_device_not_found | (hass) | Test we handle a device not found in the user step. | Test we handle a device not found in the user step. | async def test_flow_user_device_not_found(hass):
"""Test we handle a device not found in the user step."""
device = get_device("Living Room")
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, return_val... | [
"async",
"def",
"test_flow_user_device_not_found",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
... | [
158,
0
] | [
174,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_device_not_supported | (hass) | Test we handle a device not supported in the user step. | Test we handle a device not supported in the user step. | async def test_flow_user_device_not_supported(hass):
"""Test we handle a device not supported in the user step."""
device = get_device("Kitchen")
mock_api = device.get_mock_api()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
... | [
"async",
"def",
"test_flow_user_device_not_supported",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Kitchen\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".... | [
177,
0
] | [
193,
46
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_network_unreachable | (hass) | Test we handle a network unreachable in the user step. | Test we handle a network unreachable in the user step. | async def test_flow_user_network_unreachable(hass):
"""Test we handle a network unreachable in the user step."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, side_effect=OSError(errno.ENETUNREACH, None)... | [
"async",
"def",
"test_flow_user_network_unreachable",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
... | [
196,
0
] | [
210,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_user_os_error | (hass) | Test we handle an OS error in the user step. | Test we handle an OS error in the user step. | async def test_flow_user_os_error(hass):
"""Test we handle an OS error in the user step."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, side_effect=OSError()):
result = await hass.config_entrie... | [
"async",
"def",
"test_flow_user_os_error",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")... | [
213,
0
] | [
227,
50
] | python | en | ['en', 'en', 'en'] | True |
test_flow_auth_authentication_error | (hass) | Test we handle an authentication error in the auth step. | Test we handle an authentication error in the auth step. | async def test_flow_auth_authentication_error(hass):
"""Test we handle an authentication error in the auth step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = blke.AuthenticationError()
result = await hass.config_entries.flow.async_init(
... | [
"async",
"def",
"test_flow_auth_authentication_error",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"blke",
".",
"Au... | [
230,
0
] | [
248,
55
] | python | en | ['en', 'en', 'en'] | True |
test_flow_auth_network_timeout | (hass) | Test we handle a network timeout in the auth step. | Test we handle a network timeout in the auth step. | async def test_flow_auth_network_timeout(hass):
"""Test we handle a network timeout in the auth step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = blke.NetworkTimeoutError()
result = await hass.config_entries.flow.async_init(
DOMAIN, con... | [
"async",
"def",
"test_flow_auth_network_timeout",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"blke",
".",
"Network... | [
251,
0
] | [
269,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_auth_firmware_error | (hass) | Test we handle a firmware error in the auth step. | Test we handle a firmware error in the auth step. | async def test_flow_auth_firmware_error(hass):
"""Test we handle a firmware error in the auth step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = blke.BroadlinkException()
result = await hass.config_entries.flow.async_init(
DOMAIN, contex... | [
"async",
"def",
"test_flow_auth_firmware_error",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"blke",
".",
"Broadlin... | [
272,
0
] | [
290,
50
] | python | en | ['en', 'en', 'en'] | True |
test_flow_auth_network_unreachable | (hass) | Test we handle a network unreachable in the auth step. | Test we handle a network unreachable in the auth step. | async def test_flow_auth_network_unreachable(hass):
"""Test we handle a network unreachable in the auth step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = OSError(errno.ENETUNREACH, None)
result = await hass.config_entries.flow.async_init(
... | [
"async",
"def",
"test_flow_auth_network_unreachable",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"OSError",
"(",
"... | [
293,
0
] | [
311,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_auth_os_error | (hass) | Test we handle an OS error in the auth step. | Test we handle an OS error in the auth step. | async def test_flow_auth_os_error(hass):
"""Test we handle an OS error in the auth step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = OSError()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries... | [
"async",
"def",
"test_flow_auth_os_error",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"OSError",
"(",
")",
"resu... | [
314,
0
] | [
332,
50
] | python | en | ['en', 'en', 'en'] | True |
test_flow_reset_works | (hass) | Test we finish a config flow after a manual unlock. | Test we finish a config flow after a manual unlock. | async def test_flow_reset_works(hass):
"""Test we finish a config flow after a manual unlock."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.auth.side_effect = blke.AuthenticationError()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"s... | [
"async",
"def",
"test_flow_reset_works",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"auth",
".",
"side_effect",
"=",
"blke",
".",
"AuthenticationEr... | [
335,
0
] | [
364,
52
] | python | en | ['en', 'en', 'en'] | True |
test_flow_unlock_works | (hass) | Test we finish a config flow with an unlock request. | Test we finish a config flow with an unlock request. | async def test_flow_unlock_works(hass):
"""Test we finish a config flow with an unlock request."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.is_locked = True
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOUR... | [
"async",
"def",
"test_flow_unlock_works",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"is_locked",
"=",
"True",
"result",
"=",
"await",
"hass",
".... | [
367,
0
] | [
402,
44
] | python | en | ['en', 'en', 'en'] | True |
test_flow_unlock_network_timeout | (hass) | Test we handle a network timeout in the unlock step. | Test we handle a network timeout in the unlock step. | async def test_flow_unlock_network_timeout(hass):
"""Test we handle a network timeout in the unlock step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.is_locked = True
mock_api.set_lock.side_effect = blke.NetworkTimeoutError()
result = await hass.config_entrie... | [
"async",
"def",
"test_flow_unlock_network_timeout",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"is_locked",
"=",
"True",
"mock_api",
".",
"set_lock",... | [
405,
0
] | [
429,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_unlock_firmware_error | (hass) | Test we handle a firmware error in the unlock step. | Test we handle a firmware error in the unlock step. | async def test_flow_unlock_firmware_error(hass):
"""Test we handle a firmware error in the unlock step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.is_locked = True
mock_api.set_lock.side_effect = blke.BroadlinkException
result = await hass.config_entries.flo... | [
"async",
"def",
"test_flow_unlock_firmware_error",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"is_locked",
"=",
"True",
"mock_api",
".",
"set_lock",
... | [
432,
0
] | [
456,
50
] | python | en | ['en', 'en', 'en'] | True |
test_flow_unlock_network_unreachable | (hass) | Test we handle a network unreachable in the unlock step. | Test we handle a network unreachable in the unlock step. | async def test_flow_unlock_network_unreachable(hass):
"""Test we handle a network unreachable in the unlock step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.is_locked = True
mock_api.set_lock.side_effect = OSError(errno.ENETUNREACH, None)
result = await hass... | [
"async",
"def",
"test_flow_unlock_network_unreachable",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"is_locked",
"=",
"True",
"mock_api",
".",
"set_lo... | [
459,
0
] | [
483,
57
] | python | en | ['en', 'en', 'en'] | True |
test_flow_unlock_os_error | (hass) | Test we handle an OS error in the unlock step. | Test we handle an OS error in the unlock step. | async def test_flow_unlock_os_error(hass):
"""Test we handle an OS error in the unlock step."""
device = get_device("Living Room")
mock_api = device.get_mock_api()
mock_api.is_locked = True
mock_api.set_lock.side_effect = OSError()
result = await hass.config_entries.flow.async_init(
DOM... | [
"async",
"def",
"test_flow_unlock_os_error",
"(",
"hass",
")",
":",
"device",
"=",
"get_device",
"(",
"\"Living Room\"",
")",
"mock_api",
"=",
"device",
".",
"get_mock_api",
"(",
")",
"mock_api",
".",
"is_locked",
"=",
"True",
"mock_api",
".",
"set_lock",
".",... | [
486,
0
] | [
510,
50
] | 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.