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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
SetEnvVar | (env_var, value) | Sets an environment variable to a given value; unsets it when the
given value is None.
| Sets an environment variable to a given value; unsets it when the
given value is None.
| def SetEnvVar(env_var, value):
"""Sets an environment variable to a given value; unsets it when the
given value is None.
"""
env_var = env_var.upper()
if value is not None:
os.environ[env_var] = value
elif env_var in os.environ:
del os.environ[env_var] | [
"def",
"SetEnvVar",
"(",
"env_var",
",",
"value",
")",
":",
"env_var",
"=",
"env_var",
".",
"upper",
"(",
")",
"if",
"value",
"is",
"not",
"None",
":",
"os",
".",
"environ",
"[",
"env_var",
"]",
"=",
"value",
"elif",
"env_var",
"in",
"os",
".",
"en... | [
55,
0
] | [
64,
27
] | python | en | ['en', 'en', 'en'] | True |
Run | (command) | Runs a command; returns True/False if its exit code is/isn't 0. | Runs a command; returns True/False if its exit code is/isn't 0. | def Run(command):
"""Runs a command; returns True/False if its exit code is/isn't 0."""
print('Running "%s". . .' % ' '.join(command))
p = gtest_test_utils.Subprocess(command)
return p.exited and p.exit_code == 0 | [
"def",
"Run",
"(",
"command",
")",
":",
"print",
"(",
"'Running \"%s\". . .'",
"%",
"' '",
".",
"join",
"(",
"command",
")",
")",
"p",
"=",
"gtest_test_utils",
".",
"Subprocess",
"(",
"command",
")",
"return",
"p",
".",
"exited",
"and",
"p",
".",
"exit... | [
67,
0
] | [
72,
38
] | python | en | ['en', 'ca', 'en'] | True |
ThrowOnFailureTest.RunAndVerify | (self, env_var_value, flag_value, should_fail) | Runs googletest-throw-on-failure-test_ and verifies that it does
(or does not) exit with a non-zero code.
Args:
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
variable; None if the variable should be unset.
flag_value: value of the --gtest_break_on_f... | Runs googletest-throw-on-failure-test_ and verifies that it does
(or does not) exit with a non-zero code. | def RunAndVerify(self, env_var_value, flag_value, should_fail):
"""Runs googletest-throw-on-failure-test_ and verifies that it does
(or does not) exit with a non-zero code.
Args:
env_var_value: value of the GTEST_BREAK_ON_FAILURE environment
variable; None if the variable s... | [
"def",
"RunAndVerify",
"(",
"self",
",",
"env_var_value",
",",
"flag_value",
",",
"should_fail",
")",
":",
"SetEnvVar",
"(",
"THROW_ON_FAILURE",
",",
"env_var_value",
")",
"if",
"env_var_value",
"is",
"None",
":",
"env_var_value_msg",
"=",
"' is not set'",
"else",... | [
79,
2
] | [
122,
44
] | python | en | ['en', 'en', 'en'] | True |
ThrowOnFailureTest.testDefaultBehavior | (self) | Tests the behavior of the default mode. | Tests the behavior of the default mode. | def testDefaultBehavior(self):
"""Tests the behavior of the default mode."""
self.RunAndVerify(env_var_value=None, flag_value=None, should_fail=False) | [
"def",
"testDefaultBehavior",
"(",
"self",
")",
":",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"None",
",",
"flag_value",
"=",
"None",
",",
"should_fail",
"=",
"False",
")"
] | [
124,
2
] | [
127,
77
] | python | en | ['en', 'en', 'en'] | True |
ThrowOnFailureTest.testThrowOnFailureEnvVar | (self) | Tests using the GTEST_THROW_ON_FAILURE environment variable. | Tests using the GTEST_THROW_ON_FAILURE environment variable. | def testThrowOnFailureEnvVar(self):
"""Tests using the GTEST_THROW_ON_FAILURE environment variable."""
self.RunAndVerify(env_var_value='0',
flag_value=None,
should_fail=False)
self.RunAndVerify(env_var_value='1',
flag_value=None,
... | [
"def",
"testThrowOnFailureEnvVar",
"(",
"self",
")",
":",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"'0'",
",",
"flag_value",
"=",
"None",
",",
"should_fail",
"=",
"False",
")",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"'1'",
","... | [
129,
2
] | [
137,
39
] | python | en | ['en', 'en', 'en'] | True |
ThrowOnFailureTest.testThrowOnFailureFlag | (self) | Tests using the --gtest_throw_on_failure flag. | Tests using the --gtest_throw_on_failure flag. | def testThrowOnFailureFlag(self):
"""Tests using the --gtest_throw_on_failure flag."""
self.RunAndVerify(env_var_value=None,
flag_value='0',
should_fail=False)
self.RunAndVerify(env_var_value=None,
flag_value='1',
shoul... | [
"def",
"testThrowOnFailureFlag",
"(",
"self",
")",
":",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"None",
",",
"flag_value",
"=",
"'0'",
",",
"should_fail",
"=",
"False",
")",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"None",
",",... | [
139,
2
] | [
147,
39
] | python | en | ['en', 'en', 'en'] | True |
ThrowOnFailureTest.testThrowOnFailureFlagOverridesEnvVar | (self) | Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE. | Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE. | def testThrowOnFailureFlagOverridesEnvVar(self):
"""Tests that --gtest_throw_on_failure overrides GTEST_THROW_ON_FAILURE."""
self.RunAndVerify(env_var_value='0',
flag_value='0',
should_fail=False)
self.RunAndVerify(env_var_value='0',
flag_va... | [
"def",
"testThrowOnFailureFlagOverridesEnvVar",
"(",
"self",
")",
":",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
"'0'",
",",
"flag_value",
"=",
"'0'",
",",
"should_fail",
"=",
"False",
")",
"self",
".",
"RunAndVerify",
"(",
"env_var_value",
"=",
... | [
149,
2
] | [
163,
39
] | python | en | ['en', 'en', 'en'] | True |
test_switch | (hass, hank_binary_switch, integration, client) | Test the switch. | Test the switch. | async def test_switch(hass, hank_binary_switch, integration, client):
"""Test the switch."""
state = hass.states.get(SWITCH_ENTITY)
node = hank_binary_switch
assert state
assert state.state == "off"
# Test turning on
await hass.services.async_call(
"switch", "turn_on", {"entity_id"... | [
"async",
"def",
"test_switch",
"(",
"hass",
",",
"hank_binary_switch",
",",
"integration",
",",
"client",
")",
":",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"SWITCH_ENTITY",
")",
"node",
"=",
"hank_binary_switch",
"assert",
"state",
"assert",
"s... | [
10,
0
] | [
87,
33
] | python | en | ['en', 'en', 'en'] | True |
test_barrier_signaling_switch | (hass, gdc_zw062, integration, client) | Test barrier signaling state switch. | Test barrier signaling state switch. | async def test_barrier_signaling_switch(hass, gdc_zw062, integration, client):
"""Test barrier signaling state switch."""
node = gdc_zw062
entity = "switch.aeon_labs_garage_door_controller_gen5_signaling_state_visual"
state = hass.states.get(entity)
assert state
assert state.state == "on"
... | [
"async",
"def",
"test_barrier_signaling_switch",
"(",
"hass",
",",
"gdc_zw062",
",",
"integration",
",",
"client",
")",
":",
"node",
"=",
"gdc_zw062",
"entity",
"=",
"\"switch.aeon_labs_garage_door_controller_gen5_signaling_state_visual\"",
"state",
"=",
"hass",
".",
"s... | [
90,
0
] | [
225,
34
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Old way of setting up Hue lights.
Can only be called when a user accidentally mentions hue platform in their
config. But even in that case it would have been ignored.
| Old way of setting up Hue lights. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Old way of setting up Hue lights.
Can only be called when a user accidentally mentions hue platform in their
config. But even in that case it would have been ignored.
""" | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":"
] | [
75,
0
] | [
80,
7
] | python | en | ['en', 'en', 'en'] | True |
create_light | (item_class, coordinator, bridge, is_group, rooms, api, item_id) | Create the light. | Create the light. | def create_light(item_class, coordinator, bridge, is_group, rooms, api, item_id):
"""Create the light."""
api_item = api[item_id]
if is_group:
supported_features = 0
for light_id in api_item.lights:
if light_id not in bridge.api.lights:
continue
light... | [
"def",
"create_light",
"(",
"item_class",
",",
"coordinator",
",",
"bridge",
",",
"is_group",
",",
"rooms",
",",
"api",
",",
"item_id",
")",
":",
"api_item",
"=",
"api",
"[",
"item_id",
"]",
"if",
"is_group",
":",
"supported_features",
"=",
"0",
"for",
"... | [
83,
0
] | [
99,
5
] | python | en | ['en', 'zh', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Hue lights from a config entry. | Set up the Hue lights from a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Hue lights from a config entry."""
bridge = hass.data[HUE_DOMAIN][config_entry.entry_id]
api_version = tuple(int(v) for v in bridge.api.config.apiversion.split("."))
rooms = {}
allow_groups = bridge.allow_groups
... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"bridge",
"=",
"hass",
".",
"data",
"[",
"HUE_DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"api_version",
"=",
"tuple",
"(",
"int",
"(",
... | [
102,
0
] | [
220,
38
] | python | en | ['en', 'en', 'en'] | True |
async_safe_fetch | (bridge, fetch_method) | Safely fetch data. | Safely fetch data. | async def async_safe_fetch(bridge, fetch_method):
"""Safely fetch data."""
try:
with async_timeout.timeout(4):
return await bridge.async_request_call(fetch_method)
except aiohue.Unauthorized as err:
await bridge.handle_unauthorized_error()
raise UpdateFailed("Unauthorized... | [
"async",
"def",
"async_safe_fetch",
"(",
"bridge",
",",
"fetch_method",
")",
":",
"try",
":",
"with",
"async_timeout",
".",
"timeout",
"(",
"4",
")",
":",
"return",
"await",
"bridge",
".",
"async_request_call",
"(",
"fetch_method",
")",
"except",
"aiohue",
"... | [
223,
0
] | [
232,
56
] | python | cs | ['cy', 'cs', 'en'] | False |
async_update_items | (
bridge, api, current, async_add_entities, create_item, new_items_callback
) | Update items. | Update items. | def async_update_items(
bridge, api, current, async_add_entities, create_item, new_items_callback
):
"""Update items."""
new_items = []
for item_id in api:
if item_id in current:
continue
current[item_id] = create_item(api, item_id)
new_items.append(current[item_id]... | [
"def",
"async_update_items",
"(",
"bridge",
",",
"api",
",",
"current",
",",
"async_add_entities",
",",
"create_item",
",",
"new_items_callback",
")",
":",
"new_items",
"=",
"[",
"]",
"for",
"item_id",
"in",
"api",
":",
"if",
"item_id",
"in",
"current",
":",... | [
236,
0
] | [
255,
37
] | python | en | ['en', 'la', 'en'] | False |
hue_brightness_to_hass | (value) | Convert hue brightness 1..254 to hass format 0..255. | Convert hue brightness 1..254 to hass format 0..255. | def hue_brightness_to_hass(value):
"""Convert hue brightness 1..254 to hass format 0..255."""
return min(255, round((value / 254) * 255)) | [
"def",
"hue_brightness_to_hass",
"(",
"value",
")",
":",
"return",
"min",
"(",
"255",
",",
"round",
"(",
"(",
"value",
"/",
"254",
")",
"*",
"255",
")",
")"
] | [
258,
0
] | [
260,
47
] | python | en | ['en', 'en', 'en'] | True |
hass_to_hue_brightness | (value) | Convert hass brightness 0..255 to hue 1..254 scale. | Convert hass brightness 0..255 to hue 1..254 scale. | def hass_to_hue_brightness(value):
"""Convert hass brightness 0..255 to hue 1..254 scale."""
return max(1, round((value / 255) * 254)) | [
"def",
"hass_to_hue_brightness",
"(",
"value",
")",
":",
"return",
"max",
"(",
"1",
",",
"round",
"(",
"(",
"value",
"/",
"255",
")",
"*",
"254",
")",
")"
] | [
263,
0
] | [
265,
45
] | python | en | ['en', 'en', 'en'] | True |
HueLight.__init__ | (self, coordinator, bridge, is_group, light, supported_features, rooms) | Initialize the light. | Initialize the light. | def __init__(self, coordinator, bridge, is_group, light, supported_features, rooms):
"""Initialize the light."""
super().__init__(coordinator)
self.light = light
self.bridge = bridge
self.is_group = is_group
self._supported_features = supported_features
self._room... | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
",",
"bridge",
",",
"is_group",
",",
"light",
",",
"supported_features",
",",
"rooms",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"light",
"=",
"light",
"self",
... | [
271,
4
] | [
305,
33
] | python | en | ['en', 'en', 'en'] | True |
HueLight.unique_id | (self) | Return the unique ID of this Hue light. | Return the unique ID of this Hue light. | def unique_id(self):
"""Return the unique ID of this Hue light."""
unique_id = self.light.uniqueid
if not unique_id and self.is_group and self.light.room:
unique_id = self.light.room["id"]
return unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"unique_id",
"=",
"self",
".",
"light",
".",
"uniqueid",
"if",
"not",
"unique_id",
"and",
"self",
".",
"is_group",
"and",
"self",
".",
"light",
".",
"room",
":",
"unique_id",
"=",
"self",
".",
"light",
".",
... | [
308,
4
] | [
314,
24
] | python | en | ['en', 'en', 'en'] | True |
HueLight.device_id | (self) | Return the ID of this Hue light. | Return the ID of this Hue light. | def device_id(self):
"""Return the ID of this Hue light."""
return self.unique_id | [
"def",
"device_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"unique_id"
] | [
317,
4
] | [
319,
29
] | python | en | ['en', 'en', 'en'] | True |
HueLight.name | (self) | Return the name of the Hue light. | Return the name of the Hue light. | def name(self):
"""Return the name of the Hue light."""
return self.light.name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"light",
".",
"name"
] | [
322,
4
] | [
324,
30
] | python | en | ['en', 'mi', 'en'] | True |
HueLight.brightness | (self) | Return the brightness of this light between 0..255. | Return the brightness of this light between 0..255. | def brightness(self):
"""Return the brightness of this light between 0..255."""
if self.is_group:
bri = self.light.action.get("bri")
else:
bri = self.light.state.get("bri")
if bri is None:
return bri
return hue_brightness_to_hass(bri) | [
"def",
"brightness",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_group",
":",
"bri",
"=",
"self",
".",
"light",
".",
"action",
".",
"get",
"(",
"\"bri\"",
")",
"else",
":",
"bri",
"=",
"self",
".",
"light",
".",
"state",
".",
"get",
"(",
"\"bri... | [
327,
4
] | [
337,
42
] | python | en | ['en', 'en', 'en'] | True |
HueLight._color_mode | (self) | Return the hue color mode. | Return the hue color mode. | def _color_mode(self):
"""Return the hue color mode."""
if self.is_group:
return self.light.action.get("colormode")
return self.light.state.get("colormode") | [
"def",
"_color_mode",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_group",
":",
"return",
"self",
".",
"light",
".",
"action",
".",
"get",
"(",
"\"colormode\"",
")",
"return",
"self",
".",
"light",
".",
"state",
".",
"get",
"(",
"\"colormode\"",
")"
] | [
340,
4
] | [
344,
48
] | python | en | ['en', 'pt', 'en'] | True |
HueLight.hs_color | (self) | Return the hs color value. | Return the hs color value. | def hs_color(self):
"""Return the hs color value."""
mode = self._color_mode
source = self.light.action if self.is_group else self.light.state
if mode in ("xy", "hs") and "xy" in source:
return color.color_xy_to_hs(*source["xy"], self.gamut)
return None | [
"def",
"hs_color",
"(",
"self",
")",
":",
"mode",
"=",
"self",
".",
"_color_mode",
"source",
"=",
"self",
".",
"light",
".",
"action",
"if",
"self",
".",
"is_group",
"else",
"self",
".",
"light",
".",
"state",
"if",
"mode",
"in",
"(",
"\"xy\"",
",",
... | [
347,
4
] | [
355,
19
] | python | en | ['en', 'en', 'en'] | True |
HueLight.color_temp | (self) | Return the CT color value. | Return the CT color value. | def color_temp(self):
"""Return the CT color value."""
# Don't return color temperature unless in color temperature mode
if self._color_mode != "ct":
return None
if self.is_group:
return self.light.action.get("ct")
return self.light.state.get("ct") | [
"def",
"color_temp",
"(",
"self",
")",
":",
"# Don't return color temperature unless in color temperature mode",
"if",
"self",
".",
"_color_mode",
"!=",
"\"ct\"",
":",
"return",
"None",
"if",
"self",
".",
"is_group",
":",
"return",
"self",
".",
"light",
".",
"acti... | [
358,
4
] | [
366,
41
] | python | en | ['en', 'en', 'en'] | True |
HueLight.min_mireds | (self) | Return the coldest color_temp that this light supports. | Return the coldest color_temp that this light supports. | def min_mireds(self):
"""Return the coldest color_temp that this light supports."""
if self.is_group:
return super().min_mireds
min_mireds = self.light.controlcapabilities.get("ct", {}).get("min")
# We filter out '0' too, which can be incorrectly reported by 3rd party buls
... | [
"def",
"min_mireds",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_group",
":",
"return",
"super",
"(",
")",
".",
"min_mireds",
"min_mireds",
"=",
"self",
".",
"light",
".",
"controlcapabilities",
".",
"get",
"(",
"\"ct\"",
",",
"{",
"}",
")",
".",
"... | [
369,
4
] | [
380,
25
] | python | en | ['en', 'en', 'en'] | True |
HueLight.max_mireds | (self) | Return the warmest color_temp that this light supports. | Return the warmest color_temp that this light supports. | def max_mireds(self):
"""Return the warmest color_temp that this light supports."""
if self.is_group:
return super().max_mireds
if self.is_livarno:
return 500
max_mireds = self.light.controlcapabilities.get("ct", {}).get("max")
if not max_mireds:
... | [
"def",
"max_mireds",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_group",
":",
"return",
"super",
"(",
")",
".",
"max_mireds",
"if",
"self",
".",
"is_livarno",
":",
"return",
"500",
"max_mireds",
"=",
"self",
".",
"light",
".",
"controlcapabilities",
".... | [
383,
4
] | [
395,
25
] | python | en | ['en', 'en', 'en'] | True |
HueLight.is_on | (self) | Return true if device is on. | Return true if device is on. | def is_on(self):
"""Return true if device is on."""
if self.is_group:
return self.light.state["any_on"]
return self.light.state["on"] | [
"def",
"is_on",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_group",
":",
"return",
"self",
".",
"light",
".",
"state",
"[",
"\"any_on\"",
"]",
"return",
"self",
".",
"light",
".",
"state",
"[",
"\"on\"",
"]"
] | [
398,
4
] | [
402,
37
] | python | en | ['en', 'fy', 'en'] | True |
HueLight.available | (self) | Return if light is available. | Return if light is available. | def available(self):
"""Return if light is available."""
return self.coordinator.last_update_success and (
self.is_group
or self.bridge.allow_unreachable
or self.light.state["reachable"]
) | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"last_update_success",
"and",
"(",
"self",
".",
"is_group",
"or",
"self",
".",
"bridge",
".",
"allow_unreachable",
"or",
"self",
".",
"light",
".",
"state",
"[",
"\"reach... | [
405,
4
] | [
411,
9
] | python | en | ['en', 'en', 'en'] | True |
HueLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return self._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_supported_features"
] | [
414,
4
] | [
416,
39
] | python | en | ['da', 'en', 'en'] | True |
HueLight.effect | (self) | Return the current effect. | Return the current effect. | def effect(self):
"""Return the current effect."""
return self.light.state.get("effect", None) | [
"def",
"effect",
"(",
"self",
")",
":",
"return",
"self",
".",
"light",
".",
"state",
".",
"get",
"(",
"\"effect\"",
",",
"None",
")"
] | [
419,
4
] | [
421,
51
] | python | en | ['en', 'en', 'en'] | True |
HueLight.effect_list | (self) | Return the list of supported effects. | Return the list of supported effects. | def effect_list(self):
"""Return the list of supported effects."""
if self.is_osram:
return [EFFECT_RANDOM]
return [EFFECT_COLORLOOP, EFFECT_RANDOM] | [
"def",
"effect_list",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_osram",
":",
"return",
"[",
"EFFECT_RANDOM",
"]",
"return",
"[",
"EFFECT_COLORLOOP",
",",
"EFFECT_RANDOM",
"]"
] | [
424,
4
] | [
428,
48
] | python | en | ['en', 'en', 'en'] | True |
HueLight.device_info | (self) | Return the device info. | Return the device info. | def device_info(self):
"""Return the device info."""
if self.light.type in (
GROUP_TYPE_LIGHT_GROUP,
GROUP_TYPE_ROOM,
GROUP_TYPE_LUMINAIRE,
GROUP_TYPE_LIGHT_SOURCE,
):
return None
info = {
"identifiers": {(HUE_DOMAI... | [
"def",
"device_info",
"(",
"self",
")",
":",
"if",
"self",
".",
"light",
".",
"type",
"in",
"(",
"GROUP_TYPE_LIGHT_GROUP",
",",
"GROUP_TYPE_ROOM",
",",
"GROUP_TYPE_LUMINAIRE",
",",
"GROUP_TYPE_LIGHT_SOURCE",
",",
")",
":",
"return",
"None",
"info",
"=",
"{",
... | [
431,
4
] | [
456,
19
] | python | en | ['en', 'en', 'en'] | True |
HueLight.async_added_to_hass | (self) | Handle entity being added to Home Assistant. | Handle entity being added to Home Assistant. | async def async_added_to_hass(self) -> None:
"""Handle entity being added to Home Assistant."""
self.async_on_remove(
self.bridge.listen_updates(
self.light.ITEM_TYPE, self.light.id, self.async_write_ha_state
)
)
await super().async_added_to_hass() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"bridge",
".",
"listen_updates",
"(",
"self",
".",
"light",
".",
"ITEM_TYPE",
",",
"self",
".",
"light",
".",
"id",
",",
"self",... | [
458,
4
] | [
465,
43
] | python | en | ['en', 'en', 'en'] | True |
HueLight.async_turn_on | (self, **kwargs) | Turn the specified or all lights on. | Turn the specified or all lights on. | async def async_turn_on(self, **kwargs):
"""Turn the specified or all lights on."""
command = {"on": True}
if ATTR_TRANSITION in kwargs:
command["transitiontime"] = int(kwargs[ATTR_TRANSITION] * 10)
if ATTR_HS_COLOR in kwargs:
if self.is_osram:
c... | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"command",
"=",
"{",
"\"on\"",
":",
"True",
"}",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"command",
"[",
"\"transitiontime\"",
"]",
"=",
"int",
"(",
"kwargs",
"[",
"... | [
467,
4
] | [
521,
54
] | python | en | ['en', 'en', 'en'] | True |
HueLight.async_turn_off | (self, **kwargs) | Turn the specified or all lights off. | Turn the specified or all lights off. | async def async_turn_off(self, **kwargs):
"""Turn the specified or all lights off."""
command = {"on": False}
if ATTR_TRANSITION in kwargs:
command["transitiontime"] = int(kwargs[ATTR_TRANSITION] * 10)
flash = kwargs.get(ATTR_FLASH)
if flash == FLASH_LONG:
... | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"command",
"=",
"{",
"\"on\"",
":",
"False",
"}",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"command",
"[",
"\"transitiontime\"",
"]",
"=",
"int",
"(",
"kwargs",
"[",
... | [
523,
4
] | [
550,
54
] | python | en | ['en', 'en', 'en'] | True |
HueLight.extra_state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def extra_state_attributes(self):
"""Return the device state attributes."""
if not self.is_group:
return {}
return {ATTR_IS_HUE_GROUP: self.is_group} | [
"def",
"extra_state_attributes",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_group",
":",
"return",
"{",
"}",
"return",
"{",
"ATTR_IS_HUE_GROUP",
":",
"self",
".",
"is_group",
"}"
] | [
553,
4
] | [
557,
49
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Statistics sensor. | Set up the Statistics sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Statistics sensor."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
entity_id = config.get(CONF_ENTITY_ID)
name = config.get(CONF_NAME)
sampling_size = config.get(CONF_SAMPLING_SIZE)
... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"entity_id",
"=",
"config",
"."... | [
79,
0
] | [
107,
15
] | python | en | ['en', 'ca', 'en'] | True |
StatisticsSensor.__init__ | (
self,
entity_id,
name,
sampling_size,
max_age,
precision,
quantile_intervals,
quantile_method,
) | Initialize the Statistics sensor. | Initialize the Statistics sensor. | def __init__(
self,
entity_id,
name,
sampling_size,
max_age,
precision,
quantile_intervals,
quantile_method,
):
"""Initialize the Statistics sensor."""
self._entity_id = entity_id
self.is_binary = self._entity_id.split(".")[0] =... | [
"def",
"__init__",
"(",
"self",
",",
"entity_id",
",",
"name",
",",
"sampling_size",
",",
"max_age",
",",
"precision",
",",
"quantile_intervals",
",",
"quantile_method",
",",
")",
":",
"self",
".",
"_entity_id",
"=",
"entity_id",
"self",
".",
"is_binary",
"=... | [
113,
4
] | [
141,
36
] | python | en | ['en', 'bg', 'en'] | True |
StatisticsSensor.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
@callback
def async_stats_sensor_state_listener(event):
"""Handle the sensor state changes."""
new_state = event.data.get("new_state")
if new_state is None:
return
sel... | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"@",
"callback",
"def",
"async_stats_sensor_state_listener",
"(",
"event",
")",
":",
"\"\"\"Handle the sensor state changes.\"\"\"",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",... | [
143,
4
] | [
178,
9
] | python | en | ['en', 'no', 'en'] | False |
StatisticsSensor._add_state_to_queue | (self, new_state) | Add the state to the queue. | Add the state to the queue. | def _add_state_to_queue(self, new_state):
"""Add the state to the queue."""
if new_state.state in (STATE_UNKNOWN, STATE_UNAVAILABLE):
return
try:
if self.is_binary:
self.states.append(new_state.state)
else:
self.states.append(f... | [
"def",
"_add_state_to_queue",
"(",
"self",
",",
"new_state",
")",
":",
"if",
"new_state",
".",
"state",
"in",
"(",
"STATE_UNKNOWN",
",",
"STATE_UNAVAILABLE",
")",
":",
"return",
"try",
":",
"if",
"self",
".",
"is_binary",
":",
"self",
".",
"states",
".",
... | [
180,
4
] | [
197,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.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"
] | [
200,
4
] | [
202,
25
] | python | en | ['en', 'mi', 'en'] | True |
StatisticsSensor.native_value | (self) | Return the state of the sensor. | Return the state of the sensor. | def native_value(self):
"""Return the state of the sensor."""
return self.mean if not self.is_binary else self.count | [
"def",
"native_value",
"(",
"self",
")",
":",
"return",
"self",
".",
"mean",
"if",
"not",
"self",
".",
"is_binary",
"else",
"self",
".",
"count"
] | [
205,
4
] | [
207,
62
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.native_unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement if not self.is_binary else None | [
"def",
"native_unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement",
"if",
"not",
"self",
".",
"is_binary",
"else",
"None"
] | [
210,
4
] | [
212,
72
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
215,
4
] | [
217,
20
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.extra_state_attributes | (self) | Return the state attributes of the sensor. | Return the state attributes of the sensor. | def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
if not self.is_binary:
return {
ATTR_SAMPLING_SIZE: self._sampling_size,
ATTR_COUNT: self.count,
ATTR_MEAN: self.mean,
ATTR_MEDIAN: self.median,
... | [
"def",
"extra_state_attributes",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_binary",
":",
"return",
"{",
"ATTR_SAMPLING_SIZE",
":",
"self",
".",
"_sampling_size",
",",
"ATTR_COUNT",
":",
"self",
".",
"count",
",",
"ATTR_MEAN",
":",
"self",
".",
"... | [
220,
4
] | [
239,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
242,
4
] | [
244,
19
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._purge_old | (self) | Remove states which are older than self._max_age. | Remove states which are older than self._max_age. | def _purge_old(self):
"""Remove states which are older than self._max_age."""
now = dt_util.utcnow()
_LOGGER.debug(
"%s: purging records older then %s(%s)",
self.entity_id,
dt_util.as_local(now - self._max_age),
self._max_age,
)
w... | [
"def",
"_purge_old",
"(",
"self",
")",
":",
"now",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"%s: purging records older then %s(%s)\"",
",",
"self",
".",
"entity_id",
",",
"dt_util",
".",
"as_local",
"(",
"now",
"-",
"self",
... | [
246,
4
] | [
265,
33
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._next_to_purge_timestamp | (self) | Find the timestamp when the next purge would occur. | Find the timestamp when the next purge would occur. | def _next_to_purge_timestamp(self):
"""Find the timestamp when the next purge would occur."""
if self.ages and self._max_age:
# Take the oldest entry from the ages list and add the configured max_age.
# If executed after purging old states, the result is the next timestamp
... | [
"def",
"_next_to_purge_timestamp",
"(",
"self",
")",
":",
"if",
"self",
".",
"ages",
"and",
"self",
".",
"_max_age",
":",
"# Take the oldest entry from the ages list and add the configured max_age.",
"# If executed after purging old states, the result is the next timestamp",
"# in ... | [
267,
4
] | [
274,
19
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor.async_update | (self) | Get the latest data and updates the states. | Get the latest data and updates the states. | async def async_update(self):
"""Get the latest data and updates the states."""
_LOGGER.debug("%s: updating statistics", self.entity_id)
if self._max_age is not None:
self._purge_old()
self.count = len(self.states)
if not self.is_binary:
try: # require ... | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"%s: updating statistics\"",
",",
"self",
".",
"entity_id",
")",
"if",
"self",
".",
"_max_age",
"is",
"not",
"None",
":",
"self",
".",
"_purge_old",
"(",
")",
"self",
... | [
276,
4
] | [
356,
13
] | python | en | ['en', 'en', 'en'] | True |
StatisticsSensor._async_initialize_from_database | (self) | Initialize the list of states from the database.
The query will get the list of states in DESCENDING order so that we
can limit the result to self._sample_size. Afterwards reverse the
list so that we get it in the right order again.
If MaxAge is provided then query will restrict to ent... | Initialize the list of states from the database. | async def _async_initialize_from_database(self):
"""Initialize the list of states from the database.
The query will get the list of states in DESCENDING order so that we
can limit the result to self._sample_size. Afterwards reverse the
list so that we get it in the right order again.
... | [
"async",
"def",
"_async_initialize_from_database",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"%s: initializing values from the database\"",
",",
"self",
".",
"entity_id",
")",
"with",
"session_scope",
"(",
"hass",
"=",
"self",
".",
"hass",
")",
"as",
... | [
358,
4
] | [
397,
81
] | python | en | ['en', 'en', 'en'] | True |
toposort | (data) | Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
| Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding sets.
| def toposort(data):
"""Dependencies are expressed as a dictionary whose keys are items
and whose values are a set of dependent items. Output is a list of
sets in topological order. The first set consists of items with no
dependences, each subsequent set consists of items that depend upon
items in the preceeding set... | [
"def",
"toposort",
"(",
"data",
")",
":",
"# Special case empty input.",
"if",
"len",
"(",
"data",
")",
"==",
"0",
":",
"return",
"# Copy the input so as to leave it unmodified.",
"data",
"=",
"data",
".",
"copy",
"(",
")",
"# Ignore self dependencies.",
"for",
"k... | [
40,
0
] | [
71,
124
] | python | en | ['en', 'en', 'en'] | True |
toposort_flatten | (data, sort=True) | Returns a single list of dependencies. For any set returned by
toposort(), those items are sorted and appended to the result (just to
make the results deterministic). | Returns a single list of dependencies. For any set returned by
toposort(), those items are sorted and appended to the result (just to
make the results deterministic). | def toposort_flatten(data, sort=True):
"""Returns a single list of dependencies. For any set returned by
toposort(), those items are sorted and appended to the result (just to
make the results deterministic)."""
result = []
for d in toposort(data):
result.extend((sorted if sort else list)(d))
r... | [
"def",
"toposort_flatten",
"(",
"data",
",",
"sort",
"=",
"True",
")",
":",
"result",
"=",
"[",
"]",
"for",
"d",
"in",
"toposort",
"(",
"data",
")",
":",
"result",
".",
"extend",
"(",
"(",
"sorted",
"if",
"sort",
"else",
"list",
")",
"(",
"d",
")... | [
74,
0
] | [
82,
17
] | python | en | ['en', 'en', 'en'] | True |
test_executor_shutdown_can_interrupt_threads | (caplog) | Test that the executor shutdown can interrupt threads. | Test that the executor shutdown can interrupt threads. | async def test_executor_shutdown_can_interrupt_threads(caplog):
"""Test that the executor shutdown can interrupt threads."""
iexecutor = InterruptibleThreadPoolExecutor()
def _loop_sleep_in_executor():
while True:
time.sleep(0.1)
sleep_futures = []
for _ in range(100):
... | [
"async",
"def",
"test_executor_shutdown_can_interrupt_threads",
"(",
"caplog",
")",
":",
"iexecutor",
"=",
"InterruptibleThreadPoolExecutor",
"(",
")",
"def",
"_loop_sleep_in_executor",
"(",
")",
":",
"while",
"True",
":",
"time",
".",
"sleep",
"(",
"0.1",
")",
"s... | [
12,
0
] | [
33,
43
] | python | en | ['en', 'en', 'en'] | True |
test_executor_shutdown_only_logs_max_attempts | (caplog) | Test that the executor shutdown will only log max attempts. | Test that the executor shutdown will only log max attempts. | async def test_executor_shutdown_only_logs_max_attempts(caplog):
"""Test that the executor shutdown will only log max attempts."""
iexecutor = InterruptibleThreadPoolExecutor()
def _loop_sleep_in_executor():
time.sleep(0.2)
iexecutor.submit(_loop_sleep_in_executor)
with patch.object(exec... | [
"async",
"def",
"test_executor_shutdown_only_logs_max_attempts",
"(",
"caplog",
")",
":",
"iexecutor",
"=",
"InterruptibleThreadPoolExecutor",
"(",
")",
"def",
"_loop_sleep_in_executor",
"(",
")",
":",
"time",
".",
"sleep",
"(",
"0.2",
")",
"iexecutor",
".",
"submit... | [
36,
0
] | [
53,
24
] | python | en | ['en', 'en', 'en'] | True |
test_executor_shutdown_does_not_log_shutdown_on_first_attempt | (caplog) | Test that the executor shutdown does not log on first attempt. | Test that the executor shutdown does not log on first attempt. | async def test_executor_shutdown_does_not_log_shutdown_on_first_attempt(caplog):
"""Test that the executor shutdown does not log on first attempt."""
iexecutor = InterruptibleThreadPoolExecutor()
def _do_nothing():
return
for _ in range(5):
iexecutor.submit(_do_nothing)
iexecutor... | [
"async",
"def",
"test_executor_shutdown_does_not_log_shutdown_on_first_attempt",
"(",
"caplog",
")",
":",
"iexecutor",
"=",
"InterruptibleThreadPoolExecutor",
"(",
")",
"def",
"_do_nothing",
"(",
")",
":",
"return",
"for",
"_",
"in",
"range",
"(",
"5",
")",
":",
"... | [
56,
0
] | [
69,
60
] | python | en | ['en', 'en', 'en'] | True |
test_overall_timeout_reached | (caplog) | Test that shutdown moves on when the overall timeout is reached. | Test that shutdown moves on when the overall timeout is reached. | async def test_overall_timeout_reached(caplog):
"""Test that shutdown moves on when the overall timeout is reached."""
iexecutor = InterruptibleThreadPoolExecutor()
def _loop_sleep_in_executor():
time.sleep(1)
for _ in range(6):
iexecutor.submit(_loop_sleep_in_executor)
start = t... | [
"async",
"def",
"test_overall_timeout_reached",
"(",
"caplog",
")",
":",
"iexecutor",
"=",
"InterruptibleThreadPoolExecutor",
"(",
")",
"def",
"_loop_sleep_in_executor",
"(",
")",
":",
"time",
".",
"sleep",
"(",
"1",
")",
"for",
"_",
"in",
"range",
"(",
"6",
... | [
72,
0
] | [
90,
24
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Lutron scenes. | Set up the Lutron scenes. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Lutron scenes."""
devs = []
for scene_data in hass.data[LUTRON_DEVICES]["scene"]:
(area_name, keypad_name, device, led) = scene_data
dev = LutronScene(
area_name, keypad_name, device, led, hass.dat... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"devs",
"=",
"[",
"]",
"for",
"scene_data",
"in",
"hass",
".",
"data",
"[",
"LUTRON_DEVICES",
"]",
"[",
"\"scene\"",
"]",
":",
"(",
... | [
8,
0
] | [
18,
28
] | python | en | ['en', 'sr', 'en'] | True |
LutronScene.__init__ | (self, area_name, keypad_name, lutron_device, lutron_led, controller) | Initialize the scene/button. | Initialize the scene/button. | def __init__(self, area_name, keypad_name, lutron_device, lutron_led, controller):
"""Initialize the scene/button."""
super().__init__(area_name, lutron_device, controller)
self._keypad_name = keypad_name
self._led = lutron_led | [
"def",
"__init__",
"(",
"self",
",",
"area_name",
",",
"keypad_name",
",",
"lutron_device",
",",
"lutron_led",
",",
"controller",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"area_name",
",",
"lutron_device",
",",
"controller",
")",
"self",
".",
"_k... | [
24,
4
] | [
28,
30
] | python | en | ['en', 'it', 'en'] | True |
LutronScene.activate | (self, **kwargs: Any) | Activate the scene. | Activate the scene. | def activate(self, **kwargs: Any) -> None:
"""Activate the scene."""
self._lutron_device.press() | [
"def",
"activate",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"self",
".",
"_lutron_device",
".",
"press",
"(",
")"
] | [
30,
4
] | [
32,
35
] | python | en | ['en', 'it', 'en'] | True |
LutronScene.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return f"{self._area_name} {self._keypad_name}: {self._lutron_device.name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._area_name} {self._keypad_name}: {self._lutron_device.name}\""
] | [
35,
4
] | [
37,
83
] | python | en | ['en', 'en', 'en'] | True |
run_download_docker | () | Run the Docker image to download the translations. | Run the Docker image to download the translations. | def run_download_docker():
"""Run the Docker image to download the translations."""
print("Running Docker to download latest translations.")
run = subprocess.run(
[
"docker",
"run",
"-v",
f"{DOWNLOAD_DIR}:/opt/dest/locale",
"--rm",
... | [
"def",
"run_download_docker",
"(",
")",
":",
"print",
"(",
"\"Running Docker to download latest translations.\"",
")",
"run",
"=",
"subprocess",
".",
"run",
"(",
"[",
"\"docker\"",
",",
"\"run\"",
",",
"\"-v\"",
",",
"f\"{DOWNLOAD_DIR}:/opt/dest/locale\"",
",",
"\"--r... | [
18,
0
] | [
51,
56
] | python | en | ['en', 'en', 'en'] | True |
save_json | (filename: str, data: list | dict) | Save JSON data to a file.
Returns True on success.
| Save JSON data to a file. | def save_json(filename: str, data: list | dict):
"""Save JSON data to a file.
Returns True on success.
"""
data = json.dumps(data, sort_keys=True, indent=4)
with open(filename, "w", encoding="utf-8") as fdesc:
fdesc.write(data)
return True
return False | [
"def",
"save_json",
"(",
"filename",
":",
"str",
",",
"data",
":",
"list",
"|",
"dict",
")",
":",
"data",
"=",
"json",
".",
"dumps",
"(",
"data",
",",
"sort_keys",
"=",
"True",
",",
"indent",
"=",
"4",
")",
"with",
"open",
"(",
"filename",
",",
"... | [
54,
0
] | [
63,
16
] | python | en | ['en', 'en', 'en'] | True |
get_component_path | (lang, component) | Get the component translation path. | Get the component translation path. | def get_component_path(lang, component):
"""Get the component translation path."""
if os.path.isdir(os.path.join("homeassistant", "components", component)):
return os.path.join(
"homeassistant", "components", component, "translations", f"{lang}.json"
)
raise ExitApp(f"Integration... | [
"def",
"get_component_path",
"(",
"lang",
",",
"component",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"os",
".",
"path",
".",
"join",
"(",
"\"homeassistant\"",
",",
"\"components\"",
",",
"component",
")",
")",
":",
"return",
"os",
".",
"pa... | [
66,
0
] | [
72,
87
] | python | en | ['en', 'en', 'en'] | True |
get_platform_path | (lang, component, platform) | Get the platform translation path. | Get the platform translation path. | def get_platform_path(lang, component, platform):
"""Get the platform translation path."""
return os.path.join(
"homeassistant",
"components",
component,
"translations",
f"{platform}.{lang}.json",
) | [
"def",
"get_platform_path",
"(",
"lang",
",",
"component",
",",
"platform",
")",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"\"homeassistant\"",
",",
"\"components\"",
",",
"component",
",",
"\"translations\"",
",",
"f\"{platform}.{lang}.json\"",
",",
"... | [
75,
0
] | [
83,
5
] | python | en | ['en', 'da', 'en'] | True |
get_component_translations | (translations) | Get the component level translations. | Get the component level translations. | def get_component_translations(translations):
"""Get the component level translations."""
translations = translations.copy()
translations.pop("platform", None)
return translations | [
"def",
"get_component_translations",
"(",
"translations",
")",
":",
"translations",
"=",
"translations",
".",
"copy",
"(",
")",
"translations",
".",
"pop",
"(",
"\"platform\"",
",",
"None",
")",
"return",
"translations"
] | [
86,
0
] | [
91,
23
] | python | en | ['en', 'en', 'en'] | True |
save_language_translations | (lang, translations) | Distribute the translations for this language. | Distribute the translations for this language. | def save_language_translations(lang, translations):
"""Distribute the translations for this language."""
components = translations.get("component", {})
for component, component_translations in components.items():
base_translations = get_component_translations(component_translations)
if base_... | [
"def",
"save_language_translations",
"(",
"lang",
",",
"translations",
")",
":",
"components",
"=",
"translations",
".",
"get",
"(",
"\"component\"",
",",
"{",
"}",
")",
"for",
"component",
",",
"component_translations",
"in",
"components",
".",
"items",
"(",
... | [
94,
0
] | [
112,
50
] | python | en | ['en', 'en', 'en'] | True |
write_integration_translations | () | Write integration translations. | Write integration translations. | def write_integration_translations():
"""Write integration translations."""
for lang_file in DOWNLOAD_DIR.glob("*.json"):
lang = lang_file.stem
translations = json.loads(lang_file.read_text())
save_language_translations(lang, translations) | [
"def",
"write_integration_translations",
"(",
")",
":",
"for",
"lang_file",
"in",
"DOWNLOAD_DIR",
".",
"glob",
"(",
"\"*.json\"",
")",
":",
"lang",
"=",
"lang_file",
".",
"stem",
"translations",
"=",
"json",
".",
"loads",
"(",
"lang_file",
".",
"read_text",
... | [
115,
0
] | [
120,
54
] | python | en | ['en', 'ko', 'en'] | True |
delete_old_translations | () | Delete old translations. | Delete old translations. | def delete_old_translations():
"""Delete old translations."""
for fil in INTEGRATIONS_DIR.glob("*/translations/*"):
fil.unlink() | [
"def",
"delete_old_translations",
"(",
")",
":",
"for",
"fil",
"in",
"INTEGRATIONS_DIR",
".",
"glob",
"(",
"\"*/translations/*\"",
")",
":",
"fil",
".",
"unlink",
"(",
")"
] | [
123,
0
] | [
126,
20
] | python | en | ['en', 'da', 'en'] | True |
run | () | Run the script. | Run the script. | def run():
"""Run the script."""
DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True)
run_download_docker()
delete_old_translations()
write_integration_translations()
return 0 | [
"def",
"run",
"(",
")",
":",
"DOWNLOAD_DIR",
".",
"mkdir",
"(",
"parents",
"=",
"True",
",",
"exist_ok",
"=",
"True",
")",
"run_download_docker",
"(",
")",
"delete_old_translations",
"(",
")",
"write_integration_translations",
"(",
")",
"return",
"0"
] | [
129,
0
] | [
139,
12
] | python | en | ['en', 'co', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Template weather. | Set up the Template weather. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Template weather."""
name = config[CONF_NAME]
condition_template = config[CONF_CONDITION_TEMPLATE]
temperature_template = config[CONF_TEMPERATURE_TEMPLATE]
humidity_template = config[CONF_HUMIDITY_T... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"condition_template",
"=",
"config",
"[",
"CONF_CONDITION_TEMPLATE",
"]",
"... | [
77,
0
] | [
111,
5
] | python | en | ['en', 'en', 'en'] | True |
WeatherTemplate.__init__ | (
self,
hass,
name,
condition_template,
temperature_template,
humidity_template,
attribution_template,
pressure_template,
wind_speed_template,
wind_bearing_template,
ozone_template,
visibility_template,
forecast_temp... | Initialize the Demo weather. | Initialize the Demo weather. | def __init__(
self,
hass,
name,
condition_template,
temperature_template,
humidity_template,
attribution_template,
pressure_template,
wind_speed_template,
wind_bearing_template,
ozone_template,
visibility_template,
f... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"name",
",",
"condition_template",
",",
"temperature_template",
",",
"humidity_template",
",",
"attribution_template",
",",
"pressure_template",
",",
"wind_speed_template",
",",
"wind_bearing_template",
",",
"ozone_templ... | [
117,
4
] | [
160,
27
] | python | en | ['en', 'en', 'en'] | True |
WeatherTemplate.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"
] | [
163,
4
] | [
165,
25
] | python | en | ['en', 'mi', 'en'] | True |
WeatherTemplate.condition | (self) | Return the current condition. | Return the current condition. | def condition(self):
"""Return the current condition."""
return self._condition | [
"def",
"condition",
"(",
"self",
")",
":",
"return",
"self",
".",
"_condition"
] | [
168,
4
] | [
170,
30
] | python | en | ['en', 'en', 'en'] | True |
WeatherTemplate.temperature | (self) | Return the temperature. | Return the temperature. | def temperature(self):
"""Return the temperature."""
return self._temperature | [
"def",
"temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_temperature"
] | [
173,
4
] | [
175,
32
] | python | en | ['en', 'la', 'en'] | True |
WeatherTemplate.temperature_unit | (self) | Return the unit of measurement. | Return the unit of measurement. | def temperature_unit(self):
"""Return the unit of measurement."""
return self.hass.config.units.temperature_unit | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"self",
".",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit"
] | [
178,
4
] | [
180,
54
] | python | en | ['en', 'la', 'en'] | True |
WeatherTemplate.humidity | (self) | Return the humidity. | Return the humidity. | def humidity(self):
"""Return the humidity."""
return self._humidity | [
"def",
"humidity",
"(",
"self",
")",
":",
"return",
"self",
".",
"_humidity"
] | [
183,
4
] | [
185,
29
] | python | en | ['en', 'sw', 'en'] | True |
WeatherTemplate.wind_speed | (self) | Return the wind speed. | Return the wind speed. | def wind_speed(self):
"""Return the wind speed."""
return self._wind_speed | [
"def",
"wind_speed",
"(",
"self",
")",
":",
"return",
"self",
".",
"_wind_speed"
] | [
188,
4
] | [
190,
31
] | python | en | ['en', 'zh', 'en'] | True |
WeatherTemplate.wind_bearing | (self) | Return the wind bearing. | Return the wind bearing. | def wind_bearing(self):
"""Return the wind bearing."""
return self._wind_bearing | [
"def",
"wind_bearing",
"(",
"self",
")",
":",
"return",
"self",
".",
"_wind_bearing"
] | [
193,
4
] | [
195,
33
] | python | en | ['en', 'ig', 'en'] | True |
WeatherTemplate.ozone | (self) | Return the ozone level. | Return the ozone level. | def ozone(self):
"""Return the ozone level."""
return self._ozone | [
"def",
"ozone",
"(",
"self",
")",
":",
"return",
"self",
".",
"_ozone"
] | [
198,
4
] | [
200,
26
] | python | en | ['en', 'zu', 'en'] | True |
WeatherTemplate.visibility | (self) | Return the visibility. | Return the visibility. | def visibility(self):
"""Return the visibility."""
return self._visibility | [
"def",
"visibility",
"(",
"self",
")",
":",
"return",
"self",
".",
"_visibility"
] | [
203,
4
] | [
205,
31
] | python | en | ['en', 'en', 'en'] | True |
WeatherTemplate.pressure | (self) | Return the air pressure. | Return the air pressure. | def pressure(self):
"""Return the air pressure."""
return self._pressure | [
"def",
"pressure",
"(",
"self",
")",
":",
"return",
"self",
".",
"_pressure"
] | [
208,
4
] | [
210,
29
] | python | en | ['en', 'id', 'en'] | True |
WeatherTemplate.forecast | (self) | Return the forecast. | Return the forecast. | def forecast(self):
"""Return the forecast."""
return self._forecast | [
"def",
"forecast",
"(",
"self",
")",
":",
"return",
"self",
".",
"_forecast"
] | [
213,
4
] | [
215,
29
] | python | en | ['en', 'no', 'en'] | True |
WeatherTemplate.attribution | (self) | Return the attribution. | Return the attribution. | def attribution(self):
"""Return the attribution."""
if self._attribution is None:
return "Powered by Home Assistant"
return self._attribution | [
"def",
"attribution",
"(",
"self",
")",
":",
"if",
"self",
".",
"_attribution",
"is",
"None",
":",
"return",
"\"Powered by Home Assistant\"",
"return",
"self",
".",
"_attribution"
] | [
218,
4
] | [
222,
32
] | python | en | ['en', 'ja', 'en'] | True |
WeatherTemplate.unique_id | (self) | Return the unique id of this weather instance. | Return the unique id of this weather instance. | def unique_id(self):
"""Return the unique id of this weather instance."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
225,
4
] | [
227,
30
] | python | en | ['en', 'en', 'en'] | True |
WeatherTemplate.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
if self._condition_template:
self.add_template_attribute(
"_condition",
self._condition_template,
lambda condition: condition if condition in CONDITION_CLASSES else None,
... | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"if",
"self",
".",
"_condition_template",
":",
"self",
".",
"add_template_attribute",
"(",
"\"_condition\"",
",",
"self",
".",
"_condition_template",
",",
"lambda",
"condition",
":",
"condition",
"if",
... | [
229,
4
] | [
283,
43
] | python | en | ['en', 'no', 'en'] | False |
test_humanify_alexa_event | (hass) | Test humanifying Alexa event. | Test humanifying Alexa event. | async def test_humanify_alexa_event(hass):
"""Test humanifying Alexa event."""
hass.config.components.add("recorder")
await async_setup_component(hass, "alexa", {})
await async_setup_component(hass, "logbook", {})
hass.states.async_set("light.kitchen", "on", {"friendly_name": "Kitchen Light"})
e... | [
"async",
"def",
"test_humanify_alexa_event",
"(",
"hass",
")",
":",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"\"recorder\"",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"alexa\"",
",",
"{",
"}",
")",
"await",
"async_setup_compo... | [
8,
0
] | [
68,
54
] | python | en | ['xh', 'en', 'en'] | True |
CharSetProber.filter_international_words | (buf) |
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delimited
by markers. This function works to ... |
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF] | def filter_international_words(buf):
"""
We define three types of bytes:
alphabet: english alphabets [a-zA-Z]
international: international characters [\x80-\xFF]
marker: everything else [^a-zA-Z\x80-\xFF]
The input buffer can be thought to contain a series of words delim... | [
"def",
"filter_international_words",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"# This regex expression filters out only words that have at-least one",
"# international character. The word may include one marker character at",
"# the end.",
"words",
"=",
"re",
"... | [
66,
4
] | [
100,
23
] | python | en | ['en', 'error', 'th'] | False |
CharSetProber.filter_with_english_letters | (buf) |
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
This filter can be applied to all scripts which... |
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >. | def filter_with_english_letters(buf):
"""
Returns a copy of ``buf`` that retains only the sequences of English
alphabet and high byte characters that are not between <> characters.
Also retains English alphabet and high byte characters immediately
before occurrences of >.
... | [
"def",
"filter_with_english_letters",
"(",
"buf",
")",
":",
"filtered",
"=",
"bytearray",
"(",
")",
"in_tag",
"=",
"False",
"prev",
"=",
"0",
"for",
"curr",
"in",
"range",
"(",
"len",
"(",
"buf",
")",
")",
":",
"# Slice here to get bytes instead of an int with... | [
103,
4
] | [
144,
23
] | python | en | ['en', 'error', 'th'] | False |
opener_for | (ca_bundle=None) | Get a urlopen() replacement that uses ca_bundle for verification | Get a urlopen() replacement that uses ca_bundle for verification | def opener_for(ca_bundle=None):
"""Get a urlopen() replacement that uses ca_bundle for verification"""
return urllib.request.build_opener(
VerifyingHTTPSHandler(ca_bundle or find_ca_bundle())
).open | [
"def",
"opener_for",
"(",
"ca_bundle",
"=",
"None",
")",
":",
"return",
"urllib",
".",
"request",
".",
"build_opener",
"(",
"VerifyingHTTPSHandler",
"(",
"ca_bundle",
"or",
"find_ca_bundle",
"(",
")",
")",
")",
".",
"open"
] | [
210,
0
] | [
214,
10
] | python | en | ['en', 'en', 'en'] | True |
find_ca_bundle | () | Return an existing CA bundle path, or None | Return an existing CA bundle path, or None | def find_ca_bundle():
"""Return an existing CA bundle path, or None"""
extant_cert_paths = filter(os.path.isfile, cert_paths)
return (
get_win_certfile()
or next(extant_cert_paths, None)
or _certifi_where()
) | [
"def",
"find_ca_bundle",
"(",
")",
":",
"extant_cert_paths",
"=",
"filter",
"(",
"os",
".",
"path",
".",
"isfile",
",",
"cert_paths",
")",
"return",
"(",
"get_win_certfile",
"(",
")",
"or",
"next",
"(",
"extant_cert_paths",
",",
"None",
")",
"or",
"_certif... | [
251,
0
] | [
258,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) | Set up the diffuser select entities. | Set up the diffuser select entities. | async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the diffuser select entities."""
diffusers = hass.data[DOMAIN][config_entry.entry_id][DEVICES]
coordinators = hass.data[DOMAIN][config_entry.entry_id][COORDI... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
",",
"async_add_entities",
":",
"AddEntitiesCallback",
",",
")",
"->",
"None",
":",
"diffusers",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",... | [
18,
0
] | [
29,
5
] | python | en | ['en', 'en', 'en'] | True |
DiffuserRoomSize.__init__ | (
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
) | Initialize the diffuser room size select entity. | Initialize the diffuser room size select entity. | def __init__(
self, diffuser: Diffuser, coordinator: RitualsDataUpdateCoordinator
) -> None:
"""Initialize the diffuser room size select entity."""
super().__init__(diffuser, coordinator, ROOM_SIZE_SUFFIX)
self._attr_entity_registry_enabled_default = diffuser.has_battery | [
"def",
"__init__",
"(",
"self",
",",
"diffuser",
":",
"Diffuser",
",",
"coordinator",
":",
"RitualsDataUpdateCoordinator",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"diffuser",
",",
"coordinator",
",",
"ROOM_SIZE_SUFFIX",
")",
"self",
... | [
39,
4
] | [
44,
73
] | python | en | ['en', 'en', 'en'] | True |
DiffuserRoomSize.current_option | (self) | Return the diffuser room size. | Return the diffuser room size. | def current_option(self) -> str:
"""Return the diffuser room size."""
return str(self._diffuser.room_size_square_meter) | [
"def",
"current_option",
"(",
"self",
")",
"->",
"str",
":",
"return",
"str",
"(",
"self",
".",
"_diffuser",
".",
"room_size_square_meter",
")"
] | [
47,
4
] | [
49,
57
] | python | en | ['en', 'en', 'en'] | True |
DiffuserRoomSize.async_select_option | (self, option: str) | Change the diffuser room size. | Change the diffuser room size. | async def async_select_option(self, option: str) -> None:
"""Change the diffuser room size."""
await self._diffuser.set_room_size_square_meter(int(option)) | [
"async",
"def",
"async_select_option",
"(",
"self",
",",
"option",
":",
"str",
")",
"->",
"None",
":",
"await",
"self",
".",
"_diffuser",
".",
"set_room_size_square_meter",
"(",
"int",
"(",
"option",
")",
")"
] | [
51,
4
] | [
53,
68
] | python | en | ['en', 'en', 'en'] | True |
test_setup_minimum | (hass) | Test old platform setup with minimum configuration. | Test old platform setup with minimum configuration. | async def test_setup_minimum(hass):
"""Test old platform setup with minimum configuration."""
config = {"sensor": {"platform": "onewire"}}
with assert_setup_component(1, "sensor"):
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
await hass.async_block_till_done() | [
"async",
"def",
"test_setup_minimum",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"onewire\"",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
",",
"\"sensor\"",
")",
":",
"assert",
"await",
"async_setup_comp... | [
36,
0
] | [
41,
38
] | python | en | ['en', 'zu', 'en'] | True |
test_setup_sysbus | (hass) | Test old platform setup with SysBus configuration. | Test old platform setup with SysBus configuration. | async def test_setup_sysbus(hass):
"""Test old platform setup with SysBus configuration."""
config = {
"sensor": {
"platform": "onewire",
"mount_dir": DEFAULT_SYSBUS_MOUNT_DIR,
}
}
with assert_setup_component(1, "sensor"):
assert await async_setup_componen... | [
"async",
"def",
"test_setup_sysbus",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"onewire\"",
",",
"\"mount_dir\"",
":",
"DEFAULT_SYSBUS_MOUNT_DIR",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
",",
"... | [
44,
0
] | [
54,
38
] | python | en | ['en', 'da', 'en'] | True |
test_setup_owserver | (hass) | Test old platform setup with OWServer configuration. | Test old platform setup with OWServer configuration. | async def test_setup_owserver(hass):
"""Test old platform setup with OWServer configuration."""
config = {"sensor": {"platform": "onewire", "host": "localhost"}}
with assert_setup_component(1, "sensor"):
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
await hass.async_block_till_... | [
"async",
"def",
"test_setup_owserver",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"onewire\"",
",",
"\"host\"",
":",
"\"localhost\"",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
",",
"\"sensor\"",
")",
... | [
57,
0
] | [
62,
38
] | python | en | ['en', 'da', 'en'] | True |
test_setup_owserver_with_port | (hass) | Test old platform setup with OWServer configuration. | Test old platform setup with OWServer configuration. | async def test_setup_owserver_with_port(hass):
"""Test old platform setup with OWServer configuration."""
config = {"sensor": {"platform": "onewire", "host": "localhost", "port": "1234"}}
with assert_setup_component(1, "sensor"):
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
aw... | [
"async",
"def",
"test_setup_owserver_with_port",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"onewire\"",
",",
"\"host\"",
":",
"\"localhost\"",
",",
"\"port\"",
":",
"\"1234\"",
"}",
"}",
"with",
"assert_setup_compo... | [
65,
0
] | [
70,
38
] | python | en | ['en', 'da', 'en'] | True |
test_sensors_on_owserver_coupler | (owproxy, hass, device_id) | Test for 1-Wire sensors connected to DS2409 coupler. | Test for 1-Wire sensors connected to DS2409 coupler. | async def test_sensors_on_owserver_coupler(owproxy, hass, device_id):
"""Test for 1-Wire sensors connected to DS2409 coupler."""
await async_setup_component(hass, "persistent_notification", {})
entity_registry = mock_registry(hass)
mock_coupler = MOCK_COUPLERS[device_id]
dir_side_effect = [] # Li... | [
"async",
"def",
"test_sensors_on_owserver_coupler",
"(",
"owproxy",
",",
"hass",
",",
"device_id",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"entity_registry",
"=",
"mock_registry",
"(",
"hass",
... | [
75,
0
] | [
129,
80
] | python | en | ['en', 'en', 'en'] | True |
test_owserver_setup_valid_device | (owproxy, hass, device_id, platform) | Test for 1-Wire device.
As they would be on a clean setup: all binary-sensors and switches disabled.
| Test for 1-Wire device. | async def test_owserver_setup_valid_device(owproxy, hass, device_id, platform):
"""Test for 1-Wire device.
As they would be on a clean setup: all binary-sensors and switches disabled.
"""
await async_setup_component(hass, "persistent_notification", {})
entity_registry = mock_registry(hass)
devi... | [
"async",
"def",
"test_owserver_setup_valid_device",
"(",
"owproxy",
",",
"hass",
",",
"device_id",
",",
"platform",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"entity_registry",
"=",
"mock_registr... | [
135,
0
] | [
180,
13
] | python | en | ['fr', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.