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 |
---|---|---|---|---|---|---|---|---|---|---|---|
BluesoundPlayer.async_update | (self) | Update internal status of the entity. | Update internal status of the entity. | async def async_update(self):
"""Update internal status of the entity."""
if not self._is_online:
return
await self.async_update_sync_status()
await self.async_update_presets()
await self.async_update_captures()
await self.async_update_services() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_is_online",
":",
"return",
"await",
"self",
".",
"async_update_sync_status",
"(",
")",
"await",
"self",
".",
"async_update_presets",
"(",
")",
"await",
"self",
".",
"async_update_captures",
"(",
")",
"await",
"self",
".",
"async_update_services",
"(",
")"
] | [
328,
4
] | [
336,
42
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.send_bluesound_command | (
self, method, raise_timeout=False, allow_offline=False
) | Send command to the player. | Send command to the player. | async def send_bluesound_command(
self, method, raise_timeout=False, allow_offline=False
):
"""Send command to the player."""
if not self._is_online and not allow_offline:
return
if method[0] == "/":
method = method[1:]
url = f"http://{self.host}:{self.port}/{method}"
_LOGGER.debug("Calling URL: %s", url)
response = None
try:
websession = async_get_clientsession(self._hass)
with async_timeout.timeout(10):
response = await websession.get(url)
if response.status == HTTP_OK:
result = await response.text()
if result:
data = xmltodict.parse(result)
else:
data = None
elif response.status == 595:
_LOGGER.info("Status 595 returned, treating as timeout")
raise BluesoundPlayer._TimeoutException()
else:
_LOGGER.error("Error %s on %s", response.status, url)
return None
except (asyncio.TimeoutError, aiohttp.ClientError):
if raise_timeout:
_LOGGER.info("Timeout: %s", self.host)
raise
_LOGGER.debug("Failed communicating: %s", self.host)
return None
return data | [
"async",
"def",
"send_bluesound_command",
"(",
"self",
",",
"method",
",",
"raise_timeout",
"=",
"False",
",",
"allow_offline",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"_is_online",
"and",
"not",
"allow_offline",
":",
"return",
"if",
"method",
"[",
"0",
"]",
"==",
"\"/\"",
":",
"method",
"=",
"method",
"[",
"1",
":",
"]",
"url",
"=",
"f\"http://{self.host}:{self.port}/{method}\"",
"_LOGGER",
".",
"debug",
"(",
"\"Calling URL: %s\"",
",",
"url",
")",
"response",
"=",
"None",
"try",
":",
"websession",
"=",
"async_get_clientsession",
"(",
"self",
".",
"_hass",
")",
"with",
"async_timeout",
".",
"timeout",
"(",
"10",
")",
":",
"response",
"=",
"await",
"websession",
".",
"get",
"(",
"url",
")",
"if",
"response",
".",
"status",
"==",
"HTTP_OK",
":",
"result",
"=",
"await",
"response",
".",
"text",
"(",
")",
"if",
"result",
":",
"data",
"=",
"xmltodict",
".",
"parse",
"(",
"result",
")",
"else",
":",
"data",
"=",
"None",
"elif",
"response",
".",
"status",
"==",
"595",
":",
"_LOGGER",
".",
"info",
"(",
"\"Status 595 returned, treating as timeout\"",
")",
"raise",
"BluesoundPlayer",
".",
"_TimeoutException",
"(",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error %s on %s\"",
",",
"response",
".",
"status",
",",
"url",
")",
"return",
"None",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"aiohttp",
".",
"ClientError",
")",
":",
"if",
"raise_timeout",
":",
"_LOGGER",
".",
"info",
"(",
"\"Timeout: %s\"",
",",
"self",
".",
"host",
")",
"raise",
"_LOGGER",
".",
"debug",
"(",
"\"Failed communicating: %s\"",
",",
"self",
".",
"host",
")",
"return",
"None",
"return",
"data"
] | [
338,
4
] | [
377,
19
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_update_status | (self) | Use the poll session to always get the status of the player. | Use the poll session to always get the status of the player. | async def async_update_status(self):
"""Use the poll session to always get the status of the player."""
response = None
url = "Status"
etag = ""
if self._status is not None:
etag = self._status.get("@etag", "")
if etag != "":
url = f"Status?etag={etag}&timeout=120.0"
url = f"http://{self.host}:{self.port}/{url}"
_LOGGER.debug("Calling URL: %s", url)
try:
with async_timeout.timeout(125):
response = await self._polling_session.get(
url, headers={CONNECTION: KEEP_ALIVE}
)
if response.status == HTTP_OK:
result = await response.text()
self._is_online = True
self._last_status_update = dt_util.utcnow()
self._status = xmltodict.parse(result)["status"].copy()
group_name = self._status.get("groupName")
if group_name != self._group_name:
_LOGGER.debug("Group name change detected on device: %s", self.host)
self._group_name = group_name
# rebuild ordered list of entity_ids that are in the group, master is first
self._group_list = self.rebuild_bluesound_group()
# the sleep is needed to make sure that the
# devices is synced
await asyncio.sleep(1)
await self.async_trigger_sync_on_all()
elif self.is_grouped:
# when player is grouped we need to fetch volume from
# sync_status. We will force an update if the player is
# grouped this isn't a foolproof solution. A better
# solution would be to fetch sync_status more often when
# the device is playing. This would solve a lot of
# problems. This change will be done when the
# communication is moved to a separate library
await self.force_update_sync_status()
self.async_write_ha_state()
elif response.status == 595:
_LOGGER.info("Status 595 returned, treating as timeout")
raise BluesoundPlayer._TimeoutException()
else:
_LOGGER.error(
"Error %s on %s. Trying one more time", response.status, url
)
except (asyncio.TimeoutError, ClientError):
self._is_online = False
self._last_status_update = None
self._status = None
self.async_write_ha_state()
_LOGGER.info("Client connection error, marking %s as offline", self._name)
raise | [
"async",
"def",
"async_update_status",
"(",
"self",
")",
":",
"response",
"=",
"None",
"url",
"=",
"\"Status\"",
"etag",
"=",
"\"\"",
"if",
"self",
".",
"_status",
"is",
"not",
"None",
":",
"etag",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"@etag\"",
",",
"\"\"",
")",
"if",
"etag",
"!=",
"\"\"",
":",
"url",
"=",
"f\"Status?etag={etag}&timeout=120.0\"",
"url",
"=",
"f\"http://{self.host}:{self.port}/{url}\"",
"_LOGGER",
".",
"debug",
"(",
"\"Calling URL: %s\"",
",",
"url",
")",
"try",
":",
"with",
"async_timeout",
".",
"timeout",
"(",
"125",
")",
":",
"response",
"=",
"await",
"self",
".",
"_polling_session",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"{",
"CONNECTION",
":",
"KEEP_ALIVE",
"}",
")",
"if",
"response",
".",
"status",
"==",
"HTTP_OK",
":",
"result",
"=",
"await",
"response",
".",
"text",
"(",
")",
"self",
".",
"_is_online",
"=",
"True",
"self",
".",
"_last_status_update",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"self",
".",
"_status",
"=",
"xmltodict",
".",
"parse",
"(",
"result",
")",
"[",
"\"status\"",
"]",
".",
"copy",
"(",
")",
"group_name",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"groupName\"",
")",
"if",
"group_name",
"!=",
"self",
".",
"_group_name",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Group name change detected on device: %s\"",
",",
"self",
".",
"host",
")",
"self",
".",
"_group_name",
"=",
"group_name",
"# rebuild ordered list of entity_ids that are in the group, master is first",
"self",
".",
"_group_list",
"=",
"self",
".",
"rebuild_bluesound_group",
"(",
")",
"# the sleep is needed to make sure that the",
"# devices is synced",
"await",
"asyncio",
".",
"sleep",
"(",
"1",
")",
"await",
"self",
".",
"async_trigger_sync_on_all",
"(",
")",
"elif",
"self",
".",
"is_grouped",
":",
"# when player is grouped we need to fetch volume from",
"# sync_status. We will force an update if the player is",
"# grouped this isn't a foolproof solution. A better",
"# solution would be to fetch sync_status more often when",
"# the device is playing. This would solve a lot of",
"# problems. This change will be done when the",
"# communication is moved to a separate library",
"await",
"self",
".",
"force_update_sync_status",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")",
"elif",
"response",
".",
"status",
"==",
"595",
":",
"_LOGGER",
".",
"info",
"(",
"\"Status 595 returned, treating as timeout\"",
")",
"raise",
"BluesoundPlayer",
".",
"_TimeoutException",
"(",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error %s on %s. Trying one more time\"",
",",
"response",
".",
"status",
",",
"url",
")",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"ClientError",
")",
":",
"self",
".",
"_is_online",
"=",
"False",
"self",
".",
"_last_status_update",
"=",
"None",
"self",
".",
"_status",
"=",
"None",
"self",
".",
"async_write_ha_state",
"(",
")",
"_LOGGER",
".",
"info",
"(",
"\"Client connection error, marking %s as offline\"",
",",
"self",
".",
"_name",
")",
"raise"
] | [
379,
4
] | [
444,
17
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_trigger_sync_on_all | (self) | Trigger sync status update on all devices. | Trigger sync status update on all devices. | async def async_trigger_sync_on_all(self):
"""Trigger sync status update on all devices."""
_LOGGER.debug("Trigger sync status on all devices")
for player in self._hass.data[DATA_BLUESOUND]:
await player.force_update_sync_status() | [
"async",
"def",
"async_trigger_sync_on_all",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Trigger sync status on all devices\"",
")",
"for",
"player",
"in",
"self",
".",
"_hass",
".",
"data",
"[",
"DATA_BLUESOUND",
"]",
":",
"await",
"player",
".",
"force_update_sync_status",
"(",
")"
] | [
446,
4
] | [
451,
51
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_update_sync_status | (self, on_updated_cb=None, raise_timeout=False) | Update sync status. | Update sync status. | async def async_update_sync_status(self, on_updated_cb=None, raise_timeout=False):
"""Update sync status."""
await self.force_update_sync_status(on_updated_cb, raise_timeout=False) | [
"async",
"def",
"async_update_sync_status",
"(",
"self",
",",
"on_updated_cb",
"=",
"None",
",",
"raise_timeout",
"=",
"False",
")",
":",
"await",
"self",
".",
"force_update_sync_status",
"(",
"on_updated_cb",
",",
"raise_timeout",
"=",
"False",
")"
] | [
454,
4
] | [
456,
79
] | python | en | ['fr', 'sn', 'en'] | False |
BluesoundPlayer.async_update_captures | (self) | Update Capture sources. | Update Capture sources. | async def async_update_captures(self):
"""Update Capture sources."""
resp = await self.send_bluesound_command("RadioBrowse?service=Capture")
if not resp:
return
self._capture_items = []
def _create_capture_item(item):
self._capture_items.append(
{
"title": item.get("@text", ""),
"name": item.get("@text", ""),
"type": item.get("@serviceType", "Capture"),
"image": item.get("@image", ""),
"url": item.get("@URL", ""),
}
)
if "radiotime" in resp and "item" in resp["radiotime"]:
if isinstance(resp["radiotime"]["item"], list):
for item in resp["radiotime"]["item"]:
_create_capture_item(item)
else:
_create_capture_item(resp["radiotime"]["item"])
return self._capture_items | [
"async",
"def",
"async_update_captures",
"(",
"self",
")",
":",
"resp",
"=",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"RadioBrowse?service=Capture\"",
")",
"if",
"not",
"resp",
":",
"return",
"self",
".",
"_capture_items",
"=",
"[",
"]",
"def",
"_create_capture_item",
"(",
"item",
")",
":",
"self",
".",
"_capture_items",
".",
"append",
"(",
"{",
"\"title\"",
":",
"item",
".",
"get",
"(",
"\"@text\"",
",",
"\"\"",
")",
",",
"\"name\"",
":",
"item",
".",
"get",
"(",
"\"@text\"",
",",
"\"\"",
")",
",",
"\"type\"",
":",
"item",
".",
"get",
"(",
"\"@serviceType\"",
",",
"\"Capture\"",
")",
",",
"\"image\"",
":",
"item",
".",
"get",
"(",
"\"@image\"",
",",
"\"\"",
")",
",",
"\"url\"",
":",
"item",
".",
"get",
"(",
"\"@URL\"",
",",
"\"\"",
")",
",",
"}",
")",
"if",
"\"radiotime\"",
"in",
"resp",
"and",
"\"item\"",
"in",
"resp",
"[",
"\"radiotime\"",
"]",
":",
"if",
"isinstance",
"(",
"resp",
"[",
"\"radiotime\"",
"]",
"[",
"\"item\"",
"]",
",",
"list",
")",
":",
"for",
"item",
"in",
"resp",
"[",
"\"radiotime\"",
"]",
"[",
"\"item\"",
"]",
":",
"_create_capture_item",
"(",
"item",
")",
"else",
":",
"_create_capture_item",
"(",
"resp",
"[",
"\"radiotime\"",
"]",
"[",
"\"item\"",
"]",
")",
"return",
"self",
".",
"_capture_items"
] | [
459,
4
] | [
484,
34
] | python | en | ['en', 'nl', 'en'] | True |
BluesoundPlayer.async_update_presets | (self) | Update Presets. | Update Presets. | async def async_update_presets(self):
"""Update Presets."""
resp = await self.send_bluesound_command("Presets")
if not resp:
return
self._preset_items = []
def _create_preset_item(item):
self._preset_items.append(
{
"title": item.get("@name", ""),
"name": item.get("@name", ""),
"type": "preset",
"image": item.get("@image", ""),
"is_raw_url": True,
"url2": item.get("@url", ""),
"url": f"Preset?id={item.get('@id', '')}",
}
)
if "presets" in resp and "preset" in resp["presets"]:
if isinstance(resp["presets"]["preset"], list):
for item in resp["presets"]["preset"]:
_create_preset_item(item)
else:
_create_preset_item(resp["presets"]["preset"])
return self._preset_items | [
"async",
"def",
"async_update_presets",
"(",
"self",
")",
":",
"resp",
"=",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Presets\"",
")",
"if",
"not",
"resp",
":",
"return",
"self",
".",
"_preset_items",
"=",
"[",
"]",
"def",
"_create_preset_item",
"(",
"item",
")",
":",
"self",
".",
"_preset_items",
".",
"append",
"(",
"{",
"\"title\"",
":",
"item",
".",
"get",
"(",
"\"@name\"",
",",
"\"\"",
")",
",",
"\"name\"",
":",
"item",
".",
"get",
"(",
"\"@name\"",
",",
"\"\"",
")",
",",
"\"type\"",
":",
"\"preset\"",
",",
"\"image\"",
":",
"item",
".",
"get",
"(",
"\"@image\"",
",",
"\"\"",
")",
",",
"\"is_raw_url\"",
":",
"True",
",",
"\"url2\"",
":",
"item",
".",
"get",
"(",
"\"@url\"",
",",
"\"\"",
")",
",",
"\"url\"",
":",
"f\"Preset?id={item.get('@id', '')}\"",
",",
"}",
")",
"if",
"\"presets\"",
"in",
"resp",
"and",
"\"preset\"",
"in",
"resp",
"[",
"\"presets\"",
"]",
":",
"if",
"isinstance",
"(",
"resp",
"[",
"\"presets\"",
"]",
"[",
"\"preset\"",
"]",
",",
"list",
")",
":",
"for",
"item",
"in",
"resp",
"[",
"\"presets\"",
"]",
"[",
"\"preset\"",
"]",
":",
"_create_preset_item",
"(",
"item",
")",
"else",
":",
"_create_preset_item",
"(",
"resp",
"[",
"\"presets\"",
"]",
"[",
"\"preset\"",
"]",
")",
"return",
"self",
".",
"_preset_items"
] | [
487,
4
] | [
514,
33
] | python | co | ['de', 'co', 'en'] | False |
BluesoundPlayer.async_update_services | (self) | Update Services. | Update Services. | async def async_update_services(self):
"""Update Services."""
resp = await self.send_bluesound_command("Services")
if not resp:
return
self._services_items = []
def _create_service_item(item):
self._services_items.append(
{
"title": item.get("@displayname", ""),
"name": item.get("@name", ""),
"type": item.get("@type", ""),
"image": item.get("@icon", ""),
"url": item.get("@name", ""),
}
)
if "services" in resp and "service" in resp["services"]:
if isinstance(resp["services"]["service"], list):
for item in resp["services"]["service"]:
_create_service_item(item)
else:
_create_service_item(resp["services"]["service"])
return self._services_items | [
"async",
"def",
"async_update_services",
"(",
"self",
")",
":",
"resp",
"=",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Services\"",
")",
"if",
"not",
"resp",
":",
"return",
"self",
".",
"_services_items",
"=",
"[",
"]",
"def",
"_create_service_item",
"(",
"item",
")",
":",
"self",
".",
"_services_items",
".",
"append",
"(",
"{",
"\"title\"",
":",
"item",
".",
"get",
"(",
"\"@displayname\"",
",",
"\"\"",
")",
",",
"\"name\"",
":",
"item",
".",
"get",
"(",
"\"@name\"",
",",
"\"\"",
")",
",",
"\"type\"",
":",
"item",
".",
"get",
"(",
"\"@type\"",
",",
"\"\"",
")",
",",
"\"image\"",
":",
"item",
".",
"get",
"(",
"\"@icon\"",
",",
"\"\"",
")",
",",
"\"url\"",
":",
"item",
".",
"get",
"(",
"\"@name\"",
",",
"\"\"",
")",
",",
"}",
")",
"if",
"\"services\"",
"in",
"resp",
"and",
"\"service\"",
"in",
"resp",
"[",
"\"services\"",
"]",
":",
"if",
"isinstance",
"(",
"resp",
"[",
"\"services\"",
"]",
"[",
"\"service\"",
"]",
",",
"list",
")",
":",
"for",
"item",
"in",
"resp",
"[",
"\"services\"",
"]",
"[",
"\"service\"",
"]",
":",
"_create_service_item",
"(",
"item",
")",
"else",
":",
"_create_service_item",
"(",
"resp",
"[",
"\"services\"",
"]",
"[",
"\"service\"",
"]",
")",
"return",
"self",
".",
"_services_items"
] | [
517,
4
] | [
542,
35
] | python | en | ['en', 'en', 'en'] | False |
BluesoundPlayer.media_content_type | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_type(self):
"""Content type of current playing media."""
return MEDIA_TYPE_MUSIC | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"return",
"MEDIA_TYPE_MUSIC"
] | [
545,
4
] | [
547,
31
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
if self._status is None:
return STATE_OFF
if self.is_grouped and not self.is_master:
return STATE_GROUPED
status = self._status.get("state")
if status in ("pause", "stop"):
return STATE_PAUSED
if status in ("stream", "play"):
return STATE_PLAYING
return STATE_IDLE | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
":",
"return",
"STATE_OFF",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"STATE_GROUPED",
"status",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"state\"",
")",
"if",
"status",
"in",
"(",
"\"pause\"",
",",
"\"stop\"",
")",
":",
"return",
"STATE_PAUSED",
"if",
"status",
"in",
"(",
"\"stream\"",
",",
"\"play\"",
")",
":",
"return",
"STATE_PLAYING",
"return",
"STATE_IDLE"
] | [
550,
4
] | [
563,
25
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
return self._status.get("title1") | [
"def",
"media_title",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"return",
"self",
".",
"_status",
".",
"get",
"(",
"\"title1\"",
")"
] | [
566,
4
] | [
571,
41
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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)."""
if self._status is None:
return None
if self.is_grouped and not self.is_master:
return self._group_name
artist = self._status.get("artist")
if not artist:
artist = self._status.get("title2")
return artist | [
"def",
"media_artist",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
":",
"return",
"None",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"self",
".",
"_group_name",
"artist",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"artist\"",
")",
"if",
"not",
"artist",
":",
"artist",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"title2\"",
")",
"return",
"artist"
] | [
574,
4
] | [
585,
21
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.media_album_name | (self) | Artist of current playing media (Music track only). | Artist of current playing media (Music track only). | def media_album_name(self):
"""Artist of current playing media (Music track only)."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
album = self._status.get("album")
if not album:
album = self._status.get("title3")
return album | [
"def",
"media_album_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"album",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"album\"",
")",
"if",
"not",
"album",
":",
"album",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"title3\"",
")",
"return",
"album"
] | [
588,
4
] | [
596,
20
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
url = self._status.get("image")
if not url:
return
if url[0] == "/":
url = f"http://{self.host}:{self.port}{url}"
return url | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"url",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"image\"",
")",
"if",
"not",
"url",
":",
"return",
"if",
"url",
"[",
"0",
"]",
"==",
"\"/\"",
":",
"url",
"=",
"f\"http://{self.host}:{self.port}{url}\"",
"return",
"url"
] | [
599,
4
] | [
610,
18
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
mediastate = self.state
if self._last_status_update is None or mediastate == STATE_IDLE:
return None
position = self._status.get("secs")
if position is None:
return None
position = float(position)
if mediastate == STATE_PLAYING:
position += (dt_util.utcnow() - self._last_status_update).total_seconds()
return position | [
"def",
"media_position",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"mediastate",
"=",
"self",
".",
"state",
"if",
"self",
".",
"_last_status_update",
"is",
"None",
"or",
"mediastate",
"==",
"STATE_IDLE",
":",
"return",
"None",
"position",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"secs\"",
")",
"if",
"position",
"is",
"None",
":",
"return",
"None",
"position",
"=",
"float",
"(",
"position",
")",
"if",
"mediastate",
"==",
"STATE_PLAYING",
":",
"position",
"+=",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
"-",
"self",
".",
"_last_status_update",
")",
".",
"total_seconds",
"(",
")",
"return",
"position"
] | [
613,
4
] | [
630,
23
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
duration = self._status.get("totlen")
if duration is None:
return None
return float(duration) | [
"def",
"media_duration",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"duration",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"totlen\"",
")",
"if",
"duration",
"is",
"None",
":",
"return",
"None",
"return",
"float",
"(",
"duration",
")"
] | [
633,
4
] | [
641,
30
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.media_position_updated_at | (self) | Last time status was updated. | Last time status was updated. | def media_position_updated_at(self):
"""Last time status was updated."""
return self._last_status_update | [
"def",
"media_position_updated_at",
"(",
"self",
")",
":",
"return",
"self",
".",
"_last_status_update"
] | [
644,
4
] | [
646,
39
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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)."""
volume = self._status.get("volume")
if self.is_grouped:
volume = self._sync_status.get("@volume")
if volume is not None:
return int(volume) / 100
return None | [
"def",
"volume_level",
"(",
"self",
")",
":",
"volume",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"volume\"",
")",
"if",
"self",
".",
"is_grouped",
":",
"volume",
"=",
"self",
".",
"_sync_status",
".",
"get",
"(",
"\"@volume\"",
")",
"if",
"volume",
"is",
"not",
"None",
":",
"return",
"int",
"(",
"volume",
")",
"/",
"100",
"return",
"None"
] | [
649,
4
] | [
657,
19
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.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."""
mute = self._status.get("mute")
if self.is_grouped:
mute = self._sync_status.get("@mute")
if mute is not None:
mute = bool(int(mute))
return mute | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"mute",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"mute\"",
")",
"if",
"self",
".",
"is_grouped",
":",
"mute",
"=",
"self",
".",
"_sync_status",
".",
"get",
"(",
"\"@mute\"",
")",
"if",
"mute",
"is",
"not",
"None",
":",
"mute",
"=",
"bool",
"(",
"int",
"(",
"mute",
")",
")",
"return",
"mute"
] | [
660,
4
] | [
668,
19
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
671,
4
] | [
673,
25
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.bluesound_device_name | (self) | Return the device name as returned by the device. | Return the device name as returned by the device. | def bluesound_device_name(self):
"""Return the device name as returned by the device."""
return self._bluesound_device_name | [
"def",
"bluesound_device_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_bluesound_device_name"
] | [
676,
4
] | [
678,
42
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.icon | (self) | Return the icon of the device. | Return the icon of the device. | def icon(self):
"""Return the icon of the device."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
681,
4
] | [
683,
25
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.source_list | (self) | List of available input sources. | List of available input sources. | def source_list(self):
"""List of available input sources."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
sources = []
for source in self._preset_items:
sources.append(source["title"])
for source in [
x
for x in self._services_items
if x["type"] == "LocalMusic" or x["type"] == "RadioService"
]:
sources.append(source["title"])
for source in self._capture_items:
sources.append(source["title"])
return sources | [
"def",
"source_list",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"sources",
"=",
"[",
"]",
"for",
"source",
"in",
"self",
".",
"_preset_items",
":",
"sources",
".",
"append",
"(",
"source",
"[",
"\"title\"",
"]",
")",
"for",
"source",
"in",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_services_items",
"if",
"x",
"[",
"\"type\"",
"]",
"==",
"\"LocalMusic\"",
"or",
"x",
"[",
"\"type\"",
"]",
"==",
"\"RadioService\"",
"]",
":",
"sources",
".",
"append",
"(",
"source",
"[",
"\"title\"",
"]",
")",
"for",
"source",
"in",
"self",
".",
"_capture_items",
":",
"sources",
".",
"append",
"(",
"source",
"[",
"\"title\"",
"]",
")",
"return",
"sources"
] | [
686,
4
] | [
706,
22
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.source | (self) | Name of the current input source. | Name of the current input source. | def source(self):
"""Name of the current input source."""
if self._status is None or (self.is_grouped and not self.is_master):
return None
current_service = self._status.get("service", "")
if current_service == "":
return ""
stream_url = self._status.get("streamUrl", "")
if self._status.get("is_preset", "") == "1" and stream_url != "":
# This check doesn't work with all presets, for example playlists.
# But it works with radio service_items will catch playlists.
items = [
x
for x in self._preset_items
if "url2" in x and parse.unquote(x["url2"]) == stream_url
]
if items:
return items[0]["title"]
# This could be a bit difficult to detect. Bluetooth could be named
# different things and there is not any way to match chooses in
# capture list to current playing. It's a bit of guesswork.
# This method will be needing some tweaking over time.
title = self._status.get("title1", "").lower()
if title == "bluetooth" or stream_url == "Capture:hw:2,0/44100/16/2":
items = [
x
for x in self._capture_items
if x["url"] == "Capture%3Abluez%3Abluetooth"
]
if items:
return items[0]["title"]
items = [x for x in self._capture_items if x["url"] == stream_url]
if items:
return items[0]["title"]
if stream_url[:8] == "Capture:":
stream_url = stream_url[8:]
idx = BluesoundPlayer._try_get_index(stream_url, ":")
if idx > 0:
stream_url = stream_url[:idx]
for item in self._capture_items:
url = parse.unquote(item["url"])
if url[:8] == "Capture:":
url = url[8:]
idx = BluesoundPlayer._try_get_index(url, ":")
if idx > 0:
url = url[:idx]
if url.lower() == stream_url.lower():
return item["title"]
items = [x for x in self._capture_items if x["name"] == current_service]
if items:
return items[0]["title"]
items = [x for x in self._services_items if x["name"] == current_service]
if items:
return items[0]["title"]
if self._status.get("streamUrl", "") != "":
_LOGGER.debug(
"Couldn't find source of stream URL: %s",
self._status.get("streamUrl", ""),
)
return None | [
"def",
"source",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
"or",
"(",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
")",
":",
"return",
"None",
"current_service",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"service\"",
",",
"\"\"",
")",
"if",
"current_service",
"==",
"\"\"",
":",
"return",
"\"\"",
"stream_url",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"streamUrl\"",
",",
"\"\"",
")",
"if",
"self",
".",
"_status",
".",
"get",
"(",
"\"is_preset\"",
",",
"\"\"",
")",
"==",
"\"1\"",
"and",
"stream_url",
"!=",
"\"\"",
":",
"# This check doesn't work with all presets, for example playlists.",
"# But it works with radio service_items will catch playlists.",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_preset_items",
"if",
"\"url2\"",
"in",
"x",
"and",
"parse",
".",
"unquote",
"(",
"x",
"[",
"\"url2\"",
"]",
")",
"==",
"stream_url",
"]",
"if",
"items",
":",
"return",
"items",
"[",
"0",
"]",
"[",
"\"title\"",
"]",
"# This could be a bit difficult to detect. Bluetooth could be named",
"# different things and there is not any way to match chooses in",
"# capture list to current playing. It's a bit of guesswork.",
"# This method will be needing some tweaking over time.",
"title",
"=",
"self",
".",
"_status",
".",
"get",
"(",
"\"title1\"",
",",
"\"\"",
")",
".",
"lower",
"(",
")",
"if",
"title",
"==",
"\"bluetooth\"",
"or",
"stream_url",
"==",
"\"Capture:hw:2,0/44100/16/2\"",
":",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_capture_items",
"if",
"x",
"[",
"\"url\"",
"]",
"==",
"\"Capture%3Abluez%3Abluetooth\"",
"]",
"if",
"items",
":",
"return",
"items",
"[",
"0",
"]",
"[",
"\"title\"",
"]",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_capture_items",
"if",
"x",
"[",
"\"url\"",
"]",
"==",
"stream_url",
"]",
"if",
"items",
":",
"return",
"items",
"[",
"0",
"]",
"[",
"\"title\"",
"]",
"if",
"stream_url",
"[",
":",
"8",
"]",
"==",
"\"Capture:\"",
":",
"stream_url",
"=",
"stream_url",
"[",
"8",
":",
"]",
"idx",
"=",
"BluesoundPlayer",
".",
"_try_get_index",
"(",
"stream_url",
",",
"\":\"",
")",
"if",
"idx",
">",
"0",
":",
"stream_url",
"=",
"stream_url",
"[",
":",
"idx",
"]",
"for",
"item",
"in",
"self",
".",
"_capture_items",
":",
"url",
"=",
"parse",
".",
"unquote",
"(",
"item",
"[",
"\"url\"",
"]",
")",
"if",
"url",
"[",
":",
"8",
"]",
"==",
"\"Capture:\"",
":",
"url",
"=",
"url",
"[",
"8",
":",
"]",
"idx",
"=",
"BluesoundPlayer",
".",
"_try_get_index",
"(",
"url",
",",
"\":\"",
")",
"if",
"idx",
">",
"0",
":",
"url",
"=",
"url",
"[",
":",
"idx",
"]",
"if",
"url",
".",
"lower",
"(",
")",
"==",
"stream_url",
".",
"lower",
"(",
")",
":",
"return",
"item",
"[",
"\"title\"",
"]",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_capture_items",
"if",
"x",
"[",
"\"name\"",
"]",
"==",
"current_service",
"]",
"if",
"items",
":",
"return",
"items",
"[",
"0",
"]",
"[",
"\"title\"",
"]",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_services_items",
"if",
"x",
"[",
"\"name\"",
"]",
"==",
"current_service",
"]",
"if",
"items",
":",
"return",
"items",
"[",
"0",
"]",
"[",
"\"title\"",
"]",
"if",
"self",
".",
"_status",
".",
"get",
"(",
"\"streamUrl\"",
",",
"\"\"",
")",
"!=",
"\"\"",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Couldn't find source of stream URL: %s\"",
",",
"self",
".",
"_status",
".",
"get",
"(",
"\"streamUrl\"",
",",
"\"\"",
")",
",",
")",
"return",
"None"
] | [
709,
4
] | [
777,
19
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.supported_features | (self) | Flag of media commands that are supported. | Flag of media commands that are supported. | def supported_features(self):
"""Flag of media commands that are supported."""
if self._status is None:
return 0
if self.is_grouped and not self.is_master:
return SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE
supported = SUPPORT_CLEAR_PLAYLIST
if self._status.get("indexing", "0") == "0":
supported = (
supported
| SUPPORT_PAUSE
| SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_PLAY_MEDIA
| SUPPORT_STOP
| SUPPORT_PLAY
| SUPPORT_SELECT_SOURCE
| SUPPORT_SHUFFLE_SET
)
current_vol = self.volume_level
if current_vol is not None and current_vol >= 0:
supported = (
supported
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_SET
| SUPPORT_VOLUME_MUTE
)
if self._status.get("canSeek", "") == "1":
supported = supported | SUPPORT_SEEK
return supported | [
"def",
"supported_features",
"(",
"self",
")",
":",
"if",
"self",
".",
"_status",
"is",
"None",
":",
"return",
"0",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"SUPPORT_VOLUME_STEP",
"|",
"SUPPORT_VOLUME_SET",
"|",
"SUPPORT_VOLUME_MUTE",
"supported",
"=",
"SUPPORT_CLEAR_PLAYLIST",
"if",
"self",
".",
"_status",
".",
"get",
"(",
"\"indexing\"",
",",
"\"0\"",
")",
"==",
"\"0\"",
":",
"supported",
"=",
"(",
"supported",
"|",
"SUPPORT_PAUSE",
"|",
"SUPPORT_PREVIOUS_TRACK",
"|",
"SUPPORT_NEXT_TRACK",
"|",
"SUPPORT_PLAY_MEDIA",
"|",
"SUPPORT_STOP",
"|",
"SUPPORT_PLAY",
"|",
"SUPPORT_SELECT_SOURCE",
"|",
"SUPPORT_SHUFFLE_SET",
")",
"current_vol",
"=",
"self",
".",
"volume_level",
"if",
"current_vol",
"is",
"not",
"None",
"and",
"current_vol",
">=",
"0",
":",
"supported",
"=",
"(",
"supported",
"|",
"SUPPORT_VOLUME_STEP",
"|",
"SUPPORT_VOLUME_SET",
"|",
"SUPPORT_VOLUME_MUTE",
")",
"if",
"self",
".",
"_status",
".",
"get",
"(",
"\"canSeek\"",
",",
"\"\"",
")",
"==",
"\"1\"",
":",
"supported",
"=",
"supported",
"|",
"SUPPORT_SEEK",
"return",
"supported"
] | [
780,
4
] | [
815,
24
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.is_master | (self) | Return true if player is a coordinator. | Return true if player is a coordinator. | def is_master(self):
"""Return true if player is a coordinator."""
return self._is_master | [
"def",
"is_master",
"(",
"self",
")",
":",
"return",
"self",
".",
"_is_master"
] | [
818,
4
] | [
820,
30
] | python | en | ['en', 'lb', 'en'] | True |
BluesoundPlayer.is_grouped | (self) | Return true if player is a coordinator. | Return true if player is a coordinator. | def is_grouped(self):
"""Return true if player is a coordinator."""
return self._master is not None or self._is_master | [
"def",
"is_grouped",
"(",
"self",
")",
":",
"return",
"self",
".",
"_master",
"is",
"not",
"None",
"or",
"self",
".",
"_is_master"
] | [
823,
4
] | [
825,
58
] | python | en | ['en', 'lb', 'en'] | True |
BluesoundPlayer.shuffle | (self) | Return true if shuffle is active. | Return true if shuffle is active. | def shuffle(self):
"""Return true if shuffle is active."""
return self._status.get("shuffle", "0") == "1" | [
"def",
"shuffle",
"(",
"self",
")",
":",
"return",
"self",
".",
"_status",
".",
"get",
"(",
"\"shuffle\"",
",",
"\"0\"",
")",
"==",
"\"1\""
] | [
828,
4
] | [
830,
54
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_join | (self, master) | Join the player to a group. | Join the player to a group. | async def async_join(self, master):
"""Join the player to a group."""
master_device = [
device
for device in self.hass.data[DATA_BLUESOUND]
if device.entity_id == master
]
if master_device:
_LOGGER.debug(
"Trying to join player: %s to master: %s",
self.host,
master_device[0].host,
)
await master_device[0].async_add_slave(self)
else:
_LOGGER.error("Master not found %s", master_device) | [
"async",
"def",
"async_join",
"(",
"self",
",",
"master",
")",
":",
"master_device",
"=",
"[",
"device",
"for",
"device",
"in",
"self",
".",
"hass",
".",
"data",
"[",
"DATA_BLUESOUND",
"]",
"if",
"device",
".",
"entity_id",
"==",
"master",
"]",
"if",
"master_device",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Trying to join player: %s to master: %s\"",
",",
"self",
".",
"host",
",",
"master_device",
"[",
"0",
"]",
".",
"host",
",",
")",
"await",
"master_device",
"[",
"0",
"]",
".",
"async_add_slave",
"(",
"self",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Master not found %s\"",
",",
"master_device",
")"
] | [
832,
4
] | [
849,
63
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.device_state_attributes | (self) | List members in group. | List members in group. | def device_state_attributes(self):
"""List members in group."""
attributes = {}
if self._group_list:
attributes = {ATTR_BLUESOUND_GROUP: self._group_list}
attributes[ATTR_MASTER] = self._is_master
return attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attributes",
"=",
"{",
"}",
"if",
"self",
".",
"_group_list",
":",
"attributes",
"=",
"{",
"ATTR_BLUESOUND_GROUP",
":",
"self",
".",
"_group_list",
"}",
"attributes",
"[",
"ATTR_MASTER",
"]",
"=",
"self",
".",
"_is_master",
"return",
"attributes"
] | [
852,
4
] | [
860,
25
] | python | en | ['en', 'af', 'en'] | True |
BluesoundPlayer.rebuild_bluesound_group | (self) | Rebuild the list of entities in speaker group. | Rebuild the list of entities in speaker group. | def rebuild_bluesound_group(self):
"""Rebuild the list of entities in speaker group."""
if self._group_name is None:
return None
bluesound_group = []
device_group = self._group_name.split("+")
sorted_entities = sorted(
self._hass.data[DATA_BLUESOUND],
key=lambda entity: entity.is_master,
reverse=True,
)
bluesound_group = [
entity.name
for entity in sorted_entities
if entity.bluesound_device_name in device_group
]
return bluesound_group | [
"def",
"rebuild_bluesound_group",
"(",
"self",
")",
":",
"if",
"self",
".",
"_group_name",
"is",
"None",
":",
"return",
"None",
"bluesound_group",
"=",
"[",
"]",
"device_group",
"=",
"self",
".",
"_group_name",
".",
"split",
"(",
"\"+\"",
")",
"sorted_entities",
"=",
"sorted",
"(",
"self",
".",
"_hass",
".",
"data",
"[",
"DATA_BLUESOUND",
"]",
",",
"key",
"=",
"lambda",
"entity",
":",
"entity",
".",
"is_master",
",",
"reverse",
"=",
"True",
",",
")",
"bluesound_group",
"=",
"[",
"entity",
".",
"name",
"for",
"entity",
"in",
"sorted_entities",
"if",
"entity",
".",
"bluesound_device_name",
"in",
"device_group",
"]",
"return",
"bluesound_group"
] | [
862,
4
] | [
882,
30
] | python | en | ['en', 'af', 'en'] | True |
BluesoundPlayer.async_unjoin | (self) | Unjoin the player from a group. | Unjoin the player from a group. | async def async_unjoin(self):
"""Unjoin the player from a group."""
if self._master is None:
return
_LOGGER.debug("Trying to unjoin player: %s", self.host)
await self._master.async_remove_slave(self) | [
"async",
"def",
"async_unjoin",
"(",
"self",
")",
":",
"if",
"self",
".",
"_master",
"is",
"None",
":",
"return",
"_LOGGER",
".",
"debug",
"(",
"\"Trying to unjoin player: %s\"",
",",
"self",
".",
"host",
")",
"await",
"self",
".",
"_master",
".",
"async_remove_slave",
"(",
"self",
")"
] | [
884,
4
] | [
890,
51
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_add_slave | (self, slave_device) | Add slave to master. | Add slave to master. | async def async_add_slave(self, slave_device):
"""Add slave to master."""
return await self.send_bluesound_command(
f"/AddSlave?slave={slave_device.host}&port={slave_device.port}"
) | [
"async",
"def",
"async_add_slave",
"(",
"self",
",",
"slave_device",
")",
":",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"f\"/AddSlave?slave={slave_device.host}&port={slave_device.port}\"",
")"
] | [
892,
4
] | [
896,
9
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_remove_slave | (self, slave_device) | Remove slave to master. | Remove slave to master. | async def async_remove_slave(self, slave_device):
"""Remove slave to master."""
return await self.send_bluesound_command(
f"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}"
) | [
"async",
"def",
"async_remove_slave",
"(",
"self",
",",
"slave_device",
")",
":",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"f\"/RemoveSlave?slave={slave_device.host}&port={slave_device.port}\"",
")"
] | [
898,
4
] | [
902,
9
] | python | en | ['en', 'it', 'en'] | True |
BluesoundPlayer.async_increase_timer | (self) | Increase sleep time on player. | Increase sleep time on player. | async def async_increase_timer(self):
"""Increase sleep time on player."""
sleep_time = await self.send_bluesound_command("/Sleep")
if sleep_time is None:
_LOGGER.error("Error while increasing sleep time on player: %s", self.host)
return 0
return int(sleep_time.get("sleep", "0")) | [
"async",
"def",
"async_increase_timer",
"(",
"self",
")",
":",
"sleep_time",
"=",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"/Sleep\"",
")",
"if",
"sleep_time",
"is",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error while increasing sleep time on player: %s\"",
",",
"self",
".",
"host",
")",
"return",
"0",
"return",
"int",
"(",
"sleep_time",
".",
"get",
"(",
"\"sleep\"",
",",
"\"0\"",
")",
")"
] | [
904,
4
] | [
911,
48
] | python | en | ['en', 'ceb', 'en'] | True |
BluesoundPlayer.async_clear_timer | (self) | Clear sleep timer on player. | Clear sleep timer on player. | async def async_clear_timer(self):
"""Clear sleep timer on player."""
sleep = 1
while sleep > 0:
sleep = await self.async_increase_timer() | [
"async",
"def",
"async_clear_timer",
"(",
"self",
")",
":",
"sleep",
"=",
"1",
"while",
"sleep",
">",
"0",
":",
"sleep",
"=",
"await",
"self",
".",
"async_increase_timer",
"(",
")"
] | [
913,
4
] | [
917,
53
] | python | en | ['en', 'ga', 'en'] | True |
BluesoundPlayer.async_set_shuffle | (self, shuffle) | Enable or disable shuffle mode. | Enable or disable shuffle mode. | async def async_set_shuffle(self, shuffle):
"""Enable or disable shuffle mode."""
value = "1" if shuffle else "0"
return await self.send_bluesound_command(f"/Shuffle?state={value}") | [
"async",
"def",
"async_set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"value",
"=",
"\"1\"",
"if",
"shuffle",
"else",
"\"0\"",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"f\"/Shuffle?state={value}\"",
")"
] | [
919,
4
] | [
922,
75
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_select_source | (self, source) | Select input source. | Select input source. | async def async_select_source(self, source):
"""Select input source."""
if self.is_grouped and not self.is_master:
return
items = [x for x in self._preset_items if x["title"] == source]
if not items:
items = [x for x in self._services_items if x["title"] == source]
if not items:
items = [x for x in self._capture_items if x["title"] == source]
if not items:
return
selected_source = items[0]
url = f"Play?url={selected_source['url']}&preset_id&image={selected_source['image']}"
if "is_raw_url" in selected_source and selected_source["is_raw_url"]:
url = selected_source["url"]
return await self.send_bluesound_command(url) | [
"async",
"def",
"async_select_source",
"(",
"self",
",",
"source",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_preset_items",
"if",
"x",
"[",
"\"title\"",
"]",
"==",
"source",
"]",
"if",
"not",
"items",
":",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_services_items",
"if",
"x",
"[",
"\"title\"",
"]",
"==",
"source",
"]",
"if",
"not",
"items",
":",
"items",
"=",
"[",
"x",
"for",
"x",
"in",
"self",
".",
"_capture_items",
"if",
"x",
"[",
"\"title\"",
"]",
"==",
"source",
"]",
"if",
"not",
"items",
":",
"return",
"selected_source",
"=",
"items",
"[",
"0",
"]",
"url",
"=",
"f\"Play?url={selected_source['url']}&preset_id&image={selected_source['image']}\"",
"if",
"\"is_raw_url\"",
"in",
"selected_source",
"and",
"selected_source",
"[",
"\"is_raw_url\"",
"]",
":",
"url",
"=",
"selected_source",
"[",
"\"url\"",
"]",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"url",
")"
] | [
924,
4
] | [
945,
53
] | python | en | ['fr', 'su', 'en'] | False |
BluesoundPlayer.async_clear_playlist | (self) | Clear players playlist. | Clear players playlist. | async def async_clear_playlist(self):
"""Clear players playlist."""
if self.is_grouped and not self.is_master:
return
return await self.send_bluesound_command("Clear") | [
"async",
"def",
"async_clear_playlist",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Clear\"",
")"
] | [
947,
4
] | [
952,
57
] | python | en | ['fr', 'en', 'en'] | True |
BluesoundPlayer.async_media_next_track | (self) | Send media_next command to media player. | Send media_next command to media player. | async def async_media_next_track(self):
"""Send media_next command to media player."""
if self.is_grouped and not self.is_master:
return
cmd = "Skip"
if self._status and "actions" in self._status:
for action in self._status["actions"]["action"]:
if "@name" in action and "@url" in action and action["@name"] == "skip":
cmd = action["@url"]
return await self.send_bluesound_command(cmd) | [
"async",
"def",
"async_media_next_track",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"cmd",
"=",
"\"Skip\"",
"if",
"self",
".",
"_status",
"and",
"\"actions\"",
"in",
"self",
".",
"_status",
":",
"for",
"action",
"in",
"self",
".",
"_status",
"[",
"\"actions\"",
"]",
"[",
"\"action\"",
"]",
":",
"if",
"\"@name\"",
"in",
"action",
"and",
"\"@url\"",
"in",
"action",
"and",
"action",
"[",
"\"@name\"",
"]",
"==",
"\"skip\"",
":",
"cmd",
"=",
"action",
"[",
"\"@url\"",
"]",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"cmd",
")"
] | [
954,
4
] | [
965,
53
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_media_previous_track | (self) | Send media_previous command to media player. | Send media_previous command to media player. | async def async_media_previous_track(self):
"""Send media_previous command to media player."""
if self.is_grouped and not self.is_master:
return
cmd = "Back"
if self._status and "actions" in self._status:
for action in self._status["actions"]["action"]:
if "@name" in action and "@url" in action and action["@name"] == "back":
cmd = action["@url"]
return await self.send_bluesound_command(cmd) | [
"async",
"def",
"async_media_previous_track",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"cmd",
"=",
"\"Back\"",
"if",
"self",
".",
"_status",
"and",
"\"actions\"",
"in",
"self",
".",
"_status",
":",
"for",
"action",
"in",
"self",
".",
"_status",
"[",
"\"actions\"",
"]",
"[",
"\"action\"",
"]",
":",
"if",
"\"@name\"",
"in",
"action",
"and",
"\"@url\"",
"in",
"action",
"and",
"action",
"[",
"\"@name\"",
"]",
"==",
"\"back\"",
":",
"cmd",
"=",
"action",
"[",
"\"@url\"",
"]",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"cmd",
")"
] | [
967,
4
] | [
978,
53
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_media_play | (self) | Send media_play command to media player. | Send media_play command to media player. | async def async_media_play(self):
"""Send media_play command to media player."""
if self.is_grouped and not self.is_master:
return
return await self.send_bluesound_command("Play") | [
"async",
"def",
"async_media_play",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Play\"",
")"
] | [
980,
4
] | [
985,
56
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_media_pause | (self) | Send media_pause command to media player. | Send media_pause command to media player. | async def async_media_pause(self):
"""Send media_pause command to media player."""
if self.is_grouped and not self.is_master:
return
return await self.send_bluesound_command("Pause") | [
"async",
"def",
"async_media_pause",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Pause\"",
")"
] | [
987,
4
] | [
992,
57
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_media_stop | (self) | Send stop command. | Send stop command. | async def async_media_stop(self):
"""Send stop command."""
if self.is_grouped and not self.is_master:
return
return await self.send_bluesound_command("Pause") | [
"async",
"def",
"async_media_stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Pause\"",
")"
] | [
994,
4
] | [
999,
57
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_media_seek | (self, position) | Send media_seek command to media player. | Send media_seek command to media player. | async def async_media_seek(self, position):
"""Send media_seek command to media player."""
if self.is_grouped and not self.is_master:
return
return await self.send_bluesound_command(f"Play?seek={float(position)}") | [
"async",
"def",
"async_media_seek",
"(",
"self",
",",
"position",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"f\"Play?seek={float(position)}\"",
")"
] | [
1001,
4
] | [
1006,
80
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_play_media | (self, media_type, media_id, **kwargs) |
Send the play_media command to the media player.
If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the queue.
|
Send the play_media command to the media player. | async def async_play_media(self, media_type, media_id, **kwargs):
"""
Send the play_media command to the media player.
If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the queue.
"""
if self.is_grouped and not self.is_master:
return
url = f"Play?url={media_id}"
if kwargs.get(ATTR_MEDIA_ENQUEUE):
return await self.send_bluesound_command(url)
return await self.send_bluesound_command(url) | [
"async",
"def",
"async_play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"is_grouped",
"and",
"not",
"self",
".",
"is_master",
":",
"return",
"url",
"=",
"f\"Play?url={media_id}\"",
"if",
"kwargs",
".",
"get",
"(",
"ATTR_MEDIA_ENQUEUE",
")",
":",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"url",
")",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"url",
")"
] | [
1008,
4
] | [
1022,
53
] | python | en | ['en', 'error', 'th'] | False |
BluesoundPlayer.async_volume_up | (self) | Volume up the media player. | Volume up the media player. | async def async_volume_up(self):
"""Volume up the media player."""
current_vol = self.volume_level
if not current_vol or current_vol >= 1:
return
return await self.async_set_volume_level(current_vol + 0.01) | [
"async",
"def",
"async_volume_up",
"(",
"self",
")",
":",
"current_vol",
"=",
"self",
".",
"volume_level",
"if",
"not",
"current_vol",
"or",
"current_vol",
">=",
"1",
":",
"return",
"return",
"await",
"self",
".",
"async_set_volume_level",
"(",
"current_vol",
"+",
"0.01",
")"
] | [
1024,
4
] | [
1029,
68
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_volume_down | (self) | Volume down the media player. | Volume down the media player. | async def async_volume_down(self):
"""Volume down the media player."""
current_vol = self.volume_level
if not current_vol or current_vol <= 0:
return
return await self.async_set_volume_level(current_vol - 0.01) | [
"async",
"def",
"async_volume_down",
"(",
"self",
")",
":",
"current_vol",
"=",
"self",
".",
"volume_level",
"if",
"not",
"current_vol",
"or",
"current_vol",
"<=",
"0",
":",
"return",
"return",
"await",
"self",
".",
"async_set_volume_level",
"(",
"current_vol",
"-",
"0.01",
")"
] | [
1031,
4
] | [
1036,
68
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_set_volume_level | (self, volume) | Send volume_up command to media player. | Send volume_up command to media player. | async def async_set_volume_level(self, volume):
"""Send volume_up command to media player."""
if volume < 0:
volume = 0
elif volume > 1:
volume = 1
return await self.send_bluesound_command(f"Volume?level={float(volume) * 100}") | [
"async",
"def",
"async_set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"if",
"volume",
"<",
"0",
":",
"volume",
"=",
"0",
"elif",
"volume",
">",
"1",
":",
"volume",
"=",
"1",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"f\"Volume?level={float(volume) * 100}\"",
")"
] | [
1038,
4
] | [
1044,
87
] | python | en | ['en', 'en', 'en'] | True |
BluesoundPlayer.async_mute_volume | (self, mute) | Send mute command to media player. | Send mute command to media player. | async def async_mute_volume(self, mute):
"""Send mute command to media player."""
if mute:
return await self.send_bluesound_command("Volume?mute=1")
return await self.send_bluesound_command("Volume?mute=0") | [
"async",
"def",
"async_mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"if",
"mute",
":",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Volume?mute=1\"",
")",
"return",
"await",
"self",
".",
"send_bluesound_command",
"(",
"\"Volume?mute=0\"",
")"
] | [
1046,
4
] | [
1050,
65
] | python | en | ['en', 'en', 'en'] | True |
ChromeCastZeroconf.set_zeroconf | (cls, zconf) | Set zeroconf. | Set zeroconf. | def set_zeroconf(cls, zconf):
"""Set zeroconf."""
cls.__zconf = zconf | [
"def",
"set_zeroconf",
"(",
"cls",
",",
"zconf",
")",
":",
"cls",
".",
"__zconf",
"=",
"zconf"
] | [
49,
4
] | [
51,
27
] | python | en | ['eu', 'sr', 'en'] | False |
ChromeCastZeroconf.get_zeroconf | (cls) | Get zeroconf. | Get zeroconf. | def get_zeroconf(cls):
"""Get zeroconf."""
return cls.__zconf | [
"def",
"get_zeroconf",
"(",
"cls",
")",
":",
"return",
"cls",
".",
"__zconf"
] | [
54,
4
] | [
56,
26
] | python | en | ['eu', 'nl', 'en'] | False |
CastStatusListener.__init__ | (self, cast_device, chromecast, mz_mgr) | Initialize the status listener. | Initialize the status listener. | def __init__(self, cast_device, chromecast, mz_mgr):
"""Initialize the status listener."""
self._cast_device = cast_device
self._uuid = chromecast.uuid
self._valid = True
self._mz_mgr = mz_mgr
chromecast.register_status_listener(self)
chromecast.socket_client.media_controller.register_status_listener(self)
chromecast.register_connection_listener(self)
if cast_device._cast_info.is_audio_group:
self._mz_mgr.add_multizone(chromecast)
else:
self._mz_mgr.register_listener(chromecast.uuid, self) | [
"def",
"__init__",
"(",
"self",
",",
"cast_device",
",",
"chromecast",
",",
"mz_mgr",
")",
":",
"self",
".",
"_cast_device",
"=",
"cast_device",
"self",
".",
"_uuid",
"=",
"chromecast",
".",
"uuid",
"self",
".",
"_valid",
"=",
"True",
"self",
".",
"_mz_mgr",
"=",
"mz_mgr",
"chromecast",
".",
"register_status_listener",
"(",
"self",
")",
"chromecast",
".",
"socket_client",
".",
"media_controller",
".",
"register_status_listener",
"(",
"self",
")",
"chromecast",
".",
"register_connection_listener",
"(",
"self",
")",
"if",
"cast_device",
".",
"_cast_info",
".",
"is_audio_group",
":",
"self",
".",
"_mz_mgr",
".",
"add_multizone",
"(",
"chromecast",
")",
"else",
":",
"self",
".",
"_mz_mgr",
".",
"register_listener",
"(",
"chromecast",
".",
"uuid",
",",
"self",
")"
] | [
67,
4
] | [
80,
65
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.new_cast_status | (self, cast_status) | Handle reception of a new CastStatus. | Handle reception of a new CastStatus. | def new_cast_status(self, cast_status):
"""Handle reception of a new CastStatus."""
if self._valid:
self._cast_device.new_cast_status(cast_status) | [
"def",
"new_cast_status",
"(",
"self",
",",
"cast_status",
")",
":",
"if",
"self",
".",
"_valid",
":",
"self",
".",
"_cast_device",
".",
"new_cast_status",
"(",
"cast_status",
")"
] | [
82,
4
] | [
85,
58
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.new_media_status | (self, media_status) | Handle reception of a new MediaStatus. | Handle reception of a new MediaStatus. | def new_media_status(self, media_status):
"""Handle reception of a new MediaStatus."""
if self._valid:
self._cast_device.new_media_status(media_status) | [
"def",
"new_media_status",
"(",
"self",
",",
"media_status",
")",
":",
"if",
"self",
".",
"_valid",
":",
"self",
".",
"_cast_device",
".",
"new_media_status",
"(",
"media_status",
")"
] | [
87,
4
] | [
90,
60
] | python | en | ['en', 'es', 'en'] | True |
CastStatusListener.new_connection_status | (self, connection_status) | Handle reception of a new ConnectionStatus. | Handle reception of a new ConnectionStatus. | def new_connection_status(self, connection_status):
"""Handle reception of a new ConnectionStatus."""
if self._valid:
self._cast_device.new_connection_status(connection_status) | [
"def",
"new_connection_status",
"(",
"self",
",",
"connection_status",
")",
":",
"if",
"self",
".",
"_valid",
":",
"self",
".",
"_cast_device",
".",
"new_connection_status",
"(",
"connection_status",
")"
] | [
92,
4
] | [
95,
70
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.added_to_multizone | (group_uuid) | Handle the cast added to a group. | Handle the cast added to a group. | def added_to_multizone(group_uuid):
"""Handle the cast added to a group.""" | [
"def",
"added_to_multizone",
"(",
"group_uuid",
")",
":"
] | [
98,
4
] | [
99,
47
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.removed_from_multizone | (self, group_uuid) | Handle the cast removed from a group. | Handle the cast removed from a group. | def removed_from_multizone(self, group_uuid):
"""Handle the cast removed from a group."""
if self._valid:
self._cast_device.multizone_new_media_status(group_uuid, None) | [
"def",
"removed_from_multizone",
"(",
"self",
",",
"group_uuid",
")",
":",
"if",
"self",
".",
"_valid",
":",
"self",
".",
"_cast_device",
".",
"multizone_new_media_status",
"(",
"group_uuid",
",",
"None",
")"
] | [
101,
4
] | [
104,
74
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.multizone_new_cast_status | (self, group_uuid, cast_status) | Handle reception of a new CastStatus for a group. | Handle reception of a new CastStatus for a group. | def multizone_new_cast_status(self, group_uuid, cast_status):
"""Handle reception of a new CastStatus for a group.""" | [
"def",
"multizone_new_cast_status",
"(",
"self",
",",
"group_uuid",
",",
"cast_status",
")",
":"
] | [
106,
4
] | [
107,
63
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.multizone_new_media_status | (self, group_uuid, media_status) | Handle reception of a new MediaStatus for a group. | Handle reception of a new MediaStatus for a group. | def multizone_new_media_status(self, group_uuid, media_status):
"""Handle reception of a new MediaStatus for a group."""
if self._valid:
self._cast_device.multizone_new_media_status(group_uuid, media_status) | [
"def",
"multizone_new_media_status",
"(",
"self",
",",
"group_uuid",
",",
"media_status",
")",
":",
"if",
"self",
".",
"_valid",
":",
"self",
".",
"_cast_device",
".",
"multizone_new_media_status",
"(",
"group_uuid",
",",
"media_status",
")"
] | [
109,
4
] | [
112,
82
] | python | en | ['en', 'en', 'en'] | True |
CastStatusListener.invalidate | (self) | Invalidate this status listener.
All following callbacks won't be forwarded.
| Invalidate this status listener. | def invalidate(self):
"""Invalidate this status listener.
All following callbacks won't be forwarded.
"""
# pylint: disable=protected-access
if self._cast_device._cast_info.is_audio_group:
self._mz_mgr.remove_multizone(self._uuid)
else:
self._mz_mgr.deregister_listener(self._uuid, self)
self._valid = False | [
"def",
"invalidate",
"(",
"self",
")",
":",
"# pylint: disable=protected-access",
"if",
"self",
".",
"_cast_device",
".",
"_cast_info",
".",
"is_audio_group",
":",
"self",
".",
"_mz_mgr",
".",
"remove_multizone",
"(",
"self",
".",
"_uuid",
")",
"else",
":",
"self",
".",
"_mz_mgr",
".",
"deregister_listener",
"(",
"self",
".",
"_uuid",
",",
"self",
")",
"self",
".",
"_valid",
"=",
"False"
] | [
114,
4
] | [
124,
27
] | python | en | ['en', 'la', 'en'] | True |
setup_platform | (
hass, config: ConfigType, add_entities: Callable[[list], None], discovery_info=None
) | Set up the Sesame platform. | Set up the Sesame platform. | def setup_platform(
hass, config: ConfigType, add_entities: Callable[[list], None], discovery_info=None
):
"""Set up the Sesame platform."""
api_key = config.get(CONF_API_KEY)
add_entities(
[SesameDevice(sesame) for sesame in pysesame2.get_sesames(api_key)],
update_before_add=True,
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
":",
"ConfigType",
",",
"add_entities",
":",
"Callable",
"[",
"[",
"list",
"]",
",",
"None",
"]",
",",
"discovery_info",
"=",
"None",
")",
":",
"api_key",
"=",
"config",
".",
"get",
"(",
"CONF_API_KEY",
")",
"add_entities",
"(",
"[",
"SesameDevice",
"(",
"sesame",
")",
"for",
"sesame",
"in",
"pysesame2",
".",
"get_sesames",
"(",
"api_key",
")",
"]",
",",
"update_before_add",
"=",
"True",
",",
")"
] | [
22,
0
] | [
31,
5
] | python | en | ['en', 'da', 'en'] | True |
SesameDevice.__init__ | (self, sesame: object) | Initialize the Sesame device. | Initialize the Sesame device. | def __init__(self, sesame: object) -> None:
"""Initialize the Sesame device."""
self._sesame = sesame
# Cached properties from pysesame object.
self._device_id = None
self._serial = None
self._nickname = None
self._is_locked = False
self._responsive = False
self._battery = -1 | [
"def",
"__init__",
"(",
"self",
",",
"sesame",
":",
"object",
")",
"->",
"None",
":",
"self",
".",
"_sesame",
"=",
"sesame",
"# Cached properties from pysesame object.",
"self",
".",
"_device_id",
"=",
"None",
"self",
".",
"_serial",
"=",
"None",
"self",
".",
"_nickname",
"=",
"None",
"self",
".",
"_is_locked",
"=",
"False",
"self",
".",
"_responsive",
"=",
"False",
"self",
".",
"_battery",
"=",
"-",
"1"
] | [
37,
4
] | [
47,
26
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self) -> str:
"""Return the name of the device."""
return self._nickname | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_nickname"
] | [
50,
4
] | [
52,
29
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
return self._responsive | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_responsive"
] | [
55,
4
] | [
57,
31
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.is_locked | (self) | Return True if the device is currently locked, else False. | Return True if the device is currently locked, else False. | def is_locked(self) -> bool:
"""Return True if the device is currently locked, else False."""
return self._is_locked | [
"def",
"is_locked",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_is_locked"
] | [
60,
4
] | [
62,
30
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.state | (self) | Get the state of the device. | Get the state of the device. | def state(self) -> str:
"""Get the state of the device."""
return STATE_LOCKED if self._is_locked else STATE_UNLOCKED | [
"def",
"state",
"(",
"self",
")",
"->",
"str",
":",
"return",
"STATE_LOCKED",
"if",
"self",
".",
"_is_locked",
"else",
"STATE_UNLOCKED"
] | [
65,
4
] | [
67,
66
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.lock | (self, **kwargs) | Lock the device. | Lock the device. | def lock(self, **kwargs) -> None:
"""Lock the device."""
self._sesame.lock() | [
"def",
"lock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"self",
".",
"_sesame",
".",
"lock",
"(",
")"
] | [
69,
4
] | [
71,
27
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.unlock | (self, **kwargs) | Unlock the device. | Unlock the device. | def unlock(self, **kwargs) -> None:
"""Unlock the device."""
self._sesame.unlock() | [
"def",
"unlock",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"self",
".",
"_sesame",
".",
"unlock",
"(",
")"
] | [
73,
4
] | [
75,
29
] | python | en | ['en', 'zh', 'en'] | True |
SesameDevice.update | (self) | Update the internal state of the device. | Update the internal state of the device. | def update(self) -> None:
"""Update the internal state of the device."""
status = self._sesame.get_status()
self._nickname = self._sesame.nickname
self._device_id = str(self._sesame.id)
self._serial = self._sesame.serial
self._battery = status["battery"]
self._is_locked = status["locked"]
self._responsive = status["responsive"] | [
"def",
"update",
"(",
"self",
")",
"->",
"None",
":",
"status",
"=",
"self",
".",
"_sesame",
".",
"get_status",
"(",
")",
"self",
".",
"_nickname",
"=",
"self",
".",
"_sesame",
".",
"nickname",
"self",
".",
"_device_id",
"=",
"str",
"(",
"self",
".",
"_sesame",
".",
"id",
")",
"self",
".",
"_serial",
"=",
"self",
".",
"_sesame",
".",
"serial",
"self",
".",
"_battery",
"=",
"status",
"[",
"\"battery\"",
"]",
"self",
".",
"_is_locked",
"=",
"status",
"[",
"\"locked\"",
"]",
"self",
".",
"_responsive",
"=",
"status",
"[",
"\"responsive\"",
"]"
] | [
77,
4
] | [
85,
47
] | python | en | ['en', 'en', 'en'] | True |
SesameDevice.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self) -> dict:
"""Return the state attributes."""
return {
ATTR_DEVICE_ID: self._device_id,
ATTR_SERIAL_NO: self._serial,
ATTR_BATTERY_LEVEL: self._battery,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"{",
"ATTR_DEVICE_ID",
":",
"self",
".",
"_device_id",
",",
"ATTR_SERIAL_NO",
":",
"self",
".",
"_serial",
",",
"ATTR_BATTERY_LEVEL",
":",
"self",
".",
"_battery",
",",
"}"
] | [
88,
4
] | [
94,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Home Connect sensor. | Set up the Home Connect sensor. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Home Connect sensor."""
def get_entities():
"""Get a list of entities."""
entities = []
hc_api = hass.data[DOMAIN][config_entry.entry_id]
for device_dict in hc_api.devices:
entity_dicts = device_dict.get("entities", {}).get("sensor", [])
entities += [HomeConnectSensor(**d) for d in entity_dicts]
return entities
async_add_entities(await hass.async_add_executor_job(get_entities), True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"def",
"get_entities",
"(",
")",
":",
"\"\"\"Get a list of entities.\"\"\"",
"entities",
"=",
"[",
"]",
"hc_api",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"for",
"device_dict",
"in",
"hc_api",
".",
"devices",
":",
"entity_dicts",
"=",
"device_dict",
".",
"get",
"(",
"\"entities\"",
",",
"{",
"}",
")",
".",
"get",
"(",
"\"sensor\"",
",",
"[",
"]",
")",
"entities",
"+=",
"[",
"HomeConnectSensor",
"(",
"*",
"*",
"d",
")",
"for",
"d",
"in",
"entity_dicts",
"]",
"return",
"entities",
"async_add_entities",
"(",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"get_entities",
")",
",",
"True",
")"
] | [
14,
0
] | [
26,
77
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectSensor.__init__ | (self, device, desc, key, unit, icon, device_class, sign=1) | Initialize the entity. | Initialize the entity. | def __init__(self, device, desc, key, unit, icon, device_class, sign=1):
"""Initialize the entity."""
super().__init__(device, desc)
self._state = None
self._key = key
self._unit = unit
self._icon = icon
self._device_class = device_class
self._sign = sign | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"desc",
",",
"key",
",",
"unit",
",",
"icon",
",",
"device_class",
",",
"sign",
"=",
"1",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"device",
",",
"desc",
")",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_key",
"=",
"key",
"self",
".",
"_unit",
"=",
"unit",
"self",
".",
"_icon",
"=",
"icon",
"self",
".",
"_device_class",
"=",
"device_class",
"self",
".",
"_sign",
"=",
"sign"
] | [
32,
4
] | [
40,
25
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectSensor.state | (self) | Return true if the binary sensor is on. | Return true if the binary sensor is on. | def state(self):
"""Return true if the binary sensor is on."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
43,
4
] | [
45,
26
] | python | en | ['en', 'fy', 'en'] | True |
HomeConnectSensor.available | (self) | Return true if the sensor is available. | Return true if the sensor is available. | def available(self):
"""Return true if the sensor is available."""
return self._state is not None | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state",
"is",
"not",
"None"
] | [
48,
4
] | [
50,
38
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectSensor.async_update | (self) | Update the sensos status. | Update the sensos status. | async def async_update(self):
"""Update the sensos status."""
status = self.device.appliance.status
if self._key not in status:
self._state = None
else:
if self.device_class == DEVICE_CLASS_TIMESTAMP:
if "value" not in status[self._key]:
self._state = None
elif (
self._state is not None
and self._sign == 1
and dt_util.parse_datetime(self._state) < dt_util.utcnow()
):
# if the date is supposed to be in the future but we're
# already past it, set state to None.
self._state = None
else:
seconds = self._sign * float(status[self._key]["value"])
self._state = (
dt_util.utcnow() + timedelta(seconds=seconds)
).isoformat()
else:
self._state = status[self._key].get("value")
_LOGGER.debug("Updated, new state: %s", self._state) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"status",
"=",
"self",
".",
"device",
".",
"appliance",
".",
"status",
"if",
"self",
".",
"_key",
"not",
"in",
"status",
":",
"self",
".",
"_state",
"=",
"None",
"else",
":",
"if",
"self",
".",
"device_class",
"==",
"DEVICE_CLASS_TIMESTAMP",
":",
"if",
"\"value\"",
"not",
"in",
"status",
"[",
"self",
".",
"_key",
"]",
":",
"self",
".",
"_state",
"=",
"None",
"elif",
"(",
"self",
".",
"_state",
"is",
"not",
"None",
"and",
"self",
".",
"_sign",
"==",
"1",
"and",
"dt_util",
".",
"parse_datetime",
"(",
"self",
".",
"_state",
")",
"<",
"dt_util",
".",
"utcnow",
"(",
")",
")",
":",
"# if the date is supposed to be in the future but we're",
"# already past it, set state to None.",
"self",
".",
"_state",
"=",
"None",
"else",
":",
"seconds",
"=",
"self",
".",
"_sign",
"*",
"float",
"(",
"status",
"[",
"self",
".",
"_key",
"]",
"[",
"\"value\"",
"]",
")",
"self",
".",
"_state",
"=",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"seconds",
")",
")",
".",
"isoformat",
"(",
")",
"else",
":",
"self",
".",
"_state",
"=",
"status",
"[",
"self",
".",
"_key",
"]",
".",
"get",
"(",
"\"value\"",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Updated, new state: %s\"",
",",
"self",
".",
"_state",
")"
] | [
52,
4
] | [
76,
60
] | python | en | ['en', 'la', 'en'] | True |
HomeConnectSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit"
] | [
79,
4
] | [
81,
25
] | python | en | ['en', 'la', 'en'] | True |
HomeConnectSensor.icon | (self) | Return the icon. | Return the icon. | def icon(self):
"""Return the icon."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
84,
4
] | [
86,
25
] | python | en | ['en', 'sr', 'en'] | True |
HomeConnectSensor.device_class | (self) | Return the device class. | Return the device class. | def device_class(self):
"""Return the device class."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_class"
] | [
89,
4
] | [
91,
33
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up an Avion switch. | Set up an Avion switch. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up an Avion switch."""
# pylint: disable=no-member
avion = importlib.import_module("avion")
lights = []
if CONF_USERNAME in config and CONF_PASSWORD in config:
devices = avion.get_devices(config[CONF_USERNAME], config[CONF_PASSWORD])
for device in devices:
lights.append(AvionLight(device))
for address, device_config in config[CONF_DEVICES].items():
device = avion.Avion(
mac=address,
passphrase=device_config[CONF_API_KEY],
name=device_config.get(CONF_NAME),
object_id=device_config.get(CONF_ID),
connect=False,
)
lights.append(AvionLight(device))
add_entities(lights) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"# pylint: disable=no-member",
"avion",
"=",
"importlib",
".",
"import_module",
"(",
"\"avion\"",
")",
"lights",
"=",
"[",
"]",
"if",
"CONF_USERNAME",
"in",
"config",
"and",
"CONF_PASSWORD",
"in",
"config",
":",
"devices",
"=",
"avion",
".",
"get_devices",
"(",
"config",
"[",
"CONF_USERNAME",
"]",
",",
"config",
"[",
"CONF_PASSWORD",
"]",
")",
"for",
"device",
"in",
"devices",
":",
"lights",
".",
"append",
"(",
"AvionLight",
"(",
"device",
")",
")",
"for",
"address",
",",
"device_config",
"in",
"config",
"[",
"CONF_DEVICES",
"]",
".",
"items",
"(",
")",
":",
"device",
"=",
"avion",
".",
"Avion",
"(",
"mac",
"=",
"address",
",",
"passphrase",
"=",
"device_config",
"[",
"CONF_API_KEY",
"]",
",",
"name",
"=",
"device_config",
".",
"get",
"(",
"CONF_NAME",
")",
",",
"object_id",
"=",
"device_config",
".",
"get",
"(",
"CONF_ID",
")",
",",
"connect",
"=",
"False",
",",
")",
"lights",
".",
"append",
"(",
"AvionLight",
"(",
"device",
")",
")",
"add_entities",
"(",
"lights",
")"
] | [
41,
0
] | [
62,
24
] | python | en | ['en', 'lb', 'en'] | True |
AvionLight.__init__ | (self, device) | Initialize the light. | Initialize the light. | def __init__(self, device):
"""Initialize the light."""
self._name = device.name
self._address = device.mac
self._brightness = 255
self._state = False
self._switch = device | [
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"_name",
"=",
"device",
".",
"name",
"self",
".",
"_address",
"=",
"device",
".",
"mac",
"self",
".",
"_brightness",
"=",
"255",
"self",
".",
"_state",
"=",
"False",
"self",
".",
"_switch",
"=",
"device"
] | [
68,
4
] | [
74,
29
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.unique_id | (self) | Return the ID of this light. | Return the ID of this light. | def unique_id(self):
"""Return the ID of this light."""
return self._address | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_address"
] | [
77,
4
] | [
79,
28
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.name | (self) | Return the name of the device if any. | Return the name of the device if any. | def name(self):
"""Return the name of the device if any."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
82,
4
] | [
84,
25
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.is_on | (self) | Return true if device is on. | Return true if device is on. | def is_on(self):
"""Return true if device is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
87,
4
] | [
89,
26
] | python | en | ['en', 'fy', 'en'] | True |
AvionLight.brightness | (self) | Return the brightness of this light between 0..255. | Return the brightness of this light between 0..255. | def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
92,
4
] | [
94,
31
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_AVION_LED | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_AVION_LED"
] | [
97,
4
] | [
99,
32
] | python | en | ['da', 'en', 'en'] | True |
AvionLight.should_poll | (self) | Don't poll. | Don't poll. | def should_poll(self):
"""Don't poll."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
102,
4
] | [
104,
20
] | python | en | ['en', 'en', 'en'] | False |
AvionLight.assumed_state | (self) | We can't read the actual state, so assume it matches. | We can't read the actual state, so assume it matches. | def assumed_state(self):
"""We can't read the actual state, so assume it matches."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"True"
] | [
107,
4
] | [
109,
19
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.set_state | (self, brightness) | Set the state of this lamp to the provided brightness. | Set the state of this lamp to the provided brightness. | def set_state(self, brightness):
"""Set the state of this lamp to the provided brightness."""
# pylint: disable=no-member
avion = importlib.import_module("avion")
# Bluetooth LE is unreliable, and the connection may drop at any
# time. Make an effort to re-establish the link.
initial = time.monotonic()
while True:
if time.monotonic() - initial >= 10:
return False
try:
self._switch.set_brightness(brightness)
break
except avion.AvionException:
self._switch.connect()
return True | [
"def",
"set_state",
"(",
"self",
",",
"brightness",
")",
":",
"# pylint: disable=no-member",
"avion",
"=",
"importlib",
".",
"import_module",
"(",
"\"avion\"",
")",
"# Bluetooth LE is unreliable, and the connection may drop at any",
"# time. Make an effort to re-establish the link.",
"initial",
"=",
"time",
".",
"monotonic",
"(",
")",
"while",
"True",
":",
"if",
"time",
".",
"monotonic",
"(",
")",
"-",
"initial",
">=",
"10",
":",
"return",
"False",
"try",
":",
"self",
".",
"_switch",
".",
"set_brightness",
"(",
"brightness",
")",
"break",
"except",
"avion",
".",
"AvionException",
":",
"self",
".",
"_switch",
".",
"connect",
"(",
")",
"return",
"True"
] | [
111,
4
] | [
127,
19
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.turn_on | (self, **kwargs) | Turn the specified or all lights on. | Turn the specified or all lights on. | def turn_on(self, **kwargs):
"""Turn the specified or all lights on."""
brightness = kwargs.get(ATTR_BRIGHTNESS)
if brightness is not None:
self._brightness = brightness
self.set_state(self.brightness)
self._state = True | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"brightness",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")",
"if",
"brightness",
"is",
"not",
"None",
":",
"self",
".",
"_brightness",
"=",
"brightness",
"self",
".",
"set_state",
"(",
"self",
".",
"brightness",
")",
"self",
".",
"_state",
"=",
"True"
] | [
129,
4
] | [
137,
26
] | python | en | ['en', 'en', 'en'] | True |
AvionLight.turn_off | (self, **kwargs) | Turn the specified or all lights off. | Turn the specified or all lights off. | def turn_off(self, **kwargs):
"""Turn the specified or all lights off."""
self.set_state(0)
self._state = False | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"set_state",
"(",
"0",
")",
"self",
".",
"_state",
"=",
"False"
] | [
139,
4
] | [
142,
27
] | python | en | ['en', 'en', 'en'] | True |
create_humidifier_service | (accessory) | Define a humidifier characteristics as per page 219 of HAP spec. | Define a humidifier characteristics as per page 219 of HAP spec. | def create_humidifier_service(accessory):
"""Define a humidifier characteristics as per page 219 of HAP spec."""
service = accessory.add_service(ServicesTypes.HUMIDIFIER_DEHUMIDIFIER)
service.add_char(CharacteristicsTypes.ACTIVE, value=False)
cur_state = service.add_char(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT)
cur_state.value = 0
cur_state = service.add_char(
CharacteristicsTypes.CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE
)
cur_state.value = -1
targ_state = service.add_char(
CharacteristicsTypes.TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE
)
targ_state.value = 0
cur_state = service.add_char(
CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD
)
cur_state.value = 0
return service | [
"def",
"create_humidifier_service",
"(",
"accessory",
")",
":",
"service",
"=",
"accessory",
".",
"add_service",
"(",
"ServicesTypes",
".",
"HUMIDIFIER_DEHUMIDIFIER",
")",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"ACTIVE",
",",
"value",
"=",
"False",
")",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"RELATIVE_HUMIDITY_CURRENT",
")",
"cur_state",
".",
"value",
"=",
"0",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE",
")",
"cur_state",
".",
"value",
"=",
"-",
"1",
"targ_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE",
")",
"targ_state",
".",
"value",
"=",
"0",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD",
")",
"cur_state",
".",
"value",
"=",
"0",
"return",
"service"
] | [
29,
0
] | [
53,
18
] | python | en | ['en', 'en', 'en'] | True |
create_dehumidifier_service | (accessory) | Define a dehumidifier characteristics as per page 219 of HAP spec. | Define a dehumidifier characteristics as per page 219 of HAP spec. | def create_dehumidifier_service(accessory):
"""Define a dehumidifier characteristics as per page 219 of HAP spec."""
service = accessory.add_service(ServicesTypes.HUMIDIFIER_DEHUMIDIFIER)
service.add_char(CharacteristicsTypes.ACTIVE, value=False)
cur_state = service.add_char(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT)
cur_state.value = 0
cur_state = service.add_char(
CharacteristicsTypes.CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE
)
cur_state.value = -1
targ_state = service.add_char(
CharacteristicsTypes.TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE
)
targ_state.value = 0
targ_state = service.add_char(
CharacteristicsTypes.RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD
)
targ_state.value = 0
return service | [
"def",
"create_dehumidifier_service",
"(",
"accessory",
")",
":",
"service",
"=",
"accessory",
".",
"add_service",
"(",
"ServicesTypes",
".",
"HUMIDIFIER_DEHUMIDIFIER",
")",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"ACTIVE",
",",
"value",
"=",
"False",
")",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"RELATIVE_HUMIDITY_CURRENT",
")",
"cur_state",
".",
"value",
"=",
"0",
"cur_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE",
")",
"cur_state",
".",
"value",
"=",
"-",
"1",
"targ_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE",
")",
"targ_state",
".",
"value",
"=",
"0",
"targ_state",
"=",
"service",
".",
"add_char",
"(",
"CharacteristicsTypes",
".",
"RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD",
")",
"targ_state",
".",
"value",
"=",
"0",
"return",
"service"
] | [
56,
0
] | [
80,
18
] | python | en | ['en', 'ca', 'en'] | True |
test_humidifier_active_state | (hass, utcnow) | Test that we can turn a HomeKit humidifier on and off again. | Test that we can turn a HomeKit humidifier on and off again. | async def test_humidifier_active_state(hass, utcnow):
"""Test that we can turn a HomeKit humidifier on and off again."""
helper = await setup_test_component(hass, create_humidifier_service)
await hass.services.async_call(
DOMAIN, "turn_on", {"entity_id": helper.entity_id}, blocking=True
)
assert helper.characteristics[ACTIVE].value == 1
await hass.services.async_call(
DOMAIN, "turn_off", {"entity_id": helper.entity_id}, blocking=True
)
assert helper.characteristics[ACTIVE].value == 0 | [
"async",
"def",
"test_humidifier_active_state",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_humidifier_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"turn_on\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"turn_off\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"0"
] | [
83,
0
] | [
97,
52
] | python | en | ['en', 'en', 'en'] | True |
test_dehumidifier_active_state | (hass, utcnow) | Test that we can turn a HomeKit dehumidifier on and off again. | Test that we can turn a HomeKit dehumidifier on and off again. | async def test_dehumidifier_active_state(hass, utcnow):
"""Test that we can turn a HomeKit dehumidifier on and off again."""
helper = await setup_test_component(hass, create_dehumidifier_service)
await hass.services.async_call(
DOMAIN, "turn_on", {"entity_id": helper.entity_id}, blocking=True
)
assert helper.characteristics[ACTIVE].value == 1
await hass.services.async_call(
DOMAIN, "turn_off", {"entity_id": helper.entity_id}, blocking=True
)
assert helper.characteristics[ACTIVE].value == 0 | [
"async",
"def",
"test_dehumidifier_active_state",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_dehumidifier_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"turn_on\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"turn_off\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"0"
] | [
100,
0
] | [
114,
52
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier_read_humidity | (hass, utcnow) | Test that we can read the state of a HomeKit humidifier accessory. | Test that we can read the state of a HomeKit humidifier accessory. | async def test_humidifier_read_humidity(hass, utcnow):
"""Test that we can read the state of a HomeKit humidifier accessory."""
helper = await setup_test_component(hass, create_humidifier_service)
helper.characteristics[ACTIVE].value = True
helper.characteristics[RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD].value = 75
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["humidity"] == 75
helper.characteristics[ACTIVE].value = False
helper.characteristics[RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD].value = 10
state = await helper.poll_and_get_state()
assert state.state == "off"
assert state.attributes["humidity"] == 10
helper.characteristics[CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE].value = 3
state = await helper.poll_and_get_state()
assert state.attributes["humidity"] == 10 | [
"async",
"def",
"test_humidifier_read_humidity",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_humidifier_service",
")",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"=",
"True",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"=",
"75",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"75",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"=",
"False",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"=",
"10",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"off\"",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"10",
"helper",
".",
"characteristics",
"[",
"CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE",
"]",
".",
"value",
"=",
"3",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"10"
] | [
117,
0
] | [
135,
45
] | python | en | ['en', 'en', 'en'] | True |
test_dehumidifier_read_humidity | (hass, utcnow) | Test that we can read the state of a HomeKit dehumidifier accessory. | Test that we can read the state of a HomeKit dehumidifier accessory. | async def test_dehumidifier_read_humidity(hass, utcnow):
"""Test that we can read the state of a HomeKit dehumidifier accessory."""
helper = await setup_test_component(hass, create_dehumidifier_service)
helper.characteristics[ACTIVE].value = True
helper.characteristics[RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD].value = 75
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["humidity"] == 75
helper.characteristics[ACTIVE].value = False
helper.characteristics[RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD].value = 40
state = await helper.poll_and_get_state()
assert state.state == "off"
assert state.attributes["humidity"] == 40
helper.characteristics[CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE].value = 2
state = await helper.poll_and_get_state()
assert state.attributes["humidity"] == 40 | [
"async",
"def",
"test_dehumidifier_read_humidity",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_dehumidifier_service",
")",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"=",
"True",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"=",
"75",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"75",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"=",
"False",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"=",
"40",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"state",
"==",
"\"off\"",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"40",
"helper",
".",
"characteristics",
"[",
"CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE",
"]",
".",
"value",
"=",
"2",
"state",
"=",
"await",
"helper",
".",
"poll_and_get_state",
"(",
")",
"assert",
"state",
".",
"attributes",
"[",
"\"humidity\"",
"]",
"==",
"40"
] | [
138,
0
] | [
156,
45
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier_set_humidity | (hass, utcnow) | Test that we can set the state of a HomeKit humidifier accessory. | Test that we can set the state of a HomeKit humidifier accessory. | async def test_humidifier_set_humidity(hass, utcnow):
"""Test that we can set the state of a HomeKit humidifier accessory."""
helper = await setup_test_component(hass, create_humidifier_service)
await hass.services.async_call(
DOMAIN,
"set_humidity",
{"entity_id": helper.entity_id, "humidity": 20},
blocking=True,
)
assert helper.characteristics[RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD].value == 20 | [
"async",
"def",
"test_humidifier_set_humidity",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_humidifier_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"set_humidity\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
",",
"\"humidity\"",
":",
"20",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"==",
"20"
] | [
159,
0
] | [
169,
85
] | python | en | ['en', 'en', 'en'] | True |
test_dehumidifier_set_humidity | (hass, utcnow) | Test that we can set the state of a HomeKit dehumidifier accessory. | Test that we can set the state of a HomeKit dehumidifier accessory. | async def test_dehumidifier_set_humidity(hass, utcnow):
"""Test that we can set the state of a HomeKit dehumidifier accessory."""
helper = await setup_test_component(hass, create_dehumidifier_service)
await hass.services.async_call(
DOMAIN,
"set_humidity",
{"entity_id": helper.entity_id, "humidity": 20},
blocking=True,
)
assert helper.characteristics[RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD].value == 20 | [
"async",
"def",
"test_dehumidifier_set_humidity",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_dehumidifier_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"set_humidity\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
",",
"\"humidity\"",
":",
"20",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"RELATIVE_HUMIDITY_DEHUMIDIFIER_THRESHOLD",
"]",
".",
"value",
"==",
"20"
] | [
172,
0
] | [
182,
87
] | python | en | ['en', 'en', 'en'] | True |
test_humidifier_set_mode | (hass, utcnow) | Test that we can set the mode of a HomeKit humidifier accessory. | Test that we can set the mode of a HomeKit humidifier accessory. | async def test_humidifier_set_mode(hass, utcnow):
"""Test that we can set the mode of a HomeKit humidifier accessory."""
helper = await setup_test_component(hass, create_humidifier_service)
await hass.services.async_call(
DOMAIN,
"set_mode",
{"entity_id": helper.entity_id, "mode": MODE_AUTO},
blocking=True,
)
assert helper.characteristics[TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE].value == 0
assert helper.characteristics[ACTIVE].value == 1
await hass.services.async_call(
DOMAIN,
"set_mode",
{"entity_id": helper.entity_id, "mode": MODE_NORMAL},
blocking=True,
)
assert helper.characteristics[TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE].value == 1
assert helper.characteristics[ACTIVE].value == 1 | [
"async",
"def",
"test_humidifier_set_mode",
"(",
"hass",
",",
"utcnow",
")",
":",
"helper",
"=",
"await",
"setup_test_component",
"(",
"hass",
",",
"create_humidifier_service",
")",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"set_mode\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
",",
"\"mode\"",
":",
"MODE_AUTO",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE",
"]",
".",
"value",
"==",
"0",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"\"set_mode\"",
",",
"{",
"\"entity_id\"",
":",
"helper",
".",
"entity_id",
",",
"\"mode\"",
":",
"MODE_NORMAL",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"helper",
".",
"characteristics",
"[",
"TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE",
"]",
".",
"value",
"==",
"1",
"assert",
"helper",
".",
"characteristics",
"[",
"ACTIVE",
"]",
".",
"value",
"==",
"1"
] | [
185,
0
] | [
205,
52
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.