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 |
---|---|---|---|---|---|---|---|---|---|---|---|
TuyaScene.activate | (self, **kwargs: Any) | Activate the scene. | Activate the scene. | def activate(self, **kwargs: Any) -> None:
"""Activate the scene."""
self._tuya.activate() | [
"def",
"activate",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"self",
".",
"_tuya",
".",
"activate",
"(",
")"
] | [
58,
4
] | [
60,
29
] | python | en | ['en', 'it', 'en'] | True |
device_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def device_reg(hass):
"""Return an empty, loaded, registry."""
return mock_device_registry(hass) | [
"def",
"device_reg",
"(",
"hass",
")",
":",
"return",
"mock_device_registry",
"(",
"hass",
")"
] | [
20,
0
] | [
22,
37
] | python | en | ['en', 'fy', 'en'] | True |
entity_reg | (hass) | Return an empty, loaded, registry. | Return an empty, loaded, registry. | def entity_reg(hass):
"""Return an empty, loaded, registry."""
return mock_registry(hass) | [
"def",
"entity_reg",
"(",
"hass",
")",
":",
"return",
"mock_registry",
"(",
"hass",
")"
] | [
26,
0
] | [
28,
30
] | python | en | ['en', 'fy', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
32,
0
] | [
34,
57
] | python | en | ['en', 'en', 'en'] | True |
test_get_conditions | (hass, device_reg, entity_reg) | Test we get the expected conditions from a climate. | Test we get the expected conditions from a climate. | async def test_get_conditions(hass, device_reg, entity_reg):
"""Test we get the expected conditions from a climate."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set(
f"{DOMAIN}.test_5678",
const.HVAC_MODE_COOL,
{
const.ATTR_HVAC_MODE: const.HVAC_MODE_COOL,
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
const.ATTR_PRESET_MODES: [const.PRESET_HOME, const.PRESET_AWAY],
},
)
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 17})
expected_conditions = [
{
"condition": "device",
"domain": DOMAIN,
"type": "is_hvac_mode",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
},
{
"condition": "device",
"domain": DOMAIN,
"type": "is_preset_mode",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
},
]
conditions = await async_get_device_automations(hass, "condition", device_entry.id)
assert_lists_same(conditions, expected_conditions) | [
"async",
"def",
"test_get_conditions",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"f\"{DOMAIN}.test_5678\"",
",",
"const",
".",
"HVAC_MODE_COOL",
",",
"{",
"const",
".",
"ATTR_HVAC_MODE",
":",
"const",
".",
"HVAC_MODE_COOL",
",",
"const",
".",
"ATTR_PRESET_MODE",
":",
"const",
".",
"PRESET_AWAY",
",",
"const",
".",
"ATTR_PRESET_MODES",
":",
"[",
"const",
".",
"PRESET_HOME",
",",
"const",
".",
"PRESET_AWAY",
"]",
",",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"climate.test_5678\"",
",",
"\"attributes\"",
",",
"{",
"\"supported_features\"",
":",
"17",
"}",
")",
"expected_conditions",
"=",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"is_hvac_mode\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_5678\"",
",",
"}",
",",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"is_preset_mode\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_5678\"",
",",
"}",
",",
"]",
"conditions",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"condition\"",
",",
"device_entry",
".",
"id",
")",
"assert_lists_same",
"(",
"conditions",
",",
"expected_conditions",
")"
] | [
37,
0
] | [
73,
54
] | python | en | ['en', 'en', 'en'] | True |
test_get_conditions_hvac_only | (hass, device_reg, entity_reg) | Test we get the expected conditions from a climate. | Test we get the expected conditions from a climate. | async def test_get_conditions_hvac_only(hass, device_reg, entity_reg):
"""Test we get the expected conditions from a climate."""
config_entry = MockConfigEntry(domain="test", data={})
config_entry.add_to_hass(hass)
device_entry = device_reg.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(device_registry.CONNECTION_NETWORK_MAC, "12:34:56:AB:CD:EF")},
)
entity_reg.async_get_or_create(DOMAIN, "test", "5678", device_id=device_entry.id)
hass.states.async_set(
f"{DOMAIN}.test_5678",
const.HVAC_MODE_COOL,
{
const.ATTR_HVAC_MODE: const.HVAC_MODE_COOL,
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
const.ATTR_PRESET_MODES: [const.PRESET_HOME, const.PRESET_AWAY],
},
)
hass.states.async_set("climate.test_5678", "attributes", {"supported_features": 1})
expected_conditions = [
{
"condition": "device",
"domain": DOMAIN,
"type": "is_hvac_mode",
"device_id": device_entry.id,
"entity_id": f"{DOMAIN}.test_5678",
}
]
conditions = await async_get_device_automations(hass, "condition", device_entry.id)
assert_lists_same(conditions, expected_conditions) | [
"async",
"def",
"test_get_conditions_hvac_only",
"(",
"hass",
",",
"device_reg",
",",
"entity_reg",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"\"test\"",
",",
"data",
"=",
"{",
"}",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"device_entry",
"=",
"device_reg",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"device_registry",
".",
"CONNECTION_NETWORK_MAC",
",",
"\"12:34:56:AB:CD:EF\"",
")",
"}",
",",
")",
"entity_reg",
".",
"async_get_or_create",
"(",
"DOMAIN",
",",
"\"test\"",
",",
"\"5678\"",
",",
"device_id",
"=",
"device_entry",
".",
"id",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"f\"{DOMAIN}.test_5678\"",
",",
"const",
".",
"HVAC_MODE_COOL",
",",
"{",
"const",
".",
"ATTR_HVAC_MODE",
":",
"const",
".",
"HVAC_MODE_COOL",
",",
"const",
".",
"ATTR_PRESET_MODE",
":",
"const",
".",
"PRESET_AWAY",
",",
"const",
".",
"ATTR_PRESET_MODES",
":",
"[",
"const",
".",
"PRESET_HOME",
",",
"const",
".",
"PRESET_AWAY",
"]",
",",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"climate.test_5678\"",
",",
"\"attributes\"",
",",
"{",
"\"supported_features\"",
":",
"1",
"}",
")",
"expected_conditions",
"=",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"type\"",
":",
"\"is_hvac_mode\"",
",",
"\"device_id\"",
":",
"device_entry",
".",
"id",
",",
"\"entity_id\"",
":",
"f\"{DOMAIN}.test_5678\"",
",",
"}",
"]",
"conditions",
"=",
"await",
"async_get_device_automations",
"(",
"hass",
",",
"\"condition\"",
",",
"device_entry",
".",
"id",
")",
"assert_lists_same",
"(",
"conditions",
",",
"expected_conditions",
")"
] | [
76,
0
] | [
105,
54
] | python | en | ['en', 'en', 'en'] | True |
test_if_state | (hass, calls) | Test for turn_on and turn_off conditions. | Test for turn_on and turn_off conditions. | async def test_if_state(hass, calls):
"""Test for turn_on and turn_off conditions."""
hass.states.async_set(
"climate.entity",
const.HVAC_MODE_COOL,
{
const.ATTR_HVAC_MODE: const.HVAC_MODE_COOL,
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
},
)
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: [
{
"trigger": {"platform": "event", "event_type": "test_event1"},
"condition": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": "climate.entity",
"type": "is_hvac_mode",
"hvac_mode": "cool",
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "is_hvac_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}"
},
},
},
{
"trigger": {"platform": "event", "event_type": "test_event2"},
"condition": [
{
"condition": "device",
"domain": DOMAIN,
"device_id": "",
"entity_id": "climate.entity",
"type": "is_preset_mode",
"preset_mode": "away",
}
],
"action": {
"service": "test.automation",
"data_template": {
"some": "is_preset_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}"
},
},
},
]
},
)
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "is_hvac_mode - event - test_event1"
hass.states.async_set(
"climate.entity",
const.HVAC_MODE_AUTO,
{
const.ATTR_HVAC_MODE: const.HVAC_MODE_AUTO,
const.ATTR_PRESET_MODE: const.PRESET_AWAY,
},
)
# Should not fire
hass.bus.async_fire("test_event1")
await hass.async_block_till_done()
assert len(calls) == 1
hass.bus.async_fire("test_event2")
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[1].data["some"] == "is_preset_mode - event - test_event2"
hass.states.async_set(
"climate.entity",
const.HVAC_MODE_AUTO,
{
const.ATTR_HVAC_MODE: const.HVAC_MODE_AUTO,
const.ATTR_PRESET_MODE: const.PRESET_HOME,
},
)
# Should not fire
hass.bus.async_fire("test_event2")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_state",
"(",
"hass",
",",
"calls",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"climate.entity\"",
",",
"const",
".",
"HVAC_MODE_COOL",
",",
"{",
"const",
".",
"ATTR_HVAC_MODE",
":",
"const",
".",
"HVAC_MODE_COOL",
",",
"const",
".",
"ATTR_PRESET_MODE",
":",
"const",
".",
"PRESET_AWAY",
",",
"}",
",",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"[",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event1\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"\"climate.entity\"",
",",
"\"type\"",
":",
"\"is_hvac_mode\"",
",",
"\"hvac_mode\"",
":",
"\"cool\"",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"is_hvac_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}\"",
"}",
",",
"}",
",",
"}",
",",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event2\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"device\"",
",",
"\"domain\"",
":",
"DOMAIN",
",",
"\"device_id\"",
":",
"\"\"",
",",
"\"entity_id\"",
":",
"\"climate.entity\"",
",",
"\"type\"",
":",
"\"is_preset_mode\"",
",",
"\"preset_mode\"",
":",
"\"away\"",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"is_preset_mode - {{ trigger.platform }} - {{ trigger.event.event_type }}\"",
"}",
",",
"}",
",",
"}",
",",
"]",
"}",
",",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"is_hvac_mode - event - test_event1\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"climate.entity\"",
",",
"const",
".",
"HVAC_MODE_AUTO",
",",
"{",
"const",
".",
"ATTR_HVAC_MODE",
":",
"const",
".",
"HVAC_MODE_AUTO",
",",
"const",
".",
"ATTR_PRESET_MODE",
":",
"const",
".",
"PRESET_AWAY",
",",
"}",
",",
")",
"# Should not fire",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event1\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event2\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2",
"assert",
"calls",
"[",
"1",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"is_preset_mode - event - test_event2\"",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"climate.entity\"",
",",
"const",
".",
"HVAC_MODE_AUTO",
",",
"{",
"const",
".",
"ATTR_HVAC_MODE",
":",
"const",
".",
"HVAC_MODE_AUTO",
",",
"const",
".",
"ATTR_PRESET_MODE",
":",
"const",
".",
"PRESET_HOME",
",",
"}",
",",
")",
"# Should not fire",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event2\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2"
] | [
108,
0
] | [
202,
26
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.clear | (self) | Clear current events. | Clear current events. | def clear(self):
"""Clear current events."""
# We just drop the next events reference, GC or EventPool will collect them.
self._head._next_event_ = None
self._tail = self._head
self._count = 0 | [
"def",
"clear",
"(",
"self",
")",
":",
"# We just drop the next events reference, GC or EventPool will collect them.",
"self",
".",
"_head",
".",
"_next_event_",
"=",
"None",
"self",
".",
"_tail",
"=",
"self",
".",
"_head",
"self",
".",
"_count",
"=",
"0"
] | [
47,
4
] | [
53,
23
] | python | en | ['fr', 'en', 'en'] | True |
EventLinkedList.append | (self, event: Event) | Append an event to the end.
Args:
event (Event): New event to append.
| Append an event to the end. | def append(self, event: Event):
"""Append an event to the end.
Args:
event (Event): New event to append.
"""
# Link to the tail, update the tail.
self._tail._next_event_ = event
self._tail = event
# Counting.
self._count += 1 | [
"def",
"append",
"(",
"self",
",",
"event",
":",
"Event",
")",
":",
"# Link to the tail, update the tail.",
"self",
".",
"_tail",
".",
"_next_event_",
"=",
"event",
"self",
".",
"_tail",
"=",
"event",
"# Counting.",
"self",
".",
"_count",
"+=",
"1"
] | [
55,
4
] | [
66,
24
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.insert | (self, event: Event) | Insert an event to the head, will be the first one to pop.
Args:
event (Event): Event to insert.
| Insert an event to the head, will be the first one to pop. | def insert(self, event: Event):
"""Insert an event to the head, will be the first one to pop.
Args:
event (Event): Event to insert.
"""
# Link to head, update head.
event._next_event_ = self._head._next_event_
self._head._next_event_ = event
# Counting.
self._count += 1 | [
"def",
"insert",
"(",
"self",
",",
"event",
":",
"Event",
")",
":",
"# Link to head, update head.",
"event",
".",
"_next_event_",
"=",
"self",
".",
"_head",
".",
"_next_event_",
"self",
".",
"_head",
".",
"_next_event_",
"=",
"event",
"# Counting.",
"self",
".",
"_count",
"+=",
"1"
] | [
68,
4
] | [
79,
24
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.pop | (self) | Pop first event that its state is not Finished.
Returns:
Union[Event, EventList]: A list of decision events if current event is decision event, or an AtomEvent.
| Pop first event that its state is not Finished. | def pop(self) -> Union[Event, EventList]:
"""Pop first event that its state is not Finished.
Returns:
Union[Event, EventList]: A list of decision events if current event is decision event, or an AtomEvent.
"""
event: Event = self._head._next_event_
while event is not None:
# We will remove event from list until its state is FINISHED.
if event.state == EventState.FINISHED:
# Remove it (head).
self._head._next_event_ = event._next_event_
event._next_event_ = None
# Counting.
self._count -= 1
# Extract sub events, this will change the head.
self._extract_sub_events(event)
event = self._head._next_event_
continue
if event.state == EventState.EXECUTING:
return event
if event.event_type == MaroEvents.PENDING_DECISION:
decision_events = [event]
# Find following decision events.
next_event: Event = event._next_event_
while next_event is not None and next_event.event_type == MaroEvents.PENDING_DECISION:
decision_events.append(next_event)
next_event = next_event._next_event_
return decision_events
else:
return event
return None | [
"def",
"pop",
"(",
"self",
")",
"->",
"Union",
"[",
"Event",
",",
"EventList",
"]",
":",
"event",
":",
"Event",
"=",
"self",
".",
"_head",
".",
"_next_event_",
"while",
"event",
"is",
"not",
"None",
":",
"# We will remove event from list until its state is FINISHED.",
"if",
"event",
".",
"state",
"==",
"EventState",
".",
"FINISHED",
":",
"# Remove it (head).",
"self",
".",
"_head",
".",
"_next_event_",
"=",
"event",
".",
"_next_event_",
"event",
".",
"_next_event_",
"=",
"None",
"# Counting.",
"self",
".",
"_count",
"-=",
"1",
"# Extract sub events, this will change the head.",
"self",
".",
"_extract_sub_events",
"(",
"event",
")",
"event",
"=",
"self",
".",
"_head",
".",
"_next_event_",
"continue",
"if",
"event",
".",
"state",
"==",
"EventState",
".",
"EXECUTING",
":",
"return",
"event",
"if",
"event",
".",
"event_type",
"==",
"MaroEvents",
".",
"PENDING_DECISION",
":",
"decision_events",
"=",
"[",
"event",
"]",
"# Find following decision events.",
"next_event",
":",
"Event",
"=",
"event",
".",
"_next_event_",
"while",
"next_event",
"is",
"not",
"None",
"and",
"next_event",
".",
"event_type",
"==",
"MaroEvents",
".",
"PENDING_DECISION",
":",
"decision_events",
".",
"append",
"(",
"next_event",
")",
"next_event",
"=",
"next_event",
".",
"_next_event_",
"return",
"decision_events",
"else",
":",
"return",
"event",
"return",
"None"
] | [
81,
4
] | [
125,
19
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.__len__ | (self) | Length of current list. | Length of current list. | def __len__(self):
"""Length of current list."""
return self._count | [
"def",
"__len__",
"(",
"self",
")",
":",
"return",
"self",
".",
"_count"
] | [
127,
4
] | [
129,
26
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.__iter__ | (self) | Beginning of for loopping. | Beginning of for loopping. | def __iter__(self):
"""Beginning of for loopping."""
self._iter_cur_event = self._head
return self | [
"def",
"__iter__",
"(",
"self",
")",
":",
"self",
".",
"_iter_cur_event",
"=",
"self",
".",
"_head",
"return",
"self"
] | [
131,
4
] | [
135,
19
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList.__next__ | (self) | Get next item for 'for' loopping. | Get next item for 'for' loopping. | def __next__(self):
"""Get next item for 'for' loopping."""
event: Event = None
if self._iter_cur_event is None:
raise StopIteration()
if self._iter_cur_event is not None:
event = self._iter_cur_event._next_event_
if event is None:
raise StopIteration()
else:
self._iter_cur_event = event._next_event_
return event | [
"def",
"__next__",
"(",
"self",
")",
":",
"event",
":",
"Event",
"=",
"None",
"if",
"self",
".",
"_iter_cur_event",
"is",
"None",
":",
"raise",
"StopIteration",
"(",
")",
"if",
"self",
".",
"_iter_cur_event",
"is",
"not",
"None",
":",
"event",
"=",
"self",
".",
"_iter_cur_event",
".",
"_next_event_",
"if",
"event",
"is",
"None",
":",
"raise",
"StopIteration",
"(",
")",
"else",
":",
"self",
".",
"_iter_cur_event",
"=",
"event",
".",
"_next_event_",
"return",
"event"
] | [
137,
4
] | [
152,
20
] | python | en | ['en', 'en', 'en'] | True |
EventLinkedList._extract_sub_events | (self, event: Event) | Extract sub events (immediate events) of CascadeEvent to the head.
Args:
event (Event): Event to extract.
| Extract sub events (immediate events) of CascadeEvent to the head. | def _extract_sub_events(self, event: Event):
"""Extract sub events (immediate events) of CascadeEvent to the head.
Args:
event (Event): Event to extract.
"""
if type(event) == CascadeEvent:
# Make immediate event list as the head of current list.
if event._last_immediate_event is not None:
event._last_immediate_event._next_event_ = self._head._next_event_
self._head._next_event_ = event._immediate_event_head._next_event_
self._count += event._immediate_event_count
# Clear the reference for finished event.
event._immediate_event_head._next_event_ = None
event._last_immediate_event = None | [
"def",
"_extract_sub_events",
"(",
"self",
",",
"event",
":",
"Event",
")",
":",
"if",
"type",
"(",
"event",
")",
"==",
"CascadeEvent",
":",
"# Make immediate event list as the head of current list.",
"if",
"event",
".",
"_last_immediate_event",
"is",
"not",
"None",
":",
"event",
".",
"_last_immediate_event",
".",
"_next_event_",
"=",
"self",
".",
"_head",
".",
"_next_event_",
"self",
".",
"_head",
".",
"_next_event_",
"=",
"event",
".",
"_immediate_event_head",
".",
"_next_event_",
"self",
".",
"_count",
"+=",
"event",
".",
"_immediate_event_count",
"# Clear the reference for finished event.",
"event",
".",
"_immediate_event_head",
".",
"_next_event_",
"=",
"None",
"event",
".",
"_last_immediate_event",
"=",
"None"
] | [
154,
4
] | [
170,
50
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up an Arlo component. | Set up an Arlo component. | def setup(hass, config):
"""Set up an Arlo component."""
conf = config[DOMAIN]
username = conf[CONF_USERNAME]
password = conf[CONF_PASSWORD]
scan_interval = conf[CONF_SCAN_INTERVAL]
try:
arlo = PyArlo(username, password, preload=False)
if not arlo.is_connected:
return False
# assign refresh period to base station thread
arlo_base_station = next((station for station in arlo.base_stations), None)
if arlo_base_station is not None:
arlo_base_station.refresh_rate = scan_interval.total_seconds()
elif not arlo.cameras:
_LOGGER.error("No Arlo camera or base station available")
return False
hass.data[DATA_ARLO] = arlo
except (ConnectTimeout, HTTPError) as ex:
_LOGGER.error("Unable to connect to Netgear Arlo: %s", str(ex))
hass.components.persistent_notification.create(
f"Error: {ex}<br />You will need to restart hass after fixing.",
title=NOTIFICATION_TITLE,
notification_id=NOTIFICATION_ID,
)
return False
def hub_refresh(event_time):
"""Call ArloHub to refresh information."""
_LOGGER.debug("Updating Arlo Hub component")
hass.data[DATA_ARLO].update(update_cameras=True, update_base_station=True)
dispatcher_send(hass, SIGNAL_UPDATE_ARLO)
# register service
hass.services.register(DOMAIN, "update", hub_refresh)
# register scan interval for ArloHub
track_time_interval(hass, hub_refresh, scan_interval)
return True | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"conf",
"=",
"config",
"[",
"DOMAIN",
"]",
"username",
"=",
"conf",
"[",
"CONF_USERNAME",
"]",
"password",
"=",
"conf",
"[",
"CONF_PASSWORD",
"]",
"scan_interval",
"=",
"conf",
"[",
"CONF_SCAN_INTERVAL",
"]",
"try",
":",
"arlo",
"=",
"PyArlo",
"(",
"username",
",",
"password",
",",
"preload",
"=",
"False",
")",
"if",
"not",
"arlo",
".",
"is_connected",
":",
"return",
"False",
"# assign refresh period to base station thread",
"arlo_base_station",
"=",
"next",
"(",
"(",
"station",
"for",
"station",
"in",
"arlo",
".",
"base_stations",
")",
",",
"None",
")",
"if",
"arlo_base_station",
"is",
"not",
"None",
":",
"arlo_base_station",
".",
"refresh_rate",
"=",
"scan_interval",
".",
"total_seconds",
"(",
")",
"elif",
"not",
"arlo",
".",
"cameras",
":",
"_LOGGER",
".",
"error",
"(",
"\"No Arlo camera or base station available\"",
")",
"return",
"False",
"hass",
".",
"data",
"[",
"DATA_ARLO",
"]",
"=",
"arlo",
"except",
"(",
"ConnectTimeout",
",",
"HTTPError",
")",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to connect to Netgear Arlo: %s\"",
",",
"str",
"(",
"ex",
")",
")",
"hass",
".",
"components",
".",
"persistent_notification",
".",
"create",
"(",
"f\"Error: {ex}<br />You will need to restart hass after fixing.\"",
",",
"title",
"=",
"NOTIFICATION_TITLE",
",",
"notification_id",
"=",
"NOTIFICATION_ID",
",",
")",
"return",
"False",
"def",
"hub_refresh",
"(",
"event_time",
")",
":",
"\"\"\"Call ArloHub to refresh information.\"\"\"",
"_LOGGER",
".",
"debug",
"(",
"\"Updating Arlo Hub component\"",
")",
"hass",
".",
"data",
"[",
"DATA_ARLO",
"]",
".",
"update",
"(",
"update_cameras",
"=",
"True",
",",
"update_base_station",
"=",
"True",
")",
"dispatcher_send",
"(",
"hass",
",",
"SIGNAL_UPDATE_ARLO",
")",
"# register service",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"\"update\"",
",",
"hub_refresh",
")",
"# register scan interval for ArloHub",
"track_time_interval",
"(",
"hass",
",",
"hub_refresh",
",",
"scan_interval",
")",
"return",
"True"
] | [
42,
0
] | [
86,
15
] | python | en | ['en', 'en', 'en'] | True |
Auth.__init__ | (self, hass, client_id, client_secret) | Initialize the Auth class. | Initialize the Auth class. | def __init__(self, hass, client_id, client_secret):
"""Initialize the Auth class."""
self.hass = hass
self.client_id = client_id
self.client_secret = client_secret
self._prefs = None
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY)
self._get_token_lock = asyncio.Lock() | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"client_id",
",",
"client_secret",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"client_id",
"=",
"client_id",
"self",
".",
"client_secret",
"=",
"client_secret",
"self",
".",
"_prefs",
"=",
"None",
"self",
".",
"_store",
"=",
"hass",
".",
"helpers",
".",
"storage",
".",
"Store",
"(",
"STORAGE_VERSION",
",",
"STORAGE_KEY",
")",
"self",
".",
"_get_token_lock",
"=",
"asyncio",
".",
"Lock",
"(",
")"
] | [
30,
4
] | [
40,
45
] | python | en | ['en', 'en', 'en'] | True |
Auth.async_do_auth | (self, accept_grant_code) | Do authentication with an AcceptGrant code. | Do authentication with an AcceptGrant code. | async def async_do_auth(self, accept_grant_code):
"""Do authentication with an AcceptGrant code."""
# access token not retrieved yet for the first time, so this should
# be an access token request
lwa_params = {
"grant_type": "authorization_code",
"code": accept_grant_code,
CONF_CLIENT_ID: self.client_id,
CONF_CLIENT_SECRET: self.client_secret,
}
_LOGGER.debug(
"Calling LWA to get the access token (first time), with: %s",
json.dumps(lwa_params),
)
return await self._async_request_new_token(lwa_params) | [
"async",
"def",
"async_do_auth",
"(",
"self",
",",
"accept_grant_code",
")",
":",
"# access token not retrieved yet for the first time, so this should",
"# be an access token request",
"lwa_params",
"=",
"{",
"\"grant_type\"",
":",
"\"authorization_code\"",
",",
"\"code\"",
":",
"accept_grant_code",
",",
"CONF_CLIENT_ID",
":",
"self",
".",
"client_id",
",",
"CONF_CLIENT_SECRET",
":",
"self",
".",
"client_secret",
",",
"}",
"_LOGGER",
".",
"debug",
"(",
"\"Calling LWA to get the access token (first time), with: %s\"",
",",
"json",
".",
"dumps",
"(",
"lwa_params",
")",
",",
")",
"return",
"await",
"self",
".",
"_async_request_new_token",
"(",
"lwa_params",
")"
] | [
42,
4
] | [
58,
62
] | python | en | ['en', 'en', 'en'] | True |
Auth.async_invalidate_access_token | (self) | Invalidate access token. | Invalidate access token. | def async_invalidate_access_token(self):
"""Invalidate access token."""
self._prefs[STORAGE_ACCESS_TOKEN] = None | [
"def",
"async_invalidate_access_token",
"(",
"self",
")",
":",
"self",
".",
"_prefs",
"[",
"STORAGE_ACCESS_TOKEN",
"]",
"=",
"None"
] | [
61,
4
] | [
63,
48
] | python | en | ['en', 'fi', 'en'] | True |
Auth.async_get_access_token | (self) | Perform access token or token refresh request. | Perform access token or token refresh request. | async def async_get_access_token(self):
"""Perform access token or token refresh request."""
async with self._get_token_lock:
if self._prefs is None:
await self.async_load_preferences()
if self.is_token_valid():
_LOGGER.debug("Token still valid, using it")
return self._prefs[STORAGE_ACCESS_TOKEN]
if self._prefs[STORAGE_REFRESH_TOKEN] is None:
_LOGGER.debug("Token invalid and no refresh token available")
return None
lwa_params = {
"grant_type": "refresh_token",
"refresh_token": self._prefs[STORAGE_REFRESH_TOKEN],
CONF_CLIENT_ID: self.client_id,
CONF_CLIENT_SECRET: self.client_secret,
}
_LOGGER.debug("Calling LWA to refresh the access token")
return await self._async_request_new_token(lwa_params) | [
"async",
"def",
"async_get_access_token",
"(",
"self",
")",
":",
"async",
"with",
"self",
".",
"_get_token_lock",
":",
"if",
"self",
".",
"_prefs",
"is",
"None",
":",
"await",
"self",
".",
"async_load_preferences",
"(",
")",
"if",
"self",
".",
"is_token_valid",
"(",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Token still valid, using it\"",
")",
"return",
"self",
".",
"_prefs",
"[",
"STORAGE_ACCESS_TOKEN",
"]",
"if",
"self",
".",
"_prefs",
"[",
"STORAGE_REFRESH_TOKEN",
"]",
"is",
"None",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Token invalid and no refresh token available\"",
")",
"return",
"None",
"lwa_params",
"=",
"{",
"\"grant_type\"",
":",
"\"refresh_token\"",
",",
"\"refresh_token\"",
":",
"self",
".",
"_prefs",
"[",
"STORAGE_REFRESH_TOKEN",
"]",
",",
"CONF_CLIENT_ID",
":",
"self",
".",
"client_id",
",",
"CONF_CLIENT_SECRET",
":",
"self",
".",
"client_secret",
",",
"}",
"_LOGGER",
".",
"debug",
"(",
"\"Calling LWA to refresh the access token\"",
")",
"return",
"await",
"self",
".",
"_async_request_new_token",
"(",
"lwa_params",
")"
] | [
65,
4
] | [
87,
66
] | python | en | ['en', 'nl', 'en'] | True |
Auth.is_token_valid | (self) | Check if a token is already loaded and if it is still valid. | Check if a token is already loaded and if it is still valid. | def is_token_valid(self):
"""Check if a token is already loaded and if it is still valid."""
if not self._prefs[STORAGE_ACCESS_TOKEN]:
return False
expire_time = dt.parse_datetime(self._prefs[STORAGE_EXPIRE_TIME])
preemptive_expire_time = expire_time - timedelta(
seconds=PREEMPTIVE_REFRESH_TTL_IN_SECONDS
)
return dt.utcnow() < preemptive_expire_time | [
"def",
"is_token_valid",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_prefs",
"[",
"STORAGE_ACCESS_TOKEN",
"]",
":",
"return",
"False",
"expire_time",
"=",
"dt",
".",
"parse_datetime",
"(",
"self",
".",
"_prefs",
"[",
"STORAGE_EXPIRE_TIME",
"]",
")",
"preemptive_expire_time",
"=",
"expire_time",
"-",
"timedelta",
"(",
"seconds",
"=",
"PREEMPTIVE_REFRESH_TTL_IN_SECONDS",
")",
"return",
"dt",
".",
"utcnow",
"(",
")",
"<",
"preemptive_expire_time"
] | [
90,
4
] | [
100,
51
] | python | en | ['en', 'en', 'en'] | True |
Auth.async_load_preferences | (self) | Load preferences with stored tokens. | Load preferences with stored tokens. | async def async_load_preferences(self):
"""Load preferences with stored tokens."""
self._prefs = await self._store.async_load()
if self._prefs is None:
self._prefs = {
STORAGE_ACCESS_TOKEN: None,
STORAGE_REFRESH_TOKEN: None,
STORAGE_EXPIRE_TIME: None,
} | [
"async",
"def",
"async_load_preferences",
"(",
"self",
")",
":",
"self",
".",
"_prefs",
"=",
"await",
"self",
".",
"_store",
".",
"async_load",
"(",
")",
"if",
"self",
".",
"_prefs",
"is",
"None",
":",
"self",
".",
"_prefs",
"=",
"{",
"STORAGE_ACCESS_TOKEN",
":",
"None",
",",
"STORAGE_REFRESH_TOKEN",
":",
"None",
",",
"STORAGE_EXPIRE_TIME",
":",
"None",
",",
"}"
] | [
139,
4
] | [
148,
13
] | python | en | ['en', 'en', 'en'] | True |
Auth._async_update_preferences | (self, access_token, refresh_token, expire_time) | Update user preferences. | Update user preferences. | async def _async_update_preferences(self, access_token, refresh_token, expire_time):
"""Update user preferences."""
if self._prefs is None:
await self.async_load_preferences()
if access_token is not None:
self._prefs[STORAGE_ACCESS_TOKEN] = access_token
if refresh_token is not None:
self._prefs[STORAGE_REFRESH_TOKEN] = refresh_token
if expire_time is not None:
self._prefs[STORAGE_EXPIRE_TIME] = expire_time
await self._store.async_save(self._prefs) | [
"async",
"def",
"_async_update_preferences",
"(",
"self",
",",
"access_token",
",",
"refresh_token",
",",
"expire_time",
")",
":",
"if",
"self",
".",
"_prefs",
"is",
"None",
":",
"await",
"self",
".",
"async_load_preferences",
"(",
")",
"if",
"access_token",
"is",
"not",
"None",
":",
"self",
".",
"_prefs",
"[",
"STORAGE_ACCESS_TOKEN",
"]",
"=",
"access_token",
"if",
"refresh_token",
"is",
"not",
"None",
":",
"self",
".",
"_prefs",
"[",
"STORAGE_REFRESH_TOKEN",
"]",
"=",
"refresh_token",
"if",
"expire_time",
"is",
"not",
"None",
":",
"self",
".",
"_prefs",
"[",
"STORAGE_EXPIRE_TIME",
"]",
"=",
"expire_time",
"await",
"self",
".",
"_store",
".",
"async_save",
"(",
"self",
".",
"_prefs",
")"
] | [
150,
4
] | [
161,
49
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Insteon switches from a config entry. | Set up the Insteon switches from a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Insteon switches from a config entry."""
def add_entities(discovery_info=None):
"""Add the Insteon entities for the platform."""
async_add_insteon_entities(
hass, SWITCH_DOMAIN, InsteonSwitchEntity, async_add_entities, discovery_info
)
signal = f"{SIGNAL_ADD_ENTITIES}_{SWITCH_DOMAIN}"
async_dispatcher_connect(hass, signal, add_entities)
add_entities() | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"def",
"add_entities",
"(",
"discovery_info",
"=",
"None",
")",
":",
"\"\"\"Add the Insteon entities for the platform.\"\"\"",
"async_add_insteon_entities",
"(",
"hass",
",",
"SWITCH_DOMAIN",
",",
"InsteonSwitchEntity",
",",
"async_add_entities",
",",
"discovery_info",
")",
"signal",
"=",
"f\"{SIGNAL_ADD_ENTITIES}_{SWITCH_DOMAIN}\"",
"async_dispatcher_connect",
"(",
"hass",
",",
"signal",
",",
"add_entities",
")",
"add_entities",
"(",
")"
] | [
9,
0
] | [
20,
18
] | python | en | ['en', 'en', 'en'] | True |
InsteonSwitchEntity.is_on | (self) | Return the boolean response if the node is on. | Return the boolean response if the node is on. | def is_on(self):
"""Return the boolean response if the node is on."""
return bool(self._insteon_device_group.value) | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"bool",
"(",
"self",
".",
"_insteon_device_group",
".",
"value",
")"
] | [
27,
4
] | [
29,
53
] | python | en | ['en', 'en', 'en'] | True |
InsteonSwitchEntity.async_turn_on | (self, **kwargs) | Turn switch on. | Turn switch on. | async def async_turn_on(self, **kwargs):
"""Turn switch on."""
await self._insteon_device.async_on(group=self._insteon_device_group.group) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_insteon_device",
".",
"async_on",
"(",
"group",
"=",
"self",
".",
"_insteon_device_group",
".",
"group",
")"
] | [
31,
4
] | [
33,
83
] | python | en | ['en', 'en', 'en'] | True |
InsteonSwitchEntity.async_turn_off | (self, **kwargs) | Turn switch off. | Turn switch off. | async def async_turn_off(self, **kwargs):
"""Turn switch off."""
await self._insteon_device.async_off(group=self._insteon_device_group.group) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_insteon_device",
".",
"async_off",
"(",
"group",
"=",
"self",
".",
"_insteon_device_group",
".",
"group",
")"
] | [
35,
4
] | [
37,
84
] | python | en | ['en', 'en', 'en'] | True |
create_auth_code | (hass, client_id: str, user: User) | Create an authorization code to fetch tokens. | Create an authorization code to fetch tokens. | def create_auth_code(hass, client_id: str, user: User) -> str:
"""Create an authorization code to fetch tokens."""
return hass.data[DOMAIN](client_id, user) | [
"def",
"create_auth_code",
"(",
"hass",
",",
"client_id",
":",
"str",
",",
"user",
":",
"User",
")",
"->",
"str",
":",
"return",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"(",
"client_id",
",",
"user",
")"
] | [
182,
0
] | [
184,
45
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config) | Component to allow users to login. | Component to allow users to login. | async def async_setup(hass, config):
"""Component to allow users to login."""
store_result, retrieve_result = _create_auth_code_store()
hass.data[DOMAIN] = store_result
hass.http.register_view(TokenView(retrieve_result))
hass.http.register_view(LinkUserView(retrieve_result))
hass.components.websocket_api.async_register_command(
WS_TYPE_CURRENT_USER, websocket_current_user, SCHEMA_WS_CURRENT_USER
)
hass.components.websocket_api.async_register_command(
WS_TYPE_LONG_LIVED_ACCESS_TOKEN,
websocket_create_long_lived_access_token,
SCHEMA_WS_LONG_LIVED_ACCESS_TOKEN,
)
hass.components.websocket_api.async_register_command(
WS_TYPE_REFRESH_TOKENS, websocket_refresh_tokens, SCHEMA_WS_REFRESH_TOKENS
)
hass.components.websocket_api.async_register_command(
WS_TYPE_DELETE_REFRESH_TOKEN,
websocket_delete_refresh_token,
SCHEMA_WS_DELETE_REFRESH_TOKEN,
)
hass.components.websocket_api.async_register_command(
WS_TYPE_SIGN_PATH, websocket_sign_path, SCHEMA_WS_SIGN_PATH
)
await login_flow.async_setup(hass, store_result)
await mfa_setup_flow.async_setup(hass)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"store_result",
",",
"retrieve_result",
"=",
"_create_auth_code_store",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"store_result",
"hass",
".",
"http",
".",
"register_view",
"(",
"TokenView",
"(",
"retrieve_result",
")",
")",
"hass",
".",
"http",
".",
"register_view",
"(",
"LinkUserView",
"(",
"retrieve_result",
")",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_CURRENT_USER",
",",
"websocket_current_user",
",",
"SCHEMA_WS_CURRENT_USER",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_LONG_LIVED_ACCESS_TOKEN",
",",
"websocket_create_long_lived_access_token",
",",
"SCHEMA_WS_LONG_LIVED_ACCESS_TOKEN",
",",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_REFRESH_TOKENS",
",",
"websocket_refresh_tokens",
",",
"SCHEMA_WS_REFRESH_TOKENS",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_DELETE_REFRESH_TOKEN",
",",
"websocket_delete_refresh_token",
",",
"SCHEMA_WS_DELETE_REFRESH_TOKEN",
",",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_SIGN_PATH",
",",
"websocket_sign_path",
",",
"SCHEMA_WS_SIGN_PATH",
")",
"await",
"login_flow",
".",
"async_setup",
"(",
"hass",
",",
"store_result",
")",
"await",
"mfa_setup_flow",
".",
"async_setup",
"(",
"hass",
")",
"return",
"True"
] | [
187,
0
] | [
219,
15
] | python | en | ['en', 'en', 'en'] | True |
_create_auth_code_store | () | Create an in memory store. | Create an in memory store. | def _create_auth_code_store():
"""Create an in memory store."""
temp_results = {}
@callback
def store_result(client_id, result):
"""Store flow result and return a code to retrieve it."""
if isinstance(result, User):
result_type = RESULT_TYPE_USER
elif isinstance(result, Credentials):
result_type = RESULT_TYPE_CREDENTIALS
else:
raise ValueError("result has to be either User or Credentials")
code = uuid.uuid4().hex
temp_results[(client_id, result_type, code)] = (
dt_util.utcnow(),
result_type,
result,
)
return code
@callback
def retrieve_result(client_id, result_type, code):
"""Retrieve flow result."""
key = (client_id, result_type, code)
if key not in temp_results:
return None
created, _, result = temp_results.pop(key)
# OAuth 4.2.1
# The authorization code MUST expire shortly after it is issued to
# mitigate the risk of leaks. A maximum authorization code lifetime of
# 10 minutes is RECOMMENDED.
if dt_util.utcnow() - created < timedelta(minutes=10):
return result
return None
return store_result, retrieve_result | [
"def",
"_create_auth_code_store",
"(",
")",
":",
"temp_results",
"=",
"{",
"}",
"@",
"callback",
"def",
"store_result",
"(",
"client_id",
",",
"result",
")",
":",
"\"\"\"Store flow result and return a code to retrieve it.\"\"\"",
"if",
"isinstance",
"(",
"result",
",",
"User",
")",
":",
"result_type",
"=",
"RESULT_TYPE_USER",
"elif",
"isinstance",
"(",
"result",
",",
"Credentials",
")",
":",
"result_type",
"=",
"RESULT_TYPE_CREDENTIALS",
"else",
":",
"raise",
"ValueError",
"(",
"\"result has to be either User or Credentials\"",
")",
"code",
"=",
"uuid",
".",
"uuid4",
"(",
")",
".",
"hex",
"temp_results",
"[",
"(",
"client_id",
",",
"result_type",
",",
"code",
")",
"]",
"=",
"(",
"dt_util",
".",
"utcnow",
"(",
")",
",",
"result_type",
",",
"result",
",",
")",
"return",
"code",
"@",
"callback",
"def",
"retrieve_result",
"(",
"client_id",
",",
"result_type",
",",
"code",
")",
":",
"\"\"\"Retrieve flow result.\"\"\"",
"key",
"=",
"(",
"client_id",
",",
"result_type",
",",
"code",
")",
"if",
"key",
"not",
"in",
"temp_results",
":",
"return",
"None",
"created",
",",
"_",
",",
"result",
"=",
"temp_results",
".",
"pop",
"(",
"key",
")",
"# OAuth 4.2.1",
"# The authorization code MUST expire shortly after it is issued to",
"# mitigate the risk of leaks. A maximum authorization code lifetime of",
"# 10 minutes is RECOMMENDED.",
"if",
"dt_util",
".",
"utcnow",
"(",
")",
"-",
"created",
"<",
"timedelta",
"(",
"minutes",
"=",
"10",
")",
":",
"return",
"result",
"return",
"None",
"return",
"store_result",
",",
"retrieve_result"
] | [
389,
0
] | [
430,
40
] | python | en | ['en', 'en', 'en'] | True |
websocket_current_user | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Return the current user. | Return the current user. | async def websocket_current_user(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Return the current user."""
user = connection.user
enabled_modules = await hass.auth.async_get_enabled_mfa(user)
connection.send_message(
websocket_api.result_message(
msg["id"],
{
"id": user.id,
"name": user.name,
"is_owner": user.is_owner,
"is_admin": user.is_admin,
"credentials": [
{
"auth_provider_type": c.auth_provider_type,
"auth_provider_id": c.auth_provider_id,
}
for c in user.credentials
],
"mfa_modules": [
{
"id": module.id,
"name": module.name,
"enabled": module.id in enabled_modules,
}
for module in hass.auth.auth_mfa_modules
],
},
)
) | [
"async",
"def",
"websocket_current_user",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"user",
"=",
"connection",
".",
"user",
"enabled_modules",
"=",
"await",
"hass",
".",
"auth",
".",
"async_get_enabled_mfa",
"(",
"user",
")",
"connection",
".",
"send_message",
"(",
"websocket_api",
".",
"result_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"{",
"\"id\"",
":",
"user",
".",
"id",
",",
"\"name\"",
":",
"user",
".",
"name",
",",
"\"is_owner\"",
":",
"user",
".",
"is_owner",
",",
"\"is_admin\"",
":",
"user",
".",
"is_admin",
",",
"\"credentials\"",
":",
"[",
"{",
"\"auth_provider_type\"",
":",
"c",
".",
"auth_provider_type",
",",
"\"auth_provider_id\"",
":",
"c",
".",
"auth_provider_id",
",",
"}",
"for",
"c",
"in",
"user",
".",
"credentials",
"]",
",",
"\"mfa_modules\"",
":",
"[",
"{",
"\"id\"",
":",
"module",
".",
"id",
",",
"\"name\"",
":",
"module",
".",
"name",
",",
"\"enabled\"",
":",
"module",
".",
"id",
"in",
"enabled_modules",
",",
"}",
"for",
"module",
"in",
"hass",
".",
"auth",
".",
"auth_mfa_modules",
"]",
",",
"}",
",",
")",
")"
] | [
435,
0
] | [
467,
5
] | python | en | ['en', 'en', 'en'] | True |
websocket_create_long_lived_access_token | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Create or a long-lived access token. | Create or a long-lived access token. | async def websocket_create_long_lived_access_token(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Create or a long-lived access token."""
refresh_token = await hass.auth.async_create_refresh_token(
connection.user,
client_name=msg["client_name"],
client_icon=msg.get("client_icon"),
token_type=TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN,
access_token_expiration=timedelta(days=msg["lifespan"]),
)
access_token = hass.auth.async_create_access_token(refresh_token)
connection.send_message(websocket_api.result_message(msg["id"], access_token)) | [
"async",
"def",
"websocket_create_long_lived_access_token",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"refresh_token",
"=",
"await",
"hass",
".",
"auth",
".",
"async_create_refresh_token",
"(",
"connection",
".",
"user",
",",
"client_name",
"=",
"msg",
"[",
"\"client_name\"",
"]",
",",
"client_icon",
"=",
"msg",
".",
"get",
"(",
"\"client_icon\"",
")",
",",
"token_type",
"=",
"TOKEN_TYPE_LONG_LIVED_ACCESS_TOKEN",
",",
"access_token_expiration",
"=",
"timedelta",
"(",
"days",
"=",
"msg",
"[",
"\"lifespan\"",
"]",
")",
",",
")",
"access_token",
"=",
"hass",
".",
"auth",
".",
"async_create_access_token",
"(",
"refresh_token",
")",
"connection",
".",
"send_message",
"(",
"websocket_api",
".",
"result_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"access_token",
")",
")"
] | [
472,
0
] | [
486,
82
] | python | en | ['en', 'en', 'en'] | True |
websocket_refresh_tokens | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Return metadata of users refresh tokens. | Return metadata of users refresh tokens. | def websocket_refresh_tokens(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Return metadata of users refresh tokens."""
current_id = connection.refresh_token_id
connection.send_message(
websocket_api.result_message(
msg["id"],
[
{
"id": refresh.id,
"client_id": refresh.client_id,
"client_name": refresh.client_name,
"client_icon": refresh.client_icon,
"type": refresh.token_type,
"created_at": refresh.created_at,
"is_current": refresh.id == current_id,
"last_used_at": refresh.last_used_at,
"last_used_ip": refresh.last_used_ip,
}
for refresh in connection.user.refresh_tokens.values()
],
)
) | [
"def",
"websocket_refresh_tokens",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"current_id",
"=",
"connection",
".",
"refresh_token_id",
"connection",
".",
"send_message",
"(",
"websocket_api",
".",
"result_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"[",
"{",
"\"id\"",
":",
"refresh",
".",
"id",
",",
"\"client_id\"",
":",
"refresh",
".",
"client_id",
",",
"\"client_name\"",
":",
"refresh",
".",
"client_name",
",",
"\"client_icon\"",
":",
"refresh",
".",
"client_icon",
",",
"\"type\"",
":",
"refresh",
".",
"token_type",
",",
"\"created_at\"",
":",
"refresh",
".",
"created_at",
",",
"\"is_current\"",
":",
"refresh",
".",
"id",
"==",
"current_id",
",",
"\"last_used_at\"",
":",
"refresh",
".",
"last_used_at",
",",
"\"last_used_ip\"",
":",
"refresh",
".",
"last_used_ip",
",",
"}",
"for",
"refresh",
"in",
"connection",
".",
"user",
".",
"refresh_tokens",
".",
"values",
"(",
")",
"]",
",",
")",
")"
] | [
491,
0
] | [
514,
5
] | python | en | ['en', 'sn', 'en'] | True |
websocket_delete_refresh_token | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Handle a delete refresh token request. | Handle a delete refresh token request. | async def websocket_delete_refresh_token(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Handle a delete refresh token request."""
refresh_token = connection.user.refresh_tokens.get(msg["refresh_token_id"])
if refresh_token is None:
return websocket_api.error_message(
msg["id"], "invalid_token_id", "Received invalid token"
)
await hass.auth.async_remove_refresh_token(refresh_token)
connection.send_message(websocket_api.result_message(msg["id"], {})) | [
"async",
"def",
"websocket_delete_refresh_token",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"refresh_token",
"=",
"connection",
".",
"user",
".",
"refresh_tokens",
".",
"get",
"(",
"msg",
"[",
"\"refresh_token_id\"",
"]",
")",
"if",
"refresh_token",
"is",
"None",
":",
"return",
"websocket_api",
".",
"error_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"\"invalid_token_id\"",
",",
"\"Received invalid token\"",
")",
"await",
"hass",
".",
"auth",
".",
"async_remove_refresh_token",
"(",
"refresh_token",
")",
"connection",
".",
"send_message",
"(",
"websocket_api",
".",
"result_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"{",
"}",
")",
")"
] | [
519,
0
] | [
532,
72
] | python | en | ['en', 'de', 'en'] | True |
websocket_sign_path | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Handle a sign path request. | Handle a sign path request. | def websocket_sign_path(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Handle a sign path request."""
connection.send_message(
websocket_api.result_message(
msg["id"],
{
"path": async_sign_path(
hass,
connection.refresh_token_id,
msg["path"],
timedelta(seconds=msg["expires"]),
)
},
)
) | [
"def",
"websocket_sign_path",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"connection",
".",
"send_message",
"(",
"websocket_api",
".",
"result_message",
"(",
"msg",
"[",
"\"id\"",
"]",
",",
"{",
"\"path\"",
":",
"async_sign_path",
"(",
"hass",
",",
"connection",
".",
"refresh_token_id",
",",
"msg",
"[",
"\"path\"",
"]",
",",
"timedelta",
"(",
"seconds",
"=",
"msg",
"[",
"\"expires\"",
"]",
")",
",",
")",
"}",
",",
")",
")"
] | [
537,
0
] | [
553,
5
] | python | en | ['en', 'en', 'en'] | True |
TokenView.__init__ | (self, retrieve_user) | Initialize the token view. | Initialize the token view. | def __init__(self, retrieve_user):
"""Initialize the token view."""
self._retrieve_user = retrieve_user | [
"def",
"__init__",
"(",
"self",
",",
"retrieve_user",
")",
":",
"self",
".",
"_retrieve_user",
"=",
"retrieve_user"
] | [
230,
4
] | [
232,
43
] | python | en | ['en', 'en', 'en'] | True |
TokenView.post | (self, request) | Grant a token. | Grant a token. | async def post(self, request):
"""Grant a token."""
hass = request.app["hass"]
data = await request.post()
grant_type = data.get("grant_type")
# IndieAuth 6.3.5
# The revocation endpoint is the same as the token endpoint.
# The revocation request includes an additional parameter,
# action=revoke.
if data.get("action") == "revoke":
return await self._async_handle_revoke_token(hass, data)
if grant_type == "authorization_code":
return await self._async_handle_auth_code(hass, data, request.remote)
if grant_type == "refresh_token":
return await self._async_handle_refresh_token(hass, data, request.remote)
return self.json(
{"error": "unsupported_grant_type"}, status_code=HTTP_BAD_REQUEST
) | [
"async",
"def",
"post",
"(",
"self",
",",
"request",
")",
":",
"hass",
"=",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
"data",
"=",
"await",
"request",
".",
"post",
"(",
")",
"grant_type",
"=",
"data",
".",
"get",
"(",
"\"grant_type\"",
")",
"# IndieAuth 6.3.5",
"# The revocation endpoint is the same as the token endpoint.",
"# The revocation request includes an additional parameter,",
"# action=revoke.",
"if",
"data",
".",
"get",
"(",
"\"action\"",
")",
"==",
"\"revoke\"",
":",
"return",
"await",
"self",
".",
"_async_handle_revoke_token",
"(",
"hass",
",",
"data",
")",
"if",
"grant_type",
"==",
"\"authorization_code\"",
":",
"return",
"await",
"self",
".",
"_async_handle_auth_code",
"(",
"hass",
",",
"data",
",",
"request",
".",
"remote",
")",
"if",
"grant_type",
"==",
"\"refresh_token\"",
":",
"return",
"await",
"self",
".",
"_async_handle_refresh_token",
"(",
"hass",
",",
"data",
",",
"request",
".",
"remote",
")",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"unsupported_grant_type\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
")"
] | [
235,
4
] | [
257,
9
] | python | en | ['en', 'gl', 'en'] | True |
TokenView._async_handle_revoke_token | (self, hass, data) | Handle revoke token request. | Handle revoke token request. | async def _async_handle_revoke_token(self, hass, data):
"""Handle revoke token request."""
# OAuth 2.0 Token Revocation [RFC7009]
# 2.2 The authorization server responds with HTTP status code 200
# if the token has been revoked successfully or if the client
# submitted an invalid token.
token = data.get("token")
if token is None:
return web.Response(status=HTTP_OK)
refresh_token = await hass.auth.async_get_refresh_token_by_token(token)
if refresh_token is None:
return web.Response(status=HTTP_OK)
await hass.auth.async_remove_refresh_token(refresh_token)
return web.Response(status=HTTP_OK) | [
"async",
"def",
"_async_handle_revoke_token",
"(",
"self",
",",
"hass",
",",
"data",
")",
":",
"# OAuth 2.0 Token Revocation [RFC7009]",
"# 2.2 The authorization server responds with HTTP status code 200",
"# if the token has been revoked successfully or if the client",
"# submitted an invalid token.",
"token",
"=",
"data",
".",
"get",
"(",
"\"token\"",
")",
"if",
"token",
"is",
"None",
":",
"return",
"web",
".",
"Response",
"(",
"status",
"=",
"HTTP_OK",
")",
"refresh_token",
"=",
"await",
"hass",
".",
"auth",
".",
"async_get_refresh_token_by_token",
"(",
"token",
")",
"if",
"refresh_token",
"is",
"None",
":",
"return",
"web",
".",
"Response",
"(",
"status",
"=",
"HTTP_OK",
")",
"await",
"hass",
".",
"auth",
".",
"async_remove_refresh_token",
"(",
"refresh_token",
")",
"return",
"web",
".",
"Response",
"(",
"status",
"=",
"HTTP_OK",
")"
] | [
259,
4
] | [
276,
43
] | python | nl | ['nl', 'nl', 'en'] | True |
TokenView._async_handle_auth_code | (self, hass, data, remote_addr) | Handle authorization code request. | Handle authorization code request. | async def _async_handle_auth_code(self, hass, data, remote_addr):
"""Handle authorization code request."""
client_id = data.get("client_id")
if client_id is None or not indieauth.verify_client_id(client_id):
return self.json(
{"error": "invalid_request", "error_description": "Invalid client id"},
status_code=HTTP_BAD_REQUEST,
)
code = data.get("code")
if code is None:
return self.json(
{"error": "invalid_request", "error_description": "Invalid code"},
status_code=HTTP_BAD_REQUEST,
)
user = self._retrieve_user(client_id, RESULT_TYPE_USER, code)
if user is None or not isinstance(user, User):
return self.json(
{"error": "invalid_request", "error_description": "Invalid code"},
status_code=HTTP_BAD_REQUEST,
)
# refresh user
user = await hass.auth.async_get_user(user.id)
if not user.is_active:
return self.json(
{"error": "access_denied", "error_description": "User is not active"},
status_code=HTTP_FORBIDDEN,
)
refresh_token = await hass.auth.async_create_refresh_token(user, client_id)
access_token = hass.auth.async_create_access_token(refresh_token, remote_addr)
return self.json(
{
"access_token": access_token,
"token_type": "Bearer",
"refresh_token": refresh_token.token,
"expires_in": int(
refresh_token.access_token_expiration.total_seconds()
),
}
) | [
"async",
"def",
"_async_handle_auth_code",
"(",
"self",
",",
"hass",
",",
"data",
",",
"remote_addr",
")",
":",
"client_id",
"=",
"data",
".",
"get",
"(",
"\"client_id\"",
")",
"if",
"client_id",
"is",
"None",
"or",
"not",
"indieauth",
".",
"verify_client_id",
"(",
"client_id",
")",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
",",
"\"error_description\"",
":",
"\"Invalid client id\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
",",
")",
"code",
"=",
"data",
".",
"get",
"(",
"\"code\"",
")",
"if",
"code",
"is",
"None",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
",",
"\"error_description\"",
":",
"\"Invalid code\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
",",
")",
"user",
"=",
"self",
".",
"_retrieve_user",
"(",
"client_id",
",",
"RESULT_TYPE_USER",
",",
"code",
")",
"if",
"user",
"is",
"None",
"or",
"not",
"isinstance",
"(",
"user",
",",
"User",
")",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
",",
"\"error_description\"",
":",
"\"Invalid code\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
",",
")",
"# refresh user",
"user",
"=",
"await",
"hass",
".",
"auth",
".",
"async_get_user",
"(",
"user",
".",
"id",
")",
"if",
"not",
"user",
".",
"is_active",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"access_denied\"",
",",
"\"error_description\"",
":",
"\"User is not active\"",
"}",
",",
"status_code",
"=",
"HTTP_FORBIDDEN",
",",
")",
"refresh_token",
"=",
"await",
"hass",
".",
"auth",
".",
"async_create_refresh_token",
"(",
"user",
",",
"client_id",
")",
"access_token",
"=",
"hass",
".",
"auth",
".",
"async_create_access_token",
"(",
"refresh_token",
",",
"remote_addr",
")",
"return",
"self",
".",
"json",
"(",
"{",
"\"access_token\"",
":",
"access_token",
",",
"\"token_type\"",
":",
"\"Bearer\"",
",",
"\"refresh_token\"",
":",
"refresh_token",
".",
"token",
",",
"\"expires_in\"",
":",
"int",
"(",
"refresh_token",
".",
"access_token_expiration",
".",
"total_seconds",
"(",
")",
")",
",",
"}",
")"
] | [
278,
4
] | [
324,
9
] | python | en | ['de', 'en', 'en'] | True |
TokenView._async_handle_refresh_token | (self, hass, data, remote_addr) | Handle authorization code request. | Handle authorization code request. | async def _async_handle_refresh_token(self, hass, data, remote_addr):
"""Handle authorization code request."""
client_id = data.get("client_id")
if client_id is not None and not indieauth.verify_client_id(client_id):
return self.json(
{"error": "invalid_request", "error_description": "Invalid client id"},
status_code=HTTP_BAD_REQUEST,
)
token = data.get("refresh_token")
if token is None:
return self.json({"error": "invalid_request"}, status_code=HTTP_BAD_REQUEST)
refresh_token = await hass.auth.async_get_refresh_token_by_token(token)
if refresh_token is None:
return self.json({"error": "invalid_grant"}, status_code=HTTP_BAD_REQUEST)
if refresh_token.client_id != client_id:
return self.json({"error": "invalid_request"}, status_code=HTTP_BAD_REQUEST)
access_token = hass.auth.async_create_access_token(refresh_token, remote_addr)
return self.json(
{
"access_token": access_token,
"token_type": "Bearer",
"expires_in": int(
refresh_token.access_token_expiration.total_seconds()
),
}
) | [
"async",
"def",
"_async_handle_refresh_token",
"(",
"self",
",",
"hass",
",",
"data",
",",
"remote_addr",
")",
":",
"client_id",
"=",
"data",
".",
"get",
"(",
"\"client_id\"",
")",
"if",
"client_id",
"is",
"not",
"None",
"and",
"not",
"indieauth",
".",
"verify_client_id",
"(",
"client_id",
")",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
",",
"\"error_description\"",
":",
"\"Invalid client id\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
",",
")",
"token",
"=",
"data",
".",
"get",
"(",
"\"refresh_token\"",
")",
"if",
"token",
"is",
"None",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
")",
"refresh_token",
"=",
"await",
"hass",
".",
"auth",
".",
"async_get_refresh_token_by_token",
"(",
"token",
")",
"if",
"refresh_token",
"is",
"None",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_grant\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
")",
"if",
"refresh_token",
".",
"client_id",
"!=",
"client_id",
":",
"return",
"self",
".",
"json",
"(",
"{",
"\"error\"",
":",
"\"invalid_request\"",
"}",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
")",
"access_token",
"=",
"hass",
".",
"auth",
".",
"async_create_access_token",
"(",
"refresh_token",
",",
"remote_addr",
")",
"return",
"self",
".",
"json",
"(",
"{",
"\"access_token\"",
":",
"access_token",
",",
"\"token_type\"",
":",
"\"Bearer\"",
",",
"\"expires_in\"",
":",
"int",
"(",
"refresh_token",
".",
"access_token_expiration",
".",
"total_seconds",
"(",
")",
")",
",",
"}",
")"
] | [
326,
4
] | [
358,
9
] | python | en | ['de', 'en', 'en'] | True |
LinkUserView.__init__ | (self, retrieve_credentials) | Initialize the link user view. | Initialize the link user view. | def __init__(self, retrieve_credentials):
"""Initialize the link user view."""
self._retrieve_credentials = retrieve_credentials | [
"def",
"__init__",
"(",
"self",
",",
"retrieve_credentials",
")",
":",
"self",
".",
"_retrieve_credentials",
"=",
"retrieve_credentials"
] | [
367,
4
] | [
369,
57
] | python | en | ['en', 'en', 'en'] | True |
LinkUserView.post | (self, request, data) | Link a user. | Link a user. | async def post(self, request, data):
"""Link a user."""
hass = request.app["hass"]
user = request["hass_user"]
credentials = self._retrieve_credentials(
data["client_id"], RESULT_TYPE_CREDENTIALS, data["code"]
)
if credentials is None:
return self.json_message("Invalid code", status_code=HTTP_BAD_REQUEST)
await hass.auth.async_link_user(user, credentials)
return self.json_message("User linked") | [
"async",
"def",
"post",
"(",
"self",
",",
"request",
",",
"data",
")",
":",
"hass",
"=",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
"user",
"=",
"request",
"[",
"\"hass_user\"",
"]",
"credentials",
"=",
"self",
".",
"_retrieve_credentials",
"(",
"data",
"[",
"\"client_id\"",
"]",
",",
"RESULT_TYPE_CREDENTIALS",
",",
"data",
"[",
"\"code\"",
"]",
")",
"if",
"credentials",
"is",
"None",
":",
"return",
"self",
".",
"json_message",
"(",
"\"Invalid code\"",
",",
"status_code",
"=",
"HTTP_BAD_REQUEST",
")",
"await",
"hass",
".",
"auth",
".",
"async_link_user",
"(",
"user",
",",
"credentials",
")",
"return",
"self",
".",
"json_message",
"(",
"\"User linked\"",
")"
] | [
372,
4
] | [
385,
47
] | python | en | ['es', 'en', 'en'] | True |
FlaubertConfig.__init__ | (self, layerdrop=0.0, pre_norm=False, pad_token_id=2, bos_token_id=0, **kwargs) | Constructs FlaubertConfig. | Constructs FlaubertConfig. | def __init__(self, layerdrop=0.0, pre_norm=False, pad_token_id=2, bos_token_id=0, **kwargs):
"""Constructs FlaubertConfig."""
super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, **kwargs)
self.layerdrop = layerdrop
self.pre_norm = pre_norm | [
"def",
"__init__",
"(",
"self",
",",
"layerdrop",
"=",
"0.0",
",",
"pre_norm",
"=",
"False",
",",
"pad_token_id",
"=",
"2",
",",
"bos_token_id",
"=",
"0",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"pad_token_id",
"=",
"pad_token_id",
",",
"bos_token_id",
"=",
"bos_token_id",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"layerdrop",
"=",
"layerdrop",
"self",
".",
"pre_norm",
"=",
"pre_norm"
] | [
136,
4
] | [
140,
32
] | python | de | ['en', 'de', 'it'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Verisure platform. | Set up the Verisure platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Verisure platform."""
sensors = []
hub.update_overview()
if int(hub.config.get(CONF_THERMOMETERS, 1)):
sensors.extend(
[
VerisureThermometer(device_label)
for device_label in hub.get(
"$.climateValues[?(@.temperature)].deviceLabel"
)
]
)
if int(hub.config.get(CONF_HYDROMETERS, 1)):
sensors.extend(
[
VerisureHygrometer(device_label)
for device_label in hub.get(
"$.climateValues[?(@.humidity)].deviceLabel"
)
]
)
if int(hub.config.get(CONF_MOUSE, 1)):
sensors.extend(
[
VerisureMouseDetection(device_label)
for device_label in hub.get(
"$.eventCounts[?(@.deviceType=='MOUSE1')].deviceLabel"
)
]
)
add_entities(sensors) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"sensors",
"=",
"[",
"]",
"hub",
".",
"update_overview",
"(",
")",
"if",
"int",
"(",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_THERMOMETERS",
",",
"1",
")",
")",
":",
"sensors",
".",
"extend",
"(",
"[",
"VerisureThermometer",
"(",
"device_label",
")",
"for",
"device_label",
"in",
"hub",
".",
"get",
"(",
"\"$.climateValues[?(@.temperature)].deviceLabel\"",
")",
"]",
")",
"if",
"int",
"(",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_HYDROMETERS",
",",
"1",
")",
")",
":",
"sensors",
".",
"extend",
"(",
"[",
"VerisureHygrometer",
"(",
"device_label",
")",
"for",
"device_label",
"in",
"hub",
".",
"get",
"(",
"\"$.climateValues[?(@.humidity)].deviceLabel\"",
")",
"]",
")",
"if",
"int",
"(",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_MOUSE",
",",
"1",
")",
")",
":",
"sensors",
".",
"extend",
"(",
"[",
"VerisureMouseDetection",
"(",
"device_label",
")",
"for",
"device_label",
"in",
"hub",
".",
"get",
"(",
"\"$.eventCounts[?(@.deviceType=='MOUSE1')].deviceLabel\"",
")",
"]",
")",
"add_entities",
"(",
"sensors",
")"
] | [
7,
0
] | [
42,
25
] | python | en | ['en', 'lv', 'en'] | True |
VerisureThermometer.__init__ | (self, device_label) | Initialize the sensor. | Initialize the sensor. | def __init__(self, device_label):
"""Initialize the sensor."""
self._device_label = device_label | [
"def",
"__init__",
"(",
"self",
",",
"device_label",
")",
":",
"self",
".",
"_device_label",
"=",
"device_label"
] | [
48,
4
] | [
50,
41
] | python | en | ['en', 'en', 'en'] | True |
VerisureThermometer.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return (
hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].deviceArea", self._device_label
)
+ " temperature"
) | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].deviceArea\"",
",",
"self",
".",
"_device_label",
")",
"+",
"\" temperature\"",
")"
] | [
53,
4
] | [
60,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureThermometer.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].temperature", self._device_label
) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].temperature\"",
",",
"self",
".",
"_device_label",
")"
] | [
63,
4
] | [
67,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureThermometer.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return (
hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].temperature",
self._device_label,
)
is not None
) | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].temperature\"",
",",
"self",
".",
"_device_label",
",",
")",
"is",
"not",
"None",
")"
] | [
70,
4
] | [
78,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureThermometer.unit_of_measurement | (self) | Return the unit of measurement of this entity. | Return the unit of measurement of this entity. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return TEMP_CELSIUS | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"TEMP_CELSIUS"
] | [
81,
4
] | [
83,
27
] | python | en | ['en', 'en', 'en'] | True |
VerisureThermometer.update | (self) | Update the sensor. | Update the sensor. | def update(self):
"""Update the sensor."""
hub.update_overview() | [
"def",
"update",
"(",
"self",
")",
":",
"hub",
".",
"update_overview",
"(",
")"
] | [
86,
4
] | [
88,
29
] | python | en | ['en', 'nl', 'en'] | True |
VerisureHygrometer.__init__ | (self, device_label) | Initialize the sensor. | Initialize the sensor. | def __init__(self, device_label):
"""Initialize the sensor."""
self._device_label = device_label | [
"def",
"__init__",
"(",
"self",
",",
"device_label",
")",
":",
"self",
".",
"_device_label",
"=",
"device_label"
] | [
94,
4
] | [
96,
41
] | python | en | ['en', 'en', 'en'] | True |
VerisureHygrometer.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return (
hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].deviceArea", self._device_label
)
+ " humidity"
) | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].deviceArea\"",
",",
"self",
".",
"_device_label",
")",
"+",
"\" humidity\"",
")"
] | [
99,
4
] | [
106,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureHygrometer.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].humidity", self._device_label
) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].humidity\"",
",",
"self",
".",
"_device_label",
")"
] | [
109,
4
] | [
113,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureHygrometer.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return (
hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].humidity", self._device_label
)
is not None
) | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.climateValues[?(@.deviceLabel=='%s')].humidity\"",
",",
"self",
".",
"_device_label",
")",
"is",
"not",
"None",
")"
] | [
116,
4
] | [
123,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureHygrometer.unit_of_measurement | (self) | Return the unit of measurement of this entity. | Return the unit of measurement of this entity. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return PERCENTAGE | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"PERCENTAGE"
] | [
126,
4
] | [
128,
25
] | python | en | ['en', 'en', 'en'] | True |
VerisureHygrometer.update | (self) | Update the sensor. | Update the sensor. | def update(self):
"""Update the sensor."""
hub.update_overview() | [
"def",
"update",
"(",
"self",
")",
":",
"hub",
".",
"update_overview",
"(",
")"
] | [
131,
4
] | [
133,
29
] | python | en | ['en', 'nl', 'en'] | True |
VerisureMouseDetection.__init__ | (self, device_label) | Initialize the sensor. | Initialize the sensor. | def __init__(self, device_label):
"""Initialize the sensor."""
self._device_label = device_label | [
"def",
"__init__",
"(",
"self",
",",
"device_label",
")",
":",
"self",
".",
"_device_label",
"=",
"device_label"
] | [
139,
4
] | [
141,
41
] | python | en | ['en', 'en', 'en'] | True |
VerisureMouseDetection.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return (
hub.get_first(
"$.eventCounts[?(@.deviceLabel=='%s')].area", self._device_label
)
+ " mouse"
) | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.eventCounts[?(@.deviceLabel=='%s')].area\"",
",",
"self",
".",
"_device_label",
")",
"+",
"\" mouse\"",
")"
] | [
144,
4
] | [
151,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureMouseDetection.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return hub.get_first(
"$.eventCounts[?(@.deviceLabel=='%s')].detections", self._device_label
) | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"hub",
".",
"get_first",
"(",
"\"$.eventCounts[?(@.deviceLabel=='%s')].detections\"",
",",
"self",
".",
"_device_label",
")"
] | [
154,
4
] | [
158,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureMouseDetection.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return (
hub.get_first("$.eventCounts[?(@.deviceLabel=='%s')]", self._device_label)
is not None
) | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"(",
"hub",
".",
"get_first",
"(",
"\"$.eventCounts[?(@.deviceLabel=='%s')]\"",
",",
"self",
".",
"_device_label",
")",
"is",
"not",
"None",
")"
] | [
161,
4
] | [
166,
9
] | python | en | ['en', 'en', 'en'] | True |
VerisureMouseDetection.unit_of_measurement | (self) | Return the unit of measurement of this entity. | Return the unit of measurement of this entity. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return "Mice" | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"\"Mice\""
] | [
169,
4
] | [
171,
21
] | python | en | ['en', 'en', 'en'] | True |
VerisureMouseDetection.update | (self) | Update the sensor. | Update the sensor. | def update(self):
"""Update the sensor."""
hub.update_overview() | [
"def",
"update",
"(",
"self",
")",
":",
"hub",
".",
"update_overview",
"(",
")"
] | [
174,
4
] | [
176,
29
] | python | en | ['en', 'nl', 'en'] | True |
round_temp | (temperature) | Round a temperature to the resolution of the thermostat.
RadioThermostats can handle 0.5 degree temps so the input
temperature is rounded to that value and returned.
| Round a temperature to the resolution of the thermostat. | def round_temp(temperature):
"""Round a temperature to the resolution of the thermostat.
RadioThermostats can handle 0.5 degree temps so the input
temperature is rounded to that value and returned.
"""
return round(temperature * 2.0) / 2.0 | [
"def",
"round_temp",
"(",
"temperature",
")",
":",
"return",
"round",
"(",
"temperature",
"*",
"2.0",
")",
"/",
"2.0"
] | [
82,
0
] | [
88,
41
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Radio Thermostat. | Set up the Radio Thermostat. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Radio Thermostat."""
hosts = []
if CONF_HOST in config:
hosts = config[CONF_HOST]
else:
hosts.append(radiotherm.discover.discover_address())
if hosts is None:
_LOGGER.error("No Radiotherm Thermostats detected")
return False
hold_temp = config.get(CONF_HOLD_TEMP)
tstats = []
for host in hosts:
try:
tstat = radiotherm.get_thermostat(host)
tstats.append(RadioThermostat(tstat, hold_temp))
except OSError:
_LOGGER.exception("Unable to connect to Radio Thermostat: %s", host)
add_entities(tstats, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"hosts",
"=",
"[",
"]",
"if",
"CONF_HOST",
"in",
"config",
":",
"hosts",
"=",
"config",
"[",
"CONF_HOST",
"]",
"else",
":",
"hosts",
".",
"append",
"(",
"radiotherm",
".",
"discover",
".",
"discover_address",
"(",
")",
")",
"if",
"hosts",
"is",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"No Radiotherm Thermostats detected\"",
")",
"return",
"False",
"hold_temp",
"=",
"config",
".",
"get",
"(",
"CONF_HOLD_TEMP",
")",
"tstats",
"=",
"[",
"]",
"for",
"host",
"in",
"hosts",
":",
"try",
":",
"tstat",
"=",
"radiotherm",
".",
"get_thermostat",
"(",
"host",
")",
"tstats",
".",
"append",
"(",
"RadioThermostat",
"(",
"tstat",
",",
"hold_temp",
")",
")",
"except",
"OSError",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Unable to connect to Radio Thermostat: %s\"",
",",
"host",
")",
"add_entities",
"(",
"tstats",
",",
"True",
")"
] | [
102,
0
] | [
124,
30
] | python | en | ['en', 'ja', 'en'] | True |
RadioThermostat.__init__ | (self, device, hold_temp) | Initialize the thermostat. | Initialize the thermostat. | def __init__(self, device, hold_temp):
"""Initialize the thermostat."""
self.device = device
self._target_temperature = None
self._current_temperature = None
self._current_humidity = None
self._current_operation = HVAC_MODE_OFF
self._name = None
self._fmode = None
self._fstate = None
self._tmode = None
self._tstate = None
self._hold_temp = hold_temp
self._hold_set = False
self._prev_temp = None
self._preset_mode = None
self._program_mode = None
self._is_away = False
# Fan circulate mode is only supported by the CT80 models.
self._is_model_ct80 = isinstance(self.device, radiotherm.thermostat.CT80) | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"hold_temp",
")",
":",
"self",
".",
"device",
"=",
"device",
"self",
".",
"_target_temperature",
"=",
"None",
"self",
".",
"_current_temperature",
"=",
"None",
"self",
".",
"_current_humidity",
"=",
"None",
"self",
".",
"_current_operation",
"=",
"HVAC_MODE_OFF",
"self",
".",
"_name",
"=",
"None",
"self",
".",
"_fmode",
"=",
"None",
"self",
".",
"_fstate",
"=",
"None",
"self",
".",
"_tmode",
"=",
"None",
"self",
".",
"_tstate",
"=",
"None",
"self",
".",
"_hold_temp",
"=",
"hold_temp",
"self",
".",
"_hold_set",
"=",
"False",
"self",
".",
"_prev_temp",
"=",
"None",
"self",
".",
"_preset_mode",
"=",
"None",
"self",
".",
"_program_mode",
"=",
"None",
"self",
".",
"_is_away",
"=",
"False",
"# Fan circulate mode is only supported by the CT80 models.",
"self",
".",
"_is_model_ct80",
"=",
"isinstance",
"(",
"self",
".",
"device",
",",
"radiotherm",
".",
"thermostat",
".",
"CT80",
")"
] | [
130,
4
] | [
150,
81
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.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 SUPPORT_FLAGS | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_FLAGS"
] | [
153,
4
] | [
155,
28
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
# Set the time on the device. This shouldn't be in the
# constructor because it's a network call. We can't put it in
# update() because calling it will clear any temporary mode or
# temperature in the thermostat. So add it as a future job
# for the event loop to run.
self.hass.async_add_job(self.set_time) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"# Set the time on the device. This shouldn't be in the",
"# constructor because it's a network call. We can't put it in",
"# update() because calling it will clear any temporary mode or",
"# temperature in the thermostat. So add it as a future job",
"# for the event loop to run.",
"self",
".",
"hass",
".",
"async_add_job",
"(",
"self",
".",
"set_time",
")"
] | [
157,
4
] | [
164,
46
] | python | en | ['en', 'no', 'en'] | False |
RadioThermostat.name | (self) | Return the name of the Radio Thermostat. | Return the name of the Radio Thermostat. | def name(self):
"""Return the name of the Radio Thermostat."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
167,
4
] | [
169,
25
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.temperature_unit | (self) | Return the unit of measurement. | Return the unit of measurement. | def temperature_unit(self):
"""Return the unit of measurement."""
return TEMP_FAHRENHEIT | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"TEMP_FAHRENHEIT"
] | [
172,
4
] | [
174,
30
] | python | en | ['en', 'la', 'en'] | True |
RadioThermostat.precision | (self) | Return the precision of the system. | Return the precision of the system. | def precision(self):
"""Return the precision of the system."""
return PRECISION_HALVES | [
"def",
"precision",
"(",
"self",
")",
":",
"return",
"PRECISION_HALVES"
] | [
177,
4
] | [
179,
31
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.device_state_attributes | (self) | Return the device specific state attributes. | Return the device specific state attributes. | def device_state_attributes(self):
"""Return the device specific state attributes."""
return {ATTR_FAN_ACTION: self._fstate} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_FAN_ACTION",
":",
"self",
".",
"_fstate",
"}"
] | [
182,
4
] | [
184,
46
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.fan_modes | (self) | List of available fan modes. | List of available fan modes. | def fan_modes(self):
"""List of available fan modes."""
if self._is_model_ct80:
return CT80_FAN_OPERATION_LIST
return CT30_FAN_OPERATION_LIST | [
"def",
"fan_modes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_is_model_ct80",
":",
"return",
"CT80_FAN_OPERATION_LIST",
"return",
"CT30_FAN_OPERATION_LIST"
] | [
187,
4
] | [
191,
38
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.fan_mode | (self) | Return whether the fan is on. | Return whether the fan is on. | def fan_mode(self):
"""Return whether the fan is on."""
return self._fmode | [
"def",
"fan_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fmode"
] | [
194,
4
] | [
196,
26
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.set_fan_mode | (self, fan_mode) | Turn fan on/off. | Turn fan on/off. | def set_fan_mode(self, fan_mode):
"""Turn fan on/off."""
code = FAN_MODE_TO_CODE.get(fan_mode)
if code is not None:
self.device.fmode = code | [
"def",
"set_fan_mode",
"(",
"self",
",",
"fan_mode",
")",
":",
"code",
"=",
"FAN_MODE_TO_CODE",
".",
"get",
"(",
"fan_mode",
")",
"if",
"code",
"is",
"not",
"None",
":",
"self",
".",
"device",
".",
"fmode",
"=",
"code"
] | [
198,
4
] | [
202,
36
] | python | en | ['en', 'fy', 'en'] | True |
RadioThermostat.current_temperature | (self) | Return the current temperature. | Return the current temperature. | def current_temperature(self):
"""Return the current temperature."""
return self._current_temperature | [
"def",
"current_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_temperature"
] | [
205,
4
] | [
207,
40
] | python | en | ['en', 'la', 'en'] | True |
RadioThermostat.current_humidity | (self) | Return the current temperature. | Return the current temperature. | def current_humidity(self):
"""Return the current temperature."""
return self._current_humidity | [
"def",
"current_humidity",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_humidity"
] | [
210,
4
] | [
212,
37
] | python | en | ['en', 'la', 'en'] | True |
RadioThermostat.hvac_mode | (self) | Return the current operation. head, cool idle. | Return the current operation. head, cool idle. | def hvac_mode(self):
"""Return the current operation. head, cool idle."""
return self._current_operation | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_operation"
] | [
215,
4
] | [
217,
38
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.hvac_modes | (self) | Return the operation modes list. | Return the operation modes list. | def hvac_modes(self):
"""Return the operation modes list."""
return OPERATION_LIST | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"OPERATION_LIST"
] | [
220,
4
] | [
222,
29
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.hvac_action | (self) | Return the current running hvac operation if supported. | Return the current running hvac operation if supported. | def hvac_action(self):
"""Return the current running hvac operation if supported."""
if self.hvac_mode == HVAC_MODE_OFF:
return None
return self._tstate | [
"def",
"hvac_action",
"(",
"self",
")",
":",
"if",
"self",
".",
"hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"return",
"None",
"return",
"self",
".",
"_tstate"
] | [
225,
4
] | [
229,
27
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.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_temperature | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_target_temperature"
] | [
232,
4
] | [
234,
39
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.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."""
if self._program_mode == 0:
return PRESET_HOME
if self._program_mode == 1:
return PRESET_ALTERNATE
if self._program_mode == 2:
return PRESET_AWAY
if self._program_mode == 3:
return PRESET_HOLIDAY | [
"def",
"preset_mode",
"(",
"self",
")",
":",
"if",
"self",
".",
"_program_mode",
"==",
"0",
":",
"return",
"PRESET_HOME",
"if",
"self",
".",
"_program_mode",
"==",
"1",
":",
"return",
"PRESET_ALTERNATE",
"if",
"self",
".",
"_program_mode",
"==",
"2",
":",
"return",
"PRESET_AWAY",
"if",
"self",
".",
"_program_mode",
"==",
"3",
":",
"return",
"PRESET_HOLIDAY"
] | [
237,
4
] | [
246,
33
] | python | en | ['en', 'pt', 'en'] | True |
RadioThermostat.preset_modes | (self) | Return a list of available preset modes. | Return a list of available preset modes. | def preset_modes(self):
"""Return a list of available preset modes."""
return PRESET_MODES | [
"def",
"preset_modes",
"(",
"self",
")",
":",
"return",
"PRESET_MODES"
] | [
249,
4
] | [
251,
27
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.update | (self) | Update and validate the data from the thermostat. | Update and validate the data from the thermostat. | def update(self):
"""Update and validate the data from the thermostat."""
# Radio thermostats are very slow, and sometimes don't respond
# very quickly. So we need to keep the number of calls to them
# to a bare minimum or we'll hit the Home Assistant 10 sec warning. We
# have to make one call to /tstat to get temps but we'll try and
# keep the other calls to a minimum. Even with this, these
# thermostats tend to time out sometimes when they're actively
# heating or cooling.
# First time - get the name from the thermostat. This is
# normally set in the radio thermostat web app.
if self._name is None:
self._name = self.device.name["raw"]
# Request the current state from the thermostat.
try:
data = self.device.tstat["raw"]
except radiotherm.validate.RadiothermTstatError:
_LOGGER.warning(
"%s (%s) was busy (invalid value returned)",
self._name,
self.device.host,
)
return
current_temp = data["temp"]
if self._is_model_ct80:
try:
humiditydata = self.device.humidity["raw"]
except radiotherm.validate.RadiothermTstatError:
_LOGGER.warning(
"%s (%s) was busy (invalid value returned)",
self._name,
self.device.host,
)
return
self._current_humidity = humiditydata
self._program_mode = data["program_mode"]
self._preset_mode = CODE_TO_PRESET_MODE[data["program_mode"]]
# Map thermostat values into various STATE_ flags.
self._current_temperature = current_temp
self._fmode = CODE_TO_FAN_MODE[data["fmode"]]
self._fstate = CODE_TO_FAN_STATE[data["fstate"]]
self._tmode = CODE_TO_TEMP_MODE[data["tmode"]]
self._tstate = CODE_TO_TEMP_STATE[data["tstate"]]
self._current_operation = self._tmode
if self._tmode == HVAC_MODE_COOL:
self._target_temperature = data["t_cool"]
elif self._tmode == HVAC_MODE_HEAT:
self._target_temperature = data["t_heat"]
elif self._tmode == HVAC_MODE_AUTO:
# This doesn't really work - tstate is only set if the HVAC is
# active. If it's idle, we don't know what to do with the target
# temperature.
if self._tstate == CURRENT_HVAC_COOL:
self._target_temperature = data["t_cool"]
elif self._tstate == CURRENT_HVAC_HEAT:
self._target_temperature = data["t_heat"]
else:
self._current_operation = HVAC_MODE_OFF | [
"def",
"update",
"(",
"self",
")",
":",
"# Radio thermostats are very slow, and sometimes don't respond",
"# very quickly. So we need to keep the number of calls to them",
"# to a bare minimum or we'll hit the Home Assistant 10 sec warning. We",
"# have to make one call to /tstat to get temps but we'll try and",
"# keep the other calls to a minimum. Even with this, these",
"# thermostats tend to time out sometimes when they're actively",
"# heating or cooling.",
"# First time - get the name from the thermostat. This is",
"# normally set in the radio thermostat web app.",
"if",
"self",
".",
"_name",
"is",
"None",
":",
"self",
".",
"_name",
"=",
"self",
".",
"device",
".",
"name",
"[",
"\"raw\"",
"]",
"# Request the current state from the thermostat.",
"try",
":",
"data",
"=",
"self",
".",
"device",
".",
"tstat",
"[",
"\"raw\"",
"]",
"except",
"radiotherm",
".",
"validate",
".",
"RadiothermTstatError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"%s (%s) was busy (invalid value returned)\"",
",",
"self",
".",
"_name",
",",
"self",
".",
"device",
".",
"host",
",",
")",
"return",
"current_temp",
"=",
"data",
"[",
"\"temp\"",
"]",
"if",
"self",
".",
"_is_model_ct80",
":",
"try",
":",
"humiditydata",
"=",
"self",
".",
"device",
".",
"humidity",
"[",
"\"raw\"",
"]",
"except",
"radiotherm",
".",
"validate",
".",
"RadiothermTstatError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"%s (%s) was busy (invalid value returned)\"",
",",
"self",
".",
"_name",
",",
"self",
".",
"device",
".",
"host",
",",
")",
"return",
"self",
".",
"_current_humidity",
"=",
"humiditydata",
"self",
".",
"_program_mode",
"=",
"data",
"[",
"\"program_mode\"",
"]",
"self",
".",
"_preset_mode",
"=",
"CODE_TO_PRESET_MODE",
"[",
"data",
"[",
"\"program_mode\"",
"]",
"]",
"# Map thermostat values into various STATE_ flags.",
"self",
".",
"_current_temperature",
"=",
"current_temp",
"self",
".",
"_fmode",
"=",
"CODE_TO_FAN_MODE",
"[",
"data",
"[",
"\"fmode\"",
"]",
"]",
"self",
".",
"_fstate",
"=",
"CODE_TO_FAN_STATE",
"[",
"data",
"[",
"\"fstate\"",
"]",
"]",
"self",
".",
"_tmode",
"=",
"CODE_TO_TEMP_MODE",
"[",
"data",
"[",
"\"tmode\"",
"]",
"]",
"self",
".",
"_tstate",
"=",
"CODE_TO_TEMP_STATE",
"[",
"data",
"[",
"\"tstate\"",
"]",
"]",
"self",
".",
"_current_operation",
"=",
"self",
".",
"_tmode",
"if",
"self",
".",
"_tmode",
"==",
"HVAC_MODE_COOL",
":",
"self",
".",
"_target_temperature",
"=",
"data",
"[",
"\"t_cool\"",
"]",
"elif",
"self",
".",
"_tmode",
"==",
"HVAC_MODE_HEAT",
":",
"self",
".",
"_target_temperature",
"=",
"data",
"[",
"\"t_heat\"",
"]",
"elif",
"self",
".",
"_tmode",
"==",
"HVAC_MODE_AUTO",
":",
"# This doesn't really work - tstate is only set if the HVAC is",
"# active. If it's idle, we don't know what to do with the target",
"# temperature.",
"if",
"self",
".",
"_tstate",
"==",
"CURRENT_HVAC_COOL",
":",
"self",
".",
"_target_temperature",
"=",
"data",
"[",
"\"t_cool\"",
"]",
"elif",
"self",
".",
"_tstate",
"==",
"CURRENT_HVAC_HEAT",
":",
"self",
".",
"_target_temperature",
"=",
"data",
"[",
"\"t_heat\"",
"]",
"else",
":",
"self",
".",
"_current_operation",
"=",
"HVAC_MODE_OFF"
] | [
253,
4
] | [
316,
51
] | python | en | ['en', 'en', 'en'] | True |
RadioThermostat.set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | def set_temperature(self, **kwargs):
"""Set new target temperature."""
temperature = kwargs.get(ATTR_TEMPERATURE)
if temperature is None:
return
temperature = round_temp(temperature)
if self._current_operation == HVAC_MODE_COOL:
self.device.t_cool = temperature
elif self._current_operation == HVAC_MODE_HEAT:
self.device.t_heat = temperature
elif self._current_operation == HVAC_MODE_AUTO:
if self._tstate == CURRENT_HVAC_COOL:
self.device.t_cool = temperature
elif self._tstate == CURRENT_HVAC_HEAT:
self.device.t_heat = temperature
# Only change the hold if requested or if hold mode was turned
# on and we haven't set it yet.
if kwargs.get("hold_changed", False) or not self._hold_set:
if self._hold_temp:
self.device.hold = 1
self._hold_set = True
else:
self.device.hold = 0 | [
"def",
"set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"if",
"temperature",
"is",
"None",
":",
"return",
"temperature",
"=",
"round_temp",
"(",
"temperature",
")",
"if",
"self",
".",
"_current_operation",
"==",
"HVAC_MODE_COOL",
":",
"self",
".",
"device",
".",
"t_cool",
"=",
"temperature",
"elif",
"self",
".",
"_current_operation",
"==",
"HVAC_MODE_HEAT",
":",
"self",
".",
"device",
".",
"t_heat",
"=",
"temperature",
"elif",
"self",
".",
"_current_operation",
"==",
"HVAC_MODE_AUTO",
":",
"if",
"self",
".",
"_tstate",
"==",
"CURRENT_HVAC_COOL",
":",
"self",
".",
"device",
".",
"t_cool",
"=",
"temperature",
"elif",
"self",
".",
"_tstate",
"==",
"CURRENT_HVAC_HEAT",
":",
"self",
".",
"device",
".",
"t_heat",
"=",
"temperature",
"# Only change the hold if requested or if hold mode was turned",
"# on and we haven't set it yet.",
"if",
"kwargs",
".",
"get",
"(",
"\"hold_changed\"",
",",
"False",
")",
"or",
"not",
"self",
".",
"_hold_set",
":",
"if",
"self",
".",
"_hold_temp",
":",
"self",
".",
"device",
".",
"hold",
"=",
"1",
"self",
".",
"_hold_set",
"=",
"True",
"else",
":",
"self",
".",
"device",
".",
"hold",
"=",
"0"
] | [
318,
4
] | [
343,
36
] | python | en | ['en', 'ca', 'en'] | True |
RadioThermostat.set_time | (self) | Set device time. | Set device time. | def set_time(self):
"""Set device time."""
# Calling this clears any local temperature override and
# reverts to the scheduled temperature.
now = dt_util.now()
self.device.time = {
"day": now.weekday(),
"hour": now.hour,
"minute": now.minute,
} | [
"def",
"set_time",
"(",
"self",
")",
":",
"# Calling this clears any local temperature override and",
"# reverts to the scheduled temperature.",
"now",
"=",
"dt_util",
".",
"now",
"(",
")",
"self",
".",
"device",
".",
"time",
"=",
"{",
"\"day\"",
":",
"now",
".",
"weekday",
"(",
")",
",",
"\"hour\"",
":",
"now",
".",
"hour",
",",
"\"minute\"",
":",
"now",
".",
"minute",
",",
"}"
] | [
345,
4
] | [
354,
9
] | python | en | ['fr', 'en', 'en'] | True |
RadioThermostat.set_hvac_mode | (self, hvac_mode) | Set operation mode (auto, cool, heat, off). | Set operation mode (auto, cool, heat, off). | def set_hvac_mode(self, hvac_mode):
"""Set operation mode (auto, cool, heat, off)."""
if hvac_mode in (HVAC_MODE_OFF, HVAC_MODE_AUTO):
self.device.tmode = TEMP_MODE_TO_CODE[hvac_mode]
# Setting t_cool or t_heat automatically changes tmode.
elif hvac_mode == HVAC_MODE_COOL:
self.device.t_cool = self._target_temperature
elif hvac_mode == HVAC_MODE_HEAT:
self.device.t_heat = self._target_temperature | [
"def",
"set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":",
"if",
"hvac_mode",
"in",
"(",
"HVAC_MODE_OFF",
",",
"HVAC_MODE_AUTO",
")",
":",
"self",
".",
"device",
".",
"tmode",
"=",
"TEMP_MODE_TO_CODE",
"[",
"hvac_mode",
"]",
"# Setting t_cool or t_heat automatically changes tmode.",
"elif",
"hvac_mode",
"==",
"HVAC_MODE_COOL",
":",
"self",
".",
"device",
".",
"t_cool",
"=",
"self",
".",
"_target_temperature",
"elif",
"hvac_mode",
"==",
"HVAC_MODE_HEAT",
":",
"self",
".",
"device",
".",
"t_heat",
"=",
"self",
".",
"_target_temperature"
] | [
356,
4
] | [
365,
57
] | python | en | ['nl', 'ny', 'en'] | False |
RadioThermostat.set_preset_mode | (self, preset_mode) | Set Preset mode (Home, Alternate, Away, Holiday). | Set Preset mode (Home, Alternate, Away, Holiday). | def set_preset_mode(self, preset_mode):
"""Set Preset mode (Home, Alternate, Away, Holiday)."""
if preset_mode in (PRESET_MODES):
self.device.program_mode = PRESET_MODE_TO_CODE[preset_mode]
else:
_LOGGER.error(
"preset_mode %s not in PRESET_MODES",
preset_mode,
) | [
"def",
"set_preset_mode",
"(",
"self",
",",
"preset_mode",
")",
":",
"if",
"preset_mode",
"in",
"(",
"PRESET_MODES",
")",
":",
"self",
".",
"device",
".",
"program_mode",
"=",
"PRESET_MODE_TO_CODE",
"[",
"preset_mode",
"]",
"else",
":",
"_LOGGER",
".",
"error",
"(",
"\"preset_mode %s not in PRESET_MODES\"",
",",
"preset_mode",
",",
")"
] | [
367,
4
] | [
375,
13
] | python | de | ['de', 'pt', 'en'] | False |
async_setup | (hass, config) | Component doesn't support configuration through configuration.yaml. | Component doesn't support configuration through configuration.yaml. | async def async_setup(hass, config):
"""Component doesn't support configuration through configuration.yaml."""
hass.data[UNIFI_WIRELESS_CLIENTS] = wireless_clients = UnifiWirelessClients(hass)
await wireless_clients.async_load()
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"hass",
".",
"data",
"[",
"UNIFI_WIRELESS_CLIENTS",
"]",
"=",
"wireless_clients",
"=",
"UnifiWirelessClients",
"(",
"hass",
")",
"await",
"wireless_clients",
".",
"async_load",
"(",
")",
"return",
"True"
] | [
19,
0
] | [
24,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry) | Set up the UniFi component. | Set up the UniFi component. | async def async_setup_entry(hass, config_entry):
"""Set up the UniFi component."""
hass.data.setdefault(UNIFI_DOMAIN, {})
controller = UniFiController(hass, config_entry)
if not await controller.async_setup():
return False
hass.data[UNIFI_DOMAIN][config_entry.entry_id] = controller
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, controller.shutdown)
LOGGER.debug("UniFi config options %s", config_entry.options)
if controller.mac is None:
return True
device_registry = await hass.helpers.device_registry.async_get_registry()
device_registry.async_get_or_create(
config_entry_id=config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, controller.mac)},
default_manufacturer=ATTR_MANUFACTURER,
default_model="UniFi Controller",
default_name="UniFi Controller",
)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"UNIFI_DOMAIN",
",",
"{",
"}",
")",
"controller",
"=",
"UniFiController",
"(",
"hass",
",",
"config_entry",
")",
"if",
"not",
"await",
"controller",
".",
"async_setup",
"(",
")",
":",
"return",
"False",
"hass",
".",
"data",
"[",
"UNIFI_DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"=",
"controller",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"controller",
".",
"shutdown",
")",
"LOGGER",
".",
"debug",
"(",
"\"UniFi config options %s\"",
",",
"config_entry",
".",
"options",
")",
"if",
"controller",
".",
"mac",
"is",
"None",
":",
"return",
"True",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"device_registry",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"CONNECTION_NETWORK_MAC",
",",
"controller",
".",
"mac",
")",
"}",
",",
"default_manufacturer",
"=",
"ATTR_MANUFACTURER",
",",
"default_model",
"=",
"\"UniFi Controller\"",
",",
"default_name",
"=",
"\"UniFi Controller\"",
",",
")",
"return",
"True"
] | [
27,
0
] | [
53,
15
] | python | en | ['en', 'fr', 'en'] | True |
async_unload_entry | (hass, config_entry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass, config_entry):
"""Unload a config entry."""
controller = hass.data[UNIFI_DOMAIN].pop(config_entry.entry_id)
return await controller.async_reset() | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"controller",
"=",
"hass",
".",
"data",
"[",
"UNIFI_DOMAIN",
"]",
".",
"pop",
"(",
"config_entry",
".",
"entry_id",
")",
"return",
"await",
"controller",
".",
"async_reset",
"(",
")"
] | [
56,
0
] | [
59,
41
] | python | en | ['en', 'es', 'en'] | True |
UnifiWirelessClients.__init__ | (self, hass) | Set up client storage. | Set up client storage. | def __init__(self, hass):
"""Set up client storage."""
self.hass = hass
self.data = {}
self._store = hass.helpers.storage.Store(STORAGE_VERSION, STORAGE_KEY) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"data",
"=",
"{",
"}",
"self",
".",
"_store",
"=",
"hass",
".",
"helpers",
".",
"storage",
".",
"Store",
"(",
"STORAGE_VERSION",
",",
"STORAGE_KEY",
")"
] | [
68,
4
] | [
72,
78
] | python | en | ['en', 'de', 'en'] | True |
UnifiWirelessClients.async_load | (self) | Load data from file. | Load data from file. | async def async_load(self):
"""Load data from file."""
data = await self._store.async_load()
if data is not None:
self.data = data | [
"async",
"def",
"async_load",
"(",
"self",
")",
":",
"data",
"=",
"await",
"self",
".",
"_store",
".",
"async_load",
"(",
")",
"if",
"data",
"is",
"not",
"None",
":",
"self",
".",
"data",
"=",
"data"
] | [
74,
4
] | [
79,
28
] | python | en | ['en', 'en', 'en'] | True |
UnifiWirelessClients.get_data | (self, config_entry) | Get data related to a specific controller. | Get data related to a specific controller. | def get_data(self, config_entry):
"""Get data related to a specific controller."""
controller_id = get_controller_id_from_config_entry(config_entry)
key = config_entry.entry_id
if controller_id in self.data:
key = controller_id
data = self.data.get(key, {"wireless_devices": []})
return set(data["wireless_devices"]) | [
"def",
"get_data",
"(",
"self",
",",
"config_entry",
")",
":",
"controller_id",
"=",
"get_controller_id_from_config_entry",
"(",
"config_entry",
")",
"key",
"=",
"config_entry",
".",
"entry_id",
"if",
"controller_id",
"in",
"self",
".",
"data",
":",
"key",
"=",
"controller_id",
"data",
"=",
"self",
".",
"data",
".",
"get",
"(",
"key",
",",
"{",
"\"wireless_devices\"",
":",
"[",
"]",
"}",
")",
"return",
"set",
"(",
"data",
"[",
"\"wireless_devices\"",
"]",
")"
] | [
82,
4
] | [
90,
44
] | python | en | ['en', 'en', 'en'] | True |
UnifiWirelessClients.update_data | (self, data, config_entry) | Update data and schedule to save to file. | Update data and schedule to save to file. | def update_data(self, data, config_entry):
"""Update data and schedule to save to file."""
controller_id = get_controller_id_from_config_entry(config_entry)
if controller_id in self.data:
self.data.pop(controller_id)
self.data[config_entry.entry_id] = {"wireless_devices": list(data)}
self._store.async_delay_save(self._data_to_save, SAVE_DELAY) | [
"def",
"update_data",
"(",
"self",
",",
"data",
",",
"config_entry",
")",
":",
"controller_id",
"=",
"get_controller_id_from_config_entry",
"(",
"config_entry",
")",
"if",
"controller_id",
"in",
"self",
".",
"data",
":",
"self",
".",
"data",
".",
"pop",
"(",
"controller_id",
")",
"self",
".",
"data",
"[",
"config_entry",
".",
"entry_id",
"]",
"=",
"{",
"\"wireless_devices\"",
":",
"list",
"(",
"data",
")",
"}",
"self",
".",
"_store",
".",
"async_delay_save",
"(",
"self",
".",
"_data_to_save",
",",
"SAVE_DELAY",
")"
] | [
93,
4
] | [
100,
68
] | python | en | ['en', 'en', 'en'] | True |
UnifiWirelessClients._data_to_save | (self) | Return data of UniFi wireless clients to store in a file. | Return data of UniFi wireless clients to store in a file. | def _data_to_save(self):
"""Return data of UniFi wireless clients to store in a file."""
return self.data | [
"def",
"_data_to_save",
"(",
"self",
")",
":",
"return",
"self",
".",
"data"
] | [
103,
4
] | [
105,
24
] | python | en | ['en', 'en', 'en'] | True |
light_devices_fixture | (device_factory) | Fixture returns a set of mock light devices. | Fixture returns a set of mock light devices. | def light_devices_fixture(device_factory):
"""Fixture returns a set of mock light devices."""
return [
device_factory(
"Dimmer 1",
capabilities=[Capability.switch, Capability.switch_level],
status={Attribute.switch: "on", Attribute.level: 100},
),
device_factory(
"Color Dimmer 1",
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
],
status={
Attribute.switch: "off",
Attribute.level: 0,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
},
),
device_factory(
"Color Dimmer 2",
capabilities=[
Capability.switch,
Capability.switch_level,
Capability.color_control,
Capability.color_temperature,
],
status={
Attribute.switch: "on",
Attribute.level: 100,
Attribute.hue: 76.0,
Attribute.saturation: 55.0,
Attribute.color_temperature: 4500,
},
),
] | [
"def",
"light_devices_fixture",
"(",
"device_factory",
")",
":",
"return",
"[",
"device_factory",
"(",
"\"Dimmer 1\"",
",",
"capabilities",
"=",
"[",
"Capability",
".",
"switch",
",",
"Capability",
".",
"switch_level",
"]",
",",
"status",
"=",
"{",
"Attribute",
".",
"switch",
":",
"\"on\"",
",",
"Attribute",
".",
"level",
":",
"100",
"}",
",",
")",
",",
"device_factory",
"(",
"\"Color Dimmer 1\"",
",",
"capabilities",
"=",
"[",
"Capability",
".",
"switch",
",",
"Capability",
".",
"switch_level",
",",
"Capability",
".",
"color_control",
",",
"]",
",",
"status",
"=",
"{",
"Attribute",
".",
"switch",
":",
"\"off\"",
",",
"Attribute",
".",
"level",
":",
"0",
",",
"Attribute",
".",
"hue",
":",
"76.0",
",",
"Attribute",
".",
"saturation",
":",
"55.0",
",",
"}",
",",
")",
",",
"device_factory",
"(",
"\"Color Dimmer 2\"",
",",
"capabilities",
"=",
"[",
"Capability",
".",
"switch",
",",
"Capability",
".",
"switch_level",
",",
"Capability",
".",
"color_control",
",",
"Capability",
".",
"color_temperature",
",",
"]",
",",
"status",
"=",
"{",
"Attribute",
".",
"switch",
":",
"\"on\"",
",",
"Attribute",
".",
"level",
":",
"100",
",",
"Attribute",
".",
"hue",
":",
"76.0",
",",
"Attribute",
".",
"saturation",
":",
"55.0",
",",
"Attribute",
".",
"color_temperature",
":",
"4500",
",",
"}",
",",
")",
",",
"]"
] | [
28,
0
] | [
66,
5
] | python | en | ['en', 'en', 'en'] | True |
test_entity_state | (hass, light_devices) | Tests the state attributes properly match the light types. | Tests the state attributes properly match the light types. | async def test_entity_state(hass, light_devices):
"""Tests the state attributes properly match the light types."""
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Dimmer 1
state = hass.states.get("light.dimmer_1")
assert state.state == "on"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
)
assert isinstance(state.attributes[ATTR_BRIGHTNESS], int)
assert state.attributes[ATTR_BRIGHTNESS] == 255
# Color Dimmer 1
state = hass.states.get("light.color_dimmer_1")
assert state.state == "off"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR
)
# Color Dimmer 2
state = hass.states.get("light.color_dimmer_2")
assert state.state == "on"
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
)
assert state.attributes[ATTR_BRIGHTNESS] == 255
assert state.attributes[ATTR_HS_COLOR] == (273.6, 55.0)
assert isinstance(state.attributes[ATTR_COLOR_TEMP], int)
assert state.attributes[ATTR_COLOR_TEMP] == 222 | [
"async",
"def",
"test_entity_state",
"(",
"hass",
",",
"light_devices",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"devices",
"=",
"light_devices",
")",
"# Dimmer 1",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.dimmer_1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"(",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"==",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_TRANSITION",
")",
"assert",
"isinstance",
"(",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
",",
"int",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"255",
"# Color Dimmer 1",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.color_dimmer_1\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"off\"",
"assert",
"(",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"==",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_TRANSITION",
"|",
"SUPPORT_COLOR",
")",
"# Color Dimmer 2",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.color_dimmer_2\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"on\"",
"assert",
"(",
"state",
".",
"attributes",
"[",
"ATTR_SUPPORTED_FEATURES",
"]",
"==",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_TRANSITION",
"|",
"SUPPORT_COLOR",
"|",
"SUPPORT_COLOR_TEMP",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"255",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_HS_COLOR",
"]",
"==",
"(",
"273.6",
",",
"55.0",
")",
"assert",
"isinstance",
"(",
"state",
".",
"attributes",
"[",
"ATTR_COLOR_TEMP",
"]",
",",
"int",
")",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_COLOR_TEMP",
"]",
"==",
"222"
] | [
69,
0
] | [
101,
51
] | python | en | ['en', 'en', 'en'] | True |
test_entity_and_device_attributes | (hass, device_factory) | Test the attributes of the entity are correct. | Test the attributes of the entity are correct. | async def test_entity_and_device_attributes(hass, device_factory):
"""Test the attributes of the entity are correct."""
# Arrange
device = device_factory("Light 1", [Capability.switch, Capability.switch_level])
entity_registry = await hass.helpers.entity_registry.async_get_registry()
device_registry = await hass.helpers.device_registry.async_get_registry()
# Act
await setup_platform(hass, LIGHT_DOMAIN, devices=[device])
# Assert
entry = entity_registry.async_get("light.light_1")
assert entry
assert entry.unique_id == device.device_id
entry = device_registry.async_get_device({(DOMAIN, device.device_id)}, [])
assert entry
assert entry.name == device.label
assert entry.model == device.device_type_name
assert entry.manufacturer == "Unavailable" | [
"async",
"def",
"test_entity_and_device_attributes",
"(",
"hass",
",",
"device_factory",
")",
":",
"# Arrange",
"device",
"=",
"device_factory",
"(",
"\"Light 1\"",
",",
"[",
"Capability",
".",
"switch",
",",
"Capability",
".",
"switch_level",
"]",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"# Act",
"await",
"setup_platform",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"devices",
"=",
"[",
"device",
"]",
")",
"# Assert",
"entry",
"=",
"entity_registry",
".",
"async_get",
"(",
"\"light.light_1\"",
")",
"assert",
"entry",
"assert",
"entry",
".",
"unique_id",
"==",
"device",
".",
"device_id",
"entry",
"=",
"device_registry",
".",
"async_get_device",
"(",
"{",
"(",
"DOMAIN",
",",
"device",
".",
"device_id",
")",
"}",
",",
"[",
"]",
")",
"assert",
"entry",
"assert",
"entry",
".",
"name",
"==",
"device",
".",
"label",
"assert",
"entry",
".",
"model",
"==",
"device",
".",
"device_type_name",
"assert",
"entry",
".",
"manufacturer",
"==",
"\"Unavailable\""
] | [
104,
0
] | [
121,
46
] | python | en | ['en', 'en', 'en'] | True |
test_turn_off | (hass, light_devices) | Test the light turns of successfully. | Test the light turns of successfully. | async def test_turn_off(hass, light_devices):
"""Test the light turns of successfully."""
# Arrange
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
"light", "turn_off", {"entity_id": "light.color_dimmer_2"}, blocking=True
)
# Assert
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == "off" | [
"async",
"def",
"test_turn_off",
"(",
"hass",
",",
"light_devices",
")",
":",
"# Arrange",
"await",
"setup_platform",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"devices",
"=",
"light_devices",
")",
"# Act",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"\"turn_off\"",
",",
"{",
"\"entity_id\"",
":",
"\"light.color_dimmer_2\"",
"}",
",",
"blocking",
"=",
"True",
")",
"# Assert",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.color_dimmer_2\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"off\""
] | [
124,
0
] | [
135,
31
] | python | en | ['en', 'en', 'en'] | True |
test_turn_off_with_transition | (hass, light_devices) | Test the light turns of successfully with transition. | Test the light turns of successfully with transition. | async def test_turn_off_with_transition(hass, light_devices):
"""Test the light turns of successfully with transition."""
# Arrange
await setup_platform(hass, LIGHT_DOMAIN, devices=light_devices)
# Act
await hass.services.async_call(
"light",
"turn_off",
{ATTR_ENTITY_ID: "light.color_dimmer_2", ATTR_TRANSITION: 2},
blocking=True,
)
# Assert
state = hass.states.get("light.color_dimmer_2")
assert state is not None
assert state.state == "off" | [
"async",
"def",
"test_turn_off_with_transition",
"(",
"hass",
",",
"light_devices",
")",
":",
"# Arrange",
"await",
"setup_platform",
"(",
"hass",
",",
"LIGHT_DOMAIN",
",",
"devices",
"=",
"light_devices",
")",
"# Act",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"\"light\"",
",",
"\"turn_off\"",
",",
"{",
"ATTR_ENTITY_ID",
":",
"\"light.color_dimmer_2\"",
",",
"ATTR_TRANSITION",
":",
"2",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"# Assert",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"light.color_dimmer_2\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"off\""
] | [
138,
0
] | [
152,
31
] | 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.