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 |
---|---|---|---|---|---|---|---|---|---|---|---|
test_admin_change_password_no_user | (hass, hass_ws_client, owner_access_token) | Test that change password fails with unknown user. | Test that change password fails with unknown user. | async def test_admin_change_password_no_user(hass, hass_ws_client, owner_access_token):
"""Test that change password fails with unknown user."""
client = await hass_ws_client(hass, owner_access_token)
await client.send_json(
{
"id": 6,
"type": "config/auth_provider/homeassistant/admin_change_password",
"user_id": "non-existing",
"password": "new-pass",
}
)
result = await client.receive_json()
assert not result["success"], result
assert result["error"]["code"] == "user_not_found" | [
"async",
"def",
"test_admin_change_password_no_user",
"(",
"hass",
",",
"hass_ws_client",
",",
"owner_access_token",
")",
":",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
",",
"owner_access_token",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"6",
",",
"\"type\"",
":",
"\"config/auth_provider/homeassistant/admin_change_password\"",
",",
"\"user_id\"",
":",
"\"non-existing\"",
",",
"\"password\"",
":",
"\"new-pass\"",
",",
"}",
")",
"result",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"not",
"result",
"[",
"\"success\"",
"]",
",",
"result",
"assert",
"result",
"[",
"\"error\"",
"]",
"[",
"\"code\"",
"]",
"==",
"\"user_not_found\""
] | [
338,
0
] | [
353,
54
] | python | en | ['en', 'en', 'en'] | True |
test_admin_change_password_no_cred | (
hass, hass_ws_client, owner_access_token, hass_admin_user
) | Test that change password fails with unknown credential. | Test that change password fails with unknown credential. | async def test_admin_change_password_no_cred(
hass, hass_ws_client, owner_access_token, hass_admin_user
):
"""Test that change password fails with unknown credential."""
client = await hass_ws_client(hass, owner_access_token)
await client.send_json(
{
"id": 6,
"type": "config/auth_provider/homeassistant/admin_change_password",
"user_id": hass_admin_user.id,
"password": "new-pass",
}
)
result = await client.receive_json()
assert not result["success"], result
assert result["error"]["code"] == "credentials_not_found" | [
"async",
"def",
"test_admin_change_password_no_cred",
"(",
"hass",
",",
"hass_ws_client",
",",
"owner_access_token",
",",
"hass_admin_user",
")",
":",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
",",
"owner_access_token",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"6",
",",
"\"type\"",
":",
"\"config/auth_provider/homeassistant/admin_change_password\"",
",",
"\"user_id\"",
":",
"hass_admin_user",
".",
"id",
",",
"\"password\"",
":",
"\"new-pass\"",
",",
"}",
")",
"result",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"not",
"result",
"[",
"\"success\"",
"]",
",",
"result",
"assert",
"result",
"[",
"\"error\"",
"]",
"[",
"\"code\"",
"]",
"==",
"\"credentials_not_found\""
] | [
356,
0
] | [
373,
61
] | python | en | ['en', 'en', 'en'] | True |
test_admin_change_password | (
hass,
hass_ws_client,
owner_access_token,
auth_provider,
test_user_credential,
hass_admin_user,
) | Test that owners can change any password. | Test that owners can change any password. | async def test_admin_change_password(
hass,
hass_ws_client,
owner_access_token,
auth_provider,
test_user_credential,
hass_admin_user,
):
"""Test that owners can change any password."""
await hass.auth.async_link_user(hass_admin_user, test_user_credential)
client = await hass_ws_client(hass, owner_access_token)
await client.send_json(
{
"id": 6,
"type": "config/auth_provider/homeassistant/admin_change_password",
"user_id": hass_admin_user.id,
"password": "new-pass",
}
)
result = await client.receive_json()
assert result["success"], result
await auth_provider.async_validate_login("test-user", "new-pass") | [
"async",
"def",
"test_admin_change_password",
"(",
"hass",
",",
"hass_ws_client",
",",
"owner_access_token",
",",
"auth_provider",
",",
"test_user_credential",
",",
"hass_admin_user",
",",
")",
":",
"await",
"hass",
".",
"auth",
".",
"async_link_user",
"(",
"hass_admin_user",
",",
"test_user_credential",
")",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
",",
"owner_access_token",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"6",
",",
"\"type\"",
":",
"\"config/auth_provider/homeassistant/admin_change_password\"",
",",
"\"user_id\"",
":",
"hass_admin_user",
".",
"id",
",",
"\"password\"",
":",
"\"new-pass\"",
",",
"}",
")",
"result",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"result",
"[",
"\"success\"",
"]",
",",
"result",
"await",
"auth_provider",
".",
"async_validate_login",
"(",
"\"test-user\"",
",",
"\"new-pass\"",
")"
] | [
376,
0
] | [
401,
69
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up forked-daapd from a config entry. | Set up forked-daapd from a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up forked-daapd from a config entry."""
host = config_entry.data[CONF_HOST]
port = config_entry.data[CONF_PORT]
password = config_entry.data[CONF_PASSWORD]
forked_daapd_api = ForkedDaapdAPI(
async_get_clientsession(hass), host, port, password
)
forked_daapd_master = ForkedDaapdMaster(
clientsession=async_get_clientsession(hass),
api=forked_daapd_api,
ip_address=host,
api_port=port,
api_password=password,
config_entry=config_entry,
)
@callback
def async_add_zones(api, outputs):
zone_entities = []
for output in outputs:
zone_entities.append(ForkedDaapdZone(api, output, config_entry.entry_id))
async_add_entities(zone_entities, False)
remove_add_zones_listener = async_dispatcher_connect(
hass, SIGNAL_ADD_ZONES.format(config_entry.entry_id), async_add_zones
)
remove_entry_listener = config_entry.add_update_listener(update_listener)
if not hass.data.get(DOMAIN):
hass.data[DOMAIN] = {config_entry.entry_id: {}}
hass.data[DOMAIN][config_entry.entry_id] = {
HASS_DATA_REMOVE_LISTENERS_KEY: [
remove_add_zones_listener,
remove_entry_listener,
]
}
async_add_entities([forked_daapd_master], False)
forked_daapd_updater = ForkedDaapdUpdater(
hass, forked_daapd_api, config_entry.entry_id
)
await forked_daapd_updater.async_init()
hass.data[DOMAIN][config_entry.entry_id][
HASS_DATA_UPDATER_KEY
] = forked_daapd_updater | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"host",
"=",
"config_entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"port",
"=",
"config_entry",
".",
"data",
"[",
"CONF_PORT",
"]",
"password",
"=",
"config_entry",
".",
"data",
"[",
"CONF_PASSWORD",
"]",
"forked_daapd_api",
"=",
"ForkedDaapdAPI",
"(",
"async_get_clientsession",
"(",
"hass",
")",
",",
"host",
",",
"port",
",",
"password",
")",
"forked_daapd_master",
"=",
"ForkedDaapdMaster",
"(",
"clientsession",
"=",
"async_get_clientsession",
"(",
"hass",
")",
",",
"api",
"=",
"forked_daapd_api",
",",
"ip_address",
"=",
"host",
",",
"api_port",
"=",
"port",
",",
"api_password",
"=",
"password",
",",
"config_entry",
"=",
"config_entry",
",",
")",
"@",
"callback",
"def",
"async_add_zones",
"(",
"api",
",",
"outputs",
")",
":",
"zone_entities",
"=",
"[",
"]",
"for",
"output",
"in",
"outputs",
":",
"zone_entities",
".",
"append",
"(",
"ForkedDaapdZone",
"(",
"api",
",",
"output",
",",
"config_entry",
".",
"entry_id",
")",
")",
"async_add_entities",
"(",
"zone_entities",
",",
"False",
")",
"remove_add_zones_listener",
"=",
"async_dispatcher_connect",
"(",
"hass",
",",
"SIGNAL_ADD_ZONES",
".",
"format",
"(",
"config_entry",
".",
"entry_id",
")",
",",
"async_add_zones",
")",
"remove_entry_listener",
"=",
"config_entry",
".",
"add_update_listener",
"(",
"update_listener",
")",
"if",
"not",
"hass",
".",
"data",
".",
"get",
"(",
"DOMAIN",
")",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"{",
"config_entry",
".",
"entry_id",
":",
"{",
"}",
"}",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"=",
"{",
"HASS_DATA_REMOVE_LISTENERS_KEY",
":",
"[",
"remove_add_zones_listener",
",",
"remove_entry_listener",
",",
"]",
"}",
"async_add_entities",
"(",
"[",
"forked_daapd_master",
"]",
",",
"False",
")",
"forked_daapd_updater",
"=",
"ForkedDaapdUpdater",
"(",
"hass",
",",
"forked_daapd_api",
",",
"config_entry",
".",
"entry_id",
")",
"await",
"forked_daapd_updater",
".",
"async_init",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"[",
"HASS_DATA_UPDATER_KEY",
"]",
"=",
"forked_daapd_updater"
] | [
64,
0
] | [
108,
28
] | python | en | ['en', 'en', 'en'] | True |
update_listener | (hass, entry) | Handle options update. | Handle options update. | async def update_listener(hass, entry):
"""Handle options update."""
async_dispatcher_send(
hass, SIGNAL_CONFIG_OPTIONS_UPDATE.format(entry.entry_id), entry.options
) | [
"async",
"def",
"update_listener",
"(",
"hass",
",",
"entry",
")",
":",
"async_dispatcher_send",
"(",
"hass",
",",
"SIGNAL_CONFIG_OPTIONS_UPDATE",
".",
"format",
"(",
"entry",
".",
"entry_id",
")",
",",
"entry",
".",
"options",
")"
] | [
111,
0
] | [
115,
5
] | python | en | ['en', 'nl', 'en'] | True |
ForkedDaapdZone.__init__ | (self, api, output, entry_id) | Initialize the ForkedDaapd Zone. | Initialize the ForkedDaapd Zone. | def __init__(self, api, output, entry_id):
"""Initialize the ForkedDaapd Zone."""
self._api = api
self._output = output
self._output_id = output["id"]
self._last_volume = DEFAULT_UNMUTE_VOLUME # used for mute/unmute
self._available = True
self._entry_id = entry_id | [
"def",
"__init__",
"(",
"self",
",",
"api",
",",
"output",
",",
"entry_id",
")",
":",
"self",
".",
"_api",
"=",
"api",
"self",
".",
"_output",
"=",
"output",
"self",
".",
"_output_id",
"=",
"output",
"[",
"\"id\"",
"]",
"self",
".",
"_last_volume",
"=",
"DEFAULT_UNMUTE_VOLUME",
"# used for mute/unmute",
"self",
".",
"_available",
"=",
"True",
"self",
".",
"_entry_id",
"=",
"entry_id"
] | [
121,
4
] | [
128,
33
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.async_added_to_hass | (self) | Use lifecycle hooks. | Use lifecycle hooks. | async def async_added_to_hass(self):
"""Use lifecycle hooks."""
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_OUTPUTS.format(self._entry_id),
self._async_update_output_callback,
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_OUTPUTS",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"self",
".",
"_async_update_output_callback",
",",
")",
")"
] | [
130,
4
] | [
138,
9
] | python | en | ['en', 'zu', 'en'] | True |
ForkedDaapdZone.unique_id | (self) | Return unique ID. | Return unique ID. | def unique_id(self):
"""Return unique ID."""
return f"{self._entry_id}-{self._output_id}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self._entry_id}-{self._output_id}\""
] | [
151,
4
] | [
153,
52
] | python | en | ['fr', 'la', 'en'] | False |
ForkedDaapdZone.should_poll | (self) | Entity pushes its state to HA. | Entity pushes its state to HA. | def should_poll(self) -> bool:
"""Entity pushes its state to HA."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
156,
4
] | [
158,
20
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.async_toggle | (self) | Toggle the power on the zone. | Toggle the power on the zone. | async def async_toggle(self):
"""Toggle the power on the zone."""
if self.state == STATE_OFF:
await self.async_turn_on()
else:
await self.async_turn_off() | [
"async",
"def",
"async_toggle",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"STATE_OFF",
":",
"await",
"self",
".",
"async_turn_on",
"(",
")",
"else",
":",
"await",
"self",
".",
"async_turn_off",
"(",
")"
] | [
160,
4
] | [
165,
39
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.available | (self) | Return whether the zone is available. | Return whether the zone is available. | def available(self) -> bool:
"""Return whether the zone is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_available"
] | [
168,
4
] | [
170,
30
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.async_turn_on | (self) | Enable the output. | Enable the output. | async def async_turn_on(self):
"""Enable the output."""
await self._api.change_output(self._output_id, selected=True) | [
"async",
"def",
"async_turn_on",
"(",
"self",
")",
":",
"await",
"self",
".",
"_api",
".",
"change_output",
"(",
"self",
".",
"_output_id",
",",
"selected",
"=",
"True",
")"
] | [
172,
4
] | [
174,
69
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.async_turn_off | (self) | Disable the output. | Disable the output. | async def async_turn_off(self):
"""Disable the output."""
await self._api.change_output(self._output_id, selected=False) | [
"async",
"def",
"async_turn_off",
"(",
"self",
")",
":",
"await",
"self",
".",
"_api",
".",
"change_output",
"(",
"self",
".",
"_output_id",
",",
"selected",
"=",
"False",
")"
] | [
176,
4
] | [
178,
70
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.name | (self) | Return the name of the zone. | Return the name of the zone. | def name(self):
"""Return the name of the zone."""
return f"{FD_NAME} output ({self._output['name']})" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{FD_NAME} output ({self._output['name']})\""
] | [
181,
4
] | [
183,
59
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.state | (self) | State of the zone. | State of the zone. | def state(self):
"""State of the zone."""
if self._output["selected"]:
return STATE_ON
return STATE_OFF | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_output",
"[",
"\"selected\"",
"]",
":",
"return",
"STATE_ON",
"return",
"STATE_OFF"
] | [
186,
4
] | [
190,
24
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.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._output["volume"] / 100 | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_output",
"[",
"\"volume\"",
"]",
"/",
"100"
] | [
193,
4
] | [
195,
43
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.is_volume_muted | (self) | Boolean if volume is currently muted. | Boolean if volume is currently muted. | def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self._output["volume"] == 0 | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"_output",
"[",
"\"volume\"",
"]",
"==",
"0"
] | [
198,
4
] | [
200,
42
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdZone.async_mute_volume | (self, mute) | Mute the volume. | Mute the volume. | async def async_mute_volume(self, mute):
"""Mute the volume."""
if mute:
if self.volume_level == 0:
return
self._last_volume = self.volume_level # store volume level to restore later
target_volume = 0
else:
target_volume = self._last_volume # restore volume level
await self.async_set_volume_level(volume=target_volume) | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"if",
"self",
".",
"volume_level",
"==",
"0",
":",
"return",
"self",
".",
"_last_volume",
"=",
"self",
".",
"volume_level",
"# store volume level to restore later",
"target_volume",
"=",
"0",
"else",
":",
"target_volume",
"=",
"self",
".",
"_last_volume",
"# restore volume level",
"await",
"self",
".",
"async_set_volume_level",
"(",
"volume",
"=",
"target_volume",
")"
] | [
202,
4
] | [
211,
63
] | python | en | ['en', 'sn', 'en'] | True |
ForkedDaapdZone.async_set_volume_level | (self, volume) | Set volume - input range [0,1]. | Set volume - input range [0,1]. | async def async_set_volume_level(self, volume):
"""Set volume - input range [0,1]."""
await self._api.set_volume(volume=volume * 100, output_id=self._output_id) | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"await",
"self",
".",
"_api",
".",
"set_volume",
"(",
"volume",
"=",
"volume",
"*",
"100",
",",
"output_id",
"=",
"self",
".",
"_output_id",
")"
] | [
213,
4
] | [
215,
82
] | python | en | ['nl', 'fi', 'en'] | False |
ForkedDaapdZone.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 SUPPORTED_FEATURES_ZONE | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORTED_FEATURES_ZONE"
] | [
218,
4
] | [
220,
38
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.__init__ | (
self, clientsession, api, ip_address, api_port, api_password, config_entry
) | Initialize the ForkedDaapd Master Device. | Initialize the ForkedDaapd Master Device. | def __init__(
self, clientsession, api, ip_address, api_port, api_password, config_entry
):
"""Initialize the ForkedDaapd Master Device."""
self._api = api
self._player = STARTUP_DATA[
"player"
] # _player, _outputs, and _queue are loaded straight from api
self._outputs = STARTUP_DATA["outputs"]
self._queue = STARTUP_DATA["queue"]
self._track_info = defaultdict(
str
) # _track info is found by matching _player data with _queue data
self._last_outputs = [] # used for device on/off
self._last_volume = DEFAULT_UNMUTE_VOLUME
self._player_last_updated = None
self._pipe_control_api = {}
self._ip_address = (
ip_address # need to save this because pipe control is on same ip
)
self._tts_pause_time = DEFAULT_TTS_PAUSE_TIME
self._tts_volume = DEFAULT_TTS_VOLUME
self._tts_requested = False
self._tts_queued = False
self._tts_playing_event = asyncio.Event()
self._on_remove = None
self._available = False
self._clientsession = clientsession
self._config_entry = config_entry
self.update_options(config_entry.options)
self._paused_event = asyncio.Event()
self._pause_requested = False
self._sources_uris = {}
self._source = SOURCE_NAME_DEFAULT
self._max_playlists = None | [
"def",
"__init__",
"(",
"self",
",",
"clientsession",
",",
"api",
",",
"ip_address",
",",
"api_port",
",",
"api_password",
",",
"config_entry",
")",
":",
"self",
".",
"_api",
"=",
"api",
"self",
".",
"_player",
"=",
"STARTUP_DATA",
"[",
"\"player\"",
"]",
"# _player, _outputs, and _queue are loaded straight from api",
"self",
".",
"_outputs",
"=",
"STARTUP_DATA",
"[",
"\"outputs\"",
"]",
"self",
".",
"_queue",
"=",
"STARTUP_DATA",
"[",
"\"queue\"",
"]",
"self",
".",
"_track_info",
"=",
"defaultdict",
"(",
"str",
")",
"# _track info is found by matching _player data with _queue data",
"self",
".",
"_last_outputs",
"=",
"[",
"]",
"# used for device on/off",
"self",
".",
"_last_volume",
"=",
"DEFAULT_UNMUTE_VOLUME",
"self",
".",
"_player_last_updated",
"=",
"None",
"self",
".",
"_pipe_control_api",
"=",
"{",
"}",
"self",
".",
"_ip_address",
"=",
"(",
"ip_address",
"# need to save this because pipe control is on same ip",
")",
"self",
".",
"_tts_pause_time",
"=",
"DEFAULT_TTS_PAUSE_TIME",
"self",
".",
"_tts_volume",
"=",
"DEFAULT_TTS_VOLUME",
"self",
".",
"_tts_requested",
"=",
"False",
"self",
".",
"_tts_queued",
"=",
"False",
"self",
".",
"_tts_playing_event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"self",
".",
"_on_remove",
"=",
"None",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"_clientsession",
"=",
"clientsession",
"self",
".",
"_config_entry",
"=",
"config_entry",
"self",
".",
"update_options",
"(",
"config_entry",
".",
"options",
")",
"self",
".",
"_paused_event",
"=",
"asyncio",
".",
"Event",
"(",
")",
"self",
".",
"_pause_requested",
"=",
"False",
"self",
".",
"_sources_uris",
"=",
"{",
"}",
"self",
".",
"_source",
"=",
"SOURCE_NAME_DEFAULT",
"self",
".",
"_max_playlists",
"=",
"None"
] | [
226,
4
] | [
260,
34
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_added_to_hass | (self) | Use lifecycle hooks. | Use lifecycle hooks. | async def async_added_to_hass(self):
"""Use lifecycle hooks."""
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_PLAYER.format(self._config_entry.entry_id),
self._update_player,
)
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_QUEUE.format(self._config_entry.entry_id),
self._update_queue,
)
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_OUTPUTS.format(self._config_entry.entry_id),
self._update_outputs,
)
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_MASTER.format(self._config_entry.entry_id),
self._update_callback,
)
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_CONFIG_OPTIONS_UPDATE.format(self._config_entry.entry_id),
self.update_options,
)
)
self.async_on_remove(
async_dispatcher_connect(
self.hass,
SIGNAL_UPDATE_DATABASE.format(self._config_entry.entry_id),
self._update_database,
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_PLAYER",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"_update_player",
",",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_QUEUE",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"_update_queue",
",",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_OUTPUTS",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"_update_outputs",
",",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_MASTER",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"_update_callback",
",",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_CONFIG_OPTIONS_UPDATE",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"update_options",
",",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_DATABASE",
".",
"format",
"(",
"self",
".",
"_config_entry",
".",
"entry_id",
")",
",",
"self",
".",
"_update_database",
",",
")",
")"
] | [
262,
4
] | [
305,
9
] | python | en | ['en', 'zu', 'en'] | True |
ForkedDaapdMaster._update_callback | (self, available) | Call update method. | Call update method. | def _update_callback(self, available):
"""Call update method."""
self._available = available
self.async_write_ha_state() | [
"def",
"_update_callback",
"(",
"self",
",",
"available",
")",
":",
"self",
".",
"_available",
"=",
"available",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
308,
4
] | [
311,
35
] | python | en | ['en', 'sn', 'en'] | True |
ForkedDaapdMaster.update_options | (self, options) | Update forked-daapd server options. | Update forked-daapd server options. | def update_options(self, options):
"""Update forked-daapd server options."""
if CONF_LIBRESPOT_JAVA_PORT in options:
self._pipe_control_api["librespot-java"] = LibrespotJavaAPI(
self._clientsession, self._ip_address, options[CONF_LIBRESPOT_JAVA_PORT]
)
if CONF_TTS_PAUSE_TIME in options:
self._tts_pause_time = options[CONF_TTS_PAUSE_TIME]
if CONF_TTS_VOLUME in options:
self._tts_volume = options[CONF_TTS_VOLUME]
if CONF_MAX_PLAYLISTS in options:
# sources not updated until next _update_database call
self._max_playlists = options[CONF_MAX_PLAYLISTS] | [
"def",
"update_options",
"(",
"self",
",",
"options",
")",
":",
"if",
"CONF_LIBRESPOT_JAVA_PORT",
"in",
"options",
":",
"self",
".",
"_pipe_control_api",
"[",
"\"librespot-java\"",
"]",
"=",
"LibrespotJavaAPI",
"(",
"self",
".",
"_clientsession",
",",
"self",
".",
"_ip_address",
",",
"options",
"[",
"CONF_LIBRESPOT_JAVA_PORT",
"]",
")",
"if",
"CONF_TTS_PAUSE_TIME",
"in",
"options",
":",
"self",
".",
"_tts_pause_time",
"=",
"options",
"[",
"CONF_TTS_PAUSE_TIME",
"]",
"if",
"CONF_TTS_VOLUME",
"in",
"options",
":",
"self",
".",
"_tts_volume",
"=",
"options",
"[",
"CONF_TTS_VOLUME",
"]",
"if",
"CONF_MAX_PLAYLISTS",
"in",
"options",
":",
"# sources not updated until next _update_database call",
"self",
".",
"_max_playlists",
"=",
"options",
"[",
"CONF_MAX_PLAYLISTS",
"]"
] | [
314,
4
] | [
326,
61
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.unique_id | (self) | Return unique ID. | Return unique ID. | def unique_id(self):
"""Return unique ID."""
return self._config_entry.entry_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config_entry",
".",
"entry_id"
] | [
399,
4
] | [
401,
42
] | python | en | ['fr', 'la', 'en'] | False |
ForkedDaapdMaster.should_poll | (self) | Entity pushes its state to HA. | Entity pushes its state to HA. | def should_poll(self) -> bool:
"""Entity pushes its state to HA."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
404,
4
] | [
406,
20
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.available | (self) | Return whether the master is available. | Return whether the master is available. | def available(self) -> bool:
"""Return whether the master is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_available"
] | [
409,
4
] | [
411,
30
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_turn_on | (self) | Restore the last on outputs state. | Restore the last on outputs state. | async def async_turn_on(self):
"""Restore the last on outputs state."""
# restore state
await self._api.set_volume(volume=self._last_volume * 100)
if self._last_outputs:
futures = []
for output in self._last_outputs:
futures.append(
self._api.change_output(
output["id"],
selected=output["selected"],
volume=output["volume"],
)
)
await asyncio.wait(futures)
else: # enable all outputs
await self._api.set_enabled_outputs(
[output["id"] for output in self._outputs]
) | [
"async",
"def",
"async_turn_on",
"(",
"self",
")",
":",
"# restore state",
"await",
"self",
".",
"_api",
".",
"set_volume",
"(",
"volume",
"=",
"self",
".",
"_last_volume",
"*",
"100",
")",
"if",
"self",
".",
"_last_outputs",
":",
"futures",
"=",
"[",
"]",
"for",
"output",
"in",
"self",
".",
"_last_outputs",
":",
"futures",
".",
"append",
"(",
"self",
".",
"_api",
".",
"change_output",
"(",
"output",
"[",
"\"id\"",
"]",
",",
"selected",
"=",
"output",
"[",
"\"selected\"",
"]",
",",
"volume",
"=",
"output",
"[",
"\"volume\"",
"]",
",",
")",
")",
"await",
"asyncio",
".",
"wait",
"(",
"futures",
")",
"else",
":",
"# enable all outputs",
"await",
"self",
".",
"_api",
".",
"set_enabled_outputs",
"(",
"[",
"output",
"[",
"\"id\"",
"]",
"for",
"output",
"in",
"self",
".",
"_outputs",
"]",
")"
] | [
413,
4
] | [
431,
13
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_turn_off | (self) | Pause player and store outputs state. | Pause player and store outputs state. | async def async_turn_off(self):
"""Pause player and store outputs state."""
await self.async_media_pause()
self._last_outputs = self._outputs
if any(output["selected"] for output in self._outputs):
await self._api.set_enabled_outputs([]) | [
"async",
"def",
"async_turn_off",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_media_pause",
"(",
")",
"self",
".",
"_last_outputs",
"=",
"self",
".",
"_outputs",
"if",
"any",
"(",
"output",
"[",
"\"selected\"",
"]",
"for",
"output",
"in",
"self",
".",
"_outputs",
")",
":",
"await",
"self",
".",
"_api",
".",
"set_enabled_outputs",
"(",
"[",
"]",
")"
] | [
433,
4
] | [
438,
51
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_toggle | (self) | Toggle the power on the device.
Default media player component method counts idle as off.
We consider idle to be on but just not playing.
| Toggle the power on the device. | async def async_toggle(self):
"""Toggle the power on the device.
Default media player component method counts idle as off.
We consider idle to be on but just not playing.
"""
if self.state == STATE_OFF:
await self.async_turn_on()
else:
await self.async_turn_off() | [
"async",
"def",
"async_toggle",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"STATE_OFF",
":",
"await",
"self",
".",
"async_turn_on",
"(",
")",
"else",
":",
"await",
"self",
".",
"async_turn_off",
"(",
")"
] | [
440,
4
] | [
449,
39
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return f"{FD_NAME} server" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{FD_NAME} server\""
] | [
452,
4
] | [
454,
34
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.state | (self) | State of the player. | State of the player. | def state(self):
"""State of the player."""
if self._player["state"] == "play":
return STATE_PLAYING
if self._player["state"] == "pause":
return STATE_PAUSED
if not any(output["selected"] for output in self._outputs):
return STATE_OFF
if self._player["state"] == "stop": # this should catch all remaining cases
return STATE_IDLE | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_player",
"[",
"\"state\"",
"]",
"==",
"\"play\"",
":",
"return",
"STATE_PLAYING",
"if",
"self",
".",
"_player",
"[",
"\"state\"",
"]",
"==",
"\"pause\"",
":",
"return",
"STATE_PAUSED",
"if",
"not",
"any",
"(",
"output",
"[",
"\"selected\"",
"]",
"for",
"output",
"in",
"self",
".",
"_outputs",
")",
":",
"return",
"STATE_OFF",
"if",
"self",
".",
"_player",
"[",
"\"state\"",
"]",
"==",
"\"stop\"",
":",
"# this should catch all remaining cases",
"return",
"STATE_IDLE"
] | [
457,
4
] | [
466,
29
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.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._player["volume"] / 100 | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"volume\"",
"]",
"/",
"100"
] | [
469,
4
] | [
471,
43
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.is_volume_muted | (self) | Boolean if volume is currently muted. | Boolean if volume is currently muted. | def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self._player["volume"] == 0 | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"volume\"",
"]",
"==",
"0"
] | [
474,
4
] | [
476,
42
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_content_id | (self) | Content ID of current playing media. | Content ID of current playing media. | def media_content_id(self):
"""Content ID of current playing media."""
return self._player["item_id"] | [
"def",
"media_content_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"item_id\"",
"]"
] | [
479,
4
] | [
481,
38
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.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 self._track_info["media_kind"] | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"media_kind\"",
"]"
] | [
484,
4
] | [
486,
45
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_duration | (self) | Duration of current playing media in seconds. | Duration of current playing media in seconds. | def media_duration(self):
"""Duration of current playing media in seconds."""
return self._player["item_length_ms"] / 1000 | [
"def",
"media_duration",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"item_length_ms\"",
"]",
"/",
"1000"
] | [
489,
4
] | [
491,
52
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_position | (self) | Position of current playing media in seconds. | Position of current playing media in seconds. | def media_position(self):
"""Position of current playing media in seconds."""
return self._player["item_progress_ms"] / 1000 | [
"def",
"media_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"item_progress_ms\"",
"]",
"/",
"1000"
] | [
494,
4
] | [
496,
54
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_position_updated_at | (self) | When was the position of the current playing media valid. | When was the position of the current playing media valid. | def media_position_updated_at(self):
"""When was the position of the current playing media valid."""
return self._player_last_updated | [
"def",
"media_position_updated_at",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player_last_updated"
] | [
499,
4
] | [
501,
40
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
# Use album field when data_kind is url
# https://github.com/ejurgensen/forked-daapd/issues/351
if self._track_info["data_kind"] == "url":
return self._track_info["album"]
return self._track_info["title"] | [
"def",
"media_title",
"(",
"self",
")",
":",
"# Use album field when data_kind is url",
"# https://github.com/ejurgensen/forked-daapd/issues/351",
"if",
"self",
".",
"_track_info",
"[",
"\"data_kind\"",
"]",
"==",
"\"url\"",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"album\"",
"]",
"return",
"self",
".",
"_track_info",
"[",
"\"title\"",
"]"
] | [
504,
4
] | [
510,
40
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.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._track_info["artist"] | [
"def",
"media_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"artist\"",
"]"
] | [
513,
4
] | [
515,
41
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_album_name | (self) | Album name of current playing media, music track only. | Album name of current playing media, music track only. | def media_album_name(self):
"""Album name of current playing media, music track only."""
# Use title field when data_kind is url
# https://github.com/ejurgensen/forked-daapd/issues/351
if self._track_info["data_kind"] == "url":
return self._track_info["title"]
return self._track_info["album"] | [
"def",
"media_album_name",
"(",
"self",
")",
":",
"# Use title field when data_kind is url",
"# https://github.com/ejurgensen/forked-daapd/issues/351",
"if",
"self",
".",
"_track_info",
"[",
"\"data_kind\"",
"]",
"==",
"\"url\"",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"title\"",
"]",
"return",
"self",
".",
"_track_info",
"[",
"\"album\"",
"]"
] | [
518,
4
] | [
524,
40
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_album_artist | (self) | Album artist of current playing media, music track only. | Album artist of current playing media, music track only. | def media_album_artist(self):
"""Album artist of current playing media, music track only."""
return self._track_info["album_artist"] | [
"def",
"media_album_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"album_artist\"",
"]"
] | [
527,
4
] | [
529,
47
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.media_track | (self) | Track number of current playing media, music track only. | Track number of current playing media, music track only. | def media_track(self):
"""Track number of current playing media, music track only."""
return self._track_info["track_number"] | [
"def",
"media_track",
"(",
"self",
")",
":",
"return",
"self",
".",
"_track_info",
"[",
"\"track_number\"",
"]"
] | [
532,
4
] | [
534,
47
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.shuffle | (self) | Boolean if shuffle is enabled. | Boolean if shuffle is enabled. | def shuffle(self):
"""Boolean if shuffle is enabled."""
return self._player["shuffle"] | [
"def",
"shuffle",
"(",
"self",
")",
":",
"return",
"self",
".",
"_player",
"[",
"\"shuffle\"",
"]"
] | [
537,
4
] | [
539,
38
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.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 SUPPORTED_FEATURES | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORTED_FEATURES"
] | [
542,
4
] | [
544,
33
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.source | (self) | Name of the current input source. | Name of the current input source. | def source(self):
"""Name of the current input source."""
return self._source | [
"def",
"source",
"(",
"self",
")",
":",
"return",
"self",
".",
"_source"
] | [
547,
4
] | [
549,
27
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.source_list | (self) | List of available input sources. | List of available input sources. | def source_list(self):
"""List of available input sources."""
return [*self._sources_uris] | [
"def",
"source_list",
"(",
"self",
")",
":",
"return",
"[",
"*",
"self",
".",
"_sources_uris",
"]"
] | [
552,
4
] | [
554,
36
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_mute_volume | (self, mute) | Mute the volume. | Mute the volume. | async def async_mute_volume(self, mute):
"""Mute the volume."""
if mute:
if self.volume_level == 0:
return
self._last_volume = self.volume_level # store volume level to restore later
target_volume = 0
else:
target_volume = self._last_volume # restore volume level
await self._api.set_volume(volume=target_volume * 100) | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"if",
"self",
".",
"volume_level",
"==",
"0",
":",
"return",
"self",
".",
"_last_volume",
"=",
"self",
".",
"volume_level",
"# store volume level to restore later",
"target_volume",
"=",
"0",
"else",
":",
"target_volume",
"=",
"self",
".",
"_last_volume",
"# restore volume level",
"await",
"self",
".",
"_api",
".",
"set_volume",
"(",
"volume",
"=",
"target_volume",
"*",
"100",
")"
] | [
556,
4
] | [
565,
62
] | python | en | ['en', 'sn', 'en'] | True |
ForkedDaapdMaster.async_set_volume_level | (self, volume) | Set volume - input range [0,1]. | Set volume - input range [0,1]. | async def async_set_volume_level(self, volume):
"""Set volume - input range [0,1]."""
await self._api.set_volume(volume=volume * 100) | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"await",
"self",
".",
"_api",
".",
"set_volume",
"(",
"volume",
"=",
"volume",
"*",
"100",
")"
] | [
567,
4
] | [
569,
55
] | python | en | ['nl', 'fi', 'en'] | False |
ForkedDaapdMaster.async_media_play | (self) | Start playback. | Start playback. | async def async_media_play(self):
"""Start playback."""
if self._use_pipe_control():
await self._pipe_call(self._use_pipe_control(), "async_media_play")
else:
await self._api.start_playback() | [
"async",
"def",
"async_media_play",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"await",
"self",
".",
"_pipe_call",
"(",
"self",
".",
"_use_pipe_control",
"(",
")",
",",
"\"async_media_play\"",
")",
"else",
":",
"await",
"self",
".",
"_api",
".",
"start_playback",
"(",
")"
] | [
571,
4
] | [
576,
44
] | python | en | ['en', 'ny', 'en'] | False |
ForkedDaapdMaster.async_media_pause | (self) | Pause playback. | Pause playback. | async def async_media_pause(self):
"""Pause playback."""
if self._use_pipe_control():
await self._pipe_call(self._use_pipe_control(), "async_media_pause")
else:
await self._api.pause_playback() | [
"async",
"def",
"async_media_pause",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"await",
"self",
".",
"_pipe_call",
"(",
"self",
".",
"_use_pipe_control",
"(",
")",
",",
"\"async_media_pause\"",
")",
"else",
":",
"await",
"self",
".",
"_api",
".",
"pause_playback",
"(",
")"
] | [
578,
4
] | [
583,
44
] | python | de | ['de', 'lt', 'en'] | False |
ForkedDaapdMaster.async_media_stop | (self) | Stop playback. | Stop playback. | async def async_media_stop(self):
"""Stop playback."""
if self._use_pipe_control():
await self._pipe_call(self._use_pipe_control(), "async_media_stop")
else:
await self._api.stop_playback() | [
"async",
"def",
"async_media_stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"await",
"self",
".",
"_pipe_call",
"(",
"self",
".",
"_use_pipe_control",
"(",
")",
",",
"\"async_media_stop\"",
")",
"else",
":",
"await",
"self",
".",
"_api",
".",
"stop_playback",
"(",
")"
] | [
585,
4
] | [
590,
43
] | python | en | ['en', 'en', 'en'] | False |
ForkedDaapdMaster.async_media_previous_track | (self) | Skip to previous track. | Skip to previous track. | async def async_media_previous_track(self):
"""Skip to previous track."""
if self._use_pipe_control():
await self._pipe_call(
self._use_pipe_control(), "async_media_previous_track"
)
else:
await self._api.previous_track() | [
"async",
"def",
"async_media_previous_track",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"await",
"self",
".",
"_pipe_call",
"(",
"self",
".",
"_use_pipe_control",
"(",
")",
",",
"\"async_media_previous_track\"",
")",
"else",
":",
"await",
"self",
".",
"_api",
".",
"previous_track",
"(",
")"
] | [
592,
4
] | [
599,
44
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_media_next_track | (self) | Skip to next track. | Skip to next track. | async def async_media_next_track(self):
"""Skip to next track."""
if self._use_pipe_control():
await self._pipe_call(self._use_pipe_control(), "async_media_next_track")
else:
await self._api.next_track() | [
"async",
"def",
"async_media_next_track",
"(",
"self",
")",
":",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"await",
"self",
".",
"_pipe_call",
"(",
"self",
".",
"_use_pipe_control",
"(",
")",
",",
"\"async_media_next_track\"",
")",
"else",
":",
"await",
"self",
".",
"_api",
".",
"next_track",
"(",
")"
] | [
601,
4
] | [
606,
40
] | python | en | ['en', 'bg-Latn', 'en'] | True |
ForkedDaapdMaster.async_media_seek | (self, position) | Seek to position. | Seek to position. | async def async_media_seek(self, position):
"""Seek to position."""
await self._api.seek(position_ms=position * 1000) | [
"async",
"def",
"async_media_seek",
"(",
"self",
",",
"position",
")",
":",
"await",
"self",
".",
"_api",
".",
"seek",
"(",
"position_ms",
"=",
"position",
"*",
"1000",
")"
] | [
608,
4
] | [
610,
57
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_clear_playlist | (self) | Clear playlist. | Clear playlist. | async def async_clear_playlist(self):
"""Clear playlist."""
await self._api.clear_queue() | [
"async",
"def",
"async_clear_playlist",
"(",
"self",
")",
":",
"await",
"self",
".",
"_api",
".",
"clear_queue",
"(",
")"
] | [
612,
4
] | [
614,
37
] | python | en | ['en', 'en', 'en'] | False |
ForkedDaapdMaster.async_set_shuffle | (self, shuffle) | Enable/disable shuffle mode. | Enable/disable shuffle mode. | async def async_set_shuffle(self, shuffle):
"""Enable/disable shuffle mode."""
await self._api.shuffle(shuffle) | [
"async",
"def",
"async_set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"await",
"self",
".",
"_api",
".",
"shuffle",
"(",
"shuffle",
")"
] | [
616,
4
] | [
618,
40
] | python | en | ['en', 'st', 'en'] | True |
ForkedDaapdMaster.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."""
url = self._track_info.get("artwork_url")
if url:
url = self._api.full_url(url)
return url | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"url",
"=",
"self",
".",
"_track_info",
".",
"get",
"(",
"\"artwork_url\"",
")",
"if",
"url",
":",
"url",
"=",
"self",
".",
"_api",
".",
"full_url",
"(",
"url",
")",
"return",
"url"
] | [
621,
4
] | [
626,
18
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster._pause_and_wait_for_callback | (self) | Send pause and wait for the pause callback to be received. | Send pause and wait for the pause callback to be received. | async def _pause_and_wait_for_callback(self):
"""Send pause and wait for the pause callback to be received."""
self._pause_requested = True
await self.async_media_pause()
try:
await asyncio.wait_for(
self._paused_event.wait(), timeout=CALLBACK_TIMEOUT
) # wait for paused
except asyncio.TimeoutError:
self._pause_requested = False
self._paused_event.clear() | [
"async",
"def",
"_pause_and_wait_for_callback",
"(",
"self",
")",
":",
"self",
".",
"_pause_requested",
"=",
"True",
"await",
"self",
".",
"async_media_pause",
"(",
")",
"try",
":",
"await",
"asyncio",
".",
"wait_for",
"(",
"self",
".",
"_paused_event",
".",
"wait",
"(",
")",
",",
"timeout",
"=",
"CALLBACK_TIMEOUT",
")",
"# wait for paused",
"except",
"asyncio",
".",
"TimeoutError",
":",
"self",
".",
"_pause_requested",
"=",
"False",
"self",
".",
"_paused_event",
".",
"clear",
"(",
")"
] | [
643,
4
] | [
653,
34
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdMaster.async_play_media | (self, media_type, media_id, **kwargs) | Play a URI. | Play a URI. | async def async_play_media(self, media_type, media_id, **kwargs):
"""Play a URI."""
if media_type == MEDIA_TYPE_MUSIC:
saved_state = self.state # save play state
saved_mute = self.is_volume_muted
sleep_future = asyncio.create_task(
asyncio.sleep(self._tts_pause_time)
) # start timing now, but not exact because of fd buffer + tts latency
await self._pause_and_wait_for_callback()
await self._save_and_set_tts_volumes()
# save position
saved_song_position = self._player["item_progress_ms"]
saved_queue = (
self._queue if self._queue["count"] > 0 else None
) # stash queue
if saved_queue:
saved_queue_position = next(
i
for i, item in enumerate(saved_queue["items"])
if item["id"] == self._player["item_id"]
)
self._tts_requested = True
await sleep_future
await self._api.add_to_queue(uris=media_id, playback="start", clear=True)
try:
await asyncio.wait_for(
self._tts_playing_event.wait(), timeout=TTS_TIMEOUT
)
# we have started TTS, now wait for completion
await asyncio.sleep(
self._queue["items"][0]["length_ms"]
/ 1000 # player may not have updated yet so grab length from queue
+ self._tts_pause_time
)
except asyncio.TimeoutError:
self._tts_requested = False
_LOGGER.warning("TTS request timed out")
self._tts_playing_event.clear()
# TTS done, return to normal
await self.async_turn_on() # restore outputs and volumes
if saved_mute: # mute if we were muted
await self.async_mute_volume(True)
if self._use_pipe_control(): # resume pipe
await self._api.add_to_queue(
uris=self._sources_uris[self._source], clear=True
)
if saved_state == STATE_PLAYING:
await self.async_media_play()
else: # restore stashed queue
if saved_queue:
uris = ""
for item in saved_queue["items"]:
uris += item["uri"] + ","
await self._api.add_to_queue(
uris=uris,
playback="start",
playback_from_position=saved_queue_position,
clear=True,
)
await self._api.seek(position_ms=saved_song_position)
if saved_state == STATE_PAUSED:
await self.async_media_pause()
elif saved_state != STATE_PLAYING:
await self.async_media_stop()
else:
_LOGGER.debug("Media type '%s' not supported", media_type) | [
"async",
"def",
"async_play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"media_type",
"==",
"MEDIA_TYPE_MUSIC",
":",
"saved_state",
"=",
"self",
".",
"state",
"# save play state",
"saved_mute",
"=",
"self",
".",
"is_volume_muted",
"sleep_future",
"=",
"asyncio",
".",
"create_task",
"(",
"asyncio",
".",
"sleep",
"(",
"self",
".",
"_tts_pause_time",
")",
")",
"# start timing now, but not exact because of fd buffer + tts latency",
"await",
"self",
".",
"_pause_and_wait_for_callback",
"(",
")",
"await",
"self",
".",
"_save_and_set_tts_volumes",
"(",
")",
"# save position",
"saved_song_position",
"=",
"self",
".",
"_player",
"[",
"\"item_progress_ms\"",
"]",
"saved_queue",
"=",
"(",
"self",
".",
"_queue",
"if",
"self",
".",
"_queue",
"[",
"\"count\"",
"]",
">",
"0",
"else",
"None",
")",
"# stash queue",
"if",
"saved_queue",
":",
"saved_queue_position",
"=",
"next",
"(",
"i",
"for",
"i",
",",
"item",
"in",
"enumerate",
"(",
"saved_queue",
"[",
"\"items\"",
"]",
")",
"if",
"item",
"[",
"\"id\"",
"]",
"==",
"self",
".",
"_player",
"[",
"\"item_id\"",
"]",
")",
"self",
".",
"_tts_requested",
"=",
"True",
"await",
"sleep_future",
"await",
"self",
".",
"_api",
".",
"add_to_queue",
"(",
"uris",
"=",
"media_id",
",",
"playback",
"=",
"\"start\"",
",",
"clear",
"=",
"True",
")",
"try",
":",
"await",
"asyncio",
".",
"wait_for",
"(",
"self",
".",
"_tts_playing_event",
".",
"wait",
"(",
")",
",",
"timeout",
"=",
"TTS_TIMEOUT",
")",
"# we have started TTS, now wait for completion",
"await",
"asyncio",
".",
"sleep",
"(",
"self",
".",
"_queue",
"[",
"\"items\"",
"]",
"[",
"0",
"]",
"[",
"\"length_ms\"",
"]",
"/",
"1000",
"# player may not have updated yet so grab length from queue",
"+",
"self",
".",
"_tts_pause_time",
")",
"except",
"asyncio",
".",
"TimeoutError",
":",
"self",
".",
"_tts_requested",
"=",
"False",
"_LOGGER",
".",
"warning",
"(",
"\"TTS request timed out\"",
")",
"self",
".",
"_tts_playing_event",
".",
"clear",
"(",
")",
"# TTS done, return to normal",
"await",
"self",
".",
"async_turn_on",
"(",
")",
"# restore outputs and volumes",
"if",
"saved_mute",
":",
"# mute if we were muted",
"await",
"self",
".",
"async_mute_volume",
"(",
"True",
")",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"# resume pipe",
"await",
"self",
".",
"_api",
".",
"add_to_queue",
"(",
"uris",
"=",
"self",
".",
"_sources_uris",
"[",
"self",
".",
"_source",
"]",
",",
"clear",
"=",
"True",
")",
"if",
"saved_state",
"==",
"STATE_PLAYING",
":",
"await",
"self",
".",
"async_media_play",
"(",
")",
"else",
":",
"# restore stashed queue",
"if",
"saved_queue",
":",
"uris",
"=",
"\"\"",
"for",
"item",
"in",
"saved_queue",
"[",
"\"items\"",
"]",
":",
"uris",
"+=",
"item",
"[",
"\"uri\"",
"]",
"+",
"\",\"",
"await",
"self",
".",
"_api",
".",
"add_to_queue",
"(",
"uris",
"=",
"uris",
",",
"playback",
"=",
"\"start\"",
",",
"playback_from_position",
"=",
"saved_queue_position",
",",
"clear",
"=",
"True",
",",
")",
"await",
"self",
".",
"_api",
".",
"seek",
"(",
"position_ms",
"=",
"saved_song_position",
")",
"if",
"saved_state",
"==",
"STATE_PAUSED",
":",
"await",
"self",
".",
"async_media_pause",
"(",
")",
"elif",
"saved_state",
"!=",
"STATE_PLAYING",
":",
"await",
"self",
".",
"async_media_stop",
"(",
")",
"else",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Media type '%s' not supported\"",
",",
"media_type",
")"
] | [
655,
4
] | [
720,
70
] | python | en | ['en', 'zh', 'en'] | True |
ForkedDaapdMaster.async_select_source | (self, source) | Change source.
Source name reflects whether in default mode or pipe mode.
Selecting playlists/clear sets the playlists/clears but ends up in default mode.
| Change source. | async def async_select_source(self, source):
"""Change source.
Source name reflects whether in default mode or pipe mode.
Selecting playlists/clear sets the playlists/clears but ends up in default mode.
"""
if source == self._source:
return
if self._use_pipe_control(): # if pipe was playing, we need to stop it first
await self._pause_and_wait_for_callback()
self._source = source
if not self._use_pipe_control(): # playlist or clear ends up at default
self._source = SOURCE_NAME_DEFAULT
if self._sources_uris.get(source): # load uris for pipes or playlists
await self._api.add_to_queue(uris=self._sources_uris[source], clear=True)
elif source == SOURCE_NAME_CLEAR: # clear playlist
await self._api.clear_queue()
self.async_write_ha_state() | [
"async",
"def",
"async_select_source",
"(",
"self",
",",
"source",
")",
":",
"if",
"source",
"==",
"self",
".",
"_source",
":",
"return",
"if",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"# if pipe was playing, we need to stop it first",
"await",
"self",
".",
"_pause_and_wait_for_callback",
"(",
")",
"self",
".",
"_source",
"=",
"source",
"if",
"not",
"self",
".",
"_use_pipe_control",
"(",
")",
":",
"# playlist or clear ends up at default",
"self",
".",
"_source",
"=",
"SOURCE_NAME_DEFAULT",
"if",
"self",
".",
"_sources_uris",
".",
"get",
"(",
"source",
")",
":",
"# load uris for pipes or playlists",
"await",
"self",
".",
"_api",
".",
"add_to_queue",
"(",
"uris",
"=",
"self",
".",
"_sources_uris",
"[",
"source",
"]",
",",
"clear",
"=",
"True",
")",
"elif",
"source",
"==",
"SOURCE_NAME_CLEAR",
":",
"# clear playlist",
"await",
"self",
".",
"_api",
".",
"clear_queue",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
722,
4
] | [
740,
35
] | python | en | ['fr', 'sw', 'en'] | False |
ForkedDaapdMaster._use_pipe_control | (self) | Return which pipe control from KNOWN_PIPES to use. | Return which pipe control from KNOWN_PIPES to use. | def _use_pipe_control(self):
"""Return which pipe control from KNOWN_PIPES to use."""
if self._source[-7:] == " (pipe)":
return self._source[:-7]
return "" | [
"def",
"_use_pipe_control",
"(",
"self",
")",
":",
"if",
"self",
".",
"_source",
"[",
"-",
"7",
":",
"]",
"==",
"\" (pipe)\"",
":",
"return",
"self",
".",
"_source",
"[",
":",
"-",
"7",
"]",
"return",
"\"\""
] | [
742,
4
] | [
746,
17
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdUpdater.__init__ | (self, hass, api, entry_id) | Initialize. | Initialize. | def __init__(self, hass, api, entry_id):
"""Initialize."""
self.hass = hass
self._api = api
self.websocket_handler = None
self._all_output_ids = set()
self._entry_id = entry_id | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"api",
",",
"entry_id",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"_api",
"=",
"api",
"self",
".",
"websocket_handler",
"=",
"None",
"self",
".",
"_all_output_ids",
"=",
"set",
"(",
")",
"self",
".",
"_entry_id",
"=",
"entry_id"
] | [
760,
4
] | [
766,
33
] | python | en | ['en', 'en', 'it'] | False |
ForkedDaapdUpdater.async_init | (self) | Perform async portion of class initialization. | Perform async portion of class initialization. | async def async_init(self):
"""Perform async portion of class initialization."""
server_config = await self._api.get_request("config")
websocket_port = server_config.get("websocket_port")
if websocket_port:
self.websocket_handler = asyncio.create_task(
self._api.start_websocket_handler(
server_config["websocket_port"],
WS_NOTIFY_EVENT_TYPES,
self._update,
WEBSOCKET_RECONNECT_TIME,
self._disconnected_callback,
)
)
else:
_LOGGER.error("Invalid websocket port") | [
"async",
"def",
"async_init",
"(",
"self",
")",
":",
"server_config",
"=",
"await",
"self",
".",
"_api",
".",
"get_request",
"(",
"\"config\"",
")",
"websocket_port",
"=",
"server_config",
".",
"get",
"(",
"\"websocket_port\"",
")",
"if",
"websocket_port",
":",
"self",
".",
"websocket_handler",
"=",
"asyncio",
".",
"create_task",
"(",
"self",
".",
"_api",
".",
"start_websocket_handler",
"(",
"server_config",
"[",
"\"websocket_port\"",
"]",
",",
"WS_NOTIFY_EVENT_TYPES",
",",
"self",
".",
"_update",
",",
"WEBSOCKET_RECONNECT_TIME",
",",
"self",
".",
"_disconnected_callback",
",",
")",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid websocket port\"",
")"
] | [
768,
4
] | [
783,
51
] | python | en | ['en', 'en', 'en'] | True |
ForkedDaapdUpdater._update | (self, update_types) | Private update method. | Private update method. | async def _update(self, update_types):
"""Private update method."""
update_types = set(update_types)
update_events = {}
_LOGGER.debug("Updating %s", update_types)
if (
"queue" in update_types
): # update queue, queue before player for async_play_media
queue = await self._api.get_request("queue")
if queue:
update_events["queue"] = asyncio.Event()
async_dispatcher_send(
self.hass,
SIGNAL_UPDATE_QUEUE.format(self._entry_id),
queue,
update_events["queue"],
)
# order of below don't matter
if not {"outputs", "volume"}.isdisjoint(update_types): # update outputs
outputs = await self._api.get_request("outputs")
if outputs:
outputs = outputs["outputs"]
update_events[
"outputs"
] = asyncio.Event() # only for master, zones should ignore
async_dispatcher_send(
self.hass,
SIGNAL_UPDATE_OUTPUTS.format(self._entry_id),
outputs,
update_events["outputs"],
)
self._add_zones(outputs)
if not {"database"}.isdisjoint(update_types):
pipes, playlists = await asyncio.gather(
self._api.get_pipes(), self._api.get_playlists()
)
update_events["database"] = asyncio.Event()
async_dispatcher_send(
self.hass,
SIGNAL_UPDATE_DATABASE.format(self._entry_id),
pipes,
playlists,
update_events["database"],
)
if not {"update", "config"}.isdisjoint(update_types): # not supported
_LOGGER.debug("update/config notifications neither requested nor supported")
if not {"player", "options", "volume"}.isdisjoint(
update_types
): # update player
player = await self._api.get_request("player")
if player:
update_events["player"] = asyncio.Event()
if update_events.get("queue"):
await update_events[
"queue"
].wait() # make sure queue done before player for async_play_media
async_dispatcher_send(
self.hass,
SIGNAL_UPDATE_PLAYER.format(self._entry_id),
player,
update_events["player"],
)
if update_events:
await asyncio.wait(
[event.wait() for event in update_events.values()]
) # make sure callbacks done before update
async_dispatcher_send(
self.hass, SIGNAL_UPDATE_MASTER.format(self._entry_id), True
) | [
"async",
"def",
"_update",
"(",
"self",
",",
"update_types",
")",
":",
"update_types",
"=",
"set",
"(",
"update_types",
")",
"update_events",
"=",
"{",
"}",
"_LOGGER",
".",
"debug",
"(",
"\"Updating %s\"",
",",
"update_types",
")",
"if",
"(",
"\"queue\"",
"in",
"update_types",
")",
":",
"# update queue, queue before player for async_play_media",
"queue",
"=",
"await",
"self",
".",
"_api",
".",
"get_request",
"(",
"\"queue\"",
")",
"if",
"queue",
":",
"update_events",
"[",
"\"queue\"",
"]",
"=",
"asyncio",
".",
"Event",
"(",
")",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_QUEUE",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"queue",
",",
"update_events",
"[",
"\"queue\"",
"]",
",",
")",
"# order of below don't matter",
"if",
"not",
"{",
"\"outputs\"",
",",
"\"volume\"",
"}",
".",
"isdisjoint",
"(",
"update_types",
")",
":",
"# update outputs",
"outputs",
"=",
"await",
"self",
".",
"_api",
".",
"get_request",
"(",
"\"outputs\"",
")",
"if",
"outputs",
":",
"outputs",
"=",
"outputs",
"[",
"\"outputs\"",
"]",
"update_events",
"[",
"\"outputs\"",
"]",
"=",
"asyncio",
".",
"Event",
"(",
")",
"# only for master, zones should ignore",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_OUTPUTS",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"outputs",
",",
"update_events",
"[",
"\"outputs\"",
"]",
",",
")",
"self",
".",
"_add_zones",
"(",
"outputs",
")",
"if",
"not",
"{",
"\"database\"",
"}",
".",
"isdisjoint",
"(",
"update_types",
")",
":",
"pipes",
",",
"playlists",
"=",
"await",
"asyncio",
".",
"gather",
"(",
"self",
".",
"_api",
".",
"get_pipes",
"(",
")",
",",
"self",
".",
"_api",
".",
"get_playlists",
"(",
")",
")",
"update_events",
"[",
"\"database\"",
"]",
"=",
"asyncio",
".",
"Event",
"(",
")",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_DATABASE",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"pipes",
",",
"playlists",
",",
"update_events",
"[",
"\"database\"",
"]",
",",
")",
"if",
"not",
"{",
"\"update\"",
",",
"\"config\"",
"}",
".",
"isdisjoint",
"(",
"update_types",
")",
":",
"# not supported",
"_LOGGER",
".",
"debug",
"(",
"\"update/config notifications neither requested nor supported\"",
")",
"if",
"not",
"{",
"\"player\"",
",",
"\"options\"",
",",
"\"volume\"",
"}",
".",
"isdisjoint",
"(",
"update_types",
")",
":",
"# update player",
"player",
"=",
"await",
"self",
".",
"_api",
".",
"get_request",
"(",
"\"player\"",
")",
"if",
"player",
":",
"update_events",
"[",
"\"player\"",
"]",
"=",
"asyncio",
".",
"Event",
"(",
")",
"if",
"update_events",
".",
"get",
"(",
"\"queue\"",
")",
":",
"await",
"update_events",
"[",
"\"queue\"",
"]",
".",
"wait",
"(",
")",
"# make sure queue done before player for async_play_media",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_PLAYER",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"player",
",",
"update_events",
"[",
"\"player\"",
"]",
",",
")",
"if",
"update_events",
":",
"await",
"asyncio",
".",
"wait",
"(",
"[",
"event",
".",
"wait",
"(",
")",
"for",
"event",
"in",
"update_events",
".",
"values",
"(",
")",
"]",
")",
"# make sure callbacks done before update",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_MASTER",
".",
"format",
"(",
"self",
".",
"_entry_id",
")",
",",
"True",
")"
] | [
793,
4
] | [
861,
13
] | python | en | ['en', 'la', 'en'] | True |
device_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass) | [
"def",
"device_reg",
"(",
"hass",
")",
":",
"return",
"mock_device_registry",
"(",
"hass",
")"
] | [
18,
0
] | [
20,
37
] | python | en | ['en', 'fy', 'en'] | True |
entity_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass) | [
"def",
"entity_reg",
"(",
"hass",
")",
":",
"return",
"mock_registry",
"(",
"hass",
")"
] | [
24,
0
] | [
26,
30
] | python | en | ['en', 'fy', 'en'] | True |
test_websocket_get_actions | (hass, hass_ws_client, device_reg, entity_reg) | Test we get the expected conditions from a light through websocket. | Test we get the expected conditions from a light through websocket. | async def test_websocket_get_actions(hass, hass_ws_client, device_reg, entity_reg):
"""Test we get the expected conditions from a light through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
expected_actions = [
{
"domain": "light",
"type": "turn_off",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
{
"domain": "light",
"type": "turn_on",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
{
"domain": "light",
"type": "toggle",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
]
client = await hass_ws_client(hass)
await client.send_json(
{"id": 1, "type": "device_automation/action/list", "device_id": device_entry.id}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
actions = msg["result"]
assert _same_lists(actions, expected_actions) | [
"async",
"def",
"test_websocket_get_actions",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"light\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_actions",
"=",
"[",
"{",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"turn_off\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"{",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"turn_on\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"{",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"toggle\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"]",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/action/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"actions",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"_same_lists",
"(",
"actions",
",",
"expected_actions",
")"
] | [
39,
0
] | [
80,
49
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_conditions | (hass, hass_ws_client, device_reg, entity_reg) | Test we get the expected conditions from a light through websocket. | Test we get the expected conditions from a light through websocket. | async def test_websocket_get_conditions(hass, hass_ws_client, device_reg, entity_reg):
"""Test we get the expected conditions from a light through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
expected_conditions = [
{
"condition": "device",
"domain": "light",
"type": "is_off",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
{
"condition": "device",
"domain": "light",
"type": "is_on",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
]
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/condition/list",
"device_id": device_entry.id,
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
conditions = msg["result"]
assert _same_lists(conditions, expected_conditions) | [
"async",
"def",
"test_websocket_get_conditions",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"light\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_conditions",
"=",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"is_off\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"]",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/condition/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"conditions",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"_same_lists",
"(",
"conditions",
",",
"expected_conditions",
")"
] | [
83,
0
] | [
124,
55
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_triggers | (hass, hass_ws_client, device_reg, entity_reg) | Test we get the expected triggers from a light through websocket. | Test we get the expected triggers from a light through websocket. | async def test_websocket_get_triggers(hass, hass_ws_client, device_reg, entity_reg):
"""Test we get the expected triggers from a light through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
expected_triggers = [
{
"platform": "device",
"domain": "light",
"type": "turned_off",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
{
"platform": "device",
"domain": "light",
"type": "turned_on",
"device_id": device_entry.id,
"entity_id": "light.test_5678",
},
]
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/trigger/list",
"device_id": device_entry.id,
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
triggers = msg["result"]
assert _same_lists(triggers, expected_triggers) | [
"async",
"def",
"test_websocket_get_triggers",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"light\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_triggers",
"=",
"[",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"turned_off\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
",",
"\"type\"",
":",
"\"turned_on\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"\"light.test_5678\"",
",",
"}",
",",
"]",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/trigger/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"triggers",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"_same_lists",
"(",
"triggers",
",",
"expected_triggers",
")"
] | [
127,
0
] | [
168,
51
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_action_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get the expected action capabilities for an alarm through websocket. | Test we get the expected action capabilities for an alarm through websocket. | async def test_websocket_get_action_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get the expected action capabilities for an alarm through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(
"alarm_control_panel", "test", "5678", device_id=device_entry.id
)
hass.states.async_set(
"alarm_control_panel.test_5678", "attributes", {"supported_features": 15}
)
expected_capabilities = {
"arm_away": {"extra_fields": []},
"arm_home": {"extra_fields": []},
"arm_night": {"extra_fields": []},
"disarm": {
"extra_fields": [{"name": "code", "optional": True, "type": "string"}]
},
"trigger": {"extra_fields": []},
}
client = await hass_ws_client(hass)
await client.send_json(
{"id": 1, "type": "device_automation/action/list", "device_id": device_entry.id}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
actions = msg["result"]
id = 2
assert len(actions) == 5
for action in actions:
await client.send_json(
{
"id": id,
"type": "device_automation/action/capabilities",
"action": action,
}
)
msg = await client.receive_json()
assert msg["id"] == id
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities[action["type"]]
id = id + 1 | [
"async",
"def",
"test_websocket_get_action_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"alarm_control_panel\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"alarm_control_panel.test_5678\"",
",",
"\"attributes\"",
",",
"{",
"\"supported_features\"",
":",
"15",
"}",
")",
"expected_capabilities",
"=",
"{",
"\"arm_away\"",
":",
"{",
"\"extra_fields\"",
":",
"[",
"]",
"}",
",",
"\"arm_home\"",
":",
"{",
"\"extra_fields\"",
":",
"[",
"]",
"}",
",",
"\"arm_night\"",
":",
"{",
"\"extra_fields\"",
":",
"[",
"]",
"}",
",",
"\"disarm\"",
":",
"{",
"\"extra_fields\"",
":",
"[",
"{",
"\"name\"",
":",
"\"code\"",
",",
"\"optional\"",
":",
"True",
",",
"\"type\"",
":",
"\"string\"",
"}",
"]",
"}",
",",
"\"trigger\"",
":",
"{",
"\"extra_fields\"",
":",
"[",
"]",
"}",
",",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/action/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"actions",
"=",
"msg",
"[",
"\"result\"",
"]",
"id",
"=",
"2",
"assert",
"len",
"(",
"actions",
")",
"==",
"5",
"for",
"action",
"in",
"actions",
":",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"id",
",",
"\"type\"",
":",
"\"device_automation/action/capabilities\"",
",",
"\"action\"",
":",
"action",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"id",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities",
"[",
"action",
"[",
"\"type\"",
"]",
"]",
"id",
"=",
"id",
"+",
"1"
] | [
171,
0
] | [
225,
19
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_bad_action_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no action capabilities for a non existing domain. | Test we get no action capabilities for a non existing domain. | async def test_websocket_get_bad_action_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no action capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/action/capabilities",
"action": {"domain": "beer"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_bad_action_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/action/capabilities\"",
",",
"\"action\"",
":",
"{",
"\"domain\"",
":",
"\"beer\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
228,
0
] | [
248,
48
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_no_action_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no action capabilities for a domain with no device action capabilities. | Test we get no action capabilities for a domain with no device action capabilities. | async def test_websocket_get_no_action_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no action capabilities for a domain with no device action capabilities."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/action/capabilities",
"action": {"domain": "deconz"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_no_action_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/action/capabilities\"",
",",
"\"action\"",
":",
"{",
"\"domain\"",
":",
"\"deconz\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
251,
0
] | [
271,
48
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_condition_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get the expected condition capabilities for a light through websocket. | Test we get the expected condition capabilities for a light through websocket. | async def test_websocket_get_condition_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get the expected condition capabilities for a light through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
expected_capabilities = {
"extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"}
]
}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/condition/list",
"device_id": device_entry.id,
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
conditions = msg["result"]
id = 2
assert len(conditions) == 2
for condition in conditions:
await client.send_json(
{
"id": id,
"type": "device_automation/condition/capabilities",
"condition": condition,
}
)
msg = await client.receive_json()
assert msg["id"] == id
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities
id = id + 1 | [
"async",
"def",
"test_websocket_get_condition_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"light\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_capabilities",
"=",
"{",
"\"extra_fields\"",
":",
"[",
"{",
"\"name\"",
":",
"\"for\"",
",",
"\"optional\"",
":",
"True",
",",
"\"type\"",
":",
"\"positive_time_period_dict\"",
"}",
"]",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/condition/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"conditions",
"=",
"msg",
"[",
"\"result\"",
"]",
"id",
"=",
"2",
"assert",
"len",
"(",
"conditions",
")",
"==",
"2",
"for",
"condition",
"in",
"conditions",
":",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"id",
",",
"\"type\"",
":",
"\"device_automation/condition/capabilities\"",
",",
"\"condition\"",
":",
"condition",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"id",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities",
"id",
"=",
"id",
"+",
"1"
] | [
274,
0
] | [
323,
19
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_bad_condition_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no condition capabilities for a non existing domain. | Test we get no condition capabilities for a non existing domain. | async def test_websocket_get_bad_condition_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no condition capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/condition/capabilities",
"condition": {"domain": "beer"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_bad_condition_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/condition/capabilities\"",
",",
"\"condition\"",
":",
"{",
"\"domain\"",
":",
"\"beer\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
326,
0
] | [
346,
48
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_no_condition_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no condition capabilities for a domain with no device condition capabilities. | Test we get no condition capabilities for a domain with no device condition capabilities. | async def test_websocket_get_no_condition_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no condition capabilities for a domain with no device condition capabilities."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/condition/capabilities",
"condition": {"domain": "deconz"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_no_condition_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/condition/capabilities\"",
",",
"\"condition\"",
":",
"{",
"\"domain\"",
":",
"\"deconz\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
349,
0
] | [
369,
48
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_trigger_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get the expected trigger capabilities for a light through websocket. | Test we get the expected trigger capabilities for a light through websocket. | async def test_websocket_get_trigger_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get the expected trigger capabilities for a light through websocket."""
await async_setup_component(hass, "device_automation", {})
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create("light", "test", "5678", device_id=device_entry.id)
expected_capabilities = {
"extra_fields": [
{"name": "for", "optional": True, "type": "positive_time_period_dict"}
]
}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/trigger/list",
"device_id": device_entry.id,
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
triggers = msg["result"]
id = 2
assert len(triggers) == 2
for trigger in triggers:
await client.send_json(
{
"id": id,
"type": "device_automation/trigger/capabilities",
"trigger": trigger,
}
)
msg = await client.receive_json()
assert msg["id"] == id
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities
id = id + 1 | [
"async",
"def",
"test_websocket_get_trigger_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"\"light\"",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"expected_capabilities",
"=",
"{",
"\"extra_fields\"",
":",
"[",
"{",
"\"name\"",
":",
"\"for\"",
",",
"\"optional\"",
":",
"True",
",",
"\"type\"",
":",
"\"positive_time_period_dict\"",
"}",
"]",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/trigger/list\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"triggers",
"=",
"msg",
"[",
"\"result\"",
"]",
"id",
"=",
"2",
"assert",
"len",
"(",
"triggers",
")",
"==",
"2",
"for",
"trigger",
"in",
"triggers",
":",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"id",
",",
"\"type\"",
":",
"\"device_automation/trigger/capabilities\"",
",",
"\"trigger\"",
":",
"trigger",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"id",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities",
"id",
"=",
"id",
"+",
"1"
] | [
372,
0
] | [
421,
19
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_bad_trigger_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no trigger capabilities for a non existing domain. | Test we get no trigger capabilities for a non existing domain. | async def test_websocket_get_bad_trigger_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no trigger capabilities for a non existing domain."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/trigger/capabilities",
"trigger": {"domain": "beer"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_bad_trigger_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/trigger/capabilities\"",
",",
"\"trigger\"",
":",
"{",
"\"domain\"",
":",
"\"beer\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
424,
0
] | [
444,
48
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_get_no_trigger_capabilities | (
hass, hass_ws_client, device_reg, entity_reg
) | Test we get no trigger capabilities for a domain with no device trigger capabilities. | Test we get no trigger capabilities for a domain with no device trigger capabilities. | async def test_websocket_get_no_trigger_capabilities(
hass, hass_ws_client, device_reg, entity_reg
):
"""Test we get no trigger capabilities for a domain with no device trigger capabilities."""
await async_setup_component(hass, "device_automation", {})
expected_capabilities = {}
client = await hass_ws_client(hass)
await client.send_json(
{
"id": 1,
"type": "device_automation/trigger/capabilities",
"trigger": {"domain": "deconz"},
}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert msg["type"] == TYPE_RESULT
assert msg["success"]
capabilities = msg["result"]
assert capabilities == expected_capabilities | [
"async",
"def",
"test_websocket_get_no_trigger_capabilities",
"(",
"hass",
",",
"hass_ws_client",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"expected_capabilities",
"=",
"{",
"}",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/trigger/capabilities\"",
",",
"\"trigger\"",
":",
"{",
"\"domain\"",
":",
"\"deconz\"",
"}",
",",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"msg",
"[",
"\"type\"",
"]",
"==",
"TYPE_RESULT",
"assert",
"msg",
"[",
"\"success\"",
"]",
"capabilities",
"=",
"msg",
"[",
"\"result\"",
"]",
"assert",
"capabilities",
"==",
"expected_capabilities"
] | [
447,
0
] | [
467,
48
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_non_existing_integration | (hass, caplog) | Test device automation with non existing integration. | Test device automation with non existing integration. | async def test_automation_with_non_existing_integration(hass, caplog):
"""Test device automation with non existing integration."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {
"platform": "device",
"device_id": "none",
"domain": "beer",
},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert "Integration 'beer' not found" in caplog.text | [
"async",
"def",
"test_automation_with_non_existing_integration",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"device_id\"",
":",
"\"none\"",
",",
"\"domain\"",
":",
"\"beer\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"Integration 'beer' not found\"",
"in",
"caplog",
".",
"text"
] | [
470,
0
] | [
488,
56
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_integration_without_device_action | (hass, caplog) | Test automation with integration without device action support. | Test automation with integration without device action support. | async def test_automation_with_integration_without_device_action(hass, caplog):
"""Test automation with integration without device action support."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"action": {"device_id": "", "domain": "test"},
}
},
)
assert (
"Integration 'test' does not support device automation actions" in caplog.text
) | [
"async",
"def",
"test_automation_with_integration_without_device_action",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"action\"",
":",
"{",
"\"device_id\"",
":",
"\"\"",
",",
"\"domain\"",
":",
"\"test\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"(",
"\"Integration 'test' does not support device automation actions\"",
"in",
"caplog",
".",
"text",
")"
] | [
491,
0
] | [
507,
5
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_integration_without_device_condition | (hass, caplog) | Test automation with integration without device condition support. | Test automation with integration without device condition support. | async def test_automation_with_integration_without_device_condition(hass, caplog):
"""Test automation with integration without device condition support."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": {
"condition": "device",
"device_id": "none",
"domain": "test",
},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert (
"Integration 'test' does not support device automation conditions"
in caplog.text
) | [
"async",
"def",
"test_automation_with_integration_without_device_condition",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"device_id\"",
":",
"\"none\"",
",",
"\"domain\"",
":",
"\"test\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"(",
"\"Integration 'test' does not support device automation conditions\"",
"in",
"caplog",
".",
"text",
")"
] | [
510,
0
] | [
532,
5
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_integration_without_device_trigger | (hass, caplog) | Test automation with integration without device trigger support. | Test automation with integration without device trigger support. | async def test_automation_with_integration_without_device_trigger(hass, caplog):
"""Test automation with integration without device trigger support."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {
"platform": "device",
"device_id": "none",
"domain": "test",
},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert (
"Integration 'test' does not support device automation triggers" in caplog.text
) | [
"async",
"def",
"test_automation_with_integration_without_device_trigger",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"device_id\"",
":",
"\"none\"",
",",
"\"domain\"",
":",
"\"test\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"(",
"\"Integration 'test' does not support device automation triggers\"",
"in",
"caplog",
".",
"text",
")"
] | [
535,
0
] | [
555,
5
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_bad_action | (hass, caplog) | Test automation with bad device action. | Test automation with bad device action. | async def test_automation_with_bad_action(hass, caplog):
"""Test automation with bad device action."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"action": {"device_id": "", "domain": "light"},
}
},
)
assert "required key not provided" in caplog.text | [
"async",
"def",
"test_automation_with_bad_action",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"action\"",
":",
"{",
"\"device_id\"",
":",
"\"\"",
",",
"\"domain\"",
":",
"\"light\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"required key not provided\"",
"in",
"caplog",
".",
"text"
] | [
558,
0
] | [
572,
53
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_bad_condition_action | (hass, caplog) | Test automation with bad device action. | Test automation with bad device action. | async def test_automation_with_bad_condition_action(hass, caplog):
"""Test automation with bad device action."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"action": {"condition": "device", "device_id": "", "domain": "light"},
}
},
)
assert "required key not provided" in caplog.text | [
"async",
"def",
"test_automation_with_bad_condition_action",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"action\"",
":",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"domain\"",
":",
"\"light\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"required key not provided\"",
"in",
"caplog",
".",
"text"
] | [
575,
0
] | [
589,
53
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_bad_condition | (hass, caplog) | Test automation with bad device condition. | Test automation with bad device condition. | async def test_automation_with_bad_condition(hass, caplog):
"""Test automation with bad device condition."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": {"condition": "device", "domain": "light"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert "required key not provided" in caplog.text | [
"async",
"def",
"test_automation_with_bad_condition",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"required key not provided\"",
"in",
"caplog",
".",
"text"
] | [
592,
0
] | [
607,
53
] | python | en | ['en', 'en', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
611,
0
] | [
613,
57
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_sub_condition | (hass, calls) | Test automation with device condition under and/or conditions. | Test automation with device condition under and/or conditions. | async def test_automation_with_sub_condition(hass, calls):
"""Test automation with device condition under and/or conditions."""
DOMAIN = "light"
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
await hass.async_block_till_done()
ent1, ent2, ent3 = platform.ENTITIES
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": [
{
"condition": "and",
"conditions": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent1.entity_id,
"type": "is_on",
},
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent2.entity_id,
"type": "is_on",
},
],
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "and {{ trigger.%s }}"
% "}} - {{ trigger.".join(("platform", "event.event_type"))
},
},
},
{
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": [
{
"condition": "or",
"conditions": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent1.entity_id,
"type": "is_on",
},
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": ent2.entity_id,
"type": "is_on",
},
],
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "or {{ trigger.%s }}"
% "}} - {{ trigger.".join(("platform", "event.event_type"))
},
},
},
]
},
)
await hass.async_block_till_done()
assert hass.states.get(ent1.entity_id).state == STATE_ON
assert hass.states.get(ent2.entity_id).state == STATE_OFF
assert len(calls) == 0
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "or event - test_event1"
hass.states.async_set(ent1.entity_id, STATE_OFF)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
hass.states.async_set(ent2.entity_id, STATE_ON)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[1].data["some"] == "or event - test_event1"
hass.states.async_set(ent1.entity_id, STATE_ON)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 4
assert _same_lists(
[calls[2].data["some"], calls[3].data["some"]],
["or event - test_event1", "and event - test_event1"],
) | [
"async",
"def",
"test_automation_with_sub_condition",
"(",
"hass",
",",
"calls",
")",
":",
"DOMAIN",
"=",
"\"light\"",
"platform",
"=",
"getattr",
"(",
"hass",
".",
"components",
",",
"f\"test.{DOMAIN}\"",
")",
"platform",
".",
"init",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_PLATFORM",
":",
"\"test\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"ent1",
",",
"ent2",
",",
"ent3",
"=",
"platform",
".",
"ENTITIES",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"[",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"and\"",
",",
"\"conditions\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent1",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"}",
",",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent2",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"}",
",",
"]",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"and {{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"event.event_type\"",
")",
")",
"}",
",",
"}",
",",
"}",
",",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"or\"",
",",
"\"conditions\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent1",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"}",
",",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"ent2",
".",
"entity_id",
",",
"\"type\"",
":",
"\"is_on\"",
",",
"}",
",",
"]",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"or {{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"event.event_type\"",
")",
")",
"}",
",",
"}",
",",
"}",
",",
"]",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"ent1",
".",
"entity_id",
")",
".",
"state",
"==",
"STATE_ON",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"ent2",
".",
"entity_id",
")",
".",
"state",
"==",
"STATE_OFF",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"or event - test_event1\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"ent1",
".",
"entity_id",
",",
"STATE_OFF",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"ent2",
".",
"entity_id",
",",
"STATE_ON",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2",
"assert",
"calls",
"[",
"1",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"or event - test_event1\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"ent1",
".",
"entity_id",
",",
"STATE_ON",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"4",
"assert",
"_same_lists",
"(",
"[",
"calls",
"[",
"2",
"]",
".",
"data",
"[",
"\"some\"",
"]",
",",
"calls",
"[",
"3",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"]",
",",
"[",
"\"or event - test_event1\"",
",",
"\"and event - test_event1\"",
"]",
",",
")"
] | [
616,
0
] | [
724,
5
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_bad_sub_condition | (hass, caplog) | Test automation with bad device condition under and/or conditions. | Test automation with bad device condition under and/or conditions. | async def test_automation_with_bad_sub_condition(hass, caplog):
"""Test automation with bad device condition under and/or conditions."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": {
"condition": "and",
"conditions": [{"condition": "device", "domain": "light"}],
},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert "required key not provided" in caplog.text | [
"async",
"def",
"test_automation_with_bad_sub_condition",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"{",
"\"condition\"",
":",
"\"and\"",
",",
"\"conditions\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
"}",
"]",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"required key not provided\"",
"in",
"caplog",
".",
"text"
] | [
727,
0
] | [
745,
53
] | python | en | ['en', 'en', 'en'] | True |
test_automation_with_bad_trigger | (hass, caplog) | Test automation with bad device trigger. | Test automation with bad device trigger. | async def test_automation_with_bad_trigger(hass, caplog):
"""Test automation with bad device trigger."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"alias": "hello",
"trigger": {"platform": "device", "domain": "light"},
"action": {"service": "test.automation", "entity_id": "hello.world"},
}
},
)
assert "required key not provided" in caplog.text | [
"async",
"def",
"test_automation_with_bad_trigger",
"(",
"hass",
",",
"caplog",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"alias\"",
":",
"\"hello\"",
",",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"\"light\"",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"entity_id\"",
":",
"\"hello.world\"",
"}",
",",
"}",
"}",
",",
")",
"assert",
"\"required key not provided\"",
"in",
"caplog",
".",
"text"
] | [
748,
0
] | [
762,
53
] | python | en | ['en', 'en', 'en'] | True |
test_websocket_device_not_found | (hass, hass_ws_client) | Test calling command with unknown device. | Test calling command with unknown device. | async def test_websocket_device_not_found(hass, hass_ws_client):
"""Test calling command with unknown device."""
await async_setup_component(hass, "device_automation", {})
client = await hass_ws_client(hass)
await client.send_json(
{"id": 1, "type": "device_automation/action/list", "device_id": "non-existing"}
)
msg = await client.receive_json()
assert msg["id"] == 1
assert not msg["success"]
assert msg["error"] == {"code": "not_found", "message": "Device not found"} | [
"async",
"def",
"test_websocket_device_not_found",
"(",
"hass",
",",
"hass_ws_client",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"device_automation\"",
",",
"{",
"}",
")",
"client",
"=",
"await",
"hass_ws_client",
"(",
"hass",
")",
"await",
"client",
".",
"send_json",
"(",
"{",
"\"id\"",
":",
"1",
",",
"\"type\"",
":",
"\"device_automation/action/list\"",
",",
"\"device_id\"",
":",
"\"non-existing\"",
"}",
")",
"msg",
"=",
"await",
"client",
".",
"receive_json",
"(",
")",
"assert",
"msg",
"[",
"\"id\"",
"]",
"==",
"1",
"assert",
"not",
"msg",
"[",
"\"success\"",
"]",
"assert",
"msg",
"[",
"\"error\"",
"]",
"==",
"{",
"\"code\"",
":",
"\"not_found\"",
",",
"\"message\"",
":",
"\"Device not found\"",
"}"
] | [
765,
0
] | [
776,
79
] | python | en | ['en', 'en', 'en'] | True |
create_lock_service | (accessory) | Define a lock characteristics as per page 219 of HAP spec. | Define a lock characteristics as per page 219 of HAP spec. | def create_lock_service(accessory):
"""Define a lock characteristics as per page 219 of HAP spec."""
service = accessory.add_service(ServicesTypes.LOCK_MECHANISM)
cur_state = service.add_char(CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE)
cur_state.value = 0
targ_state = service.add_char(CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE)
targ_state.value = 0
# According to the spec, a battery-level characteristic is normally
# part of a separate service. However as the code was written (which
# predates this test) the battery level would have to be part of the lock
# service as it is here.
targ_state = service.add_char(CharacteristicsTypes.BATTERY_LEVEL)
targ_state.value = 50
return service | [
"def",
"create_lock_service",
"(",
"accessory",
")",
":",
"service",
"=",
"accessory",
".",
"add_service",
"(",
"ServicesTypes",
".",
"LOCK_MECHANISM",
")",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"LOCK_MECHANISM_CURRENT_STATE",
")",
"cur_state",
".",
"value",
"=",
"0",
"targ_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"LOCK_MECHANISM_TARGET_STATE",
")",
"targ_state",
".",
"value",
"=",
"0",
"# According to the spec, a battery-level characteristic is normally",
"# part of a separate service. However as the code was written (which",
"# predates this test) the battery level would have to be part of the lock",
"# service as it is here.",
"targ_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"BATTERY_LEVEL",
")",
"targ_state",
".",
"value",
"=",
"50",
"return",
"service"
] | [
10,
0
] | [
27,
18
] | python | en | ['en', 'ca', 'en'] | True |
test_switch_change_lock_state | (hass, utcnow) | Test that we can turn a HomeKit lock on and off again. | Test that we can turn a HomeKit lock on and off again. | async def test_switch_change_lock_state(hass, utcnow):
"""Test that we can turn a HomeKit lock on and off again."""
helper = await setup_test_component(hass, create_lock_service)
await hass.services.async_call(
"lock", "lock", {"entity_id": "lock.testdevice"}, blocking=True
)
assert helper.characteristics[LOCK_TARGET_STATE].value == 1
await hass.services.async_call(
"lock", "unlock", {"entity_id": "lock.testdevice"}, blocking=True
)
assert helper.characteristics[LOCK_TARGET_STATE].value == 0 | [
"async",
"def",
"test_switch_change_lock_state",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_lock_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"lock\"",
",",
"\"lock\"",
",",
"{",
"\"entity_id\"",
":",
"\"lock.testdevice\"",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"LOCK_TARGET_STATE",
"]",
".",
"value",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"lock\"",
",",
"\"unlock\"",
",",
"{",
"\"entity_id\"",
":",
"\"lock.testdevice\"",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"LOCK_TARGET_STATE",
"]",
".",
"value",
"==",
"0"
] | [
30,
0
] | [
42,
63
] | python | en | ['en', 'en', 'en'] | True |
test_switch_read_lock_state | (hass, utcnow) | Test that we can read the state of a HomeKit lock accessory. | Test that we can read the state of a HomeKit lock accessory. | async def test_switch_read_lock_state(hass, utcnow):
"""Test that we can read the state of a HomeKit lock accessory."""
helper = await setup_test_component(hass, create_lock_service)
helper.characteristics[LOCK_CURRENT_STATE].value = 0
helper.characteristics[LOCK_TARGET_STATE].value = 0
state = await helper.poll_and_get_state()
assert state.state == "unlocked"
assert state.attributes["battery_level"] == 50
helper.characteristics[LOCK_CURRENT_STATE].value = 1
helper.characteristics[LOCK_TARGET_STATE].value = 1
state = await helper.poll_and_get_state()
assert state.state == "locked" | [
"async",
"def",
"test_switch_read_lock_state",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_lock_service",
")",
"helper",
".",
"characteristics",
"[",
"LOCK_CURRENT_STATE",
"]",
".",
"value",
"=",
"0",
"helper",
".",
"characteristics",
"[",
"LOCK_TARGET_STATE",
"]",
".",
"value",
"=",
"0",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"unlocked\"",
"assert",
"state",
".",
"attributes",
"[",
"\"battery_level\"",
"]",
"==",
"50",
"helper",
".",
"characteristics",
"[",
"LOCK_CURRENT_STATE",
"]",
".",
"value",
"=",
"1",
"helper",
".",
"characteristics",
"[",
"LOCK_TARGET_STATE",
"]",
".",
"value",
"=",
"1",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"locked\""
] | [
45,
0
] | [
58,
34
] | python | en | ['en', 'en', 'en'] | True |
device_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass) | [
"def",
"device_reg",
"(",
"hass",
")",
":",
"return",
"mock_device_registry",
"(",
"hass",
")"
] | [
27,
0
] | [
29,
37
] | python | en | ['en', 'fy', 'en'] | True |
entity_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass) | [
"def",
"entity_reg",
"(",
"hass",
")",
":",
"return",
"mock_registry",
"(",
"hass",
")"
] | [
33,
0
] | [
35,
30
] | python | en | ['en', 'fy', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
39,
0
] | [
41,
57
] | python | en | ['en', 'en', 'en'] | True |
test_get_triggers | (hass, device_reg, entity_reg) | Test we get the expected triggers from a cover. | Test we get the expected triggers from a cover. | async def test_get_triggers(hass, device_reg, entity_reg):
"""Test we get the expected triggers from a cover."""
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
ent = platform.ENTITIES[0]
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
expected_triggers = [
{
"platform": "device",
"domain": DOMAIN,
"type": "opened",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "closed",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "opening",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "closing",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
]
triggers = await async_get_device_automations(hass, "trigger", device_entry.id)
assert_lists_same(triggers, expected_triggers) | [
"async",
"def",
"test_get_triggers",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"platform",
"=",
"getattr",
"(",
"hass",
".",
"components",
",",
"f\"test.{DOMAIN}\"",
")",
"platform",
".",
"init",
"(",
")",
"ent",
"=",
"platform",
".",
"ENTITIES",
"[",
"0",
"]",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"ent",
".",
"unique_id",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_PLATFORM",
":",
"\"test\"",
"}",
"}",
")",
"expected_triggers",
"=",
"[",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"opened\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"closed\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"opening\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"closing\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"]",
"triggers",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"trigger\"",
",",
"device_entry",
".",
"id",
")",
"assert_lists_same",
"(",
"triggers",
",",
"expected_triggers",
")"
] | [
44,
0
] | [
92,
50
] | python | en | ['en', 'en', 'en'] | True |
test_get_triggers_set_pos | (hass, device_reg, entity_reg) | Test we get the expected triggers from a cover. | Test we get the expected triggers from a cover. | async def test_get_triggers_set_pos(hass, device_reg, entity_reg):
"""Test we get the expected triggers from a cover."""
platform = getattr(hass.components, f"test.{DOMAIN}")
platform.init()
ent = platform.ENTITIES[1]
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(
DOMAIN, "test", ent.unique_id, device_id=device_entry.id
)
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {CONF_PLATFORM: "test"}})
expected_triggers = [
{
"platform": "device",
"domain": DOMAIN,
"type": "opened",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "closed",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "opening",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "closing",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
{
"platform": "device",
"domain": DOMAIN,
"type": "position",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_{ent.unique_id}",
},
]
triggers = await async_get_device_automations(hass, "trigger", device_entry.id)
assert_lists_same(triggers, expected_triggers) | [
"async",
"def",
"test_get_triggers_set_pos",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"platform",
"=",
"getattr",
"(",
"hass",
".",
"components",
",",
"f\"test.{DOMAIN}\"",
")",
"platform",
".",
"init",
"(",
")",
"ent",
"=",
"platform",
".",
"ENTITIES",
"[",
"1",
"]",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"ent",
".",
"unique_id",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_PLATFORM",
":",
"\"test\"",
"}",
"}",
")",
"expected_triggers",
"=",
"[",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"opened\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"closed\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"opening\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"closing\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"{",
"\"platform\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"position\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_{ent.unique_id}\"",
",",
"}",
",",
"]",
"triggers",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"trigger\"",
",",
"device_entry",
".",
"id",
")",
"assert_lists_same",
"(",
"triggers",
",",
"expected_triggers",
")"
] | [
95,
0
] | [
150,
50
] | 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.