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 |
---|---|---|---|---|---|---|---|---|---|---|---|
add_group | (organisation, group) |
Create a group for the given organisation.
|
Create a group for the given organisation.
| def add_group(organisation, group):
"""
Create a group for the given organisation.
"""
groupobj = organisation.add_group(group)
if groupobj is None:
msg = "Group {} already exists in organisation {}."
sys.exit(msg.format(group, organisation))
else:
mark_imperative(organisation.name, "groups", groupobj.name) | [
"def",
"add_group",
"(",
"organisation",
",",
"group",
")",
":",
"groupobj",
"=",
"organisation",
".",
"add_group",
"(",
"group",
")",
"if",
"groupobj",
"is",
"None",
":",
"msg",
"=",
"\"Group {} already exists in organisation {}.\"",
"sys",
".",
"exit",
"(",
"msg",
".",
"format",
"(",
"group",
",",
"organisation",
")",
")",
"else",
":",
"mark_imperative",
"(",
"organisation",
".",
"name",
",",
"\"groups\"",
",",
"groupobj",
".",
"name",
")"
] | [
616,
0
] | [
625,
67
] | python | en | ['en', 'error', 'th'] | False |
del_group | (organisation, group) |
Delete a group from the given organisation.
|
Delete a group from the given organisation.
| def del_group(organisation, group):
"""
Delete a group from the given organisation.
"""
organisation.del_group(group)
click("Group {} deleted.".format(group), err=True) | [
"def",
"del_group",
"(",
"organisation",
",",
"group",
")",
":",
"organisation",
".",
"del_group",
"(",
"group",
")",
"click",
"(",
"\"Group {} deleted.\"",
".",
"format",
"(",
"group",
")",
",",
"err",
"=",
"True",
")"
] | [
631,
0
] | [
636,
54
] | python | en | ['en', 'error', 'th'] | False |
add_or_delete | (old, new, add_fun, del_fun) |
Given an 'old' and 'new' list, figure out the intersections and invoke
'add_fun' against every element that is not in the 'old' list and 'del_fun'
against every element that is not in the 'new' list.
Returns a tuple where the first element is the list of elements that were
added and the second element consisting of elements that were deleted.
|
Given an 'old' and 'new' list, figure out the intersections and invoke
'add_fun' against every element that is not in the 'old' list and 'del_fun'
against every element that is not in the 'new' list. | def add_or_delete(old, new, add_fun, del_fun):
"""
Given an 'old' and 'new' list, figure out the intersections and invoke
'add_fun' against every element that is not in the 'old' list and 'del_fun'
against every element that is not in the 'new' list.
Returns a tuple where the first element is the list of elements that were
added and the second element consisting of elements that were deleted.
"""
old_set = set(old)
new_set = set(new)
to_delete = old_set - new_set
to_add = new_set - old_set
for elem in to_delete:
del_fun(elem)
for elem in to_add:
add_fun(elem)
return to_add, to_delete | [
"def",
"add_or_delete",
"(",
"old",
",",
"new",
",",
"add_fun",
",",
"del_fun",
")",
":",
"old_set",
"=",
"set",
"(",
"old",
")",
"new_set",
"=",
"set",
"(",
"new",
")",
"to_delete",
"=",
"old_set",
"-",
"new_set",
"to_add",
"=",
"new_set",
"-",
"old_set",
"for",
"elem",
"in",
"to_delete",
":",
"del_fun",
"(",
"elem",
")",
"for",
"elem",
"in",
"to_add",
":",
"add_fun",
"(",
"elem",
")",
"return",
"to_add",
",",
"to_delete"
] | [
639,
0
] | [
656,
28
] | python | en | ['en', 'error', 'th'] | False |
process_json | (json_file) |
Create and delete users, groups and organisations based on a JSON file.
The structure of this file is exactly the same as the
'services.taskserver.organisations' option of the NixOS module and is used
for declaratively adding and deleting users.
Hence this subcommand is not recommended outside of the scope of the NixOS
module.
|
Create and delete users, groups and organisations based on a JSON file. | def process_json(json_file):
"""
Create and delete users, groups and organisations based on a JSON file.
The structure of this file is exactly the same as the
'services.taskserver.organisations' option of the NixOS module and is used
for declaratively adding and deleting users.
Hence this subcommand is not recommended outside of the scope of the NixOS
module.
"""
data = json.load(json_file)
mgr = Manager(ignore_imperative=True)
add_or_delete(mgr.orgs.keys(), data.keys(), mgr.add_org, mgr.del_org)
for org in mgr.orgs.values():
if is_imperative(org.name):
continue
add_or_delete(org.users.keys(), data[org.name]['users'],
org.add_user, org.del_user)
add_or_delete(org.groups.keys(), data[org.name]['groups'],
org.add_group, org.del_group) | [
"def",
"process_json",
"(",
"json_file",
")",
":",
"data",
"=",
"json",
".",
"load",
"(",
"json_file",
")",
"mgr",
"=",
"Manager",
"(",
"ignore_imperative",
"=",
"True",
")",
"add_or_delete",
"(",
"mgr",
".",
"orgs",
".",
"keys",
"(",
")",
",",
"data",
".",
"keys",
"(",
")",
",",
"mgr",
".",
"add_org",
",",
"mgr",
".",
"del_org",
")",
"for",
"org",
"in",
"mgr",
".",
"orgs",
".",
"values",
"(",
")",
":",
"if",
"is_imperative",
"(",
"org",
".",
"name",
")",
":",
"continue",
"add_or_delete",
"(",
"org",
".",
"users",
".",
"keys",
"(",
")",
",",
"data",
"[",
"org",
".",
"name",
"]",
"[",
"'users'",
"]",
",",
"org",
".",
"add_user",
",",
"org",
".",
"del_user",
")",
"add_or_delete",
"(",
"org",
".",
"groups",
".",
"keys",
"(",
")",
",",
"data",
"[",
"org",
".",
"name",
"]",
"[",
"'groups'",
"]",
",",
"org",
".",
"add_group",
",",
"org",
".",
"del_group",
")"
] | [
661,
0
] | [
683,
51
] | python | en | ['en', 'error', 'th'] | False |
Organisation.add_user | (self, name) |
Create a new user along with a certificate and key.
Returns a 'User' object or None if the user already exists.
|
Create a new user along with a certificate and key. | def add_user(self, name):
"""
Create a new user along with a certificate and key.
Returns a 'User' object or None if the user already exists.
"""
if self.ignore_imperative and is_imperative(self.name):
return None
if name not in self.users.keys():
output = taskd_cmd("add", "user", self.name, name,
capture_stdout=True)
key = RE_USERKEY.search(output)
if key is None:
msg = "Unable to find key while creating user {}."
raise TaskdError(msg.format(name))
generate_key(self.name, name)
newuser = User(self.name, name, key.group(1))
self._lazy_users[name] = newuser
return newuser
return None | [
"def",
"add_user",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"ignore_imperative",
"and",
"is_imperative",
"(",
"self",
".",
"name",
")",
":",
"return",
"None",
"if",
"name",
"not",
"in",
"self",
".",
"users",
".",
"keys",
"(",
")",
":",
"output",
"=",
"taskd_cmd",
"(",
"\"add\"",
",",
"\"user\"",
",",
"self",
".",
"name",
",",
"name",
",",
"capture_stdout",
"=",
"True",
")",
"key",
"=",
"RE_USERKEY",
".",
"search",
"(",
"output",
")",
"if",
"key",
"is",
"None",
":",
"msg",
"=",
"\"Unable to find key while creating user {}.\"",
"raise",
"TaskdError",
"(",
"msg",
".",
"format",
"(",
"name",
")",
")",
"generate_key",
"(",
"self",
".",
"name",
",",
"name",
")",
"newuser",
"=",
"User",
"(",
"self",
".",
"name",
",",
"name",
",",
"key",
".",
"group",
"(",
"1",
")",
")",
"self",
".",
"_lazy_users",
"[",
"name",
"]",
"=",
"newuser",
"return",
"newuser",
"return",
"None"
] | [
293,
4
] | [
313,
19
] | python | en | ['en', 'error', 'th'] | False |
Organisation.del_user | (self, name) |
Delete a user and revoke its keys.
|
Delete a user and revoke its keys.
| def del_user(self, name):
"""
Delete a user and revoke its keys.
"""
if name in self.users.keys():
user = self.get_user(name)
if self.ignore_imperative and \
is_imperative(self.name, "users", user.key):
return
# Work around https://bug.tasktools.org/browse/TD-40:
rmtree(mkpath(self.name, "users", user.key))
revoke_key(self.name, name)
del self._lazy_users[name] | [
"def",
"del_user",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"users",
".",
"keys",
"(",
")",
":",
"user",
"=",
"self",
".",
"get_user",
"(",
"name",
")",
"if",
"self",
".",
"ignore_imperative",
"and",
"is_imperative",
"(",
"self",
".",
"name",
",",
"\"users\"",
",",
"user",
".",
"key",
")",
":",
"return",
"# Work around https://bug.tasktools.org/browse/TD-40:",
"rmtree",
"(",
"mkpath",
"(",
"self",
".",
"name",
",",
"\"users\"",
",",
"user",
".",
"key",
")",
")",
"revoke_key",
"(",
"self",
".",
"name",
",",
"name",
")",
"del",
"self",
".",
"_lazy_users",
"[",
"name",
"]"
] | [
315,
4
] | [
329,
38
] | python | en | ['en', 'error', 'th'] | False |
Organisation.add_group | (self, name) |
Create a new group.
Returns a 'Group' object or None if the group already exists.
|
Create a new group. | def add_group(self, name):
"""
Create a new group.
Returns a 'Group' object or None if the group already exists.
"""
if self.ignore_imperative and is_imperative(self.name):
return None
if name not in self.groups.keys():
taskd_cmd("add", "group", self.name, name)
newgroup = Group(self.name, name)
self._lazy_groups[name] = newgroup
return newgroup
return None | [
"def",
"add_group",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"ignore_imperative",
"and",
"is_imperative",
"(",
"self",
".",
"name",
")",
":",
"return",
"None",
"if",
"name",
"not",
"in",
"self",
".",
"groups",
".",
"keys",
"(",
")",
":",
"taskd_cmd",
"(",
"\"add\"",
",",
"\"group\"",
",",
"self",
".",
"name",
",",
"name",
")",
"newgroup",
"=",
"Group",
"(",
"self",
".",
"name",
",",
"name",
")",
"self",
".",
"_lazy_groups",
"[",
"name",
"]",
"=",
"newgroup",
"return",
"newgroup",
"return",
"None"
] | [
331,
4
] | [
344,
19
] | python | en | ['en', 'error', 'th'] | False |
Organisation.del_group | (self, name) |
Delete a group.
|
Delete a group.
| def del_group(self, name):
"""
Delete a group.
"""
if name in self.users.keys():
if self.ignore_imperative and \
is_imperative(self.name, "groups", name):
return
taskd_cmd("remove", "group", self.name, name)
del self._lazy_groups[name] | [
"def",
"del_group",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"users",
".",
"keys",
"(",
")",
":",
"if",
"self",
".",
"ignore_imperative",
"and",
"is_imperative",
"(",
"self",
".",
"name",
",",
"\"groups\"",
",",
"name",
")",
":",
"return",
"taskd_cmd",
"(",
"\"remove\"",
",",
"\"group\"",
",",
"self",
".",
"name",
",",
"name",
")",
"del",
"self",
".",
"_lazy_groups",
"[",
"name",
"]"
] | [
346,
4
] | [
355,
39
] | python | en | ['en', 'error', 'th'] | False |
Manager.__init__ | (self, ignore_imperative=False) |
Instantiates an organisations manager.
If ignore_imperative is True, all actions that modify data are checked
whether they're created imperatively and if so, they will result in no
operation.
|
Instantiates an organisations manager. | def __init__(self, ignore_imperative=False):
"""
Instantiates an organisations manager.
If ignore_imperative is True, all actions that modify data are checked
whether they're created imperatively and if so, they will result in no
operation.
"""
self.ignore_imperative = ignore_imperative | [
"def",
"__init__",
"(",
"self",
",",
"ignore_imperative",
"=",
"False",
")",
":",
"self",
".",
"ignore_imperative",
"=",
"ignore_imperative"
] | [
381,
4
] | [
389,
50
] | python | en | ['en', 'error', 'th'] | False |
Manager.add_org | (self, name) |
Create a new organisation.
Returns an 'Organisation' object or None if the organisation already
exists.
|
Create a new organisation. | def add_org(self, name):
"""
Create a new organisation.
Returns an 'Organisation' object or None if the organisation already
exists.
"""
if name not in self.orgs.keys():
taskd_cmd("add", "org", name)
neworg = Organisation(name, self.ignore_imperative)
self._lazy_orgs[name] = neworg
return neworg
return None | [
"def",
"add_org",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"orgs",
".",
"keys",
"(",
")",
":",
"taskd_cmd",
"(",
"\"add\"",
",",
"\"org\"",
",",
"name",
")",
"neworg",
"=",
"Organisation",
"(",
"name",
",",
"self",
".",
"ignore_imperative",
")",
"self",
".",
"_lazy_orgs",
"[",
"name",
"]",
"=",
"neworg",
"return",
"neworg",
"return",
"None"
] | [
391,
4
] | [
403,
19
] | python | en | ['en', 'error', 'th'] | False |
Manager.del_org | (self, name) |
Delete and revoke keys of an organisation with all its users and
groups.
|
Delete and revoke keys of an organisation with all its users and
groups.
| def del_org(self, name):
"""
Delete and revoke keys of an organisation with all its users and
groups.
"""
org = self.get_org(name)
if org is not None:
if self.ignore_imperative and is_imperative(name):
return
for user in org.users.keys():
org.del_user(user)
for group in org.groups.keys():
org.del_group(group)
taskd_cmd("remove", "org", name)
del self._lazy_orgs[name] | [
"def",
"del_org",
"(",
"self",
",",
"name",
")",
":",
"org",
"=",
"self",
".",
"get_org",
"(",
"name",
")",
"if",
"org",
"is",
"not",
"None",
":",
"if",
"self",
".",
"ignore_imperative",
"and",
"is_imperative",
"(",
"name",
")",
":",
"return",
"for",
"user",
"in",
"org",
".",
"users",
".",
"keys",
"(",
")",
":",
"org",
".",
"del_user",
"(",
"user",
")",
"for",
"group",
"in",
"org",
".",
"groups",
".",
"keys",
"(",
")",
":",
"org",
".",
"del_group",
"(",
"group",
")",
"taskd_cmd",
"(",
"\"remove\"",
",",
"\"org\"",
",",
"name",
")",
"del",
"self",
".",
"_lazy_orgs",
"[",
"name",
"]"
] | [
405,
4
] | [
419,
37
] | python | en | ['en', 'error', 'th'] | False |
async_setup | (hass) | Set up the Group config API. | Set up the Group config API. | async def async_setup(hass):
"""Set up the Group config API."""
async def hook(action, config_key):
"""post_write_hook for Config View that reloads groups."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
hass.http.register_view(
EditKeyBasedConfigView(
"group",
"config",
GROUP_CONFIG_PATH,
cv.slug,
GROUP_SCHEMA,
post_write_hook=hook,
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
")",
":",
"async",
"def",
"hook",
"(",
"action",
",",
"config_key",
")",
":",
"\"\"\"post_write_hook for Config View that reloads groups.\"\"\"",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_RELOAD",
")",
"hass",
".",
"http",
".",
"register_view",
"(",
"EditKeyBasedConfigView",
"(",
"\"group\"",
",",
"\"config\"",
",",
"GROUP_CONFIG_PATH",
",",
"cv",
".",
"slug",
",",
"GROUP_SCHEMA",
",",
"post_write_hook",
"=",
"hook",
",",
")",
")",
"return",
"True"
] | [
15,
0
] | [
32,
15
] | python | en | ['en', 'pt', 'en'] | True |
async_describe_on_off_states | (
hass: HomeAssistantType, registry: GroupIntegrationRegistry
) | Describe group on off states. | Describe group on off states. | def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry
) -> None:
"""Describe group on off states."""
return | [
"def",
"async_describe_on_off_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"registry",
":",
"GroupIntegrationRegistry",
")",
"->",
"None",
":",
"return"
] | [
36,
0
] | [
40,
10
] | python | en | ['en', 'en', 'en'] | True |
convert | (value: float, unit_1: str, unit_2: str) | Convert one unit of measurement to another. | Convert one unit of measurement to another. | def convert(value: float, unit_1: str, unit_2: str) -> float:
"""Convert one unit of measurement to another."""
if unit_1 not in VALID_UNITS:
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(unit_1, PRESSURE))
if unit_2 not in VALID_UNITS:
raise ValueError(UNIT_NOT_RECOGNIZED_TEMPLATE.format(unit_2, PRESSURE))
if not isinstance(value, Number):
raise TypeError(f"{value} is not of numeric type")
if unit_1 == unit_2 or unit_1 not in VALID_UNITS:
return value
pascals = value / UNIT_CONVERSION[unit_1]
return pascals * UNIT_CONVERSION[unit_2] | [
"def",
"convert",
"(",
"value",
":",
"float",
",",
"unit_1",
":",
"str",
",",
"unit_2",
":",
"str",
")",
"->",
"float",
":",
"if",
"unit_1",
"not",
"in",
"VALID_UNITS",
":",
"raise",
"ValueError",
"(",
"UNIT_NOT_RECOGNIZED_TEMPLATE",
".",
"format",
"(",
"unit_1",
",",
"PRESSURE",
")",
")",
"if",
"unit_2",
"not",
"in",
"VALID_UNITS",
":",
"raise",
"ValueError",
"(",
"UNIT_NOT_RECOGNIZED_TEMPLATE",
".",
"format",
"(",
"unit_2",
",",
"PRESSURE",
")",
")",
"if",
"not",
"isinstance",
"(",
"value",
",",
"Number",
")",
":",
"raise",
"TypeError",
"(",
"f\"{value} is not of numeric type\"",
")",
"if",
"unit_1",
"==",
"unit_2",
"or",
"unit_1",
"not",
"in",
"VALID_UNITS",
":",
"return",
"value",
"pascals",
"=",
"value",
"/",
"UNIT_CONVERSION",
"[",
"unit_1",
"]",
"return",
"pascals",
"*",
"UNIT_CONVERSION",
"[",
"unit_2",
"]"
] | [
24,
0
] | [
38,
44
] | python | en | ['en', 'en', 'en'] | True |
test_sync_turn_on | (hass) | Test if async turn_on calls sync turn_on. | Test if async turn_on calls sync turn_on. | async def test_sync_turn_on(hass):
"""Test if async turn_on calls sync turn_on."""
humidifier = MockHumidifierEntity()
humidifier.hass = hass
humidifier.turn_on = MagicMock()
await humidifier.async_turn_on()
assert humidifier.turn_on.called | [
"async",
"def",
"test_sync_turn_on",
"(",
"hass",
")",
":",
"humidifier",
"=",
"MockHumidifierEntity",
"(",
")",
"humidifier",
".",
"hass",
"=",
"hass",
"humidifier",
".",
"turn_on",
"=",
"MagicMock",
"(",
")",
"await",
"humidifier",
".",
"async_turn_on",
"(",
")",
"assert",
"humidifier",
".",
"turn_on",
".",
"called"
] | [
15,
0
] | [
23,
36
] | python | en | ['en', 'cy', 'en'] | True |
test_sync_turn_off | (hass) | Test if async turn_off calls sync turn_off. | Test if async turn_off calls sync turn_off. | async def test_sync_turn_off(hass):
"""Test if async turn_off calls sync turn_off."""
humidifier = MockHumidifierEntity()
humidifier.hass = hass
humidifier.turn_off = MagicMock()
await humidifier.async_turn_off()
assert humidifier.turn_off.called | [
"async",
"def",
"test_sync_turn_off",
"(",
"hass",
")",
":",
"humidifier",
"=",
"MockHumidifierEntity",
"(",
")",
"humidifier",
".",
"hass",
"=",
"hass",
"humidifier",
".",
"turn_off",
"=",
"MagicMock",
"(",
")",
"await",
"humidifier",
".",
"async_turn_off",
"(",
")",
"assert",
"humidifier",
".",
"turn_off",
".",
"called"
] | [
26,
0
] | [
34,
37
] | python | en | ['en', 'cy', 'en'] | True |
MockHumidifierEntity.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return 0 | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"0"
] | [
10,
4
] | [
12,
16
] | python | en | ['en', 'en', 'en'] | True |
test_setup_config_full | (hass) | Test setup with all data. | Test setup with all data. | async def test_setup_config_full(hass):
"""Test setup with all data."""
config = {"logentries": {"token": "secret"}}
hass.bus.listen = MagicMock()
assert await async_setup_component(hass, logentries.DOMAIN, config)
assert hass.bus.listen.called
assert EVENT_STATE_CHANGED == hass.bus.listen.call_args_list[0][0][0] | [
"async",
"def",
"test_setup_config_full",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"logentries\"",
":",
"{",
"\"token\"",
":",
"\"secret\"",
"}",
"}",
"hass",
".",
"bus",
".",
"listen",
"=",
"MagicMock",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"logentries",
".",
"DOMAIN",
",",
"config",
")",
"assert",
"hass",
".",
"bus",
".",
"listen",
".",
"called",
"assert",
"EVENT_STATE_CHANGED",
"==",
"hass",
".",
"bus",
".",
"listen",
".",
"call_args_list",
"[",
"0",
"]",
"[",
"0",
"]",
"[",
"0",
"]"
] | [
11,
0
] | [
17,
73
] | python | en | ['en', 'en', 'en'] | True |
test_setup_config_defaults | (hass) | Test setup with defaults. | Test setup with defaults. | async def test_setup_config_defaults(hass):
"""Test setup with defaults."""
config = {"logentries": {"token": "token"}}
hass.bus.listen = MagicMock()
assert await async_setup_component(hass, logentries.DOMAIN, config)
assert hass.bus.listen.called
assert EVENT_STATE_CHANGED == hass.bus.listen.call_args_list[0][0][0] | [
"async",
"def",
"test_setup_config_defaults",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"logentries\"",
":",
"{",
"\"token\"",
":",
"\"token\"",
"}",
"}",
"hass",
".",
"bus",
".",
"listen",
"=",
"MagicMock",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"logentries",
".",
"DOMAIN",
",",
"config",
")",
"assert",
"hass",
".",
"bus",
".",
"listen",
".",
"called",
"assert",
"EVENT_STATE_CHANGED",
"==",
"hass",
".",
"bus",
".",
"listen",
".",
"call_args_list",
"[",
"0",
"]",
"[",
"0",
"]",
"[",
"0",
"]"
] | [
20,
0
] | [
26,
73
] | python | en | ['en', 'en', 'en'] | True |
mock_dump | () | Mock json dumps. | Mock json dumps. | def mock_dump():
"""Mock json dumps."""
with patch("json.dumps") as mock_dump:
yield mock_dump | [
"def",
"mock_dump",
"(",
")",
":",
"with",
"patch",
"(",
"\"json.dumps\"",
")",
"as",
"mock_dump",
":",
"yield",
"mock_dump"
] | [
30,
0
] | [
33,
23
] | python | fr | ['fr', 'fr', 'en'] | True |
mock_requests | () | Mock requests. | Mock requests. | def mock_requests():
"""Mock requests."""
with patch.object(logentries, "requests") as mock_requests:
yield mock_requests | [
"def",
"mock_requests",
"(",
")",
":",
"with",
"patch",
".",
"object",
"(",
"logentries",
",",
"\"requests\"",
")",
"as",
"mock_requests",
":",
"yield",
"mock_requests"
] | [
37,
0
] | [
40,
27
] | python | en | ['en', 'nl', 'en'] | False |
test_event_listener | (hass, mock_dump, mock_requests) | Test event listener. | Test event listener. | async def test_event_listener(hass, mock_dump, mock_requests):
"""Test event listener."""
mock_dump.side_effect = lambda x: x
mock_post = mock_requests.post
mock_requests.exceptions.RequestException = Exception
config = {"logentries": {"token": "token"}}
hass.bus.listen = MagicMock()
assert await async_setup_component(hass, logentries.DOMAIN, config)
handler_method = hass.bus.listen.call_args_list[0][0][1]
valid = {"1": 1, "1.0": 1.0, STATE_ON: 1, STATE_OFF: 0, "foo": "foo"}
for in_, out in valid.items():
state = MagicMock(state=in_, domain="fake", object_id="entity", attributes={})
event = MagicMock(data={"new_state": state}, time_fired=12345)
body = [
{
"domain": "fake",
"entity_id": "entity",
"attributes": {},
"time": "12345",
"value": out,
}
]
payload = {
"host": "https://webhook.logentries.com/noformat/logs/token",
"event": body,
}
handler_method(event)
assert mock_post.call_count == 1
assert mock_post.call_args == call(payload["host"], data=payload, timeout=10)
mock_post.reset_mock() | [
"async",
"def",
"test_event_listener",
"(",
"hass",
",",
"mock_dump",
",",
"mock_requests",
")",
":",
"mock_dump",
".",
"side_effect",
"=",
"lambda",
"x",
":",
"x",
"mock_post",
"=",
"mock_requests",
".",
"post",
"mock_requests",
".",
"exceptions",
".",
"RequestException",
"=",
"Exception",
"config",
"=",
"{",
"\"logentries\"",
":",
"{",
"\"token\"",
":",
"\"token\"",
"}",
"}",
"hass",
".",
"bus",
".",
"listen",
"=",
"MagicMock",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"logentries",
".",
"DOMAIN",
",",
"config",
")",
"handler_method",
"=",
"hass",
".",
"bus",
".",
"listen",
".",
"call_args_list",
"[",
"0",
"]",
"[",
"0",
"]",
"[",
"1",
"]",
"valid",
"=",
"{",
"\"1\"",
":",
"1",
",",
"\"1.0\"",
":",
"1.0",
",",
"STATE_ON",
":",
"1",
",",
"STATE_OFF",
":",
"0",
",",
"\"foo\"",
":",
"\"foo\"",
"}",
"for",
"in_",
",",
"out",
"in",
"valid",
".",
"items",
"(",
")",
":",
"state",
"=",
"MagicMock",
"(",
"state",
"=",
"in_",
",",
"domain",
"=",
"\"fake\"",
",",
"object_id",
"=",
"\"entity\"",
",",
"attributes",
"=",
"{",
"}",
")",
"event",
"=",
"MagicMock",
"(",
"data",
"=",
"{",
"\"new_state\"",
":",
"state",
"}",
",",
"time_fired",
"=",
"12345",
")",
"body",
"=",
"[",
"{",
"\"domain\"",
":",
"\"fake\"",
",",
"\"entity_id\"",
":",
"\"entity\"",
",",
"\"attributes\"",
":",
"{",
"}",
",",
"\"time\"",
":",
"\"12345\"",
",",
"\"value\"",
":",
"out",
",",
"}",
"]",
"payload",
"=",
"{",
"\"host\"",
":",
"\"https://webhook.logentries.com/noformat/logs/token\"",
",",
"\"event\"",
":",
"body",
",",
"}",
"handler_method",
"(",
"event",
")",
"assert",
"mock_post",
".",
"call_count",
"==",
"1",
"assert",
"mock_post",
".",
"call_args",
"==",
"call",
"(",
"payload",
"[",
"\"host\"",
"]",
",",
"data",
"=",
"payload",
",",
"timeout",
"=",
"10",
")",
"mock_post",
".",
"reset_mock",
"(",
")"
] | [
43,
0
] | [
73,
30
] | python | de | ['fr', 'de', 'nl'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Tikteck platform. | Set up the Tikteck platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Tikteck platform."""
lights = []
for address, device_config in config[CONF_DEVICES].items():
device = {}
device["name"] = device_config[CONF_NAME]
device["password"] = device_config[CONF_PASSWORD]
device["address"] = address
light = TikteckLight(device)
if light.is_valid:
lights.append(light)
add_entities(lights) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"lights",
"=",
"[",
"]",
"for",
"address",
",",
"device_config",
"in",
"config",
"[",
"CONF_DEVICES",
"]",
".",
"items",
"(",
")",
":",
"device",
"=",
"{",
"}",
"device",
"[",
"\"name\"",
"]",
"=",
"device_config",
"[",
"CONF_NAME",
"]",
"device",
"[",
"\"password\"",
"]",
"=",
"device_config",
"[",
"CONF_PASSWORD",
"]",
"device",
"[",
"\"address\"",
"]",
"=",
"address",
"light",
"=",
"TikteckLight",
"(",
"device",
")",
"if",
"light",
".",
"is_valid",
":",
"lights",
".",
"append",
"(",
"light",
")",
"add_entities",
"(",
"lights",
")"
] | [
31,
0
] | [
43,
24
] | python | en | ['en', 'lv', 'en'] | True |
TikteckLight.__init__ | (self, device) | Initialize the light. | Initialize the light. | def __init__(self, device):
"""Initialize the light."""
self._name = device["name"]
self._address = device["address"]
self._password = device["password"]
self._brightness = 255
self._hs = [0, 0]
self._state = False
self.is_valid = True
self._bulb = tikteck.tikteck(self._address, "Smart Light", self._password)
if self._bulb.connect() is False:
self.is_valid = False
_LOGGER.error("Failed to connect to bulb %s, %s", self._address, self._name) | [
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"_name",
"=",
"device",
"[",
"\"name\"",
"]",
"self",
".",
"_address",
"=",
"device",
"[",
"\"address\"",
"]",
"self",
".",
"_password",
"=",
"device",
"[",
"\"password\"",
"]",
"self",
".",
"_brightness",
"=",
"255",
"self",
".",
"_hs",
"=",
"[",
"0",
",",
"0",
"]",
"self",
".",
"_state",
"=",
"False",
"self",
".",
"is_valid",
"=",
"True",
"self",
".",
"_bulb",
"=",
"tikteck",
".",
"tikteck",
"(",
"self",
".",
"_address",
",",
"\"Smart Light\"",
",",
"self",
".",
"_password",
")",
"if",
"self",
".",
"_bulb",
".",
"connect",
"(",
")",
"is",
"False",
":",
"self",
".",
"is_valid",
"=",
"False",
"_LOGGER",
".",
"error",
"(",
"\"Failed to connect to bulb %s, %s\"",
",",
"self",
".",
"_address",
",",
"self",
".",
"_name",
")"
] | [
49,
4
] | [
62,
88
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.unique_id | (self) | Return the ID of this light. | Return the ID of this light. | def unique_id(self):
"""Return the ID of this light."""
return self._address | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_address"
] | [
65,
4
] | [
67,
28
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.name | (self) | Return the name of the device if any. | Return the name of the device if any. | def name(self):
"""Return the name of the device if any."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
70,
4
] | [
72,
25
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.is_on | (self) | Return true if device is on. | Return true if device is on. | def is_on(self):
"""Return true if device is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
75,
4
] | [
77,
26
] | python | en | ['en', 'fy', 'en'] | True |
TikteckLight.brightness | (self) | Return the brightness of this light between 0..255. | Return the brightness of this light between 0..255. | def brightness(self):
"""Return the brightness of this light between 0..255."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
80,
4
] | [
82,
31
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.hs_color | (self) | Return the color property. | Return the color property. | def hs_color(self):
"""Return the color property."""
return self._hs | [
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hs"
] | [
85,
4
] | [
87,
23
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_TIKTECK_LED | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_TIKTECK_LED"
] | [
90,
4
] | [
92,
34
] | python | en | ['da', 'en', 'en'] | True |
TikteckLight.should_poll | (self) | Return the polling state. | Return the polling state. | def should_poll(self):
"""Return the polling state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
95,
4
] | [
97,
20
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.assumed_state | (self) | Return the assumed state. | Return the assumed state. | def assumed_state(self):
"""Return the assumed state."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"True"
] | [
100,
4
] | [
102,
19
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.set_state | (self, red, green, blue, brightness) | Set the bulb state. | Set the bulb state. | def set_state(self, red, green, blue, brightness):
"""Set the bulb state."""
return self._bulb.set_state(red, green, blue, brightness) | [
"def",
"set_state",
"(",
"self",
",",
"red",
",",
"green",
",",
"blue",
",",
"brightness",
")",
":",
"return",
"self",
".",
"_bulb",
".",
"set_state",
"(",
"red",
",",
"green",
",",
"blue",
",",
"brightness",
")"
] | [
104,
4
] | [
106,
65
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.turn_on | (self, **kwargs) | Turn the specified light on. | Turn the specified light on. | def turn_on(self, **kwargs):
"""Turn the specified light on."""
self._state = True
hs_color = kwargs.get(ATTR_HS_COLOR)
brightness = kwargs.get(ATTR_BRIGHTNESS)
if hs_color is not None:
self._hs = hs_color
if brightness is not None:
self._brightness = brightness
rgb = color_util.color_hs_to_RGB(*self._hs)
self.set_state(rgb[0], rgb[1], rgb[2], self.brightness)
self.schedule_update_ha_state() | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_state",
"=",
"True",
"hs_color",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_HS_COLOR",
")",
"brightness",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")",
"if",
"hs_color",
"is",
"not",
"None",
":",
"self",
".",
"_hs",
"=",
"hs_color",
"if",
"brightness",
"is",
"not",
"None",
":",
"self",
".",
"_brightness",
"=",
"brightness",
"rgb",
"=",
"color_util",
".",
"color_hs_to_RGB",
"(",
"*",
"self",
".",
"_hs",
")",
"self",
".",
"set_state",
"(",
"rgb",
"[",
"0",
"]",
",",
"rgb",
"[",
"1",
"]",
",",
"rgb",
"[",
"2",
"]",
",",
"self",
".",
"brightness",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
108,
4
] | [
123,
39
] | python | en | ['en', 'en', 'en'] | True |
TikteckLight.turn_off | (self, **kwargs) | Turn the specified light off. | Turn the specified light off. | def turn_off(self, **kwargs):
"""Turn the specified light off."""
self._state = False
self.set_state(0, 0, 0, 0)
self.schedule_update_ha_state() | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_state",
"=",
"False",
"self",
".",
"set_state",
"(",
"0",
",",
"0",
",",
"0",
",",
"0",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
125,
4
] | [
129,
39
] | python | en | ['en', 'en', 'en'] | True |
RadioType.list | (cls) | Return a list of descriptions. | Return a list of descriptions. | def list(cls) -> List[str]:
"""Return a list of descriptions."""
return [e.description for e in RadioType] | [
"def",
"list",
"(",
"cls",
")",
"->",
"List",
"[",
"str",
"]",
":",
"return",
"[",
"e",
".",
"description",
"for",
"e",
"in",
"RadioType",
"]"
] | [
200,
4
] | [
202,
49
] | python | en | ['en', 'ca', 'en'] | True |
RadioType.get_by_description | (cls, description: str) | Get radio by description. | Get radio by description. | def get_by_description(cls, description: str) -> str:
"""Get radio by description."""
for radio in cls:
if radio.description == description:
return radio.name
raise ValueError | [
"def",
"get_by_description",
"(",
"cls",
",",
"description",
":",
"str",
")",
"->",
"str",
":",
"for",
"radio",
"in",
"cls",
":",
"if",
"radio",
".",
"description",
"==",
"description",
":",
"return",
"radio",
".",
"name",
"raise",
"ValueError"
] | [
205,
4
] | [
210,
24
] | python | en | ['en', 'es', 'en'] | True |
RadioType.__init__ | (self, description: str, controller_cls: CALLABLE_T) | Init instance. | Init instance. | def __init__(self, description: str, controller_cls: CALLABLE_T):
"""Init instance."""
self._desc = description
self._ctrl_cls = controller_cls | [
"def",
"__init__",
"(",
"self",
",",
"description",
":",
"str",
",",
"controller_cls",
":",
"CALLABLE_T",
")",
":",
"self",
".",
"_desc",
"=",
"description",
"self",
".",
"_ctrl_cls",
"=",
"controller_cls"
] | [
212,
4
] | [
215,
39
] | python | en | ['en', 'en', 'en'] | False |
RadioType.controller | (self) | Return controller class. | Return controller class. | def controller(self) -> CALLABLE_T:
"""Return controller class."""
return self._ctrl_cls | [
"def",
"controller",
"(",
"self",
")",
"->",
"CALLABLE_T",
":",
"return",
"self",
".",
"_ctrl_cls"
] | [
218,
4
] | [
220,
29
] | python | en | ['sv', 'lb', 'en'] | False |
RadioType.description | (self) | Return radio type description. | Return radio type description. | def description(self) -> str:
"""Return radio type description."""
return self._desc | [
"def",
"description",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_desc"
] | [
223,
4
] | [
225,
25
] | python | en | ['it', 'la', 'en'] | False |
async_setup_entry | (hass: HomeAssistantType, config_entry, async_add_entities) | Set up switches. | Set up switches. | async def async_setup_entry(hass: HomeAssistantType, config_entry, async_add_entities):
"""Set up switches."""
entities = await hass.async_add_executor_job(
add_available_devices, hass, CONF_SWITCH, SmartPlugSwitch
)
if entities:
async_add_entities(entities, update_before_add=True)
if hass.data[TPLINK_DOMAIN][f"{CONF_SWITCH}_remaining"]:
raise PlatformNotReady | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"add_available_devices",
",",
"hass",
",",
"CONF_SWITCH",
",",
"SmartPlugSwitch",
")",
"if",
"entities",
":",
"async_add_entities",
"(",
"entities",
",",
"update_before_add",
"=",
"True",
")",
"if",
"hass",
".",
"data",
"[",
"TPLINK_DOMAIN",
"]",
"[",
"f\"{CONF_SWITCH}_remaining\"",
"]",
":",
"raise",
"PlatformNotReady"
] | [
31,
0
] | [
41,
30
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.__init__ | (self, smartplug: SmartPlug) | Initialize the switch. | Initialize the switch. | def __init__(self, smartplug: SmartPlug):
"""Initialize the switch."""
self.smartplug = smartplug
self._sysinfo = None
self._state = None
self._is_available = False
# Set up emeter cache
self._emeter_params = {}
self._mac = None
self._alias = None
self._model = None
self._device_id = None
self._host = None | [
"def",
"__init__",
"(",
"self",
",",
"smartplug",
":",
"SmartPlug",
")",
":",
"self",
".",
"smartplug",
"=",
"smartplug",
"self",
".",
"_sysinfo",
"=",
"None",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_is_available",
"=",
"False",
"# Set up emeter cache",
"self",
".",
"_emeter_params",
"=",
"{",
"}",
"self",
".",
"_mac",
"=",
"None",
"self",
".",
"_alias",
"=",
"None",
"self",
".",
"_model",
"=",
"None",
"self",
".",
"_device_id",
"=",
"None",
"self",
".",
"_host",
"=",
"None"
] | [
47,
4
] | [
60,
25
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return self._device_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_id"
] | [
63,
4
] | [
65,
30
] | python | ca | ['fr', 'ca', 'en'] | False |
SmartPlugSwitch.name | (self) | Return the name of the Smart Plug. | Return the name of the Smart Plug. | def name(self):
"""Return the name of the Smart Plug."""
return self._alias | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_alias"
] | [
68,
4
] | [
70,
26
] | python | en | ['en', 'ceb', 'en'] | True |
SmartPlugSwitch.device_info | (self) | Return information about the device. | Return information about the device. | def device_info(self):
"""Return information about the device."""
return {
"name": self._alias,
"model": self._model,
"manufacturer": "TP-Link",
"connections": {(dr.CONNECTION_NETWORK_MAC, self._mac)},
"sw_version": self._sysinfo["sw_ver"],
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"name\"",
":",
"self",
".",
"_alias",
",",
"\"model\"",
":",
"self",
".",
"_model",
",",
"\"manufacturer\"",
":",
"\"TP-Link\"",
",",
"\"connections\"",
":",
"{",
"(",
"dr",
".",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"_mac",
")",
"}",
",",
"\"sw_version\"",
":",
"self",
".",
"_sysinfo",
"[",
"\"sw_ver\"",
"]",
",",
"}"
] | [
73,
4
] | [
81,
9
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.available | (self) | Return if switch is available. | Return if switch is available. | def available(self) -> bool:
"""Return if switch is available."""
return self._is_available | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_is_available"
] | [
84,
4
] | [
86,
33
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.is_on | (self) | Return true if switch is on. | Return true if switch is on. | def is_on(self):
"""Return true if switch is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
89,
4
] | [
91,
26
] | python | en | ['en', 'fy', 'en'] | True |
SmartPlugSwitch.turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | def turn_on(self, **kwargs):
"""Turn the switch on."""
self.smartplug.turn_on() | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"smartplug",
".",
"turn_on",
"(",
")"
] | [
93,
4
] | [
95,
32
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | def turn_off(self, **kwargs):
"""Turn the switch off."""
self.smartplug.turn_off() | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"smartplug",
".",
"turn_off",
"(",
")"
] | [
97,
4
] | [
99,
33
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.device_state_attributes | (self) | Return the state attributes of the device. | Return the state attributes of the device. | def device_state_attributes(self):
"""Return the state attributes of the device."""
return self._emeter_params | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_emeter_params"
] | [
102,
4
] | [
104,
34
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch._plug_from_context | (self) | Return the plug from the context. | Return the plug from the context. | def _plug_from_context(self):
"""Return the plug from the context."""
children = self.smartplug.sys_info["children"]
return next(c for c in children if c["id"] == self.smartplug.context) | [
"def",
"_plug_from_context",
"(",
"self",
")",
":",
"children",
"=",
"self",
".",
"smartplug",
".",
"sys_info",
"[",
"\"children\"",
"]",
"return",
"next",
"(",
"c",
"for",
"c",
"in",
"children",
"if",
"c",
"[",
"\"id\"",
"]",
"==",
"self",
".",
"smartplug",
".",
"context",
")"
] | [
107,
4
] | [
110,
77
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.update_state | (self) | Update the TP-Link switch's state. | Update the TP-Link switch's state. | def update_state(self):
"""Update the TP-Link switch's state."""
if self.smartplug.context is None:
self._state = self.smartplug.state == self.smartplug.SWITCH_STATE_ON
else:
self._state = self._plug_from_context["state"] == 1 | [
"def",
"update_state",
"(",
"self",
")",
":",
"if",
"self",
".",
"smartplug",
".",
"context",
"is",
"None",
":",
"self",
".",
"_state",
"=",
"self",
".",
"smartplug",
".",
"state",
"==",
"self",
".",
"smartplug",
".",
"SWITCH_STATE_ON",
"else",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_plug_from_context",
"[",
"\"state\"",
"]",
"==",
"1"
] | [
112,
4
] | [
117,
63
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.attempt_update | (self, update_attempt) | Attempt to get details from the TP-Link switch. | Attempt to get details from the TP-Link switch. | def attempt_update(self, update_attempt):
"""Attempt to get details from the TP-Link switch."""
try:
if not self._sysinfo:
self._sysinfo = self.smartplug.sys_info
self._mac = self._sysinfo["mac"]
self._model = self._sysinfo["model"]
self._host = self.smartplug.host
if self.smartplug.context is None:
self._alias = self._sysinfo["alias"]
self._device_id = self._mac
else:
self._alias = self._plug_from_context["alias"]
self._device_id = self.smartplug.context
self.update_state()
if self.smartplug.has_emeter:
emeter_readings = self.smartplug.get_emeter_realtime()
self._emeter_params[ATTR_CURRENT_POWER_W] = "{:.2f}".format(
emeter_readings["power"]
)
self._emeter_params[ATTR_TOTAL_ENERGY_KWH] = "{:.3f}".format(
emeter_readings["total"]
)
self._emeter_params[ATTR_VOLTAGE] = "{:.1f}".format(
emeter_readings["voltage"]
)
self._emeter_params[ATTR_CURRENT_A] = "{:.2f}".format(
emeter_readings["current"]
)
emeter_statics = self.smartplug.get_emeter_daily()
try:
self._emeter_params[ATTR_TODAY_ENERGY_KWH] = "{:.3f}".format(
emeter_statics[int(time.strftime("%e"))]
)
except KeyError:
# Device returned no daily history
pass
return True
except (SmartDeviceException, OSError) as ex:
if update_attempt == 0:
_LOGGER.debug(
"Retrying in %s seconds for %s|%s due to: %s",
SLEEP_TIME,
self._host,
self._alias,
ex,
)
return False | [
"def",
"attempt_update",
"(",
"self",
",",
"update_attempt",
")",
":",
"try",
":",
"if",
"not",
"self",
".",
"_sysinfo",
":",
"self",
".",
"_sysinfo",
"=",
"self",
".",
"smartplug",
".",
"sys_info",
"self",
".",
"_mac",
"=",
"self",
".",
"_sysinfo",
"[",
"\"mac\"",
"]",
"self",
".",
"_model",
"=",
"self",
".",
"_sysinfo",
"[",
"\"model\"",
"]",
"self",
".",
"_host",
"=",
"self",
".",
"smartplug",
".",
"host",
"if",
"self",
".",
"smartplug",
".",
"context",
"is",
"None",
":",
"self",
".",
"_alias",
"=",
"self",
".",
"_sysinfo",
"[",
"\"alias\"",
"]",
"self",
".",
"_device_id",
"=",
"self",
".",
"_mac",
"else",
":",
"self",
".",
"_alias",
"=",
"self",
".",
"_plug_from_context",
"[",
"\"alias\"",
"]",
"self",
".",
"_device_id",
"=",
"self",
".",
"smartplug",
".",
"context",
"self",
".",
"update_state",
"(",
")",
"if",
"self",
".",
"smartplug",
".",
"has_emeter",
":",
"emeter_readings",
"=",
"self",
".",
"smartplug",
".",
"get_emeter_realtime",
"(",
")",
"self",
".",
"_emeter_params",
"[",
"ATTR_CURRENT_POWER_W",
"]",
"=",
"\"{:.2f}\"",
".",
"format",
"(",
"emeter_readings",
"[",
"\"power\"",
"]",
")",
"self",
".",
"_emeter_params",
"[",
"ATTR_TOTAL_ENERGY_KWH",
"]",
"=",
"\"{:.3f}\"",
".",
"format",
"(",
"emeter_readings",
"[",
"\"total\"",
"]",
")",
"self",
".",
"_emeter_params",
"[",
"ATTR_VOLTAGE",
"]",
"=",
"\"{:.1f}\"",
".",
"format",
"(",
"emeter_readings",
"[",
"\"voltage\"",
"]",
")",
"self",
".",
"_emeter_params",
"[",
"ATTR_CURRENT_A",
"]",
"=",
"\"{:.2f}\"",
".",
"format",
"(",
"emeter_readings",
"[",
"\"current\"",
"]",
")",
"emeter_statics",
"=",
"self",
".",
"smartplug",
".",
"get_emeter_daily",
"(",
")",
"try",
":",
"self",
".",
"_emeter_params",
"[",
"ATTR_TODAY_ENERGY_KWH",
"]",
"=",
"\"{:.3f}\"",
".",
"format",
"(",
"emeter_statics",
"[",
"int",
"(",
"time",
".",
"strftime",
"(",
"\"%e\"",
")",
")",
"]",
")",
"except",
"KeyError",
":",
"# Device returned no daily history",
"pass",
"return",
"True",
"except",
"(",
"SmartDeviceException",
",",
"OSError",
")",
"as",
"ex",
":",
"if",
"update_attempt",
"==",
"0",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Retrying in %s seconds for %s|%s due to: %s\"",
",",
"SLEEP_TIME",
",",
"self",
".",
"_host",
",",
"self",
".",
"_alias",
",",
"ex",
",",
")",
"return",
"False"
] | [
119,
4
] | [
170,
24
] | python | en | ['en', 'en', 'en'] | True |
SmartPlugSwitch.async_update | (self) | Update the TP-Link switch's state. | Update the TP-Link switch's state. | async def async_update(self):
"""Update the TP-Link switch's state."""
for update_attempt in range(MAX_ATTEMPTS):
is_ready = await self.hass.async_add_executor_job(
self.attempt_update, update_attempt
)
if is_ready:
self._is_available = True
if update_attempt > 0:
_LOGGER.debug(
"Device %s|%s responded after %s attempts",
self._host,
self._alias,
update_attempt,
)
break
await asyncio.sleep(SLEEP_TIME)
else:
if self._is_available:
_LOGGER.warning(
"Could not read state for %s|%s", self.smartplug.host, self._alias
)
self._is_available = False | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"for",
"update_attempt",
"in",
"range",
"(",
"MAX_ATTEMPTS",
")",
":",
"is_ready",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"attempt_update",
",",
"update_attempt",
")",
"if",
"is_ready",
":",
"self",
".",
"_is_available",
"=",
"True",
"if",
"update_attempt",
">",
"0",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Device %s|%s responded after %s attempts\"",
",",
"self",
".",
"_host",
",",
"self",
".",
"_alias",
",",
"update_attempt",
",",
")",
"break",
"await",
"asyncio",
".",
"sleep",
"(",
"SLEEP_TIME",
")",
"else",
":",
"if",
"self",
".",
"_is_available",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Could not read state for %s|%s\"",
",",
"self",
".",
"smartplug",
".",
"host",
",",
"self",
".",
"_alias",
")",
"self",
".",
"_is_available",
"=",
"False"
] | [
172,
4
] | [
196,
38
] | python | en | ['en', 'en', 'en'] | True |
clear_discovery_hash | (hass, discovery_hash) | Clear entry in ALREADY_DISCOVERED list. | Clear entry in ALREADY_DISCOVERED list. | def clear_discovery_hash(hass, discovery_hash):
"""Clear entry in ALREADY_DISCOVERED list."""
if ALREADY_DISCOVERED not in hass.data:
# Discovery is shutting down
return
del hass.data[ALREADY_DISCOVERED][discovery_hash] | [
"def",
"clear_discovery_hash",
"(",
"hass",
",",
"discovery_hash",
")",
":",
"if",
"ALREADY_DISCOVERED",
"not",
"in",
"hass",
".",
"data",
":",
"# Discovery is shutting down",
"return",
"del",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
"[",
"discovery_hash",
"]"
] | [
28,
0
] | [
33,
53
] | python | en | ['en', 'en', 'en'] | True |
set_discovery_hash | (hass, discovery_hash) | Set entry in ALREADY_DISCOVERED list. | Set entry in ALREADY_DISCOVERED list. | def set_discovery_hash(hass, discovery_hash):
"""Set entry in ALREADY_DISCOVERED list."""
hass.data[ALREADY_DISCOVERED][discovery_hash] = {} | [
"def",
"set_discovery_hash",
"(",
"hass",
",",
"discovery_hash",
")",
":",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
"[",
"discovery_hash",
"]",
"=",
"{",
"}"
] | [
36,
0
] | [
38,
54
] | python | en | ['en', 'en', 'en'] | True |
async_start | (
hass: HomeAssistantType, discovery_topic, config_entry, tasmota_mqtt, setup_device
) | Start Tasmota device discovery. | Start Tasmota device discovery. | async def async_start(
hass: HomeAssistantType, discovery_topic, config_entry, tasmota_mqtt, setup_device
) -> bool:
"""Start Tasmota device discovery."""
async def _discover_entity(tasmota_entity_config, discovery_hash, platform):
"""Handle adding or updating a discovered entity."""
if not tasmota_entity_config:
# Entity disabled, clean up entity registry
entity_registry = await hass.helpers.entity_registry.async_get_registry()
unique_id = unique_id_from_hash(discovery_hash)
entity_id = entity_registry.async_get_entity_id(platform, DOMAIN, unique_id)
if entity_id:
_LOGGER.debug("Removing entity: %s %s", platform, discovery_hash)
entity_registry.async_remove(entity_id)
return
if discovery_hash in hass.data[ALREADY_DISCOVERED]:
_LOGGER.debug(
"Entity already added, sending update: %s %s",
platform,
discovery_hash,
)
async_dispatcher_send(
hass,
TASMOTA_DISCOVERY_ENTITY_UPDATED.format(*discovery_hash),
tasmota_entity_config,
)
else:
tasmota_entity = tasmota_get_entity(tasmota_entity_config, tasmota_mqtt)
_LOGGER.debug(
"Adding new entity: %s %s %s",
platform,
discovery_hash,
tasmota_entity.unique_id,
)
hass.data[ALREADY_DISCOVERED][discovery_hash] = None
async_dispatcher_send(
hass,
TASMOTA_DISCOVERY_ENTITY_NEW.format(platform),
tasmota_entity,
discovery_hash,
)
async def async_device_discovered(payload, mac):
"""Process the received message."""
if ALREADY_DISCOVERED not in hass.data:
# Discovery is shutting down
return
_LOGGER.debug("Received discovery data for tasmota device: %s", mac)
tasmota_device_config = tasmota_get_device_config(payload)
setup_device(tasmota_device_config, mac)
if not payload:
return
tasmota_triggers = tasmota_get_triggers(payload)
for trigger_config in tasmota_triggers:
discovery_hash = (mac, "automation", "trigger", trigger_config.trigger_id)
if discovery_hash in hass.data[ALREADY_DISCOVERED]:
_LOGGER.debug(
"Trigger already added, sending update: %s",
discovery_hash,
)
async_dispatcher_send(
hass,
TASMOTA_DISCOVERY_ENTITY_UPDATED.format(*discovery_hash),
trigger_config,
)
elif trigger_config.is_active:
_LOGGER.debug("Adding new trigger: %s", discovery_hash)
hass.data[ALREADY_DISCOVERED][discovery_hash] = None
tasmota_trigger = tasmota_get_trigger(trigger_config, tasmota_mqtt)
async_dispatcher_send(
hass,
TASMOTA_DISCOVERY_ENTITY_NEW.format("device_automation"),
tasmota_trigger,
discovery_hash,
)
for platform in PLATFORMS:
tasmota_entities = tasmota_get_entities_for_platform(payload, platform)
for (tasmota_entity_config, discovery_hash) in tasmota_entities:
await _discover_entity(tasmota_entity_config, discovery_hash, platform)
async def async_sensors_discovered(sensors, mac):
"""Handle discovery of (additional) sensors."""
platform = sensor.DOMAIN
device_registry = await hass.helpers.device_registry.async_get_registry()
entity_registry = await hass.helpers.entity_registry.async_get_registry()
device = device_registry.async_get_device(set(), {("mac", mac)})
if device is None:
_LOGGER.warning("Got sensors for unknown device mac: %s", mac)
return
orphaned_entities = {
entry.unique_id
for entry in async_entries_for_device(entity_registry, device.id)
if entry.domain == sensor.DOMAIN and entry.platform == DOMAIN
}
for (tasmota_sensor_config, discovery_hash) in sensors:
if tasmota_sensor_config:
orphaned_entities.discard(tasmota_sensor_config.unique_id)
await _discover_entity(tasmota_sensor_config, discovery_hash, platform)
for unique_id in orphaned_entities:
entity_id = entity_registry.async_get_entity_id(platform, DOMAIN, unique_id)
if entity_id:
_LOGGER.debug("Removing entity: %s %s", platform, entity_id)
entity_registry.async_remove(entity_id)
hass.data[ALREADY_DISCOVERED] = {}
tasmota_discovery = TasmotaDiscovery(discovery_topic, tasmota_mqtt)
await tasmota_discovery.start_discovery(
async_device_discovered, async_sensors_discovered
)
hass.data[TASMOTA_DISCOVERY_INSTANCE] = tasmota_discovery | [
"async",
"def",
"async_start",
"(",
"hass",
":",
"HomeAssistantType",
",",
"discovery_topic",
",",
"config_entry",
",",
"tasmota_mqtt",
",",
"setup_device",
")",
"->",
"bool",
":",
"async",
"def",
"_discover_entity",
"(",
"tasmota_entity_config",
",",
"discovery_hash",
",",
"platform",
")",
":",
"\"\"\"Handle adding or updating a discovered entity.\"\"\"",
"if",
"not",
"tasmota_entity_config",
":",
"# Entity disabled, clean up entity registry",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"unique_id",
"=",
"unique_id_from_hash",
"(",
"discovery_hash",
")",
"entity_id",
"=",
"entity_registry",
".",
"async_get_entity_id",
"(",
"platform",
",",
"DOMAIN",
",",
"unique_id",
")",
"if",
"entity_id",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Removing entity: %s %s\"",
",",
"platform",
",",
"discovery_hash",
")",
"entity_registry",
".",
"async_remove",
"(",
"entity_id",
")",
"return",
"if",
"discovery_hash",
"in",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Entity already added, sending update: %s %s\"",
",",
"platform",
",",
"discovery_hash",
",",
")",
"async_dispatcher_send",
"(",
"hass",
",",
"TASMOTA_DISCOVERY_ENTITY_UPDATED",
".",
"format",
"(",
"*",
"discovery_hash",
")",
",",
"tasmota_entity_config",
",",
")",
"else",
":",
"tasmota_entity",
"=",
"tasmota_get_entity",
"(",
"tasmota_entity_config",
",",
"tasmota_mqtt",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Adding new entity: %s %s %s\"",
",",
"platform",
",",
"discovery_hash",
",",
"tasmota_entity",
".",
"unique_id",
",",
")",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
"[",
"discovery_hash",
"]",
"=",
"None",
"async_dispatcher_send",
"(",
"hass",
",",
"TASMOTA_DISCOVERY_ENTITY_NEW",
".",
"format",
"(",
"platform",
")",
",",
"tasmota_entity",
",",
"discovery_hash",
",",
")",
"async",
"def",
"async_device_discovered",
"(",
"payload",
",",
"mac",
")",
":",
"\"\"\"Process the received message.\"\"\"",
"if",
"ALREADY_DISCOVERED",
"not",
"in",
"hass",
".",
"data",
":",
"# Discovery is shutting down",
"return",
"_LOGGER",
".",
"debug",
"(",
"\"Received discovery data for tasmota device: %s\"",
",",
"mac",
")",
"tasmota_device_config",
"=",
"tasmota_get_device_config",
"(",
"payload",
")",
"setup_device",
"(",
"tasmota_device_config",
",",
"mac",
")",
"if",
"not",
"payload",
":",
"return",
"tasmota_triggers",
"=",
"tasmota_get_triggers",
"(",
"payload",
")",
"for",
"trigger_config",
"in",
"tasmota_triggers",
":",
"discovery_hash",
"=",
"(",
"mac",
",",
"\"automation\"",
",",
"\"trigger\"",
",",
"trigger_config",
".",
"trigger_id",
")",
"if",
"discovery_hash",
"in",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Trigger already added, sending update: %s\"",
",",
"discovery_hash",
",",
")",
"async_dispatcher_send",
"(",
"hass",
",",
"TASMOTA_DISCOVERY_ENTITY_UPDATED",
".",
"format",
"(",
"*",
"discovery_hash",
")",
",",
"trigger_config",
",",
")",
"elif",
"trigger_config",
".",
"is_active",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Adding new trigger: %s\"",
",",
"discovery_hash",
")",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
"[",
"discovery_hash",
"]",
"=",
"None",
"tasmota_trigger",
"=",
"tasmota_get_trigger",
"(",
"trigger_config",
",",
"tasmota_mqtt",
")",
"async_dispatcher_send",
"(",
"hass",
",",
"TASMOTA_DISCOVERY_ENTITY_NEW",
".",
"format",
"(",
"\"device_automation\"",
")",
",",
"tasmota_trigger",
",",
"discovery_hash",
",",
")",
"for",
"platform",
"in",
"PLATFORMS",
":",
"tasmota_entities",
"=",
"tasmota_get_entities_for_platform",
"(",
"payload",
",",
"platform",
")",
"for",
"(",
"tasmota_entity_config",
",",
"discovery_hash",
")",
"in",
"tasmota_entities",
":",
"await",
"_discover_entity",
"(",
"tasmota_entity_config",
",",
"discovery_hash",
",",
"platform",
")",
"async",
"def",
"async_sensors_discovered",
"(",
"sensors",
",",
"mac",
")",
":",
"\"\"\"Handle discovery of (additional) sensors.\"\"\"",
"platform",
"=",
"sensor",
".",
"DOMAIN",
"device_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"device",
"=",
"device_registry",
".",
"async_get_device",
"(",
"set",
"(",
")",
",",
"{",
"(",
"\"mac\"",
",",
"mac",
")",
"}",
")",
"if",
"device",
"is",
"None",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Got sensors for unknown device mac: %s\"",
",",
"mac",
")",
"return",
"orphaned_entities",
"=",
"{",
"entry",
".",
"unique_id",
"for",
"entry",
"in",
"async_entries_for_device",
"(",
"entity_registry",
",",
"device",
".",
"id",
")",
"if",
"entry",
".",
"domain",
"==",
"sensor",
".",
"DOMAIN",
"and",
"entry",
".",
"platform",
"==",
"DOMAIN",
"}",
"for",
"(",
"tasmota_sensor_config",
",",
"discovery_hash",
")",
"in",
"sensors",
":",
"if",
"tasmota_sensor_config",
":",
"orphaned_entities",
".",
"discard",
"(",
"tasmota_sensor_config",
".",
"unique_id",
")",
"await",
"_discover_entity",
"(",
"tasmota_sensor_config",
",",
"discovery_hash",
",",
"platform",
")",
"for",
"unique_id",
"in",
"orphaned_entities",
":",
"entity_id",
"=",
"entity_registry",
".",
"async_get_entity_id",
"(",
"platform",
",",
"DOMAIN",
",",
"unique_id",
")",
"if",
"entity_id",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Removing entity: %s %s\"",
",",
"platform",
",",
"entity_id",
")",
"entity_registry",
".",
"async_remove",
"(",
"entity_id",
")",
"hass",
".",
"data",
"[",
"ALREADY_DISCOVERED",
"]",
"=",
"{",
"}",
"tasmota_discovery",
"=",
"TasmotaDiscovery",
"(",
"discovery_topic",
",",
"tasmota_mqtt",
")",
"await",
"tasmota_discovery",
".",
"start_discovery",
"(",
"async_device_discovered",
",",
"async_sensors_discovered",
")",
"hass",
".",
"data",
"[",
"TASMOTA_DISCOVERY_INSTANCE",
"]",
"=",
"tasmota_discovery"
] | [
41,
0
] | [
165,
61
] | python | en | ['it', 'ru-Latn', 'en'] | False |
async_stop | (hass: HomeAssistantType) | Stop Tasmota device discovery. | Stop Tasmota device discovery. | async def async_stop(hass: HomeAssistantType) -> bool:
"""Stop Tasmota device discovery."""
hass.data.pop(ALREADY_DISCOVERED)
tasmota_discovery = hass.data.pop(TASMOTA_DISCOVERY_INSTANCE)
await tasmota_discovery.stop_discovery() | [
"async",
"def",
"async_stop",
"(",
"hass",
":",
"HomeAssistantType",
")",
"->",
"bool",
":",
"hass",
".",
"data",
".",
"pop",
"(",
"ALREADY_DISCOVERED",
")",
"tasmota_discovery",
"=",
"hass",
".",
"data",
".",
"pop",
"(",
"TASMOTA_DISCOVERY_INSTANCE",
")",
"await",
"tasmota_discovery",
".",
"stop_discovery",
"(",
")"
] | [
168,
0
] | [
172,
44
] | python | en | ['it', 'lt', 'en'] | False |
_state_validator | (config) | Validate the state. | Validate the state. | def _state_validator(config):
"""Validate the state."""
config = copy.deepcopy(config)
for state in SUPPORTED_PRETRIGGER_STATES:
if CONF_DELAY_TIME not in config[state]:
config[state][CONF_DELAY_TIME] = config[CONF_DELAY_TIME]
if CONF_TRIGGER_TIME not in config[state]:
config[state][CONF_TRIGGER_TIME] = config[CONF_TRIGGER_TIME]
for state in SUPPORTED_ARMING_STATES:
if CONF_ARMING_TIME not in config[state]:
config[state][CONF_ARMING_TIME] = config[CONF_ARMING_TIME]
return config | [
"def",
"_state_validator",
"(",
"config",
")",
":",
"config",
"=",
"copy",
".",
"deepcopy",
"(",
"config",
")",
"for",
"state",
"in",
"SUPPORTED_PRETRIGGER_STATES",
":",
"if",
"CONF_DELAY_TIME",
"not",
"in",
"config",
"[",
"state",
"]",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_DELAY_TIME",
"]",
"=",
"config",
"[",
"CONF_DELAY_TIME",
"]",
"if",
"CONF_TRIGGER_TIME",
"not",
"in",
"config",
"[",
"state",
"]",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_TRIGGER_TIME",
"]",
"=",
"config",
"[",
"CONF_TRIGGER_TIME",
"]",
"for",
"state",
"in",
"SUPPORTED_ARMING_STATES",
":",
"if",
"CONF_ARMING_TIME",
"not",
"in",
"config",
"[",
"state",
"]",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_ARMING_TIME",
"]",
"=",
"config",
"[",
"CONF_ARMING_TIME",
"]",
"return",
"config"
] | [
73,
0
] | [
85,
17
] | python | en | ['en', 'en', 'en'] | True |
_state_schema | (state) | Validate the state. | Validate the state. | def _state_schema(state):
"""Validate the state."""
schema = {}
if state in SUPPORTED_PRETRIGGER_STATES:
schema[vol.Optional(CONF_DELAY_TIME)] = vol.All(
cv.time_period, cv.positive_timedelta
)
schema[vol.Optional(CONF_TRIGGER_TIME)] = vol.All(
cv.time_period, cv.positive_timedelta
)
if state in SUPPORTED_ARMING_STATES:
schema[vol.Optional(CONF_ARMING_TIME)] = vol.All(
cv.time_period, cv.positive_timedelta
)
return vol.Schema(schema) | [
"def",
"_state_schema",
"(",
"state",
")",
":",
"schema",
"=",
"{",
"}",
"if",
"state",
"in",
"SUPPORTED_PRETRIGGER_STATES",
":",
"schema",
"[",
"vol",
".",
"Optional",
"(",
"CONF_DELAY_TIME",
")",
"]",
"=",
"vol",
".",
"All",
"(",
"cv",
".",
"time_period",
",",
"cv",
".",
"positive_timedelta",
")",
"schema",
"[",
"vol",
".",
"Optional",
"(",
"CONF_TRIGGER_TIME",
")",
"]",
"=",
"vol",
".",
"All",
"(",
"cv",
".",
"time_period",
",",
"cv",
".",
"positive_timedelta",
")",
"if",
"state",
"in",
"SUPPORTED_ARMING_STATES",
":",
"schema",
"[",
"vol",
".",
"Optional",
"(",
"CONF_ARMING_TIME",
")",
"]",
"=",
"vol",
".",
"All",
"(",
"cv",
".",
"time_period",
",",
"cv",
".",
"positive_timedelta",
")",
"return",
"vol",
".",
"Schema",
"(",
"schema",
")"
] | [
88,
0
] | [
102,
29
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the manual alarm platform. | Set up the manual alarm platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the manual alarm platform."""
add_entities(
[
ManualAlarm(
hass,
config[CONF_NAME],
config.get(CONF_CODE),
config.get(CONF_CODE_TEMPLATE),
config.get(CONF_CODE_ARM_REQUIRED),
config.get(CONF_DISARM_AFTER_TRIGGER, DEFAULT_DISARM_AFTER_TRIGGER),
config,
)
]
) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"add_entities",
"(",
"[",
"ManualAlarm",
"(",
"hass",
",",
"config",
"[",
"CONF_NAME",
"]",
",",
"config",
".",
"get",
"(",
"CONF_CODE",
")",
",",
"config",
".",
"get",
"(",
"CONF_CODE_TEMPLATE",
")",
",",
"config",
".",
"get",
"(",
"CONF_CODE_ARM_REQUIRED",
")",
",",
"config",
".",
"get",
"(",
"CONF_DISARM_AFTER_TRIGGER",
",",
"DEFAULT_DISARM_AFTER_TRIGGER",
")",
",",
"config",
",",
")",
"]",
")"
] | [
149,
0
] | [
163,
5
] | python | en | ['en', 'su', 'en'] | True |
ManualAlarm.__init__ | (
self,
hass,
name,
code,
code_template,
code_arm_required,
disarm_after_trigger,
config,
) | Init the manual alarm panel. | Init the manual alarm panel. | def __init__(
self,
hass,
name,
code,
code_template,
code_arm_required,
disarm_after_trigger,
config,
):
"""Init the manual alarm panel."""
self._state = STATE_ALARM_DISARMED
self._hass = hass
self._name = name
if code_template:
self._code = code_template
self._code.hass = hass
else:
self._code = code or None
self._code_arm_required = code_arm_required
self._disarm_after_trigger = disarm_after_trigger
self._previous_state = self._state
self._state_ts = None
self._delay_time_by_state = {
state: config[state][CONF_DELAY_TIME]
for state in SUPPORTED_PRETRIGGER_STATES
}
self._trigger_time_by_state = {
state: config[state][CONF_TRIGGER_TIME]
for state in SUPPORTED_PRETRIGGER_STATES
}
self._arming_time_by_state = {
state: config[state][CONF_ARMING_TIME] for state in SUPPORTED_ARMING_STATES
} | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"name",
",",
"code",
",",
"code_template",
",",
"code_arm_required",
",",
"disarm_after_trigger",
",",
"config",
",",
")",
":",
"self",
".",
"_state",
"=",
"STATE_ALARM_DISARMED",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_name",
"=",
"name",
"if",
"code_template",
":",
"self",
".",
"_code",
"=",
"code_template",
"self",
".",
"_code",
".",
"hass",
"=",
"hass",
"else",
":",
"self",
".",
"_code",
"=",
"code",
"or",
"None",
"self",
".",
"_code_arm_required",
"=",
"code_arm_required",
"self",
".",
"_disarm_after_trigger",
"=",
"disarm_after_trigger",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_state",
"self",
".",
"_state_ts",
"=",
"None",
"self",
".",
"_delay_time_by_state",
"=",
"{",
"state",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_DELAY_TIME",
"]",
"for",
"state",
"in",
"SUPPORTED_PRETRIGGER_STATES",
"}",
"self",
".",
"_trigger_time_by_state",
"=",
"{",
"state",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_TRIGGER_TIME",
"]",
"for",
"state",
"in",
"SUPPORTED_PRETRIGGER_STATES",
"}",
"self",
".",
"_arming_time_by_state",
"=",
"{",
"state",
":",
"config",
"[",
"state",
"]",
"[",
"CONF_ARMING_TIME",
"]",
"for",
"state",
"in",
"SUPPORTED_ARMING_STATES",
"}"
] | [
177,
4
] | [
211,
9
] | python | en | ['en', 'ja', 'en'] | True |
ManualAlarm.should_poll | (self) | Return the polling state. | Return the polling state. | def should_poll(self):
"""Return the polling state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
214,
4
] | [
216,
20
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
219,
4
] | [
221,
25
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
if self._state == STATE_ALARM_TRIGGERED:
if self._within_pending_time(self._state):
return STATE_ALARM_PENDING
trigger_time = self._trigger_time_by_state[self._previous_state]
if (
self._state_ts + self._pending_time(self._state) + trigger_time
) < dt_util.utcnow():
if self._disarm_after_trigger:
return STATE_ALARM_DISARMED
self._state = self._previous_state
return self._state
if self._state in SUPPORTED_ARMING_STATES and self._within_arming_time(
self._state
):
return STATE_ALARM_ARMING
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"==",
"STATE_ALARM_TRIGGERED",
":",
"if",
"self",
".",
"_within_pending_time",
"(",
"self",
".",
"_state",
")",
":",
"return",
"STATE_ALARM_PENDING",
"trigger_time",
"=",
"self",
".",
"_trigger_time_by_state",
"[",
"self",
".",
"_previous_state",
"]",
"if",
"(",
"self",
".",
"_state_ts",
"+",
"self",
".",
"_pending_time",
"(",
"self",
".",
"_state",
")",
"+",
"trigger_time",
")",
"<",
"dt_util",
".",
"utcnow",
"(",
")",
":",
"if",
"self",
".",
"_disarm_after_trigger",
":",
"return",
"STATE_ALARM_DISARMED",
"self",
".",
"_state",
"=",
"self",
".",
"_previous_state",
"return",
"self",
".",
"_state",
"if",
"self",
".",
"_state",
"in",
"SUPPORTED_ARMING_STATES",
"and",
"self",
".",
"_within_arming_time",
"(",
"self",
".",
"_state",
")",
":",
"return",
"STATE_ALARM_ARMING",
"return",
"self",
".",
"_state"
] | [
224,
4
] | [
243,
26
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return (
SUPPORT_ALARM_ARM_HOME
| SUPPORT_ALARM_ARM_AWAY
| SUPPORT_ALARM_ARM_NIGHT
| SUPPORT_ALARM_TRIGGER
| SUPPORT_ALARM_ARM_CUSTOM_BYPASS
) | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"(",
"SUPPORT_ALARM_ARM_HOME",
"|",
"SUPPORT_ALARM_ARM_AWAY",
"|",
"SUPPORT_ALARM_ARM_NIGHT",
"|",
"SUPPORT_ALARM_TRIGGER",
"|",
"SUPPORT_ALARM_ARM_CUSTOM_BYPASS",
")"
] | [
246,
4
] | [
254,
9
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._active_state | (self) | Get the current state. | Get the current state. | def _active_state(self):
"""Get the current state."""
if self.state in (STATE_ALARM_PENDING, STATE_ALARM_ARMING):
return self._previous_state
return self._state | [
"def",
"_active_state",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"in",
"(",
"STATE_ALARM_PENDING",
",",
"STATE_ALARM_ARMING",
")",
":",
"return",
"self",
".",
"_previous_state",
"return",
"self",
".",
"_state"
] | [
257,
4
] | [
261,
26
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._arming_time | (self, state) | Get the arming time. | Get the arming time. | def _arming_time(self, state):
"""Get the arming time."""
return self._arming_time_by_state[state] | [
"def",
"_arming_time",
"(",
"self",
",",
"state",
")",
":",
"return",
"self",
".",
"_arming_time_by_state",
"[",
"state",
"]"
] | [
263,
4
] | [
265,
48
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._pending_time | (self, state) | Get the pending time. | Get the pending time. | def _pending_time(self, state):
"""Get the pending time."""
return self._delay_time_by_state[self._previous_state] | [
"def",
"_pending_time",
"(",
"self",
",",
"state",
")",
":",
"return",
"self",
".",
"_delay_time_by_state",
"[",
"self",
".",
"_previous_state",
"]"
] | [
267,
4
] | [
269,
62
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._within_arming_time | (self, state) | Get if the action is in the arming time window. | Get if the action is in the arming time window. | def _within_arming_time(self, state):
"""Get if the action is in the arming time window."""
return self._state_ts + self._arming_time(state) > dt_util.utcnow() | [
"def",
"_within_arming_time",
"(",
"self",
",",
"state",
")",
":",
"return",
"self",
".",
"_state_ts",
"+",
"self",
".",
"_arming_time",
"(",
"state",
")",
">",
"dt_util",
".",
"utcnow",
"(",
")"
] | [
271,
4
] | [
273,
75
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._within_pending_time | (self, state) | Get if the action is in the pending time window. | Get if the action is in the pending time window. | def _within_pending_time(self, state):
"""Get if the action is in the pending time window."""
return self._state_ts + self._pending_time(state) > dt_util.utcnow() | [
"def",
"_within_pending_time",
"(",
"self",
",",
"state",
")",
":",
"return",
"self",
".",
"_state_ts",
"+",
"self",
".",
"_pending_time",
"(",
"state",
")",
">",
"dt_util",
".",
"utcnow",
"(",
")"
] | [
275,
4
] | [
277,
76
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.code_format | (self) | Return one or more digits/characters. | Return one or more digits/characters. | def code_format(self):
"""Return one or more digits/characters."""
if self._code is None:
return None
if isinstance(self._code, str) and re.search("^\\d+$", self._code):
return alarm.FORMAT_NUMBER
return alarm.FORMAT_TEXT | [
"def",
"code_format",
"(",
"self",
")",
":",
"if",
"self",
".",
"_code",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"self",
".",
"_code",
",",
"str",
")",
"and",
"re",
".",
"search",
"(",
"\"^\\\\d+$\"",
",",
"self",
".",
"_code",
")",
":",
"return",
"alarm",
".",
"FORMAT_NUMBER",
"return",
"alarm",
".",
"FORMAT_TEXT"
] | [
280,
4
] | [
286,
32
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.code_arm_required | (self) | Whether the code is required for arm actions. | Whether the code is required for arm actions. | def code_arm_required(self):
"""Whether the code is required for arm actions."""
return self._code_arm_required | [
"def",
"code_arm_required",
"(",
"self",
")",
":",
"return",
"self",
".",
"_code_arm_required"
] | [
289,
4
] | [
291,
38
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | def alarm_disarm(self, code=None):
"""Send disarm command."""
if not self._validate_code(code, STATE_ALARM_DISARMED):
return
self._state = STATE_ALARM_DISARMED
self._state_ts = dt_util.utcnow()
self.schedule_update_ha_state() | [
"def",
"alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"STATE_ALARM_DISARMED",
")",
":",
"return",
"self",
".",
"_state",
"=",
"STATE_ALARM_DISARMED",
"self",
".",
"_state_ts",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
293,
4
] | [
300,
39
] | python | en | ['en', 'pt', 'en'] | True |
ManualAlarm.alarm_arm_home | (self, code=None) | Send arm home command. | Send arm home command. | def alarm_arm_home(self, code=None):
"""Send arm home command."""
if self._code_arm_required and not self._validate_code(
code, STATE_ALARM_ARMED_HOME
):
return
self._update_state(STATE_ALARM_ARMED_HOME) | [
"def",
"alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"self",
".",
"_code_arm_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"STATE_ALARM_ARMED_HOME",
")",
":",
"return",
"self",
".",
"_update_state",
"(",
"STATE_ALARM_ARMED_HOME",
")"
] | [
302,
4
] | [
309,
50
] | python | en | ['en', 'pt', 'en'] | True |
ManualAlarm.alarm_arm_away | (self, code=None) | Send arm away command. | Send arm away command. | def alarm_arm_away(self, code=None):
"""Send arm away command."""
if self._code_arm_required and not self._validate_code(
code, STATE_ALARM_ARMED_AWAY
):
return
self._update_state(STATE_ALARM_ARMED_AWAY) | [
"def",
"alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"self",
".",
"_code_arm_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"STATE_ALARM_ARMED_AWAY",
")",
":",
"return",
"self",
".",
"_update_state",
"(",
"STATE_ALARM_ARMED_AWAY",
")"
] | [
311,
4
] | [
318,
50
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.alarm_arm_night | (self, code=None) | Send arm night command. | Send arm night command. | def alarm_arm_night(self, code=None):
"""Send arm night command."""
if self._code_arm_required and not self._validate_code(
code, STATE_ALARM_ARMED_NIGHT
):
return
self._update_state(STATE_ALARM_ARMED_NIGHT) | [
"def",
"alarm_arm_night",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"self",
".",
"_code_arm_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"STATE_ALARM_ARMED_NIGHT",
")",
":",
"return",
"self",
".",
"_update_state",
"(",
"STATE_ALARM_ARMED_NIGHT",
")"
] | [
320,
4
] | [
327,
51
] | python | en | ['en', 'zh', 'en'] | True |
ManualAlarm.alarm_arm_custom_bypass | (self, code=None) | Send arm custom bypass command. | Send arm custom bypass command. | def alarm_arm_custom_bypass(self, code=None):
"""Send arm custom bypass command."""
if self._code_arm_required and not self._validate_code(
code, STATE_ALARM_ARMED_CUSTOM_BYPASS
):
return
self._update_state(STATE_ALARM_ARMED_CUSTOM_BYPASS) | [
"def",
"alarm_arm_custom_bypass",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"self",
".",
"_code_arm_required",
"and",
"not",
"self",
".",
"_validate_code",
"(",
"code",
",",
"STATE_ALARM_ARMED_CUSTOM_BYPASS",
")",
":",
"return",
"self",
".",
"_update_state",
"(",
"STATE_ALARM_ARMED_CUSTOM_BYPASS",
")"
] | [
329,
4
] | [
336,
59
] | python | en | ['en', 'ga', 'en'] | True |
ManualAlarm.alarm_trigger | (self, code=None) |
Send alarm trigger command.
No code needed, a trigger time of zero for the current state
disables the alarm.
|
Send alarm trigger command. | def alarm_trigger(self, code=None):
"""
Send alarm trigger command.
No code needed, a trigger time of zero for the current state
disables the alarm.
"""
if not self._trigger_time_by_state[self._active_state]:
return
self._update_state(STATE_ALARM_TRIGGERED) | [
"def",
"alarm_trigger",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_trigger_time_by_state",
"[",
"self",
".",
"_active_state",
"]",
":",
"return",
"self",
".",
"_update_state",
"(",
"STATE_ALARM_TRIGGERED",
")"
] | [
338,
4
] | [
347,
49
] | python | en | ['en', 'error', 'th'] | False |
ManualAlarm._update_state | (self, state) | Update the state. | Update the state. | def _update_state(self, state):
"""Update the state."""
if self._state == state:
return
self._previous_state = self._state
self._state = state
self._state_ts = dt_util.utcnow()
self.schedule_update_ha_state()
if state == STATE_ALARM_TRIGGERED:
pending_time = self._pending_time(state)
track_point_in_time(
self._hass, self.async_scheduled_update, self._state_ts + pending_time
)
trigger_time = self._trigger_time_by_state[self._previous_state]
track_point_in_time(
self._hass,
self.async_scheduled_update,
self._state_ts + pending_time + trigger_time,
)
elif state in SUPPORTED_ARMING_STATES:
arming_time = self._arming_time(state)
if arming_time:
track_point_in_time(
self._hass,
self.async_scheduled_update,
self._state_ts + arming_time,
) | [
"def",
"_update_state",
"(",
"self",
",",
"state",
")",
":",
"if",
"self",
".",
"_state",
"==",
"state",
":",
"return",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_state",
"self",
".",
"_state",
"=",
"state",
"self",
".",
"_state_ts",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")",
"if",
"state",
"==",
"STATE_ALARM_TRIGGERED",
":",
"pending_time",
"=",
"self",
".",
"_pending_time",
"(",
"state",
")",
"track_point_in_time",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"async_scheduled_update",
",",
"self",
".",
"_state_ts",
"+",
"pending_time",
")",
"trigger_time",
"=",
"self",
".",
"_trigger_time_by_state",
"[",
"self",
".",
"_previous_state",
"]",
"track_point_in_time",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"async_scheduled_update",
",",
"self",
".",
"_state_ts",
"+",
"pending_time",
"+",
"trigger_time",
",",
")",
"elif",
"state",
"in",
"SUPPORTED_ARMING_STATES",
":",
"arming_time",
"=",
"self",
".",
"_arming_time",
"(",
"state",
")",
"if",
"arming_time",
":",
"track_point_in_time",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"async_scheduled_update",
",",
"self",
".",
"_state_ts",
"+",
"arming_time",
",",
")"
] | [
349,
4
] | [
378,
17
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm._validate_code | (self, code, state) | Validate given code. | Validate given code. | def _validate_code(self, code, state):
"""Validate given code."""
if self._code is None:
return True
if isinstance(self._code, str):
alarm_code = self._code
else:
alarm_code = self._code.render(
parse_result=False, from_state=self._state, to_state=state
)
check = not alarm_code or code == alarm_code
if not check:
_LOGGER.warning("Invalid code given for %s", state)
return check | [
"def",
"_validate_code",
"(",
"self",
",",
"code",
",",
"state",
")",
":",
"if",
"self",
".",
"_code",
"is",
"None",
":",
"return",
"True",
"if",
"isinstance",
"(",
"self",
".",
"_code",
",",
"str",
")",
":",
"alarm_code",
"=",
"self",
".",
"_code",
"else",
":",
"alarm_code",
"=",
"self",
".",
"_code",
".",
"render",
"(",
"parse_result",
"=",
"False",
",",
"from_state",
"=",
"self",
".",
"_state",
",",
"to_state",
"=",
"state",
")",
"check",
"=",
"not",
"alarm_code",
"or",
"code",
"==",
"alarm_code",
"if",
"not",
"check",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Invalid code given for %s\"",
",",
"state",
")",
"return",
"check"
] | [
380,
4
] | [
393,
20
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self.state == STATE_ALARM_PENDING or self.state == STATE_ALARM_ARMING:
return {
ATTR_PREVIOUS_STATE: self._previous_state,
ATTR_NEXT_STATE: self._state,
}
return {} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"state",
"==",
"STATE_ALARM_PENDING",
"or",
"self",
".",
"state",
"==",
"STATE_ALARM_ARMING",
":",
"return",
"{",
"ATTR_PREVIOUS_STATE",
":",
"self",
".",
"_previous_state",
",",
"ATTR_NEXT_STATE",
":",
"self",
".",
"_state",
",",
"}",
"return",
"{",
"}"
] | [
396,
4
] | [
403,
17
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.async_scheduled_update | (self, now) | Update state at a scheduled point in time. | Update state at a scheduled point in time. | def async_scheduled_update(self, now):
"""Update state at a scheduled point in time."""
self.async_write_ha_state() | [
"def",
"async_scheduled_update",
"(",
"self",
",",
"now",
")",
":",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
406,
4
] | [
408,
35
] | python | en | ['en', 'en', 'en'] | True |
ManualAlarm.async_added_to_hass | (self) | Run when entity about to be added to hass. | Run when entity about to be added to hass. | async def async_added_to_hass(self):
"""Run when entity about to be added to hass."""
await super().async_added_to_hass()
state = await self.async_get_last_state()
if state:
if (
(
state.state == STATE_ALARM_PENDING
or state.state == STATE_ALARM_ARMING
)
and hasattr(state, "attributes")
and state.attributes[ATTR_PREVIOUS_STATE]
):
# If in arming or pending state, we return to the ATTR_PREVIOUS_STATE
self._state = state.attributes[ATTR_PREVIOUS_STATE]
self._state_ts = dt_util.utcnow()
else:
self._state = state.state
self._state_ts = state.last_updated | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_added_to_hass",
"(",
")",
"state",
"=",
"await",
"self",
".",
"async_get_last_state",
"(",
")",
"if",
"state",
":",
"if",
"(",
"(",
"state",
".",
"state",
"==",
"STATE_ALARM_PENDING",
"or",
"state",
".",
"state",
"==",
"STATE_ALARM_ARMING",
")",
"and",
"hasattr",
"(",
"state",
",",
"\"attributes\"",
")",
"and",
"state",
".",
"attributes",
"[",
"ATTR_PREVIOUS_STATE",
"]",
")",
":",
"# If in arming or pending state, we return to the ATTR_PREVIOUS_STATE",
"self",
".",
"_state",
"=",
"state",
".",
"attributes",
"[",
"ATTR_PREVIOUS_STATE",
"]",
"self",
".",
"_state_ts",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"else",
":",
"self",
".",
"_state",
"=",
"state",
".",
"state",
"self",
".",
"_state_ts",
"=",
"state",
".",
"last_updated"
] | [
410,
4
] | [
428,
51
] | python | en | ['en', 'en', 'en'] | True |
test_moon_day1 | (hass) | Test the Moon sensor. | Test the Moon sensor. | async def test_moon_day1(hass):
"""Test the Moon sensor."""
config = {"sensor": {"platform": "moon", "name": "moon_day1"}}
await async_setup_component(hass, HA_DOMAIN, {})
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
assert hass.states.get("sensor.moon_day1")
with patch(
"homeassistant.components.moon.sensor.dt_util.utcnow", return_value=DAY1
):
await async_update_entity(hass, "sensor.moon_day1")
assert hass.states.get("sensor.moon_day1").state == "waxing_crescent" | [
"async",
"def",
"test_moon_day1",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"moon\"",
",",
"\"name\"",
":",
"\"moon_day1\"",
"}",
"}",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.moon_day1\"",
")",
"with",
"patch",
"(",
"\"homeassistant.components.moon.sensor.dt_util.utcnow\"",
",",
"return_value",
"=",
"DAY1",
")",
":",
"await",
"async_update_entity",
"(",
"hass",
",",
"\"sensor.moon_day1\"",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.moon_day1\"",
")",
".",
"state",
"==",
"\"waxing_crescent\""
] | [
17,
0
] | [
32,
73
] | python | en | ['en', 'st', 'en'] | True |
test_moon_day2 | (hass) | Test the Moon sensor. | Test the Moon sensor. | async def test_moon_day2(hass):
"""Test the Moon sensor."""
config = {"sensor": {"platform": "moon", "name": "moon_day2"}}
await async_setup_component(hass, HA_DOMAIN, {})
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
assert hass.states.get("sensor.moon_day2")
with patch(
"homeassistant.components.moon.sensor.dt_util.utcnow", return_value=DAY2
):
await async_update_entity(hass, "sensor.moon_day2")
assert hass.states.get("sensor.moon_day2").state == "waning_gibbous" | [
"async",
"def",
"test_moon_day2",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"moon\"",
",",
"\"name\"",
":",
"\"moon_day2\"",
"}",
"}",
"await",
"async_setup_component",
"(",
"hass",
",",
"HA_DOMAIN",
",",
"{",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.moon_day2\"",
")",
"with",
"patch",
"(",
"\"homeassistant.components.moon.sensor.dt_util.utcnow\"",
",",
"return_value",
"=",
"DAY2",
")",
":",
"await",
"async_update_entity",
"(",
"hass",
",",
"\"sensor.moon_day2\"",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.moon_day2\"",
")",
".",
"state",
"==",
"\"waning_gibbous\""
] | [
35,
0
] | [
50,
72
] | python | en | ['en', 'st', 'en'] | True |
async_update_entity | (hass, entity_id) | Run an update action for an entity. | Run an update action for an entity. | async def async_update_entity(hass, entity_id):
"""Run an update action for an entity."""
await hass.services.async_call(
HA_DOMAIN,
SERVICE_UPDATE_ENTITY,
{ATTR_ENTITY_ID: entity_id},
blocking=True,
)
await hass.async_block_till_done() | [
"async",
"def",
"async_update_entity",
"(",
"hass",
",",
"entity_id",
")",
":",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"HA_DOMAIN",
",",
"SERVICE_UPDATE_ENTITY",
",",
"{",
"ATTR_ENTITY_ID",
":",
"entity_id",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
53,
0
] | [
61,
38
] | python | en | ['br', 'en', 'en'] | True |
is_datetime | (val: str, tzone=None) | Check if a string is datetime, return the datetime if yes. | Check if a string is datetime, return the datetime if yes. | def is_datetime(val: str, tzone=None):
"""Check if a string is datetime, return the datetime if yes."""
try:
# default time zone
if tzone is None:
tzone = UTC
else:
tzone = gettz(tzone)
dt = parse_dt(val)
dt = dt.replace(tzinfo=tzone)
return True, dt
except Exception:
pass
return False, None | [
"def",
"is_datetime",
"(",
"val",
":",
"str",
",",
"tzone",
"=",
"None",
")",
":",
"try",
":",
"# default time zone",
"if",
"tzone",
"is",
"None",
":",
"tzone",
"=",
"UTC",
"else",
":",
"tzone",
"=",
"gettz",
"(",
"tzone",
")",
"dt",
"=",
"parse_dt",
"(",
"val",
")",
"dt",
"=",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"tzone",
")",
"return",
"True",
",",
"dt",
"except",
"Exception",
":",
"pass",
"return",
"False",
",",
"None"
] | [
14,
0
] | [
31,
22
] | python | en | ['en', 'en', 'en'] | True |
convert_val | (val: str, dtype: str, tzone) | A simple function to convert str value into specified data type. | A simple function to convert str value into specified data type. | def convert_val(val: str, dtype: str, tzone):
"""A simple function to convert str value into specified data type."""
result = None
# process the value first
# clear
val = val.strip("\"\'")
# clear space at 2 side
val = val.strip()
# NOTE: we only support numeric value for now
t = dtype_convert_map[dtype]
try:
# convert to float first, to avoid int("1.111") error
v = float(val)
result = t(v)
except ValueError:
# is it a datetime?
is_dt, dt = is_datetime(val, tzone)
if is_dt:
# convert into UTC, then utc timestamp
dt = dt.astimezone(UTC)
result = calendar.timegm(dt.timetuple())
if result is None:
warnings.warn(f"Cannot parse value '{val}' into type '{dtype}'")
return result | [
"def",
"convert_val",
"(",
"val",
":",
"str",
",",
"dtype",
":",
"str",
",",
"tzone",
")",
":",
"result",
"=",
"None",
"# process the value first",
"# clear",
"val",
"=",
"val",
".",
"strip",
"(",
"\"\\\"\\'\"",
")",
"# clear space at 2 side",
"val",
"=",
"val",
".",
"strip",
"(",
")",
"# NOTE: we only support numeric value for now",
"t",
"=",
"dtype_convert_map",
"[",
"dtype",
"]",
"try",
":",
"# convert to float first, to avoid int(\"1.111\") error",
"v",
"=",
"float",
"(",
"val",
")",
"result",
"=",
"t",
"(",
"v",
")",
"except",
"ValueError",
":",
"# is it a datetime?",
"is_dt",
",",
"dt",
"=",
"is_datetime",
"(",
"val",
",",
"tzone",
")",
"if",
"is_dt",
":",
"# convert into UTC, then utc timestamp",
"dt",
"=",
"dt",
".",
"astimezone",
"(",
"UTC",
")",
"result",
"=",
"calendar",
".",
"timegm",
"(",
"dt",
".",
"timetuple",
"(",
")",
")",
"if",
"result",
"is",
"None",
":",
"warnings",
".",
"warn",
"(",
"f\"Cannot parse value '{val}' into type '{dtype}'\"",
")",
"return",
"result"
] | [
34,
0
] | [
64,
17
] | python | en | ['en', 'en', 'en'] | True |
BinaryConverter.add_csv | (self, csv_file: str) | Convert specified csv file into current binary file, this converter will not sort the item.
This method can be called several times to convert multiple csv file into one binary,
the order will be same as calling sequence.
Args:
csv_file(str): Csv to convert.
| Convert specified csv file into current binary file, this converter will not sort the item.
This method can be called several times to convert multiple csv file into one binary,
the order will be same as calling sequence. | def add_csv(self, csv_file: str):
"""Convert specified csv file into current binary file, this converter will not sort the item.
This method can be called several times to convert multiple csv file into one binary,
the order will be same as calling sequence.
Args:
csv_file(str): Csv to convert.
"""
with open(csv_file, newline='') as csv_fp:
reader = DictReader(csv_fp)
# write items
self._write_items(reader) | [
"def",
"add_csv",
"(",
"self",
",",
"csv_file",
":",
"str",
")",
":",
"with",
"open",
"(",
"csv_file",
",",
"newline",
"=",
"''",
")",
"as",
"csv_fp",
":",
"reader",
"=",
"DictReader",
"(",
"csv_fp",
")",
"# write items",
"self",
".",
"_write_items",
"(",
"reader",
")"
] | [
113,
4
] | [
125,
37
] | python | en | ['en', 'en', 'en'] | True |
BinaryConverter.flush | (self) | Flush the result into output file. | Flush the result into output file. | def flush(self):
"""Flush the result into output file."""
self._update_header() | [
"def",
"flush",
"(",
"self",
")",
":",
"self",
".",
"_update_header",
"(",
")"
] | [
127,
4
] | [
129,
29
] | python | en | ['en', 'en', 'en'] | True |
BinaryConverter._update_header | (self) | Update file header. | Update file header. | def _update_header(self):
"""Update file header."""
header_bytes = header_struct.pack(
b"MARO",
SINGLE_BIN_FILE_TYPE,
VERSION,
self._item_count,
self._item_size,
self._meta_offset,
self._meta_size,
self._data_offset,
self._data_size,
self._starttime,
self._endtime
)
self._meta_offset = len(header_bytes)
# seek the output file beginning
self._output_fp.seek(0, 0)
self._output_fp.write(header_bytes)
# seek to the file end
self._output_fp.seek(0, 2) | [
"def",
"_update_header",
"(",
"self",
")",
":",
"header_bytes",
"=",
"header_struct",
".",
"pack",
"(",
"b\"MARO\"",
",",
"SINGLE_BIN_FILE_TYPE",
",",
"VERSION",
",",
"self",
".",
"_item_count",
",",
"self",
".",
"_item_size",
",",
"self",
".",
"_meta_offset",
",",
"self",
".",
"_meta_size",
",",
"self",
".",
"_data_offset",
",",
"self",
".",
"_data_size",
",",
"self",
".",
"_starttime",
",",
"self",
".",
"_endtime",
")",
"self",
".",
"_meta_offset",
"=",
"len",
"(",
"header_bytes",
")",
"# seek the output file beginning",
"self",
".",
"_output_fp",
".",
"seek",
"(",
"0",
",",
"0",
")",
"self",
".",
"_output_fp",
".",
"write",
"(",
"header_bytes",
")",
"# seek to the file end",
"self",
".",
"_output_fp",
".",
"seek",
"(",
"0",
",",
"2",
")"
] | [
139,
4
] | [
160,
34
] | python | en | ['en', 'de', 'en'] | True |
BinaryConverter._write_meta | (self) | Write file meta. | Write file meta. | def _write_meta(self):
"""Write file meta."""
meta_bytes = self._meta.to_bytes()
# update header info
self._data_offset = self._meta_offset + len(meta_bytes)
self._meta_size = len(meta_bytes)
self._output_fp.write(meta_bytes) | [
"def",
"_write_meta",
"(",
"self",
")",
":",
"meta_bytes",
"=",
"self",
".",
"_meta",
".",
"to_bytes",
"(",
")",
"# update header info",
"self",
".",
"_data_offset",
"=",
"self",
".",
"_meta_offset",
"+",
"len",
"(",
"meta_bytes",
")",
"self",
".",
"_meta_size",
"=",
"len",
"(",
"meta_bytes",
")",
"self",
".",
"_output_fp",
".",
"write",
"(",
"meta_bytes",
")"
] | [
162,
4
] | [
170,
41
] | python | en | ['fr', 'mi', 'en'] | False |
BinaryConverter._write_items | (self, reader: DictReader) | Write items into binary. | Write items into binary. | def _write_items(self, reader: DictReader):
"""Write items into binary."""
# columns need to convert
columns = self._meta.columns
# values buffer from each row, used to pack into binary
values = [0] * len(columns.keys())
# item binary buffer
buffer = memoryview(bytearray(self._meta.item_size))
# field -> data type
field_type_dict = self._meta.items()
# some column's value may cannot be parse, will skip it
has_invalid_column = False
for row in reader:
field_index = 0
has_invalid_column = False
# clear the values
for j in range(len(values)):
values[j] = 0
# read from current row
for field, dtype in field_type_dict.items():
column_name = columns[field]
# NOTE: we allow field not exist in csv file, the value will be zero
if column_name in row:
val = convert_val(row[column_name], dtype, self._meta.time_zone)
values[field_index] = val
if val is None:
has_invalid_column = True
break
# keep the start and end tick
if field == "timestamp":
if not self._is_starttime_changed:
self._is_starttime_changed = True
self._starttime = val
else:
self._starttime = min(self._starttime, val)
self._endtime = max(val, self._endtime)
field_index += 1
if not has_invalid_column:
# convert item into bytes buffer, and write to file
self._meta.item_to_bytes(values, buffer)
self._output_fp.write(buffer)
# update header fields for final update
self._item_count += 1
self._data_size += self._item_size | [
"def",
"_write_items",
"(",
"self",
",",
"reader",
":",
"DictReader",
")",
":",
"# columns need to convert",
"columns",
"=",
"self",
".",
"_meta",
".",
"columns",
"# values buffer from each row, used to pack into binary",
"values",
"=",
"[",
"0",
"]",
"*",
"len",
"(",
"columns",
".",
"keys",
"(",
")",
")",
"# item binary buffer",
"buffer",
"=",
"memoryview",
"(",
"bytearray",
"(",
"self",
".",
"_meta",
".",
"item_size",
")",
")",
"# field -> data type",
"field_type_dict",
"=",
"self",
".",
"_meta",
".",
"items",
"(",
")",
"# some column's value may cannot be parse, will skip it",
"has_invalid_column",
"=",
"False",
"for",
"row",
"in",
"reader",
":",
"field_index",
"=",
"0",
"has_invalid_column",
"=",
"False",
"# clear the values",
"for",
"j",
"in",
"range",
"(",
"len",
"(",
"values",
")",
")",
":",
"values",
"[",
"j",
"]",
"=",
"0",
"# read from current row",
"for",
"field",
",",
"dtype",
"in",
"field_type_dict",
".",
"items",
"(",
")",
":",
"column_name",
"=",
"columns",
"[",
"field",
"]",
"# NOTE: we allow field not exist in csv file, the value will be zero",
"if",
"column_name",
"in",
"row",
":",
"val",
"=",
"convert_val",
"(",
"row",
"[",
"column_name",
"]",
",",
"dtype",
",",
"self",
".",
"_meta",
".",
"time_zone",
")",
"values",
"[",
"field_index",
"]",
"=",
"val",
"if",
"val",
"is",
"None",
":",
"has_invalid_column",
"=",
"True",
"break",
"# keep the start and end tick",
"if",
"field",
"==",
"\"timestamp\"",
":",
"if",
"not",
"self",
".",
"_is_starttime_changed",
":",
"self",
".",
"_is_starttime_changed",
"=",
"True",
"self",
".",
"_starttime",
"=",
"val",
"else",
":",
"self",
".",
"_starttime",
"=",
"min",
"(",
"self",
".",
"_starttime",
",",
"val",
")",
"self",
".",
"_endtime",
"=",
"max",
"(",
"val",
",",
"self",
".",
"_endtime",
")",
"field_index",
"+=",
"1",
"if",
"not",
"has_invalid_column",
":",
"# convert item into bytes buffer, and write to file",
"self",
".",
"_meta",
".",
"item_to_bytes",
"(",
"values",
",",
"buffer",
")",
"self",
".",
"_output_fp",
".",
"write",
"(",
"buffer",
")",
"# update header fields for final update",
"self",
".",
"_item_count",
"+=",
"1",
"self",
".",
"_data_size",
"+=",
"self",
".",
"_item_size"
] | [
172,
4
] | [
225,
50
] | python | en | ['en', 'lt', 'en'] | True |
validate_mqtt_light | (value) | Validate MQTT light schema. | Validate MQTT light schema. | def validate_mqtt_light(value):
"""Validate MQTT light schema."""
schemas = {
"basic": PLATFORM_SCHEMA_BASIC,
"json": PLATFORM_SCHEMA_JSON,
"template": PLATFORM_SCHEMA_TEMPLATE,
}
return schemas[value[CONF_SCHEMA]](value) | [
"def",
"validate_mqtt_light",
"(",
"value",
")",
":",
"schemas",
"=",
"{",
"\"basic\"",
":",
"PLATFORM_SCHEMA_BASIC",
",",
"\"json\"",
":",
"PLATFORM_SCHEMA_JSON",
",",
"\"template\"",
":",
"PLATFORM_SCHEMA_TEMPLATE",
",",
"}",
"return",
"schemas",
"[",
"value",
"[",
"CONF_SCHEMA",
"]",
"]",
"(",
"value",
")"
] | [
24,
0
] | [
31,
45
] | python | de | ['de', 'de', 'it'] | True |
async_setup_platform | (
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
) | Set up MQTT light through configuration.yaml. | Set up MQTT light through configuration.yaml. | async def async_setup_platform(
hass: HomeAssistantType, config: ConfigType, async_add_entities, discovery_info=None
):
"""Set up MQTT light through configuration.yaml."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
await _async_setup_entity(hass, config, async_add_entities) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigType",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"await",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")"
] | [
39,
0
] | [
44,
63
] | python | en | ['en', 'zh', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up MQTT light dynamically through MQTT discovery. | Set up MQTT light dynamically through MQTT discovery. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up MQTT light dynamically through MQTT discovery."""
async def async_discover(discovery_payload):
"""Discover and add a MQTT light."""
discovery_data = discovery_payload.discovery_data
try:
config = PLATFORM_SCHEMA(discovery_payload)
await _async_setup_entity(
hass, config, async_add_entities, config_entry, discovery_data
)
except Exception:
clear_discovery_hash(hass, discovery_data[ATTR_DISCOVERY_HASH])
raise
async_dispatcher_connect(
hass, MQTT_DISCOVERY_NEW.format(light.DOMAIN, "mqtt"), async_discover
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"async",
"def",
"async_discover",
"(",
"discovery_payload",
")",
":",
"\"\"\"Discover and add a MQTT light.\"\"\"",
"discovery_data",
"=",
"discovery_payload",
".",
"discovery_data",
"try",
":",
"config",
"=",
"PLATFORM_SCHEMA",
"(",
"discovery_payload",
")",
"await",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"config_entry",
",",
"discovery_data",
")",
"except",
"Exception",
":",
"clear_discovery_hash",
"(",
"hass",
",",
"discovery_data",
"[",
"ATTR_DISCOVERY_HASH",
"]",
")",
"raise",
"async_dispatcher_connect",
"(",
"hass",
",",
"MQTT_DISCOVERY_NEW",
".",
"format",
"(",
"light",
".",
"DOMAIN",
",",
"\"mqtt\"",
")",
",",
"async_discover",
")"
] | [
47,
0
] | [
64,
5
] | python | en | ['en', 'lb', 'en'] | True |
_async_setup_entity | (
hass, config, async_add_entities, config_entry=None, discovery_data=None
) | Set up a MQTT Light. | Set up a MQTT Light. | async def _async_setup_entity(
hass, config, async_add_entities, config_entry=None, discovery_data=None
):
"""Set up a MQTT Light."""
setup_entity = {
"basic": async_setup_entity_basic,
"json": async_setup_entity_json,
"template": async_setup_entity_template,
}
await setup_entity[config[CONF_SCHEMA]](
hass, config, async_add_entities, config_entry, discovery_data
) | [
"async",
"def",
"_async_setup_entity",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"config_entry",
"=",
"None",
",",
"discovery_data",
"=",
"None",
")",
":",
"setup_entity",
"=",
"{",
"\"basic\"",
":",
"async_setup_entity_basic",
",",
"\"json\"",
":",
"async_setup_entity_json",
",",
"\"template\"",
":",
"async_setup_entity_template",
",",
"}",
"await",
"setup_entity",
"[",
"config",
"[",
"CONF_SCHEMA",
"]",
"]",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"config_entry",
",",
"discovery_data",
")"
] | [
67,
0
] | [
78,
5
] | python | en | ['en', 'lb', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up an OpenTherm Gateway climate entity. | Set up an OpenTherm Gateway climate entity. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up an OpenTherm Gateway climate entity."""
ents = []
ents.append(
OpenThermClimate(
hass.data[DATA_OPENTHERM_GW][DATA_GATEWAYS][config_entry.data[CONF_ID]],
config_entry.options,
)
)
async_add_entities(ents) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"ents",
"=",
"[",
"]",
"ents",
".",
"append",
"(",
"OpenThermClimate",
"(",
"hass",
".",
"data",
"[",
"DATA_OPENTHERM_GW",
"]",
"[",
"DATA_GATEWAYS",
"]",
"[",
"config_entry",
".",
"data",
"[",
"CONF_ID",
"]",
"]",
",",
"config_entry",
".",
"options",
",",
")",
")",
"async_add_entities",
"(",
"ents",
")"
] | [
39,
0
] | [
49,
28
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.__init__ | (self, gw_dev, options) | Initialize the device. | Initialize the device. | def __init__(self, gw_dev, options):
"""Initialize the device."""
self._gateway = gw_dev
self.entity_id = async_generate_entity_id(
ENTITY_ID_FORMAT, gw_dev.gw_id, hass=gw_dev.hass
)
self.friendly_name = gw_dev.name
self.floor_temp = options.get(CONF_FLOOR_TEMP, DEFAULT_FLOOR_TEMP)
self.temp_precision = options.get(CONF_PRECISION)
self._available = False
self._current_operation = None
self._current_temperature = None
self._hvac_mode = HVAC_MODE_HEAT
self._new_target_temperature = None
self._target_temperature = None
self._away_mode_a = None
self._away_mode_b = None
self._away_state_a = False
self._away_state_b = False
self._unsub_options = None
self._unsub_updates = None | [
"def",
"__init__",
"(",
"self",
",",
"gw_dev",
",",
"options",
")",
":",
"self",
".",
"_gateway",
"=",
"gw_dev",
"self",
".",
"entity_id",
"=",
"async_generate_entity_id",
"(",
"ENTITY_ID_FORMAT",
",",
"gw_dev",
".",
"gw_id",
",",
"hass",
"=",
"gw_dev",
".",
"hass",
")",
"self",
".",
"friendly_name",
"=",
"gw_dev",
".",
"name",
"self",
".",
"floor_temp",
"=",
"options",
".",
"get",
"(",
"CONF_FLOOR_TEMP",
",",
"DEFAULT_FLOOR_TEMP",
")",
"self",
".",
"temp_precision",
"=",
"options",
".",
"get",
"(",
"CONF_PRECISION",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"_current_operation",
"=",
"None",
"self",
".",
"_current_temperature",
"=",
"None",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_HEAT",
"self",
".",
"_new_target_temperature",
"=",
"None",
"self",
".",
"_target_temperature",
"=",
"None",
"self",
".",
"_away_mode_a",
"=",
"None",
"self",
".",
"_away_mode_b",
"=",
"None",
"self",
".",
"_away_state_a",
"=",
"False",
"self",
".",
"_away_state_b",
"=",
"False",
"self",
".",
"_unsub_options",
"=",
"None",
"self",
".",
"_unsub_updates",
"=",
"None"
] | [
55,
4
] | [
75,
34
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.