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 |
---|---|---|---|---|---|---|---|---|---|---|---|
KebaBinarySensor.device_state_attributes | (self) | Return the state attributes of the binary sensor. | Return the state attributes of the binary sensor. | def device_state_attributes(self):
"""Return the state attributes of the binary sensor."""
return self._attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_attributes"
] | [
73,
4
] | [
75,
31
] | python | en | ['en', 'en', 'en'] | True |
KebaBinarySensor.async_update | (self) | Get latest cached states from the device. | Get latest cached states from the device. | async def async_update(self):
"""Get latest cached states from the device."""
if self._key == "Online":
self._is_on = self._keba.get_value(self._key)
elif self._key == "Plug":
self._is_on = self._keba.get_value("Plug_plugged")
self._attributes["plugged_on_wallbox"] = self._keba.get_value(
"Plug_wallbox"
)
self._attributes["plug_locked"] = self._keba.get_value("Plug_locked")
self._attributes["plugged_on_EV"] = self._keba.get_value("Plug_EV")
elif self._key == "State":
self._is_on = self._keba.get_value("State_on")
self._attributes["status"] = self._keba.get_value("State_details")
self._attributes["max_charging_rate"] = str(
self._keba.get_value("Max curr")
)
elif self._key == "Tmo FS":
self._is_on = not self._keba.get_value("FS_on")
self._attributes["failsafe_timeout"] = str(self._keba.get_value("Tmo FS"))
self._attributes["fallback_current"] = str(self._keba.get_value("Curr FS"))
elif self._key == "Authreq":
self._is_on = self._keba.get_value(self._key) == 0 | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"if",
"self",
".",
"_key",
"==",
"\"Online\"",
":",
"self",
".",
"_is_on",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"self",
".",
"_key",
")",
"elif",
"self",
".",
"_key",
"==",
"\"Plug\"",
":",
"self",
".",
"_is_on",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Plug_plugged\"",
")",
"self",
".",
"_attributes",
"[",
"\"plugged_on_wallbox\"",
"]",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Plug_wallbox\"",
")",
"self",
".",
"_attributes",
"[",
"\"plug_locked\"",
"]",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Plug_locked\"",
")",
"self",
".",
"_attributes",
"[",
"\"plugged_on_EV\"",
"]",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Plug_EV\"",
")",
"elif",
"self",
".",
"_key",
"==",
"\"State\"",
":",
"self",
".",
"_is_on",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"State_on\"",
")",
"self",
".",
"_attributes",
"[",
"\"status\"",
"]",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"State_details\"",
")",
"self",
".",
"_attributes",
"[",
"\"max_charging_rate\"",
"]",
"=",
"str",
"(",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Max curr\"",
")",
")",
"elif",
"self",
".",
"_key",
"==",
"\"Tmo FS\"",
":",
"self",
".",
"_is_on",
"=",
"not",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"FS_on\"",
")",
"self",
".",
"_attributes",
"[",
"\"failsafe_timeout\"",
"]",
"=",
"str",
"(",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Tmo FS\"",
")",
")",
"self",
".",
"_attributes",
"[",
"\"fallback_current\"",
"]",
"=",
"str",
"(",
"self",
".",
"_keba",
".",
"get_value",
"(",
"\"Curr FS\"",
")",
")",
"elif",
"self",
".",
"_key",
"==",
"\"Authreq\"",
":",
"self",
".",
"_is_on",
"=",
"self",
".",
"_keba",
".",
"get_value",
"(",
"self",
".",
"_key",
")",
"==",
"0"
] | [
77,
4
] | [
102,
62
] | python | en | ['en', 'en', 'en'] | True |
KebaBinarySensor.update_callback | (self) | Schedule a state update. | Schedule a state update. | def update_callback(self):
"""Schedule a state update."""
self.async_schedule_update_ha_state(True) | [
"def",
"update_callback",
"(",
"self",
")",
":",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
104,
4
] | [
106,
49
] | python | en | ['en', 'co', 'en'] | True |
KebaBinarySensor.async_added_to_hass | (self) | Add update callback after being added to hass. | Add update callback after being added to hass. | async def async_added_to_hass(self):
"""Add update callback after being added to hass."""
self._keba.add_update_listener(self.update_callback) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"_keba",
".",
"add_update_listener",
"(",
"self",
".",
"update_callback",
")"
] | [
108,
4
] | [
110,
60
] | python | en | ['en', 'en', 'en'] | True |
test_platform_manually_configured | (hass) | Test that nothing happens when configuring unifi through device tracker platform. | Test that nothing happens when configuring unifi through device tracker platform. | async def test_platform_manually_configured(hass):
"""Test that nothing happens when configuring unifi through device tracker platform."""
assert (
await async_setup_component(
hass, TRACKER_DOMAIN, {TRACKER_DOMAIN: {"platform": UNIFI_DOMAIN}}
)
is False
)
assert UNIFI_DOMAIN not in hass.data | [
"async",
"def",
"test_platform_manually_configured",
"(",
"hass",
")",
":",
"assert",
"(",
"await",
"async_setup_component",
"(",
"hass",
",",
"TRACKER_DOMAIN",
",",
"{",
"TRACKER_DOMAIN",
":",
"{",
"\"platform\"",
":",
"UNIFI_DOMAIN",
"}",
"}",
")",
"is",
"False",
")",
"assert",
"UNIFI_DOMAIN",
"not",
"in",
"hass",
".",
"data"
] | [
152,
0
] | [
160,
40
] | python | en | ['en', 'en', 'en'] | True |
test_no_clients | (hass) | Test the update_clients function when no clients are found. | Test the update_clients function when no clients are found. | async def test_no_clients(hass):
"""Test the update_clients function when no clients are found."""
await setup_unifi_integration(hass)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 0 | [
"async",
"def",
"test_no_clients",
"(",
"hass",
")",
":",
"await",
"setup_unifi_integration",
"(",
"hass",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"0"
] | [
163,
0
] | [
167,
65
] | python | en | ['en', 'en', 'en'] | True |
test_tracked_wireless_clients | (hass) | Test the update_items function with some clients. | Test the update_items function with some clients. | async def test_tracked_wireless_clients(hass):
"""Test the update_items function with some clients."""
controller = await setup_unifi_integration(hass, clients_response=[CLIENT_1])
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "not_home"
# State change signalling works without events
client_1_copy = copy(CLIENT_1)
controller.api.websocket._data = {
"meta": {"message": MESSAGE_CLIENT},
"data": [client_1_copy],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
# State change signalling works with events
controller.api.websocket._data = {
"meta": {"message": MESSAGE_EVENT},
"data": [EVENT_CLIENT_1_WIRELESS_DISCONNECTED],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
async_fire_time_changed(hass, dt_util.utcnow() + controller.option_detection_time)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
controller.api.websocket._data = {
"meta": {"message": MESSAGE_EVENT},
"data": [EVENT_CLIENT_1_WIRELESS_CONNECTED],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home" | [
"async",
"def",
"test_tracked_wireless_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
"]",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"# State change signalling works without events",
"client_1_copy",
"=",
"copy",
"(",
"CLIENT_1",
")",
"controller",
".",
"api",
".",
"websocket",
".",
"_data",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_copy",
"]",
",",
"}",
"controller",
".",
"api",
".",
"session_handler",
"(",
"SIGNAL_DATA",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"# State change signalling works with events",
"controller",
".",
"api",
".",
"websocket",
".",
"_data",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_EVENT",
"}",
",",
"\"data\"",
":",
"[",
"EVENT_CLIENT_1_WIRELESS_DISCONNECTED",
"]",
",",
"}",
"controller",
".",
"api",
".",
"session_handler",
"(",
"SIGNAL_DATA",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"controller",
".",
"option_detection_time",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"controller",
".",
"api",
".",
"websocket",
".",
"_data",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_EVENT",
"}",
",",
"\"data\"",
":",
"[",
"EVENT_CLIENT_1_WIRELESS_CONNECTED",
"]",
",",
"}",
"controller",
".",
"api",
".",
"session_handler",
"(",
"SIGNAL_DATA",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\""
] | [
170,
0
] | [
216,
35
] | python | en | ['en', 'en', 'en'] | True |
test_tracked_clients | (hass) | Test the update_items function with some clients. | Test the update_items function with some clients. | async def test_tracked_clients(hass):
"""Test the update_items function with some clients."""
client_4_copy = copy(CLIENT_4)
client_4_copy["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
controller = await setup_unifi_integration(
hass,
options={CONF_SSID_FILTER: ["ssid"]},
clients_response=[CLIENT_1, CLIENT_2, CLIENT_3, CLIENT_5, client_4_copy],
known_wireless_clients=(CLIENT_4["mac"],),
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 4
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "not_home"
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
assert client_2.state == "not_home"
# Client on SSID not in SSID filter
client_3 = hass.states.get("device_tracker.client_3")
assert not client_3
# Wireless client with wired bug, if bug active on restart mark device away
client_4 = hass.states.get("device_tracker.client_4")
assert client_4 is not None
assert client_4.state == "not_home"
# A client that has never been seen should be marked away.
client_5 = hass.states.get("device_tracker.client_5")
assert client_5 is not None
assert client_5.state == "not_home"
# State change signalling works
client_1_copy = copy(CLIENT_1)
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_copy]}
controller.api.message_handler(event)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home" | [
"async",
"def",
"test_tracked_clients",
"(",
"hass",
")",
":",
"client_4_copy",
"=",
"copy",
"(",
"CLIENT_4",
")",
"client_4_copy",
"[",
"\"last_seen\"",
"]",
"=",
"dt_util",
".",
"as_timestamp",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
")",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_SSID_FILTER",
":",
"[",
"\"ssid\"",
"]",
"}",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
",",
"CLIENT_3",
",",
"CLIENT_5",
",",
"client_4_copy",
"]",
",",
"known_wireless_clients",
"=",
"(",
"CLIENT_4",
"[",
"\"mac\"",
"]",
",",
")",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"4",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"assert",
"client_2",
".",
"state",
"==",
"\"not_home\"",
"# Client on SSID not in SSID filter",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"not",
"client_3",
"# Wireless client with wired bug, if bug active on restart mark device away",
"client_4",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_4\"",
")",
"assert",
"client_4",
"is",
"not",
"None",
"assert",
"client_4",
".",
"state",
"==",
"\"not_home\"",
"# A client that has never been seen should be marked away.",
"client_5",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_5\"",
")",
"assert",
"client_5",
"is",
"not",
"None",
"assert",
"client_5",
".",
"state",
"==",
"\"not_home\"",
"# State change signalling works",
"client_1_copy",
"=",
"copy",
"(",
"CLIENT_1",
")",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\""
] | [
219,
0
] | [
261,
35
] | python | en | ['en', 'en', 'en'] | True |
test_tracked_devices | (hass) | Test the update_items function with some devices. | Test the update_items function with some devices. | async def test_tracked_devices(hass):
"""Test the update_items function with some devices."""
controller = await setup_unifi_integration(
hass,
devices_response=[DEVICE_1, DEVICE_2],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
device_1 = hass.states.get("device_tracker.device_1")
assert device_1
assert device_1.state == "home"
device_2 = hass.states.get("device_tracker.device_2")
assert device_2
assert device_2.state == "not_home"
# State change signalling work
device_1_copy = copy(DEVICE_1)
device_1_copy["next_interval"] = 20
event = {"meta": {"message": MESSAGE_DEVICE}, "data": [device_1_copy]}
controller.api.message_handler(event)
device_2_copy = copy(DEVICE_2)
device_2_copy["next_interval"] = 50
event = {"meta": {"message": MESSAGE_DEVICE}, "data": [device_2_copy]}
controller.api.message_handler(event)
await hass.async_block_till_done()
device_1 = hass.states.get("device_tracker.device_1")
assert device_1.state == "home"
device_2 = hass.states.get("device_tracker.device_2")
assert device_2.state == "home"
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=90))
await hass.async_block_till_done()
device_1 = hass.states.get("device_tracker.device_1")
assert device_1.state == "not_home"
device_2 = hass.states.get("device_tracker.device_2")
assert device_2.state == "home"
# Disabled device is unavailable
device_1_copy = copy(DEVICE_1)
device_1_copy["disabled"] = True
event = {"meta": {"message": MESSAGE_DEVICE}, "data": [device_1_copy]}
controller.api.message_handler(event)
await hass.async_block_till_done()
device_1 = hass.states.get("device_tracker.device_1")
assert device_1.state == STATE_UNAVAILABLE
# Update device registry when device is upgraded
device_2_copy = copy(DEVICE_2)
device_2_copy["version"] = EVENT_DEVICE_2_UPGRADED["version_to"]
message = {"meta": {"message": MESSAGE_DEVICE}, "data": [device_2_copy]}
controller.api.message_handler(message)
event = {"meta": {"message": MESSAGE_EVENT}, "data": [EVENT_DEVICE_2_UPGRADED]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Verify device registry has been updated
entity_registry = await hass.helpers.entity_registry.async_get_registry()
entry = entity_registry.async_get("device_tracker.device_2")
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(entry.device_id)
assert device.sw_version == EVENT_DEVICE_2_UPGRADED["version_to"] | [
"async",
"def",
"test_tracked_devices",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
",",
"DEVICE_2",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"assert",
"device_1",
".",
"state",
"==",
"\"home\"",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
"assert",
"device_2",
".",
"state",
"==",
"\"not_home\"",
"# State change signalling work",
"device_1_copy",
"=",
"copy",
"(",
"DEVICE_1",
")",
"device_1_copy",
"[",
"\"next_interval\"",
"]",
"=",
"20",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_DEVICE",
"}",
",",
"\"data\"",
":",
"[",
"device_1_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"device_2_copy",
"=",
"copy",
"(",
"DEVICE_2",
")",
"device_2_copy",
"[",
"\"next_interval\"",
"]",
"=",
"50",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_DEVICE",
"}",
",",
"\"data\"",
":",
"[",
"device_2_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
".",
"state",
"==",
"\"home\"",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
".",
"state",
"==",
"\"home\"",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"90",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
".",
"state",
"==",
"\"not_home\"",
"device_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_2\"",
")",
"assert",
"device_2",
".",
"state",
"==",
"\"home\"",
"# Disabled device is unavailable",
"device_1_copy",
"=",
"copy",
"(",
"DEVICE_1",
")",
"device_1_copy",
"[",
"\"disabled\"",
"]",
"=",
"True",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_DEVICE",
"}",
",",
"\"data\"",
":",
"[",
"device_1_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"# Update device registry when device is upgraded",
"device_2_copy",
"=",
"copy",
"(",
"DEVICE_2",
")",
"device_2_copy",
"[",
"\"version\"",
"]",
"=",
"EVENT_DEVICE_2_UPGRADED",
"[",
"\"version_to\"",
"]",
"message",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_DEVICE",
"}",
",",
"\"data\"",
":",
"[",
"device_2_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"message",
")",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_EVENT",
"}",
",",
"\"data\"",
":",
"[",
"EVENT_DEVICE_2_UPGRADED",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Verify device registry has been updated",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"device_tracker.device_2\"",
")",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device",
"=",
"device_registry",
".",
"async_get",
"(",
"entry",
".",
"device_id",
")",
"assert",
"device",
".",
"sw_version",
"==",
"EVENT_DEVICE_2_UPGRADED",
"[",
"\"version_to\"",
"]"
] | [
264,
0
] | [
328,
69
] | python | en | ['en', 'en', 'en'] | True |
test_remove_clients | (hass) | Test the remove_items function with some clients. | Test the remove_items function with some clients. | async def test_remove_clients(hass):
"""Test the remove_items function with some clients."""
controller = await setup_unifi_integration(
hass, clients_response=[CLIENT_1, CLIENT_2]
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
wired_client = hass.states.get("device_tracker.wired_client")
assert wired_client is not None
controller.api.websocket._data = {
"meta": {"message": MESSAGE_CLIENT_REMOVED},
"data": [CLIENT_1],
}
controller.api.session_handler(SIGNAL_DATA)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is None
wired_client = hass.states.get("device_tracker.wired_client")
assert wired_client is not None | [
"async",
"def",
"test_remove_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
"]",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"wired_client",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"wired_client",
"is",
"not",
"None",
"controller",
".",
"api",
".",
"websocket",
".",
"_data",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT_REMOVED",
"}",
",",
"\"data\"",
":",
"[",
"CLIENT_1",
"]",
",",
"}",
"controller",
".",
"api",
".",
"session_handler",
"(",
"SIGNAL_DATA",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"None",
"wired_client",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"wired_client",
"is",
"not",
"None"
] | [
331,
0
] | [
357,
35
] | python | en | ['en', 'en', 'en'] | True |
test_controller_state_change | (hass) | Verify entities state reflect on controller becoming unavailable. | Verify entities state reflect on controller becoming unavailable. | async def test_controller_state_change(hass):
"""Verify entities state reflect on controller becoming unavailable."""
controller = await setup_unifi_integration(
hass,
clients_response=[CLIENT_1],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
# Controller unavailable
controller.async_unifi_signalling_callback(
SIGNAL_CONNECTION_STATE, STATE_DISCONNECTED
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == STATE_UNAVAILABLE
device_1 = hass.states.get("device_tracker.device_1")
assert device_1.state == STATE_UNAVAILABLE
# Controller available
controller.async_unifi_signalling_callback(SIGNAL_CONNECTION_STATE, STATE_RUNNING)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
device_1 = hass.states.get("device_tracker.device_1")
assert device_1.state == "home" | [
"async",
"def",
"test_controller_state_change",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"# Controller unavailable",
"controller",
".",
"async_unifi_signalling_callback",
"(",
"SIGNAL_CONNECTION_STATE",
",",
"STATE_DISCONNECTED",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"# Controller available",
"controller",
".",
"async_unifi_signalling_callback",
"(",
"SIGNAL_CONNECTION_STATE",
",",
"STATE_RUNNING",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
".",
"state",
"==",
"\"home\""
] | [
360,
0
] | [
389,
35
] | python | en | ['en', 'en', 'en'] | True |
test_option_track_clients | (hass) | Test the tracking of clients can be turned off. | Test the tracking of clients can be turned off. | async def test_option_track_clients(hass):
"""Test the tracking of clients can be turned off."""
controller = await setup_unifi_integration(
hass,
clients_response=[CLIENT_1, CLIENT_2],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 3
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_CLIENTS: False},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_CLIENTS: True},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None | [
"async",
"def",
"test_option_track_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"3",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_CLIENTS",
":",
"False",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_CLIENTS",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
392,
0
] | [
438,
31
] | python | en | ['en', 'en', 'en'] | True |
test_option_track_wired_clients | (hass) | Test the tracking of wired clients can be turned off. | Test the tracking of wired clients can be turned off. | async def test_option_track_wired_clients(hass):
"""Test the tracking of wired clients can be turned off."""
controller = await setup_unifi_integration(
hass,
clients_response=[CLIENT_1, CLIENT_2],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 3
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_WIRED_CLIENTS: False},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_WIRED_CLIENTS: True},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None | [
"async",
"def",
"test_option_track_wired_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"3",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_WIRED_CLIENTS",
":",
"False",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_WIRED_CLIENTS",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
441,
0
] | [
487,
31
] | python | en | ['en', 'en', 'en'] | True |
test_option_track_devices | (hass) | Test the tracking of devices can be turned off. | Test the tracking of devices can be turned off. | async def test_option_track_devices(hass):
"""Test the tracking of devices can be turned off."""
controller = await setup_unifi_integration(
hass,
clients_response=[CLIENT_1, CLIENT_2],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 3
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_DEVICES: False},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_DEVICES: True},
)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None | [
"async",
"def",
"test_option_track_devices",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"3",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_DEVICES",
":",
"False",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_DEVICES",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
490,
0
] | [
536,
31
] | python | en | ['en', 'en', 'en'] | True |
test_option_ssid_filter | (hass) | Test the SSID filter works.
Client 1 will travel from a supported SSID to an unsupported ssid.
Client 3 will be removed on change of options since it is in an unsupported SSID.
| Test the SSID filter works. | async def test_option_ssid_filter(hass):
"""Test the SSID filter works.
Client 1 will travel from a supported SSID to an unsupported ssid.
Client 3 will be removed on change of options since it is in an unsupported SSID.
"""
client_1_copy = copy(CLIENT_1)
client_1_copy["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
controller = await setup_unifi_integration(
hass, clients_response=[client_1_copy, CLIENT_3]
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
client_3 = hass.states.get("device_tracker.client_3")
assert client_3
# Setting SSID filter will remove clients outside of filter
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_SSID_FILTER: ["ssid"]},
)
await hass.async_block_till_done()
# Not affected by SSID filter
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
# Removed due to SSID filter
client_3 = hass.states.get("device_tracker.client_3")
assert not client_3
# Roams to SSID outside of filter
client_1_copy = copy(CLIENT_1)
client_1_copy["essid"] = "other_ssid"
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_copy]}
controller.api.message_handler(event)
# Data update while SSID filter is in effect shouldn't create the client
client_3_copy = copy(CLIENT_3)
client_3_copy["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_3_copy]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# SSID filter marks client as away
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
# SSID still outside of filter
client_3 = hass.states.get("device_tracker.client_3")
assert not client_3
# Remove SSID filter
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_SSID_FILTER: []},
)
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_copy]}
controller.api.message_handler(event)
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_3_copy]}
controller.api.message_handler(event)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
client_3 = hass.states.get("device_tracker.client_3")
assert client_3.state == "home"
async_fire_time_changed(hass, dt_util.utcnow() + controller.option_detection_time)
await hass.async_block_till_done()
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
# Client won't go away until after next update
client_3 = hass.states.get("device_tracker.client_3")
assert client_3.state == "home"
# Trigger update to get client marked as away
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [CLIENT_3]}
controller.api.message_handler(event)
async_fire_time_changed(hass, dt_util.utcnow() + controller.option_detection_time)
await hass.async_block_till_done()
client_3 = hass.states.get("device_tracker.client_3")
assert client_3.state == "not_home" | [
"async",
"def",
"test_option_ssid_filter",
"(",
"hass",
")",
":",
"client_1_copy",
"=",
"copy",
"(",
"CLIENT_1",
")",
"client_1_copy",
"[",
"\"last_seen\"",
"]",
"=",
"dt_util",
".",
"as_timestamp",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
")",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"client_1_copy",
",",
"CLIENT_3",
"]",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"client_3",
"# Setting SSID filter will remove clients outside of filter",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_SSID_FILTER",
":",
"[",
"\"ssid\"",
"]",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Not affected by SSID filter",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"# Removed due to SSID filter",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"not",
"client_3",
"# Roams to SSID outside of filter",
"client_1_copy",
"=",
"copy",
"(",
"CLIENT_1",
")",
"client_1_copy",
"[",
"\"essid\"",
"]",
"=",
"\"other_ssid\"",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"# Data update while SSID filter is in effect shouldn't create the client",
"client_3_copy",
"=",
"copy",
"(",
"CLIENT_3",
")",
"client_3_copy",
"[",
"\"last_seen\"",
"]",
"=",
"dt_util",
".",
"as_timestamp",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
")",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_3_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# SSID filter marks client as away",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"# SSID still outside of filter",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"not",
"client_3",
"# Remove SSID filter",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_SSID_FILTER",
":",
"[",
"]",
"}",
",",
")",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_3_copy",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"client_3",
".",
"state",
"==",
"\"home\"",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"controller",
".",
"option_detection_time",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"# Client won't go away until after next update",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"client_3",
".",
"state",
"==",
"\"home\"",
"# Trigger update to get client marked as away",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"CLIENT_3",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"controller",
".",
"option_detection_time",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"client_3",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_3\"",
")",
"assert",
"client_3",
".",
"state",
"==",
"\"not_home\""
] | [
539,
0
] | [
628,
39
] | python | en | ['en', 'en', 'en'] | True |
test_wireless_client_go_wired_issue | (hass) | Test the solution to catch wireless device go wired UniFi issue.
UniFi has a known issue that when a wireless device goes away it sometimes gets marked as wired.
| Test the solution to catch wireless device go wired UniFi issue. | async def test_wireless_client_go_wired_issue(hass):
"""Test the solution to catch wireless device go wired UniFi issue.
UniFi has a known issue that when a wireless device goes away it sometimes gets marked as wired.
"""
client_1_client = copy(CLIENT_1)
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
controller = await setup_unifi_integration(hass, clients_response=[client_1_client])
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
# Client is wireless
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
# Trigger wired bug
client_1_client["is_wired"] = True
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Wired bug fix keeps client marked as wireless
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
# Pass time
async_fire_time_changed(hass, dt_util.utcnow() + controller.option_detection_time)
await hass.async_block_till_done()
# Marked as home according to the timer
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
assert client_1.attributes["is_wired"] is False
# Try to mark client as connected
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Make sure it don't go online again until wired bug disappears
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
assert client_1.attributes["is_wired"] is False
# Make client wireless
client_1_client["is_wired"] = False
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Client is no longer affected by wired bug and can be marked online
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False | [
"async",
"def",
"test_wireless_client_go_wired_issue",
"(",
"hass",
")",
":",
"client_1_client",
"=",
"copy",
"(",
"CLIENT_1",
")",
"client_1_client",
"[",
"\"last_seen\"",
"]",
"=",
"dt_util",
".",
"as_timestamp",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
")",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"clients_response",
"=",
"[",
"client_1_client",
"]",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"# Client is wireless",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False",
"# Trigger wired bug",
"client_1_client",
"[",
"\"is_wired\"",
"]",
"=",
"True",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Wired bug fix keeps client marked as wireless",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False",
"# Pass time",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"controller",
".",
"option_detection_time",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Marked as home according to the timer",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False",
"# Try to mark client as connected",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Make sure it don't go online again until wired bug disappears",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False",
"# Make client wireless",
"client_1_client",
"[",
"\"is_wired\"",
"]",
"=",
"False",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Client is no longer affected by wired bug and can be marked online",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False"
] | [
631,
0
] | [
687,
51
] | python | en | ['en', 'en', 'en'] | True |
test_option_ignore_wired_bug | (hass) | Test option to ignore wired bug. | Test option to ignore wired bug. | async def test_option_ignore_wired_bug(hass):
"""Test option to ignore wired bug."""
client_1_client = copy(CLIENT_1)
client_1_client["last_seen"] = dt_util.as_timestamp(dt_util.utcnow())
controller = await setup_unifi_integration(
hass, options={CONF_IGNORE_WIRED_BUG: True}, clients_response=[client_1_client]
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
# Client is wireless
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False
# Trigger wired bug
client_1_client["is_wired"] = True
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Wired bug in effect
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is True
# pass time
async_fire_time_changed(hass, dt_util.utcnow() + controller.option_detection_time)
await hass.async_block_till_done()
# Timer marks client as away
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "not_home"
assert client_1.attributes["is_wired"] is True
# Mark client as connected again
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Ignoring wired bug allows client to go home again even while affected
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is True
# Make client wireless
client_1_client["is_wired"] = False
event = {"meta": {"message": MESSAGE_CLIENT}, "data": [client_1_client]}
controller.api.message_handler(event)
await hass.async_block_till_done()
# Client is wireless and still connected
client_1 = hass.states.get("device_tracker.client_1")
assert client_1.state == "home"
assert client_1.attributes["is_wired"] is False | [
"async",
"def",
"test_option_ignore_wired_bug",
"(",
"hass",
")",
":",
"client_1_client",
"=",
"copy",
"(",
"CLIENT_1",
")",
"client_1_client",
"[",
"\"last_seen\"",
"]",
"=",
"dt_util",
".",
"as_timestamp",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
")",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_IGNORE_WIRED_BUG",
":",
"True",
"}",
",",
"clients_response",
"=",
"[",
"client_1_client",
"]",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"# Client is wireless",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False",
"# Trigger wired bug",
"client_1_client",
"[",
"\"is_wired\"",
"]",
"=",
"True",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Wired bug in effect",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"True",
"# pass time",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"controller",
".",
"option_detection_time",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Timer marks client as away",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"not_home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"True",
"# Mark client as connected again",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Ignoring wired bug allows client to go home again even while affected",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"True",
"# Make client wireless",
"client_1_client",
"[",
"\"is_wired\"",
"]",
"=",
"False",
"event",
"=",
"{",
"\"meta\"",
":",
"{",
"\"message\"",
":",
"MESSAGE_CLIENT",
"}",
",",
"\"data\"",
":",
"[",
"client_1_client",
"]",
"}",
"controller",
".",
"api",
".",
"message_handler",
"(",
"event",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Client is wireless and still connected",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
".",
"state",
"==",
"\"home\"",
"assert",
"client_1",
".",
"attributes",
"[",
"\"is_wired\"",
"]",
"is",
"False"
] | [
690,
0
] | [
745,
51
] | python | en | ['en', 'en', 'en'] | True |
test_restoring_client | (hass) | Test the update_items function with some clients. | Test the update_items function with some clients. | async def test_restoring_client(hass):
"""Test the update_items function with some clients."""
config_entry = config_entries.ConfigEntry(
version=1,
domain=UNIFI_DOMAIN,
title="Mock Title",
data=ENTRY_CONFIG,
source="test",
connection_class=config_entries.CONN_CLASS_LOCAL_POLL,
system_options={},
options={},
entry_id=1,
)
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
TRACKER_DOMAIN,
UNIFI_DOMAIN,
f'{CLIENT_1["mac"]}-site_id',
suggested_object_id=CLIENT_1["hostname"],
config_entry=config_entry,
)
registry.async_get_or_create(
TRACKER_DOMAIN,
UNIFI_DOMAIN,
f'{CLIENT_2["mac"]}-site_id',
suggested_object_id=CLIENT_2["hostname"],
config_entry=config_entry,
)
await setup_unifi_integration(
hass,
options={CONF_BLOCK_CLIENT: True},
clients_response=[CLIENT_2],
clients_all_response=[CLIENT_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
device_1 = hass.states.get("device_tracker.client_1")
assert device_1 is not None | [
"async",
"def",
"test_restoring_client",
"(",
"hass",
")",
":",
"config_entry",
"=",
"config_entries",
".",
"ConfigEntry",
"(",
"version",
"=",
"1",
",",
"domain",
"=",
"UNIFI_DOMAIN",
",",
"title",
"=",
"\"Mock Title\"",
",",
"data",
"=",
"ENTRY_CONFIG",
",",
"source",
"=",
"\"test\"",
",",
"connection_class",
"=",
"config_entries",
".",
"CONN_CLASS_LOCAL_POLL",
",",
"system_options",
"=",
"{",
"}",
",",
"options",
"=",
"{",
"}",
",",
"entry_id",
"=",
"1",
",",
")",
"registry",
"=",
"await",
"entity_registry",
".",
"async_get_registry",
"(",
"hass",
")",
"registry",
".",
"async_get_or_create",
"(",
"TRACKER_DOMAIN",
",",
"UNIFI_DOMAIN",
",",
"f'{CLIENT_1[\"mac\"]}-site_id'",
",",
"suggested_object_id",
"=",
"CLIENT_1",
"[",
"\"hostname\"",
"]",
",",
"config_entry",
"=",
"config_entry",
",",
")",
"registry",
".",
"async_get_or_create",
"(",
"TRACKER_DOMAIN",
",",
"UNIFI_DOMAIN",
",",
"f'{CLIENT_2[\"mac\"]}-site_id'",
",",
"suggested_object_id",
"=",
"CLIENT_2",
"[",
"\"hostname\"",
"]",
",",
"config_entry",
"=",
"config_entry",
",",
")",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_BLOCK_CLIENT",
":",
"True",
"}",
",",
"clients_response",
"=",
"[",
"CLIENT_2",
"]",
",",
"clients_all_response",
"=",
"[",
"CLIENT_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
748,
0
] | [
787,
31
] | python | en | ['en', 'en', 'en'] | True |
test_dont_track_clients | (hass) | Test don't track clients config works. | Test don't track clients config works. | async def test_dont_track_clients(hass):
"""Test don't track clients config works."""
controller = await setup_unifi_integration(
hass,
options={CONF_TRACK_CLIENTS: False},
clients_response=[CLIENT_1],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_CLIENTS: True},
)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None | [
"async",
"def",
"test_dont_track_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_TRACK_CLIENTS",
":",
"False",
"}",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_CLIENTS",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
790,
0
] | [
818,
31
] | python | en | ['nl', 'en', 'en'] | True |
test_dont_track_devices | (hass) | Test don't track devices config works. | Test don't track devices config works. | async def test_dont_track_devices(hass):
"""Test don't track devices config works."""
controller = await setup_unifi_integration(
hass,
options={CONF_TRACK_DEVICES: False},
clients_response=[CLIENT_1],
devices_response=[DEVICE_1],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_DEVICES: True},
)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
device_1 = hass.states.get("device_tracker.device_1")
assert device_1 is not None | [
"async",
"def",
"test_dont_track_devices",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_TRACK_DEVICES",
":",
"False",
"}",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
"]",
",",
"devices_response",
"=",
"[",
"DEVICE_1",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_DEVICES",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"device_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.device_1\"",
")",
"assert",
"device_1",
"is",
"not",
"None"
] | [
821,
0
] | [
849,
31
] | python | en | ['nl', 'en', 'en'] | True |
test_dont_track_wired_clients | (hass) | Test don't track wired clients config works. | Test don't track wired clients config works. | async def test_dont_track_wired_clients(hass):
"""Test don't track wired clients config works."""
controller = await setup_unifi_integration(
hass,
options={CONF_TRACK_WIRED_CLIENTS: False},
clients_response=[CLIENT_1, CLIENT_2],
)
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 1
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is None
hass.config_entries.async_update_entry(
controller.config_entry,
options={CONF_TRACK_WIRED_CLIENTS: True},
)
await hass.async_block_till_done()
assert len(hass.states.async_entity_ids(TRACKER_DOMAIN)) == 2
client_1 = hass.states.get("device_tracker.client_1")
assert client_1 is not None
client_2 = hass.states.get("device_tracker.wired_client")
assert client_2 is not None | [
"async",
"def",
"test_dont_track_wired_clients",
"(",
"hass",
")",
":",
"controller",
"=",
"await",
"setup_unifi_integration",
"(",
"hass",
",",
"options",
"=",
"{",
"CONF_TRACK_WIRED_CLIENTS",
":",
"False",
"}",
",",
"clients_response",
"=",
"[",
"CLIENT_1",
",",
"CLIENT_2",
"]",
",",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"1",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"None",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"controller",
".",
"config_entry",
",",
"options",
"=",
"{",
"CONF_TRACK_WIRED_CLIENTS",
":",
"True",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
"TRACKER_DOMAIN",
")",
")",
"==",
"2",
"client_1",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.client_1\"",
")",
"assert",
"client_1",
"is",
"not",
"None",
"client_2",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"device_tracker.wired_client\"",
")",
"assert",
"client_2",
"is",
"not",
"None"
] | [
852,
0
] | [
879,
31
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, base_config) | Set up the Supla component. | Set up the Supla component. | async def async_setup(hass, base_config):
"""Set up the Supla component."""
server_confs = base_config[DOMAIN][CONF_SERVERS]
hass.data[DOMAIN] = {SUPLA_SERVERS: {}, SUPLA_COORDINATORS: {}}
session = async_get_clientsession(hass)
for server_conf in server_confs:
server_address = server_conf[CONF_SERVER]
server = SuplaAPI(server_address, server_conf[CONF_ACCESS_TOKEN], session)
# Test connection
try:
srv_info = await server.get_server_info()
if srv_info.get("authenticated"):
hass.data[DOMAIN][SUPLA_SERVERS][server_conf[CONF_SERVER]] = server
else:
_LOGGER.error(
"Server: %s not configured. API call returned: %s",
server_address,
srv_info,
)
return False
except OSError:
_LOGGER.exception(
"Server: %s not configured. Error on Supla API access: ", server_address
)
return False
await discover_devices(hass, base_config)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"base_config",
")",
":",
"server_confs",
"=",
"base_config",
"[",
"DOMAIN",
"]",
"[",
"CONF_SERVERS",
"]",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"{",
"SUPLA_SERVERS",
":",
"{",
"}",
",",
"SUPLA_COORDINATORS",
":",
"{",
"}",
"}",
"session",
"=",
"async_get_clientsession",
"(",
"hass",
")",
"for",
"server_conf",
"in",
"server_confs",
":",
"server_address",
"=",
"server_conf",
"[",
"CONF_SERVER",
"]",
"server",
"=",
"SuplaAPI",
"(",
"server_address",
",",
"server_conf",
"[",
"CONF_ACCESS_TOKEN",
"]",
",",
"session",
")",
"# Test connection",
"try",
":",
"srv_info",
"=",
"await",
"server",
".",
"get_server_info",
"(",
")",
"if",
"srv_info",
".",
"get",
"(",
"\"authenticated\"",
")",
":",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"SUPLA_SERVERS",
"]",
"[",
"server_conf",
"[",
"CONF_SERVER",
"]",
"]",
"=",
"server",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Server: %s not configured. API call returned: %s\"",
",",
"server_address",
",",
"srv_info",
",",
")",
"return",
"False",
"except",
"OSError",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Server: %s not configured. Error on Supla API access: \"",
",",
"server_address",
")",
"return",
"False",
"await",
"discover_devices",
"(",
"hass",
",",
"base_config",
")",
"return",
"True"
] | [
52,
0
] | [
88,
15
] | python | en | ['en', 'en', 'en'] | True |
discover_devices | (hass, hass_config) |
Run periodically to discover new devices.
Currently it is only run at startup.
|
Run periodically to discover new devices. | async def discover_devices(hass, hass_config):
"""
Run periodically to discover new devices.
Currently it is only run at startup.
"""
component_configs = {}
for server_name, server in hass.data[DOMAIN][SUPLA_SERVERS].items():
async def _fetch_channels():
async with async_timeout.timeout(SCAN_INTERVAL.total_seconds()):
channels = {
channel["id"]: channel
for channel in await server.get_channels(
include=["iodevice", "state", "connected"]
)
}
return channels
coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name=f"{DOMAIN}-{server_name}",
update_method=_fetch_channels,
update_interval=SCAN_INTERVAL,
)
await coordinator.async_refresh()
hass.data[DOMAIN][SUPLA_COORDINATORS][server_name] = coordinator
for channel_id, channel in coordinator.data.items():
channel_function = channel["function"]["name"]
if channel_function == SUPLA_FUNCTION_NONE:
_LOGGER.debug(
"Ignored function: %s, channel id: %s",
channel_function,
channel["id"],
)
continue
component_name = SUPLA_FUNCTION_HA_CMP_MAP.get(channel_function)
if component_name is None:
_LOGGER.warning(
"Unsupported function: %s, channel id: %s",
channel_function,
channel["id"],
)
continue
channel["server_name"] = server_name
component_configs.setdefault(component_name, []).append(
{
"channel_id": channel_id,
"server_name": server_name,
"function_name": channel["function"]["name"],
}
)
# Load discovered devices
for component_name, config in component_configs.items():
await async_load_platform(hass, component_name, DOMAIN, config, hass_config) | [
"async",
"def",
"discover_devices",
"(",
"hass",
",",
"hass_config",
")",
":",
"component_configs",
"=",
"{",
"}",
"for",
"server_name",
",",
"server",
"in",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"SUPLA_SERVERS",
"]",
".",
"items",
"(",
")",
":",
"async",
"def",
"_fetch_channels",
"(",
")",
":",
"async",
"with",
"async_timeout",
".",
"timeout",
"(",
"SCAN_INTERVAL",
".",
"total_seconds",
"(",
")",
")",
":",
"channels",
"=",
"{",
"channel",
"[",
"\"id\"",
"]",
":",
"channel",
"for",
"channel",
"in",
"await",
"server",
".",
"get_channels",
"(",
"include",
"=",
"[",
"\"iodevice\"",
",",
"\"state\"",
",",
"\"connected\"",
"]",
")",
"}",
"return",
"channels",
"coordinator",
"=",
"DataUpdateCoordinator",
"(",
"hass",
",",
"_LOGGER",
",",
"name",
"=",
"f\"{DOMAIN}-{server_name}\"",
",",
"update_method",
"=",
"_fetch_channels",
",",
"update_interval",
"=",
"SCAN_INTERVAL",
",",
")",
"await",
"coordinator",
".",
"async_refresh",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"SUPLA_COORDINATORS",
"]",
"[",
"server_name",
"]",
"=",
"coordinator",
"for",
"channel_id",
",",
"channel",
"in",
"coordinator",
".",
"data",
".",
"items",
"(",
")",
":",
"channel_function",
"=",
"channel",
"[",
"\"function\"",
"]",
"[",
"\"name\"",
"]",
"if",
"channel_function",
"==",
"SUPLA_FUNCTION_NONE",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Ignored function: %s, channel id: %s\"",
",",
"channel_function",
",",
"channel",
"[",
"\"id\"",
"]",
",",
")",
"continue",
"component_name",
"=",
"SUPLA_FUNCTION_HA_CMP_MAP",
".",
"get",
"(",
"channel_function",
")",
"if",
"component_name",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unsupported function: %s, channel id: %s\"",
",",
"channel_function",
",",
"channel",
"[",
"\"id\"",
"]",
",",
")",
"continue",
"channel",
"[",
"\"server_name\"",
"]",
"=",
"server_name",
"component_configs",
".",
"setdefault",
"(",
"component_name",
",",
"[",
"]",
")",
".",
"append",
"(",
"{",
"\"channel_id\"",
":",
"channel_id",
",",
"\"server_name\"",
":",
"server_name",
",",
"\"function_name\"",
":",
"channel",
"[",
"\"function\"",
"]",
"[",
"\"name\"",
"]",
",",
"}",
")",
"# Load discovered devices",
"for",
"component_name",
",",
"config",
"in",
"component_configs",
".",
"items",
"(",
")",
":",
"await",
"async_load_platform",
"(",
"hass",
",",
"component_name",
",",
"DOMAIN",
",",
"config",
",",
"hass_config",
")"
] | [
91,
0
] | [
155,
84
] | python | en | ['en', 'error', 'th'] | False |
SuplaChannel.__init__ | (self, config, server, coordinator) | Init from config, hookup[ server and coordinator. | Init from config, hookup[ server and coordinator. | def __init__(self, config, server, coordinator):
"""Init from config, hookup[ server and coordinator."""
super().__init__(coordinator)
self.server_name = config["server_name"]
self.channel_id = config["channel_id"]
self.server = server | [
"def",
"__init__",
"(",
"self",
",",
"config",
",",
"server",
",",
"coordinator",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"server_name",
"=",
"config",
"[",
"\"server_name\"",
"]",
"self",
".",
"channel_id",
"=",
"config",
"[",
"\"channel_id\"",
"]",
"self",
".",
"server",
"=",
"server"
] | [
161,
4
] | [
166,
28
] | python | en | ['en', 'en', 'en'] | True |
SuplaChannel.channel_data | (self) | Return channel data taken from coordinator. | Return channel data taken from coordinator. | def channel_data(self):
"""Return channel data taken from coordinator."""
return self.coordinator.data.get(self.channel_id) | [
"def",
"channel_data",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
".",
"get",
"(",
"self",
".",
"channel_id",
")"
] | [
169,
4
] | [
171,
57
] | python | en | ['en', 'de', 'en'] | True |
SuplaChannel.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return "supla-{}-{}".format(
self.channel_data["iodevice"]["gUIDString"].lower(),
self.channel_data["channelNumber"],
) | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"supla-{}-{}\"",
".",
"format",
"(",
"self",
".",
"channel_data",
"[",
"\"iodevice\"",
"]",
"[",
"\"gUIDString\"",
"]",
".",
"lower",
"(",
")",
",",
"self",
".",
"channel_data",
"[",
"\"channelNumber\"",
"]",
",",
")"
] | [
174,
4
] | [
179,
9
] | python | ca | ['fr', 'ca', 'en'] | False |
SuplaChannel.name | (self) | Return the name of the device. | Return the name of the device. | def name(self) -> Optional[str]:
"""Return the name of the device."""
return self.channel_data["caption"] | [
"def",
"name",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"channel_data",
"[",
"\"caption\"",
"]"
] | [
182,
4
] | [
184,
43
] | python | en | ['en', 'en', 'en'] | True |
SuplaChannel.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self) -> bool:
"""Return True if entity is available."""
if self.channel_data is None:
return False
state = self.channel_data.get("state")
if state is None:
return False
return state.get("connected") | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"channel_data",
"is",
"None",
":",
"return",
"False",
"state",
"=",
"self",
".",
"channel_data",
".",
"get",
"(",
"\"state\"",
")",
"if",
"state",
"is",
"None",
":",
"return",
"False",
"return",
"state",
".",
"get",
"(",
"\"connected\"",
")"
] | [
187,
4
] | [
194,
37
] | python | en | ['en', 'en', 'en'] | True |
SuplaChannel.async_action | (self, action, **add_pars) |
Run server action.
Actions are currently hardcoded in components.
Supla's API enables autodiscovery
|
Run server action. | async def async_action(self, action, **add_pars):
"""
Run server action.
Actions are currently hardcoded in components.
Supla's API enables autodiscovery
"""
_LOGGER.debug(
"Executing action %s on channel %d, params: %s",
action,
self.channel_data["id"],
add_pars,
)
await self.server.execute_action(self.channel_data["id"], action, **add_pars)
# Update state
await self.coordinator.async_request_refresh() | [
"async",
"def",
"async_action",
"(",
"self",
",",
"action",
",",
"*",
"*",
"add_pars",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Executing action %s on channel %d, params: %s\"",
",",
"action",
",",
"self",
".",
"channel_data",
"[",
"\"id\"",
"]",
",",
"add_pars",
",",
")",
"await",
"self",
".",
"server",
".",
"execute_action",
"(",
"self",
".",
"channel_data",
"[",
"\"id\"",
"]",
",",
"action",
",",
"*",
"*",
"add_pars",
")",
"# Update state",
"await",
"self",
".",
"coordinator",
".",
"async_request_refresh",
"(",
")"
] | [
196,
4
] | [
212,
54
] | python | en | ['en', 'error', 'th'] | False |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up August cameras. | Set up August cameras. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up August cameras."""
data = hass.data[DOMAIN][config_entry.entry_id][DATA_AUGUST]
devices = []
for doorbell in data.doorbells:
devices.append(AugustCamera(data, doorbell, DEFAULT_TIMEOUT))
async_add_entities(devices, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"[",
"DATA_AUGUST",
"]",
"devices",
"=",
"[",
"]",
"for",
"doorbell",
"in",
"data",
".",
"doorbells",
":",
"devices",
".",
"append",
"(",
"AugustCamera",
"(",
"data",
",",
"doorbell",
",",
"DEFAULT_TIMEOUT",
")",
")",
"async_add_entities",
"(",
"devices",
",",
"True",
")"
] | [
13,
0
] | [
21,
37
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.__init__ | (self, data, device, timeout) | Initialize a August security camera. | Initialize a August security camera. | def __init__(self, data, device, timeout):
"""Initialize a August security camera."""
super().__init__(data, device)
self._data = data
self._device = device
self._timeout = timeout
self._image_url = None
self._image_content = None | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"device",
",",
"timeout",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"data",
",",
"device",
")",
"self",
".",
"_data",
"=",
"data",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_timeout",
"=",
"timeout",
"self",
".",
"_image_url",
"=",
"None",
"self",
".",
"_image_content",
"=",
"None"
] | [
27,
4
] | [
34,
34
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.name | (self) | Return the name of this device. | Return the name of this device. | def name(self):
"""Return the name of this device."""
return f"{self._device.device_name} Camera" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._device.device_name} Camera\""
] | [
37,
4
] | [
39,
51
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.is_recording | (self) | Return true if the device is recording. | Return true if the device is recording. | def is_recording(self):
"""Return true if the device is recording."""
return self._device.has_subscription | [
"def",
"is_recording",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"has_subscription"
] | [
42,
4
] | [
44,
44
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.motion_detection_enabled | (self) | Return the camera motion detection status. | Return the camera motion detection status. | def motion_detection_enabled(self):
"""Return the camera motion detection status."""
return True | [
"def",
"motion_detection_enabled",
"(",
"self",
")",
":",
"return",
"True"
] | [
47,
4
] | [
49,
19
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.brand | (self) | Return the camera brand. | Return the camera brand. | def brand(self):
"""Return the camera brand."""
return DEFAULT_NAME | [
"def",
"brand",
"(",
"self",
")",
":",
"return",
"DEFAULT_NAME"
] | [
52,
4
] | [
54,
27
] | python | en | ['en', 'bs', 'en'] | True |
AugustCamera.model | (self) | Return the camera model. | Return the camera model. | def model(self):
"""Return the camera model."""
return self._detail.model | [
"def",
"model",
"(",
"self",
")",
":",
"return",
"self",
".",
"_detail",
".",
"model"
] | [
57,
4
] | [
59,
33
] | python | en | ['en', 'co', 'en'] | True |
AugustCamera._update_from_data | (self) | Get the latest state of the sensor. | Get the latest state of the sensor. | def _update_from_data(self):
"""Get the latest state of the sensor."""
doorbell_activity = self._data.activity_stream.get_latest_device_activity(
self._device_id, [ActivityType.DOORBELL_MOTION]
)
if doorbell_activity is not None:
update_doorbell_image_from_activity(self._detail, doorbell_activity) | [
"def",
"_update_from_data",
"(",
"self",
")",
":",
"doorbell_activity",
"=",
"self",
".",
"_data",
".",
"activity_stream",
".",
"get_latest_device_activity",
"(",
"self",
".",
"_device_id",
",",
"[",
"ActivityType",
".",
"DOORBELL_MOTION",
"]",
")",
"if",
"doorbell_activity",
"is",
"not",
"None",
":",
"update_doorbell_image_from_activity",
"(",
"self",
".",
"_detail",
",",
"doorbell_activity",
")"
] | [
62,
4
] | [
69,
80
] | python | en | ['en', 'en', 'en'] | True |
AugustCamera.async_camera_image | (self) | Return bytes of camera image. | Return bytes of camera image. | async def async_camera_image(self):
"""Return bytes of camera image."""
self._update_from_data()
if self._image_url is not self._detail.image_url:
self._image_url = self._detail.image_url
self._image_content = await self._detail.async_get_doorbell_image(
aiohttp_client.async_get_clientsession(self.hass), timeout=self._timeout
)
return self._image_content | [
"async",
"def",
"async_camera_image",
"(",
"self",
")",
":",
"self",
".",
"_update_from_data",
"(",
")",
"if",
"self",
".",
"_image_url",
"is",
"not",
"self",
".",
"_detail",
".",
"image_url",
":",
"self",
".",
"_image_url",
"=",
"self",
".",
"_detail",
".",
"image_url",
"self",
".",
"_image_content",
"=",
"await",
"self",
".",
"_detail",
".",
"async_get_doorbell_image",
"(",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
"self",
".",
"hass",
")",
",",
"timeout",
"=",
"self",
".",
"_timeout",
")",
"return",
"self",
".",
"_image_content"
] | [
71,
4
] | [
80,
34
] | python | en | ['en', 'zu', 'en'] | True |
AugustCamera.unique_id | (self) | Get the unique id of the camera. | Get the unique id of the camera. | def unique_id(self) -> str:
"""Get the unique id of the camera."""
return f"{self._device_id:s}_camera" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{self._device_id:s}_camera\""
] | [
83,
4
] | [
85,
44
] | python | en | ['en', 'en', 'en'] | True |
session | (hass) | Return aioclient session. | Return aioclient session. | async def session(hass):
"""Return aioclient session."""
return hass.helpers.aiohttp_client.async_get_clientsession() | [
"async",
"def",
"session",
"(",
"hass",
")",
":",
"return",
"hass",
".",
"helpers",
".",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
")"
] | [
26,
0
] | [
28,
64
] | python | en | ['en', 'fr', 'en'] | True |
raising_session | (loop) | Return an aioclient session that only fails. | Return an aioclient session that only fails. | async def raising_session(loop):
"""Return an aioclient session that only fails."""
return Mock(get=Mock(side_effect=aiohttp.ClientError)) | [
"async",
"def",
"raising_session",
"(",
"loop",
")",
":",
"return",
"Mock",
"(",
"get",
"=",
"Mock",
"(",
"side_effect",
"=",
"aiohttp",
".",
"ClientError",
")",
")"
] | [
32,
0
] | [
34,
58
] | python | en | ['en', 'en', 'en'] | True |
test_get_distance_to_same_place | () | Test getting the distance. | Test getting the distance. | def test_get_distance_to_same_place():
"""Test getting the distance."""
meters = location_util.distance(
COORDINATES_PARIS[0],
COORDINATES_PARIS[1],
COORDINATES_PARIS[0],
COORDINATES_PARIS[1],
)
assert meters == 0 | [
"def",
"test_get_distance_to_same_place",
"(",
")",
":",
"meters",
"=",
"location_util",
".",
"distance",
"(",
"COORDINATES_PARIS",
"[",
"0",
"]",
",",
"COORDINATES_PARIS",
"[",
"1",
"]",
",",
"COORDINATES_PARIS",
"[",
"0",
"]",
",",
"COORDINATES_PARIS",
"[",
"1",
"]",
",",
")",
"assert",
"meters",
"==",
"0"
] | [
37,
0
] | [
46,
22
] | python | en | ['en', 'en', 'en'] | True |
test_get_distance | () | Test getting the distance. | Test getting the distance. | def test_get_distance():
"""Test getting the distance."""
meters = location_util.distance(
COORDINATES_PARIS[0],
COORDINATES_PARIS[1],
COORDINATES_NEW_YORK[0],
COORDINATES_NEW_YORK[1],
)
assert meters / 1000 - DISTANCE_KM < 0.01 | [
"def",
"test_get_distance",
"(",
")",
":",
"meters",
"=",
"location_util",
".",
"distance",
"(",
"COORDINATES_PARIS",
"[",
"0",
"]",
",",
"COORDINATES_PARIS",
"[",
"1",
"]",
",",
"COORDINATES_NEW_YORK",
"[",
"0",
"]",
",",
"COORDINATES_NEW_YORK",
"[",
"1",
"]",
",",
")",
"assert",
"meters",
"/",
"1000",
"-",
"DISTANCE_KM",
"<",
"0.01"
] | [
49,
0
] | [
58,
45
] | python | en | ['en', 'en', 'en'] | True |
test_get_kilometers | () | Test getting the distance between given coordinates in km. | Test getting the distance between given coordinates in km. | def test_get_kilometers():
"""Test getting the distance between given coordinates in km."""
kilometers = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK)
assert round(kilometers, 2) == DISTANCE_KM | [
"def",
"test_get_kilometers",
"(",
")",
":",
"kilometers",
"=",
"location_util",
".",
"vincenty",
"(",
"COORDINATES_PARIS",
",",
"COORDINATES_NEW_YORK",
")",
"assert",
"round",
"(",
"kilometers",
",",
"2",
")",
"==",
"DISTANCE_KM"
] | [
61,
0
] | [
64,
46
] | python | en | ['en', 'en', 'en'] | True |
test_get_miles | () | Test getting the distance between given coordinates in miles. | Test getting the distance between given coordinates in miles. | def test_get_miles():
"""Test getting the distance between given coordinates in miles."""
miles = location_util.vincenty(COORDINATES_PARIS, COORDINATES_NEW_YORK, miles=True)
assert round(miles, 2) == DISTANCE_MILES | [
"def",
"test_get_miles",
"(",
")",
":",
"miles",
"=",
"location_util",
".",
"vincenty",
"(",
"COORDINATES_PARIS",
",",
"COORDINATES_NEW_YORK",
",",
"miles",
"=",
"True",
")",
"assert",
"round",
"(",
"miles",
",",
"2",
")",
"==",
"DISTANCE_MILES"
] | [
67,
0
] | [
70,
44
] | python | en | ['en', 'en', 'en'] | True |
test_detect_location_info_ipapi | (aioclient_mock, session) | Test detect location info using ipapi.co. | Test detect location info using ipapi.co. | async def test_detect_location_info_ipapi(aioclient_mock, session):
"""Test detect location info using ipapi.co."""
aioclient_mock.get(location_util.IPAPI, text=load_fixture("ipapi.co.json"))
info = await location_util.async_detect_location_info(session, _test_real=True)
assert info is not None
assert info.ip == "1.2.3.4"
assert info.country_code == "CH"
assert info.country_name == "Switzerland"
assert info.region_code == "BE"
assert info.region_name == "Bern"
assert info.city == "Bern"
assert info.zip_code == "3000"
assert info.time_zone == "Europe/Zurich"
assert info.latitude == 46.9480278
assert info.longitude == 7.4490812
assert info.use_metric | [
"async",
"def",
"test_detect_location_info_ipapi",
"(",
"aioclient_mock",
",",
"session",
")",
":",
"aioclient_mock",
".",
"get",
"(",
"location_util",
".",
"IPAPI",
",",
"text",
"=",
"load_fixture",
"(",
"\"ipapi.co.json\"",
")",
")",
"info",
"=",
"await",
"location_util",
".",
"async_detect_location_info",
"(",
"session",
",",
"_test_real",
"=",
"True",
")",
"assert",
"info",
"is",
"not",
"None",
"assert",
"info",
".",
"ip",
"==",
"\"1.2.3.4\"",
"assert",
"info",
".",
"country_code",
"==",
"\"CH\"",
"assert",
"info",
".",
"country_name",
"==",
"\"Switzerland\"",
"assert",
"info",
".",
"region_code",
"==",
"\"BE\"",
"assert",
"info",
".",
"region_name",
"==",
"\"Bern\"",
"assert",
"info",
".",
"city",
"==",
"\"Bern\"",
"assert",
"info",
".",
"zip_code",
"==",
"\"3000\"",
"assert",
"info",
".",
"time_zone",
"==",
"\"Europe/Zurich\"",
"assert",
"info",
".",
"latitude",
"==",
"46.9480278",
"assert",
"info",
".",
"longitude",
"==",
"7.4490812",
"assert",
"info",
".",
"use_metric"
] | [
73,
0
] | [
90,
26
] | python | en | ['da', 'en', 'en'] | True |
test_detect_location_info_ipapi_exhaust | (aioclient_mock, session) | Test detect location info using ipapi.co. | Test detect location info using ipapi.co. | async def test_detect_location_info_ipapi_exhaust(aioclient_mock, session):
"""Test detect location info using ipapi.co."""
aioclient_mock.get(location_util.IPAPI, json={"latitude": "Sign up to access"})
aioclient_mock.get(location_util.IP_API, text=load_fixture("ip-api.com.json"))
info = await location_util.async_detect_location_info(session, _test_real=True)
assert info is not None
# ip_api result because ipapi got skipped
assert info.country_code == "US"
assert len(aioclient_mock.mock_calls) == 2 | [
"async",
"def",
"test_detect_location_info_ipapi_exhaust",
"(",
"aioclient_mock",
",",
"session",
")",
":",
"aioclient_mock",
".",
"get",
"(",
"location_util",
".",
"IPAPI",
",",
"json",
"=",
"{",
"\"latitude\"",
":",
"\"Sign up to access\"",
"}",
")",
"aioclient_mock",
".",
"get",
"(",
"location_util",
".",
"IP_API",
",",
"text",
"=",
"load_fixture",
"(",
"\"ip-api.com.json\"",
")",
")",
"info",
"=",
"await",
"location_util",
".",
"async_detect_location_info",
"(",
"session",
",",
"_test_real",
"=",
"True",
")",
"assert",
"info",
"is",
"not",
"None",
"# ip_api result because ipapi got skipped",
"assert",
"info",
".",
"country_code",
"==",
"\"US\"",
"assert",
"len",
"(",
"aioclient_mock",
".",
"mock_calls",
")",
"==",
"2"
] | [
93,
0
] | [
103,
46
] | python | en | ['da', 'en', 'en'] | True |
test_detect_location_info_ip_api | (aioclient_mock, session) | Test detect location info using ip-api.com. | Test detect location info using ip-api.com. | async def test_detect_location_info_ip_api(aioclient_mock, session):
"""Test detect location info using ip-api.com."""
aioclient_mock.get(location_util.IP_API, text=load_fixture("ip-api.com.json"))
with patch("homeassistant.util.location._get_ipapi", return_value=None):
info = await location_util.async_detect_location_info(session, _test_real=True)
assert info is not None
assert info.ip == "1.2.3.4"
assert info.country_code == "US"
assert info.country_name == "United States"
assert info.region_code == "CA"
assert info.region_name == "California"
assert info.city == "San Diego"
assert info.zip_code == "92122"
assert info.time_zone == "America/Los_Angeles"
assert info.latitude == 32.8594
assert info.longitude == -117.2073
assert not info.use_metric | [
"async",
"def",
"test_detect_location_info_ip_api",
"(",
"aioclient_mock",
",",
"session",
")",
":",
"aioclient_mock",
".",
"get",
"(",
"location_util",
".",
"IP_API",
",",
"text",
"=",
"load_fixture",
"(",
"\"ip-api.com.json\"",
")",
")",
"with",
"patch",
"(",
"\"homeassistant.util.location._get_ipapi\"",
",",
"return_value",
"=",
"None",
")",
":",
"info",
"=",
"await",
"location_util",
".",
"async_detect_location_info",
"(",
"session",
",",
"_test_real",
"=",
"True",
")",
"assert",
"info",
"is",
"not",
"None",
"assert",
"info",
".",
"ip",
"==",
"\"1.2.3.4\"",
"assert",
"info",
".",
"country_code",
"==",
"\"US\"",
"assert",
"info",
".",
"country_name",
"==",
"\"United States\"",
"assert",
"info",
".",
"region_code",
"==",
"\"CA\"",
"assert",
"info",
".",
"region_name",
"==",
"\"California\"",
"assert",
"info",
".",
"city",
"==",
"\"San Diego\"",
"assert",
"info",
".",
"zip_code",
"==",
"\"92122\"",
"assert",
"info",
".",
"time_zone",
"==",
"\"America/Los_Angeles\"",
"assert",
"info",
".",
"latitude",
"==",
"32.8594",
"assert",
"info",
".",
"longitude",
"==",
"-",
"117.2073",
"assert",
"not",
"info",
".",
"use_metric"
] | [
106,
0
] | [
124,
30
] | python | da | ['da', 'pt', 'en'] | False |
test_detect_location_info_both_queries_fail | (session) | Ensure we return None if both queries fail. | Ensure we return None if both queries fail. | async def test_detect_location_info_both_queries_fail(session):
"""Ensure we return None if both queries fail."""
with patch("homeassistant.util.location._get_ipapi", return_value=None), patch(
"homeassistant.util.location._get_ip_api", return_value=None
):
info = await location_util.async_detect_location_info(session, _test_real=True)
assert info is None | [
"async",
"def",
"test_detect_location_info_both_queries_fail",
"(",
"session",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.util.location._get_ipapi\"",
",",
"return_value",
"=",
"None",
")",
",",
"patch",
"(",
"\"homeassistant.util.location._get_ip_api\"",
",",
"return_value",
"=",
"None",
")",
":",
"info",
"=",
"await",
"location_util",
".",
"async_detect_location_info",
"(",
"session",
",",
"_test_real",
"=",
"True",
")",
"assert",
"info",
"is",
"None"
] | [
127,
0
] | [
133,
23
] | python | en | ['fr', 'gd', 'en'] | False |
test_freegeoip_query_raises | (raising_session) | Test ipapi.co query when the request to API fails. | Test ipapi.co query when the request to API fails. | async def test_freegeoip_query_raises(raising_session):
"""Test ipapi.co query when the request to API fails."""
info = await location_util._get_ipapi(raising_session)
assert info is None | [
"async",
"def",
"test_freegeoip_query_raises",
"(",
"raising_session",
")",
":",
"info",
"=",
"await",
"location_util",
".",
"_get_ipapi",
"(",
"raising_session",
")",
"assert",
"info",
"is",
"None"
] | [
136,
0
] | [
139,
23
] | python | en | ['en', 'en', 'en'] | True |
test_ip_api_query_raises | (raising_session) | Test ip api query when the request to API fails. | Test ip api query when the request to API fails. | async def test_ip_api_query_raises(raising_session):
"""Test ip api query when the request to API fails."""
info = await location_util._get_ip_api(raising_session)
assert info is None | [
"async",
"def",
"test_ip_api_query_raises",
"(",
"raising_session",
")",
":",
"info",
"=",
"await",
"location_util",
".",
"_get_ip_api",
"(",
"raising_session",
")",
"assert",
"info",
"is",
"None"
] | [
142,
0
] | [
145,
23
] | python | en | ['en', 'en', 'en'] | True |
Game._score_offset_to_speed | (score_offset: int) | Values were acquired experimentally.
| Values were acquired experimentally.
| def _score_offset_to_speed(score_offset: int) -> float:
""" Values were acquired experimentally.
"""
if not 0 <= score_offset <= 1000:
raise ValueError(
f"score_offset must be between 0 and 1000: {score_offset}")
if score_offset % 100:
raise ValueError(
f"score_offset is not round number: {score_offset}")
if score_offset == 0:
return 6.0
elif score_offset == 100:
return 6.66
elif score_offset == 200:
return 7.2
elif score_offset == 300:
return 7.75
elif score_offset == 400:
return 8.2
elif score_offset == 500:
return 8.75
elif score_offset == 600:
return 9.17
elif score_offset == 700:
return 9.6
elif score_offset == 800:
return 10.0
elif score_offset == 900:
return 10.4
elif score_offset == 1000:
return 10.8 | [
"def",
"_score_offset_to_speed",
"(",
"score_offset",
":",
"int",
")",
"->",
"float",
":",
"if",
"not",
"0",
"<=",
"score_offset",
"<=",
"1000",
":",
"raise",
"ValueError",
"(",
"f\"score_offset must be between 0 and 1000: {score_offset}\"",
")",
"if",
"score_offset",
"%",
"100",
":",
"raise",
"ValueError",
"(",
"f\"score_offset is not round number: {score_offset}\"",
")",
"if",
"score_offset",
"==",
"0",
":",
"return",
"6.0",
"elif",
"score_offset",
"==",
"100",
":",
"return",
"6.66",
"elif",
"score_offset",
"==",
"200",
":",
"return",
"7.2",
"elif",
"score_offset",
"==",
"300",
":",
"return",
"7.75",
"elif",
"score_offset",
"==",
"400",
":",
"return",
"8.2",
"elif",
"score_offset",
"==",
"500",
":",
"return",
"8.75",
"elif",
"score_offset",
"==",
"600",
":",
"return",
"9.17",
"elif",
"score_offset",
"==",
"700",
":",
"return",
"9.6",
"elif",
"score_offset",
"==",
"800",
":",
"return",
"10.0",
"elif",
"score_offset",
"==",
"900",
":",
"return",
"10.4",
"elif",
"score_offset",
"==",
"1000",
":",
"return",
"10.8"
] | [
46,
4
] | [
77,
23
] | python | en | ['en', 'en', 'en'] | True |
toon_exception_handler | (func) | Decorate Toon calls to handle Toon exceptions.
A decorator that wraps the passed in function, catches Toon errors,
and handles the availability of the device in the data coordinator.
| Decorate Toon calls to handle Toon exceptions. | def toon_exception_handler(func):
"""Decorate Toon calls to handle Toon exceptions.
A decorator that wraps the passed in function, catches Toon errors,
and handles the availability of the device in the data coordinator.
"""
async def handler(self, *args, **kwargs):
try:
await func(self, *args, **kwargs)
self.coordinator.update_listeners()
except ToonConnectionError as error:
_LOGGER.error("Error communicating with API: %s", error)
self.coordinator.last_update_success = False
self.coordinator.update_listeners()
except ToonError as error:
_LOGGER.error("Invalid response from API: %s", error)
return handler | [
"def",
"toon_exception_handler",
"(",
"func",
")",
":",
"async",
"def",
"handler",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"await",
"func",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"coordinator",
".",
"update_listeners",
"(",
")",
"except",
"ToonConnectionError",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error communicating with API: %s\"",
",",
"error",
")",
"self",
".",
"coordinator",
".",
"last_update_success",
"=",
"False",
"self",
".",
"coordinator",
".",
"update_listeners",
"(",
")",
"except",
"ToonError",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid response from API: %s\"",
",",
"error",
")",
"return",
"handler"
] | [
8,
0
] | [
28,
18
] | python | en | ['en', 'en', 'en'] | True |
async_set_domains_to_be_loaded | (hass: core.HomeAssistant, domains: Set[str]) | Set domains that are going to be loaded from the config.
This will allow us to properly handle after_dependencies.
| Set domains that are going to be loaded from the config. | def async_set_domains_to_be_loaded(hass: core.HomeAssistant, domains: Set[str]) -> None:
"""Set domains that are going to be loaded from the config.
This will allow us to properly handle after_dependencies.
"""
hass.data[DATA_SETUP_DONE] = {domain: asyncio.Event() for domain in domains} | [
"def",
"async_set_domains_to_be_loaded",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"domains",
":",
"Set",
"[",
"str",
"]",
")",
"->",
"None",
":",
"hass",
".",
"data",
"[",
"DATA_SETUP_DONE",
"]",
"=",
"{",
"domain",
":",
"asyncio",
".",
"Event",
"(",
")",
"for",
"domain",
"in",
"domains",
"}"
] | [
28,
0
] | [
33,
80
] | python | en | ['en', 'en', 'en'] | True |
setup_component | (hass: core.HomeAssistant, domain: str, config: ConfigType) | Set up a component and all its dependencies. | Set up a component and all its dependencies. | def setup_component(hass: core.HomeAssistant, domain: str, config: ConfigType) -> bool:
"""Set up a component and all its dependencies."""
return asyncio.run_coroutine_threadsafe(
async_setup_component(hass, domain, config), hass.loop
).result() | [
"def",
"setup_component",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"domain",
":",
"str",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"return",
"asyncio",
".",
"run_coroutine_threadsafe",
"(",
"async_setup_component",
"(",
"hass",
",",
"domain",
",",
"config",
")",
",",
"hass",
".",
"loop",
")",
".",
"result",
"(",
")"
] | [
36,
0
] | [
40,
14
] | python | en | ['en', 'en', 'en'] | True |
async_setup_component | (
hass: core.HomeAssistant, domain: str, config: ConfigType
) | Set up a component and all its dependencies.
This method is a coroutine.
| Set up a component and all its dependencies. | async def async_setup_component(
hass: core.HomeAssistant, domain: str, config: ConfigType
) -> bool:
"""Set up a component and all its dependencies.
This method is a coroutine.
"""
if domain in hass.config.components:
return True
setup_tasks = hass.data.setdefault(DATA_SETUP, {})
if domain in setup_tasks:
return await setup_tasks[domain] # type: ignore
task = setup_tasks[domain] = hass.async_create_task(
_async_setup_component(hass, domain, config)
)
try:
return await task # type: ignore
finally:
if domain in hass.data.get(DATA_SETUP_DONE, {}):
hass.data[DATA_SETUP_DONE].pop(domain).set() | [
"async",
"def",
"async_setup_component",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"domain",
":",
"str",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"if",
"domain",
"in",
"hass",
".",
"config",
".",
"components",
":",
"return",
"True",
"setup_tasks",
"=",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DATA_SETUP",
",",
"{",
"}",
")",
"if",
"domain",
"in",
"setup_tasks",
":",
"return",
"await",
"setup_tasks",
"[",
"domain",
"]",
"# type: ignore",
"task",
"=",
"setup_tasks",
"[",
"domain",
"]",
"=",
"hass",
".",
"async_create_task",
"(",
"_async_setup_component",
"(",
"hass",
",",
"domain",
",",
"config",
")",
")",
"try",
":",
"return",
"await",
"task",
"# type: ignore",
"finally",
":",
"if",
"domain",
"in",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_SETUP_DONE",
",",
"{",
"}",
")",
":",
"hass",
".",
"data",
"[",
"DATA_SETUP_DONE",
"]",
".",
"pop",
"(",
"domain",
")",
".",
"set",
"(",
")"
] | [
43,
0
] | [
66,
56
] | python | en | ['en', 'en', 'en'] | True |
_async_process_dependencies | (
hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration
) | Ensure all dependencies are set up. | Ensure all dependencies are set up. | async def _async_process_dependencies(
hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration
) -> bool:
"""Ensure all dependencies are set up."""
dependencies_tasks = {
dep: hass.loop.create_task(async_setup_component(hass, dep, config))
for dep in integration.dependencies
if dep not in hass.config.components
}
after_dependencies_tasks = {}
to_be_loaded = hass.data.get(DATA_SETUP_DONE, {})
for dep in integration.after_dependencies:
if (
dep not in dependencies_tasks
and dep in to_be_loaded
and dep not in hass.config.components
):
after_dependencies_tasks[dep] = hass.loop.create_task(
to_be_loaded[dep].wait()
)
if not dependencies_tasks and not after_dependencies_tasks:
return True
if dependencies_tasks:
_LOGGER.debug(
"Dependency %s will wait for dependencies %s",
integration.domain,
list(dependencies_tasks),
)
if after_dependencies_tasks:
_LOGGER.debug(
"Dependency %s will wait for after dependencies %s",
integration.domain,
list(after_dependencies_tasks),
)
async with hass.timeout.async_freeze(integration.domain):
results = await asyncio.gather(
*dependencies_tasks.values(), *after_dependencies_tasks.values()
)
failed = [
domain for idx, domain in enumerate(dependencies_tasks) if not results[idx]
]
if failed:
_LOGGER.error(
"Unable to set up dependencies of %s. Setup failed for dependencies: %s",
integration.domain,
", ".join(failed),
)
return False
return True | [
"async",
"def",
"_async_process_dependencies",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
",",
"integration",
":",
"loader",
".",
"Integration",
")",
"->",
"bool",
":",
"dependencies_tasks",
"=",
"{",
"dep",
":",
"hass",
".",
"loop",
".",
"create_task",
"(",
"async_setup_component",
"(",
"hass",
",",
"dep",
",",
"config",
")",
")",
"for",
"dep",
"in",
"integration",
".",
"dependencies",
"if",
"dep",
"not",
"in",
"hass",
".",
"config",
".",
"components",
"}",
"after_dependencies_tasks",
"=",
"{",
"}",
"to_be_loaded",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_SETUP_DONE",
",",
"{",
"}",
")",
"for",
"dep",
"in",
"integration",
".",
"after_dependencies",
":",
"if",
"(",
"dep",
"not",
"in",
"dependencies_tasks",
"and",
"dep",
"in",
"to_be_loaded",
"and",
"dep",
"not",
"in",
"hass",
".",
"config",
".",
"components",
")",
":",
"after_dependencies_tasks",
"[",
"dep",
"]",
"=",
"hass",
".",
"loop",
".",
"create_task",
"(",
"to_be_loaded",
"[",
"dep",
"]",
".",
"wait",
"(",
")",
")",
"if",
"not",
"dependencies_tasks",
"and",
"not",
"after_dependencies_tasks",
":",
"return",
"True",
"if",
"dependencies_tasks",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Dependency %s will wait for dependencies %s\"",
",",
"integration",
".",
"domain",
",",
"list",
"(",
"dependencies_tasks",
")",
",",
")",
"if",
"after_dependencies_tasks",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Dependency %s will wait for after dependencies %s\"",
",",
"integration",
".",
"domain",
",",
"list",
"(",
"after_dependencies_tasks",
")",
",",
")",
"async",
"with",
"hass",
".",
"timeout",
".",
"async_freeze",
"(",
"integration",
".",
"domain",
")",
":",
"results",
"=",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"dependencies_tasks",
".",
"values",
"(",
")",
",",
"*",
"after_dependencies_tasks",
".",
"values",
"(",
")",
")",
"failed",
"=",
"[",
"domain",
"for",
"idx",
",",
"domain",
"in",
"enumerate",
"(",
"dependencies_tasks",
")",
"if",
"not",
"results",
"[",
"idx",
"]",
"]",
"if",
"failed",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to set up dependencies of %s. Setup failed for dependencies: %s\"",
",",
"integration",
".",
"domain",
",",
"\", \"",
".",
"join",
"(",
"failed",
")",
",",
")",
"return",
"False",
"return",
"True"
] | [
69,
0
] | [
124,
15
] | python | en | ['en', 'en', 'en'] | True |
_async_setup_component | (
hass: core.HomeAssistant, domain: str, config: ConfigType
) | Set up a component for Home Assistant.
This method is a coroutine.
| Set up a component for Home Assistant. | async def _async_setup_component(
hass: core.HomeAssistant, domain: str, config: ConfigType
) -> bool:
"""Set up a component for Home Assistant.
This method is a coroutine.
"""
def log_error(msg: str, link: Optional[str] = None) -> None:
"""Log helper."""
_LOGGER.error("Setup failed for %s: %s", domain, msg)
async_notify_setup_error(hass, domain, link)
try:
integration = await loader.async_get_integration(hass, domain)
except loader.IntegrationNotFound:
log_error("Integration not found.")
return False
if integration.disabled:
log_error(f"dependency is disabled - {integration.disabled}")
return False
# Validate all dependencies exist and there are no circular dependencies
if not await integration.resolve_dependencies():
return False
# Process requirements as soon as possible, so we can import the component
# without requiring imports to be in functions.
try:
await async_process_deps_reqs(hass, config, integration)
except HomeAssistantError as err:
log_error(str(err), integration.documentation)
return False
# Some integrations fail on import because they call functions incorrectly.
# So we do it before validating config to catch these errors.
try:
component = integration.get_component()
except ImportError as err:
log_error(f"Unable to import component: {err}", integration.documentation)
return False
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Setup failed for %s: unknown error", domain)
return False
processed_config = await conf_util.async_process_component_config(
hass, config, integration
)
if processed_config is None:
log_error("Invalid config.", integration.documentation)
return False
start = timer()
_LOGGER.info("Setting up %s", domain)
hass.data.setdefault(DATA_SETUP_STARTED, {})[domain] = dt_util.utcnow()
if hasattr(component, "PLATFORM_SCHEMA"):
# Entity components have their own warning
warn_task = None
else:
warn_task = hass.loop.call_later(
SLOW_SETUP_WARNING,
_LOGGER.warning,
"Setup of %s is taking over %s seconds.",
domain,
SLOW_SETUP_WARNING,
)
try:
if hasattr(component, "async_setup"):
task = component.async_setup(hass, processed_config) # type: ignore
elif hasattr(component, "setup"):
# This should not be replaced with hass.async_add_executor_job because
# we don't want to track this task in case it blocks startup.
task = hass.loop.run_in_executor(
None, component.setup, hass, processed_config # type: ignore
)
else:
log_error("No setup function defined.")
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
async with hass.timeout.async_timeout(SLOW_SETUP_MAX_WAIT, domain):
result = await task
except asyncio.TimeoutError:
_LOGGER.error(
"Setup of %s is taking longer than %s seconds."
" Startup will proceed without waiting any longer",
domain,
SLOW_SETUP_MAX_WAIT,
)
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Error during setup of component %s", domain)
async_notify_setup_error(hass, domain, integration.documentation)
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
finally:
end = timer()
if warn_task:
warn_task.cancel()
_LOGGER.info("Setup of domain %s took %.1f seconds", domain, end - start)
if result is False:
log_error("Integration failed to initialize.")
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
if result is not True:
log_error(
f"Integration {domain!r} did not return boolean if setup was "
"successful. Disabling component."
)
hass.data[DATA_SETUP_STARTED].pop(domain)
return False
# Flush out async_setup calling create_task. Fragile but covered by test.
await asyncio.sleep(0)
await hass.config_entries.flow.async_wait_init_flow_finish(domain)
await asyncio.gather(
*[
entry.async_setup(hass, integration=integration)
for entry in hass.config_entries.async_entries(domain)
]
)
hass.config.components.add(domain)
hass.data[DATA_SETUP_STARTED].pop(domain)
# Cleanup
if domain in hass.data[DATA_SETUP]:
hass.data[DATA_SETUP].pop(domain)
hass.bus.async_fire(EVENT_COMPONENT_LOADED, {ATTR_COMPONENT: domain})
return True | [
"async",
"def",
"_async_setup_component",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"domain",
":",
"str",
",",
"config",
":",
"ConfigType",
")",
"->",
"bool",
":",
"def",
"log_error",
"(",
"msg",
":",
"str",
",",
"link",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"\"\"\"Log helper.\"\"\"",
"_LOGGER",
".",
"error",
"(",
"\"Setup failed for %s: %s\"",
",",
"domain",
",",
"msg",
")",
"async_notify_setup_error",
"(",
"hass",
",",
"domain",
",",
"link",
")",
"try",
":",
"integration",
"=",
"await",
"loader",
".",
"async_get_integration",
"(",
"hass",
",",
"domain",
")",
"except",
"loader",
".",
"IntegrationNotFound",
":",
"log_error",
"(",
"\"Integration not found.\"",
")",
"return",
"False",
"if",
"integration",
".",
"disabled",
":",
"log_error",
"(",
"f\"dependency is disabled - {integration.disabled}\"",
")",
"return",
"False",
"# Validate all dependencies exist and there are no circular dependencies",
"if",
"not",
"await",
"integration",
".",
"resolve_dependencies",
"(",
")",
":",
"return",
"False",
"# Process requirements as soon as possible, so we can import the component",
"# without requiring imports to be in functions.",
"try",
":",
"await",
"async_process_deps_reqs",
"(",
"hass",
",",
"config",
",",
"integration",
")",
"except",
"HomeAssistantError",
"as",
"err",
":",
"log_error",
"(",
"str",
"(",
"err",
")",
",",
"integration",
".",
"documentation",
")",
"return",
"False",
"# Some integrations fail on import because they call functions incorrectly.",
"# So we do it before validating config to catch these errors.",
"try",
":",
"component",
"=",
"integration",
".",
"get_component",
"(",
")",
"except",
"ImportError",
"as",
"err",
":",
"log_error",
"(",
"f\"Unable to import component: {err}\"",
",",
"integration",
".",
"documentation",
")",
"return",
"False",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"exception",
"(",
"\"Setup failed for %s: unknown error\"",
",",
"domain",
")",
"return",
"False",
"processed_config",
"=",
"await",
"conf_util",
".",
"async_process_component_config",
"(",
"hass",
",",
"config",
",",
"integration",
")",
"if",
"processed_config",
"is",
"None",
":",
"log_error",
"(",
"\"Invalid config.\"",
",",
"integration",
".",
"documentation",
")",
"return",
"False",
"start",
"=",
"timer",
"(",
")",
"_LOGGER",
".",
"info",
"(",
"\"Setting up %s\"",
",",
"domain",
")",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DATA_SETUP_STARTED",
",",
"{",
"}",
")",
"[",
"domain",
"]",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"if",
"hasattr",
"(",
"component",
",",
"\"PLATFORM_SCHEMA\"",
")",
":",
"# Entity components have their own warning",
"warn_task",
"=",
"None",
"else",
":",
"warn_task",
"=",
"hass",
".",
"loop",
".",
"call_later",
"(",
"SLOW_SETUP_WARNING",
",",
"_LOGGER",
".",
"warning",
",",
"\"Setup of %s is taking over %s seconds.\"",
",",
"domain",
",",
"SLOW_SETUP_WARNING",
",",
")",
"try",
":",
"if",
"hasattr",
"(",
"component",
",",
"\"async_setup\"",
")",
":",
"task",
"=",
"component",
".",
"async_setup",
"(",
"hass",
",",
"processed_config",
")",
"# type: ignore",
"elif",
"hasattr",
"(",
"component",
",",
"\"setup\"",
")",
":",
"# This should not be replaced with hass.async_add_executor_job because",
"# we don't want to track this task in case it blocks startup.",
"task",
"=",
"hass",
".",
"loop",
".",
"run_in_executor",
"(",
"None",
",",
"component",
".",
"setup",
",",
"hass",
",",
"processed_config",
"# type: ignore",
")",
"else",
":",
"log_error",
"(",
"\"No setup function defined.\"",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"return",
"False",
"async",
"with",
"hass",
".",
"timeout",
".",
"async_timeout",
"(",
"SLOW_SETUP_MAX_WAIT",
",",
"domain",
")",
":",
"result",
"=",
"await",
"task",
"except",
"asyncio",
".",
"TimeoutError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Setup of %s is taking longer than %s seconds.\"",
"\" Startup will proceed without waiting any longer\"",
",",
"domain",
",",
"SLOW_SETUP_MAX_WAIT",
",",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"return",
"False",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"exception",
"(",
"\"Error during setup of component %s\"",
",",
"domain",
")",
"async_notify_setup_error",
"(",
"hass",
",",
"domain",
",",
"integration",
".",
"documentation",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"return",
"False",
"finally",
":",
"end",
"=",
"timer",
"(",
")",
"if",
"warn_task",
":",
"warn_task",
".",
"cancel",
"(",
")",
"_LOGGER",
".",
"info",
"(",
"\"Setup of domain %s took %.1f seconds\"",
",",
"domain",
",",
"end",
"-",
"start",
")",
"if",
"result",
"is",
"False",
":",
"log_error",
"(",
"\"Integration failed to initialize.\"",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"return",
"False",
"if",
"result",
"is",
"not",
"True",
":",
"log_error",
"(",
"f\"Integration {domain!r} did not return boolean if setup was \"",
"\"successful. Disabling component.\"",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"return",
"False",
"# Flush out async_setup calling create_task. Fragile but covered by test.",
"await",
"asyncio",
".",
"sleep",
"(",
"0",
")",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_wait_init_flow_finish",
"(",
"domain",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"entry",
".",
"async_setup",
"(",
"hass",
",",
"integration",
"=",
"integration",
")",
"for",
"entry",
"in",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"domain",
")",
"]",
")",
"hass",
".",
"config",
".",
"components",
".",
"add",
"(",
"domain",
")",
"hass",
".",
"data",
"[",
"DATA_SETUP_STARTED",
"]",
".",
"pop",
"(",
"domain",
")",
"# Cleanup",
"if",
"domain",
"in",
"hass",
".",
"data",
"[",
"DATA_SETUP",
"]",
":",
"hass",
".",
"data",
"[",
"DATA_SETUP",
"]",
".",
"pop",
"(",
"domain",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_COMPONENT_LOADED",
",",
"{",
"ATTR_COMPONENT",
":",
"domain",
"}",
")",
"return",
"True"
] | [
127,
0
] | [
265,
15
] | python | en | ['en', 'en', 'en'] | True |
async_prepare_setup_platform | (
hass: core.HomeAssistant, hass_config: ConfigType, domain: str, platform_name: str
) | Load a platform and makes sure dependencies are setup.
This method is a coroutine.
| Load a platform and makes sure dependencies are setup. | async def async_prepare_setup_platform(
hass: core.HomeAssistant, hass_config: ConfigType, domain: str, platform_name: str
) -> Optional[ModuleType]:
"""Load a platform and makes sure dependencies are setup.
This method is a coroutine.
"""
platform_path = PLATFORM_FORMAT.format(domain=domain, platform=platform_name)
def log_error(msg: str) -> None:
"""Log helper."""
_LOGGER.error("Unable to prepare setup for platform %s: %s", platform_path, msg)
async_notify_setup_error(hass, platform_path)
try:
integration = await loader.async_get_integration(hass, platform_name)
except loader.IntegrationNotFound:
log_error("Integration not found")
return None
# Process deps and reqs as soon as possible, so that requirements are
# available when we import the platform.
try:
await async_process_deps_reqs(hass, hass_config, integration)
except HomeAssistantError as err:
log_error(str(err))
return None
try:
platform = integration.get_platform(domain)
except ImportError as exc:
log_error(f"Platform not found ({exc}).")
return None
# Already loaded
if platform_path in hass.config.components:
return platform
# Platforms cannot exist on their own, they are part of their integration.
# If the integration is not set up yet, and can be set up, set it up.
if integration.domain not in hass.config.components:
try:
component = integration.get_component()
except ImportError as exc:
log_error(f"Unable to import the component ({exc}).")
return None
if hasattr(component, "setup") or hasattr(component, "async_setup"):
if not await async_setup_component(hass, integration.domain, hass_config):
log_error("Unable to set up component.")
return None
return platform | [
"async",
"def",
"async_prepare_setup_platform",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"hass_config",
":",
"ConfigType",
",",
"domain",
":",
"str",
",",
"platform_name",
":",
"str",
")",
"->",
"Optional",
"[",
"ModuleType",
"]",
":",
"platform_path",
"=",
"PLATFORM_FORMAT",
".",
"format",
"(",
"domain",
"=",
"domain",
",",
"platform",
"=",
"platform_name",
")",
"def",
"log_error",
"(",
"msg",
":",
"str",
")",
"->",
"None",
":",
"\"\"\"Log helper.\"\"\"",
"_LOGGER",
".",
"error",
"(",
"\"Unable to prepare setup for platform %s: %s\"",
",",
"platform_path",
",",
"msg",
")",
"async_notify_setup_error",
"(",
"hass",
",",
"platform_path",
")",
"try",
":",
"integration",
"=",
"await",
"loader",
".",
"async_get_integration",
"(",
"hass",
",",
"platform_name",
")",
"except",
"loader",
".",
"IntegrationNotFound",
":",
"log_error",
"(",
"\"Integration not found\"",
")",
"return",
"None",
"# Process deps and reqs as soon as possible, so that requirements are",
"# available when we import the platform.",
"try",
":",
"await",
"async_process_deps_reqs",
"(",
"hass",
",",
"hass_config",
",",
"integration",
")",
"except",
"HomeAssistantError",
"as",
"err",
":",
"log_error",
"(",
"str",
"(",
"err",
")",
")",
"return",
"None",
"try",
":",
"platform",
"=",
"integration",
".",
"get_platform",
"(",
"domain",
")",
"except",
"ImportError",
"as",
"exc",
":",
"log_error",
"(",
"f\"Platform not found ({exc}).\"",
")",
"return",
"None",
"# Already loaded",
"if",
"platform_path",
"in",
"hass",
".",
"config",
".",
"components",
":",
"return",
"platform",
"# Platforms cannot exist on their own, they are part of their integration.",
"# If the integration is not set up yet, and can be set up, set it up.",
"if",
"integration",
".",
"domain",
"not",
"in",
"hass",
".",
"config",
".",
"components",
":",
"try",
":",
"component",
"=",
"integration",
".",
"get_component",
"(",
")",
"except",
"ImportError",
"as",
"exc",
":",
"log_error",
"(",
"f\"Unable to import the component ({exc}).\"",
")",
"return",
"None",
"if",
"hasattr",
"(",
"component",
",",
"\"setup\"",
")",
"or",
"hasattr",
"(",
"component",
",",
"\"async_setup\"",
")",
":",
"if",
"not",
"await",
"async_setup_component",
"(",
"hass",
",",
"integration",
".",
"domain",
",",
"hass_config",
")",
":",
"log_error",
"(",
"\"Unable to set up component.\"",
")",
"return",
"None",
"return",
"platform"
] | [
268,
0
] | [
320,
19
] | python | en | ['en', 'en', 'en'] | True |
async_process_deps_reqs | (
hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration
) | Process all dependencies and requirements for a module.
Module is a Python module of either a component or platform.
| Process all dependencies and requirements for a module. | async def async_process_deps_reqs(
hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration
) -> None:
"""Process all dependencies and requirements for a module.
Module is a Python module of either a component or platform.
"""
processed = hass.data.get(DATA_DEPS_REQS)
if processed is None:
processed = hass.data[DATA_DEPS_REQS] = set()
elif integration.domain in processed:
return
if not await _async_process_dependencies(hass, config, integration):
raise HomeAssistantError("Could not set up all dependencies.")
if not hass.config.skip_pip and integration.requirements:
async with hass.timeout.async_freeze(integration.domain):
await requirements.async_get_integration_with_requirements(
hass, integration.domain
)
processed.add(integration.domain) | [
"async",
"def",
"async_process_deps_reqs",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"config",
":",
"ConfigType",
",",
"integration",
":",
"loader",
".",
"Integration",
")",
"->",
"None",
":",
"processed",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DATA_DEPS_REQS",
")",
"if",
"processed",
"is",
"None",
":",
"processed",
"=",
"hass",
".",
"data",
"[",
"DATA_DEPS_REQS",
"]",
"=",
"set",
"(",
")",
"elif",
"integration",
".",
"domain",
"in",
"processed",
":",
"return",
"if",
"not",
"await",
"_async_process_dependencies",
"(",
"hass",
",",
"config",
",",
"integration",
")",
":",
"raise",
"HomeAssistantError",
"(",
"\"Could not set up all dependencies.\"",
")",
"if",
"not",
"hass",
".",
"config",
".",
"skip_pip",
"and",
"integration",
".",
"requirements",
":",
"async",
"with",
"hass",
".",
"timeout",
".",
"async_freeze",
"(",
"integration",
".",
"domain",
")",
":",
"await",
"requirements",
".",
"async_get_integration_with_requirements",
"(",
"hass",
",",
"integration",
".",
"domain",
")",
"processed",
".",
"add",
"(",
"integration",
".",
"domain",
")"
] | [
323,
0
] | [
346,
37
] | python | en | ['en', 'en', 'en'] | True |
async_when_setup | (
hass: core.HomeAssistant,
component: str,
when_setup_cb: Callable[[core.HomeAssistant, str], Awaitable[None]],
) | Call a method when a component is setup. | Call a method when a component is setup. | def async_when_setup(
hass: core.HomeAssistant,
component: str,
when_setup_cb: Callable[[core.HomeAssistant, str], Awaitable[None]],
) -> None:
"""Call a method when a component is setup."""
async def when_setup() -> None:
"""Call the callback."""
try:
await when_setup_cb(hass, component)
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Error handling when_setup callback for %s", component)
# Running it in a new task so that it always runs after
if component in hass.config.components:
hass.async_create_task(when_setup())
return
unsub = None
async def loaded_event(event: core.Event) -> None:
"""Call the callback."""
if event.data[ATTR_COMPONENT] != component:
return
unsub() # type: ignore
await when_setup()
unsub = hass.bus.async_listen(EVENT_COMPONENT_LOADED, loaded_event) | [
"def",
"async_when_setup",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
",",
"component",
":",
"str",
",",
"when_setup_cb",
":",
"Callable",
"[",
"[",
"core",
".",
"HomeAssistant",
",",
"str",
"]",
",",
"Awaitable",
"[",
"None",
"]",
"]",
",",
")",
"->",
"None",
":",
"async",
"def",
"when_setup",
"(",
")",
"->",
"None",
":",
"\"\"\"Call the callback.\"\"\"",
"try",
":",
"await",
"when_setup_cb",
"(",
"hass",
",",
"component",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"exception",
"(",
"\"Error handling when_setup callback for %s\"",
",",
"component",
")",
"# Running it in a new task so that it always runs after",
"if",
"component",
"in",
"hass",
".",
"config",
".",
"components",
":",
"hass",
".",
"async_create_task",
"(",
"when_setup",
"(",
")",
")",
"return",
"unsub",
"=",
"None",
"async",
"def",
"loaded_event",
"(",
"event",
":",
"core",
".",
"Event",
")",
"->",
"None",
":",
"\"\"\"Call the callback.\"\"\"",
"if",
"event",
".",
"data",
"[",
"ATTR_COMPONENT",
"]",
"!=",
"component",
":",
"return",
"unsub",
"(",
")",
"# type: ignore",
"await",
"when_setup",
"(",
")",
"unsub",
"=",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"EVENT_COMPONENT_LOADED",
",",
"loaded_event",
")"
] | [
350,
0
] | [
379,
71
] | python | en | ['en', 'en', 'en'] | True |
TelnetMock.__init__ | (self, host, port, timeout=0) | Initialize Telnet object. | Initialize Telnet object. | def __init__(self, host, port, timeout=0):
"""Initialize Telnet object."""
self.host = host
self.port = port
self.timeout = timeout
self.sample_data = bytes(
"|/dev/sda1|WDC WD30EZRX-12DC0B0|29|C|"
+ "|/dev/sdb1|WDC WD15EADS-11P7B2|32|C|"
+ "|/dev/sdc1|WDC WD20EARX-22MMMB0|29|C|"
+ "|/dev/sdd1|WDC WD15EARS-00Z5B1|89|F|",
"ascii",
) | [
"def",
"__init__",
"(",
"self",
",",
"host",
",",
"port",
",",
"timeout",
"=",
"0",
")",
":",
"self",
".",
"host",
"=",
"host",
"self",
".",
"port",
"=",
"port",
"self",
".",
"timeout",
"=",
"timeout",
"self",
".",
"sample_data",
"=",
"bytes",
"(",
"\"|/dev/sda1|WDC WD30EZRX-12DC0B0|29|C|\"",
"+",
"\"|/dev/sdb1|WDC WD15EADS-11P7B2|32|C|\"",
"+",
"\"|/dev/sdc1|WDC WD20EARX-22MMMB0|29|C|\"",
"+",
"\"|/dev/sdd1|WDC WD15EARS-00Z5B1|89|F|\"",
",",
"\"ascii\"",
",",
")"
] | [
34,
4
] | [
45,
9
] | python | fy | ['pl', 'fy', 'it'] | False |
TelnetMock.read_all | (self) | Return sample values. | Return sample values. | def read_all(self):
"""Return sample values."""
if self.host == "alice.local":
raise ConnectionRefusedError
if self.host == "bob.local":
raise socket.gaierror
return self.sample_data | [
"def",
"read_all",
"(",
"self",
")",
":",
"if",
"self",
".",
"host",
"==",
"\"alice.local\"",
":",
"raise",
"ConnectionRefusedError",
"if",
"self",
".",
"host",
"==",
"\"bob.local\"",
":",
"raise",
"socket",
".",
"gaierror",
"return",
"self",
".",
"sample_data"
] | [
47,
4
] | [
53,
31
] | python | en | ['en', 'et', 'en'] | True |
TestHDDTempSensor.setUp | (self) | Set up things to run when tests begin. | Set up things to run when tests begin. | def setUp(self):
"""Set up things to run when tests begin."""
self.hass = get_test_home_assistant()
self.config = VALID_CONFIG_ONE_DISK
self.reference = {
"/dev/sda1": {
"device": "/dev/sda1",
"temperature": "29",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD30EZRX-12DC0B0",
},
"/dev/sdb1": {
"device": "/dev/sdb1",
"temperature": "32",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD15EADS-11P7B2",
},
"/dev/sdc1": {
"device": "/dev/sdc1",
"temperature": "29",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD20EARX-22MMMB0",
},
"/dev/sdd1": {
"device": "/dev/sdd1",
"temperature": "32",
"unit_of_measurement": TEMP_CELSIUS,
"model": "WDC WD15EARS-00Z5B1",
},
}
self.addCleanup(self.hass.stop) | [
"def",
"setUp",
"(",
"self",
")",
":",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"config",
"=",
"VALID_CONFIG_ONE_DISK",
"self",
".",
"reference",
"=",
"{",
"\"/dev/sda1\"",
":",
"{",
"\"device\"",
":",
"\"/dev/sda1\"",
",",
"\"temperature\"",
":",
"\"29\"",
",",
"\"unit_of_measurement\"",
":",
"TEMP_CELSIUS",
",",
"\"model\"",
":",
"\"WDC WD30EZRX-12DC0B0\"",
",",
"}",
",",
"\"/dev/sdb1\"",
":",
"{",
"\"device\"",
":",
"\"/dev/sdb1\"",
",",
"\"temperature\"",
":",
"\"32\"",
",",
"\"unit_of_measurement\"",
":",
"TEMP_CELSIUS",
",",
"\"model\"",
":",
"\"WDC WD15EADS-11P7B2\"",
",",
"}",
",",
"\"/dev/sdc1\"",
":",
"{",
"\"device\"",
":",
"\"/dev/sdc1\"",
",",
"\"temperature\"",
":",
"\"29\"",
",",
"\"unit_of_measurement\"",
":",
"TEMP_CELSIUS",
",",
"\"model\"",
":",
"\"WDC WD20EARX-22MMMB0\"",
",",
"}",
",",
"\"/dev/sdd1\"",
":",
"{",
"\"device\"",
":",
"\"/dev/sdd1\"",
",",
"\"temperature\"",
":",
"\"32\"",
",",
"\"unit_of_measurement\"",
":",
"TEMP_CELSIUS",
",",
"\"model\"",
":",
"\"WDC WD15EARS-00Z5B1\"",
",",
"}",
",",
"}",
"self",
".",
"addCleanup",
"(",
"self",
".",
"hass",
".",
"stop",
")"
] | [
59,
4
] | [
89,
39
] | python | en | ['en', 'en', 'en'] | True |
TestHDDTempSensor.test_hddtemp_min_config | (self) | Test minimal hddtemp configuration. | Test minimal hddtemp configuration. | def test_hddtemp_min_config(self):
"""Test minimal hddtemp configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_MINIMAL)
self.hass.block_till_done()
entity = self.hass.states.all()[0].entity_id
state = self.hass.states.get(entity)
reference = self.reference[state.attributes.get("device")]
assert state.state == reference["temperature"]
assert state.attributes.get("device") == reference["device"]
assert state.attributes.get("model") == reference["model"]
assert (
state.attributes.get("unit_of_measurement")
== reference["unit_of_measurement"]
)
assert (
state.attributes.get("friendly_name")
== f"HD Temperature {reference['device']}"
) | [
"def",
"test_hddtemp_min_config",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_MINIMAL",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"entity",
"=",
"self",
".",
"hass",
".",
"states",
".",
"all",
"(",
")",
"[",
"0",
"]",
".",
"entity_id",
"state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"entity",
")",
"reference",
"=",
"self",
".",
"reference",
"[",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"]",
"assert",
"state",
".",
"state",
"==",
"reference",
"[",
"\"temperature\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"==",
"reference",
"[",
"\"device\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"model\"",
")",
"==",
"reference",
"[",
"\"model\"",
"]",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"reference",
"[",
"\"unit_of_measurement\"",
"]",
")",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"friendly_name\"",
")",
"==",
"f\"HD Temperature {reference['device']}\"",
")"
] | [
92,
4
] | [
112,
9
] | python | de | ['de', 'ro', 'en'] | False |
TestHDDTempSensor.test_hddtemp_rename_config | (self) | Test hddtemp configuration with different name. | Test hddtemp configuration with different name. | def test_hddtemp_rename_config(self):
"""Test hddtemp configuration with different name."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_NAME)
self.hass.block_till_done()
entity = self.hass.states.all()[0].entity_id
state = self.hass.states.get(entity)
reference = self.reference[state.attributes.get("device")]
assert state.attributes.get("friendly_name") == f"FooBar {reference['device']}" | [
"def",
"test_hddtemp_rename_config",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_NAME",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"entity",
"=",
"self",
".",
"hass",
".",
"states",
".",
"all",
"(",
")",
"[",
"0",
"]",
".",
"entity_id",
"state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"entity",
")",
"reference",
"=",
"self",
".",
"reference",
"[",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"friendly_name\"",
")",
"==",
"f\"FooBar {reference['device']}\""
] | [
115,
4
] | [
125,
87
] | python | en | ['en', 'en', 'en'] | True |
TestHDDTempSensor.test_hddtemp_one_disk | (self) | Test hddtemp one disk configuration. | Test hddtemp one disk configuration. | def test_hddtemp_one_disk(self):
"""Test hddtemp one disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_ONE_DISK)
self.hass.block_till_done()
state = self.hass.states.get("sensor.hd_temperature_dev_sdd1")
reference = self.reference[state.attributes.get("device")]
assert state.state == reference["temperature"]
assert state.attributes.get("device") == reference["device"]
assert state.attributes.get("model") == reference["model"]
assert (
state.attributes.get("unit_of_measurement")
== reference["unit_of_measurement"]
)
assert (
state.attributes.get("friendly_name")
== f"HD Temperature {reference['device']}"
) | [
"def",
"test_hddtemp_one_disk",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_ONE_DISK",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.hd_temperature_dev_sdd1\"",
")",
"reference",
"=",
"self",
".",
"reference",
"[",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"]",
"assert",
"state",
".",
"state",
"==",
"reference",
"[",
"\"temperature\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"==",
"reference",
"[",
"\"device\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"model\"",
")",
"==",
"reference",
"[",
"\"model\"",
"]",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"reference",
"[",
"\"unit_of_measurement\"",
"]",
")",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"friendly_name\"",
")",
"==",
"f\"HD Temperature {reference['device']}\"",
")"
] | [
128,
4
] | [
147,
9
] | python | en | ['da', 'en', 'en'] | True |
TestHDDTempSensor.test_hddtemp_wrong_disk | (self) | Test hddtemp wrong disk configuration. | Test hddtemp wrong disk configuration. | def test_hddtemp_wrong_disk(self):
"""Test hddtemp wrong disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_WRONG_DISK)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 1
state = self.hass.states.get("sensor.hd_temperature_dev_sdx1")
assert state.attributes.get("friendly_name") == "HD Temperature /dev/sdx1" | [
"def",
"test_hddtemp_wrong_disk",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_WRONG_DISK",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"hass",
".",
"states",
".",
"all",
"(",
")",
")",
"==",
"1",
"state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.hd_temperature_dev_sdx1\"",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"friendly_name\"",
")",
"==",
"\"HD Temperature /dev/sdx1\""
] | [
150,
4
] | [
157,
82
] | python | en | ['id', 'en', 'en'] | True |
TestHDDTempSensor.test_hddtemp_multiple_disks | (self) | Test hddtemp multiple disk configuration. | Test hddtemp multiple disk configuration. | def test_hddtemp_multiple_disks(self):
"""Test hddtemp multiple disk configuration."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_MULTIPLE_DISKS)
self.hass.block_till_done()
for sensor in [
"sensor.hd_temperature_dev_sda1",
"sensor.hd_temperature_dev_sdb1",
"sensor.hd_temperature_dev_sdc1",
]:
state = self.hass.states.get(sensor)
reference = self.reference[state.attributes.get("device")]
assert state.state == reference["temperature"]
assert state.attributes.get("device") == reference["device"]
assert state.attributes.get("model") == reference["model"]
assert (
state.attributes.get("unit_of_measurement")
== reference["unit_of_measurement"]
)
assert (
state.attributes.get("friendly_name")
== f"HD Temperature {reference['device']}"
) | [
"def",
"test_hddtemp_multiple_disks",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_MULTIPLE_DISKS",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"for",
"sensor",
"in",
"[",
"\"sensor.hd_temperature_dev_sda1\"",
",",
"\"sensor.hd_temperature_dev_sdb1\"",
",",
"\"sensor.hd_temperature_dev_sdc1\"",
",",
"]",
":",
"state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"sensor",
")",
"reference",
"=",
"self",
".",
"reference",
"[",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"]",
"assert",
"state",
".",
"state",
"==",
"reference",
"[",
"\"temperature\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"device\"",
")",
"==",
"reference",
"[",
"\"device\"",
"]",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"model\"",
")",
"==",
"reference",
"[",
"\"model\"",
"]",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"unit_of_measurement\"",
")",
"==",
"reference",
"[",
"\"unit_of_measurement\"",
"]",
")",
"assert",
"(",
"state",
".",
"attributes",
".",
"get",
"(",
"\"friendly_name\"",
")",
"==",
"f\"HD Temperature {reference['device']}\"",
")"
] | [
160,
4
] | [
185,
13
] | python | da | ['da', 'da', 'en'] | True |
TestHDDTempSensor.test_hddtemp_host_refused | (self) | Test hddtemp if host unreachable. | Test hddtemp if host unreachable. | def test_hddtemp_host_refused(self):
"""Test hddtemp if host unreachable."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_HOST)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 0 | [
"def",
"test_hddtemp_host_refused",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_HOST",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"hass",
".",
"states",
".",
"all",
"(",
")",
")",
"==",
"0"
] | [
188,
4
] | [
192,
47
] | python | en | ['de', 'en', 'en'] | True |
TestHDDTempSensor.test_hddtemp_host_unreachable | (self) | Test hddtemp if host unreachable. | Test hddtemp if host unreachable. | def test_hddtemp_host_unreachable(self):
"""Test hddtemp if host unreachable."""
assert setup_component(self.hass, "sensor", VALID_CONFIG_HOST_UNREACHABLE)
self.hass.block_till_done()
assert len(self.hass.states.all()) == 0 | [
"def",
"test_hddtemp_host_unreachable",
"(",
"self",
")",
":",
"assert",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"sensor\"",
",",
"VALID_CONFIG_HOST_UNREACHABLE",
")",
"self",
".",
"hass",
".",
"block_till_done",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"hass",
".",
"states",
".",
"all",
"(",
")",
")",
"==",
"0"
] | [
195,
4
] | [
199,
47
] | python | en | ['de', 'en', 'en'] | True |
test_signal_messenger_init | (hass) | Test that service loads successfully. | Test that service loads successfully. | async def test_signal_messenger_init(hass):
"""Test that service loads successfully."""
config = {
BASE_COMPONENT: {
"name": "test",
"platform": "signal_messenger",
"url": "http://127.0.0.1:8080",
"number": "+43443434343",
"recipients": ["+435565656565"],
}
}
with patch("pysignalclirestapi.SignalCliRestApi.send_message", return_value=None):
assert await async_setup_component(hass, BASE_COMPONENT, config)
await hass.async_block_till_done()
# Test that service loads successfully
assert hass.services.has_service(BASE_COMPONENT, "test") | [
"async",
"def",
"test_signal_messenger_init",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"BASE_COMPONENT",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"signal_messenger\"",
",",
"\"url\"",
":",
"\"http://127.0.0.1:8080\"",
",",
"\"number\"",
":",
"\"+43443434343\"",
",",
"\"recipients\"",
":",
"[",
"\"+435565656565\"",
"]",
",",
"}",
"}",
"with",
"patch",
"(",
"\"pysignalclirestapi.SignalCliRestApi.send_message\"",
",",
"return_value",
"=",
"None",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"BASE_COMPONENT",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# Test that service loads successfully",
"assert",
"hass",
".",
"services",
".",
"has_service",
"(",
"BASE_COMPONENT",
",",
"\"test\"",
")"
] | [
17,
0
] | [
35,
64
] | python | en | ['en', 'en', 'en'] | True |
TestSignalMesssenger.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self):
"""Set up things to be run when tests are started."""
recipients = ["+435565656565"]
number = "+43443434343"
client = SignalCliRestApi("http://127.0.0.1:8080", number)
self._signalmessenger = signalmessenger.SignalNotificationService(
recipients, client
) | [
"def",
"setUp",
"(",
"self",
")",
":",
"recipients",
"=",
"[",
"\"+435565656565\"",
"]",
"number",
"=",
"\"+43443434343\"",
"client",
"=",
"SignalCliRestApi",
"(",
"\"http://127.0.0.1:8080\"",
",",
"number",
")",
"self",
".",
"_signalmessenger",
"=",
"signalmessenger",
".",
"SignalNotificationService",
"(",
"recipients",
",",
"client",
")"
] | [
41,
4
] | [
48,
9
] | python | en | ['en', 'en', 'en'] | True |
TestSignalMesssenger.test_send_message | (self, mock) | Test send message. | Test send message. | def test_send_message(self, mock):
"""Test send message."""
message = "Testing Signal Messenger platform :)"
mock.register_uri(
"POST",
"http://127.0.0.1:8080/v2/send",
status_code=201,
)
mock.register_uri(
"GET",
"http://127.0.0.1:8080/v1/about",
status_code=200,
json={"versions": ["v1", "v2"]},
)
with self.assertLogs(
"homeassistant.components.signal_messenger.notify", level="DEBUG"
) as context:
self._signalmessenger.send_message(message)
self.assertIn("Sending signal message", context.output[0])
self.assertTrue(mock.called)
self.assertEqual(mock.call_count, 2) | [
"def",
"test_send_message",
"(",
"self",
",",
"mock",
")",
":",
"message",
"=",
"\"Testing Signal Messenger platform :)\"",
"mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"http://127.0.0.1:8080/v2/send\"",
",",
"status_code",
"=",
"201",
",",
")",
"mock",
".",
"register_uri",
"(",
"\"GET\"",
",",
"\"http://127.0.0.1:8080/v1/about\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"versions\"",
":",
"[",
"\"v1\"",
",",
"\"v2\"",
"]",
"}",
",",
")",
"with",
"self",
".",
"assertLogs",
"(",
"\"homeassistant.components.signal_messenger.notify\"",
",",
"level",
"=",
"\"DEBUG\"",
")",
"as",
"context",
":",
"self",
".",
"_signalmessenger",
".",
"send_message",
"(",
"message",
")",
"self",
".",
"assertIn",
"(",
"\"Sending signal message\"",
",",
"context",
".",
"output",
"[",
"0",
"]",
")",
"self",
".",
"assertTrue",
"(",
"mock",
".",
"called",
")",
"self",
".",
"assertEqual",
"(",
"mock",
".",
"call_count",
",",
"2",
")"
] | [
51,
4
] | [
71,
44
] | python | en | ['en', 'de', 'en'] | True |
TestSignalMesssenger.test_send_message_should_show_deprecation_warning | (self, mock) | Test send message. | Test send message. | def test_send_message_should_show_deprecation_warning(self, mock):
"""Test send message."""
message = "Testing Signal Messenger platform with attachment :)"
mock.register_uri(
"POST",
"http://127.0.0.1:8080/v2/send",
status_code=201,
)
mock.register_uri(
"GET",
"http://127.0.0.1:8080/v1/about",
status_code=200,
json={"versions": ["v1", "v2"]},
)
with self.assertLogs(
"homeassistant.components.signal_messenger.notify", level="WARNING"
) as context:
with tempfile.NamedTemporaryFile(
suffix=".png", prefix=os.path.basename(__file__)
) as tf:
data = {"data": {"attachment": tf.name}}
self._signalmessenger.send_message(message, **data)
self.assertIn(
"The 'attachment' option is deprecated, please replace it with 'attachments'. This option will become invalid in version 0.108",
context.output[0],
)
self.assertTrue(mock.called)
self.assertEqual(mock.call_count, 2) | [
"def",
"test_send_message_should_show_deprecation_warning",
"(",
"self",
",",
"mock",
")",
":",
"message",
"=",
"\"Testing Signal Messenger platform with attachment :)\"",
"mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"http://127.0.0.1:8080/v2/send\"",
",",
"status_code",
"=",
"201",
",",
")",
"mock",
".",
"register_uri",
"(",
"\"GET\"",
",",
"\"http://127.0.0.1:8080/v1/about\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"versions\"",
":",
"[",
"\"v1\"",
",",
"\"v2\"",
"]",
"}",
",",
")",
"with",
"self",
".",
"assertLogs",
"(",
"\"homeassistant.components.signal_messenger.notify\"",
",",
"level",
"=",
"\"WARNING\"",
")",
"as",
"context",
":",
"with",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"suffix",
"=",
"\".png\"",
",",
"prefix",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"__file__",
")",
")",
"as",
"tf",
":",
"data",
"=",
"{",
"\"data\"",
":",
"{",
"\"attachment\"",
":",
"tf",
".",
"name",
"}",
"}",
"self",
".",
"_signalmessenger",
".",
"send_message",
"(",
"message",
",",
"*",
"*",
"data",
")",
"self",
".",
"assertIn",
"(",
"\"The 'attachment' option is deprecated, please replace it with 'attachments'. This option will become invalid in version 0.108\"",
",",
"context",
".",
"output",
"[",
"0",
"]",
",",
")",
"self",
".",
"assertTrue",
"(",
"mock",
".",
"called",
")",
"self",
".",
"assertEqual",
"(",
"mock",
".",
"call_count",
",",
"2",
")"
] | [
74,
4
] | [
101,
44
] | python | en | ['en', 'de', 'en'] | True |
TestSignalMesssenger.test_send_message_with_attachment | (self, mock) | Test send message. | Test send message. | def test_send_message_with_attachment(self, mock):
"""Test send message."""
message = "Testing Signal Messenger platform :)"
mock.register_uri(
"POST",
"http://127.0.0.1:8080/v2/send",
status_code=201,
)
mock.register_uri(
"GET",
"http://127.0.0.1:8080/v1/about",
status_code=200,
json={"versions": ["v1", "v2"]},
)
with self.assertLogs(
"homeassistant.components.signal_messenger.notify", level="DEBUG"
) as context:
with tempfile.NamedTemporaryFile(
suffix=".png", prefix=os.path.basename(__file__)
) as tf:
data = {"data": {"attachments": [tf.name]}}
self._signalmessenger.send_message(message, **data)
self.assertIn("Sending signal message", context.output[0])
self.assertTrue(mock.called)
self.assertEqual(mock.call_count, 2) | [
"def",
"test_send_message_with_attachment",
"(",
"self",
",",
"mock",
")",
":",
"message",
"=",
"\"Testing Signal Messenger platform :)\"",
"mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"http://127.0.0.1:8080/v2/send\"",
",",
"status_code",
"=",
"201",
",",
")",
"mock",
".",
"register_uri",
"(",
"\"GET\"",
",",
"\"http://127.0.0.1:8080/v1/about\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"versions\"",
":",
"[",
"\"v1\"",
",",
"\"v2\"",
"]",
"}",
",",
")",
"with",
"self",
".",
"assertLogs",
"(",
"\"homeassistant.components.signal_messenger.notify\"",
",",
"level",
"=",
"\"DEBUG\"",
")",
"as",
"context",
":",
"with",
"tempfile",
".",
"NamedTemporaryFile",
"(",
"suffix",
"=",
"\".png\"",
",",
"prefix",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"__file__",
")",
")",
"as",
"tf",
":",
"data",
"=",
"{",
"\"data\"",
":",
"{",
"\"attachments\"",
":",
"[",
"tf",
".",
"name",
"]",
"}",
"}",
"self",
".",
"_signalmessenger",
".",
"send_message",
"(",
"message",
",",
"*",
"*",
"data",
")",
"self",
".",
"assertIn",
"(",
"\"Sending signal message\"",
",",
"context",
".",
"output",
"[",
"0",
"]",
")",
"self",
".",
"assertTrue",
"(",
"mock",
".",
"called",
")",
"self",
".",
"assertEqual",
"(",
"mock",
".",
"call_count",
",",
"2",
")"
] | [
104,
4
] | [
128,
44
] | python | en | ['en', 'de', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the generic thermostat platform. | Set up the generic thermostat platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the generic thermostat platform."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
name = config.get(CONF_NAME)
heater_entity_id = config.get(CONF_HEATER)
sensor_entity_id = config.get(CONF_SENSOR)
min_temp = config.get(CONF_MIN_TEMP)
max_temp = config.get(CONF_MAX_TEMP)
target_temp = config.get(CONF_TARGET_TEMP)
ac_mode = config.get(CONF_AC_MODE)
min_cycle_duration = config.get(CONF_MIN_DUR)
cold_tolerance = config.get(CONF_COLD_TOLERANCE)
hot_tolerance = config.get(CONF_HOT_TOLERANCE)
keep_alive = config.get(CONF_KEEP_ALIVE)
initial_hvac_mode = config.get(CONF_INITIAL_HVAC_MODE)
away_temp = config.get(CONF_AWAY_TEMP)
precision = config.get(CONF_PRECISION)
unit = hass.config.units.temperature_unit
async_add_entities(
[
GenericThermostat(
name,
heater_entity_id,
sensor_entity_id,
min_temp,
max_temp,
target_temp,
ac_mode,
min_cycle_duration,
cold_tolerance,
hot_tolerance,
keep_alive,
initial_hvac_mode,
away_temp,
precision,
unit,
)
]
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"heater_entity_id",
"=",
"config",
".",
"get",
"(",
"CONF_HEATER",
")",
"sensor_entity_id",
"=",
"config",
".",
"get",
"(",
"CONF_SENSOR",
")",
"min_temp",
"=",
"config",
".",
"get",
"(",
"CONF_MIN_TEMP",
")",
"max_temp",
"=",
"config",
".",
"get",
"(",
"CONF_MAX_TEMP",
")",
"target_temp",
"=",
"config",
".",
"get",
"(",
"CONF_TARGET_TEMP",
")",
"ac_mode",
"=",
"config",
".",
"get",
"(",
"CONF_AC_MODE",
")",
"min_cycle_duration",
"=",
"config",
".",
"get",
"(",
"CONF_MIN_DUR",
")",
"cold_tolerance",
"=",
"config",
".",
"get",
"(",
"CONF_COLD_TOLERANCE",
")",
"hot_tolerance",
"=",
"config",
".",
"get",
"(",
"CONF_HOT_TOLERANCE",
")",
"keep_alive",
"=",
"config",
".",
"get",
"(",
"CONF_KEEP_ALIVE",
")",
"initial_hvac_mode",
"=",
"config",
".",
"get",
"(",
"CONF_INITIAL_HVAC_MODE",
")",
"away_temp",
"=",
"config",
".",
"get",
"(",
"CONF_AWAY_TEMP",
")",
"precision",
"=",
"config",
".",
"get",
"(",
"CONF_PRECISION",
")",
"unit",
"=",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit",
"async_add_entities",
"(",
"[",
"GenericThermostat",
"(",
"name",
",",
"heater_entity_id",
",",
"sensor_entity_id",
",",
"min_temp",
",",
"max_temp",
",",
"target_temp",
",",
"ac_mode",
",",
"min_cycle_duration",
",",
"cold_tolerance",
",",
"hot_tolerance",
",",
"keep_alive",
",",
"initial_hvac_mode",
",",
"away_temp",
",",
"precision",
",",
"unit",
",",
")",
"]",
")"
] | [
91,
0
] | [
132,
5
] | python | en | ['en', 'da', 'en'] | True |
GenericThermostat.__init__ | (
self,
name,
heater_entity_id,
sensor_entity_id,
min_temp,
max_temp,
target_temp,
ac_mode,
min_cycle_duration,
cold_tolerance,
hot_tolerance,
keep_alive,
initial_hvac_mode,
away_temp,
precision,
unit,
) | Initialize the thermostat. | Initialize the thermostat. | def __init__(
self,
name,
heater_entity_id,
sensor_entity_id,
min_temp,
max_temp,
target_temp,
ac_mode,
min_cycle_duration,
cold_tolerance,
hot_tolerance,
keep_alive,
initial_hvac_mode,
away_temp,
precision,
unit,
):
"""Initialize the thermostat."""
self._name = name
self.heater_entity_id = heater_entity_id
self.sensor_entity_id = sensor_entity_id
self.ac_mode = ac_mode
self.min_cycle_duration = min_cycle_duration
self._cold_tolerance = cold_tolerance
self._hot_tolerance = hot_tolerance
self._keep_alive = keep_alive
self._hvac_mode = initial_hvac_mode
self._saved_target_temp = target_temp or away_temp
self._temp_precision = precision
if self.ac_mode:
self._hvac_list = [HVAC_MODE_COOL, HVAC_MODE_OFF]
else:
self._hvac_list = [HVAC_MODE_HEAT, HVAC_MODE_OFF]
self._active = False
self._cur_temp = None
self._temp_lock = asyncio.Lock()
self._min_temp = min_temp
self._max_temp = max_temp
self._target_temp = target_temp
self._unit = unit
self._support_flags = SUPPORT_FLAGS
if away_temp:
self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE
self._away_temp = away_temp
self._is_away = False | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"heater_entity_id",
",",
"sensor_entity_id",
",",
"min_temp",
",",
"max_temp",
",",
"target_temp",
",",
"ac_mode",
",",
"min_cycle_duration",
",",
"cold_tolerance",
",",
"hot_tolerance",
",",
"keep_alive",
",",
"initial_hvac_mode",
",",
"away_temp",
",",
"precision",
",",
"unit",
",",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"heater_entity_id",
"=",
"heater_entity_id",
"self",
".",
"sensor_entity_id",
"=",
"sensor_entity_id",
"self",
".",
"ac_mode",
"=",
"ac_mode",
"self",
".",
"min_cycle_duration",
"=",
"min_cycle_duration",
"self",
".",
"_cold_tolerance",
"=",
"cold_tolerance",
"self",
".",
"_hot_tolerance",
"=",
"hot_tolerance",
"self",
".",
"_keep_alive",
"=",
"keep_alive",
"self",
".",
"_hvac_mode",
"=",
"initial_hvac_mode",
"self",
".",
"_saved_target_temp",
"=",
"target_temp",
"or",
"away_temp",
"self",
".",
"_temp_precision",
"=",
"precision",
"if",
"self",
".",
"ac_mode",
":",
"self",
".",
"_hvac_list",
"=",
"[",
"HVAC_MODE_COOL",
",",
"HVAC_MODE_OFF",
"]",
"else",
":",
"self",
".",
"_hvac_list",
"=",
"[",
"HVAC_MODE_HEAT",
",",
"HVAC_MODE_OFF",
"]",
"self",
".",
"_active",
"=",
"False",
"self",
".",
"_cur_temp",
"=",
"None",
"self",
".",
"_temp_lock",
"=",
"asyncio",
".",
"Lock",
"(",
")",
"self",
".",
"_min_temp",
"=",
"min_temp",
"self",
".",
"_max_temp",
"=",
"max_temp",
"self",
".",
"_target_temp",
"=",
"target_temp",
"self",
".",
"_unit",
"=",
"unit",
"self",
".",
"_support_flags",
"=",
"SUPPORT_FLAGS",
"if",
"away_temp",
":",
"self",
".",
"_support_flags",
"=",
"SUPPORT_FLAGS",
"|",
"SUPPORT_PRESET_MODE",
"self",
".",
"_away_temp",
"=",
"away_temp",
"self",
".",
"_is_away",
"=",
"False"
] | [
138,
4
] | [
183,
29
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.async_added_to_hass | (self) | Run when entity about to be added. | Run when entity about to be added. | async def async_added_to_hass(self):
"""Run when entity about to be added."""
await super().async_added_to_hass()
# Add listener
self.async_on_remove(
async_track_state_change_event(
self.hass, [self.sensor_entity_id], self._async_sensor_changed
)
)
self.async_on_remove(
async_track_state_change_event(
self.hass, [self.heater_entity_id], self._async_switch_changed
)
)
if self._keep_alive:
self.async_on_remove(
async_track_time_interval(
self.hass, self._async_control_heating, self._keep_alive
)
)
@callback
def _async_startup(event):
"""Init on startup."""
sensor_state = self.hass.states.get(self.sensor_entity_id)
if sensor_state and sensor_state.state not in (
STATE_UNAVAILABLE,
STATE_UNKNOWN,
):
self._async_update_temp(sensor_state)
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, _async_startup)
# Check If we have an old state
old_state = await self.async_get_last_state()
if old_state is not None:
# If we have no initial temperature, restore
if self._target_temp is None:
# If we have a previously saved temperature
if old_state.attributes.get(ATTR_TEMPERATURE) is None:
if self.ac_mode:
self._target_temp = self.max_temp
else:
self._target_temp = self.min_temp
_LOGGER.warning(
"Undefined target temperature, falling back to %s",
self._target_temp,
)
else:
self._target_temp = float(old_state.attributes[ATTR_TEMPERATURE])
if old_state.attributes.get(ATTR_PRESET_MODE) == PRESET_AWAY:
self._is_away = True
if not self._hvac_mode and old_state.state:
self._hvac_mode = old_state.state
else:
# No previous state, try and restore defaults
if self._target_temp is None:
if self.ac_mode:
self._target_temp = self.max_temp
else:
self._target_temp = self.min_temp
_LOGGER.warning(
"No previously saved temperature, setting to %s", self._target_temp
)
# Set default state to off
if not self._hvac_mode:
self._hvac_mode = HVAC_MODE_OFF | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"# Add listener",
"self",
".",
"async_on_remove",
"(",
"async_track_state_change_event",
"(",
"self",
".",
"hass",
",",
"[",
"self",
".",
"sensor_entity_id",
"]",
",",
"self",
".",
"_async_sensor_changed",
")",
")",
"self",
".",
"async_on_remove",
"(",
"async_track_state_change_event",
"(",
"self",
".",
"hass",
",",
"[",
"self",
".",
"heater_entity_id",
"]",
",",
"self",
".",
"_async_switch_changed",
")",
")",
"if",
"self",
".",
"_keep_alive",
":",
"self",
".",
"async_on_remove",
"(",
"async_track_time_interval",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_async_control_heating",
",",
"self",
".",
"_keep_alive",
")",
")",
"@",
"callback",
"def",
"_async_startup",
"(",
"event",
")",
":",
"\"\"\"Init on startup.\"\"\"",
"sensor_state",
"=",
"self",
".",
"hass",
".",
"states",
".",
"get",
"(",
"self",
".",
"sensor_entity_id",
")",
"if",
"sensor_state",
"and",
"sensor_state",
".",
"state",
"not",
"in",
"(",
"STATE_UNAVAILABLE",
",",
"STATE_UNKNOWN",
",",
")",
":",
"self",
".",
"_async_update_temp",
"(",
"sensor_state",
")",
"self",
".",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_START",
",",
"_async_startup",
")",
"# Check If we have an old state",
"old_state",
"=",
"await",
"self",
".",
"async_get_last_state",
"(",
")",
"if",
"old_state",
"is",
"not",
"None",
":",
"# If we have no initial temperature, restore",
"if",
"self",
".",
"_target_temp",
"is",
"None",
":",
"# If we have a previously saved temperature",
"if",
"old_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"is",
"None",
":",
"if",
"self",
".",
"ac_mode",
":",
"self",
".",
"_target_temp",
"=",
"self",
".",
"max_temp",
"else",
":",
"self",
".",
"_target_temp",
"=",
"self",
".",
"min_temp",
"_LOGGER",
".",
"warning",
"(",
"\"Undefined target temperature, falling back to %s\"",
",",
"self",
".",
"_target_temp",
",",
")",
"else",
":",
"self",
".",
"_target_temp",
"=",
"float",
"(",
"old_state",
".",
"attributes",
"[",
"ATTR_TEMPERATURE",
"]",
")",
"if",
"old_state",
".",
"attributes",
".",
"get",
"(",
"ATTR_PRESET_MODE",
")",
"==",
"PRESET_AWAY",
":",
"self",
".",
"_is_away",
"=",
"True",
"if",
"not",
"self",
".",
"_hvac_mode",
"and",
"old_state",
".",
"state",
":",
"self",
".",
"_hvac_mode",
"=",
"old_state",
".",
"state",
"else",
":",
"# No previous state, try and restore defaults",
"if",
"self",
".",
"_target_temp",
"is",
"None",
":",
"if",
"self",
".",
"ac_mode",
":",
"self",
".",
"_target_temp",
"=",
"self",
".",
"max_temp",
"else",
":",
"self",
".",
"_target_temp",
"=",
"self",
".",
"min_temp",
"_LOGGER",
".",
"warning",
"(",
"\"No previously saved temperature, setting to %s\"",
",",
"self",
".",
"_target_temp",
")",
"# Set default state to off",
"if",
"not",
"self",
".",
"_hvac_mode",
":",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_OFF"
] | [
185,
4
] | [
255,
43
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.should_poll | (self) | Return the polling state. | Return the polling state. | def should_poll(self):
"""Return the polling state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
258,
4
] | [
260,
20
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.name | (self) | Return the name of the thermostat. | Return the name of the thermostat. | def name(self):
"""Return the name of the thermostat."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
263,
4
] | [
265,
25
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.precision | (self) | Return the precision of the system. | Return the precision of the system. | def precision(self):
"""Return the precision of the system."""
if self._temp_precision is not None:
return self._temp_precision
return super().precision | [
"def",
"precision",
"(",
"self",
")",
":",
"if",
"self",
".",
"_temp_precision",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_temp_precision",
"return",
"super",
"(",
")",
".",
"precision"
] | [
268,
4
] | [
272,
32
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.temperature_unit | (self) | Return the unit of measurement. | Return the unit of measurement. | def temperature_unit(self):
"""Return the unit of measurement."""
return self._unit | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit"
] | [
275,
4
] | [
277,
25
] | python | en | ['en', 'la', 'en'] | True |
GenericThermostat.current_temperature | (self) | Return the sensor temperature. | Return the sensor temperature. | def current_temperature(self):
"""Return the sensor temperature."""
return self._cur_temp | [
"def",
"current_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_cur_temp"
] | [
280,
4
] | [
282,
29
] | python | en | ['en', 'la', 'en'] | True |
GenericThermostat.hvac_mode | (self) | Return current operation. | Return current operation. | def hvac_mode(self):
"""Return current operation."""
return self._hvac_mode | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hvac_mode"
] | [
285,
4
] | [
287,
30
] | python | bg | ['nl', 'bg', 'en'] | False |
GenericThermostat.hvac_action | (self) | Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
| Return the current running hvac operation if supported. | def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
if self._hvac_mode == HVAC_MODE_OFF:
return CURRENT_HVAC_OFF
if not self._is_device_active:
return CURRENT_HVAC_IDLE
if self.ac_mode:
return CURRENT_HVAC_COOL
return CURRENT_HVAC_HEAT | [
"def",
"hvac_action",
"(",
"self",
")",
":",
"if",
"self",
".",
"_hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"return",
"CURRENT_HVAC_OFF",
"if",
"not",
"self",
".",
"_is_device_active",
":",
"return",
"CURRENT_HVAC_IDLE",
"if",
"self",
".",
"ac_mode",
":",
"return",
"CURRENT_HVAC_COOL",
"return",
"CURRENT_HVAC_HEAT"
] | [
290,
4
] | [
301,
32
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.target_temperature | (self) | Return the temperature we try to reach. | Return the temperature we try to reach. | def target_temperature(self):
"""Return the temperature we try to reach."""
return self._target_temp | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_target_temp"
] | [
304,
4
] | [
306,
32
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.hvac_modes | (self) | List of available operation modes. | List of available operation modes. | def hvac_modes(self):
"""List of available operation modes."""
return self._hvac_list | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hvac_list"
] | [
309,
4
] | [
311,
30
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.preset_mode | (self) | Return the current preset mode, e.g., home, away, temp. | Return the current preset mode, e.g., home, away, temp. | def preset_mode(self):
"""Return the current preset mode, e.g., home, away, temp."""
return PRESET_AWAY if self._is_away else PRESET_NONE | [
"def",
"preset_mode",
"(",
"self",
")",
":",
"return",
"PRESET_AWAY",
"if",
"self",
".",
"_is_away",
"else",
"PRESET_NONE"
] | [
314,
4
] | [
316,
60
] | python | en | ['en', 'pt', 'en'] | True |
GenericThermostat.preset_modes | (self) | Return a list of available preset modes or PRESET_NONE if _away_temp is undefined. | Return a list of available preset modes or PRESET_NONE if _away_temp is undefined. | def preset_modes(self):
"""Return a list of available preset modes or PRESET_NONE if _away_temp is undefined."""
return [PRESET_NONE, PRESET_AWAY] if self._away_temp else PRESET_NONE | [
"def",
"preset_modes",
"(",
"self",
")",
":",
"return",
"[",
"PRESET_NONE",
",",
"PRESET_AWAY",
"]",
"if",
"self",
".",
"_away_temp",
"else",
"PRESET_NONE"
] | [
319,
4
] | [
321,
77
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.async_set_hvac_mode | (self, hvac_mode) | Set hvac mode. | Set hvac mode. | async def async_set_hvac_mode(self, hvac_mode):
"""Set hvac mode."""
if hvac_mode == HVAC_MODE_HEAT:
self._hvac_mode = HVAC_MODE_HEAT
await self._async_control_heating(force=True)
elif hvac_mode == HVAC_MODE_COOL:
self._hvac_mode = HVAC_MODE_COOL
await self._async_control_heating(force=True)
elif hvac_mode == HVAC_MODE_OFF:
self._hvac_mode = HVAC_MODE_OFF
if self._is_device_active:
await self._async_heater_turn_off()
else:
_LOGGER.error("Unrecognized hvac mode: %s", hvac_mode)
return
# Ensure we update the current operation after changing the mode
self.async_write_ha_state() | [
"async",
"def",
"async_set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":",
"if",
"hvac_mode",
"==",
"HVAC_MODE_HEAT",
":",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_HEAT",
"await",
"self",
".",
"_async_control_heating",
"(",
"force",
"=",
"True",
")",
"elif",
"hvac_mode",
"==",
"HVAC_MODE_COOL",
":",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_COOL",
"await",
"self",
".",
"_async_control_heating",
"(",
"force",
"=",
"True",
")",
"elif",
"hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_OFF",
"if",
"self",
".",
"_is_device_active",
":",
"await",
"self",
".",
"_async_heater_turn_off",
"(",
")",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unrecognized hvac mode: %s\"",
",",
"hvac_mode",
")",
"return",
"# Ensure we update the current operation after changing the mode",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
323,
4
] | [
339,
35
] | python | da | ['da', 'pt', 'ru'] | False |
GenericThermostat.async_set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
self._target_temp = temperature
await self._async_control_heating(force=True)
self.async_write_ha_state() | [
"async",
"def",
"async_set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"if",
"temperature",
"is",
"None",
":",
"return",
"self",
".",
"_target_temp",
"=",
"temperature",
"await",
"self",
".",
"_async_control_heating",
"(",
"force",
"=",
"True",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
341,
4
] | [
348,
35
] | python | en | ['en', 'ca', 'en'] | True |
GenericThermostat.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self):
"""Return the minimum temperature."""
if self._min_temp is not None:
return self._min_temp
# get default temp from super class
return super().min_temp | [
"def",
"min_temp",
"(",
"self",
")",
":",
"if",
"self",
".",
"_min_temp",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_min_temp",
"# get default temp from super class",
"return",
"super",
"(",
")",
".",
"min_temp"
] | [
351,
4
] | [
357,
31
] | python | en | ['en', 'la', 'en'] | True |
GenericThermostat.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self):
"""Return the maximum temperature."""
if self._max_temp is not None:
return self._max_temp
# Get default temp from super class
return super().max_temp | [
"def",
"max_temp",
"(",
"self",
")",
":",
"if",
"self",
".",
"_max_temp",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_max_temp",
"# Get default temp from super class",
"return",
"super",
"(",
")",
".",
"max_temp"
] | [
360,
4
] | [
366,
31
] | python | en | ['en', 'la', 'en'] | True |
GenericThermostat._async_sensor_changed | (self, event) | Handle temperature changes. | Handle temperature changes. | async def _async_sensor_changed(self, event):
"""Handle temperature changes."""
new_state = event.data.get("new_state")
if new_state is None or new_state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
return
self._async_update_temp(new_state)
await self._async_control_heating()
self.async_write_ha_state() | [
"async",
"def",
"_async_sensor_changed",
"(",
"self",
",",
"event",
")",
":",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",
")",
"if",
"new_state",
"is",
"None",
"or",
"new_state",
".",
"state",
"in",
"(",
"STATE_UNAVAILABLE",
",",
"STATE_UNKNOWN",
")",
":",
"return",
"self",
".",
"_async_update_temp",
"(",
"new_state",
")",
"await",
"self",
".",
"_async_control_heating",
"(",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
368,
4
] | [
376,
35
] | python | en | ['en', 'fr', 'en'] | True |
GenericThermostat._async_switch_changed | (self, event) | Handle heater switch state changes. | Handle heater switch state changes. | def _async_switch_changed(self, event):
"""Handle heater switch state changes."""
new_state = event.data.get("new_state")
if new_state is None:
return
self.async_write_ha_state() | [
"def",
"_async_switch_changed",
"(",
"self",
",",
"event",
")",
":",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",
")",
"if",
"new_state",
"is",
"None",
":",
"return",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
379,
4
] | [
384,
35
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat._async_update_temp | (self, state) | Update thermostat with latest state from sensor. | Update thermostat with latest state from sensor. | def _async_update_temp(self, state):
"""Update thermostat with latest state from sensor."""
try:
self._cur_temp = float(state.state)
except ValueError as ex:
_LOGGER.error("Unable to update from sensor: %s", ex) | [
"def",
"_async_update_temp",
"(",
"self",
",",
"state",
")",
":",
"try",
":",
"self",
".",
"_cur_temp",
"=",
"float",
"(",
"state",
".",
"state",
")",
"except",
"ValueError",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to update from sensor: %s\"",
",",
"ex",
")"
] | [
387,
4
] | [
392,
65
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat._async_control_heating | (self, time=None, force=False) | Check if we need to turn heating on or off. | Check if we need to turn heating on or off. | async def _async_control_heating(self, time=None, force=False):
"""Check if we need to turn heating on or off."""
async with self._temp_lock:
if not self._active and None not in (self._cur_temp, self._target_temp):
self._active = True
_LOGGER.info(
"Obtained current and target temperature. "
"Generic thermostat active. %s, %s",
self._cur_temp,
self._target_temp,
)
if not self._active or self._hvac_mode == HVAC_MODE_OFF:
return
if not force and time is None:
# If the `force` argument is True, we
# ignore `min_cycle_duration`.
# If the `time` argument is not none, we were invoked for
# keep-alive purposes, and `min_cycle_duration` is irrelevant.
if self.min_cycle_duration:
if self._is_device_active:
current_state = STATE_ON
else:
current_state = HVAC_MODE_OFF
long_enough = condition.state(
self.hass,
self.heater_entity_id,
current_state,
self.min_cycle_duration,
)
if not long_enough:
return
too_cold = self._target_temp >= self._cur_temp + self._cold_tolerance
too_hot = self._cur_temp >= self._target_temp + self._hot_tolerance
if self._is_device_active:
if (self.ac_mode and too_cold) or (not self.ac_mode and too_hot):
_LOGGER.info("Turning off heater %s", self.heater_entity_id)
await self._async_heater_turn_off()
elif time is not None:
# The time argument is passed only in keep-alive case
_LOGGER.info(
"Keep-alive - Turning on heater heater %s",
self.heater_entity_id,
)
await self._async_heater_turn_on()
else:
if (self.ac_mode and too_hot) or (not self.ac_mode and too_cold):
_LOGGER.info("Turning on heater %s", self.heater_entity_id)
await self._async_heater_turn_on()
elif time is not None:
# The time argument is passed only in keep-alive case
_LOGGER.info(
"Keep-alive - Turning off heater %s", self.heater_entity_id
)
await self._async_heater_turn_off() | [
"async",
"def",
"_async_control_heating",
"(",
"self",
",",
"time",
"=",
"None",
",",
"force",
"=",
"False",
")",
":",
"async",
"with",
"self",
".",
"_temp_lock",
":",
"if",
"not",
"self",
".",
"_active",
"and",
"None",
"not",
"in",
"(",
"self",
".",
"_cur_temp",
",",
"self",
".",
"_target_temp",
")",
":",
"self",
".",
"_active",
"=",
"True",
"_LOGGER",
".",
"info",
"(",
"\"Obtained current and target temperature. \"",
"\"Generic thermostat active. %s, %s\"",
",",
"self",
".",
"_cur_temp",
",",
"self",
".",
"_target_temp",
",",
")",
"if",
"not",
"self",
".",
"_active",
"or",
"self",
".",
"_hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"return",
"if",
"not",
"force",
"and",
"time",
"is",
"None",
":",
"# If the `force` argument is True, we",
"# ignore `min_cycle_duration`.",
"# If the `time` argument is not none, we were invoked for",
"# keep-alive purposes, and `min_cycle_duration` is irrelevant.",
"if",
"self",
".",
"min_cycle_duration",
":",
"if",
"self",
".",
"_is_device_active",
":",
"current_state",
"=",
"STATE_ON",
"else",
":",
"current_state",
"=",
"HVAC_MODE_OFF",
"long_enough",
"=",
"condition",
".",
"state",
"(",
"self",
".",
"hass",
",",
"self",
".",
"heater_entity_id",
",",
"current_state",
",",
"self",
".",
"min_cycle_duration",
",",
")",
"if",
"not",
"long_enough",
":",
"return",
"too_cold",
"=",
"self",
".",
"_target_temp",
">=",
"self",
".",
"_cur_temp",
"+",
"self",
".",
"_cold_tolerance",
"too_hot",
"=",
"self",
".",
"_cur_temp",
">=",
"self",
".",
"_target_temp",
"+",
"self",
".",
"_hot_tolerance",
"if",
"self",
".",
"_is_device_active",
":",
"if",
"(",
"self",
".",
"ac_mode",
"and",
"too_cold",
")",
"or",
"(",
"not",
"self",
".",
"ac_mode",
"and",
"too_hot",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Turning off heater %s\"",
",",
"self",
".",
"heater_entity_id",
")",
"await",
"self",
".",
"_async_heater_turn_off",
"(",
")",
"elif",
"time",
"is",
"not",
"None",
":",
"# The time argument is passed only in keep-alive case",
"_LOGGER",
".",
"info",
"(",
"\"Keep-alive - Turning on heater heater %s\"",
",",
"self",
".",
"heater_entity_id",
",",
")",
"await",
"self",
".",
"_async_heater_turn_on",
"(",
")",
"else",
":",
"if",
"(",
"self",
".",
"ac_mode",
"and",
"too_hot",
")",
"or",
"(",
"not",
"self",
".",
"ac_mode",
"and",
"too_cold",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Turning on heater %s\"",
",",
"self",
".",
"heater_entity_id",
")",
"await",
"self",
".",
"_async_heater_turn_on",
"(",
")",
"elif",
"time",
"is",
"not",
"None",
":",
"# The time argument is passed only in keep-alive case",
"_LOGGER",
".",
"info",
"(",
"\"Keep-alive - Turning off heater %s\"",
",",
"self",
".",
"heater_entity_id",
")",
"await",
"self",
".",
"_async_heater_turn_off",
"(",
")"
] | [
394,
4
] | [
450,
55
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat._is_device_active | (self) | If the toggleable device is currently active. | If the toggleable device is currently active. | def _is_device_active(self):
"""If the toggleable device is currently active."""
return self.hass.states.is_state(self.heater_entity_id, STATE_ON) | [
"def",
"_is_device_active",
"(",
"self",
")",
":",
"return",
"self",
".",
"hass",
".",
"states",
".",
"is_state",
"(",
"self",
".",
"heater_entity_id",
",",
"STATE_ON",
")"
] | [
453,
4
] | [
455,
73
] | python | en | ['en', 'en', 'en'] | True |
GenericThermostat.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self):
"""Return the list of supported features."""
return self._support_flags | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_support_flags"
] | [
458,
4
] | [
460,
34
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.