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 |
---|---|---|---|---|---|---|---|---|---|---|---|
MinutPointEntity.value | (self) | Return the sensor value. | Return the sensor value. | def value(self):
"""Return the sensor value."""
return self._value | [
"def",
"value",
"(",
"self",
")",
":",
"return",
"self",
".",
"_value"
] | [
345,
4
] | [
347,
26
] | python | en | ['en', 'no', 'en'] | True |
test_set_config_entry_unique_id | (hass, entry, mock_plex_server) | Test updating missing unique_id from config entry. | Test updating missing unique_id from config entry. | async def test_set_config_entry_unique_id(hass, entry, mock_plex_server):
"""Test updating missing unique_id from config entry."""
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED
assert (
hass.config_entries.async_entries(const.DOMAIN)[0].unique_id
== mock_plex_server.machineIdentifier
) | [
"async",
"def",
"test_set_config_entry_unique_id",
"(",
"hass",
",",
"entry",
",",
"mock_plex_server",
")",
":",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"assert",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
"[",
"0",
"]",
".",
"unique_id",
"==",
"mock_plex_server",
".",
"machineIdentifier",
")"
] | [
26,
0
] | [
34,
5
] | python | en | ['en', 'en', 'en'] | True |
test_setup_config_entry_with_error | (hass, entry) | Test setup component from config entry with errors. | Test setup component from config entry with errors. | async def test_setup_config_entry_with_error(hass, entry):
"""Test setup component from config entry with errors."""
with patch(
"homeassistant.components.plex.PlexServer.connect",
side_effect=requests.exceptions.ConnectionError,
):
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id) is False
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert entry.state == ENTRY_STATE_SETUP_RETRY
with patch(
"homeassistant.components.plex.PlexServer.connect",
side_effect=plexapi.exceptions.BadRequest,
):
next_update = dt_util.utcnow() + timedelta(seconds=30)
async_fire_time_changed(hass, next_update)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert entry.state == ENTRY_STATE_SETUP_ERROR | [
"async",
"def",
"test_setup_config_entry_with_error",
"(",
"hass",
",",
"entry",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.plex.PlexServer.connect\"",
",",
"side_effect",
"=",
"requests",
".",
"exceptions",
".",
"ConnectionError",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"is",
"False",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_RETRY",
"with",
"patch",
"(",
"\"homeassistant.components.plex.PlexServer.connect\"",
",",
"side_effect",
"=",
"plexapi",
".",
"exceptions",
".",
"BadRequest",
",",
")",
":",
"next_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"30",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"next_update",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_ERROR"
] | [
37,
0
] | [
59,
49
] | python | en | ['en', 'en', 'en'] | True |
test_setup_with_insecure_config_entry | (hass, entry, setup_plex_server) | Test setup component with config. | Test setup component with config. | async def test_setup_with_insecure_config_entry(hass, entry, setup_plex_server):
"""Test setup component with config."""
INSECURE_DATA = copy.deepcopy(DEFAULT_DATA)
INSECURE_DATA[const.PLEX_SERVER_CONFIG][CONF_VERIFY_SSL] = False
entry.data = INSECURE_DATA
await setup_plex_server(config_entry=entry)
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED | [
"async",
"def",
"test_setup_with_insecure_config_entry",
"(",
"hass",
",",
"entry",
",",
"setup_plex_server",
")",
":",
"INSECURE_DATA",
"=",
"copy",
".",
"deepcopy",
"(",
"DEFAULT_DATA",
")",
"INSECURE_DATA",
"[",
"const",
".",
"PLEX_SERVER_CONFIG",
"]",
"[",
"CONF_VERIFY_SSL",
"]",
"=",
"False",
"entry",
".",
"data",
"=",
"INSECURE_DATA",
"await",
"setup_plex_server",
"(",
"config_entry",
"=",
"entry",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED"
] | [
62,
0
] | [
71,
44
] | python | en | ['en', 'en', 'en'] | True |
test_unload_config_entry | (hass, entry, mock_plex_server) | Test unloading a config entry. | Test unloading a config entry. | async def test_unload_config_entry(hass, entry, mock_plex_server):
"""Test unloading a config entry."""
config_entries = hass.config_entries.async_entries(const.DOMAIN)
assert len(config_entries) == 1
assert entry is config_entries[0]
assert entry.state == ENTRY_STATE_LOADED
server_id = mock_plex_server.machineIdentifier
loaded_server = hass.data[const.DOMAIN][const.SERVERS][server_id]
assert loaded_server.plex_server == mock_plex_server
websocket = hass.data[const.DOMAIN][const.WEBSOCKETS][server_id]
await hass.config_entries.async_unload(entry.entry_id)
assert websocket.close.called
assert entry.state == ENTRY_STATE_NOT_LOADED | [
"async",
"def",
"test_unload_config_entry",
"(",
"hass",
",",
"entry",
",",
"mock_plex_server",
")",
":",
"config_entries",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
"assert",
"len",
"(",
"config_entries",
")",
"==",
"1",
"assert",
"entry",
"is",
"config_entries",
"[",
"0",
"]",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"server_id",
"=",
"mock_plex_server",
".",
"machineIdentifier",
"loaded_server",
"=",
"hass",
".",
"data",
"[",
"const",
".",
"DOMAIN",
"]",
"[",
"const",
".",
"SERVERS",
"]",
"[",
"server_id",
"]",
"assert",
"loaded_server",
".",
"plex_server",
"==",
"mock_plex_server",
"websocket",
"=",
"hass",
".",
"data",
"[",
"const",
".",
"DOMAIN",
"]",
"[",
"const",
".",
"WEBSOCKETS",
"]",
"[",
"server_id",
"]",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"entry",
".",
"entry_id",
")",
"assert",
"websocket",
".",
"close",
".",
"called",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_NOT_LOADED"
] | [
74,
0
] | [
88,
48
] | python | en | ['en', 'en', 'en'] | True |
test_setup_with_photo_session | (hass, entry, mock_websocket, setup_plex_server) | Test setup component with config. | Test setup component with config. | async def test_setup_with_photo_session(hass, entry, mock_websocket, setup_plex_server):
"""Test setup component with config."""
mock_plex_server = await setup_plex_server(config_entry=entry, session_type="photo")
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert entry.state == ENTRY_STATE_LOADED
trigger_plex_update(mock_websocket)
await hass.async_block_till_done()
media_player = hass.states.get("media_player.plex_product_title")
assert media_player.state == "idle"
sensor = hass.states.get("sensor.plex_plex_server_1")
assert sensor.state == str(len(mock_plex_server.accounts)) | [
"async",
"def",
"test_setup_with_photo_session",
"(",
"hass",
",",
"entry",
",",
"mock_websocket",
",",
"setup_plex_server",
")",
":",
"mock_plex_server",
"=",
"await",
"setup_plex_server",
"(",
"config_entry",
"=",
"entry",
",",
"session_type",
"=",
"\"photo\"",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"trigger_plex_update",
"(",
"mock_websocket",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"media_player",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"media_player.plex_product_title\"",
")",
"assert",
"media_player",
".",
"state",
"==",
"\"idle\"",
"sensor",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.plex_plex_server_1\"",
")",
"assert",
"sensor",
".",
"state",
"==",
"str",
"(",
"len",
"(",
"mock_plex_server",
".",
"accounts",
")",
")"
] | [
91,
0
] | [
105,
62
] | python | en | ['en', 'en', 'en'] | True |
test_setup_when_certificate_changed | (hass, entry) | Test setup component when the Plex certificate has changed. | Test setup component when the Plex certificate has changed. | async def test_setup_when_certificate_changed(hass, entry):
"""Test setup component when the Plex certificate has changed."""
old_domain = "1-2-3-4.1234567890abcdef1234567890abcdef.plex.direct"
old_url = f"https://{old_domain}:32400"
OLD_HOSTNAME_DATA = copy.deepcopy(DEFAULT_DATA)
OLD_HOSTNAME_DATA[const.PLEX_SERVER_CONFIG][CONF_URL] = old_url
class WrongCertHostnameException(requests.exceptions.SSLError):
"""Mock the exception showing a mismatched hostname."""
def __init__(self):
self.__context__ = ssl.SSLCertVerificationError(
f"hostname '{old_domain}' doesn't match"
)
old_entry = MockConfigEntry(
domain=const.DOMAIN,
data=OLD_HOSTNAME_DATA,
options=DEFAULT_OPTIONS,
unique_id=DEFAULT_DATA["server_id"],
)
# Test with account failure
with patch(
"plexapi.server.PlexServer", side_effect=WrongCertHostnameException
), patch(
"plexapi.myplex.MyPlexAccount", side_effect=plexapi.exceptions.Unauthorized
):
old_entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(old_entry.entry_id) is False
await hass.async_block_till_done()
assert old_entry.state == ENTRY_STATE_SETUP_ERROR
await hass.config_entries.async_unload(old_entry.entry_id)
# Test with no servers found
with patch(
"plexapi.server.PlexServer", side_effect=WrongCertHostnameException
), patch("plexapi.myplex.MyPlexAccount", return_value=MockPlexAccount(servers=0)):
assert await hass.config_entries.async_setup(old_entry.entry_id) is False
await hass.async_block_till_done()
assert old_entry.state == ENTRY_STATE_SETUP_ERROR
await hass.config_entries.async_unload(old_entry.entry_id)
# Test with success
with patch(
"plexapi.server.PlexServer", side_effect=WrongCertHostnameException
), patch("plexapi.myplex.MyPlexAccount", return_value=MockPlexAccount()):
assert await hass.config_entries.async_setup(old_entry.entry_id)
await hass.async_block_till_done()
assert len(hass.config_entries.async_entries(const.DOMAIN)) == 1
assert old_entry.state == ENTRY_STATE_LOADED
assert (
old_entry.data[const.PLEX_SERVER_CONFIG][CONF_URL]
== entry.data[const.PLEX_SERVER_CONFIG][CONF_URL]
) | [
"async",
"def",
"test_setup_when_certificate_changed",
"(",
"hass",
",",
"entry",
")",
":",
"old_domain",
"=",
"\"1-2-3-4.1234567890abcdef1234567890abcdef.plex.direct\"",
"old_url",
"=",
"f\"https://{old_domain}:32400\"",
"OLD_HOSTNAME_DATA",
"=",
"copy",
".",
"deepcopy",
"(",
"DEFAULT_DATA",
")",
"OLD_HOSTNAME_DATA",
"[",
"const",
".",
"PLEX_SERVER_CONFIG",
"]",
"[",
"CONF_URL",
"]",
"=",
"old_url",
"class",
"WrongCertHostnameException",
"(",
"requests",
".",
"exceptions",
".",
"SSLError",
")",
":",
"\"\"\"Mock the exception showing a mismatched hostname.\"\"\"",
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"__context__",
"=",
"ssl",
".",
"SSLCertVerificationError",
"(",
"f\"hostname '{old_domain}' doesn't match\"",
")",
"old_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"const",
".",
"DOMAIN",
",",
"data",
"=",
"OLD_HOSTNAME_DATA",
",",
"options",
"=",
"DEFAULT_OPTIONS",
",",
"unique_id",
"=",
"DEFAULT_DATA",
"[",
"\"server_id\"",
"]",
",",
")",
"# Test with account failure",
"with",
"patch",
"(",
"\"plexapi.server.PlexServer\"",
",",
"side_effect",
"=",
"WrongCertHostnameException",
")",
",",
"patch",
"(",
"\"plexapi.myplex.MyPlexAccount\"",
",",
"side_effect",
"=",
"plexapi",
".",
"exceptions",
".",
"Unauthorized",
")",
":",
"old_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"old_entry",
".",
"entry_id",
")",
"is",
"False",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"old_entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_ERROR",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"old_entry",
".",
"entry_id",
")",
"# Test with no servers found",
"with",
"patch",
"(",
"\"plexapi.server.PlexServer\"",
",",
"side_effect",
"=",
"WrongCertHostnameException",
")",
",",
"patch",
"(",
"\"plexapi.myplex.MyPlexAccount\"",
",",
"return_value",
"=",
"MockPlexAccount",
"(",
"servers",
"=",
"0",
")",
")",
":",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"old_entry",
".",
"entry_id",
")",
"is",
"False",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"old_entry",
".",
"state",
"==",
"ENTRY_STATE_SETUP_ERROR",
"await",
"hass",
".",
"config_entries",
".",
"async_unload",
"(",
"old_entry",
".",
"entry_id",
")",
"# Test with success",
"with",
"patch",
"(",
"\"plexapi.server.PlexServer\"",
",",
"side_effect",
"=",
"WrongCertHostnameException",
")",
",",
"patch",
"(",
"\"plexapi.myplex.MyPlexAccount\"",
",",
"return_value",
"=",
"MockPlexAccount",
"(",
")",
")",
":",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"old_entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"const",
".",
"DOMAIN",
")",
")",
"==",
"1",
"assert",
"old_entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"assert",
"(",
"old_entry",
".",
"data",
"[",
"const",
".",
"PLEX_SERVER_CONFIG",
"]",
"[",
"CONF_URL",
"]",
"==",
"entry",
".",
"data",
"[",
"const",
".",
"PLEX_SERVER_CONFIG",
"]",
"[",
"CONF_URL",
"]",
")"
] | [
108,
0
] | [
168,
5
] | python | en | ['en', 'en', 'en'] | True |
test_tokenless_server | (hass, entry, mock_websocket, setup_plex_server) | Test setup with a server with token auth disabled. | Test setup with a server with token auth disabled. | async def test_tokenless_server(hass, entry, mock_websocket, setup_plex_server):
"""Test setup with a server with token auth disabled."""
TOKENLESS_DATA = copy.deepcopy(DEFAULT_DATA)
TOKENLESS_DATA[const.PLEX_SERVER_CONFIG].pop(CONF_TOKEN, None)
entry.data = TOKENLESS_DATA
await setup_plex_server(config_entry=entry)
assert entry.state == ENTRY_STATE_LOADED | [
"async",
"def",
"test_tokenless_server",
"(",
"hass",
",",
"entry",
",",
"mock_websocket",
",",
"setup_plex_server",
")",
":",
"TOKENLESS_DATA",
"=",
"copy",
".",
"deepcopy",
"(",
"DEFAULT_DATA",
")",
"TOKENLESS_DATA",
"[",
"const",
".",
"PLEX_SERVER_CONFIG",
"]",
".",
"pop",
"(",
"CONF_TOKEN",
",",
"None",
")",
"entry",
".",
"data",
"=",
"TOKENLESS_DATA",
"await",
"setup_plex_server",
"(",
"config_entry",
"=",
"entry",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED"
] | [
171,
0
] | [
178,
44
] | python | en | ['en', 'en', 'en'] | True |
test_bad_token_with_tokenless_server | (hass, entry) | Test setup with a bad token and a server with token auth disabled. | Test setup with a bad token and a server with token auth disabled. | async def test_bad_token_with_tokenless_server(hass, entry):
"""Test setup with a bad token and a server with token auth disabled."""
with patch("plexapi.server.PlexServer", return_value=MockPlexServer()), patch(
"plexapi.myplex.MyPlexAccount", side_effect=plexapi.exceptions.Unauthorized
), patch(
"homeassistant.components.plex.GDM", return_value=MockGDM(disabled=True)
), patch(
"homeassistant.components.plex.PlexWebsocket", autospec=True
) as mock_websocket:
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state == ENTRY_STATE_LOADED
# Ensure updates that rely on account return nothing
trigger_plex_update(mock_websocket)
await hass.async_block_till_done() | [
"async",
"def",
"test_bad_token_with_tokenless_server",
"(",
"hass",
",",
"entry",
")",
":",
"with",
"patch",
"(",
"\"plexapi.server.PlexServer\"",
",",
"return_value",
"=",
"MockPlexServer",
"(",
")",
")",
",",
"patch",
"(",
"\"plexapi.myplex.MyPlexAccount\"",
",",
"side_effect",
"=",
"plexapi",
".",
"exceptions",
".",
"Unauthorized",
")",
",",
"patch",
"(",
"\"homeassistant.components.plex.GDM\"",
",",
"return_value",
"=",
"MockGDM",
"(",
"disabled",
"=",
"True",
")",
")",
",",
"patch",
"(",
"\"homeassistant.components.plex.PlexWebsocket\"",
",",
"autospec",
"=",
"True",
")",
"as",
"mock_websocket",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"entry",
".",
"state",
"==",
"ENTRY_STATE_LOADED",
"# Ensure updates that rely on account return nothing",
"trigger_plex_update",
"(",
"mock_websocket",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
181,
0
] | [
198,
38
] | python | en | ['en', 'en', 'en'] | True |
DecisionEvent.action_scope | (self) | dict: A dictionary that contains requirements of current and neighbor stations,
key is the station index, value is the max demand or supply number.
| dict: A dictionary that contains requirements of current and neighbor stations,
key is the station index, value is the max demand or supply number.
| def action_scope(self) -> dict:
"""dict: A dictionary that contains requirements of current and neighbor stations,
key is the station index, value is the max demand or supply number.
"""
if self._action_scope is None:
self._action_scope = self._action_scope_func(self.station_idx, self.type)
return self._action_scope | [
"def",
"action_scope",
"(",
"self",
")",
"->",
"dict",
":",
"if",
"self",
".",
"_action_scope",
"is",
"None",
":",
"self",
".",
"_action_scope",
"=",
"self",
".",
"_action_scope_func",
"(",
"self",
".",
"station_idx",
",",
"self",
".",
"type",
")",
"return",
"self",
".",
"_action_scope"
] | [
72,
4
] | [
79,
33
] | python | en | ['en', 'en', 'en'] | True |
DecisionEvent.__getstate__ | (self) | Return pickleable dictionary. | Return pickleable dictionary. | def __getstate__(self):
"""Return pickleable dictionary."""
return {
"station_idx": self.station_idx,
"tick": self.tick,
"frame_index": self.frame_index,
"type": self.type,
"action_scope": self.action_scope} | [
"def",
"__getstate__",
"(",
"self",
")",
":",
"return",
"{",
"\"station_idx\"",
":",
"self",
".",
"station_idx",
",",
"\"tick\"",
":",
"self",
".",
"tick",
",",
"\"frame_index\"",
":",
"self",
".",
"frame_index",
",",
"\"type\"",
":",
"self",
".",
"type",
",",
"\"action_scope\"",
":",
"self",
".",
"action_scope",
"}"
] | [
81,
4
] | [
88,
46
] | python | en | ['it', 'en', 'en'] | True |
get_available_regions | (hass, service) | Get available regions for a service. | Get available regions for a service. | async def get_available_regions(hass, service):
"""Get available regions for a service."""
session = aiobotocore.get_session()
# get_available_regions is not a coroutine since it does not perform
# network I/O. But it still perform file I/O heavily, so put it into
# an executor thread to unblock event loop
return await hass.async_add_executor_job(session.get_available_regions, service) | [
"async",
"def",
"get_available_regions",
"(",
"hass",
",",
"service",
")",
":",
"session",
"=",
"aiobotocore",
".",
"get_session",
"(",
")",
"# get_available_regions is not a coroutine since it does not perform",
"# network I/O. But it still perform file I/O heavily, so put it into",
"# an executor thread to unblock event loop",
"return",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"session",
".",
"get_available_regions",
",",
"service",
")"
] | [
29,
0
] | [
36,
84
] | python | en | ['en', 'en', 'en'] | True |
async_get_service | (hass, config, discovery_info=None) | Get the AWS notification service. | Get the AWS notification service. | async def async_get_service(hass, config, discovery_info=None):
"""Get the AWS notification service."""
if discovery_info is None:
_LOGGER.error("Please config aws notify platform in aws component")
return None
session = None
conf = discovery_info
service = conf[CONF_SERVICE]
region_name = conf[CONF_REGION]
available_regions = await get_available_regions(hass, service)
if region_name not in available_regions:
_LOGGER.error(
"Region %s is not available for %s service, must in %s",
region_name,
service,
available_regions,
)
return None
aws_config = conf.copy()
del aws_config[CONF_SERVICE]
del aws_config[CONF_REGION]
if CONF_PLATFORM in aws_config:
del aws_config[CONF_PLATFORM]
if CONF_NAME in aws_config:
del aws_config[CONF_NAME]
if CONF_CONTEXT in aws_config:
del aws_config[CONF_CONTEXT]
if not aws_config:
# no platform config, use the first aws component credential instead
if hass.data[DATA_SESSIONS]:
session = next(iter(hass.data[DATA_SESSIONS].values()))
else:
_LOGGER.error("Missing aws credential for %s", config[CONF_NAME])
return None
if session is None:
credential_name = aws_config.get(CONF_CREDENTIAL_NAME)
if credential_name is not None:
session = hass.data[DATA_SESSIONS].get(credential_name)
if session is None:
_LOGGER.warning("No available aws session for %s", credential_name)
del aws_config[CONF_CREDENTIAL_NAME]
if session is None:
profile = aws_config.get(CONF_PROFILE_NAME)
if profile is not None:
session = aiobotocore.AioSession(profile=profile)
del aws_config[CONF_PROFILE_NAME]
else:
session = aiobotocore.AioSession()
aws_config[CONF_REGION] = region_name
if service == "lambda":
context_str = json.dumps(
{"custom": conf.get(CONF_CONTEXT, {})}, cls=JSONEncoder
)
context_b64 = base64.b64encode(context_str.encode("utf-8"))
context = context_b64.decode("utf-8")
return AWSLambda(session, aws_config, context)
if service == "sns":
return AWSSNS(session, aws_config)
if service == "sqs":
return AWSSQS(session, aws_config)
# should not reach here since service was checked in schema
return None | [
"async",
"def",
"async_get_service",
"(",
"hass",
",",
"config",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"Please config aws notify platform in aws component\"",
")",
"return",
"None",
"session",
"=",
"None",
"conf",
"=",
"discovery_info",
"service",
"=",
"conf",
"[",
"CONF_SERVICE",
"]",
"region_name",
"=",
"conf",
"[",
"CONF_REGION",
"]",
"available_regions",
"=",
"await",
"get_available_regions",
"(",
"hass",
",",
"service",
")",
"if",
"region_name",
"not",
"in",
"available_regions",
":",
"_LOGGER",
".",
"error",
"(",
"\"Region %s is not available for %s service, must in %s\"",
",",
"region_name",
",",
"service",
",",
"available_regions",
",",
")",
"return",
"None",
"aws_config",
"=",
"conf",
".",
"copy",
"(",
")",
"del",
"aws_config",
"[",
"CONF_SERVICE",
"]",
"del",
"aws_config",
"[",
"CONF_REGION",
"]",
"if",
"CONF_PLATFORM",
"in",
"aws_config",
":",
"del",
"aws_config",
"[",
"CONF_PLATFORM",
"]",
"if",
"CONF_NAME",
"in",
"aws_config",
":",
"del",
"aws_config",
"[",
"CONF_NAME",
"]",
"if",
"CONF_CONTEXT",
"in",
"aws_config",
":",
"del",
"aws_config",
"[",
"CONF_CONTEXT",
"]",
"if",
"not",
"aws_config",
":",
"# no platform config, use the first aws component credential instead",
"if",
"hass",
".",
"data",
"[",
"DATA_SESSIONS",
"]",
":",
"session",
"=",
"next",
"(",
"iter",
"(",
"hass",
".",
"data",
"[",
"DATA_SESSIONS",
"]",
".",
"values",
"(",
")",
")",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Missing aws credential for %s\"",
",",
"config",
"[",
"CONF_NAME",
"]",
")",
"return",
"None",
"if",
"session",
"is",
"None",
":",
"credential_name",
"=",
"aws_config",
".",
"get",
"(",
"CONF_CREDENTIAL_NAME",
")",
"if",
"credential_name",
"is",
"not",
"None",
":",
"session",
"=",
"hass",
".",
"data",
"[",
"DATA_SESSIONS",
"]",
".",
"get",
"(",
"credential_name",
")",
"if",
"session",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"No available aws session for %s\"",
",",
"credential_name",
")",
"del",
"aws_config",
"[",
"CONF_CREDENTIAL_NAME",
"]",
"if",
"session",
"is",
"None",
":",
"profile",
"=",
"aws_config",
".",
"get",
"(",
"CONF_PROFILE_NAME",
")",
"if",
"profile",
"is",
"not",
"None",
":",
"session",
"=",
"aiobotocore",
".",
"AioSession",
"(",
"profile",
"=",
"profile",
")",
"del",
"aws_config",
"[",
"CONF_PROFILE_NAME",
"]",
"else",
":",
"session",
"=",
"aiobotocore",
".",
"AioSession",
"(",
")",
"aws_config",
"[",
"CONF_REGION",
"]",
"=",
"region_name",
"if",
"service",
"==",
"\"lambda\"",
":",
"context_str",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"custom\"",
":",
"conf",
".",
"get",
"(",
"CONF_CONTEXT",
",",
"{",
"}",
")",
"}",
",",
"cls",
"=",
"JSONEncoder",
")",
"context_b64",
"=",
"base64",
".",
"b64encode",
"(",
"context_str",
".",
"encode",
"(",
"\"utf-8\"",
")",
")",
"context",
"=",
"context_b64",
".",
"decode",
"(",
"\"utf-8\"",
")",
"return",
"AWSLambda",
"(",
"session",
",",
"aws_config",
",",
"context",
")",
"if",
"service",
"==",
"\"sns\"",
":",
"return",
"AWSSNS",
"(",
"session",
",",
"aws_config",
")",
"if",
"service",
"==",
"\"sqs\"",
":",
"return",
"AWSSQS",
"(",
"session",
",",
"aws_config",
")",
"# should not reach here since service was checked in schema",
"return",
"None"
] | [
39,
0
] | [
114,
15
] | python | en | ['en', 'en', 'en'] | True |
AWSNotify.__init__ | (self, session, aws_config) | Initialize the service. | Initialize the service. | def __init__(self, session, aws_config):
"""Initialize the service."""
self.session = session
self.aws_config = aws_config | [
"def",
"__init__",
"(",
"self",
",",
"session",
",",
"aws_config",
")",
":",
"self",
".",
"session",
"=",
"session",
"self",
".",
"aws_config",
"=",
"aws_config"
] | [
120,
4
] | [
123,
36
] | python | en | ['en', 'en', 'en'] | True |
AWSLambda.__init__ | (self, session, aws_config, context) | Initialize the service. | Initialize the service. | def __init__(self, session, aws_config, context):
"""Initialize the service."""
super().__init__(session, aws_config)
self.context = context | [
"def",
"__init__",
"(",
"self",
",",
"session",
",",
"aws_config",
",",
"context",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"session",
",",
"aws_config",
")",
"self",
".",
"context",
"=",
"context"
] | [
131,
4
] | [
134,
30
] | python | en | ['en', 'en', 'en'] | True |
AWSLambda.async_send_message | (self, message="", **kwargs) | Send notification to specified LAMBDA ARN. | Send notification to specified LAMBDA ARN. | async def async_send_message(self, message="", **kwargs):
"""Send notification to specified LAMBDA ARN."""
if not kwargs.get(ATTR_TARGET):
_LOGGER.error("At least one target is required")
return
cleaned_kwargs = {k: v for k, v in kwargs.items() if v is not None}
payload = {"message": message}
payload.update(cleaned_kwargs)
json_payload = json.dumps(payload)
async with self.session.create_client(
self.service, **self.aws_config
) as client:
tasks = []
for target in kwargs.get(ATTR_TARGET, []):
tasks.append(
client.invoke(
FunctionName=target,
Payload=json_payload,
ClientContext=self.context,
)
)
if tasks:
await asyncio.gather(*tasks) | [
"async",
"def",
"async_send_message",
"(",
"self",
",",
"message",
"=",
"\"\"",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"At least one target is required\"",
")",
"return",
"cleaned_kwargs",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
"if",
"v",
"is",
"not",
"None",
"}",
"payload",
"=",
"{",
"\"message\"",
":",
"message",
"}",
"payload",
".",
"update",
"(",
"cleaned_kwargs",
")",
"json_payload",
"=",
"json",
".",
"dumps",
"(",
"payload",
")",
"async",
"with",
"self",
".",
"session",
".",
"create_client",
"(",
"self",
".",
"service",
",",
"*",
"*",
"self",
".",
"aws_config",
")",
"as",
"client",
":",
"tasks",
"=",
"[",
"]",
"for",
"target",
"in",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
",",
"[",
"]",
")",
":",
"tasks",
".",
"append",
"(",
"client",
".",
"invoke",
"(",
"FunctionName",
"=",
"target",
",",
"Payload",
"=",
"json_payload",
",",
"ClientContext",
"=",
"self",
".",
"context",
",",
")",
")",
"if",
"tasks",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"tasks",
")"
] | [
136,
4
] | [
161,
44
] | python | en | ['en', 'fy', 'en'] | True |
AWSSNS.async_send_message | (self, message="", **kwargs) | Send notification to specified SNS ARN. | Send notification to specified SNS ARN. | async def async_send_message(self, message="", **kwargs):
"""Send notification to specified SNS ARN."""
if not kwargs.get(ATTR_TARGET):
_LOGGER.error("At least one target is required")
return
message_attributes = {
k: {"StringValue": json.dumps(v), "DataType": "String"}
for k, v in kwargs.items()
if v is not None
}
subject = kwargs.get(ATTR_TITLE, ATTR_TITLE_DEFAULT)
async with self.session.create_client(
self.service, **self.aws_config
) as client:
tasks = []
for target in kwargs.get(ATTR_TARGET, []):
tasks.append(
client.publish(
TargetArn=target,
Message=message,
Subject=subject,
MessageAttributes=message_attributes,
)
)
if tasks:
await asyncio.gather(*tasks) | [
"async",
"def",
"async_send_message",
"(",
"self",
",",
"message",
"=",
"\"\"",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"At least one target is required\"",
")",
"return",
"message_attributes",
"=",
"{",
"k",
":",
"{",
"\"StringValue\"",
":",
"json",
".",
"dumps",
"(",
"v",
")",
",",
"\"DataType\"",
":",
"\"String\"",
"}",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
"if",
"v",
"is",
"not",
"None",
"}",
"subject",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TITLE",
",",
"ATTR_TITLE_DEFAULT",
")",
"async",
"with",
"self",
".",
"session",
".",
"create_client",
"(",
"self",
".",
"service",
",",
"*",
"*",
"self",
".",
"aws_config",
")",
"as",
"client",
":",
"tasks",
"=",
"[",
"]",
"for",
"target",
"in",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
",",
"[",
"]",
")",
":",
"tasks",
".",
"append",
"(",
"client",
".",
"publish",
"(",
"TargetArn",
"=",
"target",
",",
"Message",
"=",
"message",
",",
"Subject",
"=",
"subject",
",",
"MessageAttributes",
"=",
"message_attributes",
",",
")",
")",
"if",
"tasks",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"tasks",
")"
] | [
169,
4
] | [
197,
44
] | python | en | ['en', 'en', 'en'] | True |
AWSSQS.async_send_message | (self, message="", **kwargs) | Send notification to specified SQS ARN. | Send notification to specified SQS ARN. | async def async_send_message(self, message="", **kwargs):
"""Send notification to specified SQS ARN."""
if not kwargs.get(ATTR_TARGET):
_LOGGER.error("At least one target is required")
return
cleaned_kwargs = {k: v for k, v in kwargs.items() if v is not None}
message_body = {"message": message}
message_body.update(cleaned_kwargs)
json_body = json.dumps(message_body)
message_attributes = {}
for key, val in cleaned_kwargs.items():
message_attributes[key] = {
"StringValue": json.dumps(val),
"DataType": "String",
}
async with self.session.create_client(
self.service, **self.aws_config
) as client:
tasks = []
for target in kwargs.get(ATTR_TARGET, []):
tasks.append(
client.send_message(
QueueUrl=target,
MessageBody=json_body,
MessageAttributes=message_attributes,
)
)
if tasks:
await asyncio.gather(*tasks) | [
"async",
"def",
"async_send_message",
"(",
"self",
",",
"message",
"=",
"\"\"",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"At least one target is required\"",
")",
"return",
"cleaned_kwargs",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
"if",
"v",
"is",
"not",
"None",
"}",
"message_body",
"=",
"{",
"\"message\"",
":",
"message",
"}",
"message_body",
".",
"update",
"(",
"cleaned_kwargs",
")",
"json_body",
"=",
"json",
".",
"dumps",
"(",
"message_body",
")",
"message_attributes",
"=",
"{",
"}",
"for",
"key",
",",
"val",
"in",
"cleaned_kwargs",
".",
"items",
"(",
")",
":",
"message_attributes",
"[",
"key",
"]",
"=",
"{",
"\"StringValue\"",
":",
"json",
".",
"dumps",
"(",
"val",
")",
",",
"\"DataType\"",
":",
"\"String\"",
",",
"}",
"async",
"with",
"self",
".",
"session",
".",
"create_client",
"(",
"self",
".",
"service",
",",
"*",
"*",
"self",
".",
"aws_config",
")",
"as",
"client",
":",
"tasks",
"=",
"[",
"]",
"for",
"target",
"in",
"kwargs",
".",
"get",
"(",
"ATTR_TARGET",
",",
"[",
"]",
")",
":",
"tasks",
".",
"append",
"(",
"client",
".",
"send_message",
"(",
"QueueUrl",
"=",
"target",
",",
"MessageBody",
"=",
"json_body",
",",
"MessageAttributes",
"=",
"message_attributes",
",",
")",
")",
"if",
"tasks",
":",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"tasks",
")"
] | [
205,
4
] | [
236,
44
] | python | en | ['en', 'en', 'en'] | True |
MockGDM.__init__ | (self, disabled=False) | Initialize the object. | Initialize the object. | def __init__(self, disabled=False):
"""Initialize the object."""
self.entries = []
self.disabled = disabled | [
"def",
"__init__",
"(",
"self",
",",
"disabled",
"=",
"False",
")",
":",
"self",
".",
"entries",
"=",
"[",
"]",
"self",
".",
"disabled",
"=",
"disabled"
] | [
82,
4
] | [
85,
32
] | python | en | ['en', 'en', 'en'] | True |
MockGDM.scan | (self, scan_for_clients=False) | Mock the scan call. | Mock the scan call. | def scan(self, scan_for_clients=False):
"""Mock the scan call."""
if self.disabled:
return
if scan_for_clients:
self.entries = GDM_CLIENT_PAYLOAD
else:
self.entries = GDM_SERVER_PAYLOAD | [
"def",
"scan",
"(",
"self",
",",
"scan_for_clients",
"=",
"False",
")",
":",
"if",
"self",
".",
"disabled",
":",
"return",
"if",
"scan_for_clients",
":",
"self",
".",
"entries",
"=",
"GDM_CLIENT_PAYLOAD",
"else",
":",
"self",
".",
"entries",
"=",
"GDM_SERVER_PAYLOAD"
] | [
87,
4
] | [
95,
45
] | python | en | ['en', 'en', 'en'] | True |
MockResource.__init__ | (self, index, kind="server") | Initialize the object. | Initialize the object. | def __init__(self, index, kind="server"):
"""Initialize the object."""
if kind == "server":
self.name = MOCK_SERVERS[index][CONF_SERVER]
self.clientIdentifier = MOCK_SERVERS[index][ # pylint: disable=invalid-name
CONF_SERVER_IDENTIFIER
]
self.provides = ["server"]
self.device = MockPlexServer(index)
else:
self.name = f"plex.tv Resource Player {index+10}"
self.clientIdentifier = f"client-{index+10}"
self.provides = ["player"]
self.device = MockPlexClient(
baseurl=f"http://192.168.0.1{index}:32500", index=index + 10
)
self.presence = index == 0
self.publicAddressMatches = True | [
"def",
"__init__",
"(",
"self",
",",
"index",
",",
"kind",
"=",
"\"server\"",
")",
":",
"if",
"kind",
"==",
"\"server\"",
":",
"self",
".",
"name",
"=",
"MOCK_SERVERS",
"[",
"index",
"]",
"[",
"CONF_SERVER",
"]",
"self",
".",
"clientIdentifier",
"=",
"MOCK_SERVERS",
"[",
"index",
"]",
"[",
"# pylint: disable=invalid-name",
"CONF_SERVER_IDENTIFIER",
"]",
"self",
".",
"provides",
"=",
"[",
"\"server\"",
"]",
"self",
".",
"device",
"=",
"MockPlexServer",
"(",
"index",
")",
"else",
":",
"self",
".",
"name",
"=",
"f\"plex.tv Resource Player {index+10}\"",
"self",
".",
"clientIdentifier",
"=",
"f\"client-{index+10}\"",
"self",
".",
"provides",
"=",
"[",
"\"player\"",
"]",
"self",
".",
"device",
"=",
"MockPlexClient",
"(",
"baseurl",
"=",
"f\"http://192.168.0.1{index}:32500\"",
",",
"index",
"=",
"index",
"+",
"10",
")",
"self",
".",
"presence",
"=",
"index",
"==",
"0",
"self",
".",
"publicAddressMatches",
"=",
"True"
] | [
101,
4
] | [
118,
44
] | python | en | ['en', 'en', 'en'] | True |
MockResource.connect | (self, timeout) | Mock the resource connect method. | Mock the resource connect method. | def connect(self, timeout):
"""Mock the resource connect method."""
return self.device | [
"def",
"connect",
"(",
"self",
",",
"timeout",
")",
":",
"return",
"self",
".",
"device"
] | [
120,
4
] | [
122,
26
] | python | en | ['en', 'en', 'en'] | True |
MockPlexAccount.__init__ | (self, servers=1, players=3) | Initialize the object. | Initialize the object. | def __init__(self, servers=1, players=3):
"""Initialize the object."""
self._resources = []
for index in range(servers):
self._resources.append(MockResource(index))
for index in range(players):
self._resources.append(MockResource(index, kind="player")) | [
"def",
"__init__",
"(",
"self",
",",
"servers",
"=",
"1",
",",
"players",
"=",
"3",
")",
":",
"self",
".",
"_resources",
"=",
"[",
"]",
"for",
"index",
"in",
"range",
"(",
"servers",
")",
":",
"self",
".",
"_resources",
".",
"append",
"(",
"MockResource",
"(",
"index",
")",
")",
"for",
"index",
"in",
"range",
"(",
"players",
")",
":",
"self",
".",
"_resources",
".",
"append",
"(",
"MockResource",
"(",
"index",
",",
"kind",
"=",
"\"player\"",
")",
")"
] | [
128,
4
] | [
134,
70
] | python | en | ['en', 'en', 'en'] | True |
MockPlexAccount.resource | (self, name) | Mock the PlexAccount resource lookup method. | Mock the PlexAccount resource lookup method. | def resource(self, name):
"""Mock the PlexAccount resource lookup method."""
return [x for x in self._resources if x.name == name][0] | [
"def",
"resource",
"(",
"self",
",",
"name",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_resources",
"if",
"x",
".",
"name",
"==",
"name",
"]",
"[",
"0",
"]"
] | [
136,
4
] | [
138,
64
] | python | en | ['en', 'nl', 'en'] | True |
MockPlexAccount.resources | (self) | Mock the PlexAccount resources listing method. | Mock the PlexAccount resources listing method. | def resources(self):
"""Mock the PlexAccount resources listing method."""
return self._resources | [
"def",
"resources",
"(",
"self",
")",
":",
"return",
"self",
".",
"_resources"
] | [
140,
4
] | [
142,
30
] | python | en | ['en', 'sr', 'en'] | True |
MockPlexAccount.sonos_speaker | (self, speaker_name) | Mock the PlexAccount Sonos lookup method. | Mock the PlexAccount Sonos lookup method. | def sonos_speaker(self, speaker_name):
"""Mock the PlexAccount Sonos lookup method."""
return MockPlexSonosClient(speaker_name) | [
"def",
"sonos_speaker",
"(",
"self",
",",
"speaker_name",
")",
":",
"return",
"MockPlexSonosClient",
"(",
"speaker_name",
")"
] | [
144,
4
] | [
146,
48
] | python | en | ['en', 'sr', 'en'] | True |
MockPlexSystemAccount.__init__ | (self, index) | Initialize the object. | Initialize the object. | def __init__(self, index):
"""Initialize the object."""
# Start accountIDs at 1 to set proper owner.
self.name = list(MOCK_USERS)[index]
self.accountID = index + 1 | [
"def",
"__init__",
"(",
"self",
",",
"index",
")",
":",
"# Start accountIDs at 1 to set proper owner.",
"self",
".",
"name",
"=",
"list",
"(",
"MOCK_USERS",
")",
"[",
"index",
"]",
"self",
".",
"accountID",
"=",
"index",
"+",
"1"
] | [
152,
4
] | [
156,
34
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.__init__ | (
self,
index=0,
config_entry=None,
num_users=len(MOCK_USERS),
session_type="video",
) | Initialize the object. | Initialize the object. | def __init__(
self,
index=0,
config_entry=None,
num_users=len(MOCK_USERS),
session_type="video",
):
"""Initialize the object."""
if config_entry:
self._data = config_entry.data
else:
self._data = DEFAULT_DATA
self._baseurl = self._data[PLEX_SERVER_CONFIG][CONF_URL]
self.friendlyName = self._data[CONF_SERVER]
self.machineIdentifier = self._data[CONF_SERVER_IDENTIFIER]
self._systemAccounts = list(map(MockPlexSystemAccount, range(num_users)))
self._clients = []
self._session = None
self._sessions = []
self.set_clients(num_users)
self.set_sessions(num_users, session_type)
self._cache = {} | [
"def",
"__init__",
"(",
"self",
",",
"index",
"=",
"0",
",",
"config_entry",
"=",
"None",
",",
"num_users",
"=",
"len",
"(",
"MOCK_USERS",
")",
",",
"session_type",
"=",
"\"video\"",
",",
")",
":",
"if",
"config_entry",
":",
"self",
".",
"_data",
"=",
"config_entry",
".",
"data",
"else",
":",
"self",
".",
"_data",
"=",
"DEFAULT_DATA",
"self",
".",
"_baseurl",
"=",
"self",
".",
"_data",
"[",
"PLEX_SERVER_CONFIG",
"]",
"[",
"CONF_URL",
"]",
"self",
".",
"friendlyName",
"=",
"self",
".",
"_data",
"[",
"CONF_SERVER",
"]",
"self",
".",
"machineIdentifier",
"=",
"self",
".",
"_data",
"[",
"CONF_SERVER_IDENTIFIER",
"]",
"self",
".",
"_systemAccounts",
"=",
"list",
"(",
"map",
"(",
"MockPlexSystemAccount",
",",
"range",
"(",
"num_users",
")",
")",
")",
"self",
".",
"_clients",
"=",
"[",
"]",
"self",
".",
"_session",
"=",
"None",
"self",
".",
"_sessions",
"=",
"[",
"]",
"self",
".",
"set_clients",
"(",
"num_users",
")",
"self",
".",
"set_sessions",
"(",
"num_users",
",",
"session_type",
")",
"self",
".",
"_cache",
"=",
"{",
"}"
] | [
162,
4
] | [
187,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.set_clients | (self, num_clients) | Set up mock PlexClients for this PlexServer. | Set up mock PlexClients for this PlexServer. | def set_clients(self, num_clients):
"""Set up mock PlexClients for this PlexServer."""
self._clients = [
MockPlexClient(baseurl=self._baseurl, index=x) for x in range(num_clients)
] | [
"def",
"set_clients",
"(",
"self",
",",
"num_clients",
")",
":",
"self",
".",
"_clients",
"=",
"[",
"MockPlexClient",
"(",
"baseurl",
"=",
"self",
".",
"_baseurl",
",",
"index",
"=",
"x",
")",
"for",
"x",
"in",
"range",
"(",
"num_clients",
")",
"]"
] | [
189,
4
] | [
193,
9
] | python | en | ['en', 'fr', 'en'] | True |
MockPlexServer.set_sessions | (self, num_sessions, session_type) | Set up mock PlexSessions for this PlexServer. | Set up mock PlexSessions for this PlexServer. | def set_sessions(self, num_sessions, session_type):
"""Set up mock PlexSessions for this PlexServer."""
self._sessions = [
MockPlexSession(self._clients[x], mediatype=session_type, index=x)
for x in range(num_sessions)
] | [
"def",
"set_sessions",
"(",
"self",
",",
"num_sessions",
",",
"session_type",
")",
":",
"self",
".",
"_sessions",
"=",
"[",
"MockPlexSession",
"(",
"self",
".",
"_clients",
"[",
"x",
"]",
",",
"mediatype",
"=",
"session_type",
",",
"index",
"=",
"x",
")",
"for",
"x",
"in",
"range",
"(",
"num_sessions",
")",
"]"
] | [
195,
4
] | [
200,
9
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.clear_clients | (self) | Clear all active PlexClients. | Clear all active PlexClients. | def clear_clients(self):
"""Clear all active PlexClients."""
self._clients = [] | [
"def",
"clear_clients",
"(",
"self",
")",
":",
"self",
".",
"_clients",
"=",
"[",
"]"
] | [
202,
4
] | [
204,
26
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.clear_sessions | (self) | Clear all active PlexSessions. | Clear all active PlexSessions. | def clear_sessions(self):
"""Clear all active PlexSessions."""
self._sessions = [] | [
"def",
"clear_sessions",
"(",
"self",
")",
":",
"self",
".",
"_sessions",
"=",
"[",
"]"
] | [
206,
4
] | [
208,
27
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.clients | (self) | Mock the clients method. | Mock the clients method. | def clients(self):
"""Mock the clients method."""
return self._clients | [
"def",
"clients",
"(",
"self",
")",
":",
"return",
"self",
".",
"_clients"
] | [
210,
4
] | [
212,
28
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.createToken | (self) | Mock the createToken method. | Mock the createToken method. | def createToken(self):
"""Mock the createToken method."""
return "temporary_token" | [
"def",
"createToken",
"(",
"self",
")",
":",
"return",
"\"temporary_token\""
] | [
214,
4
] | [
216,
32
] | python | en | ['en', 'fi', 'en'] | True |
MockPlexServer.sessions | (self) | Mock the sessions method. | Mock the sessions method. | def sessions(self):
"""Mock the sessions method."""
return self._sessions | [
"def",
"sessions",
"(",
"self",
")",
":",
"return",
"self",
".",
"_sessions"
] | [
218,
4
] | [
220,
29
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.systemAccounts | (self) | Mock the systemAccounts lookup method. | Mock the systemAccounts lookup method. | def systemAccounts(self):
"""Mock the systemAccounts lookup method."""
return self._systemAccounts | [
"def",
"systemAccounts",
"(",
"self",
")",
":",
"return",
"self",
".",
"_systemAccounts"
] | [
222,
4
] | [
224,
35
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.url | (self, path, includeToken=False) | Mock method to generate a server URL. | Mock method to generate a server URL. | def url(self, path, includeToken=False):
"""Mock method to generate a server URL."""
return f"{self._baseurl}{path}" | [
"def",
"url",
"(",
"self",
",",
"path",
",",
"includeToken",
"=",
"False",
")",
":",
"return",
"f\"{self._baseurl}{path}\""
] | [
226,
4
] | [
228,
39
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.accounts | (self) | Mock the accounts property. | Mock the accounts property. | def accounts(self):
"""Mock the accounts property."""
return set(MOCK_USERS) | [
"def",
"accounts",
"(",
"self",
")",
":",
"return",
"set",
"(",
"MOCK_USERS",
")"
] | [
231,
4
] | [
233,
30
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.version | (self) | Mock version of PlexServer. | Mock version of PlexServer. | def version(self):
"""Mock version of PlexServer."""
return "1.0" | [
"def",
"version",
"(",
"self",
")",
":",
"return",
"\"1.0\""
] | [
236,
4
] | [
238,
20
] | python | en | ['en', 'sv', 'en'] | True |
MockPlexServer.library | (self) | Mock library object of PlexServer. | Mock library object of PlexServer. | def library(self):
"""Mock library object of PlexServer."""
return MockPlexLibrary(self) | [
"def",
"library",
"(",
"self",
")",
":",
"return",
"MockPlexLibrary",
"(",
"self",
")"
] | [
241,
4
] | [
243,
36
] | python | en | ['en', 'fy', 'en'] | True |
MockPlexServer.playlist | (self, playlist) | Mock the playlist lookup method. | Mock the playlist lookup method. | def playlist(self, playlist):
"""Mock the playlist lookup method."""
return MockPlexMediaItem(playlist, mediatype="playlist") | [
"def",
"playlist",
"(",
"self",
",",
"playlist",
")",
":",
"return",
"MockPlexMediaItem",
"(",
"playlist",
",",
"mediatype",
"=",
"\"playlist\"",
")"
] | [
245,
4
] | [
247,
64
] | python | en | ['en', 'et', 'en'] | True |
MockPlexServer.playlists | (self) | Mock the playlists lookup method with a lazy init. | Mock the playlists lookup method with a lazy init. | def playlists(self):
"""Mock the playlists lookup method with a lazy init."""
return [
MockPlexPlaylist(
self.library.section("Movies").all()
+ self.library.section("TV Shows").all()
),
MockPlexPlaylist(self.library.section("Music").all()),
] | [
"def",
"playlists",
"(",
"self",
")",
":",
"return",
"[",
"MockPlexPlaylist",
"(",
"self",
".",
"library",
".",
"section",
"(",
"\"Movies\"",
")",
".",
"all",
"(",
")",
"+",
"self",
".",
"library",
".",
"section",
"(",
"\"TV Shows\"",
")",
".",
"all",
"(",
")",
")",
",",
"MockPlexPlaylist",
"(",
"self",
".",
"library",
".",
"section",
"(",
"\"Music\"",
")",
".",
"all",
"(",
")",
")",
",",
"]"
] | [
250,
4
] | [
258,
9
] | python | en | ['en', 'en', 'en'] | True |
MockPlexServer.fetchItem | (self, item) | Mock the fetchItem method. | Mock the fetchItem method. | def fetchItem(self, item):
"""Mock the fetchItem method."""
for section in self.library.sections():
result = section.fetchItem(item)
if result:
return result | [
"def",
"fetchItem",
"(",
"self",
",",
"item",
")",
":",
"for",
"section",
"in",
"self",
".",
"library",
".",
"sections",
"(",
")",
":",
"result",
"=",
"section",
".",
"fetchItem",
"(",
"item",
")",
"if",
"result",
":",
"return",
"result"
] | [
260,
4
] | [
265,
29
] | python | en | ['en', 'da', 'en'] | True |
MockPlexClient.__init__ | (self, server=None, baseurl=None, token=None, index=0) | Initialize the object. | Initialize the object. | def __init__(self, server=None, baseurl=None, token=None, index=0):
"""Initialize the object."""
self.machineIdentifier = f"client-{index+1}"
self._baseurl = baseurl
self._index = index | [
"def",
"__init__",
"(",
"self",
",",
"server",
"=",
"None",
",",
"baseurl",
"=",
"None",
",",
"token",
"=",
"None",
",",
"index",
"=",
"0",
")",
":",
"self",
".",
"machineIdentifier",
"=",
"f\"client-{index+1}\"",
"self",
".",
"_baseurl",
"=",
"baseurl",
"self",
".",
"_index",
"=",
"index"
] | [
271,
4
] | [
275,
27
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.url | (self, key) | Mock the url method. | Mock the url method. | def url(self, key):
"""Mock the url method."""
return f"{self._baseurl}{key}" | [
"def",
"url",
"(",
"self",
",",
"key",
")",
":",
"return",
"f\"{self._baseurl}{key}\""
] | [
277,
4
] | [
279,
38
] | python | en | ['en', 'xh', 'en'] | True |
MockPlexClient.device | (self) | Mock the device attribute. | Mock the device attribute. | def device(self):
"""Mock the device attribute."""
return "DEVICE" | [
"def",
"device",
"(",
"self",
")",
":",
"return",
"\"DEVICE\""
] | [
282,
4
] | [
284,
23
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.platform | (self) | Mock the platform attribute. | Mock the platform attribute. | def platform(self):
"""Mock the platform attribute."""
return "PLATFORM" | [
"def",
"platform",
"(",
"self",
")",
":",
"return",
"\"PLATFORM\""
] | [
287,
4
] | [
289,
25
] | python | en | ['en', 'da', 'en'] | True |
MockPlexClient.product | (self) | Mock the product attribute. | Mock the product attribute. | def product(self):
"""Mock the product attribute."""
if self._index == 1:
return "Plex Web"
return "PRODUCT" | [
"def",
"product",
"(",
"self",
")",
":",
"if",
"self",
".",
"_index",
"==",
"1",
":",
"return",
"\"Plex Web\"",
"return",
"\"PRODUCT\""
] | [
292,
4
] | [
296,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.protocolCapabilities | (self) | Mock the protocolCapabilities attribute. | Mock the protocolCapabilities attribute. | def protocolCapabilities(self):
"""Mock the protocolCapabilities attribute."""
return ["playback"] | [
"def",
"protocolCapabilities",
"(",
"self",
")",
":",
"return",
"[",
"\"playback\"",
"]"
] | [
299,
4
] | [
301,
27
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.state | (self) | Mock the state attribute. | Mock the state attribute. | def state(self):
"""Mock the state attribute."""
return "playing" | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"\"playing\""
] | [
304,
4
] | [
306,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.title | (self) | Mock the title attribute. | Mock the title attribute. | def title(self):
"""Mock the title attribute."""
return "TITLE" | [
"def",
"title",
"(",
"self",
")",
":",
"return",
"\"TITLE\""
] | [
309,
4
] | [
311,
22
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.version | (self) | Mock the version attribute. | Mock the version attribute. | def version(self):
"""Mock the version attribute."""
return "1.0" | [
"def",
"version",
"(",
"self",
")",
":",
"return",
"\"1.0\""
] | [
314,
4
] | [
316,
20
] | python | en | ['en', 'en', 'en'] | True |
MockPlexClient.proxyThroughServer | (self, value=True, server=None) | Mock the proxyThroughServer method. | Mock the proxyThroughServer method. | def proxyThroughServer(self, value=True, server=None):
"""Mock the proxyThroughServer method."""
pass | [
"def",
"proxyThroughServer",
"(",
"self",
",",
"value",
"=",
"True",
",",
"server",
"=",
"None",
")",
":",
"pass"
] | [
318,
4
] | [
320,
12
] | python | en | ['en', 'be', 'en'] | True |
MockPlexClient.playMedia | (self, item) | Mock the playMedia method. | Mock the playMedia method. | def playMedia(self, item):
"""Mock the playMedia method."""
pass | [
"def",
"playMedia",
"(",
"self",
",",
"item",
")",
":",
"pass"
] | [
322,
4
] | [
324,
12
] | python | en | ['en', 'xh', 'en'] | True |
MockPlexSession.__init__ | (self, player, mediatype, index=0) | Initialize the object. | Initialize the object. | def __init__(self, player, mediatype, index=0):
"""Initialize the object."""
self.TYPE = mediatype
self.usernames = [list(MOCK_USERS)[index]]
self.players = [player]
self._section = MockPlexLibrarySection("Movies") | [
"def",
"__init__",
"(",
"self",
",",
"player",
",",
"mediatype",
",",
"index",
"=",
"0",
")",
":",
"self",
".",
"TYPE",
"=",
"mediatype",
"self",
".",
"usernames",
"=",
"[",
"list",
"(",
"MOCK_USERS",
")",
"[",
"index",
"]",
"]",
"self",
".",
"players",
"=",
"[",
"player",
"]",
"self",
".",
"_section",
"=",
"MockPlexLibrarySection",
"(",
"\"Movies\"",
")"
] | [
330,
4
] | [
335,
56
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.duration | (self) | Mock the duration attribute. | Mock the duration attribute. | def duration(self):
"""Mock the duration attribute."""
return 10000000 | [
"def",
"duration",
"(",
"self",
")",
":",
"return",
"10000000"
] | [
338,
4
] | [
340,
23
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.librarySectionID | (self) | Mock the librarySectionID attribute. | Mock the librarySectionID attribute. | def librarySectionID(self):
"""Mock the librarySectionID attribute."""
return 1 | [
"def",
"librarySectionID",
"(",
"self",
")",
":",
"return",
"1"
] | [
343,
4
] | [
345,
16
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.ratingKey | (self) | Mock the ratingKey attribute. | Mock the ratingKey attribute. | def ratingKey(self):
"""Mock the ratingKey attribute."""
return 123 | [
"def",
"ratingKey",
"(",
"self",
")",
":",
"return",
"123"
] | [
348,
4
] | [
350,
18
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.section | (self) | Mock the section method. | Mock the section method. | def section(self):
"""Mock the section method."""
return self._section | [
"def",
"section",
"(",
"self",
")",
":",
"return",
"self",
".",
"_section"
] | [
352,
4
] | [
354,
28
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.summary | (self) | Mock the summary attribute. | Mock the summary attribute. | def summary(self):
"""Mock the summary attribute."""
return "SUMMARY" | [
"def",
"summary",
"(",
"self",
")",
":",
"return",
"\"SUMMARY\""
] | [
357,
4
] | [
359,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.thumbUrl | (self) | Mock the thumbUrl attribute. | Mock the thumbUrl attribute. | def thumbUrl(self):
"""Mock the thumbUrl attribute."""
return "http://1.2.3.4/thumb" | [
"def",
"thumbUrl",
"(",
"self",
")",
":",
"return",
"\"http://1.2.3.4/thumb\""
] | [
362,
4
] | [
364,
37
] | python | en | ['en', 'sq', 'en'] | True |
MockPlexSession.title | (self) | Mock the title attribute. | Mock the title attribute. | def title(self):
"""Mock the title attribute."""
return "TITLE" | [
"def",
"title",
"(",
"self",
")",
":",
"return",
"\"TITLE\""
] | [
367,
4
] | [
369,
22
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.type | (self) | Mock the type attribute. | Mock the type attribute. | def type(self):
"""Mock the type attribute."""
return "movie" | [
"def",
"type",
"(",
"self",
")",
":",
"return",
"\"movie\""
] | [
372,
4
] | [
374,
22
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.viewOffset | (self) | Mock the viewOffset attribute. | Mock the viewOffset attribute. | def viewOffset(self):
"""Mock the viewOffset attribute."""
return 0 | [
"def",
"viewOffset",
"(",
"self",
")",
":",
"return",
"0"
] | [
377,
4
] | [
379,
16
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSession.year | (self) | Mock the year attribute. | Mock the year attribute. | def year(self):
"""Mock the year attribute."""
return 2020 | [
"def",
"year",
"(",
"self",
")",
":",
"return",
"2020"
] | [
382,
4
] | [
384,
19
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrary.__init__ | (self, plex_server) | Initialize the object. | Initialize the object. | def __init__(self, plex_server):
"""Initialize the object."""
self._plex_server = plex_server
self._sections = {}
for kind in ["Movies", "Music", "TV Shows", "Photos"]:
self._sections[kind] = MockPlexLibrarySection(kind) | [
"def",
"__init__",
"(",
"self",
",",
"plex_server",
")",
":",
"self",
".",
"_plex_server",
"=",
"plex_server",
"self",
".",
"_sections",
"=",
"{",
"}",
"for",
"kind",
"in",
"[",
"\"Movies\"",
",",
"\"Music\"",
",",
"\"TV Shows\"",
",",
"\"Photos\"",
"]",
":",
"self",
".",
"_sections",
"[",
"kind",
"]",
"=",
"MockPlexLibrarySection",
"(",
"kind",
")"
] | [
390,
4
] | [
396,
63
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrary.section | (self, title) | Mock the LibrarySection lookup. | Mock the LibrarySection lookup. | def section(self, title):
"""Mock the LibrarySection lookup."""
section = self._sections.get(title)
if section:
return section
raise NotFound | [
"def",
"section",
"(",
"self",
",",
"title",
")",
":",
"section",
"=",
"self",
".",
"_sections",
".",
"get",
"(",
"title",
")",
"if",
"section",
":",
"return",
"section",
"raise",
"NotFound"
] | [
398,
4
] | [
403,
22
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrary.sections | (self) | Return all available sections. | Return all available sections. | def sections(self):
"""Return all available sections."""
return self._sections.values() | [
"def",
"sections",
"(",
"self",
")",
":",
"return",
"self",
".",
"_sections",
".",
"values",
"(",
")"
] | [
405,
4
] | [
407,
38
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrary.sectionByID | (self, section_id) | Mock the sectionByID lookup. | Mock the sectionByID lookup. | def sectionByID(self, section_id):
"""Mock the sectionByID lookup."""
return [x for x in self.sections() if x.key == section_id][0] | [
"def",
"sectionByID",
"(",
"self",
",",
"section_id",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"sections",
"(",
")",
"if",
"x",
".",
"key",
"==",
"section_id",
"]",
"[",
"0",
"]"
] | [
409,
4
] | [
411,
69
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrary.onDeck | (self) | Mock an empty On Deck folder. | Mock an empty On Deck folder. | def onDeck(self):
"""Mock an empty On Deck folder."""
return [] | [
"def",
"onDeck",
"(",
"self",
")",
":",
"return",
"[",
"]"
] | [
413,
4
] | [
415,
17
] | python | en | ['en', 'fy', 'en'] | True |
MockPlexLibrary.recentlyAdded | (self) | Mock an empty Recently Added folder. | Mock an empty Recently Added folder. | def recentlyAdded(self):
"""Mock an empty Recently Added folder."""
return [] | [
"def",
"recentlyAdded",
"(",
"self",
")",
":",
"return",
"[",
"]"
] | [
417,
4
] | [
419,
17
] | python | en | ['en', 'cy', 'en'] | True |
MockPlexLibrarySection.__init__ | (self, library) | Initialize the object. | Initialize the object. | def __init__(self, library):
"""Initialize the object."""
self.title = library
if library == "Music":
self._item = MockPlexArtist("Artist")
elif library == "TV Shows":
self._item = MockPlexShow("TV Show")
else:
self._item = MockPlexMediaItem(library[:-1]) | [
"def",
"__init__",
"(",
"self",
",",
"library",
")",
":",
"self",
".",
"title",
"=",
"library",
"if",
"library",
"==",
"\"Music\"",
":",
"self",
".",
"_item",
"=",
"MockPlexArtist",
"(",
"\"Artist\"",
")",
"elif",
"library",
"==",
"\"TV Shows\"",
":",
"self",
".",
"_item",
"=",
"MockPlexShow",
"(",
"\"TV Show\"",
")",
"else",
":",
"self",
".",
"_item",
"=",
"MockPlexMediaItem",
"(",
"library",
"[",
":",
"-",
"1",
"]",
")"
] | [
425,
4
] | [
434,
56
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.get | (self, query) | Mock the get lookup method. | Mock the get lookup method. | def get(self, query):
"""Mock the get lookup method."""
if self._item.title == query:
return self._item
raise NotFound | [
"def",
"get",
"(",
"self",
",",
"query",
")",
":",
"if",
"self",
".",
"_item",
".",
"title",
"==",
"query",
":",
"return",
"self",
".",
"_item",
"raise",
"NotFound"
] | [
436,
4
] | [
440,
22
] | python | en | ['en', 'nl', 'en'] | True |
MockPlexLibrarySection.all | (self) | Mock the all method. | Mock the all method. | def all(self):
"""Mock the all method."""
return [self._item] | [
"def",
"all",
"(",
"self",
")",
":",
"return",
"[",
"self",
".",
"_item",
"]"
] | [
442,
4
] | [
444,
27
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.fetchItem | (self, ratingKey) | Return a specific item. | Return a specific item. | def fetchItem(self, ratingKey):
"""Return a specific item."""
for item in self.all():
if item.ratingKey == ratingKey:
return item
if item._children:
for child in item._children:
if child.ratingKey == ratingKey:
return child | [
"def",
"fetchItem",
"(",
"self",
",",
"ratingKey",
")",
":",
"for",
"item",
"in",
"self",
".",
"all",
"(",
")",
":",
"if",
"item",
".",
"ratingKey",
"==",
"ratingKey",
":",
"return",
"item",
"if",
"item",
".",
"_children",
":",
"for",
"child",
"in",
"item",
".",
"_children",
":",
"if",
"child",
".",
"ratingKey",
"==",
"ratingKey",
":",
"return",
"child"
] | [
446,
4
] | [
454,
36
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.onDeck | (self) | Mock an empty On Deck folder. | Mock an empty On Deck folder. | def onDeck(self):
"""Mock an empty On Deck folder."""
return [] | [
"def",
"onDeck",
"(",
"self",
")",
":",
"return",
"[",
"]"
] | [
456,
4
] | [
458,
17
] | python | en | ['en', 'fy', 'en'] | True |
MockPlexLibrarySection.recentlyAdded | (self) | Mock an empty Recently Added folder. | Mock an empty Recently Added folder. | def recentlyAdded(self):
"""Mock an empty Recently Added folder."""
return self.all() | [
"def",
"recentlyAdded",
"(",
"self",
")",
":",
"return",
"self",
".",
"all",
"(",
")"
] | [
460,
4
] | [
462,
25
] | python | en | ['en', 'cy', 'en'] | True |
MockPlexLibrarySection.type | (self) | Mock the library type. | Mock the library type. | def type(self):
"""Mock the library type."""
if self.title == "Movies":
return "movie"
if self.title == "Music":
return "artist"
if self.title == "TV Shows":
return "show"
if self.title == "Photos":
return "photo" | [
"def",
"type",
"(",
"self",
")",
":",
"if",
"self",
".",
"title",
"==",
"\"Movies\"",
":",
"return",
"\"movie\"",
"if",
"self",
".",
"title",
"==",
"\"Music\"",
":",
"return",
"\"artist\"",
"if",
"self",
".",
"title",
"==",
"\"TV Shows\"",
":",
"return",
"\"show\"",
"if",
"self",
".",
"title",
"==",
"\"Photos\"",
":",
"return",
"\"photo\""
] | [
465,
4
] | [
474,
26
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.TYPE | (self) | Return the library type. | Return the library type. | def TYPE(self):
"""Return the library type."""
return self.type | [
"def",
"TYPE",
"(",
"self",
")",
":",
"return",
"self",
".",
"type"
] | [
477,
4
] | [
479,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.key | (self) | Mock the key identifier property. | Mock the key identifier property. | def key(self):
"""Mock the key identifier property."""
return str(id(self.title)) | [
"def",
"key",
"(",
"self",
")",
":",
"return",
"str",
"(",
"id",
"(",
"self",
".",
"title",
")",
")"
] | [
482,
4
] | [
484,
34
] | python | en | ['en', 'fy', 'en'] | True |
MockPlexLibrarySection.search | (self, **kwargs) | Mock the LibrarySection search method. | Mock the LibrarySection search method. | def search(self, **kwargs):
"""Mock the LibrarySection search method."""
if kwargs.get("libtype") == "movie":
return self.all() | [
"def",
"search",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(",
"\"libtype\"",
")",
"==",
"\"movie\"",
":",
"return",
"self",
".",
"all",
"(",
")"
] | [
486,
4
] | [
489,
29
] | python | en | ['en', 'en', 'en'] | True |
MockPlexLibrarySection.update | (self) | Mock the update call. | Mock the update call. | def update(self):
"""Mock the update call."""
pass | [
"def",
"update",
"(",
"self",
")",
":",
"pass"
] | [
491,
4
] | [
493,
12
] | python | en | ['en', 'en', 'en'] | True |
MockPlexMediaItem.__init__ | (self, title, mediatype="video", year=2020) | Initialize the object. | Initialize the object. | def __init__(self, title, mediatype="video", year=2020):
"""Initialize the object."""
self.title = str(title)
self.type = mediatype
self.thumbUrl = "http://1.2.3.4/thumb.png"
self.year = year
self._children = [] | [
"def",
"__init__",
"(",
"self",
",",
"title",
",",
"mediatype",
"=",
"\"video\"",
",",
"year",
"=",
"2020",
")",
":",
"self",
".",
"title",
"=",
"str",
"(",
"title",
")",
"self",
".",
"type",
"=",
"mediatype",
"self",
".",
"thumbUrl",
"=",
"\"http://1.2.3.4/thumb.png\"",
"self",
".",
"year",
"=",
"year",
"self",
".",
"_children",
"=",
"[",
"]"
] | [
499,
4
] | [
505,
27
] | python | en | ['en', 'en', 'en'] | True |
MockPlexMediaItem.__iter__ | (self) | Provide iterator. | Provide iterator. | def __iter__(self):
"""Provide iterator."""
yield from self._children | [
"def",
"__iter__",
"(",
"self",
")",
":",
"yield",
"from",
"self",
".",
"_children"
] | [
507,
4
] | [
509,
33
] | python | en | ['en', 'it', 'en'] | False |
MockPlexMediaItem.ratingKey | (self) | Mock the ratingKey property. | Mock the ratingKey property. | def ratingKey(self):
"""Mock the ratingKey property."""
return id(self.title) | [
"def",
"ratingKey",
"(",
"self",
")",
":",
"return",
"id",
"(",
"self",
".",
"title",
")"
] | [
512,
4
] | [
514,
29
] | python | en | ['en', 'en', 'en'] | True |
MockPlexPlaylist.__init__ | (self, items) | Initialize the object. | Initialize the object. | def __init__(self, items):
"""Initialize the object."""
super().__init__(f"Playlist ({len(items)} Items)", "playlist")
for item in items:
self._children.append(item) | [
"def",
"__init__",
"(",
"self",
",",
"items",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"f\"Playlist ({len(items)} Items)\"",
",",
"\"playlist\"",
")",
"for",
"item",
"in",
"items",
":",
"self",
".",
"_children",
".",
"append",
"(",
"item",
")"
] | [
520,
4
] | [
524,
39
] | python | en | ['en', 'en', 'en'] | True |
MockPlexShow.__init__ | (self, show) | Initialize the object. | Initialize the object. | def __init__(self, show):
"""Initialize the object."""
super().__init__(show, "show")
for index in range(1, 5):
self._children.append(MockPlexSeason(index)) | [
"def",
"__init__",
"(",
"self",
",",
"show",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"show",
",",
"\"show\"",
")",
"for",
"index",
"in",
"range",
"(",
"1",
",",
"5",
")",
":",
"self",
".",
"_children",
".",
"append",
"(",
"MockPlexSeason",
"(",
"index",
")",
")"
] | [
530,
4
] | [
534,
56
] | python | en | ['en', 'en', 'en'] | True |
MockPlexShow.season | (self, season) | Mock the season lookup method. | Mock the season lookup method. | def season(self, season):
"""Mock the season lookup method."""
return [x for x in self._children if x.title == f"Season {season}"][0] | [
"def",
"season",
"(",
"self",
",",
"season",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_children",
"if",
"x",
".",
"title",
"==",
"f\"Season {season}\"",
"]",
"[",
"0",
"]"
] | [
536,
4
] | [
538,
78
] | python | en | ['en', 'xh', 'en'] | True |
MockPlexSeason.__init__ | (self, season) | Initialize the object. | Initialize the object. | def __init__(self, season):
"""Initialize the object."""
super().__init__(f"Season {season}", "season")
for index in range(1, 10):
self._children.append(MockPlexMediaItem(f"Episode {index}", "episode")) | [
"def",
"__init__",
"(",
"self",
",",
"season",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"f\"Season {season}\"",
",",
"\"season\"",
")",
"for",
"index",
"in",
"range",
"(",
"1",
",",
"10",
")",
":",
"self",
".",
"_children",
".",
"append",
"(",
"MockPlexMediaItem",
"(",
"f\"Episode {index}\"",
",",
"\"episode\"",
")",
")"
] | [
544,
4
] | [
548,
83
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSeason.episode | (self, episode) | Mock the episode lookup method. | Mock the episode lookup method. | def episode(self, episode):
"""Mock the episode lookup method."""
return self._children[episode - 1] | [
"def",
"episode",
"(",
"self",
",",
"episode",
")",
":",
"return",
"self",
".",
"_children",
"[",
"episode",
"-",
"1",
"]"
] | [
550,
4
] | [
552,
42
] | python | en | ['en', 'xh', 'en'] | True |
MockPlexAlbum.__init__ | (self, album) | Initialize the object. | Initialize the object. | def __init__(self, album):
"""Initialize the object."""
super().__init__(album, "album")
for index in range(1, 10):
self._children.append(MockPlexMediaTrack(index)) | [
"def",
"__init__",
"(",
"self",
",",
"album",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"album",
",",
"\"album\"",
")",
"for",
"index",
"in",
"range",
"(",
"1",
",",
"10",
")",
":",
"self",
".",
"_children",
".",
"append",
"(",
"MockPlexMediaTrack",
"(",
"index",
")",
")"
] | [
558,
4
] | [
562,
60
] | python | en | ['en', 'en', 'en'] | True |
MockPlexAlbum.track | (self, track) | Mock the track lookup method. | Mock the track lookup method. | def track(self, track):
"""Mock the track lookup method."""
try:
return [x for x in self._children if x.title == track][0]
except IndexError:
raise NotFound | [
"def",
"track",
"(",
"self",
",",
"track",
")",
":",
"try",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_children",
"if",
"x",
".",
"title",
"==",
"track",
"]",
"[",
"0",
"]",
"except",
"IndexError",
":",
"raise",
"NotFound"
] | [
564,
4
] | [
569,
26
] | python | en | ['en', 'et', 'en'] | True |
MockPlexAlbum.tracks | (self) | Mock the tracks lookup method. | Mock the tracks lookup method. | def tracks(self):
"""Mock the tracks lookup method."""
return self._children | [
"def",
"tracks",
"(",
"self",
")",
":",
"return",
"self",
".",
"_children"
] | [
571,
4
] | [
573,
29
] | python | en | ['en', 'et', 'en'] | True |
MockPlexArtist.__init__ | (self, artist) | Initialize the object. | Initialize the object. | def __init__(self, artist):
"""Initialize the object."""
super().__init__(artist, "artist")
self._album = MockPlexAlbum("Album") | [
"def",
"__init__",
"(",
"self",
",",
"artist",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"artist",
",",
"\"artist\"",
")",
"self",
".",
"_album",
"=",
"MockPlexAlbum",
"(",
"\"Album\"",
")"
] | [
579,
4
] | [
582,
44
] | python | en | ['en', 'en', 'en'] | True |
MockPlexArtist.album | (self, album) | Mock the album lookup method. | Mock the album lookup method. | def album(self, album):
"""Mock the album lookup method."""
return self._album | [
"def",
"album",
"(",
"self",
",",
"album",
")",
":",
"return",
"self",
".",
"_album"
] | [
584,
4
] | [
586,
26
] | python | en | ['en', 'nl', 'en'] | True |
MockPlexArtist.get | (self, track) | Mock the track lookup method. | Mock the track lookup method. | def get(self, track):
"""Mock the track lookup method."""
return self._album.track(track) | [
"def",
"get",
"(",
"self",
",",
"track",
")",
":",
"return",
"self",
".",
"_album",
".",
"track",
"(",
"track",
")"
] | [
588,
4
] | [
590,
39
] | python | en | ['en', 'et', 'en'] | True |
MockPlexMediaTrack.__init__ | (self, index=1) | Initialize the object. | Initialize the object. | def __init__(self, index=1):
"""Initialize the object."""
super().__init__(f"Track {index}", "track")
self.index = index | [
"def",
"__init__",
"(",
"self",
",",
"index",
"=",
"1",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"f\"Track {index}\"",
",",
"\"track\"",
")",
"self",
".",
"index",
"=",
"index"
] | [
596,
4
] | [
599,
26
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSonosClient.__init__ | (self, name) | Initialize the object. | Initialize the object. | def __init__(self, name):
"""Initialize the object."""
self.name = name | [
"def",
"__init__",
"(",
"self",
",",
"name",
")",
":",
"self",
".",
"name",
"=",
"name"
] | [
605,
4
] | [
607,
24
] | python | en | ['en', 'en', 'en'] | True |
MockPlexSonosClient.playMedia | (self, item) | Mock the playMedia method. | Mock the playMedia method. | def playMedia(self, item):
"""Mock the playMedia method."""
pass | [
"def",
"playMedia",
"(",
"self",
",",
"item",
")",
":",
"pass"
] | [
609,
4
] | [
611,
12
] | python | en | ['en', 'xh', 'en'] | True |
create_testcase05 | () | Conversion of the physical parameter to the internally defined parameter
to be passed to george
| Conversion of the physical parameter to the internally defined parameter
to be passed to george
| def create_testcase05():
import george
bjd0 = photometry['phot_bjd'] - Tref
err = bjd0*0 + photometry['phot_precision']
""" Conversion of the physical parameter to the internally defined parameter
to be passed to george
"""
gp_pams = np.zeros(4)
gp_pams[0] = np.log(activity['Hamp_PH'])*2
gp_pams[1] = np.log(activity['Pdec'])*2
gp_pams[2] = 1. / (2*activity['Oamp'] ** 2)
gp_pams[3] = np.log(activity['Prot'])
kernel = np.exp(gp_pams[0]) * \
george.kernels.ExpSquaredKernel(metric=np.exp(gp_pams[1])) * \
george.kernels.ExpSine2Kernel(gamma=gp_pams[2], log_period=gp_pams[3])
gp = george.GP(kernel)
gp.compute(bjd0, err)
prediction = gp.sample(bjd0)
obs_photometry = np.random.normal(prediction, photometry['phot_precision'])
fileout = open('TestCase05_photometry.dat', 'w')
for b, p in zip(photometry['phot_bjd'], obs_photometry):
fileout.write('{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \n'.format(
b, p, photometry['phot_precision'], 0, 0, -1))
fileout.close() | [
"def",
"create_testcase05",
"(",
")",
":",
"import",
"george",
"bjd0",
"=",
"photometry",
"[",
"'phot_bjd'",
"]",
"-",
"Tref",
"err",
"=",
"bjd0",
"*",
"0",
"+",
"photometry",
"[",
"'phot_precision'",
"]",
"gp_pams",
"=",
"np",
".",
"zeros",
"(",
"4",
")",
"gp_pams",
"[",
"0",
"]",
"=",
"np",
".",
"log",
"(",
"activity",
"[",
"'Hamp_PH'",
"]",
")",
"*",
"2",
"gp_pams",
"[",
"1",
"]",
"=",
"np",
".",
"log",
"(",
"activity",
"[",
"'Pdec'",
"]",
")",
"*",
"2",
"gp_pams",
"[",
"2",
"]",
"=",
"1.",
"/",
"(",
"2",
"*",
"activity",
"[",
"'Oamp'",
"]",
"**",
"2",
")",
"gp_pams",
"[",
"3",
"]",
"=",
"np",
".",
"log",
"(",
"activity",
"[",
"'Prot'",
"]",
")",
"kernel",
"=",
"np",
".",
"exp",
"(",
"gp_pams",
"[",
"0",
"]",
")",
"*",
"george",
".",
"kernels",
".",
"ExpSquaredKernel",
"(",
"metric",
"=",
"np",
".",
"exp",
"(",
"gp_pams",
"[",
"1",
"]",
")",
")",
"*",
"george",
".",
"kernels",
".",
"ExpSine2Kernel",
"(",
"gamma",
"=",
"gp_pams",
"[",
"2",
"]",
",",
"log_period",
"=",
"gp_pams",
"[",
"3",
"]",
")",
"gp",
"=",
"george",
".",
"GP",
"(",
"kernel",
")",
"gp",
".",
"compute",
"(",
"bjd0",
",",
"err",
")",
"prediction",
"=",
"gp",
".",
"sample",
"(",
"bjd0",
")",
"obs_photometry",
"=",
"np",
".",
"random",
".",
"normal",
"(",
"prediction",
",",
"photometry",
"[",
"'phot_precision'",
"]",
")",
"fileout",
"=",
"open",
"(",
"'TestCase05_photometry.dat'",
",",
"'w'",
")",
"for",
"b",
",",
"p",
"in",
"zip",
"(",
"photometry",
"[",
"'phot_bjd'",
"]",
",",
"obs_photometry",
")",
":",
"fileout",
".",
"write",
"(",
"'{0:14f} {1:14f} {2:14f} {3:5d} {4:5d} {5:5d} \\n'",
".",
"format",
"(",
"b",
",",
"p",
",",
"photometry",
"[",
"'phot_precision'",
"]",
",",
"0",
",",
"0",
",",
"-",
"1",
")",
")",
"fileout",
".",
"close",
"(",
")"
] | [
235,
0
] | [
265,
19
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.