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 |
---|---|---|---|---|---|---|---|---|---|---|---|
CloudGoogleConfig.should_report_state | (self) | Return if states should be proactively reported. | Return if states should be proactively reported. | def should_report_state(self):
"""Return if states should be proactively reported."""
return self._cloud.is_logged_in and self._prefs.google_report_state | [
"def",
"should_report_state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_cloud",
".",
"is_logged_in",
"and",
"self",
".",
"_prefs",
".",
"google_report_state"
] | [
58,
4
] | [
60,
75
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.local_sdk_webhook_id | (self) | Return the local SDK webhook.
Return None to disable the local SDK.
| Return the local SDK webhook. | def local_sdk_webhook_id(self):
"""Return the local SDK webhook.
Return None to disable the local SDK.
"""
return self._prefs.google_local_webhook_id | [
"def",
"local_sdk_webhook_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_prefs",
".",
"google_local_webhook_id"
] | [
63,
4
] | [
68,
50
] | python | en | ['en', 'zh', 'en'] | True |
CloudGoogleConfig.local_sdk_user_id | (self) | Return the user ID to be used for actions received via the local SDK. | Return the user ID to be used for actions received via the local SDK. | def local_sdk_user_id(self):
"""Return the user ID to be used for actions received via the local SDK."""
return self._user | [
"def",
"local_sdk_user_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_user"
] | [
71,
4
] | [
73,
25
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.cloud_user | (self) | Return Cloud User account. | Return Cloud User account. | def cloud_user(self):
"""Return Cloud User account."""
return self._user | [
"def",
"cloud_user",
"(",
"self",
")",
":",
"return",
"self",
".",
"_user"
] | [
76,
4
] | [
78,
25
] | python | en | ['en', 'id', 'en'] | True |
CloudGoogleConfig.async_initialize | (self) | Perform async initialization of config. | Perform async initialization of config. | async def async_initialize(self):
"""Perform async initialization of config."""
await super().async_initialize()
# Remove bad data that was there until 0.103.6 - Jan 6, 2020
self._store.pop_agent_user_id(self._user)
self._prefs.async_listen_updates(self._async_prefs_updated)
self.hass.bus.async_listen(
entity_registry.EVENT_ENTITY_REGISTRY_UPDATED,
self._handle_entity_registry_updated,
) | [
"async",
"def",
"async_initialize",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_initialize",
"(",
")",
"# Remove bad data that was there until 0.103.6 - Jan 6, 2020",
"self",
".",
"_store",
".",
"pop_agent_user_id",
"(",
"self",
".",
"_user",
")",
"self",
".",
"_prefs",
".",
"async_listen_updates",
"(",
"self",
".",
"_async_prefs_updated",
")",
"self",
".",
"hass",
".",
"bus",
".",
"async_listen",
"(",
"entity_registry",
".",
"EVENT_ENTITY_REGISTRY_UPDATED",
",",
"self",
".",
"_handle_entity_registry_updated",
",",
")"
] | [
80,
4
] | [
91,
9
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.should_expose | (self, state) | If a state object should be exposed. | If a state object should be exposed. | def should_expose(self, state):
"""If a state object should be exposed."""
return self._should_expose_entity_id(state.entity_id) | [
"def",
"should_expose",
"(",
"self",
",",
"state",
")",
":",
"return",
"self",
".",
"_should_expose_entity_id",
"(",
"state",
".",
"entity_id",
")"
] | [
93,
4
] | [
95,
61
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig._should_expose_entity_id | (self, entity_id) | If an entity ID should be exposed. | If an entity ID should be exposed. | def _should_expose_entity_id(self, entity_id):
"""If an entity ID should be exposed."""
if entity_id in CLOUD_NEVER_EXPOSED_ENTITIES:
return False
if not self._config["filter"].empty_filter:
return self._config["filter"](entity_id)
entity_configs = self._prefs.google_entity_configs
entity_config = entity_configs.get(entity_id, {})
entity_expose = entity_config.get(PREF_SHOULD_EXPOSE)
if entity_expose is not None:
return entity_expose
default_expose = self._prefs.google_default_expose
# Backwards compat
if default_expose is None:
return True
return split_entity_id(entity_id)[0] in default_expose | [
"def",
"_should_expose_entity_id",
"(",
"self",
",",
"entity_id",
")",
":",
"if",
"entity_id",
"in",
"CLOUD_NEVER_EXPOSED_ENTITIES",
":",
"return",
"False",
"if",
"not",
"self",
".",
"_config",
"[",
"\"filter\"",
"]",
".",
"empty_filter",
":",
"return",
"self",
".",
"_config",
"[",
"\"filter\"",
"]",
"(",
"entity_id",
")",
"entity_configs",
"=",
"self",
".",
"_prefs",
".",
"google_entity_configs",
"entity_config",
"=",
"entity_configs",
".",
"get",
"(",
"entity_id",
",",
"{",
"}",
")",
"entity_expose",
"=",
"entity_config",
".",
"get",
"(",
"PREF_SHOULD_EXPOSE",
")",
"if",
"entity_expose",
"is",
"not",
"None",
":",
"return",
"entity_expose",
"default_expose",
"=",
"self",
".",
"_prefs",
".",
"google_default_expose",
"# Backwards compat",
"if",
"default_expose",
"is",
"None",
":",
"return",
"True",
"return",
"split_entity_id",
"(",
"entity_id",
")",
"[",
"0",
"]",
"in",
"default_expose"
] | [
97,
4
] | [
117,
62
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.agent_user_id | (self) | Return Agent User Id to use for query responses. | Return Agent User Id to use for query responses. | def agent_user_id(self):
"""Return Agent User Id to use for query responses."""
return self._cloud.username | [
"def",
"agent_user_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_cloud",
".",
"username"
] | [
120,
4
] | [
122,
35
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.get_agent_user_id | (self, context) | Get agent user ID making request. | Get agent user ID making request. | def get_agent_user_id(self, context):
"""Get agent user ID making request."""
return self.agent_user_id | [
"def",
"get_agent_user_id",
"(",
"self",
",",
"context",
")",
":",
"return",
"self",
".",
"agent_user_id"
] | [
124,
4
] | [
126,
33
] | python | en | ['fr', 'en', 'en'] | True |
CloudGoogleConfig.should_2fa | (self, state) | If an entity should be checked for 2FA. | If an entity should be checked for 2FA. | def should_2fa(self, state):
"""If an entity should be checked for 2FA."""
entity_configs = self._prefs.google_entity_configs
entity_config = entity_configs.get(state.entity_id, {})
return not entity_config.get(PREF_DISABLE_2FA, DEFAULT_DISABLE_2FA) | [
"def",
"should_2fa",
"(",
"self",
",",
"state",
")",
":",
"entity_configs",
"=",
"self",
".",
"_prefs",
".",
"google_entity_configs",
"entity_config",
"=",
"entity_configs",
".",
"get",
"(",
"state",
".",
"entity_id",
",",
"{",
"}",
")",
"return",
"not",
"entity_config",
".",
"get",
"(",
"PREF_DISABLE_2FA",
",",
"DEFAULT_DISABLE_2FA",
")"
] | [
128,
4
] | [
132,
75
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.async_report_state | (self, message, agent_user_id: str) | Send a state report to Google. | Send a state report to Google. | async def async_report_state(self, message, agent_user_id: str):
"""Send a state report to Google."""
try:
await self._cloud.google_report_state.async_send_message(message)
except ErrorResponse as err:
_LOGGER.warning("Error reporting state - %s: %s", err.code, err.message) | [
"async",
"def",
"async_report_state",
"(",
"self",
",",
"message",
",",
"agent_user_id",
":",
"str",
")",
":",
"try",
":",
"await",
"self",
".",
"_cloud",
".",
"google_report_state",
".",
"async_send_message",
"(",
"message",
")",
"except",
"ErrorResponse",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error reporting state - %s: %s\"",
",",
"err",
".",
"code",
",",
"err",
".",
"message",
")"
] | [
134,
4
] | [
139,
84
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig._async_request_sync_devices | (self, agent_user_id: str) | Trigger a sync with Google. | Trigger a sync with Google. | async def _async_request_sync_devices(self, agent_user_id: str):
"""Trigger a sync with Google."""
if self._sync_entities_lock.locked():
return HTTP_OK
async with self._sync_entities_lock:
resp = await cloud_api.async_google_actions_request_sync(self._cloud)
return resp.status | [
"async",
"def",
"_async_request_sync_devices",
"(",
"self",
",",
"agent_user_id",
":",
"str",
")",
":",
"if",
"self",
".",
"_sync_entities_lock",
".",
"locked",
"(",
")",
":",
"return",
"HTTP_OK",
"async",
"with",
"self",
".",
"_sync_entities_lock",
":",
"resp",
"=",
"await",
"cloud_api",
".",
"async_google_actions_request_sync",
"(",
"self",
".",
"_cloud",
")",
"return",
"resp",
".",
"status"
] | [
141,
4
] | [
148,
30
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig._async_prefs_updated | (self, prefs) | Handle updated preferences. | Handle updated preferences. | async def _async_prefs_updated(self, prefs):
"""Handle updated preferences."""
if self.should_report_state != self.is_reporting_state:
if self.should_report_state:
self.async_enable_report_state()
else:
self.async_disable_report_state()
# State reporting is reported as a property on entities.
# So when we change it, we need to sync all entities.
await self.async_sync_entities_all()
# If entity prefs are the same or we have filter in config.yaml,
# don't sync.
elif (
self._cur_entity_prefs is not prefs.google_entity_configs
or self._cur_default_expose is not prefs.google_default_expose
) and self._config["filter"].empty_filter:
self.async_schedule_google_sync_all()
if self.enabled and not self.is_local_sdk_active:
self.async_enable_local_sdk()
elif not self.enabled and self.is_local_sdk_active:
self.async_disable_local_sdk()
self._cur_entity_prefs = prefs.google_entity_configs
self._cur_default_expose = prefs.google_default_expose | [
"async",
"def",
"_async_prefs_updated",
"(",
"self",
",",
"prefs",
")",
":",
"if",
"self",
".",
"should_report_state",
"!=",
"self",
".",
"is_reporting_state",
":",
"if",
"self",
".",
"should_report_state",
":",
"self",
".",
"async_enable_report_state",
"(",
")",
"else",
":",
"self",
".",
"async_disable_report_state",
"(",
")",
"# State reporting is reported as a property on entities.",
"# So when we change it, we need to sync all entities.",
"await",
"self",
".",
"async_sync_entities_all",
"(",
")",
"# If entity prefs are the same or we have filter in config.yaml,",
"# don't sync.",
"elif",
"(",
"self",
".",
"_cur_entity_prefs",
"is",
"not",
"prefs",
".",
"google_entity_configs",
"or",
"self",
".",
"_cur_default_expose",
"is",
"not",
"prefs",
".",
"google_default_expose",
")",
"and",
"self",
".",
"_config",
"[",
"\"filter\"",
"]",
".",
"empty_filter",
":",
"self",
".",
"async_schedule_google_sync_all",
"(",
")",
"if",
"self",
".",
"enabled",
"and",
"not",
"self",
".",
"is_local_sdk_active",
":",
"self",
".",
"async_enable_local_sdk",
"(",
")",
"elif",
"not",
"self",
".",
"enabled",
"and",
"self",
".",
"is_local_sdk_active",
":",
"self",
".",
"async_disable_local_sdk",
"(",
")",
"self",
".",
"_cur_entity_prefs",
"=",
"prefs",
".",
"google_entity_configs",
"self",
".",
"_cur_default_expose",
"=",
"prefs",
".",
"google_default_expose"
] | [
150,
4
] | [
176,
62
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig._handle_entity_registry_updated | (self, event) | Handle when entity registry updated. | Handle when entity registry updated. | async def _handle_entity_registry_updated(self, event):
"""Handle when entity registry updated."""
if not self.enabled or not self._cloud.is_logged_in:
return
# Only consider entity registry updates if info relevant for Google has changed
if event.data["action"] == "update" and not bool(
set(event.data["changes"]) & entity_registry.ENTITY_DESCRIBING_ATTRIBUTES
):
return
entity_id = event.data["entity_id"]
if not self._should_expose_entity_id(entity_id):
return
if self.hass.state == CoreState.running:
self.async_schedule_google_sync_all()
return
if self._sync_on_started:
return
self._sync_on_started = True
async def sync_google(_):
"""Sync entities to Google."""
await self.async_sync_entities_all()
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, sync_google) | [
"async",
"def",
"_handle_entity_registry_updated",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"enabled",
"or",
"not",
"self",
".",
"_cloud",
".",
"is_logged_in",
":",
"return",
"# Only consider entity registry updates if info relevant for Google has changed",
"if",
"event",
".",
"data",
"[",
"\"action\"",
"]",
"==",
"\"update\"",
"and",
"not",
"bool",
"(",
"set",
"(",
"event",
".",
"data",
"[",
"\"changes\"",
"]",
")",
"&",
"entity_registry",
".",
"ENTITY_DESCRIBING_ATTRIBUTES",
")",
":",
"return",
"entity_id",
"=",
"event",
".",
"data",
"[",
"\"entity_id\"",
"]",
"if",
"not",
"self",
".",
"_should_expose_entity_id",
"(",
"entity_id",
")",
":",
"return",
"if",
"self",
".",
"hass",
".",
"state",
"==",
"CoreState",
".",
"running",
":",
"self",
".",
"async_schedule_google_sync_all",
"(",
")",
"return",
"if",
"self",
".",
"_sync_on_started",
":",
"return",
"self",
".",
"_sync_on_started",
"=",
"True",
"async",
"def",
"sync_google",
"(",
"_",
")",
":",
"\"\"\"Sync entities to Google.\"\"\"",
"await",
"self",
".",
"async_sync_entities_all",
"(",
")",
"self",
".",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STARTED",
",",
"sync_google",
")"
] | [
178,
4
] | [
207,
81
] | python | en | ['en', 'en', 'en'] | True |
MatrixAttributeAccessor.columns | (self) | int: Column number. | int: Column number. | def columns(self) -> int:
"""int: Column number."""
return self._col_num | [
"def",
"columns",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_col_num"
] | [
24,
4
] | [
26,
28
] | python | en | ['en', 'lb', 'en'] | True |
MatrixAttributeAccessor.rows | (self) | int: Row number. | int: Row number. | def rows(self) -> int:
"""int: Row number."""
return self._row_num | [
"def",
"rows",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_row_num"
] | [
29,
4
] | [
31,
28
] | python | en | ['en', 'en', 'en'] | True |
MatrixAttributeAccessor._ensure_attr | (self) | Ensure that the attribute instance correct | Ensure that the attribute instance correct | def _ensure_attr(self):
"""Ensure that the attribute instance correct"""
if self._attr is None:
self._attr = getattr(self._node, self._attr_name, None)
assert self._attr is not None | [
"def",
"_ensure_attr",
"(",
"self",
")",
":",
"if",
"self",
".",
"_attr",
"is",
"None",
":",
"self",
".",
"_attr",
"=",
"getattr",
"(",
"self",
".",
"_node",
",",
"self",
".",
"_attr_name",
",",
"None",
")",
"assert",
"self",
".",
"_attr",
"is",
"not",
"None"
] | [
33,
4
] | [
38,
37
] | python | en | ['en', 'en', 'en'] | True |
MatrixAttributeAccessor.get_row | (self, row_idx: int) | Get values of a row.
Args:
row_idx (int): Index of target row.
Returns:
list: List of value for that row.
| Get values of a row. | def get_row(self, row_idx: int) -> list:
"""Get values of a row.
Args:
row_idx (int): Index of target row.
Returns:
list: List of value for that row.
"""
self._ensure_attr()
start = self._col_num * row_idx
return self._attr[start: start + self._col_num] | [
"def",
"get_row",
"(",
"self",
",",
"row_idx",
":",
"int",
")",
"->",
"list",
":",
"self",
".",
"_ensure_attr",
"(",
")",
"start",
"=",
"self",
".",
"_col_num",
"*",
"row_idx",
"return",
"self",
".",
"_attr",
"[",
"start",
":",
"start",
"+",
"self",
".",
"_col_num",
"]"
] | [
67,
4
] | [
79,
55
] | python | en | ['en', 'en', 'en'] | True |
MatrixAttributeAccessor.get_column | (self, column_idx: int) | Get values of a column.
Args:
column_idx (int): Index of target column.
Returns:
list: List of value for that column.
| Get values of a column. | def get_column(self, column_idx: int):
"""Get values of a column.
Args:
column_idx (int): Index of target column.
Returns:
list: List of value for that column.
"""
self._ensure_attr()
row_indices = [r * self._col_num + column_idx for r in range(self._row_num)]
return self._attr[row_indices] | [
"def",
"get_column",
"(",
"self",
",",
"column_idx",
":",
"int",
")",
":",
"self",
".",
"_ensure_attr",
"(",
")",
"row_indices",
"=",
"[",
"r",
"*",
"self",
".",
"_col_num",
"+",
"column_idx",
"for",
"r",
"in",
"range",
"(",
"self",
".",
"_row_num",
")",
"]",
"return",
"self",
".",
"_attr",
"[",
"row_indices",
"]"
] | [
81,
4
] | [
94,
38
] | python | en | ['en', 'ca', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up LW-12 WiFi LED Controller platform. | Set up LW-12 WiFi LED Controller platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up LW-12 WiFi LED Controller platform."""
# Assign configuration variables.
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
# Add devices
lw12_light = lw12.LW12Controller(host, port)
add_entities([LW12WiFi(name, lw12_light)]) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"# Assign configuration variables.",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"port",
"=",
"config",
".",
"get",
"(",
"CONF_PORT",
")",
"# Add devices",
"lw12_light",
"=",
"lw12",
".",
"LW12Controller",
"(",
"host",
",",
"port",
")",
"add_entities",
"(",
"[",
"LW12WiFi",
"(",
"name",
",",
"lw12_light",
")",
"]",
")"
] | [
38,
0
] | [
46,
46
] | python | en | ['en', 'da', 'en'] | True |
LW12WiFi.__init__ | (self, name, lw12_light) | Initialise LW-12 WiFi LED Controller.
:param name: Friendly name for this platform to use.
:param lw12_light: Instance of the LW12 controller.
| Initialise LW-12 WiFi LED Controller. | def __init__(self, name, lw12_light):
"""Initialise LW-12 WiFi LED Controller.
:param name: Friendly name for this platform to use.
:param lw12_light: Instance of the LW12 controller.
"""
self._light = lw12_light
self._name = name
self._state = None
self._effect = None
self._rgb_color = [255, 255, 255]
self._brightness = 255
# Setup feature list
self._supported_features = (
SUPPORT_BRIGHTNESS | SUPPORT_EFFECT | SUPPORT_COLOR | SUPPORT_TRANSITION
) | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"lw12_light",
")",
":",
"self",
".",
"_light",
"=",
"lw12_light",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_effect",
"=",
"None",
"self",
".",
"_rgb_color",
"=",
"[",
"255",
",",
"255",
",",
"255",
"]",
"self",
".",
"_brightness",
"=",
"255",
"# Setup feature list",
"self",
".",
"_supported_features",
"=",
"(",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_EFFECT",
"|",
"SUPPORT_COLOR",
"|",
"SUPPORT_TRANSITION",
")"
] | [
52,
4
] | [
67,
9
] | python | en | ['et', 'en', 'it'] | False |
LW12WiFi.name | (self) | Return the display name of the controlled light. | Return the display name of the controlled light. | def name(self):
"""Return the display name of the controlled light."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
70,
4
] | [
72,
25
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.brightness | (self) | Return the brightness of the light. | Return the brightness of the light. | def brightness(self):
"""Return the brightness of the light."""
return self._brightness | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"self",
".",
"_brightness"
] | [
75,
4
] | [
77,
31
] | python | en | ['en', 'no', 'en'] | True |
LW12WiFi.hs_color | (self) | Read back the hue-saturation of the light. | Read back the hue-saturation of the light. | def hs_color(self):
"""Read back the hue-saturation of the light."""
return color_util.color_RGB_to_hs(*self._rgb_color) | [
"def",
"hs_color",
"(",
"self",
")",
":",
"return",
"color_util",
".",
"color_RGB_to_hs",
"(",
"*",
"self",
".",
"_rgb_color",
")"
] | [
80,
4
] | [
82,
59
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.effect | (self) | Return current light effect. | Return current light effect. | def effect(self):
"""Return current light effect."""
if self._effect is None:
return None
return self._effect.replace("_", " ").title() | [
"def",
"effect",
"(",
"self",
")",
":",
"if",
"self",
".",
"_effect",
"is",
"None",
":",
"return",
"None",
"return",
"self",
".",
"_effect",
".",
"replace",
"(",
"\"_\"",
",",
"\" \"",
")",
".",
"title",
"(",
")"
] | [
85,
4
] | [
89,
53
] | python | da | ['fr', 'da', 'en'] | False |
LW12WiFi.is_on | (self) | Return true if light is on. | Return true if light is on. | def is_on(self):
"""Return true if light is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
92,
4
] | [
94,
26
] | python | en | ['en', 'et', 'en'] | True |
LW12WiFi.supported_features | (self) | Return a list of supported features. | Return a list of supported features. | def supported_features(self):
"""Return a list of supported features."""
return self._supported_features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"self",
".",
"_supported_features"
] | [
97,
4
] | [
99,
39
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.effect_list | (self) | Return a list of available effects.
Use the Enum element name for display.
| Return a list of available effects. | def effect_list(self):
"""Return a list of available effects.
Use the Enum element name for display.
"""
return [effect.name.replace("_", " ").title() for effect in lw12.LW12_EFFECT] | [
"def",
"effect_list",
"(",
"self",
")",
":",
"return",
"[",
"effect",
".",
"name",
".",
"replace",
"(",
"\"_\"",
",",
"\" \"",
")",
".",
"title",
"(",
")",
"for",
"effect",
"in",
"lw12",
".",
"LW12_EFFECT",
"]"
] | [
102,
4
] | [
107,
85
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.assumed_state | (self) | Return True if unable to access real state of the entity. | Return True if unable to access real state of the entity. | def assumed_state(self) -> bool:
"""Return True if unable to access real state of the entity."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"True"
] | [
110,
4
] | [
112,
19
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.should_poll | (self) | Return False to not poll the state of this entity. | Return False to not poll the state of this entity. | def should_poll(self) -> bool:
"""Return False to not poll the state of this entity."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"False"
] | [
115,
4
] | [
117,
20
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.turn_on | (self, **kwargs) | Instruct the light to turn on. | Instruct the light to turn on. | def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
self._light.light_on()
if ATTR_HS_COLOR in kwargs:
self._rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])
self._light.set_color(*self._rgb_color)
self._effect = None
if ATTR_BRIGHTNESS in kwargs:
self._brightness = kwargs.get(ATTR_BRIGHTNESS)
brightness = int(self._brightness / 255 * 100)
self._light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, brightness)
if ATTR_EFFECT in kwargs:
self._effect = kwargs[ATTR_EFFECT].replace(" ", "_").upper()
# Check if a known and supported effect was selected.
if self._effect in [eff.name for eff in lw12.LW12_EFFECT]:
# Selected effect is supported and will be applied.
self._light.set_effect(lw12.LW12_EFFECT[self._effect])
else:
# Unknown effect was set, recover by disabling the effect
# mode and log an error.
_LOGGER.error("Unknown effect selected: %s", self._effect)
self._effect = None
if ATTR_TRANSITION in kwargs:
transition_speed = int(kwargs[ATTR_TRANSITION])
self._light.set_light_option(lw12.LW12_LIGHT.FLASH, transition_speed)
self._state = True | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_light",
".",
"light_on",
"(",
")",
"if",
"ATTR_HS_COLOR",
"in",
"kwargs",
":",
"self",
".",
"_rgb_color",
"=",
"color_util",
".",
"color_hs_to_RGB",
"(",
"*",
"kwargs",
"[",
"ATTR_HS_COLOR",
"]",
")",
"self",
".",
"_light",
".",
"set_color",
"(",
"*",
"self",
".",
"_rgb_color",
")",
"self",
".",
"_effect",
"=",
"None",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"self",
".",
"_brightness",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_BRIGHTNESS",
")",
"brightness",
"=",
"int",
"(",
"self",
".",
"_brightness",
"/",
"255",
"*",
"100",
")",
"self",
".",
"_light",
".",
"set_light_option",
"(",
"lw12",
".",
"LW12_LIGHT",
".",
"BRIGHTNESS",
",",
"brightness",
")",
"if",
"ATTR_EFFECT",
"in",
"kwargs",
":",
"self",
".",
"_effect",
"=",
"kwargs",
"[",
"ATTR_EFFECT",
"]",
".",
"replace",
"(",
"\" \"",
",",
"\"_\"",
")",
".",
"upper",
"(",
")",
"# Check if a known and supported effect was selected.",
"if",
"self",
".",
"_effect",
"in",
"[",
"eff",
".",
"name",
"for",
"eff",
"in",
"lw12",
".",
"LW12_EFFECT",
"]",
":",
"# Selected effect is supported and will be applied.",
"self",
".",
"_light",
".",
"set_effect",
"(",
"lw12",
".",
"LW12_EFFECT",
"[",
"self",
".",
"_effect",
"]",
")",
"else",
":",
"# Unknown effect was set, recover by disabling the effect",
"# mode and log an error.",
"_LOGGER",
".",
"error",
"(",
"\"Unknown effect selected: %s\"",
",",
"self",
".",
"_effect",
")",
"self",
".",
"_effect",
"=",
"None",
"if",
"ATTR_TRANSITION",
"in",
"kwargs",
":",
"transition_speed",
"=",
"int",
"(",
"kwargs",
"[",
"ATTR_TRANSITION",
"]",
")",
"self",
".",
"_light",
".",
"set_light_option",
"(",
"lw12",
".",
"LW12_LIGHT",
".",
"FLASH",
",",
"transition_speed",
")",
"self",
".",
"_state",
"=",
"True"
] | [
119,
4
] | [
144,
26
] | python | en | ['en', 'en', 'en'] | True |
LW12WiFi.turn_off | (self, **kwargs) | Instruct the light to turn off. | Instruct the light to turn off. | def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._light.light_off()
self._state = False | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_light",
".",
"light_off",
"(",
")",
"self",
".",
"_state",
"=",
"False"
] | [
146,
4
] | [
149,
27
] | python | en | ['en', 'en', 'en'] | True |
test_get_jwt | (hass) | Test signing of key. | Test signing of key. | async def test_get_jwt(hass):
"""Test signing of key."""
jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJkdW1teUBkdW1teS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9ob21lZ3JhcGgiLCJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvdG9rZW4iLCJpYXQiOjE1NzEwMTEyMDAsImV4cCI6MTU3MTAxNDgwMH0.gG06SmY-zSvFwSrdFfqIdC6AnC22rwz-d2F2UDeWbywjdmFL_1zceL-OOLBwjD8MJr6nR0kmN_Osu7ml9-EzzZjJqsRUxMjGn2G8nSYHbv16R4FYIp62Ibvt6Jj_wdFobEPoy_5OJ28P5Hdu0giGMlFBJMy0Tc6MgEDZA-cwOBw"
res = _get_homegraph_jwt(
datetime(2019, 10, 14, tzinfo=timezone.utc),
DUMMY_CONFIG["service_account"]["client_email"],
DUMMY_CONFIG["service_account"]["private_key"],
)
assert res == jwt | [
"async",
"def",
"test_get_jwt",
"(",
"hass",
")",
":",
"jwt",
"=",
"\"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJkdW1teUBkdW1teS5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbSIsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9ob21lZ3JhcGgiLCJhdWQiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20vby9vYXV0aDIvdG9rZW4iLCJpYXQiOjE1NzEwMTEyMDAsImV4cCI6MTU3MTAxNDgwMH0.gG06SmY-zSvFwSrdFfqIdC6AnC22rwz-d2F2UDeWbywjdmFL_1zceL-OOLBwjD8MJr6nR0kmN_Osu7ml9-EzzZjJqsRUxMjGn2G8nSYHbv16R4FYIp62Ibvt6Jj_wdFobEPoy_5OJ28P5Hdu0giGMlFBJMy0Tc6MgEDZA-cwOBw\"",
"res",
"=",
"_get_homegraph_jwt",
"(",
"datetime",
"(",
"2019",
",",
"10",
",",
"14",
",",
"tzinfo",
"=",
"timezone",
".",
"utc",
")",
",",
"DUMMY_CONFIG",
"[",
"\"service_account\"",
"]",
"[",
"\"client_email\"",
"]",
",",
"DUMMY_CONFIG",
"[",
"\"service_account\"",
"]",
"[",
"\"private_key\"",
"]",
",",
")",
"assert",
"res",
"==",
"jwt"
] | [
34,
0
] | [
43,
21
] | python | en | ['en', 'zu', 'en'] | True |
test_get_access_token | (hass, aioclient_mock) | Test the function to get access token. | Test the function to get access token. | async def test_get_access_token(hass, aioclient_mock):
"""Test the function to get access token."""
jwt = "dummyjwt"
aioclient_mock.post(
HOMEGRAPH_TOKEN_URL,
status=200,
json={"access_token": "1234", "expires_in": 3600},
)
await _get_homegraph_token(hass, jwt)
assert aioclient_mock.call_count == 1
assert aioclient_mock.mock_calls[0][3] == {
"Authorization": f"Bearer {jwt}",
"Content-Type": "application/x-www-form-urlencoded",
} | [
"async",
"def",
"test_get_access_token",
"(",
"hass",
",",
"aioclient_mock",
")",
":",
"jwt",
"=",
"\"dummyjwt\"",
"aioclient_mock",
".",
"post",
"(",
"HOMEGRAPH_TOKEN_URL",
",",
"status",
"=",
"200",
",",
"json",
"=",
"{",
"\"access_token\"",
":",
"\"1234\"",
",",
"\"expires_in\"",
":",
"3600",
"}",
",",
")",
"await",
"_get_homegraph_token",
"(",
"hass",
",",
"jwt",
")",
"assert",
"aioclient_mock",
".",
"call_count",
"==",
"1",
"assert",
"aioclient_mock",
".",
"mock_calls",
"[",
"0",
"]",
"[",
"3",
"]",
"==",
"{",
"\"Authorization\"",
":",
"f\"Bearer {jwt}\"",
",",
"\"Content-Type\"",
":",
"\"application/x-www-form-urlencoded\"",
",",
"}"
] | [
46,
0
] | [
61,
5
] | python | en | ['en', 'en', 'en'] | True |
test_update_access_token | (hass) | Test the function to update access token when expired. | Test the function to update access token when expired. | async def test_update_access_token(hass):
"""Test the function to update access token when expired."""
jwt = "dummyjwt"
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
base_time = datetime(2019, 10, 14, tzinfo=timezone.utc)
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token, patch(
"homeassistant.components.google_assistant.http._get_homegraph_jwt"
) as mock_get_jwt, patch(
"homeassistant.core.dt_util.utcnow"
) as mock_utcnow:
mock_utcnow.return_value = base_time
mock_get_jwt.return_value = jwt
mock_get_token.return_value = MOCK_TOKEN
await config._async_update_token()
mock_get_token.assert_called_once()
mock_get_token.reset_mock()
mock_utcnow.return_value = base_time + timedelta(seconds=3600)
await config._async_update_token()
mock_get_token.assert_not_called()
mock_get_token.reset_mock()
mock_utcnow.return_value = base_time + timedelta(seconds=3601)
await config._async_update_token()
mock_get_token.assert_called_once() | [
"async",
"def",
"test_update_access_token",
"(",
"hass",
")",
":",
"jwt",
"=",
"\"dummyjwt\"",
"config",
"=",
"GoogleConfig",
"(",
"hass",
",",
"DUMMY_CONFIG",
")",
"await",
"config",
".",
"async_initialize",
"(",
")",
"base_time",
"=",
"datetime",
"(",
"2019",
",",
"10",
",",
"14",
",",
"tzinfo",
"=",
"timezone",
".",
"utc",
")",
"with",
"patch",
"(",
"\"homeassistant.components.google_assistant.http._get_homegraph_token\"",
")",
"as",
"mock_get_token",
",",
"patch",
"(",
"\"homeassistant.components.google_assistant.http._get_homegraph_jwt\"",
")",
"as",
"mock_get_jwt",
",",
"patch",
"(",
"\"homeassistant.core.dt_util.utcnow\"",
")",
"as",
"mock_utcnow",
":",
"mock_utcnow",
".",
"return_value",
"=",
"base_time",
"mock_get_jwt",
".",
"return_value",
"=",
"jwt",
"mock_get_token",
".",
"return_value",
"=",
"MOCK_TOKEN",
"await",
"config",
".",
"_async_update_token",
"(",
")",
"mock_get_token",
".",
"assert_called_once",
"(",
")",
"mock_get_token",
".",
"reset_mock",
"(",
")",
"mock_utcnow",
".",
"return_value",
"=",
"base_time",
"+",
"timedelta",
"(",
"seconds",
"=",
"3600",
")",
"await",
"config",
".",
"_async_update_token",
"(",
")",
"mock_get_token",
".",
"assert_not_called",
"(",
")",
"mock_get_token",
".",
"reset_mock",
"(",
")",
"mock_utcnow",
".",
"return_value",
"=",
"base_time",
"+",
"timedelta",
"(",
"seconds",
"=",
"3601",
")",
"await",
"config",
".",
"_async_update_token",
"(",
")",
"mock_get_token",
".",
"assert_called_once",
"(",
")"
] | [
64,
0
] | [
96,
43
] | python | en | ['en', 'en', 'en'] | True |
test_call_homegraph_api | (hass, aioclient_mock, hass_storage) | Test the function to call the homegraph api. | Test the function to call the homegraph api. | async def test_call_homegraph_api(hass, aioclient_mock, hass_storage):
"""Test the function to call the homegraph api."""
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token:
mock_get_token.return_value = MOCK_TOKEN
aioclient_mock.post(MOCK_URL, status=200, json={})
res = await config.async_call_homegraph_api(MOCK_URL, MOCK_JSON)
assert res == 200
assert mock_get_token.call_count == 1
assert aioclient_mock.call_count == 1
call = aioclient_mock.mock_calls[0]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER | [
"async",
"def",
"test_call_homegraph_api",
"(",
"hass",
",",
"aioclient_mock",
",",
"hass_storage",
")",
":",
"config",
"=",
"GoogleConfig",
"(",
"hass",
",",
"DUMMY_CONFIG",
")",
"await",
"config",
".",
"async_initialize",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.google_assistant.http._get_homegraph_token\"",
")",
"as",
"mock_get_token",
":",
"mock_get_token",
".",
"return_value",
"=",
"MOCK_TOKEN",
"aioclient_mock",
".",
"post",
"(",
"MOCK_URL",
",",
"status",
"=",
"200",
",",
"json",
"=",
"{",
"}",
")",
"res",
"=",
"await",
"config",
".",
"async_call_homegraph_api",
"(",
"MOCK_URL",
",",
"MOCK_JSON",
")",
"assert",
"res",
"==",
"200",
"assert",
"mock_get_token",
".",
"call_count",
"==",
"1",
"assert",
"aioclient_mock",
".",
"call_count",
"==",
"1",
"call",
"=",
"aioclient_mock",
".",
"mock_calls",
"[",
"0",
"]",
"assert",
"call",
"[",
"2",
"]",
"==",
"MOCK_JSON",
"assert",
"call",
"[",
"3",
"]",
"==",
"MOCK_HEADER"
] | [
99,
0
] | [
119,
37
] | python | en | ['en', 'en', 'en'] | True |
test_call_homegraph_api_retry | (hass, aioclient_mock, hass_storage) | Test the that the calls get retried with new token on 401. | Test the that the calls get retried with new token on 401. | async def test_call_homegraph_api_retry(hass, aioclient_mock, hass_storage):
"""Test the that the calls get retried with new token on 401."""
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
with patch(
"homeassistant.components.google_assistant.http._get_homegraph_token"
) as mock_get_token:
mock_get_token.return_value = MOCK_TOKEN
aioclient_mock.post(MOCK_URL, status=401, json={})
await config.async_call_homegraph_api(MOCK_URL, MOCK_JSON)
assert mock_get_token.call_count == 2
assert aioclient_mock.call_count == 2
call = aioclient_mock.mock_calls[0]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER
call = aioclient_mock.mock_calls[1]
assert call[2] == MOCK_JSON
assert call[3] == MOCK_HEADER | [
"async",
"def",
"test_call_homegraph_api_retry",
"(",
"hass",
",",
"aioclient_mock",
",",
"hass_storage",
")",
":",
"config",
"=",
"GoogleConfig",
"(",
"hass",
",",
"DUMMY_CONFIG",
")",
"await",
"config",
".",
"async_initialize",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.google_assistant.http._get_homegraph_token\"",
")",
"as",
"mock_get_token",
":",
"mock_get_token",
".",
"return_value",
"=",
"MOCK_TOKEN",
"aioclient_mock",
".",
"post",
"(",
"MOCK_URL",
",",
"status",
"=",
"401",
",",
"json",
"=",
"{",
"}",
")",
"await",
"config",
".",
"async_call_homegraph_api",
"(",
"MOCK_URL",
",",
"MOCK_JSON",
")",
"assert",
"mock_get_token",
".",
"call_count",
"==",
"2",
"assert",
"aioclient_mock",
".",
"call_count",
"==",
"2",
"call",
"=",
"aioclient_mock",
".",
"mock_calls",
"[",
"0",
"]",
"assert",
"call",
"[",
"2",
"]",
"==",
"MOCK_JSON",
"assert",
"call",
"[",
"3",
"]",
"==",
"MOCK_HEADER",
"call",
"=",
"aioclient_mock",
".",
"mock_calls",
"[",
"1",
"]",
"assert",
"call",
"[",
"2",
"]",
"==",
"MOCK_JSON",
"assert",
"call",
"[",
"3",
"]",
"==",
"MOCK_HEADER"
] | [
122,
0
] | [
144,
37
] | python | en | ['en', 'en', 'en'] | True |
test_report_state | (hass, aioclient_mock, hass_storage) | Test the report state function. | Test the report state function. | async def test_report_state(hass, aioclient_mock, hass_storage):
"""Test the report state function."""
agent_user_id = "user"
config = GoogleConfig(hass, DUMMY_CONFIG)
await config.async_initialize()
await config.async_connect_agent_user(agent_user_id)
message = {"devices": {}}
with patch.object(config, "async_call_homegraph_api") as mock_call:
await config.async_report_state(message, agent_user_id)
mock_call.assert_called_once_with(
REPORT_STATE_BASE_URL,
{"requestId": ANY, "agentUserId": agent_user_id, "payload": message},
) | [
"async",
"def",
"test_report_state",
"(",
"hass",
",",
"aioclient_mock",
",",
"hass_storage",
")",
":",
"agent_user_id",
"=",
"\"user\"",
"config",
"=",
"GoogleConfig",
"(",
"hass",
",",
"DUMMY_CONFIG",
")",
"await",
"config",
".",
"async_initialize",
"(",
")",
"await",
"config",
".",
"async_connect_agent_user",
"(",
"agent_user_id",
")",
"message",
"=",
"{",
"\"devices\"",
":",
"{",
"}",
"}",
"with",
"patch",
".",
"object",
"(",
"config",
",",
"\"async_call_homegraph_api\"",
")",
"as",
"mock_call",
":",
"await",
"config",
".",
"async_report_state",
"(",
"message",
",",
"agent_user_id",
")",
"mock_call",
".",
"assert_called_once_with",
"(",
"REPORT_STATE_BASE_URL",
",",
"{",
"\"requestId\"",
":",
"ANY",
",",
"\"agentUserId\"",
":",
"agent_user_id",
",",
"\"payload\"",
":",
"message",
"}",
",",
")"
] | [
147,
0
] | [
161,
9
] | python | en | ['en', 'en', 'en'] | True |
is_command_yes | (cmd: str) | Check if user agree with current command.
Args:
cmd (str): Command input value.
Returns:
bool: True if command value is match "yes" or "y" (case insensitive.).
| Check if user agree with current command. | def is_command_yes(cmd: str):
"""Check if user agree with current command.
Args:
cmd (str): Command input value.
Returns:
bool: True if command value is match "yes" or "y" (case insensitive.).
"""
lower_cmd = cmd.lower()
return lower_cmd == "yes" or lower_cmd == "y" | [
"def",
"is_command_yes",
"(",
"cmd",
":",
"str",
")",
":",
"lower_cmd",
"=",
"cmd",
".",
"lower",
"(",
")",
"return",
"lower_cmd",
"==",
"\"yes\"",
"or",
"lower_cmd",
"==",
"\"y\""
] | [
44,
0
] | [
55,
49
] | python | en | ['en', 'en', 'en'] | True |
new_project | (**kwargs: dict) | Create a new project. | Create a new project. | def new_project(**kwargs: dict):
"""Create a new project."""
use_builtin_scenario = is_command_yes(prompt("Use built-in scenario?", default="yes"))
if use_builtin_scenario:
generate_function = new_project_with_builtin_scenario
# Build built-in scenario completer.
builtin_scenarios = get_scenarios()
# Validator for scenario name to make sure input is a built-in scenario.
class BuiltInScenarioValidator(Validator):
"""Validate is input scenario is built-in one."""
def validate(self, document):
if document.text not in builtin_scenarios:
raise ValidationError(message="Scenario name not a built-in one.")
builtin_scenario_completer = WordCompleter(builtin_scenarios)
# Select a scenario.
scenario_name = prompt(
"Scenario name:",
default=builtin_scenarios[0],
completer=builtin_scenario_completer,
complete_while_typing=True,
validate_while_typing=True,
validator=BuiltInScenarioValidator()
)
use_builtin_topology = is_command_yes(prompt(
"Use built-in topology (configuration)?",
default="yes"
))
if use_builtin_topology:
# Build topology completer for topology selecting.
builtin_topologies = get_topologies(scenario_name)
builtin_topologies_completer = WordCompleter(builtin_topologies)
class BuiltinTopologyValidator(Validator):
"""Validate if input topology is built-in one."""
def validate(self, document):
if document.text not in builtin_topologies:
raise ValidationError(message="Topology not exist.")
topology_name = prompt(
"Topology name to use:",
default=builtin_topologies[0],
completer=builtin_topologies_completer,
validator=BuiltinTopologyValidator(),
validate_while_typing=True,
complete_while_typing=True
)
else:
topology_name = prompt(
"Topology name to create (content is copied from built-in topology.):",
validator=NonEmptyStringValidator("Topology name cannot be empty."),
validate_while_typing=True
)
else:
use_builtin_topology = False
generate_function = new_project_from_scratch
scenario_name = os.path.basename(os.getcwd())
scenario_name = prompt(
"New scenario name:",
default=scenario_name,
validator=NonEmptyStringValidator("Scenario name cannot be empty.")
)
topology_name = prompt(
"New topology name:",
default=scenario_name,
validator=NonEmptyStringValidator("Topology name cannot be empty.")
)
# Misc settings.
durations = prompt(
"Durations to emulate:",
default="100",
validator=PositiveNumberValidator(),
validate_while_typing=True
)
episodes = prompt(
"Number of episodes to emulate:",
default="10",
validator=PositiveNumberValidator(),
validate_while_typing=True
)
options = \
{
"use_builtin_scenario": use_builtin_scenario,
"scenario": scenario_name,
"total_episodes": int(episodes),
"durations": int(durations),
"use_builtin_topology": use_builtin_topology,
"topology": topology_name
}
should_continue = prompt(
pprint.pformat(options) + "\n\nIs this OK?",
default="yes"
)
if is_command_yes(should_continue):
generate_function(options) | [
"def",
"new_project",
"(",
"*",
"*",
"kwargs",
":",
"dict",
")",
":",
"use_builtin_scenario",
"=",
"is_command_yes",
"(",
"prompt",
"(",
"\"Use built-in scenario?\"",
",",
"default",
"=",
"\"yes\"",
")",
")",
"if",
"use_builtin_scenario",
":",
"generate_function",
"=",
"new_project_with_builtin_scenario",
"# Build built-in scenario completer.",
"builtin_scenarios",
"=",
"get_scenarios",
"(",
")",
"# Validator for scenario name to make sure input is a built-in scenario.",
"class",
"BuiltInScenarioValidator",
"(",
"Validator",
")",
":",
"\"\"\"Validate is input scenario is built-in one.\"\"\"",
"def",
"validate",
"(",
"self",
",",
"document",
")",
":",
"if",
"document",
".",
"text",
"not",
"in",
"builtin_scenarios",
":",
"raise",
"ValidationError",
"(",
"message",
"=",
"\"Scenario name not a built-in one.\"",
")",
"builtin_scenario_completer",
"=",
"WordCompleter",
"(",
"builtin_scenarios",
")",
"# Select a scenario.",
"scenario_name",
"=",
"prompt",
"(",
"\"Scenario name:\"",
",",
"default",
"=",
"builtin_scenarios",
"[",
"0",
"]",
",",
"completer",
"=",
"builtin_scenario_completer",
",",
"complete_while_typing",
"=",
"True",
",",
"validate_while_typing",
"=",
"True",
",",
"validator",
"=",
"BuiltInScenarioValidator",
"(",
")",
")",
"use_builtin_topology",
"=",
"is_command_yes",
"(",
"prompt",
"(",
"\"Use built-in topology (configuration)?\"",
",",
"default",
"=",
"\"yes\"",
")",
")",
"if",
"use_builtin_topology",
":",
"# Build topology completer for topology selecting.",
"builtin_topologies",
"=",
"get_topologies",
"(",
"scenario_name",
")",
"builtin_topologies_completer",
"=",
"WordCompleter",
"(",
"builtin_topologies",
")",
"class",
"BuiltinTopologyValidator",
"(",
"Validator",
")",
":",
"\"\"\"Validate if input topology is built-in one.\"\"\"",
"def",
"validate",
"(",
"self",
",",
"document",
")",
":",
"if",
"document",
".",
"text",
"not",
"in",
"builtin_topologies",
":",
"raise",
"ValidationError",
"(",
"message",
"=",
"\"Topology not exist.\"",
")",
"topology_name",
"=",
"prompt",
"(",
"\"Topology name to use:\"",
",",
"default",
"=",
"builtin_topologies",
"[",
"0",
"]",
",",
"completer",
"=",
"builtin_topologies_completer",
",",
"validator",
"=",
"BuiltinTopologyValidator",
"(",
")",
",",
"validate_while_typing",
"=",
"True",
",",
"complete_while_typing",
"=",
"True",
")",
"else",
":",
"topology_name",
"=",
"prompt",
"(",
"\"Topology name to create (content is copied from built-in topology.):\"",
",",
"validator",
"=",
"NonEmptyStringValidator",
"(",
"\"Topology name cannot be empty.\"",
")",
",",
"validate_while_typing",
"=",
"True",
")",
"else",
":",
"use_builtin_topology",
"=",
"False",
"generate_function",
"=",
"new_project_from_scratch",
"scenario_name",
"=",
"os",
".",
"path",
".",
"basename",
"(",
"os",
".",
"getcwd",
"(",
")",
")",
"scenario_name",
"=",
"prompt",
"(",
"\"New scenario name:\"",
",",
"default",
"=",
"scenario_name",
",",
"validator",
"=",
"NonEmptyStringValidator",
"(",
"\"Scenario name cannot be empty.\"",
")",
")",
"topology_name",
"=",
"prompt",
"(",
"\"New topology name:\"",
",",
"default",
"=",
"scenario_name",
",",
"validator",
"=",
"NonEmptyStringValidator",
"(",
"\"Topology name cannot be empty.\"",
")",
")",
"# Misc settings.",
"durations",
"=",
"prompt",
"(",
"\"Durations to emulate:\"",
",",
"default",
"=",
"\"100\"",
",",
"validator",
"=",
"PositiveNumberValidator",
"(",
")",
",",
"validate_while_typing",
"=",
"True",
")",
"episodes",
"=",
"prompt",
"(",
"\"Number of episodes to emulate:\"",
",",
"default",
"=",
"\"10\"",
",",
"validator",
"=",
"PositiveNumberValidator",
"(",
")",
",",
"validate_while_typing",
"=",
"True",
")",
"options",
"=",
"{",
"\"use_builtin_scenario\"",
":",
"use_builtin_scenario",
",",
"\"scenario\"",
":",
"scenario_name",
",",
"\"total_episodes\"",
":",
"int",
"(",
"episodes",
")",
",",
"\"durations\"",
":",
"int",
"(",
"durations",
")",
",",
"\"use_builtin_topology\"",
":",
"use_builtin_topology",
",",
"\"topology\"",
":",
"topology_name",
"}",
"should_continue",
"=",
"prompt",
"(",
"pprint",
".",
"pformat",
"(",
"options",
")",
"+",
"\"\\n\\nIs this OK?\"",
",",
"default",
"=",
"\"yes\"",
")",
"if",
"is_command_yes",
"(",
"should_continue",
")",
":",
"generate_function",
"(",
"options",
")"
] | [
58,
0
] | [
165,
34
] | python | en | ['en', 'en', 'en'] | True |
new_project_with_builtin_scenario | (options: dict) | Create a runner.py to run with built-in scenario.
Args:
options (dict): Options to generate runner.py.
| Create a runner.py to run with built-in scenario. | def new_project_with_builtin_scenario(options: dict):
"""Create a runner.py to run with built-in scenario.
Args:
options (dict): Options to generate runner.py.
"""
if not options["use_builtin_topology"]:
# Create a folder to place new topology.
topology_root_path = os.path.join(os.getcwd(), "topologies")
# Make topology root and itself folder exist.
if not os.path.exists(topology_root_path):
os.mkdir(topology_root_path)
topology_path = os.path.join(topology_root_path, options["topology"])
if not os.path.exists(topology_path):
os.mkdir(topology_path)
# Copy content from exist one.
scenario_name = options["scenario"]
topology_to_copy = default_topologies.get(scenario_name, None)
if topology_to_copy:
topology_to_copy_path = os.path.join(
maro.__path__[0],
"simulator",
"scenarios",
scenario_name,
"topologies",
topology_to_copy
)
# If the default one not exist, then use first one.
if not os.path.exists(topology_to_copy_path):
topology_to_copy = get_topologies(options["scenario"])[0]
topology_to_copy_path = os.path.join(
maro.__path__[0],
"simulator",
"scenarios",
scenario_name,
"topologies",
topology_to_copy
)
with open(os.path.join(topology_to_copy_path, "config.yml"), "rt") as source_fp:
with open(os.path.join(topology_path, "config.yml"), "wt") as dest_fp:
dest_fp.write(source_fp.read())
options["topology"] = f"topologies/{options['topology']}"
env = generate_environment()
generate_runner(env, options) | [
"def",
"new_project_with_builtin_scenario",
"(",
"options",
":",
"dict",
")",
":",
"if",
"not",
"options",
"[",
"\"use_builtin_topology\"",
"]",
":",
"# Create a folder to place new topology.",
"topology_root_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"\"topologies\"",
")",
"# Make topology root and itself folder exist.",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"topology_root_path",
")",
":",
"os",
".",
"mkdir",
"(",
"topology_root_path",
")",
"topology_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"topology_root_path",
",",
"options",
"[",
"\"topology\"",
"]",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"topology_path",
")",
":",
"os",
".",
"mkdir",
"(",
"topology_path",
")",
"# Copy content from exist one.",
"scenario_name",
"=",
"options",
"[",
"\"scenario\"",
"]",
"topology_to_copy",
"=",
"default_topologies",
".",
"get",
"(",
"scenario_name",
",",
"None",
")",
"if",
"topology_to_copy",
":",
"topology_to_copy_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"maro",
".",
"__path__",
"[",
"0",
"]",
",",
"\"simulator\"",
",",
"\"scenarios\"",
",",
"scenario_name",
",",
"\"topologies\"",
",",
"topology_to_copy",
")",
"# If the default one not exist, then use first one.",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"topology_to_copy_path",
")",
":",
"topology_to_copy",
"=",
"get_topologies",
"(",
"options",
"[",
"\"scenario\"",
"]",
")",
"[",
"0",
"]",
"topology_to_copy_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"maro",
".",
"__path__",
"[",
"0",
"]",
",",
"\"simulator\"",
",",
"\"scenarios\"",
",",
"scenario_name",
",",
"\"topologies\"",
",",
"topology_to_copy",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"topology_to_copy_path",
",",
"\"config.yml\"",
")",
",",
"\"rt\"",
")",
"as",
"source_fp",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"topology_path",
",",
"\"config.yml\"",
")",
",",
"\"wt\"",
")",
"as",
"dest_fp",
":",
"dest_fp",
".",
"write",
"(",
"source_fp",
".",
"read",
"(",
")",
")",
"options",
"[",
"\"topology\"",
"]",
"=",
"f\"topologies/{options['topology']}\"",
"env",
"=",
"generate_environment",
"(",
")",
"generate_runner",
"(",
"env",
",",
"options",
")"
] | [
168,
0
] | [
221,
33
] | python | en | ['en', 'en', 'en'] | True |
new_project_from_scratch | (options: dict) | Create a project to customize scenario.
Args:
options (dict): Options for new project.
| Create a project to customize scenario. | def new_project_from_scratch(options: dict):
"""Create a project to customize scenario.
Args:
options (dict): Options for new project.
"""
# Scenario folder
scenario_folder = os.path.join(os.getcwd(), "scenario")
if not os.path.exists(scenario_folder):
os.mkdir(scenario_folder)
topology_root = os.path.join(scenario_folder, "topologies")
if not os.path.exists(topology_root):
os.mkdir(topology_root)
scenario_name = options["scenario"]
topology_name = options["topology"]
options["scenario_cls"] = stringcase.pascalcase(scenario_name)
options["topology"] = f"scenario/topologies/{options['topology']}"
topology_folder = os.path.join(topology_root, topology_name)
if not os.path.exists(topology_folder):
os.mkdir(topology_folder)
env = generate_environment()
# Generate runner.py.
generate_runner(env, options)
# Generate scenario/business_engine.py.
generate_business_engine(env, scenario_folder, options)
# Generate scenario/frame_build.py.
generate_frame_builder(env, scenario_folder, options)
# Generate scenario/common.py that contains dummy DecisionEvent and Action class.
generate_commons(env, scenario_folder, options)
# Generate scenario/events.py that contains dummy events definitions.
generate_events(env, scenario_folder, options)
# Generate a empty config.yml.
with open(os.path.join(topology_folder, "config.yml"), "wt") as fp:
fp.write("# write your own configuration here, or use other format.") | [
"def",
"new_project_from_scratch",
"(",
"options",
":",
"dict",
")",
":",
"# Scenario folder",
"scenario_folder",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"\"scenario\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"scenario_folder",
")",
":",
"os",
".",
"mkdir",
"(",
"scenario_folder",
")",
"topology_root",
"=",
"os",
".",
"path",
".",
"join",
"(",
"scenario_folder",
",",
"\"topologies\"",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"topology_root",
")",
":",
"os",
".",
"mkdir",
"(",
"topology_root",
")",
"scenario_name",
"=",
"options",
"[",
"\"scenario\"",
"]",
"topology_name",
"=",
"options",
"[",
"\"topology\"",
"]",
"options",
"[",
"\"scenario_cls\"",
"]",
"=",
"stringcase",
".",
"pascalcase",
"(",
"scenario_name",
")",
"options",
"[",
"\"topology\"",
"]",
"=",
"f\"scenario/topologies/{options['topology']}\"",
"topology_folder",
"=",
"os",
".",
"path",
".",
"join",
"(",
"topology_root",
",",
"topology_name",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"topology_folder",
")",
":",
"os",
".",
"mkdir",
"(",
"topology_folder",
")",
"env",
"=",
"generate_environment",
"(",
")",
"# Generate runner.py.",
"generate_runner",
"(",
"env",
",",
"options",
")",
"# Generate scenario/business_engine.py.",
"generate_business_engine",
"(",
"env",
",",
"scenario_folder",
",",
"options",
")",
"# Generate scenario/frame_build.py.",
"generate_frame_builder",
"(",
"env",
",",
"scenario_folder",
",",
"options",
")",
"# Generate scenario/common.py that contains dummy DecisionEvent and Action class.",
"generate_commons",
"(",
"env",
",",
"scenario_folder",
",",
"options",
")",
"# Generate scenario/events.py that contains dummy events definitions.",
"generate_events",
"(",
"env",
",",
"scenario_folder",
",",
"options",
")",
"# Generate a empty config.yml.",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"topology_folder",
",",
"\"config.yml\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"\"# write your own configuration here, or use other format.\"",
")"
] | [
224,
0
] | [
271,
77
] | python | en | ['en', 'ro', 'en'] | True |
generate_environment | () | Generate a common template environment. | Generate a common template environment. | def generate_environment():
"""Generate a common template environment."""
env = Environment(
loader=PackageLoader("maro", "cli/project_generator/templates"),
trim_blocks=True
)
return env | [
"def",
"generate_environment",
"(",
")",
":",
"env",
"=",
"Environment",
"(",
"loader",
"=",
"PackageLoader",
"(",
"\"maro\"",
",",
"\"cli/project_generator/templates\"",
")",
",",
"trim_blocks",
"=",
"True",
")",
"return",
"env"
] | [
274,
0
] | [
281,
14
] | python | en | ['gl', 'en', 'en'] | True |
generate_runner | (env: Environment, options: dict) | Generate runner.py with options.
Args:
env (Environment): Template environment used to retrieve template.
options (dict): Options for runner.py.
| Generate runner.py with options. | def generate_runner(env: Environment, options: dict):
"""Generate runner.py with options.
Args:
env (Environment): Template environment used to retrieve template.
options (dict): Options for runner.py.
"""
use_builtin_scenario = options.get("use_builtin_scenario", False)
if use_builtin_scenario:
template_name = "runner.base.py.jinja"
else:
template_name = "runner.customize.py.jinja"
template = env.get_template(template_name)
with open(os.path.join(os.getcwd(), "runner.py"), "wt") as fp:
fp.write(template.render(project=options)) | [
"def",
"generate_runner",
"(",
"env",
":",
"Environment",
",",
"options",
":",
"dict",
")",
":",
"use_builtin_scenario",
"=",
"options",
".",
"get",
"(",
"\"use_builtin_scenario\"",
",",
"False",
")",
"if",
"use_builtin_scenario",
":",
"template_name",
"=",
"\"runner.base.py.jinja\"",
"else",
":",
"template_name",
"=",
"\"runner.customize.py.jinja\"",
"template",
"=",
"env",
".",
"get_template",
"(",
"template_name",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"\"runner.py\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"template",
".",
"render",
"(",
"project",
"=",
"options",
")",
")"
] | [
284,
0
] | [
301,
50
] | python | en | ['en', 'en', 'en'] | True |
generate_business_engine | (env: Environment, folder: str, options: dict) | Generate business_engine.py with options.
Args:
env (Environment): Template environment used to retrieve template.
options (dict): Options for business_engine.py.
| Generate business_engine.py with options. | def generate_business_engine(env: Environment, folder: str, options: dict):
"""Generate business_engine.py with options.
Args:
env (Environment): Template environment used to retrieve template.
options (dict): Options for business_engine.py.
"""
template = env.get_template("business_engine.py.jinja")
with open(os.path.join(folder, "business_engine.py"), "wt") as fp:
fp.write(template.render(project=options)) | [
"def",
"generate_business_engine",
"(",
"env",
":",
"Environment",
",",
"folder",
":",
"str",
",",
"options",
":",
"dict",
")",
":",
"template",
"=",
"env",
".",
"get_template",
"(",
"\"business_engine.py.jinja\"",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"business_engine.py\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"template",
".",
"render",
"(",
"project",
"=",
"options",
")",
")"
] | [
304,
0
] | [
314,
50
] | python | en | ['en', 'en', 'en'] | True |
generate_frame_builder | (env: Environment, folder: str, options: dict) | Generate frame_builder.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for frame_builder.py.
| Generate frame_builder.py with options. | def generate_frame_builder(env: Environment, folder: str, options: dict):
"""Generate frame_builder.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for frame_builder.py.
"""
template = env.get_template("frame_builder.py.jinja")
with open(os.path.join(folder, "frame_builder.py"), "wt") as fp:
fp.write(template.render(project=options)) | [
"def",
"generate_frame_builder",
"(",
"env",
":",
"Environment",
",",
"folder",
":",
"str",
",",
"options",
":",
"dict",
")",
":",
"template",
"=",
"env",
".",
"get_template",
"(",
"\"frame_builder.py.jinja\"",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"frame_builder.py\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"template",
".",
"render",
"(",
"project",
"=",
"options",
")",
")"
] | [
317,
0
] | [
328,
50
] | python | en | ['en', 'en', 'en'] | True |
generate_commons | (env: Environment, folder: str, options: dict) | Generate common.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for common.py.
| Generate common.py with options. | def generate_commons(env: Environment, folder: str, options: dict):
"""Generate common.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for common.py.
"""
template = env.get_template("common.py.jinja")
with open(os.path.join(folder, "common.py"), "wt") as fp:
fp.write(template.render(project=options)) | [
"def",
"generate_commons",
"(",
"env",
":",
"Environment",
",",
"folder",
":",
"str",
",",
"options",
":",
"dict",
")",
":",
"template",
"=",
"env",
".",
"get_template",
"(",
"\"common.py.jinja\"",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"common.py\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"template",
".",
"render",
"(",
"project",
"=",
"options",
")",
")"
] | [
331,
0
] | [
342,
50
] | python | en | ['en', 'en', 'en'] | True |
generate_events | (env: Environment, folder: str, options: dict) | Generate events.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for events.py.
| Generate events.py with options. | def generate_events(env: Environment, folder: str, options: dict):
"""Generate events.py with options.
Args:
env (Environment): Template environment used to retrieve template.
folder (str): Folder to place new file.
options (dict): Options for events.py.
"""
template = env.get_template("events.py.jinja")
with open(os.path.join(folder, "events.py"), "wt") as fp:
fp.write(template.render(project=options)) | [
"def",
"generate_events",
"(",
"env",
":",
"Environment",
",",
"folder",
":",
"str",
",",
"options",
":",
"dict",
")",
":",
"template",
"=",
"env",
".",
"get_template",
"(",
"\"events.py.jinja\"",
")",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"folder",
",",
"\"events.py\"",
")",
",",
"\"wt\"",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"template",
".",
"render",
"(",
"project",
"=",
"options",
")",
")"
] | [
345,
0
] | [
356,
50
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Dyson Sensors. | Set up the Dyson Sensors. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Dyson Sensors."""
if discovery_info is None:
return
hass.data.setdefault(DYSON_AIQ_DEVICES, [])
# Get Dyson Devices from parent component
device_ids = [device.unique_id for device in hass.data[DYSON_AIQ_DEVICES]]
new_entities = []
for device in hass.data[DYSON_DEVICES]:
if isinstance(device, DysonPureCool) and device.serial not in device_ids:
new_entities.append(DysonAirSensor(device))
if not new_entities:
return
hass.data[DYSON_AIQ_DEVICES].extend(new_entities)
add_entities(hass.data[DYSON_AIQ_DEVICES]) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"if",
"discovery_info",
"is",
"None",
":",
"return",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DYSON_AIQ_DEVICES",
",",
"[",
"]",
")",
"# Get Dyson Devices from parent component",
"device_ids",
"=",
"[",
"device",
".",
"unique_id",
"for",
"device",
"in",
"hass",
".",
"data",
"[",
"DYSON_AIQ_DEVICES",
"]",
"]",
"new_entities",
"=",
"[",
"]",
"for",
"device",
"in",
"hass",
".",
"data",
"[",
"DYSON_DEVICES",
"]",
":",
"if",
"isinstance",
"(",
"device",
",",
"DysonPureCool",
")",
"and",
"device",
".",
"serial",
"not",
"in",
"device_ids",
":",
"new_entities",
".",
"append",
"(",
"DysonAirSensor",
"(",
"device",
")",
")",
"if",
"not",
"new_entities",
":",
"return",
"hass",
".",
"data",
"[",
"DYSON_AIQ_DEVICES",
"]",
".",
"extend",
"(",
"new_entities",
")",
"add_entities",
"(",
"hass",
".",
"data",
"[",
"DYSON_AIQ_DEVICES",
"]",
")"
] | [
19,
0
] | [
38,
46
] | python | en | ['en', 'sq', 'en'] | True |
DysonAirSensor.__init__ | (self, device) | Create a new generic air quality Dyson sensor. | Create a new generic air quality Dyson sensor. | def __init__(self, device):
"""Create a new generic air quality Dyson sensor."""
self._device = device
self._old_value = None
self._name = device.name | [
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_old_value",
"=",
"None",
"self",
".",
"_name",
"=",
"device",
".",
"name"
] | [
44,
4
] | [
48,
32
] | python | en | ['en', 'ga', 'en'] | True |
DysonAirSensor.async_added_to_hass | (self) | Call when entity is added to hass. | Call when entity is added to hass. | async def async_added_to_hass(self):
"""Call when entity is added to hass."""
self._device.add_message_listener(self.on_message) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"add_message_listener",
"(",
"self",
".",
"on_message",
")"
] | [
50,
4
] | [
52,
58
] | python | en | ['en', 'en', 'en'] | True |
DysonAirSensor.on_message | (self, message) | Handle new messages which are received from the fan. | Handle new messages which are received from the fan. | def on_message(self, message):
"""Handle new messages which are received from the fan."""
_LOGGER.debug(
"%s: Message received for %s device: %s", DOMAIN, self.name, message
)
if (
self._old_value is None
or self._old_value != self._device.environmental_state
) and isinstance(message, DysonEnvironmentalSensorV2State):
self._old_value = self._device.environmental_state
self.schedule_update_ha_state() | [
"def",
"on_message",
"(",
"self",
",",
"message",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"%s: Message received for %s device: %s\"",
",",
"DOMAIN",
",",
"self",
".",
"name",
",",
"message",
")",
"if",
"(",
"self",
".",
"_old_value",
"is",
"None",
"or",
"self",
".",
"_old_value",
"!=",
"self",
".",
"_device",
".",
"environmental_state",
")",
"and",
"isinstance",
"(",
"message",
",",
"DysonEnvironmentalSensorV2State",
")",
":",
"self",
".",
"_old_value",
"=",
"self",
".",
"_device",
".",
"environmental_state",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
54,
4
] | [
64,
43
] | python | en | ['en', 'en', 'en'] | True |
DysonAirSensor.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
67,
4
] | [
69,
20
] | python | en | ['en', 'en', 'en'] | True |
DysonAirSensor.name | (self) | Return the name of the Dyson sensor. | Return the name of the Dyson sensor. | def name(self):
"""Return the name of the Dyson sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
72,
4
] | [
74,
25
] | python | en | ['en', 'sq', 'en'] | True |
DysonAirSensor.attribution | (self) | Return the attribution. | Return the attribution. | def attribution(self):
"""Return the attribution."""
return ATTRIBUTION | [
"def",
"attribution",
"(",
"self",
")",
":",
"return",
"ATTRIBUTION"
] | [
77,
4
] | [
79,
26
] | python | en | ['en', 'ja', 'en'] | True |
DysonAirSensor.air_quality_index | (self) | Return the Air Quality Index (AQI). | Return the Air Quality Index (AQI). | def air_quality_index(self):
"""Return the Air Quality Index (AQI)."""
return max(
self.particulate_matter_2_5,
self.particulate_matter_10,
self.nitrogen_dioxide,
self.volatile_organic_compounds,
) | [
"def",
"air_quality_index",
"(",
"self",
")",
":",
"return",
"max",
"(",
"self",
".",
"particulate_matter_2_5",
",",
"self",
".",
"particulate_matter_10",
",",
"self",
".",
"nitrogen_dioxide",
",",
"self",
".",
"volatile_organic_compounds",
",",
")"
] | [
82,
4
] | [
89,
9
] | python | en | ['en', 'cy', 'en'] | True |
DysonAirSensor.particulate_matter_2_5 | (self) | Return the particulate matter 2.5 level. | Return the particulate matter 2.5 level. | def particulate_matter_2_5(self):
"""Return the particulate matter 2.5 level."""
if self._device.environmental_state:
return int(self._device.environmental_state.particulate_matter_25)
return None | [
"def",
"particulate_matter_2_5",
"(",
"self",
")",
":",
"if",
"self",
".",
"_device",
".",
"environmental_state",
":",
"return",
"int",
"(",
"self",
".",
"_device",
".",
"environmental_state",
".",
"particulate_matter_25",
")",
"return",
"None"
] | [
92,
4
] | [
96,
19
] | python | en | ['en', 'en', 'en'] | True |
DysonAirSensor.particulate_matter_10 | (self) | Return the particulate matter 10 level. | Return the particulate matter 10 level. | def particulate_matter_10(self):
"""Return the particulate matter 10 level."""
if self._device.environmental_state:
return int(self._device.environmental_state.particulate_matter_10)
return None | [
"def",
"particulate_matter_10",
"(",
"self",
")",
":",
"if",
"self",
".",
"_device",
".",
"environmental_state",
":",
"return",
"int",
"(",
"self",
".",
"_device",
".",
"environmental_state",
".",
"particulate_matter_10",
")",
"return",
"None"
] | [
99,
4
] | [
103,
19
] | python | en | ['en', 'en', 'en'] | True |
DysonAirSensor.nitrogen_dioxide | (self) | Return the NO2 (nitrogen dioxide) level. | Return the NO2 (nitrogen dioxide) level. | def nitrogen_dioxide(self):
"""Return the NO2 (nitrogen dioxide) level."""
if self._device.environmental_state:
return int(self._device.environmental_state.nitrogen_dioxide)
return None | [
"def",
"nitrogen_dioxide",
"(",
"self",
")",
":",
"if",
"self",
".",
"_device",
".",
"environmental_state",
":",
"return",
"int",
"(",
"self",
".",
"_device",
".",
"environmental_state",
".",
"nitrogen_dioxide",
")",
"return",
"None"
] | [
106,
4
] | [
110,
19
] | python | en | ['en', 'da', 'en'] | True |
DysonAirSensor.volatile_organic_compounds | (self) | Return the VOC (Volatile Organic Compounds) level. | Return the VOC (Volatile Organic Compounds) level. | def volatile_organic_compounds(self):
"""Return the VOC (Volatile Organic Compounds) level."""
if self._device.environmental_state:
return int(self._device.environmental_state.volatile_organic_compounds)
return None | [
"def",
"volatile_organic_compounds",
"(",
"self",
")",
":",
"if",
"self",
".",
"_device",
".",
"environmental_state",
":",
"return",
"int",
"(",
"self",
".",
"_device",
".",
"environmental_state",
".",
"volatile_organic_compounds",
")",
"return",
"None"
] | [
113,
4
] | [
117,
19
] | python | en | ['en', 'fr', 'en'] | True |
DysonAirSensor.unique_id | (self) | Return the sensor's unique id. | Return the sensor's unique id. | def unique_id(self):
"""Return the sensor's unique id."""
return self._device.serial | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"serial"
] | [
120,
4
] | [
122,
34
] | python | en | ['en', 'ca', 'en'] | True |
DysonAirSensor.device_state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def device_state_attributes(self):
"""Return the device state attributes."""
data = {}
voc = self.volatile_organic_compounds
if voc is not None:
data[ATTR_VOC] = voc
return data | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"data",
"=",
"{",
"}",
"voc",
"=",
"self",
".",
"volatile_organic_compounds",
"if",
"voc",
"is",
"not",
"None",
":",
"data",
"[",
"ATTR_VOC",
"]",
"=",
"voc",
"return",
"data"
] | [
125,
4
] | [
132,
19
] | python | en | ['en', 'en', 'en'] | True |
calls | (hass) | Track calls to a mock service. | Track calls to a mock service. | def calls(hass):
"""Track calls to a mock service."""
return async_mock_service(hass, "test", "automation") | [
"def",
"calls",
"(",
"hass",
")",
":",
"return",
"async_mock_service",
"(",
"hass",
",",
"\"test\"",
",",
"\"automation\"",
")"
] | [
22,
0
] | [
24,
57
] | python | en | ['en', 'en', 'en'] | True |
setup_comp | (hass) | Initialize components. | Initialize components. | def setup_comp(hass):
"""Initialize components."""
mock_component(hass, "group")
hass.states.async_set("test.entity", "hello") | [
"def",
"setup_comp",
"(",
"hass",
")",
":",
"mock_component",
"(",
"hass",
",",
"\"group\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"hello\"",
")"
] | [
28,
0
] | [
31,
49
] | python | en | ['de', 'en', 'en'] | False |
test_if_fires_on_change_bool | (hass, calls) | Test for firing on boolean change. | Test for firing on boolean change. | async def test_if_fires_on_change_bool(hass, calls):
"""Test for firing on boolean change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ states.test.entity.state and true }}",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1
await hass.services.async_call(
automation.DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
blocking=True,
)
hass.states.async_set("test.entity", "planet")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_bool",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ states.test.entity.state and true }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"automation",
".",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_MATCH_ALL",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"planet\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
34,
0
] | [
63,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_str | (hass, calls) | Test for firing on change. | Test for firing on change. | async def test_if_fires_on_change_str(hass, calls):
"""Test for firing on change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ states.test.entity.state and "true" }}',
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_str",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ states.test.entity.state and \"true\" }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
66,
0
] | [
84,
26
] | python | en | ['en', 'no', 'en'] | True |
test_if_fires_on_change_str_crazy | (hass, calls) | Test for firing on change. | Test for firing on change. | async def test_if_fires_on_change_str_crazy(hass, calls):
"""Test for firing on change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ states.test.entity.state and "TrUE" }}',
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_str_crazy",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ states.test.entity.state and \"TrUE\" }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
87,
0
] | [
105,
26
] | python | en | ['en', 'no', 'en'] | True |
test_if_not_fires_on_change_bool | (hass, calls) | Test for not firing on boolean change. | Test for not firing on boolean change. | async def test_if_not_fires_on_change_bool(hass, calls):
"""Test for not firing on boolean change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ states.test.entity.state and false }}",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_on_change_bool",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ states.test.entity.state and false }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
108,
0
] | [
126,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_not_fires_on_change_str | (hass, calls) | Test for not firing on string change. | Test for not firing on string change. | async def test_if_not_fires_on_change_str(hass, calls):
"""Test for not firing on string change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "template", "value_template": "true"},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_on_change_str",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"true\"",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
129,
0
] | [
144,
26
] | python | en | ['en', 'no', 'en'] | True |
test_if_not_fires_on_change_str_crazy | (hass, calls) | Test for not firing on string change. | Test for not firing on string change. | async def test_if_not_fires_on_change_str_crazy(hass, calls):
"""Test for not firing on string change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ "Anything other than true is false." }}',
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_on_change_str_crazy",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ \"Anything other than true is false.\" }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
147,
0
] | [
165,
26
] | python | en | ['en', 'no', 'en'] | True |
test_if_fires_on_no_change | (hass, calls) | Test for firing on no change. | Test for firing on no change. | async def test_if_fires_on_no_change(hass, calls):
"""Test for firing on no change."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "template", "value_template": "{{ true }}"},
"action": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
cur_len = len(calls)
hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done()
assert cur_len == len(calls) | [
"async",
"def",
"test_if_fires_on_no_change",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ true }}\"",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"cur_len",
"=",
"len",
"(",
"calls",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"hello\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"cur_len",
"==",
"len",
"(",
"calls",
")"
] | [
168,
0
] | [
186,
32
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_two_change | (hass, calls) | Test for firing on two changes. | Test for firing on two changes. | async def test_if_fires_on_two_change(hass, calls):
"""Test for firing on two changes."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ states.test.entity.state and true }}",
},
"action": {"service": "test.automation"},
}
},
)
# Trigger once
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1
# Trigger again
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_two_change",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ states.test.entity.state and true }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"# Trigger once",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"# Trigger again",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
189,
0
] | [
213,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_template | (hass, calls) | Test for firing on change with template. | Test for firing on change with template. | async def test_if_fires_on_change_with_template(hass, calls):
"""Test for firing on change with template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ is_state("test.entity", "world") }}',
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_template",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"world\") }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
216,
0
] | [
234,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_not_fires_on_change_with_template | (hass, calls) | Test for not firing on change with template. | Test for not firing on change with template. | async def test_if_not_fires_on_change_with_template(hass, calls):
"""Test for not firing on change with template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ is_state("test.entity", "hello") }}',
},
"action": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_on_change_with_template",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"hello\") }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
237,
0
] | [
257,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_template_advanced | (hass, calls) | Test for firing on change with template advanced. | Test for firing on change with template advanced. | async def test_if_fires_on_change_with_template_advanced(hass, calls):
"""Test for firing on change with template advanced."""
context = Context()
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ is_state("test.entity", "world") }}',
},
"action": {
"service": "test.automation",
"data_template": {
"some": "{{ trigger.%s }}"
% "}} - {{ trigger.".join(
(
"platform",
"entity_id",
"from_state.state",
"to_state.state",
"for",
)
)
},
},
}
},
)
await hass.async_block_till_done()
hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].context.parent_id == context.id
assert "template - test.entity - hello - world - None" == calls[0].data["some"] | [
"async",
"def",
"test_if_fires_on_change_with_template_advanced",
"(",
"hass",
",",
"calls",
")",
":",
"context",
"=",
"Context",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"world\") }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"{{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"entity_id\"",
",",
"\"from_state.state\"",
",",
"\"to_state.state\"",
",",
"\"for\"",
",",
")",
")",
"}",
",",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
",",
"context",
"=",
"context",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"context",
".",
"parent_id",
"==",
"context",
".",
"id",
"assert",
"\"template - test.entity - hello - world - None\"",
"==",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]"
] | [
260,
0
] | [
297,
83
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_no_change_with_template_advanced | (hass, calls) | Test for firing on no change with template advanced. | Test for firing on no change with template advanced. | async def test_if_fires_on_no_change_with_template_advanced(hass, calls):
"""Test for firing on no change with template advanced."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": """{%- if is_state("test.entity", "world") -%}
true
{%- else -%}
false
{%- endif -%}""",
},
"action": {"service": "test.automation"},
}
},
)
# Different state
hass.states.async_set("test.entity", "worldz")
await hass.async_block_till_done()
assert len(calls) == 0
# Different state
hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_fires_on_no_change_with_template_advanced",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"\"\"{%- if is_state(\"test.entity\", \"world\") -%}\n true\n {%- else -%}\n false\n {%- endif -%}\"\"\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"# Different state",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"worldz\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"# Different state",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"hello\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
300,
0
] | [
328,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_template_2 | (hass, calls) | Test for firing on change with template. | Test for firing on change with template. | async def test_if_fires_on_change_with_template_2(hass, calls):
"""Test for firing on change with template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ not is_state("test.entity", "world") }}',
},
"action": {"service": "test.automation"},
}
},
)
await hass.async_block_till_done()
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
hass.states.async_set("test.entity", "home")
await hass.async_block_till_done()
assert len(calls) == 1
hass.states.async_set("test.entity", "work")
await hass.async_block_till_done()
assert len(calls) == 1
hass.states.async_set("test.entity", "not_home")
await hass.async_block_till_done()
assert len(calls) == 1
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1
hass.states.async_set("test.entity", "home")
await hass.async_block_till_done()
assert len(calls) == 2 | [
"async",
"def",
"test_if_fires_on_change_with_template_2",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ not is_state(\"test.entity\", \"world\") }}'",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"home\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"work\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"not_home\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"home\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"2"
] | [
331,
0
] | [
371,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_action | (hass, calls) | Test for firing if action. | Test for firing if action. | async def test_if_action(hass, calls):
"""Test for firing if action."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "event", "event_type": "test_event"},
"condition": [
{
"condition": "template",
"value_template": '{{ is_state("test.entity", "world") }}',
}
],
"action": {"service": "test.automation"},
}
},
)
# Condition is not true yet
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 0
# Change condition to true, but it shouldn't be triggered yet
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
# Condition is true and event is triggered
hass.bus.async_fire("test_event")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_action",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"event\"",
",",
"\"event_type\"",
":",
"\"test_event\"",
"}",
",",
"\"condition\"",
":",
"[",
"{",
"\"condition\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"world\") }}'",
",",
"}",
"]",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"# Condition is not true yet",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"# Change condition to true, but it shouldn't be triggered yet",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"# Condition is true and event is triggered",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"test_event\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
374,
0
] | [
406,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_bad_template | (hass, calls) | Test for firing on change with bad template. | Test for firing on change with bad template. | async def test_if_fires_on_change_with_bad_template(hass, calls):
"""Test for firing on change with bad template."""
with assert_setup_component(0, automation.DOMAIN):
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {"platform": "template", "value_template": "{{ "},
"action": {"service": "test.automation"},
}
},
) | [
"async",
"def",
"test_if_fires_on_change_with_bad_template",
"(",
"hass",
",",
"calls",
")",
":",
"with",
"assert_setup_component",
"(",
"0",
",",
"automation",
".",
"DOMAIN",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ \"",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")"
] | [
409,
0
] | [
421,
9
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_bad_template_2 | (hass, calls) | Test for firing on change with bad template. | Test for firing on change with bad template. | async def test_if_fires_on_change_with_bad_template_2(hass, calls):
"""Test for firing on change with bad template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ xyz | round(0) }}",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_fires_on_change_with_bad_template_2",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ xyz | round(0) }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
424,
0
] | [
442,
26
] | python | en | ['en', 'en', 'en'] | True |
test_wait_template_with_trigger | (hass, calls) | Test using wait template with 'trigger.entity_id'. | Test using wait template with 'trigger.entity_id'. | async def test_wait_template_with_trigger(hass, calls):
"""Test using wait template with 'trigger.entity_id'."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ states.test.entity.state == 'world' }}",
},
"action": [
{"event": "test_event"},
{"wait_template": "{{ is_state(trigger.entity_id, 'hello') }}"},
{
"service": "test.automation",
"data_template": {
"some": "{{ trigger.%s }}"
% "}} - {{ trigger.".join(
(
"platform",
"entity_id",
"from_state.state",
"to_state.state",
"for",
)
)
},
},
],
}
},
)
await hass.async_block_till_done()
@callback
def event_handler(event):
hass.states.async_set("test.entity", "hello")
hass.bus.async_listen_once("test_event", event_handler)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data["some"] == "template - test.entity - hello - world - None" | [
"async",
"def",
"test_wait_template_with_trigger",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ states.test.entity.state == 'world' }}\"",
",",
"}",
",",
"\"action\"",
":",
"[",
"{",
"\"event\"",
":",
"\"test_event\"",
"}",
",",
"{",
"\"wait_template\"",
":",
"\"{{ is_state(trigger.entity_id, 'hello') }}\"",
"}",
",",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"{{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"entity_id\"",
",",
"\"from_state.state\"",
",",
"\"to_state.state\"",
",",
"\"for\"",
",",
")",
")",
"}",
",",
"}",
",",
"]",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"@",
"callback",
"def",
"event_handler",
"(",
"event",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"hello\"",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"\"test_event\"",
",",
"event_handler",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"template - test.entity - hello - world - None\""
] | [
445,
0
] | [
490,
83
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for | (hass, calls) | Test for firing on change with for. | Test for firing on change with for. | async def test_if_fires_on_change_with_for(hass, calls):
"""Test for firing on change with for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": 5},
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"5",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
493,
0
] | [
515,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_advanced | (hass, calls) | Test for firing on change with for advanced. | Test for firing on change with for advanced. | async def test_if_fires_on_change_with_for_advanced(hass, calls):
"""Test for firing on change with for advanced."""
context = Context()
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ is_state("test.entity", "world") }}',
"for": {"seconds": 5},
},
"action": {
"service": "test.automation",
"data_template": {
"some": "{{ trigger.%s }}"
% "}} - {{ trigger.".join(
(
"platform",
"entity_id",
"from_state.state",
"to_state.state",
"for",
)
)
},
},
}
},
)
await hass.async_block_till_done()
hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].context.parent_id == context.id
assert "template - test.entity - hello - world - 0:00:05" == calls[0].data["some"] | [
"async",
"def",
"test_if_fires_on_change_with_for_advanced",
"(",
"hass",
",",
"calls",
")",
":",
"context",
"=",
"Context",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"world\") }}'",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"5",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"{{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"entity_id\"",
",",
"\"from_state.state\"",
",",
"\"to_state.state\"",
",",
"\"for\"",
",",
")",
")",
"}",
",",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
",",
"context",
"=",
"context",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"context",
".",
"parent_id",
"==",
"context",
".",
"id",
"assert",
"\"template - test.entity - hello - world - 0:00:05\"",
"==",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]"
] | [
518,
0
] | [
559,
86
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_0 | (hass, calls) | Test for firing on change with for: 0. | Test for firing on change with for: 0. | async def test_if_fires_on_change_with_for_0(hass, calls):
"""Test for firing on change with for: 0."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": 0},
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for_0",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"0",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
562,
0
] | [
581,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_0_advanced | (hass, calls) | Test for firing on change with for: 0 advanced. | Test for firing on change with for: 0 advanced. | async def test_if_fires_on_change_with_for_0_advanced(hass, calls):
"""Test for firing on change with for: 0 advanced."""
context = Context()
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": '{{ is_state("test.entity", "world") }}',
"for": {"seconds": 0},
},
"action": {
"service": "test.automation",
"data_template": {
"some": "{{ trigger.%s }}"
% "}} - {{ trigger.".join(
(
"platform",
"entity_id",
"from_state.state",
"to_state.state",
"for",
)
)
},
},
}
},
)
await hass.async_block_till_done()
hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].context.parent_id == context.id
assert calls[0].data["some"] == "template - test.entity - hello - world - 0:00:00" | [
"async",
"def",
"test_if_fires_on_change_with_for_0_advanced",
"(",
"hass",
",",
"calls",
")",
":",
"context",
"=",
"Context",
"(",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"'{{ is_state(\"test.entity\", \"world\") }}'",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"0",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
",",
"\"data_template\"",
":",
"{",
"\"some\"",
":",
"\"{{ trigger.%s }}\"",
"%",
"\"}} - {{ trigger.\"",
".",
"join",
"(",
"(",
"\"platform\"",
",",
"\"entity_id\"",
",",
"\"from_state.state\"",
",",
"\"to_state.state\"",
",",
"\"for\"",
",",
")",
")",
"}",
",",
"}",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
",",
"context",
"=",
"context",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"assert",
"calls",
"[",
"0",
"]",
".",
"context",
".",
"parent_id",
"==",
"context",
".",
"id",
"assert",
"calls",
"[",
"0",
"]",
".",
"data",
"[",
"\"some\"",
"]",
"==",
"\"template - test.entity - hello - world - 0:00:00\""
] | [
584,
0
] | [
622,
86
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_2 | (hass, calls) | Test for firing on change with for. | Test for firing on change with for. | async def test_if_fires_on_change_with_for_2(hass, calls):
"""Test for firing on change with for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": 5,
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for_2",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"5",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
625,
0
] | [
647,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_not_fires_on_change_with_for | (hass, calls) | Test for firing on change with for. | Test for firing on change with for. | async def test_if_not_fires_on_change_with_for(hass, calls):
"""Test for firing on change with for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": 5},
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4))
await hass.async_block_till_done()
assert len(calls) == 0
hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6))
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_on_change_with_for",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"5",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"4",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"hello\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"6",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
650,
0
] | [
678,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_not_fires_when_turned_off_with_for | (hass, calls) | Test for firing on change with for. | Test for firing on change with for. | async def test_if_not_fires_when_turned_off_with_for(hass, calls):
"""Test for firing on change with for."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": 5},
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4))
await hass.async_block_till_done()
assert len(calls) == 0
await hass.services.async_call(
automation.DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: ENTITY_MATCH_ALL},
blocking=True,
)
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6))
await hass.async_block_till_done()
assert len(calls) == 0 | [
"async",
"def",
"test_if_not_fires_when_turned_off_with_for",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"5",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"4",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"automation",
".",
"DOMAIN",
",",
"SERVICE_TURN_OFF",
",",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_MATCH_ALL",
"}",
",",
"blocking",
"=",
"True",
",",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"6",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
681,
0
] | [
713,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_template_1 | (hass, calls) | Test for firing on change with for template. | Test for firing on change with for template. | async def test_if_fires_on_change_with_for_template_1(hass, calls):
"""Test for firing on change with for template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": "{{ 5 }}"},
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for_template_1",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"\"{{ 5 }}\"",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
716,
0
] | [
738,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_template_2 | (hass, calls) | Test for firing on change with for template. | Test for firing on change with for template. | async def test_if_fires_on_change_with_for_template_2(hass, calls):
"""Test for firing on change with for template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": "{{ 5 }}",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for_template_2",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"\"{{ 5 }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
741,
0
] | [
763,
26
] | python | en | ['en', 'en', 'en'] | True |
test_if_fires_on_change_with_for_template_3 | (hass, calls) | Test for firing on change with for template. | Test for firing on change with for template. | async def test_if_fires_on_change_with_for_template_3(hass, calls):
"""Test for firing on change with for template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": "00:00:{{ 5 }}",
},
"action": {"service": "test.automation"},
}
},
)
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert len(calls) == 1 | [
"async",
"def",
"test_if_fires_on_change_with_for_template_3",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"\"00:00:{{ 5 }}\"",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"0",
"async_fire_time_changed",
"(",
"hass",
",",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1"
] | [
766,
0
] | [
788,
26
] | python | en | ['en', 'en', 'en'] | True |
test_invalid_for_template_1 | (hass, calls) | Test for invalid for template. | Test for invalid for template. | async def test_invalid_for_template_1(hass, calls):
"""Test for invalid for template."""
assert await async_setup_component(
hass,
automation.DOMAIN,
{
automation.DOMAIN: {
"trigger": {
"platform": "template",
"value_template": "{{ is_state('test.entity', 'world') }}",
"for": {"seconds": "{{ five }}"},
},
"action": {"service": "test.automation"},
}
},
)
with mock.patch.object(template_trigger, "_LOGGER") as mock_logger:
hass.states.async_set("test.entity", "world")
await hass.async_block_till_done()
assert mock_logger.error.called | [
"async",
"def",
"test_invalid_for_template_1",
"(",
"hass",
",",
"calls",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"automation",
".",
"DOMAIN",
",",
"{",
"automation",
".",
"DOMAIN",
":",
"{",
"\"trigger\"",
":",
"{",
"\"platform\"",
":",
"\"template\"",
",",
"\"value_template\"",
":",
"\"{{ is_state('test.entity', 'world') }}\"",
",",
"\"for\"",
":",
"{",
"\"seconds\"",
":",
"\"{{ five }}\"",
"}",
",",
"}",
",",
"\"action\"",
":",
"{",
"\"service\"",
":",
"\"test.automation\"",
"}",
",",
"}",
"}",
",",
")",
"with",
"mock",
".",
"patch",
".",
"object",
"(",
"template_trigger",
",",
"\"_LOGGER\"",
")",
"as",
"mock_logger",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"test.entity\"",
",",
"\"world\"",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"mock_logger",
".",
"error",
".",
"called"
] | [
791,
0
] | [
811,
39
] | python | en | ['en', 'en', 'en'] | True |
GoogleConfig.__init__ | (self, hass, config) | Initialize the config. | Initialize the config. | def __init__(self, hass, config):
"""Initialize the config."""
super().__init__(hass)
self._config = config
self._access_token = None
self._access_token_renew = None | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hass",
")",
"self",
".",
"_config",
"=",
"config",
"self",
".",
"_access_token",
"=",
"None",
"self",
".",
"_access_token_renew",
"=",
"None"
] | [
76,
4
] | [
81,
39
] | python | en | ['en', 'en', 'en'] | True |
GoogleConfig.enabled | (self) | Return if Google is enabled. | Return if Google is enabled. | def enabled(self):
"""Return if Google is enabled."""
return True | [
"def",
"enabled",
"(",
"self",
")",
":",
"return",
"True"
] | [
84,
4
] | [
86,
19
] | python | en | ['en', 'en', 'en'] | True |
GoogleConfig.entity_config | (self) | Return entity config. | Return entity config. | def entity_config(self):
"""Return entity config."""
return self._config.get(CONF_ENTITY_CONFIG) or {} | [
"def",
"entity_config",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_ENTITY_CONFIG",
")",
"or",
"{",
"}"
] | [
89,
4
] | [
91,
57
] | python | en | ['en', 'cy', 'en'] | True |
GoogleConfig.secure_devices_pin | (self) | Return entity config. | Return entity config. | def secure_devices_pin(self):
"""Return entity config."""
return self._config.get(CONF_SECURE_DEVICES_PIN) | [
"def",
"secure_devices_pin",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_SECURE_DEVICES_PIN",
")"
] | [
94,
4
] | [
96,
56
] | python | en | ['en', 'cy', 'en'] | True |
GoogleConfig.should_report_state | (self) | Return if states should be proactively reported. | Return if states should be proactively reported. | def should_report_state(self):
"""Return if states should be proactively reported."""
return self._config.get(CONF_REPORT_STATE) | [
"def",
"should_report_state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_REPORT_STATE",
")"
] | [
99,
4
] | [
101,
50
] | python | en | ['en', 'en', 'en'] | True |
GoogleConfig.should_expose | (self, state) | Return if entity should be exposed. | Return if entity should be exposed. | def should_expose(self, state) -> bool:
"""Return if entity should be exposed."""
expose_by_default = self._config.get(CONF_EXPOSE_BY_DEFAULT)
exposed_domains = self._config.get(CONF_EXPOSED_DOMAINS)
if state.attributes.get("view") is not None:
# Ignore entities that are views
return False
if state.entity_id in CLOUD_NEVER_EXPOSED_ENTITIES:
return False
explicit_expose = self.entity_config.get(state.entity_id, {}).get(CONF_EXPOSE)
domain_exposed_by_default = (
expose_by_default and state.domain in exposed_domains
)
# Expose an entity if the entity's domain is exposed by default and
# the configuration doesn't explicitly exclude it from being
# exposed, or if the entity is explicitly exposed
is_default_exposed = domain_exposed_by_default and explicit_expose is not False
return is_default_exposed or explicit_expose | [
"def",
"should_expose",
"(",
"self",
",",
"state",
")",
"->",
"bool",
":",
"expose_by_default",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_EXPOSE_BY_DEFAULT",
")",
"exposed_domains",
"=",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_EXPOSED_DOMAINS",
")",
"if",
"state",
".",
"attributes",
".",
"get",
"(",
"\"view\"",
")",
"is",
"not",
"None",
":",
"# Ignore entities that are views",
"return",
"False",
"if",
"state",
".",
"entity_id",
"in",
"CLOUD_NEVER_EXPOSED_ENTITIES",
":",
"return",
"False",
"explicit_expose",
"=",
"self",
".",
"entity_config",
".",
"get",
"(",
"state",
".",
"entity_id",
",",
"{",
"}",
")",
".",
"get",
"(",
"CONF_EXPOSE",
")",
"domain_exposed_by_default",
"=",
"(",
"expose_by_default",
"and",
"state",
".",
"domain",
"in",
"exposed_domains",
")",
"# Expose an entity if the entity's domain is exposed by default and",
"# the configuration doesn't explicitly exclude it from being",
"# exposed, or if the entity is explicitly exposed",
"is_default_exposed",
"=",
"domain_exposed_by_default",
"and",
"explicit_expose",
"is",
"not",
"False",
"return",
"is_default_exposed",
"or",
"explicit_expose"
] | [
103,
4
] | [
126,
52
] | python | en | ['en', 'en', 'en'] | True |
GoogleConfig.get_agent_user_id | (self, context) | Get agent user ID making request. | Get agent user ID making request. | def get_agent_user_id(self, context):
"""Get agent user ID making request."""
return context.user_id | [
"def",
"get_agent_user_id",
"(",
"self",
",",
"context",
")",
":",
"return",
"context",
".",
"user_id"
] | [
128,
4
] | [
130,
30
] | python | en | ['fr', 'en', 'en'] | True |
GoogleConfig.should_2fa | (self, state) | If an entity should have 2FA checked. | If an entity should have 2FA checked. | def should_2fa(self, state):
"""If an entity should have 2FA checked."""
return True | [
"def",
"should_2fa",
"(",
"self",
",",
"state",
")",
":",
"return",
"True"
] | [
132,
4
] | [
134,
19
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.