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_step_zeroconf | (hass, ping_client) | Test the zeroconf step. | Test the zeroconf step. | async def test_step_zeroconf(hass, ping_client):
"""Test the zeroconf step."""
zeroconf_data = {
"host": "192.168.1.100",
"port": 7777,
"hostname": "GVC1-ABCD.local.",
"type": "_api._udp.local.",
"name": "Guardian Valve Controller API._api._udp.local.",
"propertie... | [
"async",
"def",
"test_step_zeroconf",
"(",
"hass",
",",
"ping_client",
")",
":",
"zeroconf_data",
"=",
"{",
"\"host\"",
":",
"\"192.168.1.100\"",
",",
"\"port\"",
":",
"7777",
",",
"\"hostname\"",
":",
"\"GVC1-ABCD.local.\"",
",",
"\"type\"",
":",
"\"_api._udp.loc... | [
81,
0
] | [
107,
5
] | python | en | ['en', 'pl', 'en'] | True |
test_step_zeroconf_already_in_progress | (hass) | Test the zeroconf step aborting because it's already in progress. | Test the zeroconf step aborting because it's already in progress. | async def test_step_zeroconf_already_in_progress(hass):
"""Test the zeroconf step aborting because it's already in progress."""
zeroconf_data = {
"host": "192.168.1.100",
"port": 7777,
"hostname": "GVC1-ABCD.local.",
"type": "_api._udp.local.",
"name": "Guardian Valve Con... | [
"async",
"def",
"test_step_zeroconf_already_in_progress",
"(",
"hass",
")",
":",
"zeroconf_data",
"=",
"{",
"\"host\"",
":",
"\"192.168.1.100\"",
",",
"\"port\"",
":",
"7777",
",",
"\"hostname\"",
":",
"\"GVC1-ABCD.local.\"",
",",
"\"type\"",
":",
"\"_api._udp.local.\... | [
110,
0
] | [
131,
52
] | python | en | ['en', 'en', 'en'] | True |
test_step_zeroconf_no_discovery_info | (hass) | Test the zeroconf step aborting because no discovery info came along. | Test the zeroconf step aborting because no discovery info came along. | async def test_step_zeroconf_no_discovery_info(hass):
"""Test the zeroconf step aborting because no discovery info came along."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_ZEROCONF}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
asser... | [
"async",
"def",
"test_step_zeroconf_no_discovery_info",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_ZEROCONF",
"}",
")",
"asse... | [
134,
0
] | [
140,
47
] | python | en | ['en', 'en', 'en'] | True |
add_depth_channel | (img_tensor, pad_mode) |
img_tensor: N, C, H, W
|
img_tensor: N, C, H, W
| def add_depth_channel(img_tensor, pad_mode):
'''
img_tensor: N, C, H, W
'''
img_tensor[:, 1] = get_depth_tensor(pad_mode)
img_tensor[:, 2] = img_tensor[:, 0] * get_depth_tensor(pad_mode) | [
"def",
"add_depth_channel",
"(",
"img_tensor",
",",
"pad_mode",
")",
":",
"img_tensor",
"[",
":",
",",
"1",
"]",
"=",
"get_depth_tensor",
"(",
"pad_mode",
")",
"img_tensor",
"[",
":",
",",
"2",
"]",
"=",
"img_tensor",
"[",
":",
",",
"0",
"]",
"*",
"g... | [
255,
0
] | [
260,
68
] | python | en | ['en', 'error', 'th'] | False |
sanitize_filename | (filename: str) | r"""Sanitize a filename by removing .. / and \\. | r"""Sanitize a filename by removing .. / and \\. | def sanitize_filename(filename: str) -> str:
r"""Sanitize a filename by removing .. / and \\."""
return RE_SANITIZE_FILENAME.sub("", filename) | [
"def",
"sanitize_filename",
"(",
"filename",
":",
"str",
")",
"->",
"str",
":",
"return",
"RE_SANITIZE_FILENAME",
".",
"sub",
"(",
"\"\"",
",",
"filename",
")"
] | [
34,
0
] | [
36,
49
] | python | en | ['en', 'en', 'en'] | True |
sanitize_path | (path: str) | Sanitize a path by removing ~ and .. | Sanitize a path by removing ~ and .. | def sanitize_path(path: str) -> str:
"""Sanitize a path by removing ~ and .."""
return RE_SANITIZE_PATH.sub("", path) | [
"def",
"sanitize_path",
"(",
"path",
":",
"str",
")",
"->",
"str",
":",
"return",
"RE_SANITIZE_PATH",
".",
"sub",
"(",
"\"\"",
",",
"path",
")"
] | [
39,
0
] | [
41,
41
] | python | en | ['en', 'en', 'en'] | True |
slugify | (text: str, *, separator: str = "_") | Slugify a given text. | Slugify a given text. | def slugify(text: str, *, separator: str = "_") -> str:
"""Slugify a given text."""
return unicode_slug.slugify(text, separator=separator) | [
"def",
"slugify",
"(",
"text",
":",
"str",
",",
"*",
",",
"separator",
":",
"str",
"=",
"\"_\"",
")",
"->",
"str",
":",
"return",
"unicode_slug",
".",
"slugify",
"(",
"text",
",",
"separator",
"=",
"separator",
")"
] | [
44,
0
] | [
46,
58
] | python | en | ['en', 'gl', 'en'] | True |
repr_helper | (inp: Any) | Help creating a more readable string representation of objects. | Help creating a more readable string representation of objects. | def repr_helper(inp: Any) -> str:
"""Help creating a more readable string representation of objects."""
if isinstance(inp, (dict, MappingProxyType)):
return ", ".join(
f"{repr_helper(key)}={repr_helper(item)}" for key, item in inp.items()
)
if isinstance(inp, datetime):
r... | [
"def",
"repr_helper",
"(",
"inp",
":",
"Any",
")",
"->",
"str",
":",
"if",
"isinstance",
"(",
"inp",
",",
"(",
"dict",
",",
"MappingProxyType",
")",
")",
":",
"return",
"\", \"",
".",
"join",
"(",
"f\"{repr_helper(key)}={repr_helper(item)}\"",
"for",
"key",
... | [
49,
0
] | [
58,
19
] | python | en | ['en', 'en', 'en'] | True |
convert | (
value: Optional[T], to_type: Callable[[T], U], default: Optional[U] = None
) | Convert value to to_type, returns default if fails. | Convert value to to_type, returns default if fails. | def convert(
value: Optional[T], to_type: Callable[[T], U], default: Optional[U] = None
) -> Optional[U]:
"""Convert value to to_type, returns default if fails."""
try:
return default if value is None else to_type(value)
except (ValueError, TypeError):
# If value could not be converted
... | [
"def",
"convert",
"(",
"value",
":",
"Optional",
"[",
"T",
"]",
",",
"to_type",
":",
"Callable",
"[",
"[",
"T",
"]",
",",
"U",
"]",
",",
"default",
":",
"Optional",
"[",
"U",
"]",
"=",
"None",
")",
"->",
"Optional",
"[",
"U",
"]",
":",
"try",
... | [
61,
0
] | [
69,
22
] | python | en | ['en', 'en', 'en'] | True |
ensure_unique_string | (
preferred_string: str, current_strings: Union[Iterable[str], KeysView[str]]
) | Return a string that is not present in current_strings.
If preferred string exists will append _2, _3, ..
| Return a string that is not present in current_strings. | def ensure_unique_string(
preferred_string: str, current_strings: Union[Iterable[str], KeysView[str]]
) -> str:
"""Return a string that is not present in current_strings.
If preferred string exists will append _2, _3, ..
"""
test_string = preferred_string
current_strings_set = set(current_strin... | [
"def",
"ensure_unique_string",
"(",
"preferred_string",
":",
"str",
",",
"current_strings",
":",
"Union",
"[",
"Iterable",
"[",
"str",
"]",
",",
"KeysView",
"[",
"str",
"]",
"]",
")",
"->",
"str",
":",
"test_string",
"=",
"preferred_string",
"current_strings_s... | [
72,
0
] | [
88,
22
] | python | en | ['en', 'en', 'en'] | True |
get_local_ip | () | Try to determine the local IP address of the machine. | Try to determine the local IP address of the machine. | def get_local_ip() -> str:
"""Try to determine the local IP address of the machine."""
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# Use Google Public DNS server to determine own IP
sock.connect(("8.8.8.8", 80))
return sock.getsockname()[0] # type: ignore
... | [
"def",
"get_local_ip",
"(",
")",
"->",
"str",
":",
"try",
":",
"sock",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_DGRAM",
")",
"# Use Google Public DNS server to determine own IP",
"sock",
".",
"connect",
"(",
"(",
... | [
92,
0
] | [
107,
20
] | python | en | ['en', 'en', 'en'] | True |
get_random_string | (length: int = 10) | Return a random string with letters and digits. | Return a random string with letters and digits. | def get_random_string(length: int = 10) -> str:
"""Return a random string with letters and digits."""
generator = random.SystemRandom()
source_chars = string.ascii_letters + string.digits
return "".join(generator.choice(source_chars) for _ in range(length)) | [
"def",
"get_random_string",
"(",
"length",
":",
"int",
"=",
"10",
")",
"->",
"str",
":",
"generator",
"=",
"random",
".",
"SystemRandom",
"(",
")",
"source_chars",
"=",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
"return",
"\"\"",
".",
... | [
111,
0
] | [
116,
73
] | python | en | ['en', 'en', 'en'] | True |
OrderedEnum.__ge__ | (self, other: ENUM_T) | Return the greater than element. | Return the greater than element. | def __ge__(self, other: ENUM_T) -> bool:
"""Return the greater than element."""
if self.__class__ is other.__class__:
return bool(self.value >= other.value)
return NotImplemented | [
"def",
"__ge__",
"(",
"self",
",",
"other",
":",
"ENUM_T",
")",
"->",
"bool",
":",
"if",
"self",
".",
"__class__",
"is",
"other",
".",
"__class__",
":",
"return",
"bool",
"(",
"self",
".",
"value",
">=",
"other",
".",
"value",
")",
"return",
"NotImpl... | [
125,
4
] | [
129,
29
] | python | en | ['en', 'en', 'en'] | True |
OrderedEnum.__gt__ | (self, other: ENUM_T) | Return the greater element. | Return the greater element. | def __gt__(self, other: ENUM_T) -> bool:
"""Return the greater element."""
if self.__class__ is other.__class__:
return bool(self.value > other.value)
return NotImplemented | [
"def",
"__gt__",
"(",
"self",
",",
"other",
":",
"ENUM_T",
")",
"->",
"bool",
":",
"if",
"self",
".",
"__class__",
"is",
"other",
".",
"__class__",
":",
"return",
"bool",
"(",
"self",
".",
"value",
">",
"other",
".",
"value",
")",
"return",
"NotImple... | [
131,
4
] | [
135,
29
] | python | en | ['en', 'en', 'en'] | True |
OrderedEnum.__le__ | (self, other: ENUM_T) | Return the lower than element. | Return the lower than element. | def __le__(self, other: ENUM_T) -> bool:
"""Return the lower than element."""
if self.__class__ is other.__class__:
return bool(self.value <= other.value)
return NotImplemented | [
"def",
"__le__",
"(",
"self",
",",
"other",
":",
"ENUM_T",
")",
"->",
"bool",
":",
"if",
"self",
".",
"__class__",
"is",
"other",
".",
"__class__",
":",
"return",
"bool",
"(",
"self",
".",
"value",
"<=",
"other",
".",
"value",
")",
"return",
"NotImpl... | [
137,
4
] | [
141,
29
] | python | en | ['en', 'en', 'en'] | True |
OrderedEnum.__lt__ | (self, other: ENUM_T) | Return the lower element. | Return the lower element. | def __lt__(self, other: ENUM_T) -> bool:
"""Return the lower element."""
if self.__class__ is other.__class__:
return bool(self.value < other.value)
return NotImplemented | [
"def",
"__lt__",
"(",
"self",
",",
"other",
":",
"ENUM_T",
")",
"->",
"bool",
":",
"if",
"self",
".",
"__class__",
"is",
"other",
".",
"__class__",
":",
"return",
"bool",
"(",
"self",
".",
"value",
"<",
"other",
".",
"value",
")",
"return",
"NotImple... | [
143,
4
] | [
147,
29
] | python | en | ['en', 'en', 'en'] | True |
Throttle.__init__ | (
self, min_time: timedelta, limit_no_throttle: Optional[timedelta] = None
) | Initialize the throttle. | Initialize the throttle. | def __init__(
self, min_time: timedelta, limit_no_throttle: Optional[timedelta] = None
) -> None:
"""Initialize the throttle."""
self.min_time = min_time
self.limit_no_throttle = limit_no_throttle | [
"def",
"__init__",
"(",
"self",
",",
"min_time",
":",
"timedelta",
",",
"limit_no_throttle",
":",
"Optional",
"[",
"timedelta",
"]",
"=",
"None",
")",
"->",
"None",
":",
"self",
".",
"min_time",
"=",
"min_time",
"self",
".",
"limit_no_throttle",
"=",
"limi... | [
168,
4
] | [
173,
50
] | python | en | ['en', 'en', 'en'] | True |
Throttle.__call__ | (self, method: Callable) | Caller for the throttle. | Caller for the throttle. | def __call__(self, method: Callable) -> Callable:
"""Caller for the throttle."""
# Make sure we return a coroutine if the method is async.
if asyncio.iscoroutinefunction(method):
async def throttled_value() -> None:
"""Stand-in function for when real func is being th... | [
"def",
"__call__",
"(",
"self",
",",
"method",
":",
"Callable",
")",
"->",
"Callable",
":",
"# Make sure we return a coroutine if the method is async.",
"if",
"asyncio",
".",
"iscoroutinefunction",
"(",
"method",
")",
":",
"async",
"def",
"throttled_value",
"(",
")"... | [
175,
4
] | [
246,
22
] | python | en | ['en', 'no', 'en'] | True |
pytest_configure | (config) | Register custom marker for tests. | Register custom marker for tests. | def pytest_configure(config):
"""Register custom marker for tests."""
config.addinivalue_line(
"markers", "no_bypass_setup: mark test to disable bypass_setup_fixture"
) | [
"def",
"pytest_configure",
"(",
"config",
")",
":",
"config",
".",
"addinivalue_line",
"(",
"\"markers\"",
",",
"\"no_bypass_setup: mark test to disable bypass_setup_fixture\"",
")"
] | [
6,
0
] | [
10,
5
] | python | da | ['da', 'no', 'en'] | False |
bypass_setup_fixture | (request) | Mock component setup. | Mock component setup. | def bypass_setup_fixture(request):
"""Mock component setup."""
if "no_bypass_setup" in request.keywords:
yield
else:
with patch(
"homeassistant.components.synology_dsm.async_setup_entry", return_value=True
):
yield | [
"def",
"bypass_setup_fixture",
"(",
"request",
")",
":",
"if",
"\"no_bypass_setup\"",
"in",
"request",
".",
"keywords",
":",
"yield",
"else",
":",
"with",
"patch",
"(",
"\"homeassistant.components.synology_dsm.async_setup_entry\"",
",",
"return_value",
"=",
"True",
")... | [
14,
0
] | [
22,
17
] | python | en | ['en', 'bg', 'en'] | True |
NetatmoBase.__init__ | (self, data_handler: NetatmoDataHandler) | Set up Netatmo entity base. | Set up Netatmo entity base. | def __init__(self, data_handler: NetatmoDataHandler) -> None:
"""Set up Netatmo entity base."""
self.data_handler = data_handler
self._data_classes: List[Dict] = []
self._listeners: List[CALLBACK_TYPE] = []
self._device_name = None
self._id = None
self._model = N... | [
"def",
"__init__",
"(",
"self",
",",
"data_handler",
":",
"NetatmoDataHandler",
")",
"->",
"None",
":",
"self",
".",
"data_handler",
"=",
"data_handler",
"self",
".",
"_data_classes",
":",
"List",
"[",
"Dict",
"]",
"=",
"[",
"]",
"self",
".",
"_listeners",... | [
16,
4
] | [
26,
30
] | python | en | ['en', 'zu', 'en'] | True |
NetatmoBase.async_added_to_hass | (self) | Entity created. | Entity created. | async def async_added_to_hass(self) -> None:
"""Entity created."""
_LOGGER.debug("New client %s", self.entity_id)
for data_class in self._data_classes:
signal_name = data_class[SIGNAL_NAME]
if "home_id" in data_class:
await self.data_handler.register_data... | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
"->",
"None",
":",
"_LOGGER",
".",
"debug",
"(",
"\"New client %s\"",
",",
"self",
".",
"entity_id",
")",
"for",
"data_class",
"in",
"self",
".",
"_data_classes",
":",
"signal_name",
"=",
"data_class",
... | [
28,
4
] | [
60,
36
] | python | en | ['en', 'sm', 'en'] | False |
NetatmoBase.async_will_remove_from_hass | (self) | Run when entity will be removed from hass. | Run when entity will be removed from hass. | async def async_will_remove_from_hass(self):
"""Run when entity will be removed from hass."""
await super().async_will_remove_from_hass()
for listener in self._listeners:
listener()
for data_class in self._data_classes:
await self.data_handler.unregister_data_cl... | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_will_remove_from_hass",
"(",
")",
"for",
"listener",
"in",
"self",
".",
"_listeners",
":",
"listener",
"(",
")",
"for",
"data_class",
"in",
"self",
... | [
62,
4
] | [
72,
13
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase.async_remove | (self) | Clean up when removing entity. | Clean up when removing entity. | async def async_remove(self):
"""Clean up when removing entity."""
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
entity_entry = entity_registry.async_get(self.entity_id)
if not entity_entry:
await super().async_remove()
return
... | [
"async",
"def",
"async_remove",
"(",
"self",
")",
":",
"entity_registry",
"=",
"await",
"self",
".",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entity_entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"self",
"."... | [
74,
4
] | [
82,
52
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase.async_update_callback | (self) | Update the entity's state. | Update the entity's state. | def async_update_callback(self):
"""Update the entity's state."""
raise NotImplementedError | [
"def",
"async_update_callback",
"(",
"self",
")",
":",
"raise",
"NotImplementedError"
] | [
85,
4
] | [
87,
33
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase._data | (self) | Return data for this entity. | Return data for this entity. | def _data(self):
"""Return data for this entity."""
return self.data_handler.data[self._data_classes[0]["name"]] | [
"def",
"_data",
"(",
"self",
")",
":",
"return",
"self",
".",
"data_handler",
".",
"data",
"[",
"self",
".",
"_data_classes",
"[",
"0",
"]",
"[",
"\"name\"",
"]",
"]"
] | [
90,
4
] | [
92,
68
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase.unique_id | (self) | Return the unique ID of this entity. | Return the unique ID of this entity. | def unique_id(self):
"""Return the unique ID of this entity."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
95,
4
] | [
97,
30
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase.name | (self) | Return the name of this entity. | Return the name of this entity. | def name(self):
"""Return the name of this entity."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
100,
4
] | [
102,
25
] | python | en | ['en', 'en', 'en'] | True |
NetatmoBase.device_info | (self) | Return the device info for the sensor. | Return the device info for the sensor. | def device_info(self):
"""Return the device info for the sensor."""
return {
"identifiers": {(DOMAIN, self._id)},
"name": self._device_name,
"manufacturer": MANUFACTURER,
"model": MODELS[self._model],
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"_device_name",
",",
"\"manufacturer\"",
":",
"MANUFACTURER",
",",
"\"model\"",
... | [
105,
4
] | [
112,
9
] | python | en | ['en', 'no', 'en'] | True |
_discover | (hass, config, component_name, found_tellcore_devices) | Set up and send the discovery event. | Set up and send the discovery event. | def _discover(hass, config, component_name, found_tellcore_devices):
"""Set up and send the discovery event."""
if not found_tellcore_devices:
return
_LOGGER.info(
"Discovered %d new %s devices", len(found_tellcore_devices), component_name
)
signal_repetitions = config[DOMAIN].get(... | [
"def",
"_discover",
"(",
"hass",
",",
"config",
",",
"component_name",
",",
"found_tellcore_devices",
")",
":",
"if",
"not",
"found_tellcore_devices",
":",
"return",
"_LOGGER",
".",
"info",
"(",
"\"Discovered %d new %s devices\"",
",",
"len",
"(",
"found_tellcore_de... | [
59,
0
] | [
79,
5
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the Tellstick component. | Set up the Tellstick component. | def setup(hass, config):
"""Set up the Tellstick component."""
conf = config.get(DOMAIN, {})
net_host = conf.get(CONF_HOST)
net_ports = conf.get(CONF_PORT)
# Initialize remote tellcore client
if net_host:
net_client = TellCoreClient(
host=net_host, port_client=net_ports[0],... | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
".",
"get",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"net_host",
"=",
"conf",
".",
"get",
"(",
"CONF_HOST",
")",
"net_ports",
"=",
"conf",
".",
"get",
"(",
"CONF_PORT",
")",
"... | [
82,
0
] | [
161,
15
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.__init__ | (self, tellcore_device, signal_repetitions) | Init the Tellstick device. | Init the Tellstick device. | def __init__(self, tellcore_device, signal_repetitions):
"""Init the Tellstick device."""
self._signal_repetitions = signal_repetitions
self._state = None
self._requested_state = None
self._requested_data = None
self._repeats_left = 0
# Look up our corresponding ... | [
"def",
"__init__",
"(",
"self",
",",
"tellcore_device",
",",
"signal_repetitions",
")",
":",
"self",
".",
"_signal_repetitions",
"=",
"signal_repetitions",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_requested_state",
"=",
"None",
"self",
".",
"_requested... | [
170,
4
] | [
180,
41
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
self.async_on_remove(
self.hass.helpers.dispatcher.async_dispatcher_connect(
SIGNAL_TELLCORE_CALLBACK, self.update_from_callback
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"self",
".",
"hass",
".",
"helpers",
".",
"dispatcher",
".",
"async_dispatcher_connect",
"(",
"SIGNAL_TELLCORE_CALLBACK",
",",
"self",
".",
"update_from_callback",
"... | [
182,
4
] | [
188,
9
] | python | en | ['en', 'no', 'en'] | False |
TellstickDevice.should_poll | (self) | Tell Home Assistant not to poll this device. | Tell Home Assistant not to poll this device. | def should_poll(self):
"""Tell Home Assistant not to poll this device."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
191,
4
] | [
193,
20
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.assumed_state | (self) | Tellstick devices are always assumed state. | Tellstick devices are always assumed state. | def assumed_state(self):
"""Tellstick devices are always assumed state."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"True"
] | [
196,
4
] | [
198,
19
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.name | (self) | Return the name of the device as reported by tellcore. | Return the name of the device as reported by tellcore. | def name(self):
"""Return the name of the device as reported by tellcore."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
201,
4
] | [
203,
25
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.is_on | (self) | Return true if the device is on. | Return true if the device is on. | def is_on(self):
"""Return true if the device is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
206,
4
] | [
208,
26
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._parse_ha_data | (self, kwargs) | Turn the value from HA into something useful. | Turn the value from HA into something useful. | def _parse_ha_data(self, kwargs):
"""Turn the value from HA into something useful."""
raise NotImplementedError | [
"def",
"_parse_ha_data",
"(",
"self",
",",
"kwargs",
")",
":",
"raise",
"NotImplementedError"
] | [
210,
4
] | [
212,
33
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._parse_tellcore_data | (self, tellcore_data) | Turn the value received from tellcore into something useful. | Turn the value received from tellcore into something useful. | def _parse_tellcore_data(self, tellcore_data):
"""Turn the value received from tellcore into something useful."""
raise NotImplementedError | [
"def",
"_parse_tellcore_data",
"(",
"self",
",",
"tellcore_data",
")",
":",
"raise",
"NotImplementedError"
] | [
214,
4
] | [
216,
33
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._update_model | (self, new_state, data) | Update the device entity state to match the arguments. | Update the device entity state to match the arguments. | def _update_model(self, new_state, data):
"""Update the device entity state to match the arguments."""
raise NotImplementedError | [
"def",
"_update_model",
"(",
"self",
",",
"new_state",
",",
"data",
")",
":",
"raise",
"NotImplementedError"
] | [
218,
4
] | [
220,
33
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._send_device_command | (self, requested_state, requested_data) | Let tellcore update the actual device to the requested state. | Let tellcore update the actual device to the requested state. | def _send_device_command(self, requested_state, requested_data):
"""Let tellcore update the actual device to the requested state."""
raise NotImplementedError | [
"def",
"_send_device_command",
"(",
"self",
",",
"requested_state",
",",
"requested_data",
")",
":",
"raise",
"NotImplementedError"
] | [
222,
4
] | [
224,
33
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._send_repeated_command | (self) | Send a tellstick command once and decrease the repeat count. | Send a tellstick command once and decrease the repeat count. | def _send_repeated_command(self):
"""Send a tellstick command once and decrease the repeat count."""
with TELLSTICK_LOCK:
if self._repeats_left > 0:
self._repeats_left -= 1
try:
self._send_device_command(
self._requ... | [
"def",
"_send_repeated_command",
"(",
"self",
")",
":",
"with",
"TELLSTICK_LOCK",
":",
"if",
"self",
".",
"_repeats_left",
">",
"0",
":",
"self",
".",
"_repeats_left",
"-=",
"1",
"try",
":",
"self",
".",
"_send_device_command",
"(",
"self",
".",
"_requested_... | [
226,
4
] | [
237,
38
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._change_device_state | (self, new_state, data) | Turn on or off the device. | Turn on or off the device. | def _change_device_state(self, new_state, data):
"""Turn on or off the device."""
with TELLSTICK_LOCK:
# Set the requested state and number of repeats before calling
# _send_repeated_command the first time. Subsequent calls will be
# made from the callback. (We don't ... | [
"def",
"_change_device_state",
"(",
"self",
",",
"new_state",
",",
"data",
")",
":",
"with",
"TELLSTICK_LOCK",
":",
"# Set the requested state and number of repeats before calling",
"# _send_repeated_command the first time. Subsequent calls will be",
"# made from the callback. (We don'... | [
239,
4
] | [
255,
43
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | def turn_on(self, **kwargs):
"""Turn the switch on."""
self._change_device_state(True, self._parse_ha_data(kwargs)) | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_change_device_state",
"(",
"True",
",",
"self",
".",
"_parse_ha_data",
"(",
"kwargs",
")",
")"
] | [
257,
4
] | [
259,
68
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | def turn_off(self, **kwargs):
"""Turn the switch off."""
self._change_device_state(False, None) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_change_device_state",
"(",
"False",
",",
"None",
")"
] | [
261,
4
] | [
263,
46
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._update_model_from_command | (self, tellcore_command, tellcore_data) | Update the model, from a sent tellcore command and data. | Update the model, from a sent tellcore command and data. | def _update_model_from_command(self, tellcore_command, tellcore_data):
"""Update the model, from a sent tellcore command and data."""
if tellcore_command not in [TELLSTICK_TURNON, TELLSTICK_TURNOFF, TELLSTICK_DIM]:
_LOGGER.debug("Unhandled tellstick command: %d", tellcore_command)
... | [
"def",
"_update_model_from_command",
"(",
"self",
",",
"tellcore_command",
",",
"tellcore_data",
")",
":",
"if",
"tellcore_command",
"not",
"in",
"[",
"TELLSTICK_TURNON",
",",
"TELLSTICK_TURNOFF",
",",
"TELLSTICK_DIM",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Un... | [
265,
4
] | [
275,
9
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.update_from_callback | (self, tellcore_id, tellcore_command, tellcore_data) | Handle updates from the tellcore callback. | Handle updates from the tellcore callback. | def update_from_callback(self, tellcore_id, tellcore_command, tellcore_data):
"""Handle updates from the tellcore callback."""
if tellcore_id != self._tellcore_device.id:
return
self._update_model_from_command(tellcore_command, tellcore_data)
self.schedule_update_ha_state()
... | [
"def",
"update_from_callback",
"(",
"self",
",",
"tellcore_id",
",",
"tellcore_command",
",",
"tellcore_data",
")",
":",
"if",
"tellcore_id",
"!=",
"self",
".",
"_tellcore_device",
".",
"id",
":",
"return",
"self",
".",
"_update_model_from_command",
"(",
"tellcore... | [
277,
4
] | [
288,
41
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice._update_from_tellcore | (self) | Read the current state of the device from the tellcore library. | Read the current state of the device from the tellcore library. | def _update_from_tellcore(self):
"""Read the current state of the device from the tellcore library."""
with TELLSTICK_LOCK:
try:
last_command = self._tellcore_device.last_sent_command(
TELLSTICK_TURNON | TELLSTICK_TURNOFF | TELLSTICK_DIM
)... | [
"def",
"_update_from_tellcore",
"(",
"self",
")",
":",
"with",
"TELLSTICK_LOCK",
":",
"try",
":",
"last_command",
"=",
"self",
".",
"_tellcore_device",
".",
"last_sent_command",
"(",
"TELLSTICK_TURNON",
"|",
"TELLSTICK_TURNOFF",
"|",
"TELLSTICK_DIM",
")",
"last_data... | [
290,
4
] | [
301,
34
] | python | en | ['en', 'en', 'en'] | True |
TellstickDevice.update | (self) | Poll the current state of the device. | Poll the current state of the device. | def update(self):
"""Poll the current state of the device."""
self._update_from_tellcore() | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"_update_from_tellcore",
"(",
")"
] | [
303,
4
] | [
305,
36
] | python | en | ['en', 'en', 'en'] | True |
_async_has_devices | (hass) | Return if there are devices that can be discovered. | Return if there are devices that can be discovered. | async def _async_has_devices(hass) -> bool:
"""Return if there are devices that can be discovered."""
# TODO Check if there are any devices that can be discovered in the network.
devices = await hass.async_add_executor_job(my_pypi_dependency.discover)
return len(devices) > 0 | [
"async",
"def",
"_async_has_devices",
"(",
"hass",
")",
"->",
"bool",
":",
"# TODO Check if there are any devices that can be discovered in the network.",
"devices",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"my_pypi_dependency",
".",
"discover",
")",
"retur... | [
9,
0
] | [
13,
27
] | python | en | ['en', 'en', 'en'] | True |
test_smile_unauthorized | (hass, mock_smile_unauth) | Test failing unauthorization by Smile. | Test failing unauthorization by Smile. | async def test_smile_unauthorized(hass, mock_smile_unauth):
"""Test failing unauthorization by Smile."""
entry = await async_init_integration(hass, mock_smile_unauth)
assert entry.state == ENTRY_STATE_SETUP_ERROR | [
"async",
"def",
"test_smile_unauthorized",
"(",
"hass",
",",
"mock_smile_unauth",
")",
":",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
"mock_smile_unauth",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_ERROR"
] | [
17,
0
] | [
20,
49
] | python | en | ['en', 'en', 'it'] | True |
test_smile_error | (hass, mock_smile_error) | Test server error handling by Smile. | Test server error handling by Smile. | async def test_smile_error(hass, mock_smile_error):
"""Test server error handling by Smile."""
entry = await async_init_integration(hass, mock_smile_error)
assert entry.state == ENTRY_STATE_SETUP_RETRY | [
"async",
"def",
"test_smile_error",
"(",
"hass",
",",
"mock_smile_error",
")",
":",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
"mock_smile_error",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_RETRY"
] | [
23,
0
] | [
26,
49
] | python | da | ['no', 'da', 'en'] | False |
test_smile_notconnect | (hass, mock_smile_notconnect) | Connection failure error handling by Smile. | Connection failure error handling by Smile. | async def test_smile_notconnect(hass, mock_smile_notconnect):
"""Connection failure error handling by Smile."""
mock_smile_notconnect.connect.return_value = False
entry = await async_init_integration(hass, mock_smile_notconnect)
assert entry.state == ENTRY_STATE_SETUP_RETRY | [
"async",
"def",
"test_smile_notconnect",
"(",
"hass",
",",
"mock_smile_notconnect",
")",
":",
"mock_smile_notconnect",
".",
"connect",
".",
"return_value",
"=",
"False",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
"mock_smile_notconnect",
")",
... | [
29,
0
] | [
33,
49
] | python | en | ['en', 'en', 'en'] | True |
test_smile_timeout | (hass, mock_smile_notconnect) | Timeout error handling by Smile. | Timeout error handling by Smile. | async def test_smile_timeout(hass, mock_smile_notconnect):
"""Timeout error handling by Smile."""
mock_smile_notconnect.connect.side_effect = asyncio.TimeoutError
entry = await async_init_integration(hass, mock_smile_notconnect)
assert entry.state == ENTRY_STATE_SETUP_RETRY | [
"async",
"def",
"test_smile_timeout",
"(",
"hass",
",",
"mock_smile_notconnect",
")",
":",
"mock_smile_notconnect",
".",
"connect",
".",
"side_effect",
"=",
"asyncio",
".",
"TimeoutError",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
"mock_smil... | [
36,
0
] | [
40,
49
] | python | en | ['en', 'en', 'en'] | True |
test_smile_adam_xmlerror | (hass, mock_smile_adam) | Detect malformed XML by Smile in Adam environment. | Detect malformed XML by Smile in Adam environment. | async def test_smile_adam_xmlerror(hass, mock_smile_adam):
"""Detect malformed XML by Smile in Adam environment."""
mock_smile_adam.full_update_device.side_effect = Smile.XMLDataMissingError
entry = await async_init_integration(hass, mock_smile_adam)
assert entry.state == ENTRY_STATE_SETUP_RETRY | [
"async",
"def",
"test_smile_adam_xmlerror",
"(",
"hass",
",",
"mock_smile_adam",
")",
":",
"mock_smile_adam",
".",
"full_update_device",
".",
"side_effect",
"=",
"Smile",
".",
"XMLDataMissingError",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
... | [
43,
0
] | [
47,
49
] | python | en | ['en', 'en', 'en'] | True |
test_unload_entry | (hass, mock_smile_adam) | Test being able to unload an entry. | Test being able to unload an entry. | async def test_unload_entry(hass, mock_smile_adam):
"""Test being able to unload an entry."""
entry = await async_init_integration(hass, mock_smile_adam)
mock_smile_adam.async_reset = AsyncMock(return_value=True)
await hass.config_entries.async_unload(entry.entry_id)
await hass.async_block_till_don... | [
"async",
"def",
"test_unload_entry",
"(",
"hass",
",",
"mock_smile_adam",
")",
":",
"entry",
"=",
"await",
"async_init_integration",
"(",
"hass",
",",
"mock_smile_adam",
")",
"mock_smile_adam",
".",
"async_reset",
"=",
"AsyncMock",
"(",
"return_value",
"=",
"True"... | [
50,
0
] | [
58,
32
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry_fail | (hass) | Test async_setup_entry. | Test async_setup_entry. | async def test_async_setup_entry_fail(hass):
"""Test async_setup_entry."""
entry = MockConfigEntry(domain=DOMAIN, data={})
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ENTRY_STATE_SETUP_ERROR | [
"async",
"def",
"test_async_setup_entry_fail",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"}",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"hass",
".",
"config_entries",
"."... | [
61,
0
] | [
68,
49
] | python | en | ['en', 'be', 'en'] | False |
conv2d | (x_input, w_matrix) | conv2d returns a 2d convolution layer with full stride. | conv2d returns a 2d convolution layer with full stride. | def conv2d(x_input, w_matrix):
"""conv2d returns a 2d convolution layer with full stride."""
return tf.nn.conv2d(x_input, w_matrix, strides=[1, 1, 1, 1], padding='SAME') | [
"def",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
")",
":",
"return",
"tf",
".",
"nn",
".",
"conv2d",
"(",
"x_input",
",",
"w_matrix",
",",
"strides",
"=",
"[",
"1",
",",
"1",
",",
"1",
",",
"1",
"]",
",",
"padding",
"=",
"'SAME'",
")"
] | [
127,
0
] | [
129,
80
] | python | en | ['en', 'en', 'en'] | True |
max_pool | (x_input, pool_size) | max_pool downsamples a feature map by 2X. | max_pool downsamples a feature map by 2X. | def max_pool(x_input, pool_size):
"""max_pool downsamples a feature map by 2X."""
return tf.nn.max_pool(x_input, ksize=[1, pool_size, pool_size, 1],
strides=[1, pool_size, pool_size, 1], padding='SAME') | [
"def",
"max_pool",
"(",
"x_input",
",",
"pool_size",
")",
":",
"return",
"tf",
".",
"nn",
".",
"max_pool",
"(",
"x_input",
",",
"ksize",
"=",
"[",
"1",
",",
"pool_size",
",",
"pool_size",
",",
"1",
"]",
",",
"strides",
"=",
"[",
"1",
",",
"pool_siz... | [
132,
0
] | [
135,
79
] | python | en | ['en', 'en', 'en'] | True |
weight_variable | (shape) | weight_variable generates a weight variable of a given shape. | weight_variable generates a weight variable of a given shape. | def weight_variable(shape):
"""weight_variable generates a weight variable of a given shape."""
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial) | [
"def",
"weight_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"truncated_normal",
"(",
"shape",
",",
"stddev",
"=",
"0.1",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
143,
0
] | [
146,
31
] | python | en | ['en', 'en', 'en'] | True |
bias_variable | (shape) | bias_variable generates a bias variable of a given shape. | bias_variable generates a bias variable of a given shape. | def bias_variable(shape):
"""bias_variable generates a bias variable of a given shape."""
initial = tf.constant(0.1, shape=shape)
return tf.Variable(initial) | [
"def",
"bias_variable",
"(",
"shape",
")",
":",
"initial",
"=",
"tf",
".",
"constant",
"(",
"0.1",
",",
"shape",
"=",
"shape",
")",
"return",
"tf",
".",
"Variable",
"(",
"initial",
")"
] | [
149,
0
] | [
152,
31
] | python | en | ['en', 'en', 'en'] | True |
download_mnist_retry | (data_dir, max_num_retries=20) | Try to download mnist dataset and avoid errors | Try to download mnist dataset and avoid errors | def download_mnist_retry(data_dir, max_num_retries=20):
"""Try to download mnist dataset and avoid errors"""
for _ in range(max_num_retries):
try:
return input_data.read_data_sets(data_dir, one_hot=True)
except tf.errors.AlreadyExistsError:
time.sleep(1)
raise Excepti... | [
"def",
"download_mnist_retry",
"(",
"data_dir",
",",
"max_num_retries",
"=",
"20",
")",
":",
"for",
"_",
"in",
"range",
"(",
"max_num_retries",
")",
":",
"try",
":",
"return",
"input_data",
".",
"read_data_sets",
"(",
"data_dir",
",",
"one_hot",
"=",
"True",... | [
155,
0
] | [
162,
48
] | python | en | ['en', 'en', 'en'] | True |
main | (params) |
Main function, build mnist network, run and send result to NNI.
|
Main function, build mnist network, run and send result to NNI.
| def main(params):
'''
Main function, build mnist network, run and send result to NNI.
'''
# Import data
mnist = download_mnist_retry(params['data_dir'])
print('Mnist download data done.')
logger.debug('Mnist download data done.')
# Create the model
# Build the graph for the deep net... | [
"def",
"main",
"(",
"params",
")",
":",
"# Import data",
"mnist",
"=",
"download_mnist_retry",
"(",
"params",
"[",
"'data_dir'",
"]",
")",
"print",
"(",
"'Mnist download data done.'",
")",
"logger",
".",
"debug",
"(",
"'Mnist download data done.'",
")",
"# Create ... | [
164,
0
] | [
221,
47
] | python | en | ['en', 'error', 'th'] | False |
get_params | () | Get parameters from command line | Get parameters from command line | def get_params():
''' Get parameters from command line '''
parser = argparse.ArgumentParser()
parser.add_argument("--data_dir", type=str, default='/tmp/tensorflow/mnist/input_data', help="data directory")
parser.add_argument("--dropout_rate", type=float, default=0.5, help="dropout rate")
parser.add_... | [
"def",
"get_params",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"\"--data_dir\"",
",",
"type",
"=",
"str",
",",
"default",
"=",
"'/tmp/tensorflow/mnist/input_data'",
",",
"help",
"=",
"\"data ... | [
223,
0
] | [
238,
15
] | python | en | ['en', 'en', 'en'] | True |
MnistNetwork.__init__ | (self,
channel_1_num,
channel_2_num,
conv_size,
hidden_size,
pool_size,
learning_rate,
x_dim=784,
y_dim=10) | @nni.variable(nni.choice(2, 3, 5, 7),name=self.conv_size) | def __init__(self,
channel_1_num,
channel_2_num,
conv_size,
hidden_size,
pool_size,
learning_rate,
x_dim=784,
y_dim=10):
self.channel_1_num = channel_1_num
self.channel... | [
"def",
"__init__",
"(",
"self",
",",
"channel_1_num",
",",
"channel_2_num",
",",
"conv_size",
",",
"hidden_size",
",",
"pool_size",
",",
"learning_rate",
",",
"x_dim",
"=",
"784",
",",
"y_dim",
"=",
"10",
")",
":",
"self",
".",
"channel_1_num",
"=",
"chann... | [
20,
4
] | [
46,
28
] | python | ceb | ['en', 'ceb', 'sw'] | False | |
MnistNetwork.build_network | (self) |
Building network for mnist
|
Building network for mnist
| def build_network(self):
'''
Building network for mnist
'''
# Reshape to use within a convolutional neural net.
# Last dimension is for "features" - there is only one here, since images are
# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.
with tf.n... | [
"def",
"build_network",
"(",
"self",
")",
":",
"# Reshape to use within a convolutional neural net.",
"# Last dimension is for \"features\" - there is only one here, since images are",
"# grayscale -- it would be 3 for an RGB image, 4 for RGBA, etc.",
"with",
"tf",
".",
"name_scope",
"(",
... | [
48,
4
] | [
124,
56
] | python | en | ['en', 'error', 'th'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the iGlo lights. | Set up the iGlo lights. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the iGlo lights."""
host = config.get(CONF_HOST)
name = config.get(CONF_NAME)
port = config.get(CONF_PORT)
add_entities([IGloLamp(name, host, port)], True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"port",
"=",
"co... | [
34,
0
] | [
39,
52
] | python | en | ['en', 'haw', 'en'] | True |
IGloLamp.__init__ | (self, name, host, port) | Initialize the light. | Initialize the light. | def __init__(self, name, host, port):
"""Initialize the light."""
self._name = name
self._lamp = Lamp(0, host, port) | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"host",
",",
"port",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_lamp",
"=",
"Lamp",
"(",
"0",
",",
"host",
",",
"port",
")"
] | [
45,
4
] | [
49,
40
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.name | (self) | Return the name of the light. | Return the name of the light. | def name(self):
"""Return the name of the light."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
52,
4
] | [
54,
25
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.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."""
return int((self._lamp.state()["brightness"] / 200.0) * 255) | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"int",
"(",
"(",
"self",
".",
"_lamp",
".",
"state",
"(",
")",
"[",
"\"brightness\"",
"]",
"/",
"200.0",
")",
"*",
"255",
")"
] | [
57,
4
] | [
59,
68
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.color_temp | (self) | Return the color temperature. | Return the color temperature. | def color_temp(self):
"""Return the color temperature."""
return color_util.color_temperature_kelvin_to_mired(self._lamp.state()["white"]) | [
"def",
"color_temp",
"(",
"self",
")",
":",
"return",
"color_util",
".",
"color_temperature_kelvin_to_mired",
"(",
"self",
".",
"_lamp",
".",
"state",
"(",
")",
"[",
"\"white\"",
"]",
")"
] | [
62,
4
] | [
64,
88
] | python | en | ['en', 'la', 'en'] | True |
IGloLamp.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."""
return math.ceil(
color_util.color_temperature_kelvin_to_mired(self._lamp.max_kelvin)
) | [
"def",
"min_mireds",
"(",
"self",
")",
":",
"return",
"math",
".",
"ceil",
"(",
"color_util",
".",
"color_temperature_kelvin_to_mired",
"(",
"self",
".",
"_lamp",
".",
"max_kelvin",
")",
")"
] | [
67,
4
] | [
71,
9
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.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."""
return math.ceil(
color_util.color_temperature_kelvin_to_mired(self._lamp.min_kelvin)
) | [
"def",
"max_mireds",
"(",
"self",
")",
":",
"return",
"math",
".",
"ceil",
"(",
"color_util",
".",
"color_temperature_kelvin_to_mired",
"(",
"self",
".",
"_lamp",
".",
"min_kelvin",
")",
")"
] | [
74,
4
] | [
78,
9
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.hs_color | (self) | Return the hs value. | Return the hs value. | def hs_color(self):
"""Return the hs value."""
return color_util.color_RGB_to_hs(*self._lamp.state()["rgb"]) | [
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"color_util",
".",
"color_RGB_to_hs",
"(",
"*",
"self",
".",
"_lamp",
".",
"state",
"(",
")",
"[",
"\"rgb\"",
"]",
")"
] | [
81,
4
] | [
83,
69
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.effect | (self) | Return the current effect. | Return the current effect. | def effect(self):
"""Return the current effect."""
return self._lamp.state()["effect"] | [
"def",
"effect",
"(",
"self",
")",
":",
"return",
"self",
".",
"_lamp",
".",
"state",
"(",
")",
"[",
"\"effect\"",
"]"
] | [
86,
4
] | [
88,
43
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.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."""
return self._lamp.effect_list() | [
"def",
"effect_list",
"(",
"self",
")",
":",
"return",
"self",
".",
"_lamp",
".",
"effect_list",
"(",
")"
] | [
91,
4
] | [
93,
39
] | python | en | ['en', 'en', 'en'] | True |
IGloLamp.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP | SUPPORT_COLOR | SUPPORT_EFFECT | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_COLOR_TEMP",
"|",
"SUPPORT_COLOR",
"|",
"SUPPORT_EFFECT"
] | [
96,
4
] | [
98,
87
] | python | en | ['da', 'en', 'en'] | True |
IGloLamp.is_on | (self) | Return true if light is on. | Return true if light is on. | def is_on(self):
"""Return true if light is on."""
return self._lamp.state()["on"] | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_lamp",
".",
"state",
"(",
")",
"[",
"\"on\"",
"]"
] | [
101,
4
] | [
103,
39
] | python | en | ['en', 'et', 'en'] | True |
IGloLamp.turn_on | (self, **kwargs) | Turn the light on. | Turn the light on. | def turn_on(self, **kwargs):
"""Turn the light on."""
if not self.is_on:
self._lamp.switch(True)
if ATTR_BRIGHTNESS in kwargs:
brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0)
self._lamp.brightness(brightness)
return
if ATTR_HS_... | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"is_on",
":",
"self",
".",
"_lamp",
".",
"switch",
"(",
"True",
")",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"brightness",
"=",
"int",
"(",
"(",
"kwar... | [
105,
4
] | [
129,
18
] | python | en | ['en', 'et', 'en'] | True |
IGloLamp.turn_off | (self, **kwargs) | Turn the light off. | Turn the light off. | def turn_off(self, **kwargs):
"""Turn the light off."""
self._lamp.switch(False) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_lamp",
".",
"switch",
"(",
"False",
")"
] | [
131,
4
] | [
133,
32
] | python | en | ['en', 'zh', 'en'] | True |
shades | (name: str) | Create motorized shades with given name. | Create motorized shades with given name. | def shades(name: str):
"""Create motorized shades with given name."""
return {"name": name, "type": DeviceType.MOTORIZED_SHADES} | [
"def",
"shades",
"(",
"name",
":",
"str",
")",
":",
"return",
"{",
"\"name\"",
":",
"name",
",",
"\"type\"",
":",
"DeviceType",
".",
"MOTORIZED_SHADES",
"}"
] | [
26,
0
] | [
28,
62
] | python | en | ['en', 'en', 'en'] | True |
test_entity_registry | (hass: core.HomeAssistant) | Tests that the devices are registered in the entity registry. | Tests that the devices are registered in the entity registry. | async def test_entity_registry(hass: core.HomeAssistant):
"""Tests that the devices are registered in the entity registry."""
await setup_platform(
hass,
COVER_DOMAIN,
shades("name-1"),
bond_version={"bondid": "test-hub-id"},
bond_device_id="test-device-id",
)
re... | [
"async",
"def",
"test_entity_registry",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
",",
"bond_version",
"=",
"{",
"\"bondid\"",
":",
"\"test-hub-... | [
31,
0
] | [
43,
59
] | python | en | ['en', 'en', 'en'] | True |
test_open_cover | (hass: core.HomeAssistant) | Tests that open cover command delegates to API. | Tests that open cover command delegates to API. | async def test_open_cover(hass: core.HomeAssistant):
"""Tests that open cover command delegates to API."""
await setup_platform(
hass, COVER_DOMAIN, shades("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_open, patch_bond_device_state():
await hass.services.... | [
"async",
"def",
"test_open_cover",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"with",
"pat... | [
46,
0
] | [
61,
70
] | python | en | ['en', 'en', 'en'] | True |
test_close_cover | (hass: core.HomeAssistant) | Tests that close cover command delegates to API. | Tests that close cover command delegates to API. | async def test_close_cover(hass: core.HomeAssistant):
"""Tests that close cover command delegates to API."""
await setup_platform(
hass, COVER_DOMAIN, shades("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_close, patch_bond_device_state():
await hass.servic... | [
"async",
"def",
"test_close_cover",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"with",
"pa... | [
64,
0
] | [
79,
72
] | python | en | ['en', 'en', 'en'] | True |
test_stop_cover | (hass: core.HomeAssistant) | Tests that stop cover command delegates to API. | Tests that stop cover command delegates to API. | async def test_stop_cover(hass: core.HomeAssistant):
"""Tests that stop cover command delegates to API."""
await setup_platform(
hass, COVER_DOMAIN, shades("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_hold, patch_bond_device_state():
await hass.services.... | [
"async",
"def",
"test_stop_cover",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"with",
"pat... | [
82,
0
] | [
97,
70
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_open_cover | (hass: core.HomeAssistant) | Tests that update command sets correct state when Bond API reports cover is open. | Tests that update command sets correct state when Bond API reports cover is open. | async def test_update_reports_open_cover(hass: core.HomeAssistant):
"""Tests that update command sets correct state when Bond API reports cover is open."""
await setup_platform(hass, COVER_DOMAIN, shades("name-1"))
with patch_bond_device_state(return_value={"open": 1}):
async_fire_time_changed(hass... | [
"async",
"def",
"test_update_reports_open_cover",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"return_val... | [
100,
0
] | [
108,
58
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_closed_cover | (hass: core.HomeAssistant) | Tests that update command sets correct state when Bond API reports cover is closed. | Tests that update command sets correct state when Bond API reports cover is closed. | async def test_update_reports_closed_cover(hass: core.HomeAssistant):
"""Tests that update command sets correct state when Bond API reports cover is closed."""
await setup_platform(hass, COVER_DOMAIN, shades("name-1"))
with patch_bond_device_state(return_value={"open": 0}):
async_fire_time_changed(... | [
"async",
"def",
"test_update_reports_closed_cover",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"return_v... | [
111,
0
] | [
119,
60
] | python | en | ['en', 'en', 'en'] | True |
test_cover_available | (hass: core.HomeAssistant) | Tests that available state is updated based on API errors. | Tests that available state is updated based on API errors. | async def test_cover_available(hass: core.HomeAssistant):
"""Tests that available state is updated based on API errors."""
await help_test_entity_available(
hass, COVER_DOMAIN, shades("name-1"), "cover.name_1"
) | [
"async",
"def",
"test_cover_available",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"help_test_entity_available",
"(",
"hass",
",",
"COVER_DOMAIN",
",",
"shades",
"(",
"\"name-1\"",
")",
",",
"\"cover.name_1\"",
")"
] | [
122,
0
] | [
126,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config, async_add_entities) | Set up the Blink Alarm Control Panels. | Set up the Blink Alarm Control Panels. | async def async_setup_entry(hass, config, async_add_entities):
"""Set up the Blink Alarm Control Panels."""
data = hass.data[DOMAIN][config.entry_id]
sync_modules = []
for sync_name, sync_module in data.sync.items():
sync_modules.append(BlinkSyncModule(data, sync_name, sync_module))
async_a... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")",
":",
"data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config",
".",
"entry_id",
"]",
"sync_modules",
"=",
"[",
"]",
"for",
"sync_name",
",",
"sync... | [
18,
0
] | [
25,
36
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.__init__ | (self, data, name, sync) | Initialize the alarm control panel. | Initialize the alarm control panel. | def __init__(self, data, name, sync):
"""Initialize the alarm control panel."""
self.data = data
self.sync = sync
self._name = name
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"name",
",",
"sync",
")",
":",
"self",
".",
"data",
"=",
"data",
"self",
".",
"sync",
"=",
"sync",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state",
"=",
"None"
] | [
31,
4
] | [
36,
26
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.unique_id | (self) | Return the unique id for the sync module. | Return the unique id for the sync module. | def unique_id(self):
"""Return the unique id for the sync module."""
return self.sync.serial | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"sync",
".",
"serial"
] | [
39,
4
] | [
41,
31
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.icon | (self) | Return icon. | Return icon. | def icon(self):
"""Return icon."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
44,
4
] | [
46,
19
] | python | en | ['en', 'la', 'en'] | False |
BlinkSyncModule.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
49,
4
] | [
51,
26
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_AWAY | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"SUPPORT_ALARM_ARM_AWAY"
] | [
54,
4
] | [
56,
37
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.name | (self) | Return the name of the panel. | Return the name of the panel. | def name(self):
"""Return the name of the panel."""
return f"{DOMAIN} {self._name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{DOMAIN} {self._name}\""
] | [
59,
4
] | [
61,
39
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
attr = self.sync.attributes
attr["network_info"] = self.data.networks
attr["associated_cameras"] = list(self.sync.cameras)
attr[ATTR_ATTRIBUTION] = DEFAULT_ATTRIBUTION
return attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attr",
"=",
"self",
".",
"sync",
".",
"attributes",
"attr",
"[",
"\"network_info\"",
"]",
"=",
"self",
".",
"data",
".",
"networks",
"attr",
"[",
"\"associated_cameras\"",
"]",
"=",
"list",
"(",
"se... | [
64,
4
] | [
70,
19
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.update | (self) | Update the state of the device. | Update the state of the device. | def update(self):
"""Update the state of the device."""
_LOGGER.debug("Updating Blink Alarm Control Panel %s", self._name)
self.data.refresh()
mode = self.sync.arm
if mode:
self._state = STATE_ALARM_ARMED_AWAY
else:
self._state = STATE_ALARM_DISARM... | [
"def",
"update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Updating Blink Alarm Control Panel %s\"",
",",
"self",
".",
"_name",
")",
"self",
".",
"data",
".",
"refresh",
"(",
")",
"mode",
"=",
"self",
".",
"sync",
".",
"arm",
"if",
"mode",
... | [
72,
4
] | [
80,
46
] | python | en | ['en', 'en', 'en'] | True |
BlinkSyncModule.alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | def alarm_disarm(self, code=None):
"""Send disarm command."""
self.sync.arm = False
self.sync.refresh() | [
"def",
"alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"sync",
".",
"arm",
"=",
"False",
"self",
".",
"sync",
".",
"refresh",
"(",
")"
] | [
82,
4
] | [
85,
27
] | python | en | ['en', 'pt', 'en'] | True |
BlinkSyncModule.alarm_arm_away | (self, code=None) | Send arm command. | Send arm command. | def alarm_arm_away(self, code=None):
"""Send arm command."""
self.sync.arm = True
self.sync.refresh() | [
"def",
"alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"sync",
".",
"arm",
"=",
"True",
"self",
".",
"sync",
".",
"refresh",
"(",
")"
] | [
87,
4
] | [
90,
27
] | python | en | ['en', 'fr', 'en'] | True |
update_ema | (biased_ema, value, decay) |
calculate biased stat and unbiased stat in each step using exponential moving average method
Parameters
----------
biased_ema : float
previous stat value
value : float
current stat value
decay : float
the weight of previous stat value, larger means smoother curve
R... |
calculate biased stat and unbiased stat in each step using exponential moving average method | def update_ema(biased_ema, value, decay):
"""
calculate biased stat and unbiased stat in each step using exponential moving average method
Parameters
----------
biased_ema : float
previous stat value
value : float
current stat value
decay : float
the weight of previo... | [
"def",
"update_ema",
"(",
"biased_ema",
",",
"value",
",",
"decay",
")",
":",
"biased_ema",
"=",
"biased_ema",
"*",
"decay",
"+",
"(",
"1",
"-",
"decay",
")",
"*",
"value",
"return",
"biased_ema"
] | [
43,
0
] | [
61,
21
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.