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 |
---|---|---|---|---|---|---|---|---|---|---|---|
async_unload_entry | (hass: HomeAssistant, entry: ConfigEntry) | Unload a Notion config entry. | Unload a Notion config entry. | async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a Notion config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(entry, platform)
for platform in PLATFORMS
]
)
)
if unload_ok:
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
return unload_ok | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
")",
"->",
"bool",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"platform",
")",
"for",
"platform",
"in",
"PLATFORMS",
"]",
")",
")",
"if",
"unload_ok",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"DATA_COORDINATOR",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"return",
"unload_ok"
] | [
112,
0
] | [
125,
20
] | python | en | ['en', 'en', 'en'] | True |
async_register_new_bridge | (
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
) | Register a new bridge. | Register a new bridge. | async def async_register_new_bridge(
hass: HomeAssistant, bridge: dict, entry: ConfigEntry
):
"""Register a new bridge."""
device_registry = await dr.async_get_registry(hass)
device_registry.async_get_or_create(
config_entry_id=entry.entry_id,
identifiers={(DOMAIN, bridge["hardware_id"])},
manufacturer="Silicon Labs",
model=bridge["hardware_revision"],
name=bridge["name"] or bridge["id"],
sw_version=bridge["firmware_version"]["wifi"],
) | [
"async",
"def",
"async_register_new_bridge",
"(",
"hass",
":",
"HomeAssistant",
",",
"bridge",
":",
"dict",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"device_registry",
"=",
"await",
"dr",
".",
"async_get_registry",
"(",
"hass",
")",
"device_registry",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"entry",
".",
"entry_id",
",",
"identifiers",
"=",
"{",
"(",
"DOMAIN",
",",
"bridge",
"[",
"\"hardware_id\"",
"]",
")",
"}",
",",
"manufacturer",
"=",
"\"Silicon Labs\"",
",",
"model",
"=",
"bridge",
"[",
"\"hardware_revision\"",
"]",
",",
"name",
"=",
"bridge",
"[",
"\"name\"",
"]",
"or",
"bridge",
"[",
"\"id\"",
"]",
",",
"sw_version",
"=",
"bridge",
"[",
"\"firmware_version\"",
"]",
"[",
"\"wifi\"",
"]",
",",
")"
] | [
128,
0
] | [
140,
5
] | python | en | ['en', 'ca', 'en'] | True |
NotionEntity.__init__ | (
self,
coordinator: DataUpdateCoordinator,
task_id: str,
sensor_id: str,
bridge_id: str,
system_id: str,
name: str,
device_class: str,
) | Initialize the entity. | Initialize the entity. | def __init__(
self,
coordinator: DataUpdateCoordinator,
task_id: str,
sensor_id: str,
bridge_id: str,
system_id: str,
name: str,
device_class: str,
):
"""Initialize the entity."""
super().__init__(coordinator)
self._attrs = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._bridge_id = bridge_id
self._device_class = device_class
self._name = name
self._sensor_id = sensor_id
self._state = None
self._system_id = system_id
self._task_id = task_id | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
":",
"DataUpdateCoordinator",
",",
"task_id",
":",
"str",
",",
"sensor_id",
":",
"str",
",",
"bridge_id",
":",
"str",
",",
"system_id",
":",
"str",
",",
"name",
":",
"str",
",",
"device_class",
":",
"str",
",",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"_attrs",
"=",
"{",
"ATTR_ATTRIBUTION",
":",
"DEFAULT_ATTRIBUTION",
"}",
"self",
".",
"_bridge_id",
"=",
"bridge_id",
"self",
".",
"_device_class",
"=",
"device_class",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_sensor_id",
"=",
"sensor_id",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_system_id",
"=",
"system_id",
"self",
".",
"_task_id",
"=",
"task_id"
] | [
146,
4
] | [
165,
31
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.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.coordinator.last_update_success
and self._task_id in self.coordinator.data["tasks"]
) | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"(",
"self",
".",
"coordinator",
".",
"last_update_success",
"and",
"self",
".",
"_task_id",
"in",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"tasks\"",
"]",
")"
] | [
168,
4
] | [
173,
9
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.device_class | (self) | Return the device class. | Return the device class. | def device_class(self) -> str:
"""Return the device class."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_device_class"
] | [
176,
4
] | [
178,
33
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self) -> dict:
"""Return the state attributes."""
return self._attrs | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"self",
".",
"_attrs"
] | [
181,
4
] | [
183,
26
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.device_info | (self) | Return device registry information for this entity. | Return device registry information for this entity. | def device_info(self) -> dict:
"""Return device registry information for this entity."""
bridge = self.coordinator.data["bridges"].get(self._bridge_id, {})
sensor = self.coordinator.data["sensors"][self._sensor_id]
return {
"identifiers": {(DOMAIN, sensor["hardware_id"])},
"manufacturer": "Silicon Labs",
"model": sensor["hardware_revision"],
"name": sensor["name"],
"sw_version": sensor["firmware_version"],
"via_device": (DOMAIN, bridge.get("hardware_id")),
} | [
"def",
"device_info",
"(",
"self",
")",
"->",
"dict",
":",
"bridge",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"bridges\"",
"]",
".",
"get",
"(",
"self",
".",
"_bridge_id",
",",
"{",
"}",
")",
"sensor",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"sensors\"",
"]",
"[",
"self",
".",
"_sensor_id",
"]",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"sensor",
"[",
"\"hardware_id\"",
"]",
")",
"}",
",",
"\"manufacturer\"",
":",
"\"Silicon Labs\"",
",",
"\"model\"",
":",
"sensor",
"[",
"\"hardware_revision\"",
"]",
",",
"\"name\"",
":",
"sensor",
"[",
"\"name\"",
"]",
",",
"\"sw_version\"",
":",
"sensor",
"[",
"\"firmware_version\"",
"]",
",",
"\"via_device\"",
":",
"(",
"DOMAIN",
",",
"bridge",
".",
"get",
"(",
"\"hardware_id\"",
")",
")",
",",
"}"
] | [
186,
4
] | [
198,
9
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.name | (self) | Return the name of the entity. | Return the name of the entity. | def name(self) -> str:
"""Return the name of the entity."""
sensor = self.coordinator.data["sensors"][self._sensor_id]
return f'{sensor["name"]}: {self._name}' | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"sensor",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"sensors\"",
"]",
"[",
"self",
".",
"_sensor_id",
"]",
"return",
"f'{sensor[\"name\"]}: {self._name}'"
] | [
201,
4
] | [
204,
48
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity.unique_id | (self) | Return a unique, unchanging string that represents this entity. | Return a unique, unchanging string that represents this entity. | def unique_id(self) -> str:
"""Return a unique, unchanging string that represents this entity."""
task = self.coordinator.data["tasks"][self._task_id]
return f'{self._sensor_id}_{task["task_type"]}' | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"task",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"tasks\"",
"]",
"[",
"self",
".",
"_task_id",
"]",
"return",
"f'{self._sensor_id}_{task[\"task_type\"]}'"
] | [
207,
4
] | [
210,
55
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity._async_update_bridge_id | (self) | Update the entity's bridge ID if it has changed.
Sensors can move to other bridges based on signal strength, etc.
| Update the entity's bridge ID if it has changed. | async def _async_update_bridge_id(self) -> None:
"""Update the entity's bridge ID if it has changed.
Sensors can move to other bridges based on signal strength, etc.
"""
sensor = self.coordinator.data["sensors"][self._sensor_id]
# If the sensor's bridge ID is the same as what we had before or if it points
# to a bridge that doesn't exist (which can happen due to a Notion API bug),
# return immediately:
if (
self._bridge_id == sensor["bridge"]["id"]
or sensor["bridge"]["id"] not in self.coordinator.data["bridges"]
):
return
self._bridge_id = sensor["bridge"]["id"]
device_registry = await dr.async_get_registry(self.hass)
bridge = self.coordinator.data["bridges"][self._bridge_id]
bridge_device = device_registry.async_get_device(
{DOMAIN: bridge["hardware_id"]}, set()
)
this_device = device_registry.async_get_device(
{DOMAIN: sensor["hardware_id"]}, set()
)
device_registry.async_update_device(
this_device.id, via_device_id=bridge_device.id
) | [
"async",
"def",
"_async_update_bridge_id",
"(",
"self",
")",
"->",
"None",
":",
"sensor",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"sensors\"",
"]",
"[",
"self",
".",
"_sensor_id",
"]",
"# If the sensor's bridge ID is the same as what we had before or if it points",
"# to a bridge that doesn't exist (which can happen due to a Notion API bug),",
"# return immediately:",
"if",
"(",
"self",
".",
"_bridge_id",
"==",
"sensor",
"[",
"\"bridge\"",
"]",
"[",
"\"id\"",
"]",
"or",
"sensor",
"[",
"\"bridge\"",
"]",
"[",
"\"id\"",
"]",
"not",
"in",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"bridges\"",
"]",
")",
":",
"return",
"self",
".",
"_bridge_id",
"=",
"sensor",
"[",
"\"bridge\"",
"]",
"[",
"\"id\"",
"]",
"device_registry",
"=",
"await",
"dr",
".",
"async_get_registry",
"(",
"self",
".",
"hass",
")",
"bridge",
"=",
"self",
".",
"coordinator",
".",
"data",
"[",
"\"bridges\"",
"]",
"[",
"self",
".",
"_bridge_id",
"]",
"bridge_device",
"=",
"device_registry",
".",
"async_get_device",
"(",
"{",
"DOMAIN",
":",
"bridge",
"[",
"\"hardware_id\"",
"]",
"}",
",",
"set",
"(",
")",
")",
"this_device",
"=",
"device_registry",
".",
"async_get_device",
"(",
"{",
"DOMAIN",
":",
"sensor",
"[",
"\"hardware_id\"",
"]",
"}",
",",
"set",
"(",
")",
")",
"device_registry",
".",
"async_update_device",
"(",
"this_device",
".",
"id",
",",
"via_device_id",
"=",
"bridge_device",
".",
"id",
")"
] | [
212,
4
] | [
241,
9
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity._async_update_from_latest_data | (self) | Update the entity from the latest data. | Update the entity from the latest data. | def _async_update_from_latest_data(self) -> None:
"""Update the entity from the latest data."""
raise NotImplementedError | [
"def",
"_async_update_from_latest_data",
"(",
"self",
")",
"->",
"None",
":",
"raise",
"NotImplementedError"
] | [
244,
4
] | [
246,
33
] | python | en | ['en', 'en', 'en'] | True |
NotionEntity._handle_coordinator_update | (self) | Respond to a DataUpdateCoordinator update. | Respond to a DataUpdateCoordinator update. | def _handle_coordinator_update(self):
"""Respond to a DataUpdateCoordinator update."""
self.hass.async_create_task(self._async_update_bridge_id())
self._async_update_from_latest_data()
self.async_write_ha_state() | [
"def",
"_handle_coordinator_update",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"async_create_task",
"(",
"self",
".",
"_async_update_bridge_id",
"(",
")",
")",
"self",
".",
"_async_update_from_latest_data",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
249,
4
] | [
253,
35
] | python | en | ['en', 'de', 'en'] | True |
NotionEntity.async_added_to_hass | (self) | Handle entity which will be added. | Handle entity which will be added. | async def async_added_to_hass(self):
"""Handle entity which will be added."""
await super().async_added_to_hass()
self._async_update_from_latest_data() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"self",
".",
"_async_update_from_latest_data",
"(",
")"
] | [
255,
4
] | [
258,
45
] | python | en | ['en', 'en', 'en'] | True |
init_integration | (hass, forecast=False) | Set up the Airly integration in Home Assistant. | Set up the Airly integration in Home Assistant. | async def init_integration(hass, forecast=False) -> MockConfigEntry:
"""Set up the Airly integration in Home Assistant."""
entry = MockConfigEntry(
domain=DOMAIN,
title="Home",
unique_id="55.55-122.12",
data={
"api_key": "foo",
"latitude": 55.55,
"longitude": 122.12,
"name": "Home",
},
)
with patch(
"airly._private._RequestsHandler.get",
return_value=json.loads(load_fixture("airly_valid_station.json")),
):
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
return entry | [
"async",
"def",
"init_integration",
"(",
"hass",
",",
"forecast",
"=",
"False",
")",
"->",
"MockConfigEntry",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"title",
"=",
"\"Home\"",
",",
"unique_id",
"=",
"\"55.55-122.12\"",
",",
"data",
"=",
"{",
"\"api_key\"",
":",
"\"foo\"",
",",
"\"latitude\"",
":",
"55.55",
",",
"\"longitude\"",
":",
"122.12",
",",
"\"name\"",
":",
"\"Home\"",
",",
"}",
",",
")",
"with",
"patch",
"(",
"\"airly._private._RequestsHandler.get\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"airly_valid_station.json\"",
")",
")",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"entry"
] | [
9,
0
] | [
31,
16
] | python | en | ['en', 'en', 'en'] | True |
MaskedLinear.__init__ | (
self,
in_features: int,
out_features: int,
bias: bool = True,
mask_init: str = "constant",
mask_scale: float = 0.0,
pruning_method: str = "topK",
) |
Args:
in_features (`int`)
Size of each input sample
out_features (`int`)
Size of each output sample
bias (`bool`)
If set to ``False``, the layer will not learn an additive bias.
Default: ``True``
mask_init (`str`)
The initialization method for the score matrix if a score matrix is needed.
Choices: ["constant", "uniform", "kaiming"]
Default: ``constant``
mask_scale (`float`)
The initialization parameter for the chosen initialization method `mask_init`.
Default: ``0.``
pruning_method (`str`)
Method to compute the mask.
Choices: ["topK", "threshold", "sigmoied_threshold", "magnitude", "l0"]
Default: ``topK``
|
Args:
in_features (`int`)
Size of each input sample
out_features (`int`)
Size of each output sample
bias (`bool`)
If set to ``False``, the layer will not learn an additive bias.
Default: ``True``
mask_init (`str`)
The initialization method for the score matrix if a score matrix is needed.
Choices: ["constant", "uniform", "kaiming"]
Default: ``constant``
mask_scale (`float`)
The initialization parameter for the chosen initialization method `mask_init`.
Default: ``0.``
pruning_method (`str`)
Method to compute the mask.
Choices: ["topK", "threshold", "sigmoied_threshold", "magnitude", "l0"]
Default: ``topK``
| def __init__(
self,
in_features: int,
out_features: int,
bias: bool = True,
mask_init: str = "constant",
mask_scale: float = 0.0,
pruning_method: str = "topK",
):
"""
Args:
in_features (`int`)
Size of each input sample
out_features (`int`)
Size of each output sample
bias (`bool`)
If set to ``False``, the layer will not learn an additive bias.
Default: ``True``
mask_init (`str`)
The initialization method for the score matrix if a score matrix is needed.
Choices: ["constant", "uniform", "kaiming"]
Default: ``constant``
mask_scale (`float`)
The initialization parameter for the chosen initialization method `mask_init`.
Default: ``0.``
pruning_method (`str`)
Method to compute the mask.
Choices: ["topK", "threshold", "sigmoied_threshold", "magnitude", "l0"]
Default: ``topK``
"""
super(MaskedLinear, self).__init__(in_features=in_features, out_features=out_features, bias=bias)
assert pruning_method in ["topK", "threshold", "sigmoied_threshold", "magnitude", "l0"]
self.pruning_method = pruning_method
if self.pruning_method in ["topK", "threshold", "sigmoied_threshold", "l0"]:
self.mask_scale = mask_scale
self.mask_init = mask_init
self.mask_scores = nn.Parameter(torch.Tensor(self.weight.size()))
self.init_mask() | [
"def",
"__init__",
"(",
"self",
",",
"in_features",
":",
"int",
",",
"out_features",
":",
"int",
",",
"bias",
":",
"bool",
"=",
"True",
",",
"mask_init",
":",
"str",
"=",
"\"constant\"",
",",
"mask_scale",
":",
"float",
"=",
"0.0",
",",
"pruning_method",
":",
"str",
"=",
"\"topK\"",
",",
")",
":",
"super",
"(",
"MaskedLinear",
",",
"self",
")",
".",
"__init__",
"(",
"in_features",
"=",
"in_features",
",",
"out_features",
"=",
"out_features",
",",
"bias",
"=",
"bias",
")",
"assert",
"pruning_method",
"in",
"[",
"\"topK\"",
",",
"\"threshold\"",
",",
"\"sigmoied_threshold\"",
",",
"\"magnitude\"",
",",
"\"l0\"",
"]",
"self",
".",
"pruning_method",
"=",
"pruning_method",
"if",
"self",
".",
"pruning_method",
"in",
"[",
"\"topK\"",
",",
"\"threshold\"",
",",
"\"sigmoied_threshold\"",
",",
"\"l0\"",
"]",
":",
"self",
".",
"mask_scale",
"=",
"mask_scale",
"self",
".",
"mask_init",
"=",
"mask_init",
"self",
".",
"mask_scores",
"=",
"nn",
".",
"Parameter",
"(",
"torch",
".",
"Tensor",
"(",
"self",
".",
"weight",
".",
"size",
"(",
")",
")",
")",
"self",
".",
"init_mask",
"(",
")"
] | [
37,
4
] | [
75,
28
] | python | en | ['en', 'error', 'th'] | False |
test_maybe_schedule_update | (hass, mock_openzwave) | Test maybe schedule update. | Test maybe schedule update. | async def test_maybe_schedule_update(hass, mock_openzwave):
"""Test maybe schedule update."""
base_entity = node_entity.ZWaveBaseEntity()
base_entity.entity_id = "zwave.bla"
base_entity.hass = hass
with patch.object(hass.loop, "call_later") as mock_call_later:
base_entity._schedule_update()
assert mock_call_later.called
base_entity._schedule_update()
assert len(mock_call_later.mock_calls) == 1
assert base_entity._update_scheduled is True
do_update = mock_call_later.mock_calls[0][1][1]
do_update()
assert base_entity._update_scheduled is False
base_entity._schedule_update()
assert len(mock_call_later.mock_calls) == 2 | [
"async",
"def",
"test_maybe_schedule_update",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"base_entity",
"=",
"node_entity",
".",
"ZWaveBaseEntity",
"(",
")",
"base_entity",
".",
"entity_id",
"=",
"\"zwave.bla\"",
"base_entity",
".",
"hass",
"=",
"hass",
"with",
"patch",
".",
"object",
"(",
"hass",
".",
"loop",
",",
"\"call_later\"",
")",
"as",
"mock_call_later",
":",
"base_entity",
".",
"_schedule_update",
"(",
")",
"assert",
"mock_call_later",
".",
"called",
"base_entity",
".",
"_schedule_update",
"(",
")",
"assert",
"len",
"(",
"mock_call_later",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"base_entity",
".",
"_update_scheduled",
"is",
"True",
"do_update",
"=",
"mock_call_later",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"1",
"]",
"do_update",
"(",
")",
"assert",
"base_entity",
".",
"_update_scheduled",
"is",
"False",
"base_entity",
".",
"_schedule_update",
"(",
")",
"assert",
"len",
"(",
"mock_call_later",
".",
"mock_calls",
")",
"==",
"2"
] | [
8,
0
] | [
28,
51
] | python | de | ['de', 'de', 'en'] | True |
test_node_event_activated | (hass, mock_openzwave) | Test Node event activated event. | Test Node event activated event. | async def test_node_event_activated(hass, mock_openzwave):
"""Test Node event activated event."""
mock_receivers = []
def mock_connect(receiver, signal, *args, **kwargs):
if signal == mock_zwave.MockNetwork.SIGNAL_NODE_EVENT:
mock_receivers.append(receiver)
node = mock_zwave.MockNode(node_id=11)
with patch("pydispatch.dispatcher.connect", new=mock_connect):
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
assert len(mock_receivers) == 1
events = []
def listener(event):
events.append(event)
hass.bus.async_listen(const.EVENT_NODE_EVENT, listener)
# Test event before entity added to hass
value = 234
hass.async_add_job(mock_receivers[0], node, value)
await hass.async_block_till_done()
assert len(events) == 0
# Add entity to hass
entity.hass = hass
entity.entity_id = "zwave.mock_node"
value = 234
hass.async_add_job(mock_receivers[0], node, value)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data[ATTR_ENTITY_ID] == "zwave.mock_node"
assert events[0].data[const.ATTR_NODE_ID] == 11
assert events[0].data[const.ATTR_BASIC_LEVEL] == value | [
"async",
"def",
"test_node_event_activated",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_receivers",
"=",
"[",
"]",
"def",
"mock_connect",
"(",
"receiver",
",",
"signal",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"signal",
"==",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_NODE_EVENT",
":",
"mock_receivers",
".",
"append",
"(",
"receiver",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"node_id",
"=",
"11",
")",
"with",
"patch",
"(",
"\"pydispatch.dispatcher.connect\"",
",",
"new",
"=",
"mock_connect",
")",
":",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"mock_openzwave",
")",
"assert",
"len",
"(",
"mock_receivers",
")",
"==",
"1",
"events",
"=",
"[",
"]",
"def",
"listener",
"(",
"event",
")",
":",
"events",
".",
"append",
"(",
"event",
")",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"const",
".",
"EVENT_NODE_EVENT",
",",
"listener",
")",
"# Test event before entity added to hass",
"value",
"=",
"234",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"0",
"# Add entity to hass",
"entity",
".",
"hass",
"=",
"hass",
"entity",
".",
"entity_id",
"=",
"\"zwave.mock_node\"",
"value",
"=",
"234",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"\"zwave.mock_node\"",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_NODE_ID",
"]",
"==",
"11",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_BASIC_LEVEL",
"]",
"==",
"value"
] | [
31,
0
] | [
70,
58
] | python | en | ['en', 'en', 'en'] | True |
test_scene_activated | (hass, mock_openzwave) | Test scene activated event. | Test scene activated event. | async def test_scene_activated(hass, mock_openzwave):
"""Test scene activated event."""
mock_receivers = []
def mock_connect(receiver, signal, *args, **kwargs):
if signal == mock_zwave.MockNetwork.SIGNAL_SCENE_EVENT:
mock_receivers.append(receiver)
node = mock_zwave.MockNode(node_id=11)
with patch("pydispatch.dispatcher.connect", new=mock_connect):
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
assert len(mock_receivers) == 1
events = []
def listener(event):
events.append(event)
hass.bus.async_listen(const.EVENT_SCENE_ACTIVATED, listener)
# Test event before entity added to hass
scene_id = 123
hass.async_add_job(mock_receivers[0], node, scene_id)
await hass.async_block_till_done()
assert len(events) == 0
# Add entity to hass
entity.hass = hass
entity.entity_id = "zwave.mock_node"
scene_id = 123
hass.async_add_job(mock_receivers[0], node, scene_id)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data[ATTR_ENTITY_ID] == "zwave.mock_node"
assert events[0].data[const.ATTR_NODE_ID] == 11
assert events[0].data[const.ATTR_SCENE_ID] == scene_id | [
"async",
"def",
"test_scene_activated",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_receivers",
"=",
"[",
"]",
"def",
"mock_connect",
"(",
"receiver",
",",
"signal",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"signal",
"==",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_SCENE_EVENT",
":",
"mock_receivers",
".",
"append",
"(",
"receiver",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"node_id",
"=",
"11",
")",
"with",
"patch",
"(",
"\"pydispatch.dispatcher.connect\"",
",",
"new",
"=",
"mock_connect",
")",
":",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"mock_openzwave",
")",
"assert",
"len",
"(",
"mock_receivers",
")",
"==",
"1",
"events",
"=",
"[",
"]",
"def",
"listener",
"(",
"event",
")",
":",
"events",
".",
"append",
"(",
"event",
")",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"const",
".",
"EVENT_SCENE_ACTIVATED",
",",
"listener",
")",
"# Test event before entity added to hass",
"scene_id",
"=",
"123",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"scene_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"0",
"# Add entity to hass",
"entity",
".",
"hass",
"=",
"hass",
"entity",
".",
"entity_id",
"=",
"\"zwave.mock_node\"",
"scene_id",
"=",
"123",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"scene_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"\"zwave.mock_node\"",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_NODE_ID",
"]",
"==",
"11",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_SCENE_ID",
"]",
"==",
"scene_id"
] | [
73,
0
] | [
112,
58
] | python | en | ['en', 'en', 'en'] | True |
test_central_scene_activated | (hass, mock_openzwave) | Test central scene activated event. | Test central scene activated event. | async def test_central_scene_activated(hass, mock_openzwave):
"""Test central scene activated event."""
mock_receivers = []
def mock_connect(receiver, signal, *args, **kwargs):
if signal == mock_zwave.MockNetwork.SIGNAL_VALUE_CHANGED:
mock_receivers.append(receiver)
node = mock_zwave.MockNode(node_id=11)
with patch("pydispatch.dispatcher.connect", new=mock_connect):
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
assert len(mock_receivers) == 1
events = []
def listener(event):
events.append(event)
hass.bus.async_listen(const.EVENT_SCENE_ACTIVATED, listener)
# Test event before entity added to hass
scene_id = 1
scene_data = 3
value = mock_zwave.MockValue(
command_class=const.COMMAND_CLASS_CENTRAL_SCENE, index=scene_id, data=scene_data
)
hass.async_add_job(mock_receivers[0], node, value)
await hass.async_block_till_done()
assert len(events) == 0
# Add entity to hass
entity.hass = hass
entity.entity_id = "zwave.mock_node"
scene_id = 1
scene_data = 3
value = mock_zwave.MockValue(
command_class=const.COMMAND_CLASS_CENTRAL_SCENE, index=scene_id, data=scene_data
)
hass.async_add_job(mock_receivers[0], node, value)
await hass.async_block_till_done()
assert len(events) == 1
assert events[0].data[ATTR_ENTITY_ID] == "zwave.mock_node"
assert events[0].data[const.ATTR_NODE_ID] == 11
assert events[0].data[const.ATTR_SCENE_ID] == scene_id
assert events[0].data[const.ATTR_SCENE_DATA] == scene_data | [
"async",
"def",
"test_central_scene_activated",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_receivers",
"=",
"[",
"]",
"def",
"mock_connect",
"(",
"receiver",
",",
"signal",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"signal",
"==",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_VALUE_CHANGED",
":",
"mock_receivers",
".",
"append",
"(",
"receiver",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"node_id",
"=",
"11",
")",
"with",
"patch",
"(",
"\"pydispatch.dispatcher.connect\"",
",",
"new",
"=",
"mock_connect",
")",
":",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"mock_openzwave",
")",
"assert",
"len",
"(",
"mock_receivers",
")",
"==",
"1",
"events",
"=",
"[",
"]",
"def",
"listener",
"(",
"event",
")",
":",
"events",
".",
"append",
"(",
"event",
")",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"const",
".",
"EVENT_SCENE_ACTIVATED",
",",
"listener",
")",
"# Test event before entity added to hass",
"scene_id",
"=",
"1",
"scene_data",
"=",
"3",
"value",
"=",
"mock_zwave",
".",
"MockValue",
"(",
"command_class",
"=",
"const",
".",
"COMMAND_CLASS_CENTRAL_SCENE",
",",
"index",
"=",
"scene_id",
",",
"data",
"=",
"scene_data",
")",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"0",
"# Add entity to hass",
"entity",
".",
"hass",
"=",
"hass",
"entity",
".",
"entity_id",
"=",
"\"zwave.mock_node\"",
"scene_id",
"=",
"1",
"scene_data",
"=",
"3",
"value",
"=",
"mock_zwave",
".",
"MockValue",
"(",
"command_class",
"=",
"const",
".",
"COMMAND_CLASS_CENTRAL_SCENE",
",",
"index",
"=",
"scene_id",
",",
"data",
"=",
"scene_data",
")",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"0",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"events",
")",
"==",
"1",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
"==",
"\"zwave.mock_node\"",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_NODE_ID",
"]",
"==",
"11",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_SCENE_ID",
"]",
"==",
"scene_id",
"assert",
"events",
"[",
"0",
"]",
".",
"data",
"[",
"const",
".",
"ATTR_SCENE_DATA",
"]",
"==",
"scene_data"
] | [
115,
0
] | [
163,
62
] | python | en | ['en', 'en', 'en'] | True |
test_application_version | (hass, mock_openzwave) | Test application version. | Test application version. | async def test_application_version(hass, mock_openzwave):
"""Test application version."""
mock_receivers = {}
signal_mocks = [
mock_zwave.MockNetwork.SIGNAL_VALUE_CHANGED,
mock_zwave.MockNetwork.SIGNAL_VALUE_ADDED,
]
def mock_connect(receiver, signal, *args, **kwargs):
if signal in signal_mocks:
mock_receivers[signal] = receiver
node = mock_zwave.MockNode(node_id=11)
with patch("pydispatch.dispatcher.connect", new=mock_connect):
entity = node_entity.ZWaveNodeEntity(node, mock_openzwave)
for signal_mock in signal_mocks:
assert signal_mock in mock_receivers.keys()
events = []
def listener(event):
events.append(event)
# Make sure application version isn't set before
assert (
node_entity.ATTR_APPLICATION_VERSION
not in entity.device_state_attributes.keys()
)
# Add entity to hass
entity.hass = hass
entity.entity_id = "zwave.mock_node"
# Fire off an added value
value = mock_zwave.MockValue(
command_class=const.COMMAND_CLASS_VERSION,
label="Application Version",
data="5.10",
)
hass.async_add_job(
mock_receivers[mock_zwave.MockNetwork.SIGNAL_VALUE_ADDED], node, value
)
await hass.async_block_till_done()
assert (
entity.device_state_attributes[node_entity.ATTR_APPLICATION_VERSION] == "5.10"
)
# Fire off a changed
value = mock_zwave.MockValue(
command_class=const.COMMAND_CLASS_VERSION,
label="Application Version",
data="4.14",
)
hass.async_add_job(
mock_receivers[mock_zwave.MockNetwork.SIGNAL_VALUE_CHANGED], node, value
)
await hass.async_block_till_done()
assert (
entity.device_state_attributes[node_entity.ATTR_APPLICATION_VERSION] == "4.14"
) | [
"async",
"def",
"test_application_version",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"mock_receivers",
"=",
"{",
"}",
"signal_mocks",
"=",
"[",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_VALUE_CHANGED",
",",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_VALUE_ADDED",
",",
"]",
"def",
"mock_connect",
"(",
"receiver",
",",
"signal",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"signal",
"in",
"signal_mocks",
":",
"mock_receivers",
"[",
"signal",
"]",
"=",
"receiver",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"node_id",
"=",
"11",
")",
"with",
"patch",
"(",
"\"pydispatch.dispatcher.connect\"",
",",
"new",
"=",
"mock_connect",
")",
":",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"mock_openzwave",
")",
"for",
"signal_mock",
"in",
"signal_mocks",
":",
"assert",
"signal_mock",
"in",
"mock_receivers",
".",
"keys",
"(",
")",
"events",
"=",
"[",
"]",
"def",
"listener",
"(",
"event",
")",
":",
"events",
".",
"append",
"(",
"event",
")",
"# Make sure application version isn't set before",
"assert",
"(",
"node_entity",
".",
"ATTR_APPLICATION_VERSION",
"not",
"in",
"entity",
".",
"device_state_attributes",
".",
"keys",
"(",
")",
")",
"# Add entity to hass",
"entity",
".",
"hass",
"=",
"hass",
"entity",
".",
"entity_id",
"=",
"\"zwave.mock_node\"",
"# Fire off an added value",
"value",
"=",
"mock_zwave",
".",
"MockValue",
"(",
"command_class",
"=",
"const",
".",
"COMMAND_CLASS_VERSION",
",",
"label",
"=",
"\"Application Version\"",
",",
"data",
"=",
"\"5.10\"",
",",
")",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_VALUE_ADDED",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"(",
"entity",
".",
"device_state_attributes",
"[",
"node_entity",
".",
"ATTR_APPLICATION_VERSION",
"]",
"==",
"\"5.10\"",
")",
"# Fire off a changed",
"value",
"=",
"mock_zwave",
".",
"MockValue",
"(",
"command_class",
"=",
"const",
".",
"COMMAND_CLASS_VERSION",
",",
"label",
"=",
"\"Application Version\"",
",",
"data",
"=",
"\"4.14\"",
",",
")",
"hass",
".",
"async_add_job",
"(",
"mock_receivers",
"[",
"mock_zwave",
".",
"MockNetwork",
".",
"SIGNAL_VALUE_CHANGED",
"]",
",",
"node",
",",
"value",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"(",
"entity",
".",
"device_state_attributes",
"[",
"node_entity",
".",
"ATTR_APPLICATION_VERSION",
"]",
"==",
"\"4.14\"",
")"
] | [
166,
0
] | [
230,
5
] | python | en | ['en', 'da', 'en'] | True |
test_network_node_changed_from_value | (hass, mock_openzwave) | Test for network_node_changed. | Test for network_node_changed. | async def test_network_node_changed_from_value(hass, mock_openzwave):
"""Test for network_node_changed."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
value = mock_zwave.MockValue(node=node)
with patch.object(entity, "maybe_schedule_update") as mock:
mock_zwave.value_changed(value)
mock.assert_called_once_with() | [
"async",
"def",
"test_network_node_changed_from_value",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"value",
"=",
"mock_zwave",
".",
"MockValue",
"(",
"node",
"=",
"node",
")",
"with",
"patch",
".",
"object",
"(",
"entity",
",",
"\"maybe_schedule_update\"",
")",
"as",
"mock",
":",
"mock_zwave",
".",
"value_changed",
"(",
"value",
")",
"mock",
".",
"assert_called_once_with",
"(",
")"
] | [
233,
0
] | [
241,
38
] | python | en | ['en', 'en', 'en'] | True |
test_network_node_changed_from_node | (hass, mock_openzwave) | Test for network_node_changed. | Test for network_node_changed. | async def test_network_node_changed_from_node(hass, mock_openzwave):
"""Test for network_node_changed."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
with patch.object(entity, "maybe_schedule_update") as mock:
mock_zwave.node_changed(node)
mock.assert_called_once_with() | [
"async",
"def",
"test_network_node_changed_from_node",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"with",
"patch",
".",
"object",
"(",
"entity",
",",
"\"maybe_schedule_update\"",
")",
"as",
"mock",
":",
"mock_zwave",
".",
"node_changed",
"(",
"node",
")",
"mock",
".",
"assert_called_once_with",
"(",
")"
] | [
244,
0
] | [
251,
38
] | python | en | ['en', 'en', 'en'] | True |
test_network_node_changed_from_another_node | (hass, mock_openzwave) | Test for network_node_changed. | Test for network_node_changed. | async def test_network_node_changed_from_another_node(hass, mock_openzwave):
"""Test for network_node_changed."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
with patch.object(entity, "maybe_schedule_update") as mock:
another_node = mock_zwave.MockNode(node_id=1024)
mock_zwave.node_changed(another_node)
assert not mock.called | [
"async",
"def",
"test_network_node_changed_from_another_node",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"with",
"patch",
".",
"object",
"(",
"entity",
",",
"\"maybe_schedule_update\"",
")",
"as",
"mock",
":",
"another_node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"node_id",
"=",
"1024",
")",
"mock_zwave",
".",
"node_changed",
"(",
"another_node",
")",
"assert",
"not",
"mock",
".",
"called"
] | [
254,
0
] | [
262,
30
] | python | en | ['en', 'en', 'en'] | True |
test_network_node_changed_from_notification | (hass, mock_openzwave) | Test for network_node_changed. | Test for network_node_changed. | async def test_network_node_changed_from_notification(hass, mock_openzwave):
"""Test for network_node_changed."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
with patch.object(entity, "maybe_schedule_update") as mock:
mock_zwave.notification(node_id=node.node_id)
mock.assert_called_once_with() | [
"async",
"def",
"test_network_node_changed_from_notification",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"with",
"patch",
".",
"object",
"(",
"entity",
",",
"\"maybe_schedule_update\"",
")",
"as",
"mock",
":",
"mock_zwave",
".",
"notification",
"(",
"node_id",
"=",
"node",
".",
"node_id",
")",
"mock",
".",
"assert_called_once_with",
"(",
")"
] | [
265,
0
] | [
272,
38
] | python | en | ['en', 'en', 'en'] | True |
test_network_node_changed_from_another_notification | (hass, mock_openzwave) | Test for network_node_changed. | Test for network_node_changed. | async def test_network_node_changed_from_another_notification(hass, mock_openzwave):
"""Test for network_node_changed."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
with patch.object(entity, "maybe_schedule_update") as mock:
mock_zwave.notification(node_id=1024)
assert not mock.called | [
"async",
"def",
"test_network_node_changed_from_another_notification",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"with",
"patch",
".",
"object",
"(",
"entity",
",",
"\"maybe_schedule_update\"",
")",
"as",
"mock",
":",
"mock_zwave",
".",
"notification",
"(",
"node_id",
"=",
"1024",
")",
"assert",
"not",
"mock",
".",
"called"
] | [
275,
0
] | [
282,
30
] | python | en | ['en', 'en', 'en'] | True |
test_node_changed | (hass, mock_openzwave) | Test node_changed function. | Test node_changed function. | async def test_node_changed(hass, mock_openzwave):
"""Test node_changed function."""
zwave_network = MagicMock()
node = mock_zwave.MockNode(
query_stage="Dynamic",
is_awake=True,
is_ready=False,
is_failed=False,
is_info_received=True,
max_baud_rate=40000,
is_zwave_plus=False,
capabilities=[],
neighbors=[],
location=None,
)
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert {
"node_id": node.node_id,
"node_name": "Mock Node",
"manufacturer_name": "Test Manufacturer",
"product_name": "Test Product",
} == entity.device_state_attributes
node.get_values.return_value = {1: mock_zwave.MockValue(data=1800)}
zwave_network.manager.getNodeStatistics.return_value = {
"receivedCnt": 4,
"ccData": [
{"receivedCnt": 0, "commandClassId": 134, "sentCnt": 0},
{"receivedCnt": 1, "commandClassId": 133, "sentCnt": 1},
{"receivedCnt": 1, "commandClassId": 115, "sentCnt": 1},
{"receivedCnt": 0, "commandClassId": 114, "sentCnt": 0},
{"receivedCnt": 0, "commandClassId": 112, "sentCnt": 0},
{"receivedCnt": 1, "commandClassId": 32, "sentCnt": 1},
{"receivedCnt": 0, "commandClassId": 0, "sentCnt": 0},
],
"receivedUnsolicited": 0,
"sentTS": "2017-03-27 15:38:15:620 ",
"averageRequestRTT": 2462,
"lastResponseRTT": 3679,
"retries": 0,
"sentFailed": 1,
"sentCnt": 7,
"quality": 0,
"lastRequestRTT": 1591,
"lastReceivedMessage": [
0,
4,
0,
15,
3,
32,
3,
0,
221,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
"receivedDups": 1,
"averageResponseRTT": 2443,
"receivedTS": "2017-03-27 15:38:19:298 ",
}
entity.node_changed()
assert {
"node_id": node.node_id,
"node_name": "Mock Node",
"manufacturer_name": "Test Manufacturer",
"product_name": "Test Product",
"query_stage": "Dynamic",
"is_awake": True,
"is_ready": False,
"is_failed": False,
"is_info_received": True,
"max_baud_rate": 40000,
"is_zwave_plus": False,
"battery_level": 42,
"wake_up_interval": 1800,
"averageRequestRTT": 2462,
"averageResponseRTT": 2443,
"lastRequestRTT": 1591,
"lastResponseRTT": 3679,
"receivedCnt": 4,
"receivedDups": 1,
"receivedTS": "2017-03-27 15:38:19:298 ",
"receivedUnsolicited": 0,
"retries": 0,
"sentCnt": 7,
"sentFailed": 1,
"sentTS": "2017-03-27 15:38:15:620 ",
} == entity.device_state_attributes
node.can_wake_up_value = False
entity.node_changed()
assert "wake_up_interval" not in entity.device_state_attributes | [
"async",
"def",
"test_node_changed",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"query_stage",
"=",
"\"Dynamic\"",
",",
"is_awake",
"=",
"True",
",",
"is_ready",
"=",
"False",
",",
"is_failed",
"=",
"False",
",",
"is_info_received",
"=",
"True",
",",
"max_baud_rate",
"=",
"40000",
",",
"is_zwave_plus",
"=",
"False",
",",
"capabilities",
"=",
"[",
"]",
",",
"neighbors",
"=",
"[",
"]",
",",
"location",
"=",
"None",
",",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"{",
"\"node_id\"",
":",
"node",
".",
"node_id",
",",
"\"node_name\"",
":",
"\"Mock Node\"",
",",
"\"manufacturer_name\"",
":",
"\"Test Manufacturer\"",
",",
"\"product_name\"",
":",
"\"Test Product\"",
",",
"}",
"==",
"entity",
".",
"device_state_attributes",
"node",
".",
"get_values",
".",
"return_value",
"=",
"{",
"1",
":",
"mock_zwave",
".",
"MockValue",
"(",
"data",
"=",
"1800",
")",
"}",
"zwave_network",
".",
"manager",
".",
"getNodeStatistics",
".",
"return_value",
"=",
"{",
"\"receivedCnt\"",
":",
"4",
",",
"\"ccData\"",
":",
"[",
"{",
"\"receivedCnt\"",
":",
"0",
",",
"\"commandClassId\"",
":",
"134",
",",
"\"sentCnt\"",
":",
"0",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"1",
",",
"\"commandClassId\"",
":",
"133",
",",
"\"sentCnt\"",
":",
"1",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"1",
",",
"\"commandClassId\"",
":",
"115",
",",
"\"sentCnt\"",
":",
"1",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"0",
",",
"\"commandClassId\"",
":",
"114",
",",
"\"sentCnt\"",
":",
"0",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"0",
",",
"\"commandClassId\"",
":",
"112",
",",
"\"sentCnt\"",
":",
"0",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"1",
",",
"\"commandClassId\"",
":",
"32",
",",
"\"sentCnt\"",
":",
"1",
"}",
",",
"{",
"\"receivedCnt\"",
":",
"0",
",",
"\"commandClassId\"",
":",
"0",
",",
"\"sentCnt\"",
":",
"0",
"}",
",",
"]",
",",
"\"receivedUnsolicited\"",
":",
"0",
",",
"\"sentTS\"",
":",
"\"2017-03-27 15:38:15:620 \"",
",",
"\"averageRequestRTT\"",
":",
"2462",
",",
"\"lastResponseRTT\"",
":",
"3679",
",",
"\"retries\"",
":",
"0",
",",
"\"sentFailed\"",
":",
"1",
",",
"\"sentCnt\"",
":",
"7",
",",
"\"quality\"",
":",
"0",
",",
"\"lastRequestRTT\"",
":",
"1591",
",",
"\"lastReceivedMessage\"",
":",
"[",
"0",
",",
"4",
",",
"0",
",",
"15",
",",
"3",
",",
"32",
",",
"3",
",",
"0",
",",
"221",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"0",
",",
"]",
",",
"\"receivedDups\"",
":",
"1",
",",
"\"averageResponseRTT\"",
":",
"2443",
",",
"\"receivedTS\"",
":",
"\"2017-03-27 15:38:19:298 \"",
",",
"}",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"{",
"\"node_id\"",
":",
"node",
".",
"node_id",
",",
"\"node_name\"",
":",
"\"Mock Node\"",
",",
"\"manufacturer_name\"",
":",
"\"Test Manufacturer\"",
",",
"\"product_name\"",
":",
"\"Test Product\"",
",",
"\"query_stage\"",
":",
"\"Dynamic\"",
",",
"\"is_awake\"",
":",
"True",
",",
"\"is_ready\"",
":",
"False",
",",
"\"is_failed\"",
":",
"False",
",",
"\"is_info_received\"",
":",
"True",
",",
"\"max_baud_rate\"",
":",
"40000",
",",
"\"is_zwave_plus\"",
":",
"False",
",",
"\"battery_level\"",
":",
"42",
",",
"\"wake_up_interval\"",
":",
"1800",
",",
"\"averageRequestRTT\"",
":",
"2462",
",",
"\"averageResponseRTT\"",
":",
"2443",
",",
"\"lastRequestRTT\"",
":",
"1591",
",",
"\"lastResponseRTT\"",
":",
"3679",
",",
"\"receivedCnt\"",
":",
"4",
",",
"\"receivedDups\"",
":",
"1",
",",
"\"receivedTS\"",
":",
"\"2017-03-27 15:38:19:298 \"",
",",
"\"receivedUnsolicited\"",
":",
"0",
",",
"\"retries\"",
":",
"0",
",",
"\"sentCnt\"",
":",
"7",
",",
"\"sentFailed\"",
":",
"1",
",",
"\"sentTS\"",
":",
"\"2017-03-27 15:38:15:620 \"",
",",
"}",
"==",
"entity",
".",
"device_state_attributes",
"node",
".",
"can_wake_up_value",
"=",
"False",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"\"wake_up_interval\"",
"not",
"in",
"entity",
".",
"device_state_attributes"
] | [
285,
0
] | [
622,
67
] | python | en | ['en', 'en', 'en'] | True |
test_name | (hass, mock_openzwave) | Test name property. | Test name property. | async def test_name(hass, mock_openzwave):
"""Test name property."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert entity.name == "Mock Node" | [
"async",
"def",
"test_name",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"entity",
".",
"name",
"==",
"\"Mock Node\""
] | [
625,
0
] | [
630,
37
] | python | en | ['en', 'en', 'en'] | True |
test_state_before_update | (hass, mock_openzwave) | Test state before update was called. | Test state before update was called. | async def test_state_before_update(hass, mock_openzwave):
"""Test state before update was called."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert entity.state is None | [
"async",
"def",
"test_state_before_update",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"entity",
".",
"state",
"is",
"None"
] | [
633,
0
] | [
638,
31
] | python | en | ['en', 'en', 'en'] | True |
test_state_not_ready | (hass, mock_openzwave) | Test state property. | Test state property. | async def test_state_not_ready(hass, mock_openzwave):
"""Test state property."""
zwave_network = MagicMock()
node = mock_zwave.MockNode(
query_stage="Dynamic",
is_awake=True,
is_ready=False,
is_failed=False,
is_info_received=True,
)
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
node.is_ready = False
entity.node_changed()
assert entity.state == "initializing"
node.is_failed = True
node.query_stage = "Complete"
entity.node_changed()
assert entity.state == "dead"
node.is_failed = False
node.is_awake = False
entity.node_changed()
assert entity.state == "sleeping" | [
"async",
"def",
"test_state_not_ready",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"query_stage",
"=",
"\"Dynamic\"",
",",
"is_awake",
"=",
"True",
",",
"is_ready",
"=",
"False",
",",
"is_failed",
"=",
"False",
",",
"is_info_received",
"=",
"True",
",",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"node",
".",
"is_ready",
"=",
"False",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"initializing\"",
"node",
".",
"is_failed",
"=",
"True",
"node",
".",
"query_stage",
"=",
"\"Complete\"",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"dead\"",
"node",
".",
"is_failed",
"=",
"False",
"node",
".",
"is_awake",
"=",
"False",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"sleeping\""
] | [
641,
0
] | [
665,
37
] | python | en | ['en', 'en', 'en'] | True |
test_state_ready | (hass, mock_openzwave) | Test state property. | Test state property. | async def test_state_ready(hass, mock_openzwave):
"""Test state property."""
zwave_network = MagicMock()
node = mock_zwave.MockNode(
query_stage="Dynamic",
is_awake=True,
is_ready=False,
is_failed=False,
is_info_received=True,
)
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
node.query_stage = "Complete"
node.is_ready = True
entity.node_changed()
await hass.async_block_till_done()
assert entity.state == "ready"
node.is_failed = True
entity.node_changed()
assert entity.state == "dead"
node.is_failed = False
node.is_awake = False
entity.node_changed()
assert entity.state == "sleeping" | [
"async",
"def",
"test_state_ready",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
"query_stage",
"=",
"\"Dynamic\"",
",",
"is_awake",
"=",
"True",
",",
"is_ready",
"=",
"False",
",",
"is_failed",
"=",
"False",
",",
"is_info_received",
"=",
"True",
",",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"node",
".",
"query_stage",
"=",
"\"Complete\"",
"node",
".",
"is_ready",
"=",
"True",
"entity",
".",
"node_changed",
"(",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"ready\"",
"node",
".",
"is_failed",
"=",
"True",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"dead\"",
"node",
".",
"is_failed",
"=",
"False",
"node",
".",
"is_awake",
"=",
"False",
"entity",
".",
"node_changed",
"(",
")",
"assert",
"entity",
".",
"state",
"==",
"\"sleeping\""
] | [
668,
0
] | [
693,
37
] | python | en | ['en', 'en', 'en'] | True |
test_not_polled | (hass, mock_openzwave) | Test should_poll property. | Test should_poll property. | async def test_not_polled(hass, mock_openzwave):
"""Test should_poll property."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert not entity.should_poll | [
"async",
"def",
"test_not_polled",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"not",
"entity",
".",
"should_poll"
] | [
696,
0
] | [
701,
33
] | python | en | ['en', 'en', 'en'] | True |
test_unique_id | (hass, mock_openzwave) | Test unique_id. | Test unique_id. | async def test_unique_id(hass, mock_openzwave):
"""Test unique_id."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert entity.unique_id == "node-567" | [
"async",
"def",
"test_unique_id",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"entity",
".",
"unique_id",
"==",
"\"node-567\""
] | [
704,
0
] | [
709,
41
] | python | en | ['fr', 'la', 'en'] | False |
test_unique_id_missing_data | (hass, mock_openzwave) | Test unique_id. | Test unique_id. | async def test_unique_id_missing_data(hass, mock_openzwave):
"""Test unique_id."""
zwave_network = MagicMock()
node = mock_zwave.MockNode()
node.manufacturer_name = None
node.name = None
node.is_ready = False
entity = node_entity.ZWaveNodeEntity(node, zwave_network)
assert entity.unique_id is None | [
"async",
"def",
"test_unique_id_missing_data",
"(",
"hass",
",",
"mock_openzwave",
")",
":",
"zwave_network",
"=",
"MagicMock",
"(",
")",
"node",
"=",
"mock_zwave",
".",
"MockNode",
"(",
")",
"node",
".",
"manufacturer_name",
"=",
"None",
"node",
".",
"name",
"=",
"None",
"node",
".",
"is_ready",
"=",
"False",
"entity",
"=",
"node_entity",
".",
"ZWaveNodeEntity",
"(",
"node",
",",
"zwave_network",
")",
"assert",
"entity",
".",
"unique_id",
"is",
"None"
] | [
712,
0
] | [
721,
35
] | python | en | ['fr', 'la', 'en'] | False |
new_simple_controller_config | (
config: dict = None,
options: dict = None,
config_source=ConfigSource.CONFIG_FLOW,
serial_number="1111",
devices: Tuple[pv.VeraDevice, ...] = (),
scenes: Tuple[pv.VeraScene, ...] = (),
setup_callback: SetupCallback = None,
legacy_entity_unique_id=False,
) | Create simple contorller config. | Create simple contorller config. | def new_simple_controller_config(
config: dict = None,
options: dict = None,
config_source=ConfigSource.CONFIG_FLOW,
serial_number="1111",
devices: Tuple[pv.VeraDevice, ...] = (),
scenes: Tuple[pv.VeraScene, ...] = (),
setup_callback: SetupCallback = None,
legacy_entity_unique_id=False,
) -> ControllerConfig:
"""Create simple contorller config."""
return ControllerConfig(
config=config or {CONF_CONTROLLER: "http://127.0.0.1:123"},
options=options,
config_source=config_source,
serial_number=serial_number,
devices=devices,
scenes=scenes,
setup_callback=setup_callback,
legacy_entity_unique_id=legacy_entity_unique_id,
) | [
"def",
"new_simple_controller_config",
"(",
"config",
":",
"dict",
"=",
"None",
",",
"options",
":",
"dict",
"=",
"None",
",",
"config_source",
"=",
"ConfigSource",
".",
"CONFIG_FLOW",
",",
"serial_number",
"=",
"\"1111\"",
",",
"devices",
":",
"Tuple",
"[",
"pv",
".",
"VeraDevice",
",",
"...",
"]",
"=",
"(",
")",
",",
"scenes",
":",
"Tuple",
"[",
"pv",
".",
"VeraScene",
",",
"...",
"]",
"=",
"(",
")",
",",
"setup_callback",
":",
"SetupCallback",
"=",
"None",
",",
"legacy_entity_unique_id",
"=",
"False",
",",
")",
"->",
"ControllerConfig",
":",
"return",
"ControllerConfig",
"(",
"config",
"=",
"config",
"or",
"{",
"CONF_CONTROLLER",
":",
"\"http://127.0.0.1:123\"",
"}",
",",
"options",
"=",
"options",
",",
"config_source",
"=",
"config_source",
",",
"serial_number",
"=",
"serial_number",
",",
"devices",
"=",
"devices",
",",
"scenes",
"=",
"scenes",
",",
"setup_callback",
"=",
"setup_callback",
",",
"legacy_entity_unique_id",
"=",
"legacy_entity_unique_id",
",",
")"
] | [
55,
0
] | [
75,
5
] | python | da | ['da', 'gl', 'en'] | False |
ComponentFactory.__init__ | (self, vera_controller_class_mock) | Initialize the factory. | Initialize the factory. | def __init__(self, vera_controller_class_mock):
"""Initialize the factory."""
self.vera_controller_class_mock = vera_controller_class_mock | [
"def",
"__init__",
"(",
"self",
",",
"vera_controller_class_mock",
")",
":",
"self",
".",
"vera_controller_class_mock",
"=",
"vera_controller_class_mock"
] | [
81,
4
] | [
83,
68
] | python | en | ['en', 'en', 'en'] | True |
ComponentFactory.configure_component | (
self,
hass: HomeAssistant,
controller_config: ControllerConfig = None,
controller_configs: Tuple[ControllerConfig] = (),
) | Configure the component with multiple specific mock data. | Configure the component with multiple specific mock data. | async def configure_component(
self,
hass: HomeAssistant,
controller_config: ControllerConfig = None,
controller_configs: Tuple[ControllerConfig] = (),
) -> ComponentData:
"""Configure the component with multiple specific mock data."""
configs = list(controller_configs)
if controller_config:
configs.append(controller_config)
return ComponentData(
controller_data=tuple(
[
await self._configure_component(hass, controller_config)
for controller_config in configs
]
)
) | [
"async",
"def",
"configure_component",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"controller_config",
":",
"ControllerConfig",
"=",
"None",
",",
"controller_configs",
":",
"Tuple",
"[",
"ControllerConfig",
"]",
"=",
"(",
")",
",",
")",
"->",
"ComponentData",
":",
"configs",
"=",
"list",
"(",
"controller_configs",
")",
"if",
"controller_config",
":",
"configs",
".",
"append",
"(",
"controller_config",
")",
"return",
"ComponentData",
"(",
"controller_data",
"=",
"tuple",
"(",
"[",
"await",
"self",
".",
"_configure_component",
"(",
"hass",
",",
"controller_config",
")",
"for",
"controller_config",
"in",
"configs",
"]",
")",
")"
] | [
85,
4
] | [
104,
9
] | python | en | ['en', 'en', 'en'] | True |
ComponentFactory._configure_component | (
self, hass: HomeAssistant, controller_config: ControllerConfig
) | Configure the component with specific mock data. | Configure the component with specific mock data. | async def _configure_component(
self, hass: HomeAssistant, controller_config: ControllerConfig
) -> ControllerData:
"""Configure the component with specific mock data."""
component_config = {
**(controller_config.config or {}),
**(controller_config.options or {}),
}
if controller_config.legacy_entity_unique_id:
component_config[CONF_LEGACY_UNIQUE_ID] = True
controller = MagicMock(spec=pv.VeraController) # type: pv.VeraController
controller.base_url = component_config.get(CONF_CONTROLLER)
controller.register = MagicMock()
controller.start = MagicMock()
controller.stop = MagicMock()
controller.refresh_data = MagicMock()
controller.temperature_units = "C"
controller.serial_number = controller_config.serial_number
controller.get_devices = MagicMock(return_value=controller_config.devices)
controller.get_scenes = MagicMock(return_value=controller_config.scenes)
for vera_obj in controller.get_devices() + controller.get_scenes():
vera_obj.vera_controller = controller
controller.get_devices.reset_mock()
controller.get_scenes.reset_mock()
if controller_config.setup_callback:
controller_config.setup_callback(controller)
self.vera_controller_class_mock.return_value = controller
hass_config = {}
# Setup component through config file import.
if controller_config.config_source == ConfigSource.FILE:
hass_config[DOMAIN] = component_config
# Setup Home Assistant.
assert await async_setup_component(hass, DOMAIN, hass_config)
await hass.async_block_till_done()
# Setup component through config flow.
if controller_config.config_source == ConfigSource.CONFIG_FLOW:
await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_USER},
data=component_config,
)
await hass.async_block_till_done()
# Setup component directly from config entry.
if controller_config.config_source == ConfigSource.CONFIG_ENTRY:
entry = MockConfigEntry(
domain=DOMAIN,
data=controller_config.config,
options=controller_config.options,
unique_id="12345",
)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
update_callback = (
controller.register.call_args_list[0][0][1]
if controller.register.call_args_list
else None
)
return ControllerData(controller=controller, update_callback=update_callback) | [
"async",
"def",
"_configure_component",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"controller_config",
":",
"ControllerConfig",
")",
"->",
"ControllerData",
":",
"component_config",
"=",
"{",
"*",
"*",
"(",
"controller_config",
".",
"config",
"or",
"{",
"}",
")",
",",
"*",
"*",
"(",
"controller_config",
".",
"options",
"or",
"{",
"}",
")",
",",
"}",
"if",
"controller_config",
".",
"legacy_entity_unique_id",
":",
"component_config",
"[",
"CONF_LEGACY_UNIQUE_ID",
"]",
"=",
"True",
"controller",
"=",
"MagicMock",
"(",
"spec",
"=",
"pv",
".",
"VeraController",
")",
"# type: pv.VeraController",
"controller",
".",
"base_url",
"=",
"component_config",
".",
"get",
"(",
"CONF_CONTROLLER",
")",
"controller",
".",
"register",
"=",
"MagicMock",
"(",
")",
"controller",
".",
"start",
"=",
"MagicMock",
"(",
")",
"controller",
".",
"stop",
"=",
"MagicMock",
"(",
")",
"controller",
".",
"refresh_data",
"=",
"MagicMock",
"(",
")",
"controller",
".",
"temperature_units",
"=",
"\"C\"",
"controller",
".",
"serial_number",
"=",
"controller_config",
".",
"serial_number",
"controller",
".",
"get_devices",
"=",
"MagicMock",
"(",
"return_value",
"=",
"controller_config",
".",
"devices",
")",
"controller",
".",
"get_scenes",
"=",
"MagicMock",
"(",
"return_value",
"=",
"controller_config",
".",
"scenes",
")",
"for",
"vera_obj",
"in",
"controller",
".",
"get_devices",
"(",
")",
"+",
"controller",
".",
"get_scenes",
"(",
")",
":",
"vera_obj",
".",
"vera_controller",
"=",
"controller",
"controller",
".",
"get_devices",
".",
"reset_mock",
"(",
")",
"controller",
".",
"get_scenes",
".",
"reset_mock",
"(",
")",
"if",
"controller_config",
".",
"setup_callback",
":",
"controller_config",
".",
"setup_callback",
"(",
"controller",
")",
"self",
".",
"vera_controller_class_mock",
".",
"return_value",
"=",
"controller",
"hass_config",
"=",
"{",
"}",
"# Setup component through config file import.",
"if",
"controller_config",
".",
"config_source",
"==",
"ConfigSource",
".",
"FILE",
":",
"hass_config",
"[",
"DOMAIN",
"]",
"=",
"component_config",
"# Setup Home Assistant.",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"hass_config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Setup component through config flow.",
"if",
"controller_config",
".",
"config_source",
"==",
"ConfigSource",
".",
"CONFIG_FLOW",
":",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
",",
"data",
"=",
"component_config",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Setup component directly from config entry.",
"if",
"controller_config",
".",
"config_source",
"==",
"ConfigSource",
".",
"CONFIG_ENTRY",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"controller_config",
".",
"config",
",",
"options",
"=",
"controller_config",
".",
"options",
",",
"unique_id",
"=",
"\"12345\"",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"update_callback",
"=",
"(",
"controller",
".",
"register",
".",
"call_args_list",
"[",
"0",
"]",
"[",
"0",
"]",
"[",
"1",
"]",
"if",
"controller",
".",
"register",
".",
"call_args_list",
"else",
"None",
")",
"return",
"ControllerData",
"(",
"controller",
"=",
"controller",
",",
"update_callback",
"=",
"update_callback",
")"
] | [
106,
4
] | [
178,
85
] | python | en | ['en', 'en', 'en'] | True |
test_open_cover_intent | (hass) | Test HassOpenCover intent. | Test HassOpenCover intent. | async def test_open_cover_intent(hass):
"""Test HassOpenCover intent."""
await cover_intent.async_setup_intents(hass)
hass.states.async_set("cover.garage_door", "closed")
calls = async_mock_service(hass, "cover", SERVICE_OPEN_COVER)
response = await intent.async_handle(
hass, "test", "HassOpenCover", {"name": {"value": "garage door"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Opened garage door"
assert len(calls) == 1
call = calls[0]
assert call.domain == "cover"
assert call.service == "open_cover"
assert call.data == {"entity_id": "cover.garage_door"} | [
"async",
"def",
"test_open_cover_intent",
"(",
"hass",
")",
":",
"await",
"cover_intent",
".",
"async_setup_intents",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"cover.garage_door\"",
",",
"\"closed\"",
")",
"calls",
"=",
"async_mock_service",
"(",
"hass",
",",
"\"cover\"",
",",
"SERVICE_OPEN_COVER",
")",
"response",
"=",
"await",
"intent",
".",
"async_handle",
"(",
"hass",
",",
"\"test\"",
",",
"\"HassOpenCover\"",
",",
"{",
"\"name\"",
":",
"{",
"\"value\"",
":",
"\"garage door\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"response",
".",
"speech",
"[",
"\"plain\"",
"]",
"[",
"\"speech\"",
"]",
"==",
"\"Opened garage door\"",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"call",
"=",
"calls",
"[",
"0",
"]",
"assert",
"call",
".",
"domain",
"==",
"\"cover\"",
"assert",
"call",
".",
"service",
"==",
"\"open_cover\"",
"assert",
"call",
".",
"data",
"==",
"{",
"\"entity_id\"",
":",
"\"cover.garage_door\"",
"}"
] | [
12,
0
] | [
29,
58
] | python | en | ['en', 'en', 'en'] | True |
test_close_cover_intent | (hass) | Test HassCloseCover intent. | Test HassCloseCover intent. | async def test_close_cover_intent(hass):
"""Test HassCloseCover intent."""
await cover_intent.async_setup_intents(hass)
hass.states.async_set("cover.garage_door", "open")
calls = async_mock_service(hass, "cover", SERVICE_CLOSE_COVER)
response = await intent.async_handle(
hass, "test", "HassCloseCover", {"name": {"value": "garage door"}}
)
await hass.async_block_till_done()
assert response.speech["plain"]["speech"] == "Closed garage door"
assert len(calls) == 1
call = calls[0]
assert call.domain == "cover"
assert call.service == "close_cover"
assert call.data == {"entity_id": "cover.garage_door"} | [
"async",
"def",
"test_close_cover_intent",
"(",
"hass",
")",
":",
"await",
"cover_intent",
".",
"async_setup_intents",
"(",
"hass",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"cover.garage_door\"",
",",
"\"open\"",
")",
"calls",
"=",
"async_mock_service",
"(",
"hass",
",",
"\"cover\"",
",",
"SERVICE_CLOSE_COVER",
")",
"response",
"=",
"await",
"intent",
".",
"async_handle",
"(",
"hass",
",",
"\"test\"",
",",
"\"HassCloseCover\"",
",",
"{",
"\"name\"",
":",
"{",
"\"value\"",
":",
"\"garage door\"",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"response",
".",
"speech",
"[",
"\"plain\"",
"]",
"[",
"\"speech\"",
"]",
"==",
"\"Closed garage door\"",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"call",
"=",
"calls",
"[",
"0",
"]",
"assert",
"call",
".",
"domain",
"==",
"\"cover\"",
"assert",
"call",
".",
"service",
"==",
"\"close_cover\"",
"assert",
"call",
".",
"data",
"==",
"{",
"\"entity_id\"",
":",
"\"cover.garage_door\"",
"}"
] | [
32,
0
] | [
49,
58
] | python | en | ['en', 'en', 'en'] | True |
async_get_actions | (hass: HomeAssistant, device_id: str) | List device actions for Cover devices. | List device actions for Cover devices. | async def async_get_actions(hass: HomeAssistant, device_id: str) -> List[dict]:
"""List device actions for Cover devices."""
registry = await entity_registry.async_get_registry(hass)
actions = []
# Get all the integrations entities for this device
for entry in entity_registry.async_entries_for_device(registry, device_id):
if entry.domain != DOMAIN:
continue
state = hass.states.get(entry.entity_id)
if not state or ATTR_SUPPORTED_FEATURES not in state.attributes:
continue
supported_features = state.attributes[ATTR_SUPPORTED_FEATURES]
# Add actions for each entity that belongs to this integration
if supported_features & SUPPORT_SET_POSITION:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "set_position",
}
)
else:
if supported_features & SUPPORT_OPEN:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "open",
}
)
if supported_features & SUPPORT_CLOSE:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "close",
}
)
if supported_features & SUPPORT_STOP:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "stop",
}
)
if supported_features & SUPPORT_SET_TILT_POSITION:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "set_tilt_position",
}
)
else:
if supported_features & SUPPORT_OPEN_TILT:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "open_tilt",
}
)
if supported_features & SUPPORT_CLOSE_TILT:
actions.append(
{
CONF_DEVICE_ID: device_id,
CONF_DOMAIN: DOMAIN,
CONF_ENTITY_ID: entry.entity_id,
CONF_TYPE: "close_tilt",
}
)
return actions | [
"async",
"def",
"async_get_actions",
"(",
"hass",
":",
"HomeAssistant",
",",
"device_id",
":",
"str",
")",
"->",
"List",
"[",
"dict",
"]",
":",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"actions",
"=",
"[",
"]",
"# Get all the integrations entities for this device",
"for",
"entry",
"in",
"entity_registry",
".",
"async_entries_for_device",
"(",
"registry",
",",
"device_id",
")",
":",
"if",
"entry",
".",
"domain",
"!=",
"DOMAIN",
":",
"continue",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"entry",
".",
"entity_id",
")",
"if",
"not",
"state",
"or",
"ATTR_SUPPORTED_FEATURES",
"not",
"in",
"state",
".",
"attributes",
":",
"continue",
"supported_features",
"=",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"# Add actions for each entity that belongs to this integration",
"if",
"supported_features",
"&",
"SUPPORT_SET_POSITION",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"set_position\"",
",",
"}",
")",
"else",
":",
"if",
"supported_features",
"&",
"SUPPORT_OPEN",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"open\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_CLOSE",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"close\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_STOP",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"stop\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_SET_TILT_POSITION",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"set_tilt_position\"",
",",
"}",
")",
"else",
":",
"if",
"supported_features",
"&",
"SUPPORT_OPEN_TILT",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"open_tilt\"",
",",
"}",
")",
"if",
"supported_features",
"&",
"SUPPORT_CLOSE_TILT",
":",
"actions",
".",
"append",
"(",
"{",
"CONF_DEVICE_ID",
":",
"device_id",
",",
"CONF_DOMAIN",
":",
"DOMAIN",
",",
"CONF_ENTITY_ID",
":",
"entry",
".",
"entity_id",
",",
"CONF_TYPE",
":",
"\"close_tilt\"",
",",
"}",
")",
"return",
"actions"
] | [
58,
0
] | [
142,
18
] | python | en | ['fr', 'en', 'en'] | True |
async_get_action_capabilities | (hass: HomeAssistant, config: dict) | List action capabilities. | List action capabilities. | async def async_get_action_capabilities(hass: HomeAssistant, config: dict) -> dict:
"""List action capabilities."""
if config[CONF_TYPE] not in POSITION_ACTION_TYPES:
return {}
return {
"extra_fields": vol.Schema(
{
vol.Optional("position", default=0): vol.All(
vol.Coerce(int), vol.Range(min=0, max=100)
)
}
)
} | [
"async",
"def",
"async_get_action_capabilities",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
"->",
"dict",
":",
"if",
"config",
"[",
"CONF_TYPE",
"]",
"not",
"in",
"POSITION_ACTION_TYPES",
":",
"return",
"{",
"}",
"return",
"{",
"\"extra_fields\"",
":",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Optional",
"(",
"\"position\"",
",",
"default",
"=",
"0",
")",
":",
"vol",
".",
"All",
"(",
"vol",
".",
"Coerce",
"(",
"int",
")",
",",
"vol",
".",
"Range",
"(",
"min",
"=",
"0",
",",
"max",
"=",
"100",
")",
")",
"}",
")",
"}"
] | [
145,
0
] | [
158,
5
] | python | en | ['ro', 'ga', 'en'] | False |
async_call_action_from_config | (
hass: HomeAssistant, config: dict, variables: dict, context: Optional[Context]
) | Execute a device action. | Execute a device action. | async def async_call_action_from_config(
hass: HomeAssistant, config: dict, variables: dict, context: Optional[Context]
) -> None:
"""Execute a device action."""
config = ACTION_SCHEMA(config)
service_data = {ATTR_ENTITY_ID: config[CONF_ENTITY_ID]}
if config[CONF_TYPE] == "open":
service = SERVICE_OPEN_COVER
elif config[CONF_TYPE] == "close":
service = SERVICE_CLOSE_COVER
elif config[CONF_TYPE] == "stop":
service = SERVICE_STOP_COVER
elif config[CONF_TYPE] == "open_tilt":
service = SERVICE_OPEN_COVER_TILT
elif config[CONF_TYPE] == "close_tilt":
service = SERVICE_CLOSE_COVER_TILT
elif config[CONF_TYPE] == "set_position":
service = SERVICE_SET_COVER_POSITION
service_data[ATTR_POSITION] = config["position"]
elif config[CONF_TYPE] == "set_tilt_position":
service = SERVICE_SET_COVER_TILT_POSITION
service_data[ATTR_TILT_POSITION] = config["position"]
await hass.services.async_call(
DOMAIN, service, service_data, blocking=True, context=context
) | [
"async",
"def",
"async_call_action_from_config",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
",",
"variables",
":",
"dict",
",",
"context",
":",
"Optional",
"[",
"Context",
"]",
")",
"->",
"None",
":",
"config",
"=",
"ACTION_SCHEMA",
"(",
"config",
")",
"service_data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"config",
"[",
"CONF_ENTITY_ID",
"]",
"}",
"if",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"open\"",
":",
"service",
"=",
"SERVICE_OPEN_COVER",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"close\"",
":",
"service",
"=",
"SERVICE_CLOSE_COVER",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"stop\"",
":",
"service",
"=",
"SERVICE_STOP_COVER",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"open_tilt\"",
":",
"service",
"=",
"SERVICE_OPEN_COVER_TILT",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"close_tilt\"",
":",
"service",
"=",
"SERVICE_CLOSE_COVER_TILT",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"set_position\"",
":",
"service",
"=",
"SERVICE_SET_COVER_POSITION",
"service_data",
"[",
"ATTR_POSITION",
"]",
"=",
"config",
"[",
"\"position\"",
"]",
"elif",
"config",
"[",
"CONF_TYPE",
"]",
"==",
"\"set_tilt_position\"",
":",
"service",
"=",
"SERVICE_SET_COVER_TILT_POSITION",
"service_data",
"[",
"ATTR_TILT_POSITION",
"]",
"=",
"config",
"[",
"\"position\"",
"]",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"service",
",",
"service_data",
",",
"blocking",
"=",
"True",
",",
"context",
"=",
"context",
")"
] | [
161,
0
] | [
188,
5
] | python | en | ['ro', 'en', 'en'] | True |
_assert_tensors_equal | (a, b, atol=1e-12, prefix="") | If tensors not close, or a and b arent both tensors, raise a nice Assertion error. | If tensors not close, or a and b arent both tensors, raise a nice Assertion error. | def _assert_tensors_equal(a, b, atol=1e-12, prefix=""):
"""If tensors not close, or a and b arent both tensors, raise a nice Assertion error."""
if a is None and b is None:
return True
try:
if tf.debugging.assert_near(a, b, atol=atol):
return True
raise
except Exception:
msg = "{} != {}".format(a, b)
if prefix:
msg = prefix + ": " + msg
raise AssertionError(msg) | [
"def",
"_assert_tensors_equal",
"(",
"a",
",",
"b",
",",
"atol",
"=",
"1e-12",
",",
"prefix",
"=",
"\"\"",
")",
":",
"if",
"a",
"is",
"None",
"and",
"b",
"is",
"None",
":",
"return",
"True",
"try",
":",
"if",
"tf",
".",
"debugging",
".",
"assert_near",
"(",
"a",
",",
"b",
",",
"atol",
"=",
"atol",
")",
":",
"return",
"True",
"raise",
"except",
"Exception",
":",
"msg",
"=",
"\"{} != {}\"",
".",
"format",
"(",
"a",
",",
"b",
")",
"if",
"prefix",
":",
"msg",
"=",
"prefix",
"+",
"\": \"",
"+",
"msg",
"raise",
"AssertionError",
"(",
"msg",
")"
] | [
373,
0
] | [
385,
33
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the iTunes platform. | Set up the iTunes platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the iTunes platform."""
add_entities(
[
ItunesDevice(
config.get(CONF_NAME),
config.get(CONF_HOST),
config.get(CONF_PORT),
config[CONF_SSL],
add_entities,
)
]
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"add_entities",
"(",
"[",
"ItunesDevice",
"(",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
",",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
",",
"config",
".",
"get",
"(",
"CONF_PORT",
")",
",",
"config",
"[",
"CONF_SSL",
"]",
",",
"add_entities",
",",
")",
"]",
")"
] | [
188,
0
] | [
200,
5
] | python | en | ['en', 'lb', 'en'] | True |
Itunes.__init__ | (self, host, port, use_ssl) | Initialize the iTunes device. | Initialize the iTunes device. | def __init__(self, host, port, use_ssl):
"""Initialize the iTunes device."""
self.host = host
self.port = port
self.use_ssl = use_ssl | [
"def",
"__init__",
"(",
"self",
",",
"host",
",",
"port",
",",
"use_ssl",
")",
":",
"self",
".",
"host",
"=",
"host",
"self",
".",
"port",
"=",
"port",
"self",
".",
"use_ssl",
"=",
"use_ssl"
] | [
67,
4
] | [
71,
30
] | python | en | ['en', 'en', 'en'] | True |
Itunes._base_url | (self) | Return the base URL for endpoints. | Return the base URL for endpoints. | def _base_url(self):
"""Return the base URL for endpoints."""
if self.use_ssl:
uri_scheme = "https://"
else:
uri_scheme = "http://"
if self.port:
return f"{uri_scheme}{self.host}:{self.port}"
return f"{uri_scheme}{self.host}" | [
"def",
"_base_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"use_ssl",
":",
"uri_scheme",
"=",
"\"https://\"",
"else",
":",
"uri_scheme",
"=",
"\"http://\"",
"if",
"self",
".",
"port",
":",
"return",
"f\"{uri_scheme}{self.host}:{self.port}\"",
"return",
"f\"{uri_scheme}{self.host}\""
] | [
74,
4
] | [
84,
41
] | python | en | ['en', 'en', 'en'] | True |
Itunes._request | (self, method, path, params=None) | Make the actual request and return the parsed response. | Make the actual request and return the parsed response. | def _request(self, method, path, params=None):
"""Make the actual request and return the parsed response."""
url = f"{self._base_url}{path}"
try:
if method == "GET":
response = requests.get(url, timeout=DEFAULT_TIMEOUT)
elif method == "POST":
response = requests.put(url, params, timeout=DEFAULT_TIMEOUT)
elif method == "PUT":
response = requests.put(url, params, timeout=DEFAULT_TIMEOUT)
elif method == "DELETE":
response = requests.delete(url, timeout=DEFAULT_TIMEOUT)
return response.json()
except requests.exceptions.HTTPError:
return {"player_state": "error"}
except requests.exceptions.RequestException:
return {"player_state": "offline"} | [
"def",
"_request",
"(",
"self",
",",
"method",
",",
"path",
",",
"params",
"=",
"None",
")",
":",
"url",
"=",
"f\"{self._base_url}{path}\"",
"try",
":",
"if",
"method",
"==",
"\"GET\"",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
")",
"elif",
"method",
"==",
"\"POST\"",
":",
"response",
"=",
"requests",
".",
"put",
"(",
"url",
",",
"params",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
")",
"elif",
"method",
"==",
"\"PUT\"",
":",
"response",
"=",
"requests",
".",
"put",
"(",
"url",
",",
"params",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
")",
"elif",
"method",
"==",
"\"DELETE\"",
":",
"response",
"=",
"requests",
".",
"delete",
"(",
"url",
",",
"timeout",
"=",
"DEFAULT_TIMEOUT",
")",
"return",
"response",
".",
"json",
"(",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
":",
"return",
"{",
"\"player_state\"",
":",
"\"error\"",
"}",
"except",
"requests",
".",
"exceptions",
".",
"RequestException",
":",
"return",
"{",
"\"player_state\"",
":",
"\"offline\"",
"}"
] | [
86,
4
] | [
104,
46
] | python | en | ['en', 'en', 'en'] | True |
Itunes._command | (self, named_command) | Make a request for a controlling command. | Make a request for a controlling command. | def _command(self, named_command):
"""Make a request for a controlling command."""
return self._request("PUT", f"/{named_command}") | [
"def",
"_command",
"(",
"self",
",",
"named_command",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"f\"/{named_command}\"",
")"
] | [
106,
4
] | [
108,
56
] | python | en | ['en', 'en', 'en'] | True |
Itunes.now_playing | (self) | Return the current state. | Return the current state. | def now_playing(self):
"""Return the current state."""
return self._request("GET", "/now_playing") | [
"def",
"now_playing",
"(",
"self",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"GET\"",
",",
"\"/now_playing\"",
")"
] | [
110,
4
] | [
112,
51
] | python | en | ['en', 'en', 'en'] | True |
Itunes.set_volume | (self, level) | Set the volume and returns the current state, level 0-100. | Set the volume and returns the current state, level 0-100. | def set_volume(self, level):
"""Set the volume and returns the current state, level 0-100."""
return self._request("PUT", "/volume", {"level": level}) | [
"def",
"set_volume",
"(",
"self",
",",
"level",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"\"/volume\"",
",",
"{",
"\"level\"",
":",
"level",
"}",
")"
] | [
114,
4
] | [
116,
64
] | python | en | ['en', 'en', 'en'] | True |
Itunes.set_muted | (self, muted) | Mute and returns the current state, muted True or False. | Mute and returns the current state, muted True or False. | def set_muted(self, muted):
"""Mute and returns the current state, muted True or False."""
return self._request("PUT", "/mute", {"muted": muted}) | [
"def",
"set_muted",
"(",
"self",
",",
"muted",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"\"/mute\"",
",",
"{",
"\"muted\"",
":",
"muted",
"}",
")"
] | [
118,
4
] | [
120,
62
] | python | en | ['en', 'en', 'en'] | True |
Itunes.set_shuffle | (self, shuffle) | Set the shuffle mode, shuffle True or False. | Set the shuffle mode, shuffle True or False. | def set_shuffle(self, shuffle):
"""Set the shuffle mode, shuffle True or False."""
return self._request(
"PUT", "/shuffle", {"mode": ("songs" if shuffle else "off")}
) | [
"def",
"set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"\"/shuffle\"",
",",
"{",
"\"mode\"",
":",
"(",
"\"songs\"",
"if",
"shuffle",
"else",
"\"off\"",
")",
"}",
")"
] | [
122,
4
] | [
126,
9
] | python | en | ['en', 'zh-Latn', 'en'] | True |
Itunes.play | (self) | Set playback to play and returns the current state. | Set playback to play and returns the current state. | def play(self):
"""Set playback to play and returns the current state."""
return self._command("play") | [
"def",
"play",
"(",
"self",
")",
":",
"return",
"self",
".",
"_command",
"(",
"\"play\"",
")"
] | [
128,
4
] | [
130,
36
] | python | en | ['en', 'en', 'en'] | True |
Itunes.pause | (self) | Set playback to paused and returns the current state. | Set playback to paused and returns the current state. | def pause(self):
"""Set playback to paused and returns the current state."""
return self._command("pause") | [
"def",
"pause",
"(",
"self",
")",
":",
"return",
"self",
".",
"_command",
"(",
"\"pause\"",
")"
] | [
132,
4
] | [
134,
37
] | python | en | ['en', 'en', 'en'] | True |
Itunes.next | (self) | Skip to the next track and returns the current state. | Skip to the next track and returns the current state. | def next(self):
"""Skip to the next track and returns the current state."""
return self._command("next") | [
"def",
"next",
"(",
"self",
")",
":",
"return",
"self",
".",
"_command",
"(",
"\"next\"",
")"
] | [
136,
4
] | [
138,
36
] | python | en | ['en', 'en', 'en'] | True |
Itunes.previous | (self) | Skip back and returns the current state. | Skip back and returns the current state. | def previous(self):
"""Skip back and returns the current state."""
return self._command("previous") | [
"def",
"previous",
"(",
"self",
")",
":",
"return",
"self",
".",
"_command",
"(",
"\"previous\"",
")"
] | [
140,
4
] | [
142,
40
] | python | en | ['en', 'en', 'en'] | True |
Itunes.stop | (self) | Stop playback and return the current state. | Stop playback and return the current state. | def stop(self):
"""Stop playback and return the current state."""
return self._command("stop") | [
"def",
"stop",
"(",
"self",
")",
":",
"return",
"self",
".",
"_command",
"(",
"\"stop\"",
")"
] | [
144,
4
] | [
146,
36
] | python | en | ['en', 'en', 'en'] | True |
Itunes.play_playlist | (self, playlist_id_or_name) | Set a playlist to be current and returns the current state. | Set a playlist to be current and returns the current state. | def play_playlist(self, playlist_id_or_name):
"""Set a playlist to be current and returns the current state."""
response = self._request("GET", "/playlists")
playlists = response.get("playlists", [])
found_playlists = [
playlist
for playlist in playlists
if (playlist_id_or_name in [playlist["name"], playlist["id"]])
]
if found_playlists:
playlist = found_playlists[0]
path = f"/playlists/{playlist['id']}/play"
return self._request("PUT", path) | [
"def",
"play_playlist",
"(",
"self",
",",
"playlist_id_or_name",
")",
":",
"response",
"=",
"self",
".",
"_request",
"(",
"\"GET\"",
",",
"\"/playlists\"",
")",
"playlists",
"=",
"response",
".",
"get",
"(",
"\"playlists\"",
",",
"[",
"]",
")",
"found_playlists",
"=",
"[",
"playlist",
"for",
"playlist",
"in",
"playlists",
"if",
"(",
"playlist_id_or_name",
"in",
"[",
"playlist",
"[",
"\"name\"",
"]",
",",
"playlist",
"[",
"\"id\"",
"]",
"]",
")",
"]",
"if",
"found_playlists",
":",
"playlist",
"=",
"found_playlists",
"[",
"0",
"]",
"path",
"=",
"f\"/playlists/{playlist['id']}/play\"",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"path",
")"
] | [
148,
4
] | [
162,
45
] | python | en | ['en', 'en', 'en'] | True |
Itunes.artwork_url | (self) | Return a URL of the current track's album art. | Return a URL of the current track's album art. | def artwork_url(self):
"""Return a URL of the current track's album art."""
return f"{self._base_url}/artwork" | [
"def",
"artwork_url",
"(",
"self",
")",
":",
"return",
"f\"{self._base_url}/artwork\""
] | [
164,
4
] | [
166,
42
] | python | en | ['en', 'en', 'en'] | True |
Itunes.airplay_devices | (self) | Return a list of AirPlay devices. | Return a list of AirPlay devices. | def airplay_devices(self):
"""Return a list of AirPlay devices."""
return self._request("GET", "/airplay_devices") | [
"def",
"airplay_devices",
"(",
"self",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"GET\"",
",",
"\"/airplay_devices\"",
")"
] | [
168,
4
] | [
170,
55
] | python | en | ['en', 'en', 'en'] | True |
Itunes.airplay_device | (self, device_id) | Return an AirPlay device. | Return an AirPlay device. | def airplay_device(self, device_id):
"""Return an AirPlay device."""
return self._request("GET", f"/airplay_devices/{device_id}") | [
"def",
"airplay_device",
"(",
"self",
",",
"device_id",
")",
":",
"return",
"self",
".",
"_request",
"(",
"\"GET\"",
",",
"f\"/airplay_devices/{device_id}\"",
")"
] | [
172,
4
] | [
174,
68
] | python | en | ['en', 'tg', 'en'] | True |
Itunes.toggle_airplay_device | (self, device_id, toggle) | Toggle airplay device on or off, id, toggle True or False. | Toggle airplay device on or off, id, toggle True or False. | def toggle_airplay_device(self, device_id, toggle):
"""Toggle airplay device on or off, id, toggle True or False."""
command = "on" if toggle else "off"
path = f"/airplay_devices/{device_id}/{command}"
return self._request("PUT", path) | [
"def",
"toggle_airplay_device",
"(",
"self",
",",
"device_id",
",",
"toggle",
")",
":",
"command",
"=",
"\"on\"",
"if",
"toggle",
"else",
"\"off\"",
"path",
"=",
"f\"/airplay_devices/{device_id}/{command}\"",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"path",
")"
] | [
176,
4
] | [
180,
41
] | python | en | ['en', 'en', 'en'] | True |
Itunes.set_volume_airplay_device | (self, device_id, level) | Set volume, returns current state of device, id,level 0-100. | Set volume, returns current state of device, id,level 0-100. | def set_volume_airplay_device(self, device_id, level):
"""Set volume, returns current state of device, id,level 0-100."""
path = f"/airplay_devices/{device_id}/volume"
return self._request("PUT", path, {"level": level}) | [
"def",
"set_volume_airplay_device",
"(",
"self",
",",
"device_id",
",",
"level",
")",
":",
"path",
"=",
"f\"/airplay_devices/{device_id}/volume\"",
"return",
"self",
".",
"_request",
"(",
"\"PUT\"",
",",
"path",
",",
"{",
"\"level\"",
":",
"level",
"}",
")"
] | [
182,
4
] | [
185,
59
] | python | en | ['nl', 'en', 'en'] | True |
ItunesDevice.__init__ | (self, name, host, port, use_ssl, add_entities) | Initialize the iTunes device. | Initialize the iTunes device. | def __init__(self, name, host, port, use_ssl, add_entities):
"""Initialize the iTunes device."""
self._name = name
self._host = host
self._port = port
self._use_ssl = use_ssl
self._add_entities = add_entities
self.client = Itunes(self._host, self._port, self._use_ssl)
self.current_volume = None
self.muted = None
self.shuffled = None
self.current_title = None
self.current_album = None
self.current_artist = None
self.current_playlist = None
self.content_id = None
self.player_state = None
self.airplay_devices = {}
self.update() | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"host",
",",
"port",
",",
"use_ssl",
",",
"add_entities",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_host",
"=",
"host",
"self",
".",
"_port",
"=",
"port",
"self",
".",
"_use_ssl",
"=",
"use_ssl",
"self",
".",
"_add_entities",
"=",
"add_entities",
"self",
".",
"client",
"=",
"Itunes",
"(",
"self",
".",
"_host",
",",
"self",
".",
"_port",
",",
"self",
".",
"_use_ssl",
")",
"self",
".",
"current_volume",
"=",
"None",
"self",
".",
"muted",
"=",
"None",
"self",
".",
"shuffled",
"=",
"None",
"self",
".",
"current_title",
"=",
"None",
"self",
".",
"current_album",
"=",
"None",
"self",
".",
"current_artist",
"=",
"None",
"self",
".",
"current_playlist",
"=",
"None",
"self",
".",
"content_id",
"=",
"None",
"self",
".",
"player_state",
"=",
"None",
"self",
".",
"airplay_devices",
"=",
"{",
"}",
"self",
".",
"update",
"(",
")"
] | [
206,
4
] | [
229,
21
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.update_state | (self, state_hash) | Update all the state properties with the passed in dictionary. | Update all the state properties with the passed in dictionary. | def update_state(self, state_hash):
"""Update all the state properties with the passed in dictionary."""
self.player_state = state_hash.get("player_state", None)
self.current_volume = state_hash.get("volume", 0)
self.muted = state_hash.get("muted", None)
self.current_title = state_hash.get("name", None)
self.current_album = state_hash.get("album", None)
self.current_artist = state_hash.get("artist", None)
self.current_playlist = state_hash.get("playlist", None)
self.content_id = state_hash.get("id", None)
_shuffle = state_hash.get("shuffle", None)
self.shuffled = _shuffle == "songs" | [
"def",
"update_state",
"(",
"self",
",",
"state_hash",
")",
":",
"self",
".",
"player_state",
"=",
"state_hash",
".",
"get",
"(",
"\"player_state\"",
",",
"None",
")",
"self",
".",
"current_volume",
"=",
"state_hash",
".",
"get",
"(",
"\"volume\"",
",",
"0",
")",
"self",
".",
"muted",
"=",
"state_hash",
".",
"get",
"(",
"\"muted\"",
",",
"None",
")",
"self",
".",
"current_title",
"=",
"state_hash",
".",
"get",
"(",
"\"name\"",
",",
"None",
")",
"self",
".",
"current_album",
"=",
"state_hash",
".",
"get",
"(",
"\"album\"",
",",
"None",
")",
"self",
".",
"current_artist",
"=",
"state_hash",
".",
"get",
"(",
"\"artist\"",
",",
"None",
")",
"self",
".",
"current_playlist",
"=",
"state_hash",
".",
"get",
"(",
"\"playlist\"",
",",
"None",
")",
"self",
".",
"content_id",
"=",
"state_hash",
".",
"get",
"(",
"\"id\"",
",",
"None",
")",
"_shuffle",
"=",
"state_hash",
".",
"get",
"(",
"\"shuffle\"",
",",
"None",
")",
"self",
".",
"shuffled",
"=",
"_shuffle",
"==",
"\"songs\""
] | [
231,
4
] | [
244,
43
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.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"
] | [
247,
4
] | [
249,
25
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.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.player_state == "offline" or self.player_state is None:
return "offline"
if self.player_state == "error":
return "error"
if self.player_state == "stopped":
return STATE_IDLE
if self.player_state == "paused":
return STATE_PAUSED
return STATE_PLAYING | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"player_state",
"==",
"\"offline\"",
"or",
"self",
".",
"player_state",
"is",
"None",
":",
"return",
"\"offline\"",
"if",
"self",
".",
"player_state",
"==",
"\"error\"",
":",
"return",
"\"error\"",
"if",
"self",
".",
"player_state",
"==",
"\"stopped\"",
":",
"return",
"STATE_IDLE",
"if",
"self",
".",
"player_state",
"==",
"\"paused\"",
":",
"return",
"STATE_PAUSED",
"return",
"STATE_PLAYING"
] | [
252,
4
] | [
266,
28
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.update | (self) | Retrieve latest state. | Retrieve latest state. | def update(self):
"""Retrieve latest state."""
now_playing = self.client.now_playing()
self.update_state(now_playing)
found_devices = self.client.airplay_devices()
found_devices = found_devices.get("airplay_devices", [])
new_devices = []
for device_data in found_devices:
device_id = device_data.get("id")
if self.airplay_devices.get(device_id):
# update it
airplay_device = self.airplay_devices.get(device_id)
airplay_device.update_state(device_data)
else:
# add it
airplay_device = AirPlayDevice(device_id, self.client)
airplay_device.update_state(device_data)
self.airplay_devices[device_id] = airplay_device
new_devices.append(airplay_device)
if new_devices:
self._add_entities(new_devices) | [
"def",
"update",
"(",
"self",
")",
":",
"now_playing",
"=",
"self",
".",
"client",
".",
"now_playing",
"(",
")",
"self",
".",
"update_state",
"(",
"now_playing",
")",
"found_devices",
"=",
"self",
".",
"client",
".",
"airplay_devices",
"(",
")",
"found_devices",
"=",
"found_devices",
".",
"get",
"(",
"\"airplay_devices\"",
",",
"[",
"]",
")",
"new_devices",
"=",
"[",
"]",
"for",
"device_data",
"in",
"found_devices",
":",
"device_id",
"=",
"device_data",
".",
"get",
"(",
"\"id\"",
")",
"if",
"self",
".",
"airplay_devices",
".",
"get",
"(",
"device_id",
")",
":",
"# update it",
"airplay_device",
"=",
"self",
".",
"airplay_devices",
".",
"get",
"(",
"device_id",
")",
"airplay_device",
".",
"update_state",
"(",
"device_data",
")",
"else",
":",
"# add it",
"airplay_device",
"=",
"AirPlayDevice",
"(",
"device_id",
",",
"self",
".",
"client",
")",
"airplay_device",
".",
"update_state",
"(",
"device_data",
")",
"self",
".",
"airplay_devices",
"[",
"device_id",
"]",
"=",
"airplay_device",
"new_devices",
".",
"append",
"(",
"airplay_device",
")",
"if",
"new_devices",
":",
"self",
".",
"_add_entities",
"(",
"new_devices",
")"
] | [
268,
4
] | [
293,
43
] | python | en | ['es', 'sk', 'en'] | False |
ItunesDevice.is_volume_muted | (self) | Boolean if volume is currently muted. | Boolean if volume is currently muted. | def is_volume_muted(self):
"""Boolean if volume is currently muted."""
return self.muted | [
"def",
"is_volume_muted",
"(",
"self",
")",
":",
"return",
"self",
".",
"muted"
] | [
296,
4
] | [
298,
25
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.volume_level | (self) | Volume level of the media player (0..1). | Volume level of the media player (0..1). | def volume_level(self):
"""Volume level of the media player (0..1)."""
return self.current_volume / 100.0 | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"self",
".",
"current_volume",
"/",
"100.0"
] | [
301,
4
] | [
303,
42
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_content_id | (self) | Content ID of current playing media. | Content ID of current playing media. | def media_content_id(self):
"""Content ID of current playing media."""
return self.content_id | [
"def",
"media_content_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"content_id"
] | [
306,
4
] | [
308,
30
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.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"
] | [
311,
4
] | [
313,
31
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.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.player_state in (STATE_PLAYING, STATE_IDLE, STATE_PAUSED)
and self.current_title is not None
):
return f"{self.client.artwork_url()}?id={self.content_id}"
return (
"https://cloud.githubusercontent.com/assets/260/9829355"
"/33fab972-58cf-11e5-8ea2-2ca74bdaae40.png"
) | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"player_state",
"in",
"(",
"STATE_PLAYING",
",",
"STATE_IDLE",
",",
"STATE_PAUSED",
")",
"and",
"self",
".",
"current_title",
"is",
"not",
"None",
")",
":",
"return",
"f\"{self.client.artwork_url()}?id={self.content_id}\"",
"return",
"(",
"\"https://cloud.githubusercontent.com/assets/260/9829355\"",
"\"/33fab972-58cf-11e5-8ea2-2ca74bdaae40.png\"",
")"
] | [
316,
4
] | [
327,
9
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_title | (self) | Title of current playing media. | Title of current playing media. | def media_title(self):
"""Title of current playing media."""
return self.current_title | [
"def",
"media_title",
"(",
"self",
")",
":",
"return",
"self",
".",
"current_title"
] | [
330,
4
] | [
332,
33
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_artist | (self) | Artist of current playing media (Music track only). | Artist of current playing media (Music track only). | def media_artist(self):
"""Artist of current playing media (Music track only)."""
return self.current_artist | [
"def",
"media_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"current_artist"
] | [
335,
4
] | [
337,
34
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_album_name | (self) | Album of current playing media (Music track only). | Album of current playing media (Music track only). | def media_album_name(self):
"""Album of current playing media (Music track only)."""
return self.current_album | [
"def",
"media_album_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"current_album"
] | [
340,
4
] | [
342,
33
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_playlist | (self) | Title of the currently playing playlist. | Title of the currently playing playlist. | def media_playlist(self):
"""Title of the currently playing playlist."""
return self.current_playlist | [
"def",
"media_playlist",
"(",
"self",
")",
":",
"return",
"self",
".",
"current_playlist"
] | [
345,
4
] | [
347,
36
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.shuffle | (self) | Boolean if shuffle is enabled. | Boolean if shuffle is enabled. | def shuffle(self):
"""Boolean if shuffle is enabled."""
return self.shuffled | [
"def",
"shuffle",
"(",
"self",
")",
":",
"return",
"self",
".",
"shuffled"
] | [
350,
4
] | [
352,
28
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_ITUNES | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_ITUNES"
] | [
355,
4
] | [
357,
29
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
response = self.client.set_volume(int(volume * 100))
self.update_state(response) | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"set_volume",
"(",
"int",
"(",
"volume",
"*",
"100",
")",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
359,
4
] | [
362,
35
] | python | en | ['fr', 'zu', 'en'] | False |
ItunesDevice.mute_volume | (self, mute) | Mute (true) or unmute (false) media player. | Mute (true) or unmute (false) media player. | def mute_volume(self, mute):
"""Mute (true) or unmute (false) media player."""
response = self.client.set_muted(mute)
self.update_state(response) | [
"def",
"mute_volume",
"(",
"self",
",",
"mute",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"set_muted",
"(",
"mute",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
364,
4
] | [
367,
35
] | python | en | ['en', 'la', 'it'] | False |
ItunesDevice.set_shuffle | (self, shuffle) | Shuffle (true) or no shuffle (false) media player. | Shuffle (true) or no shuffle (false) media player. | def set_shuffle(self, shuffle):
"""Shuffle (true) or no shuffle (false) media player."""
response = self.client.set_shuffle(shuffle)
self.update_state(response) | [
"def",
"set_shuffle",
"(",
"self",
",",
"shuffle",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"set_shuffle",
"(",
"shuffle",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
369,
4
] | [
372,
35
] | python | en | ['en', 'zh-Latn', 'en'] | True |
ItunesDevice.media_play | (self) | Send media_play command to media player. | Send media_play command to media player. | def media_play(self):
"""Send media_play command to media player."""
response = self.client.play()
self.update_state(response) | [
"def",
"media_play",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"play",
"(",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
374,
4
] | [
377,
35
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_pause | (self) | Send media_pause command to media player. | Send media_pause command to media player. | def media_pause(self):
"""Send media_pause command to media player."""
response = self.client.pause()
self.update_state(response) | [
"def",
"media_pause",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"pause",
"(",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
379,
4
] | [
382,
35
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_next_track | (self) | Send media_next command to media player. | Send media_next command to media player. | def media_next_track(self):
"""Send media_next command to media player."""
response = self.client.next() # pylint: disable=not-callable
self.update_state(response) | [
"def",
"media_next_track",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"next",
"(",
")",
"# pylint: disable=not-callable",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
384,
4
] | [
387,
35
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.media_previous_track | (self) | Send media_previous command media player. | Send media_previous command media player. | def media_previous_track(self):
"""Send media_previous command media player."""
response = self.client.previous()
self.update_state(response) | [
"def",
"media_previous_track",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"previous",
"(",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
389,
4
] | [
392,
35
] | python | en | ['en', 'pt', 'en'] | True |
ItunesDevice.play_media | (self, media_type, media_id, **kwargs) | Send the play_media command to the media player. | Send the play_media command to the media player. | def play_media(self, media_type, media_id, **kwargs):
"""Send the play_media command to the media player."""
if media_type == MEDIA_TYPE_PLAYLIST:
response = self.client.play_playlist(media_id)
self.update_state(response) | [
"def",
"play_media",
"(",
"self",
",",
"media_type",
",",
"media_id",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"media_type",
"==",
"MEDIA_TYPE_PLAYLIST",
":",
"response",
"=",
"self",
".",
"client",
".",
"play_playlist",
"(",
"media_id",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
394,
4
] | [
398,
39
] | python | en | ['en', 'en', 'en'] | True |
ItunesDevice.turn_off | (self) | Turn the media player off. | Turn the media player off. | def turn_off(self):
"""Turn the media player off."""
response = self.client.stop()
self.update_state(response) | [
"def",
"turn_off",
"(",
"self",
")",
":",
"response",
"=",
"self",
".",
"client",
".",
"stop",
"(",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
400,
4
] | [
403,
35
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.__init__ | (self, device_id, client) | Initialize the AirPlay device. | Initialize the AirPlay device. | def __init__(self, device_id, client):
"""Initialize the AirPlay device."""
self._id = device_id
self.client = client
self.device_name = "AirPlay"
self.kind = None
self.active = False
self.selected = False
self.volume = 0
self.supports_audio = False
self.supports_video = False
self.player_state = None | [
"def",
"__init__",
"(",
"self",
",",
"device_id",
",",
"client",
")",
":",
"self",
".",
"_id",
"=",
"device_id",
"self",
".",
"client",
"=",
"client",
"self",
".",
"device_name",
"=",
"\"AirPlay\"",
"self",
".",
"kind",
"=",
"None",
"self",
".",
"active",
"=",
"False",
"self",
".",
"selected",
"=",
"False",
"self",
".",
"volume",
"=",
"0",
"self",
".",
"supports_audio",
"=",
"False",
"self",
".",
"supports_video",
"=",
"False",
"self",
".",
"player_state",
"=",
"None"
] | [
409,
4
] | [
420,
32
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.update_state | (self, state_hash) | Update all the state properties with the passed in dictionary. | Update all the state properties with the passed in dictionary. | def update_state(self, state_hash):
"""Update all the state properties with the passed in dictionary."""
if "player_state" in state_hash:
self.player_state = state_hash.get("player_state", None)
if "name" in state_hash:
name = state_hash.get("name", "")
self.device_name = f"{name} AirTunes Speaker".strip()
if "kind" in state_hash:
self.kind = state_hash.get("kind", None)
if "active" in state_hash:
self.active = state_hash.get("active", None)
if "selected" in state_hash:
self.selected = state_hash.get("selected", None)
if "sound_volume" in state_hash:
self.volume = state_hash.get("sound_volume", 0)
if "supports_audio" in state_hash:
self.supports_audio = state_hash.get("supports_audio", None)
if "supports_video" in state_hash:
self.supports_video = state_hash.get("supports_video", None) | [
"def",
"update_state",
"(",
"self",
",",
"state_hash",
")",
":",
"if",
"\"player_state\"",
"in",
"state_hash",
":",
"self",
".",
"player_state",
"=",
"state_hash",
".",
"get",
"(",
"\"player_state\"",
",",
"None",
")",
"if",
"\"name\"",
"in",
"state_hash",
":",
"name",
"=",
"state_hash",
".",
"get",
"(",
"\"name\"",
",",
"\"\"",
")",
"self",
".",
"device_name",
"=",
"f\"{name} AirTunes Speaker\"",
".",
"strip",
"(",
")",
"if",
"\"kind\"",
"in",
"state_hash",
":",
"self",
".",
"kind",
"=",
"state_hash",
".",
"get",
"(",
"\"kind\"",
",",
"None",
")",
"if",
"\"active\"",
"in",
"state_hash",
":",
"self",
".",
"active",
"=",
"state_hash",
".",
"get",
"(",
"\"active\"",
",",
"None",
")",
"if",
"\"selected\"",
"in",
"state_hash",
":",
"self",
".",
"selected",
"=",
"state_hash",
".",
"get",
"(",
"\"selected\"",
",",
"None",
")",
"if",
"\"sound_volume\"",
"in",
"state_hash",
":",
"self",
".",
"volume",
"=",
"state_hash",
".",
"get",
"(",
"\"sound_volume\"",
",",
"0",
")",
"if",
"\"supports_audio\"",
"in",
"state_hash",
":",
"self",
".",
"supports_audio",
"=",
"state_hash",
".",
"get",
"(",
"\"supports_audio\"",
",",
"None",
")",
"if",
"\"supports_video\"",
"in",
"state_hash",
":",
"self",
".",
"supports_video",
"=",
"state_hash",
".",
"get",
"(",
"\"supports_video\"",
",",
"None",
")"
] | [
422,
4
] | [
447,
72
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.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.device_name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"device_name"
] | [
450,
4
] | [
452,
31
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
if self.selected is True:
return "mdi:volume-high"
return "mdi:volume-off" | [
"def",
"icon",
"(",
"self",
")",
":",
"if",
"self",
".",
"selected",
"is",
"True",
":",
"return",
"\"mdi:volume-high\"",
"return",
"\"mdi:volume-off\""
] | [
455,
4
] | [
460,
31
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.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.selected is True:
return STATE_ON
return STATE_OFF | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"selected",
"is",
"True",
":",
"return",
"STATE_ON",
"return",
"STATE_OFF"
] | [
463,
4
] | [
468,
24
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.update | (self) | Retrieve latest state. | Retrieve latest state. | def update(self):
"""Retrieve latest state.""" | [
"def",
"update",
"(",
"self",
")",
":"
] | [
470,
4
] | [
471,
36
] | python | en | ['es', 'sk', 'en'] | False |
AirPlayDevice.volume_level | (self) | Return the volume. | Return the volume. | def volume_level(self):
"""Return the volume."""
return float(self.volume) / 100.0 | [
"def",
"volume_level",
"(",
"self",
")",
":",
"return",
"float",
"(",
"self",
".",
"volume",
")",
"/",
"100.0"
] | [
474,
4
] | [
476,
41
] | python | en | ['en', 'no', 'en'] | True |
AirPlayDevice.media_content_type | (self) | Flag of media content that is supported. | Flag of media content that is supported. | def media_content_type(self):
"""Flag of media content that is supported."""
return MEDIA_TYPE_MUSIC | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"return",
"MEDIA_TYPE_MUSIC"
] | [
479,
4
] | [
481,
31
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
return SUPPORT_AIRPLAY | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_AIRPLAY"
] | [
484,
4
] | [
486,
30
] | python | en | ['en', 'en', 'en'] | True |
AirPlayDevice.set_volume_level | (self, volume) | Set volume level, range 0..1. | Set volume level, range 0..1. | def set_volume_level(self, volume):
"""Set volume level, range 0..1."""
volume = int(volume * 100)
response = self.client.set_volume_airplay_device(self._id, volume)
self.update_state(response) | [
"def",
"set_volume_level",
"(",
"self",
",",
"volume",
")",
":",
"volume",
"=",
"int",
"(",
"volume",
"*",
"100",
")",
"response",
"=",
"self",
".",
"client",
".",
"set_volume_airplay_device",
"(",
"self",
".",
"_id",
",",
"volume",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
488,
4
] | [
492,
35
] | python | en | ['fr', 'zu', 'en'] | False |
AirPlayDevice.turn_on | (self) | Select AirPlay. | Select AirPlay. | def turn_on(self):
"""Select AirPlay."""
self.update_state({"selected": True})
self.schedule_update_ha_state()
response = self.client.toggle_airplay_device(self._id, True)
self.update_state(response) | [
"def",
"turn_on",
"(",
"self",
")",
":",
"self",
".",
"update_state",
"(",
"{",
"\"selected\"",
":",
"True",
"}",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")",
"response",
"=",
"self",
".",
"client",
".",
"toggle_airplay_device",
"(",
"self",
".",
"_id",
",",
"True",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
494,
4
] | [
499,
35
] | python | en | ['en', 'en', 'en'] | False |
AirPlayDevice.turn_off | (self) | Deselect AirPlay. | Deselect AirPlay. | def turn_off(self):
"""Deselect AirPlay."""
self.update_state({"selected": False})
self.schedule_update_ha_state()
response = self.client.toggle_airplay_device(self._id, False)
self.update_state(response) | [
"def",
"turn_off",
"(",
"self",
")",
":",
"self",
".",
"update_state",
"(",
"{",
"\"selected\"",
":",
"False",
"}",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")",
"response",
"=",
"self",
".",
"client",
".",
"toggle_airplay_device",
"(",
"self",
".",
"_id",
",",
"False",
")",
"self",
".",
"update_state",
"(",
"response",
")"
] | [
501,
4
] | [
506,
35
] | python | en | ['en', 'en', 'en'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.