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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
evaluate | (data_file, pred_file) |
Evaluate.
|
Evaluate.
| def evaluate(data_file, pred_file):
'''
Evaluate.
'''
expected_version = '1.1'
with open(data_file) as dataset_file:
dataset_json = json.load(dataset_file)
if dataset_json['version'] != expected_version:
print('Evaluation expects v-' + expected_version +
... | [
"def",
"evaluate",
"(",
"data_file",
",",
"pred_file",
")",
":",
"expected_version",
"=",
"'1.1'",
"with",
"open",
"(",
"data_file",
")",
"as",
"dataset_file",
":",
"dataset_json",
"=",
"json",
".",
"load",
"(",
"dataset_file",
")",
"if",
"dataset_json",
"["... | [
117,
0
] | [
134,
32
] | python | en | ['en', 'error', 'th'] | False |
evaluate_with_predictions | (data_file, predictions) |
Evalutate with predictions/
|
Evalutate with predictions/
| def evaluate_with_predictions(data_file, predictions):
'''
Evalutate with predictions/
'''
expected_version = '1.1'
with open(data_file) as dataset_file:
dataset_json = json.load(dataset_file)
if dataset_json['version'] != expected_version:
print('Evaluation expects v-' +... | [
"def",
"evaluate_with_predictions",
"(",
"data_file",
",",
"predictions",
")",
":",
"expected_version",
"=",
"'1.1'",
"with",
"open",
"(",
"data_file",
")",
"as",
"dataset_file",
":",
"dataset_json",
"=",
"json",
".",
"load",
"(",
"dataset_file",
")",
"if",
"d... | [
136,
0
] | [
149,
32
] | python | en | ['en', 'error', 'th'] | False |
nix_prefetch_url | (url, algo='sha256') | Prefetches the content of the given URL. | Prefetches the content of the given URL. | def nix_prefetch_url(url, algo='sha256'):
"""Prefetches the content of the given URL."""
print(f'nix-prefetch-url {url}')
out = subprocess.check_output(['nix-prefetch-url', '--type', algo, url])
return out.decode('utf-8').rstrip() | [
"def",
"nix_prefetch_url",
"(",
"url",
",",
"algo",
"=",
"'sha256'",
")",
":",
"print",
"(",
"f'nix-prefetch-url {url}'",
")",
"out",
"=",
"subprocess",
".",
"check_output",
"(",
"[",
"'nix-prefetch-url'",
",",
"'--type'",
",",
"algo",
",",
"url",
"]",
")",
... | [
23,
0
] | [
27,
39
] | python | en | ['en', 'en', 'en'] | True |
_handle_async_response | (func, hass, connection, msg) | Create a response and handle exception. | Create a response and handle exception. | async def _handle_async_response(func, hass, connection, msg):
"""Create a response and handle exception."""
try:
await func(hass, connection, msg)
except Exception as err: # pylint: disable=broad-except
connection.async_handle_exception(msg, err) | [
"async",
"def",
"_handle_async_response",
"(",
"func",
",",
"hass",
",",
"connection",
",",
"msg",
")",
":",
"try",
":",
"await",
"func",
"(",
"hass",
",",
"connection",
",",
"msg",
")",
"except",
"Exception",
"as",
"err",
":",
"# pylint: disable=broad-excep... | [
14,
0
] | [
19,
51
] | python | en | ['en', 'en', 'en'] | True |
async_response | (
func: Callable[[HomeAssistant, ActiveConnection, dict], Awaitable[None]]
) | Decorate an async function to handle WebSocket API messages. | Decorate an async function to handle WebSocket API messages. | def async_response(
func: Callable[[HomeAssistant, ActiveConnection, dict], Awaitable[None]]
) -> const.WebSocketCommandHandler:
"""Decorate an async function to handle WebSocket API messages."""
@callback
@wraps(func)
def schedule_handler(hass, connection, msg):
"""Schedule the handler."""... | [
"def",
"async_response",
"(",
"func",
":",
"Callable",
"[",
"[",
"HomeAssistant",
",",
"ActiveConnection",
",",
"dict",
"]",
",",
"Awaitable",
"[",
"None",
"]",
"]",
")",
"->",
"const",
".",
"WebSocketCommandHandler",
":",
"@",
"callback",
"@",
"wraps",
"(... | [
22,
0
] | [
35,
27
] | python | en | ['en', 'en', 'en'] | True |
require_admin | (func: const.WebSocketCommandHandler) | Websocket decorator to require user to be an admin. | Websocket decorator to require user to be an admin. | def require_admin(func: const.WebSocketCommandHandler) -> const.WebSocketCommandHandler:
"""Websocket decorator to require user to be an admin."""
@wraps(func)
def with_admin(hass, connection, msg):
"""Check admin and call function."""
user = connection.user
if user is None or not ... | [
"def",
"require_admin",
"(",
"func",
":",
"const",
".",
"WebSocketCommandHandler",
")",
"->",
"const",
".",
"WebSocketCommandHandler",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"with_admin",
"(",
"hass",
",",
"connection",
",",
"msg",
")",
":",
"\"\"\"Chec... | [
38,
0
] | [
51,
21
] | python | en | ['en', 'en', 'en'] | True |
ws_require_user | (
only_owner=False,
only_system_user=False,
allow_system_user=True,
only_active_user=True,
only_inactive_user=False,
) | Decorate function validating login user exist in current WS connection.
Will write out error message if not authenticated.
| Decorate function validating login user exist in current WS connection. | def ws_require_user(
only_owner=False,
only_system_user=False,
allow_system_user=True,
only_active_user=True,
only_inactive_user=False,
):
"""Decorate function validating login user exist in current WS connection.
Will write out error message if not authenticated.
"""
def validator... | [
"def",
"ws_require_user",
"(",
"only_owner",
"=",
"False",
",",
"only_system_user",
"=",
"False",
",",
"allow_system_user",
"=",
"True",
",",
"only_active_user",
"=",
"True",
",",
"only_inactive_user",
"=",
"False",
",",
")",
":",
"def",
"validator",
"(",
"fun... | [
54,
0
] | [
107,
20
] | python | en | ['de', 'en', 'en'] | True |
websocket_command | (
schema: dict,
) | Tag a function as a websocket command. | Tag a function as a websocket command. | def websocket_command(
schema: dict,
) -> Callable[[const.WebSocketCommandHandler], const.WebSocketCommandHandler]:
"""Tag a function as a websocket command."""
command = schema["type"]
def decorate(func):
"""Decorate ws command function."""
# pylint: disable=protected-access
fu... | [
"def",
"websocket_command",
"(",
"schema",
":",
"dict",
",",
")",
"->",
"Callable",
"[",
"[",
"const",
".",
"WebSocketCommandHandler",
"]",
",",
"const",
".",
"WebSocketCommandHandler",
"]",
":",
"command",
"=",
"schema",
"[",
"\"type\"",
"]",
"def",
"decora... | [
110,
0
] | [
123,
19
] | python | en | ['en', 'en', 'en'] | True |
pytest_configure | (config) | Register marker for tests that log exceptions. | Register marker for tests that log exceptions. | def pytest_configure(config):
"""Register marker for tests that log exceptions."""
config.addinivalue_line(
"markers", "no_fail_on_log_exception: mark test to not fail on logged exception"
) | [
"def",
"pytest_configure",
"(",
"config",
")",
":",
"config",
".",
"addinivalue_line",
"(",
"\"markers\"",
",",
"\"no_fail_on_log_exception: mark test to not fail on logged exception\"",
")"
] | [
52,
0
] | [
56,
5
] | python | en | ['en', 'en', 'en'] | True |
check_real | (func) | Force a function to require a keyword _test_real to be passed in. | Force a function to require a keyword _test_real to be passed in. | def check_real(func):
"""Force a function to require a keyword _test_real to be passed in."""
@functools.wraps(func)
async def guard_func(*args, **kwargs):
real = kwargs.pop("_test_real", None)
if not real:
raise Exception(
'Forgot to mock or pass "_test_real=Tr... | [
"def",
"check_real",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"async",
"def",
"guard_func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"real",
"=",
"kwargs",
".",
"pop",
"(",
"\"_test_real\"",
",",
"None",
... | [
59,
0
] | [
73,
21
] | python | en | ['en', 'en', 'en'] | True |
verify_cleanup | () | Verify that the test has cleaned up resources correctly. | Verify that the test has cleaned up resources correctly. | def verify_cleanup():
"""Verify that the test has cleaned up resources correctly."""
threads_before = frozenset(threading.enumerate())
yield
if len(INSTANCES) >= 2:
count = len(INSTANCES)
for inst in INSTANCES:
inst.stop()
pytest.exit(f"Detected non stopped instance... | [
"def",
"verify_cleanup",
"(",
")",
":",
"threads_before",
"=",
"frozenset",
"(",
"threading",
".",
"enumerate",
"(",
")",
")",
"yield",
"if",
"len",
"(",
"INSTANCES",
")",
">=",
"2",
":",
"count",
"=",
"len",
"(",
"INSTANCES",
")",
"for",
"inst",
"in",... | [
82,
0
] | [
95,
22
] | python | en | ['en', 'en', 'en'] | True |
hass_storage | () | Fixture to mock storage. | Fixture to mock storage. | def hass_storage():
"""Fixture to mock storage."""
with mock_storage() as stored_data:
yield stored_data | [
"def",
"hass_storage",
"(",
")",
":",
"with",
"mock_storage",
"(",
")",
"as",
"stored_data",
":",
"yield",
"stored_data"
] | [
99,
0
] | [
102,
25
] | python | en | ['en', 'nl', 'en'] | True |
hass | (loop, hass_storage, request) | Fixture to provide a test instance of Home Assistant. | Fixture to provide a test instance of Home Assistant. | def hass(loop, hass_storage, request):
"""Fixture to provide a test instance of Home Assistant."""
def exc_handle(loop, context):
"""Handle exceptions by rethrowing them, which will fail the test."""
# Most of these contexts will contain an exception, but not all.
# The docs note the ke... | [
"def",
"hass",
"(",
"loop",
",",
"hass_storage",
",",
"request",
")",
":",
"def",
"exc_handle",
"(",
"loop",
",",
"context",
")",
":",
"\"\"\"Handle exceptions by rethrowing them, which will fail the test.\"\"\"",
"# Most of these contexts will contain an exception, but not all... | [
106,
0
] | [
141,
16
] | python | en | ['en', 'en', 'en'] | True |
stop_hass | () | Make sure all hass are stopped. | Make sure all hass are stopped. | async def stop_hass():
"""Make sure all hass are stopped."""
orig_hass = ha.HomeAssistant
created = []
def mock_hass():
hass_inst = orig_hass()
created.append(hass_inst)
return hass_inst
with patch("homeassistant.core.HomeAssistant", mock_hass):
yield
for hass... | [
"async",
"def",
"stop_hass",
"(",
")",
":",
"orig_hass",
"=",
"ha",
".",
"HomeAssistant",
"created",
"=",
"[",
"]",
"def",
"mock_hass",
"(",
")",
":",
"hass_inst",
"=",
"orig_hass",
"(",
")",
"created",
".",
"append",
"(",
"hass_inst",
")",
"return",
"... | [
145,
0
] | [
165,
50
] | python | en | ['en', 'en', 'en'] | True |
requests_mock | () | Fixture to provide a requests mocker. | Fixture to provide a requests mocker. | def requests_mock():
"""Fixture to provide a requests mocker."""
with _requests_mock.mock() as m:
yield m | [
"def",
"requests_mock",
"(",
")",
":",
"with",
"_requests_mock",
".",
"mock",
"(",
")",
"as",
"m",
":",
"yield",
"m"
] | [
169,
0
] | [
172,
15
] | python | en | ['en', 'en', 'en'] | True |
aioclient_mock | () | Fixture to mock aioclient calls. | Fixture to mock aioclient calls. | def aioclient_mock():
"""Fixture to mock aioclient calls."""
with mock_aiohttp_client() as mock_session:
yield mock_session | [
"def",
"aioclient_mock",
"(",
")",
":",
"with",
"mock_aiohttp_client",
"(",
")",
"as",
"mock_session",
":",
"yield",
"mock_session"
] | [
176,
0
] | [
179,
26
] | python | en | ['en', 'ca', 'en'] | True |
mock_device_tracker_conf | () | Prevent device tracker from reading/writing data. | Prevent device tracker from reading/writing data. | def mock_device_tracker_conf():
"""Prevent device tracker from reading/writing data."""
devices = []
async def mock_update_config(path, id, entity):
devices.append(entity)
with patch(
"homeassistant.components.device_tracker.legacy"
".DeviceTracker.async_update_config",
... | [
"def",
"mock_device_tracker_conf",
"(",
")",
":",
"devices",
"=",
"[",
"]",
"async",
"def",
"mock_update_config",
"(",
"path",
",",
"id",
",",
"entity",
")",
":",
"devices",
".",
"append",
"(",
"entity",
")",
"with",
"patch",
"(",
"\"homeassistant.components... | [
183,
0
] | [
198,
21
] | python | en | ['en', 'en', 'en'] | True |
hass_access_token | (hass, hass_admin_user) | Return an access token to access Home Assistant. | Return an access token to access Home Assistant. | def hass_access_token(hass, hass_admin_user):
"""Return an access token to access Home Assistant."""
refresh_token = hass.loop.run_until_complete(
hass.auth.async_create_refresh_token(hass_admin_user, CLIENT_ID)
)
return hass.auth.async_create_access_token(refresh_token) | [
"def",
"hass_access_token",
"(",
"hass",
",",
"hass_admin_user",
")",
":",
"refresh_token",
"=",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"hass",
".",
"auth",
".",
"async_create_refresh_token",
"(",
"hass_admin_user",
",",
"CLIENT_ID",
")",
")",
"ret... | [
202,
0
] | [
207,
61
] | python | en | ['en', 'en', 'en'] | True |
hass_owner_user | (hass, local_auth) | Return a Home Assistant admin user. | Return a Home Assistant admin user. | def hass_owner_user(hass, local_auth):
"""Return a Home Assistant admin user."""
return MockUser(is_owner=True).add_to_hass(hass) | [
"def",
"hass_owner_user",
"(",
"hass",
",",
"local_auth",
")",
":",
"return",
"MockUser",
"(",
"is_owner",
"=",
"True",
")",
".",
"add_to_hass",
"(",
"hass",
")"
] | [
211,
0
] | [
213,
52
] | python | en | ['en', 'en', 'en'] | True |
hass_admin_user | (hass, local_auth) | Return a Home Assistant admin user. | Return a Home Assistant admin user. | def hass_admin_user(hass, local_auth):
"""Return a Home Assistant admin user."""
admin_group = hass.loop.run_until_complete(
hass.auth.async_get_group(GROUP_ID_ADMIN)
)
return MockUser(groups=[admin_group]).add_to_hass(hass) | [
"def",
"hass_admin_user",
"(",
"hass",
",",
"local_auth",
")",
":",
"admin_group",
"=",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"hass",
".",
"auth",
".",
"async_get_group",
"(",
"GROUP_ID_ADMIN",
")",
")",
"return",
"MockUser",
"(",
"groups",
"=... | [
217,
0
] | [
222,
59
] | python | en | ['en', 'en', 'en'] | True |
hass_read_only_user | (hass, local_auth) | Return a Home Assistant read only user. | Return a Home Assistant read only user. | def hass_read_only_user(hass, local_auth):
"""Return a Home Assistant read only user."""
read_only_group = hass.loop.run_until_complete(
hass.auth.async_get_group(GROUP_ID_READ_ONLY)
)
return MockUser(groups=[read_only_group]).add_to_hass(hass) | [
"def",
"hass_read_only_user",
"(",
"hass",
",",
"local_auth",
")",
":",
"read_only_group",
"=",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"hass",
".",
"auth",
".",
"async_get_group",
"(",
"GROUP_ID_READ_ONLY",
")",
")",
"return",
"MockUser",
"(",
"g... | [
226,
0
] | [
231,
63
] | python | en | ['en', 'en', 'en'] | True |
hass_read_only_access_token | (hass, hass_read_only_user) | Return a Home Assistant read only user. | Return a Home Assistant read only user. | def hass_read_only_access_token(hass, hass_read_only_user):
"""Return a Home Assistant read only user."""
refresh_token = hass.loop.run_until_complete(
hass.auth.async_create_refresh_token(hass_read_only_user, CLIENT_ID)
)
return hass.auth.async_create_access_token(refresh_token) | [
"def",
"hass_read_only_access_token",
"(",
"hass",
",",
"hass_read_only_user",
")",
":",
"refresh_token",
"=",
"hass",
".",
"loop",
".",
"run_until_complete",
"(",
"hass",
".",
"auth",
".",
"async_create_refresh_token",
"(",
"hass_read_only_user",
",",
"CLIENT_ID",
... | [
235,
0
] | [
240,
61
] | python | en | ['en', 'en', 'en'] | True |
legacy_auth | (hass) | Load legacy API password provider. | Load legacy API password provider. | def legacy_auth(hass):
"""Load legacy API password provider."""
prv = legacy_api_password.LegacyApiPasswordAuthProvider(
hass,
hass.auth._store,
{"type": "legacy_api_password", "api_password": "test-password"},
)
hass.auth._providers[(prv.type, prv.id)] = prv
return prv | [
"def",
"legacy_auth",
"(",
"hass",
")",
":",
"prv",
"=",
"legacy_api_password",
".",
"LegacyApiPasswordAuthProvider",
"(",
"hass",
",",
"hass",
".",
"auth",
".",
"_store",
",",
"{",
"\"type\"",
":",
"\"legacy_api_password\"",
",",
"\"api_password\"",
":",
"\"tes... | [
244,
0
] | [
252,
14
] | python | en | ['fr', 'mg', 'en'] | False |
local_auth | (hass) | Load local auth provider. | Load local auth provider. | def local_auth(hass):
"""Load local auth provider."""
prv = homeassistant.HassAuthProvider(
hass, hass.auth._store, {"type": "homeassistant"}
)
hass.auth._providers[(prv.type, prv.id)] = prv
return prv | [
"def",
"local_auth",
"(",
"hass",
")",
":",
"prv",
"=",
"homeassistant",
".",
"HassAuthProvider",
"(",
"hass",
",",
"hass",
".",
"auth",
".",
"_store",
",",
"{",
"\"type\"",
":",
"\"homeassistant\"",
"}",
")",
"hass",
".",
"auth",
".",
"_providers",
"[",... | [
256,
0
] | [
262,
14
] | python | en | ['en', 'it', 'fr'] | False |
hass_client | (hass, aiohttp_client, hass_access_token) | Return an authenticated HTTP client. | Return an authenticated HTTP client. | def hass_client(hass, aiohttp_client, hass_access_token):
"""Return an authenticated HTTP client."""
async def auth_client():
"""Return an authenticated client."""
return await aiohttp_client(
hass.http.app, headers={"Authorization": f"Bearer {hass_access_token}"}
)
ret... | [
"def",
"hass_client",
"(",
"hass",
",",
"aiohttp_client",
",",
"hass_access_token",
")",
":",
"async",
"def",
"auth_client",
"(",
")",
":",
"\"\"\"Return an authenticated client.\"\"\"",
"return",
"await",
"aiohttp_client",
"(",
"hass",
".",
"http",
".",
"app",
",... | [
266,
0
] | [
275,
22
] | python | en | ['en', 'en', 'en'] | True |
current_request | (hass) | Mock current request. | Mock current request. | def current_request(hass):
"""Mock current request."""
with patch("homeassistant.helpers.network.current_request") as mock_request_context:
mocked_request = make_mocked_request(
"GET",
"/some/request",
headers={"Host": "example.com"},
sslcontext=ssl.SSLCon... | [
"def",
"current_request",
"(",
"hass",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.helpers.network.current_request\"",
")",
"as",
"mock_request_context",
":",
"mocked_request",
"=",
"make_mocked_request",
"(",
"\"GET\"",
",",
"\"/some/request\"",
",",
"headers",
"=... | [
279,
0
] | [
289,
34
] | python | en | ['en', 'en', 'en'] | True |
hass_ws_client | (aiohttp_client, hass_access_token, hass) | Websocket client fixture connected to websocket server. | Websocket client fixture connected to websocket server. | def hass_ws_client(aiohttp_client, hass_access_token, hass):
"""Websocket client fixture connected to websocket server."""
async def create_client(hass=hass, access_token=hass_access_token):
"""Create a websocket client."""
assert await async_setup_component(hass, "websocket_api", {})
... | [
"def",
"hass_ws_client",
"(",
"aiohttp_client",
",",
"hass_access_token",
",",
"hass",
")",
":",
"async",
"def",
"create_client",
"(",
"hass",
"=",
"hass",
",",
"access_token",
"=",
"hass_access_token",
")",
":",
"\"\"\"Create a websocket client.\"\"\"",
"assert",
"... | [
293,
0
] | [
323,
24
] | python | en | ['en', 'da', 'en'] | True |
fail_on_log_exception | (request, monkeypatch) | Fixture to fail if a callback wrapped by catch_log_exception or coroutine wrapped by async_create_catching_coro throws. | Fixture to fail if a callback wrapped by catch_log_exception or coroutine wrapped by async_create_catching_coro throws. | def fail_on_log_exception(request, monkeypatch):
"""Fixture to fail if a callback wrapped by catch_log_exception or coroutine wrapped by async_create_catching_coro throws."""
if "no_fail_on_log_exception" in request.keywords:
return
def log_exception(format_err, *args):
raise
monkeypat... | [
"def",
"fail_on_log_exception",
"(",
"request",
",",
"monkeypatch",
")",
":",
"if",
"\"no_fail_on_log_exception\"",
"in",
"request",
".",
"keywords",
":",
"return",
"def",
"log_exception",
"(",
"format_err",
",",
"*",
"args",
")",
":",
"raise",
"monkeypatch",
".... | [
327,
0
] | [
335,
82
] | python | en | ['en', 'en', 'en'] | True |
mqtt_config | () | Fixture to allow overriding MQTT config. | Fixture to allow overriding MQTT config. | def mqtt_config():
"""Fixture to allow overriding MQTT config."""
return None | [
"def",
"mqtt_config",
"(",
")",
":",
"return",
"None"
] | [
339,
0
] | [
341,
15
] | python | en | ['en', 'ca', 'en'] | True |
mqtt_client_mock | (hass) | Fixture to mock MQTT client. | Fixture to mock MQTT client. | def mqtt_client_mock(hass):
"""Fixture to mock MQTT client."""
mid = 0
def get_mid():
nonlocal mid
mid += 1
return mid
class FakeInfo:
def __init__(self, mid):
self.mid = mid
self.rc = 0
with patch("paho.mqtt.client.Client") as mock_client:... | [
"def",
"mqtt_client_mock",
"(",
"hass",
")",
":",
"mid",
"=",
"0",
"def",
"get_mid",
"(",
")",
":",
"nonlocal",
"mid",
"mid",
"+=",
"1",
"return",
"mid",
"class",
"FakeInfo",
":",
"def",
"__init__",
"(",
"self",
",",
"mid",
")",
":",
"self",
".",
"... | [
345,
0
] | [
384,
25
] | python | en | ['en', 'ca', 'en'] | True |
mqtt_mock | (hass, mqtt_client_mock, mqtt_config) | Fixture to mock MQTT component. | Fixture to mock MQTT component. | async def mqtt_mock(hass, mqtt_client_mock, mqtt_config):
"""Fixture to mock MQTT component."""
if mqtt_config is None:
mqtt_config = {mqtt.CONF_BROKER: "mock-broker"}
result = await async_setup_component(hass, mqtt.DOMAIN, {mqtt.DOMAIN: mqtt_config})
assert result
await hass.async_block_ti... | [
"async",
"def",
"mqtt_mock",
"(",
"hass",
",",
"mqtt_client_mock",
",",
"mqtt_config",
")",
":",
"if",
"mqtt_config",
"is",
"None",
":",
"mqtt_config",
"=",
"{",
"mqtt",
".",
"CONF_BROKER",
":",
"\"mock-broker\"",
"}",
"result",
"=",
"await",
"async_setup_comp... | [
388,
0
] | [
411,
20
] | python | en | ['en', 'ca', 'en'] | True |
mock_zeroconf | () | Mock zeroconf. | Mock zeroconf. | def mock_zeroconf():
"""Mock zeroconf."""
with patch("homeassistant.components.zeroconf.HaZeroconf") as mock_zc:
yield mock_zc.return_value | [
"def",
"mock_zeroconf",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.zeroconf.HaZeroconf\"",
")",
"as",
"mock_zc",
":",
"yield",
"mock_zc",
".",
"return_value"
] | [
415,
0
] | [
418,
34
] | python | en | ['eu', 'sr', 'en'] | False |
legacy_patchable_time | () | Allow time to be patchable by using event listeners instead of asyncio loop. | Allow time to be patchable by using event listeners instead of asyncio loop. | def legacy_patchable_time():
"""Allow time to be patchable by using event listeners instead of asyncio loop."""
@ha.callback
@loader.bind_hass
def async_track_point_in_utc_time(hass, action, point_in_time):
"""Add a listener that fires once after a specific point in UTC time."""
# Ensur... | [
"def",
"legacy_patchable_time",
"(",
")",
":",
"@",
"ha",
".",
"callback",
"@",
"loader",
".",
"bind_hass",
"def",
"async_track_point_in_utc_time",
"(",
"hass",
",",
"action",
",",
"point_in_time",
")",
":",
"\"\"\"Add a listener that fires once after a specific point i... | [
422,
0
] | [
527,
13
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Add a GIOS entities from a config_entry. | Add a GIOS entities from a config_entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add a GIOS entities from a config_entry."""
name = config_entry.data[CONF_NAME]
coordinator = hass.data[DOMAIN][config_entry.entry_id]
async_add_entities([GiosAirQuality(coordinator, name)], False) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"name",
"=",
"config_entry",
".",
"data",
"[",
"CONF_NAME",
"]",
"coordinator",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
"."... | [
29,
0
] | [
35,
66
] | python | en | ['en', 'en', 'en'] | True |
round_state | (func) | Round state. | Round state. | def round_state(func):
"""Round state."""
def _decorator(self):
res = func(self)
if isinstance(res, float):
return round(res)
return res
return _decorator | [
"def",
"round_state",
"(",
"func",
")",
":",
"def",
"_decorator",
"(",
"self",
")",
":",
"res",
"=",
"func",
"(",
"self",
")",
"if",
"isinstance",
"(",
"res",
",",
"float",
")",
":",
"return",
"round",
"(",
"res",
")",
"return",
"res",
"return",
"_... | [
38,
0
] | [
47,
21
] | python | en | ['en', 'sn', 'en'] | False |
GiosAirQuality.__init__ | (self, coordinator, name) | Initialize. | Initialize. | def __init__(self, coordinator, name):
"""Initialize."""
super().__init__(coordinator)
self._name = name
self._attrs = {} | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
",",
"name",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_attrs",
"=",
"{",
"}"
] | [
53,
4
] | [
57,
24
] | python | en | ['en', 'en', 'it'] | False |
GiosAirQuality.name | (self) | Return the name. | Return the name. | def name(self):
"""Return the name."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
60,
4
] | [
62,
25
] | python | en | ['en', 'ig', 'en'] | True |
GiosAirQuality.icon | (self) | Return the icon. | Return the icon. | def icon(self):
"""Return the icon."""
if self.air_quality_index in ICONS_MAP:
return ICONS_MAP[self.air_quality_index]
return "mdi:blur" | [
"def",
"icon",
"(",
"self",
")",
":",
"if",
"self",
".",
"air_quality_index",
"in",
"ICONS_MAP",
":",
"return",
"ICONS_MAP",
"[",
"self",
".",
"air_quality_index",
"]",
"return",
"\"mdi:blur\""
] | [
65,
4
] | [
69,
25
] | python | en | ['en', 'sr', 'en'] | True |
GiosAirQuality.air_quality_index | (self) | Return the air quality index. | Return the air quality index. | def air_quality_index(self):
"""Return the air quality index."""
return self._get_sensor_value("AQI") | [
"def",
"air_quality_index",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"AQI\"",
")"
] | [
72,
4
] | [
74,
44
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality.particulate_matter_2_5 | (self) | Return the particulate matter 2.5 level. | Return the particulate matter 2.5 level. | def particulate_matter_2_5(self):
"""Return the particulate matter 2.5 level."""
return self._get_sensor_value("PM2.5") | [
"def",
"particulate_matter_2_5",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"PM2.5\"",
")"
] | [
78,
4
] | [
80,
46
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality.particulate_matter_10 | (self) | Return the particulate matter 10 level. | Return the particulate matter 10 level. | def particulate_matter_10(self):
"""Return the particulate matter 10 level."""
return self._get_sensor_value("PM10") | [
"def",
"particulate_matter_10",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"PM10\"",
")"
] | [
84,
4
] | [
86,
45
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality.ozone | (self) | Return the O3 (ozone) level. | Return the O3 (ozone) level. | def ozone(self):
"""Return the O3 (ozone) level."""
return self._get_sensor_value("O3") | [
"def",
"ozone",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"O3\"",
")"
] | [
90,
4
] | [
92,
43
] | python | en | ['en', 'ig', 'en'] | True |
GiosAirQuality.carbon_monoxide | (self) | Return the CO (carbon monoxide) level. | Return the CO (carbon monoxide) level. | def carbon_monoxide(self):
"""Return the CO (carbon monoxide) level."""
return self._get_sensor_value("CO") | [
"def",
"carbon_monoxide",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"CO\"",
")"
] | [
96,
4
] | [
98,
43
] | python | en | ['en', 'fr', 'en'] | True |
GiosAirQuality.sulphur_dioxide | (self) | Return the SO2 (sulphur dioxide) level. | Return the SO2 (sulphur dioxide) level. | def sulphur_dioxide(self):
"""Return the SO2 (sulphur dioxide) level."""
return self._get_sensor_value("SO2") | [
"def",
"sulphur_dioxide",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"SO2\"",
")"
] | [
102,
4
] | [
104,
44
] | python | en | ['en', 'no', 'en'] | True |
GiosAirQuality.nitrogen_dioxide | (self) | Return the NO2 (nitrogen dioxide) level. | Return the NO2 (nitrogen dioxide) level. | def nitrogen_dioxide(self):
"""Return the NO2 (nitrogen dioxide) level."""
return self._get_sensor_value("NO2") | [
"def",
"nitrogen_dioxide",
"(",
"self",
")",
":",
"return",
"self",
".",
"_get_sensor_value",
"(",
"\"NO2\"",
")"
] | [
108,
4
] | [
110,
44
] | python | en | ['en', 'da', 'en'] | True |
GiosAirQuality.attribution | (self) | Return the attribution. | Return the attribution. | def attribution(self):
"""Return the attribution."""
return ATTRIBUTION | [
"def",
"attribution",
"(",
"self",
")",
":",
"return",
"ATTRIBUTION"
] | [
113,
4
] | [
115,
26
] | python | en | ['en', 'ja', 'en'] | True |
GiosAirQuality.unique_id | (self) | Return a unique_id for this entity. | Return a unique_id for this entity. | def unique_id(self):
"""Return a unique_id for this entity."""
return self.coordinator.gios.station_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"gios",
".",
"station_id"
] | [
118,
4
] | [
120,
47
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality.device_info | (self) | Return the device info. | Return the device info. | def device_info(self):
"""Return the device info."""
return {
"identifiers": {(DOMAIN, self.coordinator.gios.station_id)},
"name": DEFAULT_NAME,
"manufacturer": MANUFACTURER,
"entry_type": "service",
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"coordinator",
".",
"gios",
".",
"station_id",
")",
"}",
",",
"\"name\"",
":",
"DEFAULT_NAME",
",",
"\"manufacturer\"",
":",
"MANUFACT... | [
123,
4
] | [
130,
9
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
# Different measuring stations have different sets of sensors. We don't know
# what data we will get.
for sensor in SENSOR_MAP:
if sensor in self.coordinator.data:
self._attrs[f"{SENSOR_MAP[... | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"# Different measuring stations have different sets of sensors. We don't know",
"# what data we will get.",
"for",
"sensor",
"in",
"SENSOR_MAP",
":",
"if",
"sensor",
"in",
"self",
".",
"coordinator",
".",
"data",
":",... | [
133,
4
] | [
143,
26
] | python | en | ['en', 'en', 'en'] | True |
GiosAirQuality._get_sensor_value | (self, sensor) | Return value of specified sensor. | Return value of specified sensor. | def _get_sensor_value(self, sensor):
"""Return value of specified sensor."""
if sensor in self.coordinator.data:
return self.coordinator.data[sensor]["value"]
return None | [
"def",
"_get_sensor_value",
"(",
"self",
",",
"sensor",
")",
":",
"if",
"sensor",
"in",
"self",
".",
"coordinator",
".",
"data",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"sensor",
"]",
"[",
"\"value\"",
"]",
"return",
"None"
] | [
145,
4
] | [
149,
19
] | python | en | ['en', 'da', 'en'] | True |
alter_time | (retval) | Manage multiple time mocks. | Manage multiple time mocks. | def alter_time(retval):
"""Manage multiple time mocks."""
patch1 = patch("homeassistant.util.dt.utcnow", return_value=retval)
patch2 = patch("homeassistant.util.dt.now", return_value=retval)
with patch1, patch2:
yield | [
"def",
"alter_time",
"(",
"retval",
")",
":",
"patch1",
"=",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"retval",
")",
"patch2",
"=",
"patch",
"(",
"\"homeassistant.util.dt.now\"",
",",
"return_value",
"=",
"retval",
")",
"with",
... | [
26,
0
] | [
32,
13
] | python | da | ['pl', 'da', 'en'] | False |
test_state | (hass) | Test utility sensor state. | Test utility sensor state. | async def test_state(hass):
"""Test utility sensor state."""
config = {
"utility_meter": {
"energy_bill": {
"source": "sensor.energy",
"tariffs": ["onpeak", "midpeak", "offpeak"],
}
}
}
assert await async_setup_component(hass, DOMA... | [
"async",
"def",
"test_state",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"utility_meter\"",
":",
"{",
"\"energy_bill\"",
":",
"{",
"\"source\"",
":",
"\"sensor.energy\"",
",",
"\"tariffs\"",
":",
"[",
"\"onpeak\"",
",",
"\"midpeak\"",
",",
"\"offpeak\"",
"]"... | [
35,
0
] | [
130,
33
] | python | en | ['en', 'el-Latn', 'en'] | True |
test_net_consumption | (hass) | Test utility sensor state. | Test utility sensor state. | async def test_net_consumption(hass):
"""Test utility sensor state."""
config = {
"utility_meter": {
"energy_bill": {"source": "sensor.energy", "net_consumption": True}
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert await async_setup_component(hass, ... | [
"async",
"def",
"test_net_consumption",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"utility_meter\"",
":",
"{",
"\"energy_bill\"",
":",
"{",
"\"source\"",
":",
"\"sensor.energy\"",
",",
"\"net_consumption\"",
":",
"True",
"}",
"}",
"}",
"assert",
"await",
"a... | [
133,
0
] | [
165,
30
] | python | en | ['en', 'el-Latn', 'en'] | True |
test_non_net_consumption | (hass) | Test utility sensor state. | Test utility sensor state. | async def test_non_net_consumption(hass):
"""Test utility sensor state."""
config = {
"utility_meter": {
"energy_bill": {"source": "sensor.energy", "net_consumption": False}
}
}
assert await async_setup_component(hass, DOMAIN, config)
assert await async_setup_component(h... | [
"async",
"def",
"test_non_net_consumption",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"utility_meter\"",
":",
"{",
"\"energy_bill\"",
":",
"{",
"\"source\"",
":",
"\"sensor.energy\"",
",",
"\"net_consumption\"",
":",
"False",
"}",
"}",
"}",
"assert",
"await",... | [
168,
0
] | [
200,
29
] | python | en | ['en', 'el-Latn', 'en'] | True |
gen_config | (cycle, offset=None) | Generate configuration. | Generate configuration. | def gen_config(cycle, offset=None):
"""Generate configuration."""
config = {
"utility_meter": {"energy_bill": {"source": "sensor.energy", "cycle": cycle}}
}
if offset:
config["utility_meter"]["energy_bill"]["offset"] = {
"days": offset.days,
"seconds": offset.sec... | [
"def",
"gen_config",
"(",
"cycle",
",",
"offset",
"=",
"None",
")",
":",
"config",
"=",
"{",
"\"utility_meter\"",
":",
"{",
"\"energy_bill\"",
":",
"{",
"\"source\"",
":",
"\"sensor.energy\"",
",",
"\"cycle\"",
":",
"cycle",
"}",
"}",
"}",
"if",
"offset",
... | [
203,
0
] | [
214,
17
] | python | en | ['en', 'la', 'en'] | False |
_test_self_reset | (hass, config, start_time, expect_reset=True) | Test energy sensor self reset. | Test energy sensor self reset. | async def _test_self_reset(hass, config, start_time, expect_reset=True):
"""Test energy sensor self reset."""
assert await async_setup_component(hass, DOMAIN, config)
assert await async_setup_component(hass, SENSOR_DOMAIN, config)
await hass.async_block_till_done()
hass.bus.async_fire(EVENT_HOMEASS... | [
"async",
"def",
"_test_self_reset",
"(",
"hass",
",",
"config",
",",
"start_time",
",",
"expect_reset",
"=",
"True",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"config",
")",
"assert",
"await",
"async_setup_component",... | [
217,
0
] | [
263,
33
] | python | be | ['hu', 'be', 'en'] | False |
test_self_reset_quarter_hourly | (hass, legacy_patchable_time) | Test quarter-hourly reset of meter. | Test quarter-hourly reset of meter. | async def test_self_reset_quarter_hourly(hass, legacy_patchable_time):
"""Test quarter-hourly reset of meter."""
await _test_self_reset(
hass, gen_config("quarter-hourly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_quarter_hourly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"quarter-hourly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
266,
0
] | [
270,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_quarter_hourly_first_quarter | (hass, legacy_patchable_time) | Test quarter-hourly reset of meter. | Test quarter-hourly reset of meter. | async def test_self_reset_quarter_hourly_first_quarter(hass, legacy_patchable_time):
"""Test quarter-hourly reset of meter."""
await _test_self_reset(
hass, gen_config("quarter-hourly"), "2017-12-31T23:14:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_quarter_hourly_first_quarter",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"quarter-hourly\"",
")",
",",
"\"2017-12-31T23:14:00.000000+00:00\"",
")"
] | [
273,
0
] | [
277,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_quarter_hourly_second_quarter | (hass, legacy_patchable_time) | Test quarter-hourly reset of meter. | Test quarter-hourly reset of meter. | async def test_self_reset_quarter_hourly_second_quarter(hass, legacy_patchable_time):
"""Test quarter-hourly reset of meter."""
await _test_self_reset(
hass, gen_config("quarter-hourly"), "2017-12-31T23:29:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_quarter_hourly_second_quarter",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"quarter-hourly\"",
")",
",",
"\"2017-12-31T23:29:00.000000+00:00\"",
")"
] | [
280,
0
] | [
284,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_quarter_hourly_third_quarter | (hass, legacy_patchable_time) | Test quarter-hourly reset of meter. | Test quarter-hourly reset of meter. | async def test_self_reset_quarter_hourly_third_quarter(hass, legacy_patchable_time):
"""Test quarter-hourly reset of meter."""
await _test_self_reset(
hass, gen_config("quarter-hourly"), "2017-12-31T23:44:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_quarter_hourly_third_quarter",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"quarter-hourly\"",
")",
",",
"\"2017-12-31T23:44:00.000000+00:00\"",
")"
] | [
287,
0
] | [
291,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_hourly | (hass, legacy_patchable_time) | Test hourly reset of meter. | Test hourly reset of meter. | async def test_self_reset_hourly(hass, legacy_patchable_time):
"""Test hourly reset of meter."""
await _test_self_reset(
hass, gen_config("hourly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_hourly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"hourly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
294,
0
] | [
298,
5
] | python | en | ['en', 'nl', 'en'] | True |
test_self_reset_daily | (hass, legacy_patchable_time) | Test daily reset of meter. | Test daily reset of meter. | async def test_self_reset_daily(hass, legacy_patchable_time):
"""Test daily reset of meter."""
await _test_self_reset(
hass, gen_config("daily"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_daily",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"daily\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
301,
0
] | [
305,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_weekly | (hass, legacy_patchable_time) | Test weekly reset of meter. | Test weekly reset of meter. | async def test_self_reset_weekly(hass, legacy_patchable_time):
"""Test weekly reset of meter."""
await _test_self_reset(
hass, gen_config("weekly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_weekly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"weekly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
308,
0
] | [
312,
5
] | python | en | ['en', 'af', 'en'] | True |
test_self_reset_monthly | (hass, legacy_patchable_time) | Test monthly reset of meter. | Test monthly reset of meter. | async def test_self_reset_monthly(hass, legacy_patchable_time):
"""Test monthly reset of meter."""
await _test_self_reset(
hass, gen_config("monthly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_monthly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"monthly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
315,
0
] | [
319,
5
] | python | en | ['en', 'nl', 'en'] | True |
test_self_reset_bimonthly | (hass, legacy_patchable_time) | Test bimonthly reset of meter occurs on even months. | Test bimonthly reset of meter occurs on even months. | async def test_self_reset_bimonthly(hass, legacy_patchable_time):
"""Test bimonthly reset of meter occurs on even months."""
await _test_self_reset(
hass, gen_config("bimonthly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_bimonthly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"bimonthly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
322,
0
] | [
326,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_no_reset_bimonthly | (hass, legacy_patchable_time) | Test bimonthly reset of meter does not occur on odd months. | Test bimonthly reset of meter does not occur on odd months. | async def test_self_no_reset_bimonthly(hass, legacy_patchable_time):
"""Test bimonthly reset of meter does not occur on odd months."""
await _test_self_reset(
hass,
gen_config("bimonthly"),
"2018-01-01T23:59:00.000000+00:00",
expect_reset=False,
) | [
"async",
"def",
"test_self_no_reset_bimonthly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"bimonthly\"",
")",
",",
"\"2018-01-01T23:59:00.000000+00:00\"",
",",
"expect_reset",
"=",
"False",
... | [
329,
0
] | [
336,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_reset_quarterly | (hass, legacy_patchable_time) | Test quarterly reset of meter. | Test quarterly reset of meter. | async def test_self_reset_quarterly(hass, legacy_patchable_time):
"""Test quarterly reset of meter."""
await _test_self_reset(
hass, gen_config("quarterly"), "2017-03-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_quarterly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"quarterly\"",
")",
",",
"\"2017-03-31T23:59:00.000000+00:00\"",
")"
] | [
339,
0
] | [
343,
5
] | python | en | ['en', 'la', 'en'] | True |
test_self_reset_yearly | (hass, legacy_patchable_time) | Test yearly reset of meter. | Test yearly reset of meter. | async def test_self_reset_yearly(hass, legacy_patchable_time):
"""Test yearly reset of meter."""
await _test_self_reset(
hass, gen_config("yearly"), "2017-12-31T23:59:00.000000+00:00"
) | [
"async",
"def",
"test_self_reset_yearly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"yearly\"",
")",
",",
"\"2017-12-31T23:59:00.000000+00:00\"",
")"
] | [
346,
0
] | [
350,
5
] | python | en | ['en', 'en', 'en'] | True |
test_self_no_reset_yearly | (hass, legacy_patchable_time) | Test yearly reset of meter does not occur after 1st January. | Test yearly reset of meter does not occur after 1st January. | async def test_self_no_reset_yearly(hass, legacy_patchable_time):
"""Test yearly reset of meter does not occur after 1st January."""
await _test_self_reset(
hass,
gen_config("yearly"),
"2018-01-01T23:59:00.000000+00:00",
expect_reset=False,
) | [
"async",
"def",
"test_self_no_reset_yearly",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"yearly\"",
")",
",",
"\"2018-01-01T23:59:00.000000+00:00\"",
",",
"expect_reset",
"=",
"False",
",",
... | [
353,
0
] | [
360,
5
] | python | en | ['en', 'en', 'en'] | True |
test_reset_yearly_offset | (hass, legacy_patchable_time) | Test yearly reset of meter. | Test yearly reset of meter. | async def test_reset_yearly_offset(hass, legacy_patchable_time):
"""Test yearly reset of meter."""
await _test_self_reset(
hass,
gen_config("yearly", timedelta(days=1, minutes=10)),
"2018-01-02T00:09:00.000000+00:00",
) | [
"async",
"def",
"test_reset_yearly_offset",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"yearly\"",
",",
"timedelta",
"(",
"days",
"=",
"1",
",",
"minutes",
"=",
"10",
")",
")",
","... | [
363,
0
] | [
369,
5
] | python | en | ['en', 'en', 'en'] | True |
test_no_reset_yearly_offset | (hass, legacy_patchable_time) | Test yearly reset of meter. | Test yearly reset of meter. | async def test_no_reset_yearly_offset(hass, legacy_patchable_time):
"""Test yearly reset of meter."""
await _test_self_reset(
hass,
gen_config("yearly", timedelta(31)),
"2018-01-30T23:59:00.000000+00:00",
expect_reset=False,
) | [
"async",
"def",
"test_no_reset_yearly_offset",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"await",
"_test_self_reset",
"(",
"hass",
",",
"gen_config",
"(",
"\"yearly\"",
",",
"timedelta",
"(",
"31",
")",
")",
",",
"\"2018-01-30T23:59:00.000000+00:00\"",
",... | [
372,
0
] | [
379,
5
] | 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."""
try:
devices = await hass.async_add_executor_job(pyzerproc.discover)
return len(devices) > 0
except pyzerproc.ZerprocException:
_LOGGER.error("Unable to discover nearby Zerproc devic... | [
"async",
"def",
"_async_has_devices",
"(",
"hass",
")",
"->",
"bool",
":",
"try",
":",
"devices",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"pyzerproc",
".",
"discover",
")",
"return",
"len",
"(",
"devices",
")",
">",
"0",
"except",
"pyzerp... | [
13,
0
] | [
20,
20
] | python | en | ['en', 'en', 'en'] | True |
DropPath.__init__ | (self, p=0.) |
Drop path with probability.
Parameters
----------
p : float
Probability of an path to be zeroed.
|
Drop path with probability. | def __init__(self, p=0.):
"""
Drop path with probability.
Parameters
----------
p : float
Probability of an path to be zeroed.
"""
super().__init__()
self.p = p | [
"def",
"__init__",
"(",
"self",
",",
"p",
"=",
"0.",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"p",
"=",
"p"
] | [
30,
4
] | [
40,
18
] | python | en | ['en', 'error', 'th'] | False |
fill_in_schema_dict | (some_input) | Fill in schema dict defaults from user_input. | Fill in schema dict defaults from user_input. | def fill_in_schema_dict(some_input):
"""Fill in schema dict defaults from user_input."""
schema_dict = {}
for field, _type in DATA_SCHEMA_DICT.items():
if some_input.get(str(field)):
schema_dict[
vol.Optional(str(field), default=some_input[str(field)])
] = _ty... | [
"def",
"fill_in_schema_dict",
"(",
"some_input",
")",
":",
"schema_dict",
"=",
"{",
"}",
"for",
"field",
",",
"_type",
"in",
"DATA_SCHEMA_DICT",
".",
"items",
"(",
")",
":",
"if",
"some_input",
".",
"get",
"(",
"str",
"(",
"field",
")",
")",
":",
"sche... | [
85,
0
] | [
95,
22
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdOptionsFlowHandler.__init__ | (self, config_entry) | Initialize. | Initialize. | def __init__(self, config_entry):
"""Initialize."""
self.config_entry = config_entry | [
"def",
"__init__",
"(",
"self",
",",
"config_entry",
")",
":",
"self",
".",
"config_entry",
"=",
"config_entry"
] | [
45,
4
] | [
47,
40
] | python | en | ['en', 'en', 'it'] | False |
ForkedDaapdOptionsFlowHandler.async_step_init | (self, user_input=None) | Manage the options. | Manage the options. | async def async_step_init(self, user_input=None):
"""Manage the options."""
if user_input is not None:
return self.async_create_entry(title="options", data=user_input)
return self.async_show_form(
step_id="init",
data_schema=vol.Schema(
{
... | [
"async",
"def",
"async_step_init",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"\"options\"",
",",
"data",
"=",
"user_input",
")",
"ret... | [
49,
4
] | [
82,
9
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdFlowHandler.__init__ | (self) | Initialize. | Initialize. | def __init__(self):
"""Initialize."""
self.discovery_schema = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"discovery_schema",
"=",
"None"
] | [
104,
4
] | [
106,
36
] | python | en | ['en', 'en', 'it'] | False |
ForkedDaapdFlowHandler.async_get_options_flow | (config_entry) | Return options flow handler. | Return options flow handler. | def async_get_options_flow(config_entry):
"""Return options flow handler."""
return ForkedDaapdOptionsFlowHandler(config_entry) | [
"def",
"async_get_options_flow",
"(",
"config_entry",
")",
":",
"return",
"ForkedDaapdOptionsFlowHandler",
"(",
"config_entry",
")"
] | [
110,
4
] | [
112,
58
] | python | en | ['en', 'nl', 'en'] | True |
ForkedDaapdFlowHandler.validate_input | (self, user_input) | Validate the user input. | Validate the user input. | async def validate_input(self, user_input):
"""Validate the user input."""
websession = async_get_clientsession(self.hass)
validate_result = await ForkedDaapdAPI.test_connection(
websession=websession,
host=user_input[CONF_HOST],
port=user_input[CONF_PORT],
... | [
"async",
"def",
"validate_input",
"(",
"self",
",",
"user_input",
")",
":",
"websession",
"=",
"async_get_clientsession",
"(",
"self",
".",
"hass",
")",
"validate_result",
"=",
"await",
"ForkedDaapdAPI",
".",
"test_connection",
"(",
"websession",
"=",
"websession"... | [
114,
4
] | [
126,
30
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdFlowHandler.async_step_user | (self, user_input=None) | Handle a forked-daapd config flow start.
Manage device specific parameters.
| Handle a forked-daapd config flow start. | async def async_step_user(self, user_input=None):
"""Handle a forked-daapd config flow start.
Manage device specific parameters.
"""
if user_input is not None:
# check for any entries with same host, abort if found
for entry in self._async_current_entries():
... | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"# check for any entries with same host, abort if found",
"for",
"entry",
"in",
"self",
".",
"_async_current_entries",
"(",
")",
... | [
128,
4
] | [
155,
9
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdFlowHandler.async_step_zeroconf | (self, discovery_info) | Prepare configuration for a discovered forked-daapd device. | Prepare configuration for a discovered forked-daapd device. | async def async_step_zeroconf(self, discovery_info):
"""Prepare configuration for a discovered forked-daapd device."""
version_num = 0
if discovery_info.get("properties") and discovery_info["properties"].get(
"Machine Name"
):
try:
version_num = in... | [
"async",
"def",
"async_step_zeroconf",
"(",
"self",
",",
"discovery_info",
")",
":",
"version_num",
"=",
"0",
"if",
"discovery_info",
".",
"get",
"(",
"\"properties\"",
")",
"and",
"discovery_info",
"[",
"\"properties\"",
"]",
".",
"get",
"(",
"\"Machine Name\""... | [
157,
4
] | [
192,
43
] | python | en | ['en', 'en', 'en'] | True |
async_setup_ha_cast | (
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
) | Set up Home Assistant Cast. | Set up Home Assistant Cast. | async def async_setup_ha_cast(
hass: core.HomeAssistant, entry: config_entries.ConfigEntry
):
"""Set up Home Assistant Cast."""
user_id: Optional[str] = entry.data.get("user_id")
user: Optional[auth.models.User] = None
if user_id is not None:
user = await hass.auth.async_get_user(user_id)
... | [
"async",
"def",
"async_setup_ha_cast",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"entry",
":",
"config_entries",
".",
"ConfigEntry",
")",
":",
"user_id",
":",
"Optional",
"[",
"str",
"]",
"=",
"entry",
".",
"data",
".",
"get",
"(",
"\"user_id\""... | [
18,
0
] | [
73,
5
] | python | en | ['en', 'fr', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the HomeMatic binary sensor platform. | Set up the HomeMatic binary sensor platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the HomeMatic binary sensor platform."""
if discovery_info is None:
return
devices = []
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
if discovery_info[ATTR_DISCOVERY_TYPE] == DISCOVER_BATTERY:
... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"devices",
"=",
"[",
"]",
"for",
"conf",
"in",
"discovery_info",
"[",
"ATTR_DISCOVER_... | [
33,
0
] | [
45,
31
] | python | en | ['en', 'pt', 'en'] | True |
HMBinarySensor.is_on | (self) | Return true if switch is on. | Return true if switch is on. | def is_on(self):
"""Return true if switch is on."""
if not self.available:
return False
return bool(self._hm_get_state()) | [
"def",
"is_on",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"available",
":",
"return",
"False",
"return",
"bool",
"(",
"self",
".",
"_hm_get_state",
"(",
")",
")"
] | [
52,
4
] | [
56,
41
] | python | en | ['en', 'fy', 'en'] | True |
HMBinarySensor.device_class | (self) | Return the class of this sensor from DEVICE_CLASSES. | Return the class of this sensor from DEVICE_CLASSES. | def device_class(self):
"""Return the class of this sensor from DEVICE_CLASSES."""
# If state is MOTION (Only RemoteMotion working)
if self._state == "MOTION":
return DEVICE_CLASS_MOTION
return SENSOR_TYPES_CLASS.get(self._hmdevice.__class__.__name__) | [
"def",
"device_class",
"(",
"self",
")",
":",
"# If state is MOTION (Only RemoteMotion working)",
"if",
"self",
".",
"_state",
"==",
"\"MOTION\"",
":",
"return",
"DEVICE_CLASS_MOTION",
"return",
"SENSOR_TYPES_CLASS",
".",
"get",
"(",
"self",
".",
"_hmdevice",
".",
"... | [
59,
4
] | [
64,
72
] | python | en | ['en', 'en', 'en'] | True |
HMBinarySensor._init_data_struct | (self) | Generate the data dictionary (self._data) from metadata. | Generate the data dictionary (self._data) from metadata. | def _init_data_struct(self):
"""Generate the data dictionary (self._data) from metadata."""
# Add state to data struct
if self._state:
self._data.update({self._state: None}) | [
"def",
"_init_data_struct",
"(",
"self",
")",
":",
"# Add state to data struct",
"if",
"self",
".",
"_state",
":",
"self",
".",
"_data",
".",
"update",
"(",
"{",
"self",
".",
"_state",
":",
"None",
"}",
")"
] | [
66,
4
] | [
70,
50
] | python | en | ['en', 'en', 'en'] | True |
HMBatterySensor.device_class | (self) | Return battery as a device class. | Return battery as a device class. | def device_class(self):
"""Return battery as a device class."""
return DEVICE_CLASS_BATTERY | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_BATTERY"
] | [
77,
4
] | [
79,
35
] | python | en | ['en', 'en', 'en'] | True |
HMBatterySensor.is_on | (self) | Return True if battery is low. | Return True if battery is low. | def is_on(self):
"""Return True if battery is low."""
return bool(self._hm_get_state()) | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"bool",
"(",
"self",
".",
"_hm_get_state",
"(",
")",
")"
] | [
82,
4
] | [
84,
41
] | python | en | ['en', 'fy', 'en'] | True |
HMBatterySensor._init_data_struct | (self) | Generate the data dictionary (self._data) from metadata. | Generate the data dictionary (self._data) from metadata. | def _init_data_struct(self):
"""Generate the data dictionary (self._data) from metadata."""
# Add state to data struct
if self._state:
self._data.update({self._state: None}) | [
"def",
"_init_data_struct",
"(",
"self",
")",
":",
"# Add state to data struct",
"if",
"self",
".",
"_state",
":",
"self",
".",
"_data",
".",
"update",
"(",
"{",
"self",
".",
"_state",
":",
"None",
"}",
")"
] | [
86,
4
] | [
90,
50
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the Arduino component. | Set up the Arduino component. | def setup(hass, config):
"""Set up the Arduino component."""
_LOGGER.warning(
"The %s integration has been deprecated. Please move your "
"configuration to the firmata integration. "
"https://www.home-assistant.io/integrations/firmata",
DOMAIN,
)
port = config[DOMAIN][CO... | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"The %s integration has been deprecated. Please move your \"",
"\"configuration to the firmata integration. \"",
"\"https://www.home-assistant.io/integrations/firmata\"",
",",
"DOMAIN",
",",
"... | [
23,
0
] | [
61,
15
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.__init__ | (self, port) | Initialize the board. | Initialize the board. | def __init__(self, port):
"""Initialize the board."""
self._port = port
self._board = PyMata(self._port, verbose=False) | [
"def",
"__init__",
"(",
"self",
",",
"port",
")",
":",
"self",
".",
"_port",
"=",
"port",
"self",
".",
"_board",
"=",
"PyMata",
"(",
"self",
".",
"_port",
",",
"verbose",
"=",
"False",
")"
] | [
67,
4
] | [
71,
55
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.set_mode | (self, pin, direction, mode) | Set the mode and the direction of a given pin. | Set the mode and the direction of a given pin. | def set_mode(self, pin, direction, mode):
"""Set the mode and the direction of a given pin."""
if mode == "analog" and direction == "in":
self._board.set_pin_mode(pin, self._board.INPUT, self._board.ANALOG)
elif mode == "analog" and direction == "out":
self._board.set_pin... | [
"def",
"set_mode",
"(",
"self",
",",
"pin",
",",
"direction",
",",
"mode",
")",
":",
"if",
"mode",
"==",
"\"analog\"",
"and",
"direction",
"==",
"\"in\"",
":",
"self",
".",
"_board",
".",
"set_pin_mode",
"(",
"pin",
",",
"self",
".",
"_board",
".",
"... | [
73,
4
] | [
84,
78
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.get_analog_inputs | (self) | Get the values from the pins. | Get the values from the pins. | def get_analog_inputs(self):
"""Get the values from the pins."""
self._board.capability_query()
return self._board.get_analog_response_table() | [
"def",
"get_analog_inputs",
"(",
"self",
")",
":",
"self",
".",
"_board",
".",
"capability_query",
"(",
")",
"return",
"self",
".",
"_board",
".",
"get_analog_response_table",
"(",
")"
] | [
86,
4
] | [
89,
54
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.set_digital_out_high | (self, pin) | Set a given digital pin to high. | Set a given digital pin to high. | def set_digital_out_high(self, pin):
"""Set a given digital pin to high."""
self._board.digital_write(pin, 1) | [
"def",
"set_digital_out_high",
"(",
"self",
",",
"pin",
")",
":",
"self",
".",
"_board",
".",
"digital_write",
"(",
"pin",
",",
"1",
")"
] | [
91,
4
] | [
93,
41
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.set_digital_out_low | (self, pin) | Set a given digital pin to low. | Set a given digital pin to low. | def set_digital_out_low(self, pin):
"""Set a given digital pin to low."""
self._board.digital_write(pin, 0) | [
"def",
"set_digital_out_low",
"(",
"self",
",",
"pin",
")",
":",
"self",
".",
"_board",
".",
"digital_write",
"(",
"pin",
",",
"0",
")"
] | [
95,
4
] | [
97,
41
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.get_digital_in | (self, pin) | Get the value from a given digital pin. | Get the value from a given digital pin. | def get_digital_in(self, pin):
"""Get the value from a given digital pin."""
self._board.digital_read(pin) | [
"def",
"get_digital_in",
"(",
"self",
",",
"pin",
")",
":",
"self",
".",
"_board",
".",
"digital_read",
"(",
"pin",
")"
] | [
99,
4
] | [
101,
37
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.get_analog_in | (self, pin) | Get the value from a given analog pin. | Get the value from a given analog pin. | def get_analog_in(self, pin):
"""Get the value from a given analog pin."""
self._board.analog_read(pin) | [
"def",
"get_analog_in",
"(",
"self",
",",
"pin",
")",
":",
"self",
".",
"_board",
".",
"analog_read",
"(",
"pin",
")"
] | [
103,
4
] | [
105,
36
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.get_firmata | (self) | Return the version of the Firmata firmware. | Return the version of the Firmata firmware. | def get_firmata(self):
"""Return the version of the Firmata firmware."""
return self._board.get_firmata_version() | [
"def",
"get_firmata",
"(",
"self",
")",
":",
"return",
"self",
".",
"_board",
".",
"get_firmata_version",
"(",
")"
] | [
107,
4
] | [
109,
48
] | python | en | ['en', 'en', 'en'] | True |
ArduinoBoard.disconnect | (self) | Disconnect the board and close the serial connection. | Disconnect the board and close the serial connection. | def disconnect(self):
"""Disconnect the board and close the serial connection."""
self._board.reset()
self._board.close() | [
"def",
"disconnect",
"(",
"self",
")",
":",
"self",
".",
"_board",
".",
"reset",
"(",
")",
"self",
".",
"_board",
".",
"close",
"(",
")"
] | [
111,
4
] | [
114,
27
] | python | en | ['en', 'en', 'en'] | True |
test_create_sensors | (hass) | Test creation of sensors. | Test creation of sensors. | async def test_create_sensors(hass):
"""Test creation of sensors."""
await async_init_integration(hass)
state = hass.states.get("sensor.nick_office_temperature")
assert state.state == "23"
expected_attributes = {
"attribution": "Data provided by mynexia.com",
"device_class": "temp... | [
"async",
"def",
"test_create_sensors",
"(",
"hass",
")",
":",
"await",
"async_init_integration",
"(",
"hass",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.nick_office_temperature\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"23\"",
... | [
7,
0
] | [
134,
5
] | python | en | ['en', 'bg', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.