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
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
log_exception | (format_err: Callable[..., Any], *args: Any) | Log an exception with additional context. | Log an exception with additional context. | def log_exception(format_err: Callable[..., Any], *args: Any) -> None:
"""Log an exception with additional context."""
module = inspect.getmodule(inspect.stack()[1][0])
if module is not None:
module_name = module.__name__
else:
# If Python is unable to access the sources files, the call stack frame
# will be missing information, so let's guard.
# https://github.com/home-assistant/core/issues/24982
module_name = __name__
# Do not print the wrapper in the traceback
frames = len(inspect.trace()) - 1
exc_msg = traceback.format_exc(-frames)
friendly_msg = format_err(*args)
logging.getLogger(module_name).error("%s\n%s", friendly_msg, exc_msg) | [
"def",
"log_exception",
"(",
"format_err",
":",
"Callable",
"[",
"...",
",",
"Any",
"]",
",",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"module",
"=",
"inspect",
".",
"getmodule",
"(",
"inspect",
".",
"stack",
"(",
")",
"[",
"1",
"]",
"[",
"0",
"]",
")",
"if",
"module",
"is",
"not",
"None",
":",
"module_name",
"=",
"module",
".",
"__name__",
"else",
":",
"# If Python is unable to access the sources files, the call stack frame",
"# will be missing information, so let's guard.",
"# https://github.com/home-assistant/core/issues/24982",
"module_name",
"=",
"__name__",
"# Do not print the wrapper in the traceback",
"frames",
"=",
"len",
"(",
"inspect",
".",
"trace",
"(",
")",
")",
"-",
"1",
"exc_msg",
"=",
"traceback",
".",
"format_exc",
"(",
"-",
"frames",
")",
"friendly_msg",
"=",
"format_err",
"(",
"*",
"args",
")",
"logging",
".",
"getLogger",
"(",
"module_name",
")",
".",
"error",
"(",
"\"%s\\n%s\"",
",",
"friendly_msg",
",",
"exc_msg",
")"
] | [
92,
0
] | [
107,
73
] | python | en | ['en', 'en', 'en'] | True |
catch_log_exception | (
func: Callable[..., Any], format_err: Callable[..., Any], *args: Any
) | Decorate a callback to catch and log exceptions. | Decorate a callback to catch and log exceptions. | def catch_log_exception(
func: Callable[..., Any], format_err: Callable[..., Any], *args: Any
) -> Callable[[], None]:
"""Decorate a callback to catch and log exceptions."""
# Check for partials to properly determine if coroutine function
check_func = func
while isinstance(check_func, partial):
check_func = check_func.func
wrapper_func = None
if asyncio.iscoroutinefunction(check_func):
@wraps(func)
async def async_wrapper(*args: Any) -> None:
"""Catch and log exception."""
try:
await func(*args)
except Exception: # pylint: disable=broad-except
log_exception(format_err, *args)
wrapper_func = async_wrapper
else:
@wraps(func)
def wrapper(*args: Any) -> None:
"""Catch and log exception."""
try:
func(*args)
except Exception: # pylint: disable=broad-except
log_exception(format_err, *args)
wrapper_func = wrapper
return wrapper_func | [
"def",
"catch_log_exception",
"(",
"func",
":",
"Callable",
"[",
"...",
",",
"Any",
"]",
",",
"format_err",
":",
"Callable",
"[",
"...",
",",
"Any",
"]",
",",
"*",
"args",
":",
"Any",
")",
"->",
"Callable",
"[",
"[",
"]",
",",
"None",
"]",
":",
"# Check for partials to properly determine if coroutine function",
"check_func",
"=",
"func",
"while",
"isinstance",
"(",
"check_func",
",",
"partial",
")",
":",
"check_func",
"=",
"check_func",
".",
"func",
"wrapper_func",
"=",
"None",
"if",
"asyncio",
".",
"iscoroutinefunction",
"(",
"check_func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"async",
"def",
"async_wrapper",
"(",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"\"\"\"Catch and log exception.\"\"\"",
"try",
":",
"await",
"func",
"(",
"*",
"args",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"log_exception",
"(",
"format_err",
",",
"*",
"args",
")",
"wrapper_func",
"=",
"async_wrapper",
"else",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"\"\"\"Catch and log exception.\"\"\"",
"try",
":",
"func",
"(",
"*",
"args",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"log_exception",
"(",
"format_err",
",",
"*",
"args",
")",
"wrapper_func",
"=",
"wrapper",
"return",
"wrapper_func"
] | [
110,
0
] | [
143,
23
] | python | en | ['en', 'en', 'en'] | True |
catch_log_coro_exception | (
target: Coroutine[Any, Any, Any], format_err: Callable[..., Any], *args: Any
) | Decorate a coroutine to catch and log exceptions. | Decorate a coroutine to catch and log exceptions. | def catch_log_coro_exception(
target: Coroutine[Any, Any, Any], format_err: Callable[..., Any], *args: Any
) -> Coroutine[Any, Any, Any]:
"""Decorate a coroutine to catch and log exceptions."""
async def coro_wrapper(*args: Any) -> Any:
"""Catch and log exception."""
try:
return await target
except Exception: # pylint: disable=broad-except
log_exception(format_err, *args)
return None
return coro_wrapper() | [
"def",
"catch_log_coro_exception",
"(",
"target",
":",
"Coroutine",
"[",
"Any",
",",
"Any",
",",
"Any",
"]",
",",
"format_err",
":",
"Callable",
"[",
"...",
",",
"Any",
"]",
",",
"*",
"args",
":",
"Any",
")",
"->",
"Coroutine",
"[",
"Any",
",",
"Any",
",",
"Any",
"]",
":",
"async",
"def",
"coro_wrapper",
"(",
"*",
"args",
":",
"Any",
")",
"->",
"Any",
":",
"\"\"\"Catch and log exception.\"\"\"",
"try",
":",
"return",
"await",
"target",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"log_exception",
"(",
"format_err",
",",
"*",
"args",
")",
"return",
"None",
"return",
"coro_wrapper",
"(",
")"
] | [
146,
0
] | [
159,
25
] | python | en | ['en', 'en', 'en'] | True |
async_create_catching_coro | (target: Coroutine) | Wrap a coroutine to catch and log exceptions.
The exception will be logged together with a stacktrace of where the
coroutine was wrapped.
target: target coroutine.
| Wrap a coroutine to catch and log exceptions. | def async_create_catching_coro(target: Coroutine) -> Coroutine:
"""Wrap a coroutine to catch and log exceptions.
The exception will be logged together with a stacktrace of where the
coroutine was wrapped.
target: target coroutine.
"""
trace = traceback.extract_stack()
wrapped_target = catch_log_coro_exception(
target,
lambda *args: "Exception in {} called from\n {}".format(
target.__name__,
"".join(traceback.format_list(trace[:-1])),
),
)
return wrapped_target | [
"def",
"async_create_catching_coro",
"(",
"target",
":",
"Coroutine",
")",
"->",
"Coroutine",
":",
"trace",
"=",
"traceback",
".",
"extract_stack",
"(",
")",
"wrapped_target",
"=",
"catch_log_coro_exception",
"(",
"target",
",",
"lambda",
"*",
"args",
":",
"\"Exception in {} called from\\n {}\"",
".",
"format",
"(",
"target",
".",
"__name__",
",",
"\"\"",
".",
"join",
"(",
"traceback",
".",
"format_list",
"(",
"trace",
"[",
":",
"-",
"1",
"]",
")",
")",
",",
")",
",",
")",
"return",
"wrapped_target"
] | [
162,
0
] | [
179,
25
] | python | en | ['en', 'en', 'en'] | True |
HideSensitiveDataFilter.__init__ | (self, text: str) | Initialize sensitive data filter. | Initialize sensitive data filter. | def __init__(self, text: str) -> None:
"""Initialize sensitive data filter."""
super().__init__()
self.text = text | [
"def",
"__init__",
"(",
"self",
",",
"text",
":",
"str",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"text",
"=",
"text"
] | [
17,
4
] | [
20,
24
] | python | co | ['it', 'co', 'en'] | False |
HideSensitiveDataFilter.filter | (self, record: logging.LogRecord) | Hide sensitive data in messages. | Hide sensitive data in messages. | def filter(self, record: logging.LogRecord) -> bool:
"""Hide sensitive data in messages."""
record.msg = record.msg.replace(self.text, "*******")
return True | [
"def",
"filter",
"(",
"self",
",",
"record",
":",
"logging",
".",
"LogRecord",
")",
"->",
"bool",
":",
"record",
".",
"msg",
"=",
"record",
".",
"msg",
".",
"replace",
"(",
"self",
".",
"text",
",",
"\"*******\"",
")",
"return",
"True"
] | [
22,
4
] | [
26,
19
] | python | en | ['it', 'en', 'en'] | True |
HomeAssistantQueueHandler.emit | (self, record: logging.LogRecord) | Emit a log record. | Emit a log record. | def emit(self, record: logging.LogRecord) -> None:
"""Emit a log record."""
try:
self.enqueue(record)
except asyncio.CancelledError:
raise
except Exception: # pylint: disable=broad-except
self.handleError(record) | [
"def",
"emit",
"(",
"self",
",",
"record",
":",
"logging",
".",
"LogRecord",
")",
"->",
"None",
":",
"try",
":",
"self",
".",
"enqueue",
"(",
"record",
")",
"except",
"asyncio",
".",
"CancelledError",
":",
"raise",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"self",
".",
"handleError",
"(",
"record",
")"
] | [
32,
4
] | [
39,
36
] | python | bg | ['en', 'bg', 'pt'] | False |
HomeAssistantQueueHandler.handle | (self, record: logging.LogRecord) |
Conditionally emit the specified logging record.
Depending on which filters have been added to the handler, push the new
records onto the backing Queue.
The default python logger Handler acquires a lock
in the parent class which we do not need as
SimpleQueue is already thread safe.
See https://bugs.python.org/issue24645
|
Conditionally emit the specified logging record. | def handle(self, record: logging.LogRecord) -> Any:
"""
Conditionally emit the specified logging record.
Depending on which filters have been added to the handler, push the new
records onto the backing Queue.
The default python logger Handler acquires a lock
in the parent class which we do not need as
SimpleQueue is already thread safe.
See https://bugs.python.org/issue24645
"""
return_value = self.filter(record)
if return_value:
self.emit(record)
return return_value | [
"def",
"handle",
"(",
"self",
",",
"record",
":",
"logging",
".",
"LogRecord",
")",
"->",
"Any",
":",
"return_value",
"=",
"self",
".",
"filter",
"(",
"record",
")",
"if",
"return_value",
":",
"self",
".",
"emit",
"(",
"record",
")",
"return",
"return_value"
] | [
41,
4
] | [
57,
27
] | python | en | ['en', 'error', 'th'] | False |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the fail2ban sensor. | Set up the fail2ban sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the fail2ban sensor."""
name = config.get(CONF_NAME)
jails = config.get(CONF_JAILS)
log_file = config.get(CONF_FILE_PATH, DEFAULT_LOG)
device_list = []
log_parser = BanLogParser(log_file)
for jail in jails:
device_list.append(BanSensor(name, jail, log_parser))
async_add_entities(device_list, True) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"jails",
"=",
"config",
".",
"get",
"(",
"CONF_JAILS",
")",
"log_file",
"=",
"config",
".",
"get",
"(",
"CONF_FILE_PATH",
",",
"DEFAULT_LOG",
")",
"device_list",
"=",
"[",
"]",
"log_parser",
"=",
"BanLogParser",
"(",
"log_file",
")",
"for",
"jail",
"in",
"jails",
":",
"device_list",
".",
"append",
"(",
"BanSensor",
"(",
"name",
",",
"jail",
",",
"log_parser",
")",
")",
"async_add_entities",
"(",
"device_list",
",",
"True",
")"
] | [
33,
0
] | [
44,
41
] | python | en | ['en', 'su', 'en'] | True |
BanSensor.__init__ | (self, name, jail, log_parser) | Initialize the sensor. | Initialize the sensor. | def __init__(self, name, jail, log_parser):
"""Initialize the sensor."""
self._name = f"{name} {jail}"
self.jail = jail
self.ban_dict = {STATE_CURRENT_BANS: [], STATE_ALL_BANS: []}
self.last_ban = None
self.log_parser = log_parser
self.log_parser.ip_regex[self.jail] = re.compile(
r"\[{}\]\s*(Ban|Unban) (.*)".format(re.escape(self.jail))
)
_LOGGER.debug("Setting up jail %s", self.jail) | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"jail",
",",
"log_parser",
")",
":",
"self",
".",
"_name",
"=",
"f\"{name} {jail}\"",
"self",
".",
"jail",
"=",
"jail",
"self",
".",
"ban_dict",
"=",
"{",
"STATE_CURRENT_BANS",
":",
"[",
"]",
",",
"STATE_ALL_BANS",
":",
"[",
"]",
"}",
"self",
".",
"last_ban",
"=",
"None",
"self",
".",
"log_parser",
"=",
"log_parser",
"self",
".",
"log_parser",
".",
"ip_regex",
"[",
"self",
".",
"jail",
"]",
"=",
"re",
".",
"compile",
"(",
"r\"\\[{}\\]\\s*(Ban|Unban) (.*)\"",
".",
"format",
"(",
"re",
".",
"escape",
"(",
"self",
".",
"jail",
")",
")",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Setting up jail %s\"",
",",
"self",
".",
"jail",
")"
] | [
50,
4
] | [
60,
54
] | python | en | ['en', 'en', 'en'] | True |
BanSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
63,
4
] | [
65,
25
] | python | en | ['en', 'mi', 'en'] | True |
BanSensor.state_attributes | (self) | Return the state attributes of the fail2ban sensor. | Return the state attributes of the fail2ban sensor. | def state_attributes(self):
"""Return the state attributes of the fail2ban sensor."""
return self.ban_dict | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"ban_dict"
] | [
68,
4
] | [
70,
28
] | python | en | ['en', 'en', 'en'] | True |
BanSensor.state | (self) | Return the most recently banned IP Address. | Return the most recently banned IP Address. | def state(self):
"""Return the most recently banned IP Address."""
return self.last_ban | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"last_ban"
] | [
73,
4
] | [
75,
28
] | python | en | ['en', 'en', 'en'] | True |
BanSensor.update | (self) | Update the list of banned ips. | Update the list of banned ips. | def update(self):
"""Update the list of banned ips."""
self.log_parser.read_log(self.jail)
if self.log_parser.data:
for entry in self.log_parser.data:
_LOGGER.debug(entry)
current_ip = entry[1]
if entry[0] == "Ban":
if current_ip not in self.ban_dict[STATE_CURRENT_BANS]:
self.ban_dict[STATE_CURRENT_BANS].append(current_ip)
if current_ip not in self.ban_dict[STATE_ALL_BANS]:
self.ban_dict[STATE_ALL_BANS].append(current_ip)
if len(self.ban_dict[STATE_ALL_BANS]) > 10:
self.ban_dict[STATE_ALL_BANS].pop(0)
elif entry[0] == "Unban":
if current_ip in self.ban_dict[STATE_CURRENT_BANS]:
self.ban_dict[STATE_CURRENT_BANS].remove(current_ip)
if self.ban_dict[STATE_CURRENT_BANS]:
self.last_ban = self.ban_dict[STATE_CURRENT_BANS][-1]
else:
self.last_ban = "None" | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"log_parser",
".",
"read_log",
"(",
"self",
".",
"jail",
")",
"if",
"self",
".",
"log_parser",
".",
"data",
":",
"for",
"entry",
"in",
"self",
".",
"log_parser",
".",
"data",
":",
"_LOGGER",
".",
"debug",
"(",
"entry",
")",
"current_ip",
"=",
"entry",
"[",
"1",
"]",
"if",
"entry",
"[",
"0",
"]",
"==",
"\"Ban\"",
":",
"if",
"current_ip",
"not",
"in",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
":",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
".",
"append",
"(",
"current_ip",
")",
"if",
"current_ip",
"not",
"in",
"self",
".",
"ban_dict",
"[",
"STATE_ALL_BANS",
"]",
":",
"self",
".",
"ban_dict",
"[",
"STATE_ALL_BANS",
"]",
".",
"append",
"(",
"current_ip",
")",
"if",
"len",
"(",
"self",
".",
"ban_dict",
"[",
"STATE_ALL_BANS",
"]",
")",
">",
"10",
":",
"self",
".",
"ban_dict",
"[",
"STATE_ALL_BANS",
"]",
".",
"pop",
"(",
"0",
")",
"elif",
"entry",
"[",
"0",
"]",
"==",
"\"Unban\"",
":",
"if",
"current_ip",
"in",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
":",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
".",
"remove",
"(",
"current_ip",
")",
"if",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
":",
"self",
".",
"last_ban",
"=",
"self",
".",
"ban_dict",
"[",
"STATE_CURRENT_BANS",
"]",
"[",
"-",
"1",
"]",
"else",
":",
"self",
".",
"last_ban",
"=",
"\"None\""
] | [
77,
4
] | [
100,
34
] | python | en | ['en', 'en', 'en'] | True |
BanLogParser.__init__ | (self, log_file) | Initialize the parser. | Initialize the parser. | def __init__(self, log_file):
"""Initialize the parser."""
self.log_file = log_file
self.data = []
self.ip_regex = {} | [
"def",
"__init__",
"(",
"self",
",",
"log_file",
")",
":",
"self",
".",
"log_file",
"=",
"log_file",
"self",
".",
"data",
"=",
"[",
"]",
"self",
".",
"ip_regex",
"=",
"{",
"}"
] | [
106,
4
] | [
110,
26
] | python | en | ['en', 'en', 'en'] | True |
BanLogParser.read_log | (self, jail) | Read the fail2ban log and find entries for jail. | Read the fail2ban log and find entries for jail. | def read_log(self, jail):
"""Read the fail2ban log and find entries for jail."""
self.data = []
try:
with open(self.log_file, encoding="utf-8") as file_data:
self.data = self.ip_regex[jail].findall(file_data.read())
except (IndexError, FileNotFoundError, IsADirectoryError, UnboundLocalError):
_LOGGER.warning("File not present: %s", os.path.basename(self.log_file)) | [
"def",
"read_log",
"(",
"self",
",",
"jail",
")",
":",
"self",
".",
"data",
"=",
"[",
"]",
"try",
":",
"with",
"open",
"(",
"self",
".",
"log_file",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"as",
"file_data",
":",
"self",
".",
"data",
"=",
"self",
".",
"ip_regex",
"[",
"jail",
"]",
".",
"findall",
"(",
"file_data",
".",
"read",
"(",
")",
")",
"except",
"(",
"IndexError",
",",
"FileNotFoundError",
",",
"IsADirectoryError",
",",
"UnboundLocalError",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"File not present: %s\"",
",",
"os",
".",
"path",
".",
"basename",
"(",
"self",
".",
"log_file",
")",
")"
] | [
112,
4
] | [
120,
84
] | python | en | ['en', 'en', 'en'] | True |
async_attach_trigger | (hass, config, action, automation_info) | Listen for events based on configuration. | Listen for events based on configuration. | async def async_attach_trigger(hass, config, action, automation_info):
"""Listen for events based on configuration."""
event = config.get(CONF_EVENT)
job = HassJob(action)
if event == EVENT_SHUTDOWN:
@callback
def hass_shutdown(event):
"""Execute when Home Assistant is shutting down."""
hass.async_run_hass_job(
job,
{
"trigger": {
"platform": "homeassistant",
"event": event,
"description": "Home Assistant stopping",
}
},
event.context,
)
return hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, hass_shutdown)
# Automation are enabled while hass is starting up, fire right away
# Check state because a config reload shouldn't trigger it.
if automation_info["home_assistant_start"]:
hass.async_run_hass_job(
job,
{
"trigger": {
"platform": "homeassistant",
"event": event,
"description": "Home Assistant starting",
}
},
)
return lambda: None | [
"async",
"def",
"async_attach_trigger",
"(",
"hass",
",",
"config",
",",
"action",
",",
"automation_info",
")",
":",
"event",
"=",
"config",
".",
"get",
"(",
"CONF_EVENT",
")",
"job",
"=",
"HassJob",
"(",
"action",
")",
"if",
"event",
"==",
"EVENT_SHUTDOWN",
":",
"@",
"callback",
"def",
"hass_shutdown",
"(",
"event",
")",
":",
"\"\"\"Execute when Home Assistant is shutting down.\"\"\"",
"hass",
".",
"async_run_hass_job",
"(",
"job",
",",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"homeassistant\"",
",",
"\"event\"",
":",
"event",
",",
"\"description\"",
":",
"\"Home Assistant stopping\"",
",",
"}",
"}",
",",
"event",
".",
"context",
",",
")",
"return",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"hass_shutdown",
")",
"# Automation are enabled while hass is starting up, fire right away",
"# Check state because a config reload shouldn't trigger it.",
"if",
"automation_info",
"[",
"\"home_assistant_start\"",
"]",
":",
"hass",
".",
"async_run_hass_job",
"(",
"job",
",",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"homeassistant\"",
",",
"\"event\"",
":",
"event",
",",
"\"description\"",
":",
"\"Home Assistant starting\"",
",",
"}",
"}",
",",
")",
"return",
"lambda",
":",
"None"
] | [
19,
0
] | [
57,
23
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up an ADS sensor device. | Set up an ADS sensor device. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up an ADS sensor device."""
ads_hub = hass.data.get(ads.DATA_ADS)
ads_var = config[CONF_ADS_VAR]
ads_type = config[CONF_ADS_TYPE]
name = config[CONF_NAME]
unit_of_measurement = config.get(CONF_UNIT_OF_MEASUREMENT)
factor = config.get(CONF_ADS_FACTOR)
entity = AdsSensor(ads_hub, ads_var, ads_type, name, unit_of_measurement, factor)
add_entities([entity]) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"ads_hub",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"ads",
".",
"DATA_ADS",
")",
"ads_var",
"=",
"config",
"[",
"CONF_ADS_VAR",
"]",
"ads_type",
"=",
"config",
"[",
"CONF_ADS_TYPE",
"]",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"unit_of_measurement",
"=",
"config",
".",
"get",
"(",
"CONF_UNIT_OF_MEASUREMENT",
")",
"factor",
"=",
"config",
".",
"get",
"(",
"CONF_ADS_FACTOR",
")",
"entity",
"=",
"AdsSensor",
"(",
"ads_hub",
",",
"ads_var",
",",
"ads_type",
",",
"name",
",",
"unit_of_measurement",
",",
"factor",
")",
"add_entities",
"(",
"[",
"entity",
"]",
")"
] | [
30,
0
] | [
42,
26
] | python | en | ['en', 'haw', 'en'] | True |
AdsSensor.__init__ | (self, ads_hub, ads_var, ads_type, name, unit_of_measurement, factor) | Initialize AdsSensor entity. | Initialize AdsSensor entity. | def __init__(self, ads_hub, ads_var, ads_type, name, unit_of_measurement, factor):
"""Initialize AdsSensor entity."""
super().__init__(ads_hub, name, ads_var)
self._unit_of_measurement = unit_of_measurement
self._ads_type = ads_type
self._factor = factor | [
"def",
"__init__",
"(",
"self",
",",
"ads_hub",
",",
"ads_var",
",",
"ads_type",
",",
"name",
",",
"unit_of_measurement",
",",
"factor",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"ads_hub",
",",
"name",
",",
"ads_var",
")",
"self",
".",
"_unit_of_measurement",
"=",
"unit_of_measurement",
"self",
".",
"_ads_type",
"=",
"ads_type",
"self",
".",
"_factor",
"=",
"factor"
] | [
48,
4
] | [
53,
29
] | python | es | ['es', 'pl', 'it'] | False |
AdsSensor.async_added_to_hass | (self) | Register device notification. | Register device notification. | async def async_added_to_hass(self):
"""Register device notification."""
await self.async_initialize_device(
self._ads_var,
self._ads_hub.ADS_TYPEMAP[self._ads_type],
STATE_KEY_STATE,
self._factor,
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_initialize_device",
"(",
"self",
".",
"_ads_var",
",",
"self",
".",
"_ads_hub",
".",
"ADS_TYPEMAP",
"[",
"self",
".",
"_ads_type",
"]",
",",
"STATE_KEY_STATE",
",",
"self",
".",
"_factor",
",",
")"
] | [
55,
4
] | [
62,
9
] | python | en | ['da', 'en', 'en'] | True |
AdsSensor.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_dict[STATE_KEY_STATE] | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state_dict",
"[",
"STATE_KEY_STATE",
"]"
] | [
65,
4
] | [
67,
48
] | python | en | ['en', 'en', 'en'] | True |
AdsSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
70,
4
] | [
72,
40
] | python | en | ['en', 'la', 'en'] | True |
test_form | (hass) | Test we get the form. | Test we get the form. | async def test_form(hass):
"""Test we get the form."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["errors"] == {}
with patch(
"homeassistant.components.aurora.config_flow.AuroraForecast.get_forecast_data",
return_value=True,
), patch(
"homeassistant.components.aurora.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.aurora.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
DATA,
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "Aurora - Home"
assert result2["data"] == DATA
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_form",
"(",
"hass",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"}",
"with",
"patch",
"(",
"\"homeassistant.components.aurora.config_flow.AuroraForecast.get_forecast_data\"",
",",
"return_value",
"=",
"True",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.aurora.async_setup\"",
",",
"return_value",
"=",
"True",
")",
"as",
"mock_setup",
",",
"patch",
"(",
"\"homeassistant.components.aurora.async_setup_entry\"",
",",
"return_value",
"=",
"True",
",",
")",
"as",
"mock_setup_entry",
":",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"DATA",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result2",
"[",
"\"title\"",
"]",
"==",
"\"Aurora - Home\"",
"assert",
"result2",
"[",
"\"data\"",
"]",
"==",
"DATA",
"assert",
"len",
"(",
"mock_setup",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
15,
0
] | [
43,
48
] | python | en | ['en', 'en', 'en'] | True |
test_form_cannot_connect | (hass) | Test if invalid response or no connection returned from the API. | Test if invalid response or no connection returned from the API. | async def test_form_cannot_connect(hass):
"""Test if invalid response or no connection returned from the API."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"homeassistant.components.aurora.AuroraForecast.get_forecast_data",
side_effect=ConnectionError,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
DATA,
)
assert result["type"] == "form"
assert result["step_id"] == "user"
assert result["errors"] == {"base": "cannot_connect"} | [
"async",
"def",
"test_form_cannot_connect",
"(",
"hass",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.aurora.AuroraForecast.get_forecast_data\"",
",",
"side_effect",
"=",
"ConnectionError",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"DATA",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}"
] | [
46,
0
] | [
65,
57
] | python | en | ['en', 'en', 'en'] | True |
test_with_unknown_error | (hass) | Test with unknown error response from the API. | Test with unknown error response from the API. | async def test_with_unknown_error(hass):
"""Test with unknown error response from the API."""
await setup.async_setup_component(hass, "persistent_notification", {})
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"homeassistant.components.aurora.AuroraForecast.get_forecast_data",
side_effect=Exception,
):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
DATA,
)
assert result["type"] == "form"
assert result["step_id"] == "user"
assert result["errors"] == {"base": "unknown"} | [
"async",
"def",
"test_with_unknown_error",
"(",
"hass",
")",
":",
"await",
"setup",
".",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.aurora.AuroraForecast.get_forecast_data\"",
",",
"side_effect",
"=",
"Exception",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"DATA",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"unknown\"",
"}"
] | [
68,
0
] | [
86,
50
] | python | en | ['en', 'en', 'en'] | True |
test_option_flow | (hass) | Test option flow. | Test option flow. | async def test_option_flow(hass):
"""Test option flow."""
entry = MockConfigEntry(domain=DOMAIN, data=DATA)
entry.add_to_hass(hass)
assert not entry.options
with patch("homeassistant.components.aurora.async_setup_entry", return_value=True):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(
entry.entry_id,
data=None,
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "init"
result = await hass.config_entries.options.async_configure(
result["flow_id"],
user_input={"forecast_threshold": 65},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result["title"] == ""
assert result["data"]["forecast_threshold"] == 65 | [
"async",
"def",
"test_option_flow",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"DATA",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"not",
"entry",
".",
"options",
"with",
"patch",
"(",
"\"homeassistant.components.aurora.async_setup_entry\"",
",",
"return_value",
"=",
"True",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_init",
"(",
"entry",
".",
"entry_id",
",",
"data",
"=",
"None",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"init\"",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"options",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"user_input",
"=",
"{",
"\"forecast_threshold\"",
":",
"65",
"}",
",",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"\"\"",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"\"forecast_threshold\"",
"]",
"==",
"65"
] | [
89,
0
] | [
114,
53
] | python | da | ['nl', 'da', 'en'] | False |
async_setup_entry | (hass, entry, async_add_entities) | Set up the Pi-hole sensor. | Set up the Pi-hole sensor. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the Pi-hole sensor."""
name = entry.data[CONF_NAME]
hole_data = hass.data[PIHOLE_DOMAIN][entry.entry_id]
sensors = [
PiHoleSensor(
hole_data[DATA_KEY_API],
hole_data[DATA_KEY_COORDINATOR],
name,
sensor_name,
entry.entry_id,
)
for sensor_name in SENSOR_LIST
]
async_add_entities(sensors, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"name",
"=",
"entry",
".",
"data",
"[",
"CONF_NAME",
"]",
"hole_data",
"=",
"hass",
".",
"data",
"[",
"PIHOLE_DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"sensors",
"=",
"[",
"PiHoleSensor",
"(",
"hole_data",
"[",
"DATA_KEY_API",
"]",
",",
"hole_data",
"[",
"DATA_KEY_COORDINATOR",
"]",
",",
"name",
",",
"sensor_name",
",",
"entry",
".",
"entry_id",
",",
")",
"for",
"sensor_name",
"in",
"SENSOR_LIST",
"]",
"async_add_entities",
"(",
"sensors",
",",
"True",
")"
] | [
15,
0
] | [
29,
37
] | python | en | ['en', 'haw', 'en'] | True |
PiHoleSensor.__init__ | (self, api, coordinator, name, sensor_name, server_unique_id) | Initialize a Pi-hole sensor. | Initialize a Pi-hole sensor. | def __init__(self, api, coordinator, name, sensor_name, server_unique_id):
"""Initialize a Pi-hole sensor."""
super().__init__(api, coordinator, name, server_unique_id)
self._condition = sensor_name
variable_info = SENSOR_DICT[sensor_name]
self._condition_name = variable_info[0]
self._unit_of_measurement = variable_info[1]
self._icon = variable_info[2] | [
"def",
"__init__",
"(",
"self",
",",
"api",
",",
"coordinator",
",",
"name",
",",
"sensor_name",
",",
"server_unique_id",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"api",
",",
"coordinator",
",",
"name",
",",
"server_unique_id",
")",
"self",
".",
"_condition",
"=",
"sensor_name",
"variable_info",
"=",
"SENSOR_DICT",
"[",
"sensor_name",
"]",
"self",
".",
"_condition_name",
"=",
"variable_info",
"[",
"0",
"]",
"self",
".",
"_unit_of_measurement",
"=",
"variable_info",
"[",
"1",
"]",
"self",
".",
"_icon",
"=",
"variable_info",
"[",
"2",
"]"
] | [
35,
4
] | [
44,
37
] | python | en | ['en', 'haw', 'en'] | True |
PiHoleSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self._name} {self._condition_name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name} {self._condition_name}\""
] | [
47,
4
] | [
49,
53
] | python | en | ['en', 'mi', 'en'] | True |
PiHoleSensor.unique_id | (self) | Return the unique id of the sensor. | Return the unique id of the sensor. | def unique_id(self):
"""Return the unique id of the sensor."""
return f"{self._server_unique_id}/{self._condition_name}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._server_unique_id}/{self._condition_name}\""
] | [
52,
4
] | [
54,
65
] | python | en | ['en', 'la', 'en'] | True |
PiHoleSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
57,
4
] | [
59,
25
] | python | en | ['en', 'en', 'en'] | True |
PiHoleSensor.unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
62,
4
] | [
64,
40
] | python | en | ['en', 'en', 'en'] | True |
PiHoleSensor.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
try:
return round(self.api.data[self._condition], 2)
except TypeError:
return self.api.data[self._condition] | [
"def",
"state",
"(",
"self",
")",
":",
"try",
":",
"return",
"round",
"(",
"self",
".",
"api",
".",
"data",
"[",
"self",
".",
"_condition",
"]",
",",
"2",
")",
"except",
"TypeError",
":",
"return",
"self",
".",
"api",
".",
"data",
"[",
"self",
".",
"_condition",
"]"
] | [
67,
4
] | [
72,
49
] | python | en | ['en', 'en', 'en'] | True |
PiHoleSensor.device_state_attributes | (self) | Return the state attributes of the Pi-hole. | Return the state attributes of the Pi-hole. | def device_state_attributes(self):
"""Return the state attributes of the Pi-hole."""
return {ATTR_BLOCKED_DOMAINS: self.api.data["domains_being_blocked"]} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_BLOCKED_DOMAINS",
":",
"self",
".",
"api",
".",
"data",
"[",
"\"domains_being_blocked\"",
"]",
"}"
] | [
75,
4
] | [
77,
77
] | python | en | ['en', 'en', 'en'] | True |
test_get_device_detects_lock | (mock_openzwave) | Test get_device returns a Z-Wave lock. | Test get_device returns a Z-Wave lock. | def test_get_device_detects_lock(mock_openzwave):
"""Test get_device returns a Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert isinstance(device, lock.ZwaveLock) | [
"def",
"test_get_device_detects_lock",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"isinstance",
"(",
"device",
",",
"lock",
".",
"ZwaveLock",
")"
] | [
8,
0
] | [
19,
45
] | python | en | ['en', 'en', 'en'] | True |
test_lock_turn_on_and_off | (mock_openzwave) | Test turning on a Z-Wave lock. | Test turning on a Z-Wave lock. | def test_lock_turn_on_and_off(mock_openzwave):
"""Test turning on a Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert not values.primary.data
device.lock()
assert values.primary.data
device.unlock()
assert not values.primary.data | [
"def",
"test_lock_turn_on_and_off",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"not",
"values",
".",
"primary",
".",
"data",
"device",
".",
"lock",
"(",
")",
"assert",
"values",
".",
"primary",
".",
"data",
"device",
".",
"unlock",
"(",
")",
"assert",
"not",
"values",
".",
"primary",
".",
"data"
] | [
22,
0
] | [
39,
34
] | python | en | ['en', 'en', 'en'] | True |
test_lock_value_changed | (mock_openzwave) | Test value changed for Z-Wave lock. | Test value changed for Z-Wave lock. | def test_lock_value_changed(mock_openzwave):
"""Test value changed for Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert not device.is_locked
values.primary.data = True
value_changed(values.primary)
assert device.is_locked | [
"def",
"test_lock_value_changed",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"primary",
".",
"data",
"=",
"True",
"value_changed",
"(",
"values",
".",
"primary",
")",
"assert",
"device",
".",
"is_locked"
] | [
42,
0
] | [
58,
27
] | python | en | ['en', 'en', 'en'] | True |
test_lock_state_workaround | (mock_openzwave) | Test value changed for Z-Wave lock using notification state. | Test value changed for Z-Wave lock using notification state. | def test_lock_state_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock using notification state."""
node = MockNode(manufacturer_id="0090", product_id="0440")
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=MockValue(data=1, node=node),
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values)
assert device.is_locked
values.access_control.data = 2
value_changed(values.access_control)
assert not device.is_locked | [
"def",
"test_lock_state_workaround",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"0090\"",
",",
"product_id",
"=",
"\"0440\"",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"True",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"MockValue",
"(",
"data",
"=",
"1",
",",
"node",
"=",
"node",
")",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
")",
"assert",
"device",
".",
"is_locked",
"values",
".",
"access_control",
".",
"data",
"=",
"2",
"value_changed",
"(",
"values",
".",
"access_control",
")",
"assert",
"not",
"device",
".",
"is_locked"
] | [
61,
0
] | [
74,
31
] | python | en | ['en', 'en', 'en'] | True |
test_track_message_workaround | (mock_openzwave) | Test value changed for Z-Wave lock by alarm-clearing workaround. | Test value changed for Z-Wave lock by alarm-clearing workaround. | def test_track_message_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock by alarm-clearing workaround."""
node = MockNode(
manufacturer_id="003B",
product_id="5044",
stats={"lastReceivedMessage": [0] * 6},
)
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=None,
alarm_type=None,
alarm_level=None,
)
# Here we simulate an RF lock. The first lock.get_device will call
# update properties, simulating the first DoorLock report. We then trigger
# a change, simulating the openzwave automatic refreshing behavior (which
# is enabled for at least the lock that needs this workaround)
node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
device = lock.get_device(node=node, values=values)
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[lock.ATTR_NOTIFICATION] == "RF Lock"
# Simulate a keypad unlock. We trigger a value_changed() which simulates
# the Alarm notification received from the lock. Then, we trigger
# value_changed() to simulate the automatic refreshing behavior.
values.access_control = MockValue(data=6, node=node)
values.alarm_type = MockValue(data=19, node=node)
values.alarm_level = MockValue(data=3, node=node)
node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_ALARM
value_changed(values.access_control)
node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
values.primary.data = False
value_changed(values.primary)
assert not device.is_locked
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS]
== "Unlocked with Keypad by user 3"
)
# Again, simulate an RF lock.
device.lock()
node.stats["lastReceivedMessage"][5] = const.COMMAND_CLASS_DOOR_LOCK
value_changed(values.primary)
assert device.is_locked
assert device.device_state_attributes[lock.ATTR_NOTIFICATION] == "RF Lock" | [
"def",
"test_track_message_workaround",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"003B\"",
",",
"product_id",
"=",
"\"5044\"",
",",
"stats",
"=",
"{",
"\"lastReceivedMessage\"",
":",
"[",
"0",
"]",
"*",
"6",
"}",
",",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"True",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"# Here we simulate an RF lock. The first lock.get_device will call",
"# update properties, simulating the first DoorLock report. We then trigger",
"# a change, simulating the openzwave automatic refreshing behavior (which",
"# is enabled for at least the lock that needs this workaround)",
"node",
".",
"stats",
"[",
"\"lastReceivedMessage\"",
"]",
"[",
"5",
"]",
"=",
"const",
".",
"COMMAND_CLASS_DOOR_LOCK",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
")",
"value_changed",
"(",
"values",
".",
"primary",
")",
"assert",
"device",
".",
"is_locked",
"assert",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_NOTIFICATION",
"]",
"==",
"\"RF Lock\"",
"# Simulate a keypad unlock. We trigger a value_changed() which simulates",
"# the Alarm notification received from the lock. Then, we trigger",
"# value_changed() to simulate the automatic refreshing behavior.",
"values",
".",
"access_control",
"=",
"MockValue",
"(",
"data",
"=",
"6",
",",
"node",
"=",
"node",
")",
"values",
".",
"alarm_type",
"=",
"MockValue",
"(",
"data",
"=",
"19",
",",
"node",
"=",
"node",
")",
"values",
".",
"alarm_level",
"=",
"MockValue",
"(",
"data",
"=",
"3",
",",
"node",
"=",
"node",
")",
"node",
".",
"stats",
"[",
"\"lastReceivedMessage\"",
"]",
"[",
"5",
"]",
"=",
"const",
".",
"COMMAND_CLASS_ALARM",
"value_changed",
"(",
"values",
".",
"access_control",
")",
"node",
".",
"stats",
"[",
"\"lastReceivedMessage\"",
"]",
"[",
"5",
"]",
"=",
"const",
".",
"COMMAND_CLASS_DOOR_LOCK",
"values",
".",
"primary",
".",
"data",
"=",
"False",
"value_changed",
"(",
"values",
".",
"primary",
")",
"assert",
"not",
"device",
".",
"is_locked",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Unlocked with Keypad by user 3\"",
")",
"# Again, simulate an RF lock.",
"device",
".",
"lock",
"(",
")",
"node",
".",
"stats",
"[",
"\"lastReceivedMessage\"",
"]",
"[",
"5",
"]",
"=",
"const",
".",
"COMMAND_CLASS_DOOR_LOCK",
"value_changed",
"(",
"values",
".",
"primary",
")",
"assert",
"device",
".",
"is_locked",
"assert",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_NOTIFICATION",
"]",
"==",
"\"RF Lock\""
] | [
77,
0
] | [
123,
78
] | python | en | ['en', 'en', 'en'] | True |
test_v2btze_value_changed | (mock_openzwave) | Test value changed for v2btze Z-Wave lock. | Test value changed for v2btze Z-Wave lock. | def test_v2btze_value_changed(mock_openzwave):
"""Test value changed for v2btze Z-Wave lock."""
node = MockNode(manufacturer_id="010e", product_id="0002")
values = MockEntityValues(
primary=MockValue(data=None, node=node),
v2btze_advanced=MockValue(data="Advanced", node=node),
access_control=MockValue(data=19, node=node),
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert device._v2btze
assert not device.is_locked
values.access_control.data = 24
value_changed(values.primary)
assert device.is_locked | [
"def",
"test_v2btze_value_changed",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"010e\"",
",",
"product_id",
"=",
"\"0002\"",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"v2btze_advanced",
"=",
"MockValue",
"(",
"data",
"=",
"\"Advanced\"",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"MockValue",
"(",
"data",
"=",
"19",
",",
"node",
"=",
"node",
")",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"device",
".",
"_v2btze",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"access_control",
".",
"data",
"=",
"24",
"value_changed",
"(",
"values",
".",
"primary",
")",
"assert",
"device",
".",
"is_locked"
] | [
126,
0
] | [
144,
27
] | python | en | ['en', 'da', 'en'] | True |
test_alarm_type_workaround | (mock_openzwave) | Test value changed for Z-Wave lock using alarm type. | Test value changed for Z-Wave lock using alarm type. | def test_alarm_type_workaround(mock_openzwave):
"""Test value changed for Z-Wave lock using alarm type."""
node = MockNode(manufacturer_id="0109", product_id="0000")
values = MockEntityValues(
primary=MockValue(data=True, node=node),
access_control=None,
alarm_type=MockValue(data=16, node=node),
alarm_level=None,
)
device = lock.get_device(node=node, values=values)
assert not device.is_locked
values.alarm_type.data = 18
value_changed(values.alarm_type)
assert device.is_locked
values.alarm_type.data = 19
value_changed(values.alarm_type)
assert not device.is_locked
values.alarm_type.data = 21
value_changed(values.alarm_type)
assert device.is_locked
values.alarm_type.data = 22
value_changed(values.alarm_type)
assert not device.is_locked
values.alarm_type.data = 24
value_changed(values.alarm_type)
assert device.is_locked
values.alarm_type.data = 25
value_changed(values.alarm_type)
assert not device.is_locked
values.alarm_type.data = 27
value_changed(values.alarm_type)
assert device.is_locked | [
"def",
"test_alarm_type_workaround",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"0109\"",
",",
"product_id",
"=",
"\"0000\"",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"True",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"MockValue",
"(",
"data",
"=",
"16",
",",
"node",
"=",
"node",
")",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
")",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"18",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"19",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"21",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"22",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"24",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"25",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"not",
"device",
".",
"is_locked",
"values",
".",
"alarm_type",
".",
"data",
"=",
"27",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"is_locked"
] | [
147,
0
] | [
185,
27
] | python | en | ['en', 'en', 'en'] | True |
test_lock_access_control | (mock_openzwave) | Test access control for Z-Wave lock. | Test access control for Z-Wave lock. | def test_lock_access_control(mock_openzwave):
"""Test access control for Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=MockValue(data=11, node=node),
alarm_type=None,
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert device.device_state_attributes[lock.ATTR_NOTIFICATION] == "Lock Jammed" | [
"def",
"test_lock_access_control",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"MockValue",
"(",
"data",
"=",
"11",
",",
"node",
"=",
"node",
")",
",",
"alarm_type",
"=",
"None",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_NOTIFICATION",
"]",
"==",
"\"Lock Jammed\""
] | [
188,
0
] | [
199,
82
] | python | en | ['en', 'en', 'en'] | True |
test_lock_alarm_type | (mock_openzwave) | Test alarm type for Z-Wave lock. | Test alarm type for Z-Wave lock. | def test_lock_alarm_type(mock_openzwave):
"""Test alarm type for Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=None,
alarm_type=MockValue(data=None, node=node),
alarm_level=None,
)
device = lock.get_device(node=node, values=values, node_config={})
assert lock.ATTR_LOCK_STATUS not in device.device_state_attributes
values.alarm_type.data = 21
value_changed(values.alarm_type)
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS] == "Manually Locked None"
)
values.alarm_type.data = 18
value_changed(values.alarm_type)
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS]
== "Locked with Keypad by user None"
)
values.alarm_type.data = 161
value_changed(values.alarm_type)
assert device.device_state_attributes[lock.ATTR_LOCK_STATUS] == "Tamper Alarm: None"
values.alarm_type.data = 9
value_changed(values.alarm_type)
assert device.device_state_attributes[lock.ATTR_LOCK_STATUS] == "Deadbolt Jammed" | [
"def",
"test_lock_alarm_type",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"alarm_level",
"=",
"None",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"lock",
".",
"ATTR_LOCK_STATUS",
"not",
"in",
"device",
".",
"device_state_attributes",
"values",
".",
"alarm_type",
".",
"data",
"=",
"21",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Manually Locked None\"",
")",
"values",
".",
"alarm_type",
".",
"data",
"=",
"18",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Locked with Keypad by user None\"",
")",
"values",
".",
"alarm_type",
".",
"data",
"=",
"161",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Tamper Alarm: None\"",
"values",
".",
"alarm_type",
".",
"data",
"=",
"9",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"assert",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Deadbolt Jammed\""
] | [
202,
0
] | [
234,
85
] | python | en | ['en', 'tr', 'en'] | True |
test_lock_alarm_level | (mock_openzwave) | Test alarm level for Z-Wave lock. | Test alarm level for Z-Wave lock. | def test_lock_alarm_level(mock_openzwave):
"""Test alarm level for Z-Wave lock."""
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=None, node=node),
access_control=None,
alarm_type=MockValue(data=None, node=node),
alarm_level=MockValue(data=None, node=node),
)
device = lock.get_device(node=node, values=values, node_config={})
assert lock.ATTR_LOCK_STATUS not in device.device_state_attributes
values.alarm_type.data = 21
values.alarm_level.data = 1
value_changed(values.alarm_type)
value_changed(values.alarm_level)
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS]
== "Manually Locked by Key Cylinder or Inside thumb turn"
)
values.alarm_type.data = 18
values.alarm_level.data = "alice"
value_changed(values.alarm_type)
value_changed(values.alarm_level)
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS]
== "Locked with Keypad by user alice"
)
values.alarm_type.data = 161
values.alarm_level.data = 1
value_changed(values.alarm_type)
value_changed(values.alarm_level)
assert (
device.device_state_attributes[lock.ATTR_LOCK_STATUS]
== "Tamper Alarm: Too many keypresses"
) | [
"def",
"test_lock_alarm_level",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"values",
"=",
"MockEntityValues",
"(",
"primary",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"access_control",
"=",
"None",
",",
"alarm_type",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
"alarm_level",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
")",
",",
")",
"device",
"=",
"lock",
".",
"get_device",
"(",
"node",
"=",
"node",
",",
"values",
"=",
"values",
",",
"node_config",
"=",
"{",
"}",
")",
"assert",
"lock",
".",
"ATTR_LOCK_STATUS",
"not",
"in",
"device",
".",
"device_state_attributes",
"values",
".",
"alarm_type",
".",
"data",
"=",
"21",
"values",
".",
"alarm_level",
".",
"data",
"=",
"1",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"value_changed",
"(",
"values",
".",
"alarm_level",
")",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Manually Locked by Key Cylinder or Inside thumb turn\"",
")",
"values",
".",
"alarm_type",
".",
"data",
"=",
"18",
"values",
".",
"alarm_level",
".",
"data",
"=",
"\"alice\"",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"value_changed",
"(",
"values",
".",
"alarm_level",
")",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Locked with Keypad by user alice\"",
")",
"values",
".",
"alarm_type",
".",
"data",
"=",
"161",
"values",
".",
"alarm_level",
".",
"data",
"=",
"1",
"value_changed",
"(",
"values",
".",
"alarm_type",
")",
"value_changed",
"(",
"values",
".",
"alarm_level",
")",
"assert",
"(",
"device",
".",
"device_state_attributes",
"[",
"lock",
".",
"ATTR_LOCK_STATUS",
"]",
"==",
"\"Tamper Alarm: Too many keypresses\"",
")"
] | [
237,
0
] | [
275,
5
] | python | en | ['en', 'da', 'en'] | True |
setup_ozw | (hass, mock_openzwave) | Set up the mock ZWave config entry. | Set up the mock ZWave config entry. | async def setup_ozw(hass, mock_openzwave):
"""Set up the mock ZWave config entry."""
hass.config.components.add("zwave")
config_entry = config_entries.ConfigEntry(
1,
"zwave",
"Mock Title",
{"usb_path": "mock-path", "network_key": "mock-key"},
"test",
config_entries.CONN_CLASS_LOCAL_PUSH,
system_options={},
)
await hass.config_entries.async_forward_entry_setup(config_entry, "lock")
await hass.async_block_till_done() | [
"async",
"def",
"setup_ozw",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"\"zwave\"",
")",
"config_entry",
"=",
"config_entries",
".",
"ConfigEntry",
"(",
"1",
",",
"\"zwave\"",
",",
"\"Mock Title\"",
",",
"{",
"\"usb_path\"",
":",
"\"mock-path\"",
",",
"\"network_key\"",
":",
"\"mock-key\"",
"}",
",",
"\"test\"",
",",
"config_entries",
".",
"CONN_CLASS_LOCAL_PUSH",
",",
"system_options",
"=",
"{",
"}",
",",
")",
"await",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"config_entry",
",",
"\"lock\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
278,
0
] | [
291,
38
] | python | en | ['en', 'da', 'en'] | True |
test_lock_set_usercode_service | (hass, mock_openzwave) | Test the zwave lock set_usercode service. | Test the zwave lock set_usercode service. | async def test_lock_set_usercode_service(hass, mock_openzwave):
"""Test the zwave lock set_usercode service."""
mock_network = hass.data[const.DATA_NETWORK] = MagicMock()
node = MockNode(node_id=12)
value0 = MockValue(data=" ", node=node, index=0)
value1 = MockValue(data=" ", node=node, index=1)
node.get_values.return_value = {value0.value_id: value0, value1.value_id: value1}
mock_network.nodes = {node.node_id: node}
await setup_ozw(hass, mock_openzwave)
await hass.async_block_till_done()
await hass.services.async_call(
lock.DOMAIN,
lock.SERVICE_SET_USERCODE,
{
const.ATTR_NODE_ID: node.node_id,
lock.ATTR_USERCODE: "1234",
lock.ATTR_CODE_SLOT: 1,
},
)
await hass.async_block_till_done()
assert value1.data == "1234"
mock_network.nodes = {node.node_id: node}
await hass.services.async_call(
lock.DOMAIN,
lock.SERVICE_SET_USERCODE,
{
const.ATTR_NODE_ID: node.node_id,
lock.ATTR_USERCODE: "123",
lock.ATTR_CODE_SLOT: 1,
},
)
await hass.async_block_till_done()
assert value1.data == "1234" | [
"async",
"def",
"test_lock_set_usercode_service",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_network",
"=",
"hass",
".",
"data",
"[",
"const",
".",
"DATA_NETWORK",
"]",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"MockNode",
"(",
"node_id",
"=",
"12",
")",
"value0",
"=",
"MockValue",
"(",
"data",
"=",
"\" \"",
",",
"node",
"=",
"node",
",",
"index",
"=",
"0",
")",
"value1",
"=",
"MockValue",
"(",
"data",
"=",
"\" \"",
",",
"node",
"=",
"node",
",",
"index",
"=",
"1",
")",
"node",
".",
"get_values",
".",
"return_value",
"=",
"{",
"value0",
".",
"value_id",
":",
"value0",
",",
"value1",
".",
"value_id",
":",
"value1",
"}",
"mock_network",
".",
"nodes",
"=",
"{",
"node",
".",
"node_id",
":",
"node",
"}",
"await",
"setup_ozw",
"(",
"hass",
",",
"mock_openzwave",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"lock",
".",
"DOMAIN",
",",
"lock",
".",
"SERVICE_SET_USERCODE",
",",
"{",
"const",
".",
"ATTR_NODE_ID",
":",
"node",
".",
"node_id",
",",
"lock",
".",
"ATTR_USERCODE",
":",
"\"1234\"",
",",
"lock",
".",
"ATTR_CODE_SLOT",
":",
"1",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"value1",
".",
"data",
"==",
"\"1234\"",
"mock_network",
".",
"nodes",
"=",
"{",
"node",
".",
"node_id",
":",
"node",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"lock",
".",
"DOMAIN",
",",
"lock",
".",
"SERVICE_SET_USERCODE",
",",
"{",
"const",
".",
"ATTR_NODE_ID",
":",
"node",
".",
"node_id",
",",
"lock",
".",
"ATTR_USERCODE",
":",
"\"123\"",
",",
"lock",
".",
"ATTR_CODE_SLOT",
":",
"1",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"value1",
".",
"data",
"==",
"\"1234\""
] | [
294,
0
] | [
334,
32
] | python | en | ['en', 'de', 'en'] | True |
test_lock_get_usercode_service | (hass, mock_openzwave) | Test the zwave lock get_usercode service. | Test the zwave lock get_usercode service. | async def test_lock_get_usercode_service(hass, mock_openzwave):
"""Test the zwave lock get_usercode service."""
mock_network = hass.data[const.DATA_NETWORK] = MagicMock()
node = MockNode(node_id=12)
value0 = MockValue(data=None, node=node, index=0)
value1 = MockValue(data="1234", node=node, index=1)
node.get_values.return_value = {value0.value_id: value0, value1.value_id: value1}
await setup_ozw(hass, mock_openzwave)
await hass.async_block_till_done()
with patch.object(lock, "_LOGGER") as mock_logger:
mock_network.nodes = {node.node_id: node}
await hass.services.async_call(
lock.DOMAIN,
lock.SERVICE_GET_USERCODE,
{const.ATTR_NODE_ID: node.node_id, lock.ATTR_CODE_SLOT: 1},
)
await hass.async_block_till_done()
# This service only seems to write to the log
assert mock_logger.info.called
assert len(mock_logger.info.mock_calls) == 1
assert mock_logger.info.mock_calls[0][1][2] == "1234" | [
"async",
"def",
"test_lock_get_usercode_service",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_network",
"=",
"hass",
".",
"data",
"[",
"const",
".",
"DATA_NETWORK",
"]",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"MockNode",
"(",
"node_id",
"=",
"12",
")",
"value0",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
",",
"index",
"=",
"0",
")",
"value1",
"=",
"MockValue",
"(",
"data",
"=",
"\"1234\"",
",",
"node",
"=",
"node",
",",
"index",
"=",
"1",
")",
"node",
".",
"get_values",
".",
"return_value",
"=",
"{",
"value0",
".",
"value_id",
":",
"value0",
",",
"value1",
".",
"value_id",
":",
"value1",
"}",
"await",
"setup_ozw",
"(",
"hass",
",",
"mock_openzwave",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"with",
"patch",
".",
"object",
"(",
"lock",
",",
"\"_LOGGER\"",
")",
"as",
"mock_logger",
":",
"mock_network",
".",
"nodes",
"=",
"{",
"node",
".",
"node_id",
":",
"node",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"lock",
".",
"DOMAIN",
",",
"lock",
".",
"SERVICE_GET_USERCODE",
",",
"{",
"const",
".",
"ATTR_NODE_ID",
":",
"node",
".",
"node_id",
",",
"lock",
".",
"ATTR_CODE_SLOT",
":",
"1",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# This service only seems to write to the log",
"assert",
"mock_logger",
".",
"info",
".",
"called",
"assert",
"len",
"(",
"mock_logger",
".",
"info",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"mock_logger",
".",
"info",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"2",
"]",
"==",
"\"1234\""
] | [
337,
0
] | [
360,
61
] | python | en | ['en', 'de', 'en'] | True |
test_lock_clear_usercode_service | (hass, mock_openzwave) | Test the zwave lock clear_usercode service. | Test the zwave lock clear_usercode service. | async def test_lock_clear_usercode_service(hass, mock_openzwave):
"""Test the zwave lock clear_usercode service."""
mock_network = hass.data[const.DATA_NETWORK] = MagicMock()
node = MockNode(node_id=12)
value0 = MockValue(data=None, node=node, index=0)
value1 = MockValue(data="123", node=node, index=1)
node.get_values.return_value = {value0.value_id: value0, value1.value_id: value1}
mock_network.nodes = {node.node_id: node}
await setup_ozw(hass, mock_openzwave)
await hass.async_block_till_done()
await hass.services.async_call(
lock.DOMAIN,
lock.SERVICE_CLEAR_USERCODE,
{const.ATTR_NODE_ID: node.node_id, lock.ATTR_CODE_SLOT: 1},
)
await hass.async_block_till_done()
assert value1.data == "\0\0\0" | [
"async",
"def",
"test_lock_clear_usercode_service",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_network",
"=",
"hass",
".",
"data",
"[",
"const",
".",
"DATA_NETWORK",
"]",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"MockNode",
"(",
"node_id",
"=",
"12",
")",
"value0",
"=",
"MockValue",
"(",
"data",
"=",
"None",
",",
"node",
"=",
"node",
",",
"index",
"=",
"0",
")",
"value1",
"=",
"MockValue",
"(",
"data",
"=",
"\"123\"",
",",
"node",
"=",
"node",
",",
"index",
"=",
"1",
")",
"node",
".",
"get_values",
".",
"return_value",
"=",
"{",
"value0",
".",
"value_id",
":",
"value0",
",",
"value1",
".",
"value_id",
":",
"value1",
"}",
"mock_network",
".",
"nodes",
"=",
"{",
"node",
".",
"node_id",
":",
"node",
"}",
"await",
"setup_ozw",
"(",
"hass",
",",
"mock_openzwave",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"lock",
".",
"DOMAIN",
",",
"lock",
".",
"SERVICE_CLEAR_USERCODE",
",",
"{",
"const",
".",
"ATTR_NODE_ID",
":",
"node",
".",
"node_id",
",",
"lock",
".",
"ATTR_CODE_SLOT",
":",
"1",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"value1",
".",
"data",
"==",
"\"\\0\\0\\0\""
] | [
363,
0
] | [
384,
34
] | python | en | ['en', 'en', 'en'] | True |
isPalindrome | (s) | This function checks if a string is palindrome or not using recursion
Input: String to be checked
Output: True if it is a palindrome, False if it is not
| This function checks if a string is palindrome or not using recursion
Input: String to be checked
Output: True if it is a palindrome, False if it is not
| def isPalindrome(s):
"""This function checks if a string is palindrome or not using recursion
Input: String to be checked
Output: True if it is a palindrome, False if it is not
"""
if len(s) == 0:
return True
if s[0] != s[len(s)-1]:
return False
return isPalindrome(s[1:-1]) | [
"def",
"isPalindrome",
"(",
"s",
")",
":",
"if",
"len",
"(",
"s",
")",
"==",
"0",
":",
"return",
"True",
"if",
"s",
"[",
"0",
"]",
"!=",
"s",
"[",
"len",
"(",
"s",
")",
"-",
"1",
"]",
":",
"return",
"False",
"return",
"isPalindrome",
"(",
"s",
"[",
"1",
":",
"-",
"1",
"]",
")"
] | [
3,
0
] | [
13,
32
] | python | en | ['en', 'en', 'en'] | True |
AbstractPermissions._entity_func | (self) | Return a function that can test entity access. | Return a function that can test entity access. | def _entity_func(self) -> Callable[[str, str], bool]:
"""Return a function that can test entity access."""
raise NotImplementedError | [
"def",
"_entity_func",
"(",
"self",
")",
"->",
"Callable",
"[",
"[",
"str",
",",
"str",
"]",
",",
"bool",
"]",
":",
"raise",
"NotImplementedError"
] | [
23,
4
] | [
25,
33
] | python | en | ['en', 'en', 'en'] | True |
AbstractPermissions.access_all_entities | (self, key: str) | Check if we have a certain access to all entities. | Check if we have a certain access to all entities. | def access_all_entities(self, key: str) -> bool:
"""Check if we have a certain access to all entities."""
raise NotImplementedError | [
"def",
"access_all_entities",
"(",
"self",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"raise",
"NotImplementedError"
] | [
27,
4
] | [
29,
33
] | python | en | ['en', 'en', 'en'] | True |
AbstractPermissions.check_entity | (self, entity_id: str, key: str) | Check if we can access entity. | Check if we can access entity. | def check_entity(self, entity_id: str, key: str) -> bool:
"""Check if we can access entity."""
entity_func = self._cached_entity_func
if entity_func is None:
entity_func = self._cached_entity_func = self._entity_func()
return entity_func(entity_id, key) | [
"def",
"check_entity",
"(",
"self",
",",
"entity_id",
":",
"str",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"entity_func",
"=",
"self",
".",
"_cached_entity_func",
"if",
"entity_func",
"is",
"None",
":",
"entity_func",
"=",
"self",
".",
"_cached_entity_func",
"=",
"self",
".",
"_entity_func",
"(",
")",
"return",
"entity_func",
"(",
"entity_id",
",",
"key",
")"
] | [
31,
4
] | [
38,
42
] | python | en | ['en', 'en', 'en'] | True |
PolicyPermissions.__init__ | (self, policy: PolicyType, perm_lookup: PermissionLookup) | Initialize the permission class. | Initialize the permission class. | def __init__(self, policy: PolicyType, perm_lookup: PermissionLookup) -> None:
"""Initialize the permission class."""
self._policy = policy
self._perm_lookup = perm_lookup | [
"def",
"__init__",
"(",
"self",
",",
"policy",
":",
"PolicyType",
",",
"perm_lookup",
":",
"PermissionLookup",
")",
"->",
"None",
":",
"self",
".",
"_policy",
"=",
"policy",
"self",
".",
"_perm_lookup",
"=",
"perm_lookup"
] | [
44,
4
] | [
47,
39
] | python | en | ['en', 'en', 'en'] | True |
PolicyPermissions.access_all_entities | (self, key: str) | Check if we have a certain access to all entities. | Check if we have a certain access to all entities. | def access_all_entities(self, key: str) -> bool:
"""Check if we have a certain access to all entities."""
return test_all(self._policy.get(CAT_ENTITIES), key) | [
"def",
"access_all_entities",
"(",
"self",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"return",
"test_all",
"(",
"self",
".",
"_policy",
".",
"get",
"(",
"CAT_ENTITIES",
")",
",",
"key",
")"
] | [
49,
4
] | [
51,
60
] | python | en | ['en', 'en', 'en'] | True |
PolicyPermissions._entity_func | (self) | Return a function that can test entity access. | Return a function that can test entity access. | def _entity_func(self) -> Callable[[str, str], bool]:
"""Return a function that can test entity access."""
return compile_entities(self._policy.get(CAT_ENTITIES), self._perm_lookup) | [
"def",
"_entity_func",
"(",
"self",
")",
"->",
"Callable",
"[",
"[",
"str",
",",
"str",
"]",
",",
"bool",
"]",
":",
"return",
"compile_entities",
"(",
"self",
".",
"_policy",
".",
"get",
"(",
"CAT_ENTITIES",
")",
",",
"self",
".",
"_perm_lookup",
")"
] | [
53,
4
] | [
55,
82
] | python | en | ['en', 'en', 'en'] | True |
PolicyPermissions.__eq__ | (self, other: Any) | Equals check. | Equals check. | def __eq__(self, other: Any) -> bool:
"""Equals check."""
return isinstance(other, PolicyPermissions) and other._policy == self._policy | [
"def",
"__eq__",
"(",
"self",
",",
"other",
":",
"Any",
")",
"->",
"bool",
":",
"return",
"isinstance",
"(",
"other",
",",
"PolicyPermissions",
")",
"and",
"other",
".",
"_policy",
"==",
"self",
".",
"_policy"
] | [
57,
4
] | [
59,
85
] | python | en | ['en', 'en', 'en'] | False |
_OwnerPermissions.access_all_entities | (self, key: str) | Check if we have a certain access to all entities. | Check if we have a certain access to all entities. | def access_all_entities(self, key: str) -> bool:
"""Check if we have a certain access to all entities."""
return True | [
"def",
"access_all_entities",
"(",
"self",
",",
"key",
":",
"str",
")",
"->",
"bool",
":",
"return",
"True"
] | [
65,
4
] | [
67,
19
] | python | en | ['en', 'en', 'en'] | True |
_OwnerPermissions._entity_func | (self) | Return a function that can test entity access. | Return a function that can test entity access. | def _entity_func(self) -> Callable[[str, str], bool]:
"""Return a function that can test entity access."""
return lambda entity_id, key: True | [
"def",
"_entity_func",
"(",
"self",
")",
"->",
"Callable",
"[",
"[",
"str",
",",
"str",
"]",
",",
"bool",
"]",
":",
"return",
"lambda",
"entity_id",
",",
"key",
":",
"True"
] | [
69,
4
] | [
71,
42
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.setup_method | (self, method, mock_pylitejet) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setup_method(self, method, mock_pylitejet):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.start()
self.switch_pressed_callbacks = {}
self.switch_released_callbacks = {}
def get_switch_name(number):
return f"Mock Switch #{number}"
def on_switch_pressed(number, callback):
self.switch_pressed_callbacks[number] = callback
def on_switch_released(number, callback):
self.switch_released_callbacks[number] = callback
self.mock_lj = mock_pylitejet.return_value
self.mock_lj.loads.return_value = range(0)
self.mock_lj.button_switches.return_value = range(1, 3)
self.mock_lj.all_switches.return_value = range(1, 6)
self.mock_lj.scenes.return_value = range(0)
self.mock_lj.get_switch_name.side_effect = get_switch_name
self.mock_lj.on_switch_pressed.side_effect = on_switch_pressed
self.mock_lj.on_switch_released.side_effect = on_switch_released
config = {"litejet": {"port": "/dev/serial/by-id/mock-litejet"}}
if method == self.test_include_switches_False:
config["litejet"]["include_switches"] = False
elif method != self.test_include_switches_unspecified:
config["litejet"]["include_switches"] = True
assert setup.setup_component(self.hass, litejet.DOMAIN, config)
self.hass.block_till_done() | [
"def",
"setup_method",
"(",
"self",
",",
"method",
",",
"mock_pylitejet",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"hass",
".",
"start",
"(",
")",
"self",
".",
"switch_pressed_callbacks",
"=",
"{",
"}",
"self",
".",
"switch_released_callbacks",
"=",
"{",
"}",
"def",
"get_switch_name",
"(",
"number",
")",
":",
"return",
"f\"Mock Switch #{number}\"",
"def",
"on_switch_pressed",
"(",
"number",
",",
"callback",
")",
":",
"self",
".",
"switch_pressed_callbacks",
"[",
"number",
"]",
"=",
"callback",
"def",
"on_switch_released",
"(",
"number",
",",
"callback",
")",
":",
"self",
".",
"switch_released_callbacks",
"[",
"number",
"]",
"=",
"callback",
"self",
".",
"mock_lj",
"=",
"mock_pylitejet",
".",
"return_value",
"self",
".",
"mock_lj",
".",
"loads",
".",
"return_value",
"=",
"range",
"(",
"0",
")",
"self",
".",
"mock_lj",
".",
"button_switches",
".",
"return_value",
"=",
"range",
"(",
"1",
",",
"3",
")",
"self",
".",
"mock_lj",
".",
"all_switches",
".",
"return_value",
"=",
"range",
"(",
"1",
",",
"6",
")",
"self",
".",
"mock_lj",
".",
"scenes",
".",
"return_value",
"=",
"range",
"(",
"0",
")",
"self",
".",
"mock_lj",
".",
"get_switch_name",
".",
"side_effect",
"=",
"get_switch_name",
"self",
".",
"mock_lj",
".",
"on_switch_pressed",
".",
"side_effect",
"=",
"on_switch_pressed",
"self",
".",
"mock_lj",
".",
"on_switch_released",
".",
"side_effect",
"=",
"on_switch_released",
"config",
"=",
"{",
"\"litejet\"",
":",
"{",
"\"port\"",
":",
"\"/dev/serial/by-id/mock-litejet\"",
"}",
"}",
"if",
"method",
"==",
"self",
".",
"test_include_switches_False",
":",
"config",
"[",
"\"litejet\"",
"]",
"[",
"\"include_switches\"",
"]",
"=",
"False",
"elif",
"method",
"!=",
"self",
".",
"test_include_switches_unspecified",
":",
"config",
"[",
"\"litejet\"",
"]",
"[",
"\"include_switches\"",
"]",
"=",
"True",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"litejet",
".",
"DOMAIN",
",",
"config",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")"
] | [
24,
4
] | [
57,
35
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.teardown_method | (self, method) | Stop everything that was started. | Stop everything that was started. | def teardown_method(self, method):
"""Stop everything that was started."""
self.hass.stop() | [
"def",
"teardown_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"hass",
".",
"stop",
"(",
")"
] | [
59,
4
] | [
61,
24
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.switch | (self) | Return the switch state. | Return the switch state. | def switch(self):
"""Return the switch state."""
return self.hass.states.get(ENTITY_SWITCH) | [
"def",
"switch",
"(",
"self",
")",
":",
"return",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_SWITCH",
")"
] | [
63,
4
] | [
65,
50
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.other_switch | (self) | Return the other switch state. | Return the other switch state. | def other_switch(self):
"""Return the other switch state."""
return self.hass.states.get(ENTITY_OTHER_SWITCH) | [
"def",
"other_switch",
"(",
"self",
")",
":",
"return",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"ENTITY_OTHER_SWITCH",
")"
] | [
67,
4
] | [
69,
56
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.test_include_switches_unspecified | (self) | Test that switches are ignored by default. | Test that switches are ignored by default. | def test_include_switches_unspecified(self):
"""Test that switches are ignored by default."""
self.mock_lj.button_switches.assert_not_called()
self.mock_lj.all_switches.assert_not_called() | [
"def",
"test_include_switches_unspecified",
"(",
"self",
")",
":",
"self",
".",
"mock_lj",
".",
"button_switches",
".",
"assert_not_called",
"(",
")",
"self",
".",
"mock_lj",
".",
"all_switches",
".",
"assert_not_called",
"(",
")"
] | [
71,
4
] | [
74,
53
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.test_include_switches_False | (self) | Test that switches can be explicitly ignored. | Test that switches can be explicitly ignored. | def test_include_switches_False(self):
"""Test that switches can be explicitly ignored."""
self.mock_lj.button_switches.assert_not_called()
self.mock_lj.all_switches.assert_not_called() | [
"def",
"test_include_switches_False",
"(",
"self",
")",
":",
"self",
".",
"mock_lj",
".",
"button_switches",
".",
"assert_not_called",
"(",
")",
"self",
".",
"mock_lj",
".",
"all_switches",
".",
"assert_not_called",
"(",
")"
] | [
76,
4
] | [
79,
53
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.test_on_off | (self) | Test turning the switch on and off. | Test turning the switch on and off. | def test_on_off(self):
"""Test turning the switch on and off."""
assert self.switch().state == "off"
assert self.other_switch().state == "off"
assert not switch.is_on(self.hass, ENTITY_SWITCH)
common.turn_on(self.hass, ENTITY_SWITCH)
self.hass.block_till_done()
self.mock_lj.press_switch.assert_called_with(ENTITY_SWITCH_NUMBER)
common.turn_off(self.hass, ENTITY_SWITCH)
self.hass.block_till_done()
self.mock_lj.release_switch.assert_called_with(ENTITY_SWITCH_NUMBER) | [
"def",
"test_on_off",
"(",
"self",
")",
":",
"assert",
"self",
".",
"switch",
"(",
")",
".",
"state",
"==",
"\"off\"",
"assert",
"self",
".",
"other_switch",
"(",
")",
".",
"state",
"==",
"\"off\"",
"assert",
"not",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"common",
".",
"turn_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"self",
".",
"mock_lj",
".",
"press_switch",
".",
"assert_called_with",
"(",
"ENTITY_SWITCH_NUMBER",
")",
"common",
".",
"turn_off",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"self",
".",
"mock_lj",
".",
"release_switch",
".",
"assert_called_with",
"(",
"ENTITY_SWITCH_NUMBER",
")"
] | [
81,
4
] | [
94,
76
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.test_pressed_event | (self) | Test handling an event from LiteJet. | Test handling an event from LiteJet. | def test_pressed_event(self):
"""Test handling an event from LiteJet."""
# Switch 1
_LOGGER.info(self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER])
self.switch_pressed_callbacks[ENTITY_SWITCH_NUMBER]()
self.hass.block_till_done()
assert switch.is_on(self.hass, ENTITY_SWITCH)
assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH)
assert self.switch().state == "on"
assert self.other_switch().state == "off"
# Switch 2
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
self.hass.block_till_done()
assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH)
assert switch.is_on(self.hass, ENTITY_SWITCH)
assert self.other_switch().state == "on"
assert self.switch().state == "on" | [
"def",
"test_pressed_event",
"(",
"self",
")",
":",
"# Switch 1",
"_LOGGER",
".",
"info",
"(",
"self",
".",
"switch_pressed_callbacks",
"[",
"ENTITY_SWITCH_NUMBER",
"]",
")",
"self",
".",
"switch_pressed_callbacks",
"[",
"ENTITY_SWITCH_NUMBER",
"]",
"(",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"assert",
"not",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_OTHER_SWITCH",
")",
"assert",
"self",
".",
"switch",
"(",
")",
".",
"state",
"==",
"\"on\"",
"assert",
"self",
".",
"other_switch",
"(",
")",
".",
"state",
"==",
"\"off\"",
"# Switch 2",
"self",
".",
"switch_pressed_callbacks",
"[",
"ENTITY_OTHER_SWITCH_NUMBER",
"]",
"(",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_OTHER_SWITCH",
")",
"assert",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"assert",
"self",
".",
"other_switch",
"(",
")",
".",
"state",
"==",
"\"on\"",
"assert",
"self",
".",
"switch",
"(",
")",
".",
"state",
"==",
"\"on\""
] | [
96,
4
] | [
115,
42
] | python | en | ['en', 'en', 'en'] | True |
TestLiteJetSwitch.test_released_event | (self) | Test handling an event from LiteJet. | Test handling an event from LiteJet. | def test_released_event(self):
"""Test handling an event from LiteJet."""
# Initial state is on.
self.switch_pressed_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
self.hass.block_till_done()
assert switch.is_on(self.hass, ENTITY_OTHER_SWITCH)
# Event indicates it is off now.
self.switch_released_callbacks[ENTITY_OTHER_SWITCH_NUMBER]()
self.hass.block_till_done()
assert not switch.is_on(self.hass, ENTITY_OTHER_SWITCH)
assert not switch.is_on(self.hass, ENTITY_SWITCH)
assert self.other_switch().state == "off"
assert self.switch().state == "off" | [
"def",
"test_released_event",
"(",
"self",
")",
":",
"# Initial state is on.",
"self",
".",
"switch_pressed_callbacks",
"[",
"ENTITY_OTHER_SWITCH_NUMBER",
"]",
"(",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_OTHER_SWITCH",
")",
"# Event indicates it is off now.",
"self",
".",
"switch_released_callbacks",
"[",
"ENTITY_OTHER_SWITCH_NUMBER",
"]",
"(",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"not",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_OTHER_SWITCH",
")",
"assert",
"not",
"switch",
".",
"is_on",
"(",
"self",
".",
"hass",
",",
"ENTITY_SWITCH",
")",
"assert",
"self",
".",
"other_switch",
"(",
")",
".",
"state",
"==",
"\"off\"",
"assert",
"self",
".",
"switch",
"(",
")",
".",
"state",
"==",
"\"off\""
] | [
117,
4
] | [
133,
43
] | python | en | ['en', 'en', 'en'] | True |
test_show_config_form | (hass: HomeAssistantType) | Test if initial configuration form is shown. | Test if initial configuration form is shown. | async def test_show_config_form(hass: HomeAssistantType) -> None:
"""Test if initial configuration form is shown."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}
)
assert result["type"] == RESULT_TYPE_FORM
assert result["step_id"] == "user" | [
"async",
"def",
"test_show_config_form",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"step_id\"",
"]",
"==",
"\"user\""
] | [
82,
0
] | [
89,
38
] | python | en | ['en', 'en', 'en'] | True |
test_invalid_ip | (hass: HomeAssistantType) | Test error in case of an invalid IP address. | Test error in case of an invalid IP address. | async def test_invalid_ip(hass: HomeAssistantType) -> None:
"""Test error in case of an invalid IP address."""
with patch("getmac.get_mac_address", return_value=None):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_IPV4
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {"base": "invalid_ip"} | [
"async",
"def",
"test_invalid_ip",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"getmac.get_mac_address\"",
",",
"return_value",
"=",
"None",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_IPV4",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"invalid_ip\"",
"}"
] | [
92,
0
] | [
100,
57
] | python | en | ['en', 'en', 'en'] | True |
test_same_host | (hass: HomeAssistantType) | Test abort in case of same host name. | Test abort in case of same host name. | async def test_same_host(hass: HomeAssistantType) -> None:
"""Test abort in case of same host name."""
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
with patch(
"mcstatus.server.MinecraftServer.status",
return_value=PingResponse(STATUS_RESPONSE_RAW),
):
unique_id = "mc.dummyserver.com-25565"
config_data = {
CONF_NAME: DEFAULT_NAME,
CONF_HOST: "mc.dummyserver.com",
CONF_PORT: DEFAULT_PORT,
}
mock_config_entry = MockConfigEntry(
domain=DOMAIN, unique_id=unique_id, data=config_data
)
mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT
)
assert result["type"] == RESULT_TYPE_ABORT
assert result["reason"] == "already_configured" | [
"async",
"def",
"test_same_host",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"return_value",
"=",
"PingResponse",
"(",
"STATUS_RESPONSE_RAW",
")",
",",
")",
":",
"unique_id",
"=",
"\"mc.dummyserver.com-25565\"",
"config_data",
"=",
"{",
"CONF_NAME",
":",
"DEFAULT_NAME",
",",
"CONF_HOST",
":",
"\"mc.dummyserver.com\"",
",",
"CONF_PORT",
":",
"DEFAULT_PORT",
",",
"}",
"mock_config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"unique_id",
"=",
"unique_id",
",",
"data",
"=",
"config_data",
")",
"mock_config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_ABORT",
"assert",
"result",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\""
] | [
103,
0
] | [
129,
59
] | python | en | ['en', 'en', 'en'] | True |
test_port_too_small | (hass: HomeAssistantType) | Test error in case of a too small port. | Test error in case of a too small port. | async def test_port_too_small(hass: HomeAssistantType) -> None:
"""Test error in case of a too small port."""
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_PORT_TOO_SMALL
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {"base": "invalid_port"} | [
"async",
"def",
"test_port_too_small",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_PORT_TOO_SMALL",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"invalid_port\"",
"}"
] | [
132,
0
] | [
143,
59
] | python | en | ['en', 'en', 'en'] | True |
test_port_too_large | (hass: HomeAssistantType) | Test error in case of a too large port. | Test error in case of a too large port. | async def test_port_too_large(hass: HomeAssistantType) -> None:
"""Test error in case of a too large port."""
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_PORT_TOO_LARGE
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {"base": "invalid_port"} | [
"async",
"def",
"test_port_too_large",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_PORT_TOO_LARGE",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"invalid_port\"",
"}"
] | [
146,
0
] | [
157,
59
] | python | en | ['en', 'en', 'en'] | True |
test_connection_failed | (hass: HomeAssistantType) | Test error in case of a failed connection. | Test error in case of a failed connection. | async def test_connection_failed(hass: HomeAssistantType) -> None:
"""Test error in case of a failed connection."""
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
with patch("mcstatus.server.MinecraftServer.status", side_effect=OSError):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT
)
assert result["type"] == RESULT_TYPE_FORM
assert result["errors"] == {"base": "cannot_connect"} | [
"async",
"def",
"test_connection_failed",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"side_effect",
"=",
"OSError",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_FORM",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"\"base\"",
":",
"\"cannot_connect\"",
"}"
] | [
160,
0
] | [
172,
65
] | python | en | ['en', 'en', 'en'] | True |
test_connection_succeeded_with_srv_record | (hass: HomeAssistantType) | Test config entry in case of a successful connection with a SRV record. | Test config entry in case of a successful connection with a SRV record. | async def test_connection_succeeded_with_srv_record(hass: HomeAssistantType) -> None:
"""Test config entry in case of a successful connection with a SRV record."""
with patch(
"aiodns.DNSResolver.query",
return_value=SRV_RECORDS,
):
with patch(
"mcstatus.server.MinecraftServer.status",
return_value=PingResponse(STATUS_RESPONSE_RAW),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_SRV
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == USER_INPUT_SRV[CONF_HOST]
assert result["data"][CONF_NAME] == USER_INPUT_SRV[CONF_NAME]
assert result["data"][CONF_HOST] == USER_INPUT_SRV[CONF_HOST] | [
"async",
"def",
"test_connection_succeeded_with_srv_record",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"return_value",
"=",
"SRV_RECORDS",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"return_value",
"=",
"PingResponse",
"(",
"STATUS_RESPONSE_RAW",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_SRV",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"USER_INPUT_SRV",
"[",
"CONF_HOST",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_NAME",
"]",
"==",
"USER_INPUT_SRV",
"[",
"CONF_NAME",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"USER_INPUT_SRV",
"[",
"CONF_HOST",
"]"
] | [
175,
0
] | [
192,
73
] | python | en | ['en', 'en', 'en'] | True |
test_connection_succeeded_with_host | (hass: HomeAssistantType) | Test config entry in case of a successful connection with a host name. | Test config entry in case of a successful connection with a host name. | async def test_connection_succeeded_with_host(hass: HomeAssistantType) -> None:
"""Test config entry in case of a successful connection with a host name."""
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
with patch(
"mcstatus.server.MinecraftServer.status",
return_value=PingResponse(STATUS_RESPONSE_RAW),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == USER_INPUT[CONF_HOST]
assert result["data"][CONF_NAME] == USER_INPUT[CONF_NAME]
assert result["data"][CONF_HOST] == "mc.dummyserver.com" | [
"async",
"def",
"test_connection_succeeded_with_host",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"return_value",
"=",
"PingResponse",
"(",
"STATUS_RESPONSE_RAW",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"USER_INPUT",
"[",
"CONF_HOST",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_NAME",
"]",
"==",
"USER_INPUT",
"[",
"CONF_NAME",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"mc.dummyserver.com\""
] | [
195,
0
] | [
212,
68
] | python | en | ['en', 'en', 'en'] | True |
test_connection_succeeded_with_ip4 | (hass: HomeAssistantType) | Test config entry in case of a successful connection with an IPv4 address. | Test config entry in case of a successful connection with an IPv4 address. | async def test_connection_succeeded_with_ip4(hass: HomeAssistantType) -> None:
"""Test config entry in case of a successful connection with an IPv4 address."""
with patch("getmac.get_mac_address", return_value="01:23:45:67:89:ab"):
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
with patch(
"mcstatus.server.MinecraftServer.status",
return_value=PingResponse(STATUS_RESPONSE_RAW),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_IPV4
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == USER_INPUT_IPV4[CONF_HOST]
assert result["data"][CONF_NAME] == USER_INPUT_IPV4[CONF_NAME]
assert result["data"][CONF_HOST] == "1.1.1.1" | [
"async",
"def",
"test_connection_succeeded_with_ip4",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"getmac.get_mac_address\"",
",",
"return_value",
"=",
"\"01:23:45:67:89:ab\"",
")",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"return_value",
"=",
"PingResponse",
"(",
"STATUS_RESPONSE_RAW",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_IPV4",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"USER_INPUT_IPV4",
"[",
"CONF_HOST",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_NAME",
"]",
"==",
"USER_INPUT_IPV4",
"[",
"CONF_NAME",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"1.1.1.1\""
] | [
215,
0
] | [
233,
61
] | python | en | ['en', 'en', 'en'] | True |
test_connection_succeeded_with_ip6 | (hass: HomeAssistantType) | Test config entry in case of a successful connection with an IPv6 address. | Test config entry in case of a successful connection with an IPv6 address. | async def test_connection_succeeded_with_ip6(hass: HomeAssistantType) -> None:
"""Test config entry in case of a successful connection with an IPv6 address."""
with patch("getmac.get_mac_address", return_value="01:23:45:67:89:ab"):
with patch(
"aiodns.DNSResolver.query",
side_effect=aiodns.error.DNSError,
):
with patch(
"mcstatus.server.MinecraftServer.status",
return_value=PingResponse(STATUS_RESPONSE_RAW),
):
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER}, data=USER_INPUT_IPV6
)
assert result["type"] == RESULT_TYPE_CREATE_ENTRY
assert result["title"] == USER_INPUT_IPV6[CONF_HOST]
assert result["data"][CONF_NAME] == USER_INPUT_IPV6[CONF_NAME]
assert result["data"][CONF_HOST] == "::ffff:0101:0101" | [
"async",
"def",
"test_connection_succeeded_with_ip6",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"None",
":",
"with",
"patch",
"(",
"\"getmac.get_mac_address\"",
",",
"return_value",
"=",
"\"01:23:45:67:89:ab\"",
")",
":",
"with",
"patch",
"(",
"\"aiodns.DNSResolver.query\"",
",",
"side_effect",
"=",
"aiodns",
".",
"error",
".",
"DNSError",
",",
")",
":",
"with",
"patch",
"(",
"\"mcstatus.server.MinecraftServer.status\"",
",",
"return_value",
"=",
"PingResponse",
"(",
"STATUS_RESPONSE_RAW",
")",
",",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"SOURCE_USER",
"}",
",",
"data",
"=",
"USER_INPUT_IPV6",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"RESULT_TYPE_CREATE_ENTRY",
"assert",
"result",
"[",
"\"title\"",
"]",
"==",
"USER_INPUT_IPV6",
"[",
"CONF_HOST",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_NAME",
"]",
"==",
"USER_INPUT_IPV6",
"[",
"CONF_NAME",
"]",
"assert",
"result",
"[",
"\"data\"",
"]",
"[",
"CONF_HOST",
"]",
"==",
"\"::ffff:0101:0101\""
] | [
236,
0
] | [
254,
70
] | python | en | ['en', 'en', 'en'] | True |
QueryMock.__init__ | (self) | Set up query result mock. | Set up query result mock. | def __init__(self):
"""Set up query result mock."""
self.host = "mc.dummyserver.com"
self.port = 23456
self.priority = 1
self.weight = 1
self.ttl = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"host",
"=",
"\"mc.dummyserver.com\"",
"self",
".",
"port",
"=",
"23456",
"self",
".",
"priority",
"=",
"1",
"self",
".",
"weight",
"=",
"1",
"self",
".",
"ttl",
"=",
"None"
] | [
28,
4
] | [
34,
23
] | python | en | ['en', 'en', 'en'] | True |
request_configuration | (hass, config, url, add_entities_callback) | Request configuration steps from the user. | Request configuration steps from the user. | def request_configuration(hass, config, url, add_entities_callback):
"""Request configuration steps from the user."""
configurator = hass.components.configurator
if "gpmdp" in _CONFIGURING:
configurator.notify_errors(
_CONFIGURING["gpmdp"], "Failed to register, please try again."
)
return
websocket = create_connection((url), timeout=1)
websocket.send(
json.dumps(
{
"namespace": "connect",
"method": "connect",
"arguments": ["Home Assistant"],
}
)
)
def gpmdp_configuration_callback(callback_data):
"""Handle configuration changes."""
while True:
try:
msg = json.loads(websocket.recv())
except _exceptions.WebSocketConnectionClosedException:
continue
if msg["channel"] != "connect":
continue
if msg["payload"] != "CODE_REQUIRED":
continue
pin = callback_data.get("pin")
websocket.send(
json.dumps(
{
"namespace": "connect",
"method": "connect",
"arguments": ["Home Assistant", pin],
}
)
)
tmpmsg = json.loads(websocket.recv())
if tmpmsg["channel"] == "time":
_LOGGER.error(
"Error setting up GPMDP. Please pause "
"the desktop player and try again"
)
break
code = tmpmsg["payload"]
if code == "CODE_REQUIRED":
continue
setup_gpmdp(hass, config, code, add_entities_callback)
save_json(hass.config.path(GPMDP_CONFIG_FILE), {"CODE": code})
websocket.send(
json.dumps(
{
"namespace": "connect",
"method": "connect",
"arguments": ["Home Assistant", code],
}
)
)
websocket.close()
break
_CONFIGURING["gpmdp"] = configurator.request_config(
DEFAULT_NAME,
gpmdp_configuration_callback,
description=(
"Enter the pin that is displayed in the "
"Google Play Music Desktop Player."
),
submit_caption="Submit",
fields=[{"id": "pin", "name": "Pin Code", "type": "number"}],
) | [
"def",
"request_configuration",
"(",
"hass",
",",
"config",
",",
"url",
",",
"add_entities_callback",
")",
":",
"configurator",
"=",
"hass",
".",
"components",
".",
"configurator",
"if",
"\"gpmdp\"",
"in",
"_CONFIGURING",
":",
"configurator",
".",
"notify_errors",
"(",
"_CONFIGURING",
"[",
"\"gpmdp\"",
"]",
",",
"\"Failed to register, please try again.\"",
")",
"return",
"websocket",
"=",
"create_connection",
"(",
"(",
"url",
")",
",",
"timeout",
"=",
"1",
")",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"{",
"\"namespace\"",
":",
"\"connect\"",
",",
"\"method\"",
":",
"\"connect\"",
",",
"\"arguments\"",
":",
"[",
"\"Home Assistant\"",
"]",
",",
"}",
")",
")",
"def",
"gpmdp_configuration_callback",
"(",
"callback_data",
")",
":",
"\"\"\"Handle configuration changes.\"\"\"",
"while",
"True",
":",
"try",
":",
"msg",
"=",
"json",
".",
"loads",
"(",
"websocket",
".",
"recv",
"(",
")",
")",
"except",
"_exceptions",
".",
"WebSocketConnectionClosedException",
":",
"continue",
"if",
"msg",
"[",
"\"channel\"",
"]",
"!=",
"\"connect\"",
":",
"continue",
"if",
"msg",
"[",
"\"payload\"",
"]",
"!=",
"\"CODE_REQUIRED\"",
":",
"continue",
"pin",
"=",
"callback_data",
".",
"get",
"(",
"\"pin\"",
")",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"{",
"\"namespace\"",
":",
"\"connect\"",
",",
"\"method\"",
":",
"\"connect\"",
",",
"\"arguments\"",
":",
"[",
"\"Home Assistant\"",
",",
"pin",
"]",
",",
"}",
")",
")",
"tmpmsg",
"=",
"json",
".",
"loads",
"(",
"websocket",
".",
"recv",
"(",
")",
")",
"if",
"tmpmsg",
"[",
"\"channel\"",
"]",
"==",
"\"time\"",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error setting up GPMDP. Please pause \"",
"\"the desktop player and try again\"",
")",
"break",
"code",
"=",
"tmpmsg",
"[",
"\"payload\"",
"]",
"if",
"code",
"==",
"\"CODE_REQUIRED\"",
":",
"continue",
"setup_gpmdp",
"(",
"hass",
",",
"config",
",",
"code",
",",
"add_entities_callback",
")",
"save_json",
"(",
"hass",
".",
"config",
".",
"path",
"(",
"GPMDP_CONFIG_FILE",
")",
",",
"{",
"\"CODE\"",
":",
"code",
"}",
")",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"{",
"\"namespace\"",
":",
"\"connect\"",
",",
"\"method\"",
":",
"\"connect\"",
",",
"\"arguments\"",
":",
"[",
"\"Home Assistant\"",
",",
"code",
"]",
",",
"}",
")",
")",
"websocket",
".",
"close",
"(",
")",
"break",
"_CONFIGURING",
"[",
"\"gpmdp\"",
"]",
"=",
"configurator",
".",
"request_config",
"(",
"DEFAULT_NAME",
",",
"gpmdp_configuration_callback",
",",
"description",
"=",
"(",
"\"Enter the pin that is displayed in the \"",
"\"Google Play Music Desktop Player.\"",
")",
",",
"submit_caption",
"=",
"\"Submit\"",
",",
"fields",
"=",
"[",
"{",
"\"id\"",
":",
"\"pin\"",
",",
"\"name\"",
":",
"\"Pin Code\"",
",",
"\"type\"",
":",
"\"number\"",
"}",
"]",
",",
")"
] | [
59,
0
] | [
134,
5
] | python | en | ['en', 'en', 'en'] | True |
setup_gpmdp | (hass, config, code, add_entities) | Set up gpmdp. | Set up gpmdp. | def setup_gpmdp(hass, config, code, add_entities):
"""Set up gpmdp."""
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
url = f"ws://{host}:{port}"
if not code:
request_configuration(hass, config, url, add_entities)
return
if "gpmdp" in _CONFIGURING:
configurator = hass.components.configurator
configurator.request_done(_CONFIGURING.pop("gpmdp"))
add_entities([GPMDP(name, url, code)], True) | [
"def",
"setup_gpmdp",
"(",
"hass",
",",
"config",
",",
"code",
",",
"add_entities",
")",
":",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"port",
"=",
"config",
".",
"get",
"(",
"CONF_PORT",
")",
"url",
"=",
"f\"ws://{host}:{port}\"",
"if",
"not",
"code",
":",
"request_configuration",
"(",
"hass",
",",
"config",
",",
"url",
",",
"add_entities",
")",
"return",
"if",
"\"gpmdp\"",
"in",
"_CONFIGURING",
":",
"configurator",
"=",
"hass",
".",
"components",
".",
"configurator",
"configurator",
".",
"request_done",
"(",
"_CONFIGURING",
".",
"pop",
"(",
"\"gpmdp\"",
")",
")",
"add_entities",
"(",
"[",
"GPMDP",
"(",
"name",
",",
"url",
",",
"code",
")",
"]",
",",
"True",
")"
] | [
137,
0
] | [
152,
48
] | python | en | ['en', 'ky', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the GPMDP platform. | Set up the GPMDP platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the GPMDP platform."""
codeconfig = load_json(hass.config.path(GPMDP_CONFIG_FILE))
if codeconfig:
code = codeconfig.get("CODE")
elif discovery_info is not None:
if "gpmdp" in _CONFIGURING:
return
code = None
else:
code = None
setup_gpmdp(hass, config, code, add_entities) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"codeconfig",
"=",
"load_json",
"(",
"hass",
".",
"config",
".",
"path",
"(",
"GPMDP_CONFIG_FILE",
")",
")",
"if",
"codeconfig",
":",
"code",
"=",
"codeconfig",
".",
"get",
"(",
"\"CODE\"",
")",
"elif",
"discovery_info",
"is",
"not",
"None",
":",
"if",
"\"gpmdp\"",
"in",
"_CONFIGURING",
":",
"return",
"code",
"=",
"None",
"else",
":",
"code",
"=",
"None",
"setup_gpmdp",
"(",
"hass",
",",
"config",
",",
"code",
",",
"add_entities",
")"
] | [
155,
0
] | [
166,
49
] | python | en | ['en', 'lv', 'en'] | True |
GPMDP.__init__ | (self, name, url, code) | Initialize the media player. | Initialize the media player. | def __init__(self, name, url, code):
"""Initialize the media player."""
self._connection = create_connection
self._url = url
self._authorization_code = code
self._name = name
self._status = STATE_OFF
self._ws = None
self._title = None
self._artist = None
self._albumart = None
self._seek_position = None
self._duration = None
self._volume = None
self._request_id = 0
self._available = True | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"url",
",",
"code",
")",
":",
"self",
".",
"_connection",
"=",
"create_connection",
"self",
".",
"_url",
"=",
"url",
"self",
".",
"_authorization_code",
"=",
"code",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_status",
"=",
"STATE_OFF",
"self",
".",
"_ws",
"=",
"None",
"self",
".",
"_title",
"=",
"None",
"self",
".",
"_artist",
"=",
"None",
"self",
".",
"_albumart",
"=",
"None",
"self",
".",
"_seek_position",
"=",
"None",
"self",
".",
"_duration",
"=",
"None",
"self",
".",
"_volume",
"=",
"None",
"self",
".",
"_request_id",
"=",
"0",
"self",
".",
"_available",
"=",
"True"
] | [
172,
4
] | [
188,
30
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.get_ws | (self) | Check if the websocket is setup and connected. | Check if the websocket is setup and connected. | def get_ws(self):
"""Check if the websocket is setup and connected."""
if self._ws is None:
try:
self._ws = self._connection((self._url), timeout=1)
msg = json.dumps(
{
"namespace": "connect",
"method": "connect",
"arguments": ["Home Assistant", self._authorization_code],
}
)
self._ws.send(msg)
except (socket.timeout, ConnectionRefusedError, ConnectionResetError):
self._ws = None
return self._ws | [
"def",
"get_ws",
"(",
"self",
")",
":",
"if",
"self",
".",
"_ws",
"is",
"None",
":",
"try",
":",
"self",
".",
"_ws",
"=",
"self",
".",
"_connection",
"(",
"(",
"self",
".",
"_url",
")",
",",
"timeout",
"=",
"1",
")",
"msg",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"namespace\"",
":",
"\"connect\"",
",",
"\"method\"",
":",
"\"connect\"",
",",
"\"arguments\"",
":",
"[",
"\"Home Assistant\"",
",",
"self",
".",
"_authorization_code",
"]",
",",
"}",
")",
"self",
".",
"_ws",
".",
"send",
"(",
"msg",
")",
"except",
"(",
"socket",
".",
"timeout",
",",
"ConnectionRefusedError",
",",
"ConnectionResetError",
")",
":",
"self",
".",
"_ws",
"=",
"None",
"return",
"self",
".",
"_ws"
] | [
190,
4
] | [
205,
23
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.send_gpmdp_msg | (self, namespace, method, with_id=True) | Send ws messages to GPMDP and verify request id in response. | Send ws messages to GPMDP and verify request id in response. | def send_gpmdp_msg(self, namespace, method, with_id=True):
"""Send ws messages to GPMDP and verify request id in response."""
try:
websocket = self.get_ws()
if websocket is None:
self._status = STATE_OFF
return
self._request_id += 1
websocket.send(
json.dumps(
{
"namespace": namespace,
"method": method,
"requestID": self._request_id,
}
)
)
if not with_id:
return
while True:
msg = json.loads(websocket.recv())
if "requestID" in msg:
if msg["requestID"] == self._request_id:
return msg
except (
ConnectionRefusedError,
ConnectionResetError,
_exceptions.WebSocketTimeoutException,
_exceptions.WebSocketProtocolException,
_exceptions.WebSocketPayloadException,
_exceptions.WebSocketConnectionClosedException,
):
self._ws = None | [
"def",
"send_gpmdp_msg",
"(",
"self",
",",
"namespace",
",",
"method",
",",
"with_id",
"=",
"True",
")",
":",
"try",
":",
"websocket",
"=",
"self",
".",
"get_ws",
"(",
")",
"if",
"websocket",
"is",
"None",
":",
"self",
".",
"_status",
"=",
"STATE_OFF",
"return",
"self",
".",
"_request_id",
"+=",
"1",
"websocket",
".",
"send",
"(",
"json",
".",
"dumps",
"(",
"{",
"\"namespace\"",
":",
"namespace",
",",
"\"method\"",
":",
"method",
",",
"\"requestID\"",
":",
"self",
".",
"_request_id",
",",
"}",
")",
")",
"if",
"not",
"with_id",
":",
"return",
"while",
"True",
":",
"msg",
"=",
"json",
".",
"loads",
"(",
"websocket",
".",
"recv",
"(",
")",
")",
"if",
"\"requestID\"",
"in",
"msg",
":",
"if",
"msg",
"[",
"\"requestID\"",
"]",
"==",
"self",
".",
"_request_id",
":",
"return",
"msg",
"except",
"(",
"ConnectionRefusedError",
",",
"ConnectionResetError",
",",
"_exceptions",
".",
"WebSocketTimeoutException",
",",
"_exceptions",
".",
"WebSocketProtocolException",
",",
"_exceptions",
".",
"WebSocketPayloadException",
",",
"_exceptions",
".",
"WebSocketConnectionClosedException",
",",
")",
":",
"self",
".",
"_ws",
"=",
"None"
] | [
207,
4
] | [
240,
27
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.update | (self) | Get the latest details from the player. | Get the latest details from the player. | def update(self):
"""Get the latest details from the player."""
time.sleep(1)
try:
self._available = True
playstate = self.send_gpmdp_msg("playback", "getPlaybackState")
if playstate is None:
return
self._status = PLAYBACK_DICT[str(playstate["value"])]
time_data = self.send_gpmdp_msg("playback", "getCurrentTime")
if time_data is not None:
self._seek_position = int(time_data["value"] / 1000)
track_data = self.send_gpmdp_msg("playback", "getCurrentTrack")
if track_data is not None:
self._title = track_data["value"]["title"]
self._artist = track_data["value"]["artist"]
self._albumart = track_data["value"]["albumArt"]
self._duration = int(track_data["value"]["duration"] / 1000)
volume_data = self.send_gpmdp_msg("volume", "getVolume")
if volume_data is not None:
self._volume = volume_data["value"] / 100
except OSError:
self._available = False | [
"def",
"update",
"(",
"self",
")",
":",
"time",
".",
"sleep",
"(",
"1",
")",
"try",
":",
"self",
".",
"_available",
"=",
"True",
"playstate",
"=",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"getPlaybackState\"",
")",
"if",
"playstate",
"is",
"None",
":",
"return",
"self",
".",
"_status",
"=",
"PLAYBACK_DICT",
"[",
"str",
"(",
"playstate",
"[",
"\"value\"",
"]",
")",
"]",
"time_data",
"=",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"getCurrentTime\"",
")",
"if",
"time_data",
"is",
"not",
"None",
":",
"self",
".",
"_seek_position",
"=",
"int",
"(",
"time_data",
"[",
"\"value\"",
"]",
"/",
"1000",
")",
"track_data",
"=",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"getCurrentTrack\"",
")",
"if",
"track_data",
"is",
"not",
"None",
":",
"self",
".",
"_title",
"=",
"track_data",
"[",
"\"value\"",
"]",
"[",
"\"title\"",
"]",
"self",
".",
"_artist",
"=",
"track_data",
"[",
"\"value\"",
"]",
"[",
"\"artist\"",
"]",
"self",
".",
"_albumart",
"=",
"track_data",
"[",
"\"value\"",
"]",
"[",
"\"albumArt\"",
"]",
"self",
".",
"_duration",
"=",
"int",
"(",
"track_data",
"[",
"\"value\"",
"]",
"[",
"\"duration\"",
"]",
"/",
"1000",
")",
"volume_data",
"=",
"self",
".",
"send_gpmdp_msg",
"(",
"\"volume\"",
",",
"\"getVolume\"",
")",
"if",
"volume_data",
"is",
"not",
"None",
":",
"self",
".",
"_volume",
"=",
"volume_data",
"[",
"\"value\"",
"]",
"/",
"100",
"except",
"OSError",
":",
"self",
".",
"_available",
"=",
"False"
] | [
242,
4
] | [
264,
35
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.available | (self) | Return if media player is available. | Return if media player is available. | def available(self):
"""Return if media player is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
267,
4
] | [
269,
30
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_content_type | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_type(self):
"""Content type of current playing media."""
return MEDIA_TYPE_MUSIC | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"return",
"MEDIA_TYPE_MUSIC"
] | [
272,
4
] | [
274,
31
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.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._status | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_status"
] | [
277,
4
] | [
279,
27
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
return self._title | [
"def",
"media_title",
"(",
"self",
")",
":",
"return",
"self",
".",
"_title"
] | [
282,
4
] | [
284,
26
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_artist | (self) | Artist of current playing media (Music track only). | Artist of current playing media (Music track only). | def media_artist(self):
"""Artist of current playing media (Music track only)."""
return self._artist | [
"def",
"media_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"_artist"
] | [
287,
4
] | [
289,
27
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_image_url | (self) | Image url of current playing media. | Image url of current playing media. | def media_image_url(self):
"""Image url of current playing media."""
return self._albumart | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"return",
"self",
".",
"_albumart"
] | [
292,
4
] | [
294,
29
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_seek_position | (self) | Time in seconds of current seek position. | Time in seconds of current seek position. | def media_seek_position(self):
"""Time in seconds of current seek position."""
return self._seek_position | [
"def",
"media_seek_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"_seek_position"
] | [
297,
4
] | [
299,
34
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_duration | (self) | Time in seconds of current song duration. | Time in seconds of current song duration. | def media_duration(self):
"""Time in seconds of current song duration."""
return self._duration | [
"def",
"media_duration",
"(",
"self",
")",
":",
"return",
"self",
".",
"_duration"
] | [
302,
4
] | [
304,
29
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.volume_level | (self) | Volume level of the media player (0..1). | Volume level of the media player (0..1). | def volume_level(self):
"""Volume level of the media player (0..1)."""
return self._volume | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_volume"
] | [
307,
4
] | [
309,
27
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
312,
4
] | [
314,
25
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_GPMDP | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_GPMDP"
] | [
317,
4
] | [
319,
28
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_next_track | (self) | Send media_next command to media player. | Send media_next command to media player. | def media_next_track(self):
"""Send media_next command to media player."""
self.send_gpmdp_msg("playback", "forward", False) | [
"def",
"media_next_track",
"(",
"self",
")",
":",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"forward\"",
",",
"False",
")"
] | [
321,
4
] | [
323,
57
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_previous_track | (self) | Send media_previous command to media player. | Send media_previous command to media player. | def media_previous_track(self):
"""Send media_previous command to media player."""
self.send_gpmdp_msg("playback", "rewind", False) | [
"def",
"media_previous_track",
"(",
"self",
")",
":",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"rewind\"",
",",
"False",
")"
] | [
325,
4
] | [
327,
56
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_play | (self) | Send media_play command to media player. | Send media_play command to media player. | def media_play(self):
"""Send media_play command to media player."""
self.send_gpmdp_msg("playback", "playPause", False)
self._status = STATE_PLAYING
self.schedule_update_ha_state() | [
"def",
"media_play",
"(",
"self",
")",
":",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"playPause\"",
",",
"False",
")",
"self",
".",
"_status",
"=",
"STATE_PLAYING",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
329,
4
] | [
333,
39
] | python | en | ['en', 'en', 'en'] | True |
GPMDP.media_pause | (self) | Send media_pause command to media player. | Send media_pause command to media player. | def media_pause(self):
"""Send media_pause command to media player."""
self.send_gpmdp_msg("playback", "playPause", False)
self._status = STATE_PAUSED
self.schedule_update_ha_state() | [
"def",
"media_pause",
"(",
"self",
")",
":",
"self",
".",
"send_gpmdp_msg",
"(",
"\"playback\"",
",",
"\"playPause\"",
",",
"False",
")",
"self",
".",
"_status",
"=",
"STATE_PAUSED",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
335,
4
] | [
339,
39
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.