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 |
---|---|---|---|---|---|---|---|---|---|---|---|
AlexaConfig.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",
"{",
"}"
] | [
83,
4
] | [
85,
57
] | python | en | ['en', 'cy', 'en'] | True |
AlexaConfig.should_expose | (self, entity_id) | If an entity should be exposed. | If an entity should be exposed. | def should_expose(self, entity_id):
"""If an entity should be exposed."""
if entity_id in CLOUD_NEVER_EXPOSED_ENTITIES:
return False
if not self._config[CONF_FILTER].empty_filter:
return self._config[CONF_FILTER](entity_id)
entity_configs = self._prefs.alexa_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.alexa_default_expose
# Backwards compat
if default_expose is None:
return True
return split_entity_id(entity_id)[0] in default_expose | [
"def",
"should_expose",
"(",
"self",
",",
"entity_id",
")",
":",
"if",
"entity_id",
"in",
"CLOUD_NEVER_EXPOSED_ENTITIES",
":",
"return",
"False",
"if",
"not",
"self",
".",
"_config",
"[",
"CONF_FILTER",
"]",
".",
"empty_filter",
":",
"return",
"self",
".",
"_config",
"[",
"CONF_FILTER",
"]",
"(",
"entity_id",
")",
"entity_configs",
"=",
"self",
".",
"_prefs",
".",
"alexa_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",
".",
"alexa_default_expose",
"# Backwards compat",
"if",
"default_expose",
"is",
"None",
":",
"return",
"True",
"return",
"split_entity_id",
"(",
"entity_id",
")",
"[",
"0",
"]",
"in",
"default_expose"
] | [
87,
4
] | [
107,
62
] | python | en | ['en', 'en', 'en'] | True |
AlexaConfig.async_invalidate_access_token | (self) | Invalidate access token. | Invalidate access token. | def async_invalidate_access_token(self):
"""Invalidate access token."""
self._token_valid = None | [
"def",
"async_invalidate_access_token",
"(",
"self",
")",
":",
"self",
".",
"_token_valid",
"=",
"None"
] | [
110,
4
] | [
112,
32
] | python | en | ['en', 'fi', 'en'] | True |
AlexaConfig.async_get_access_token | (self) | Get an access token. | Get an access token. | async def async_get_access_token(self):
"""Get an access token."""
if self._token_valid is not None and self._token_valid > utcnow():
return self._token
resp = await cloud_api.async_alexa_access_token(self._cloud)
body = await resp.json()
if resp.status == HTTP_BAD_REQUEST:
if body["reason"] in ("RefreshTokenNotFound", "UnknownRegion"):
if self.should_report_state:
await self._prefs.async_update(alexa_report_state=False)
self.hass.components.persistent_notification.async_create(
f"There was an error reporting state to Alexa ({body['reason']}). "
"Please re-link your Alexa skill via the Alexa app to "
"continue using it.",
"Alexa state reporting disabled",
"cloud_alexa_report",
)
raise RequireRelink
raise alexa_errors.NoTokenAvailable
self._token = body["access_token"]
self._endpoint = body["event_endpoint"]
self._token_valid = utcnow() + timedelta(seconds=body["expires_in"])
return self._token | [
"async",
"def",
"async_get_access_token",
"(",
"self",
")",
":",
"if",
"self",
".",
"_token_valid",
"is",
"not",
"None",
"and",
"self",
".",
"_token_valid",
">",
"utcnow",
"(",
")",
":",
"return",
"self",
".",
"_token",
"resp",
"=",
"await",
"cloud_api",
".",
"async_alexa_access_token",
"(",
"self",
".",
"_cloud",
")",
"body",
"=",
"await",
"resp",
".",
"json",
"(",
")",
"if",
"resp",
".",
"status",
"==",
"HTTP_BAD_REQUEST",
":",
"if",
"body",
"[",
"\"reason\"",
"]",
"in",
"(",
"\"RefreshTokenNotFound\"",
",",
"\"UnknownRegion\"",
")",
":",
"if",
"self",
".",
"should_report_state",
":",
"await",
"self",
".",
"_prefs",
".",
"async_update",
"(",
"alexa_report_state",
"=",
"False",
")",
"self",
".",
"hass",
".",
"components",
".",
"persistent_notification",
".",
"async_create",
"(",
"f\"There was an error reporting state to Alexa ({body['reason']}). \"",
"\"Please re-link your Alexa skill via the Alexa app to \"",
"\"continue using it.\"",
",",
"\"Alexa state reporting disabled\"",
",",
"\"cloud_alexa_report\"",
",",
")",
"raise",
"RequireRelink",
"raise",
"alexa_errors",
".",
"NoTokenAvailable",
"self",
".",
"_token",
"=",
"body",
"[",
"\"access_token\"",
"]",
"self",
".",
"_endpoint",
"=",
"body",
"[",
"\"event_endpoint\"",
"]",
"self",
".",
"_token_valid",
"=",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"body",
"[",
"\"expires_in\"",
"]",
")",
"return",
"self",
".",
"_token"
] | [
114,
4
] | [
140,
26
] | python | en | ['en', 'lb', 'en'] | True |
AlexaConfig._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_states:
if self.should_report_state:
await self.async_enable_proactive_mode()
else:
await self.async_disable_proactive_mode()
# 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()
return
# If user has filter in config.yaml, don't sync.
if not self._config[CONF_FILTER].empty_filter:
return
# If entity prefs are the same, don't sync.
if (
self._cur_entity_prefs is prefs.alexa_entity_configs
and self._cur_default_expose is prefs.alexa_default_expose
):
return
if self._alexa_sync_unsub:
self._alexa_sync_unsub()
self._alexa_sync_unsub = None
if self._cur_default_expose is not prefs.alexa_default_expose:
await self.async_sync_entities()
return
self._alexa_sync_unsub = async_call_later(
self.hass, SYNC_DELAY, self._sync_prefs
) | [
"async",
"def",
"_async_prefs_updated",
"(",
"self",
",",
"prefs",
")",
":",
"if",
"self",
".",
"should_report_state",
"!=",
"self",
".",
"is_reporting_states",
":",
"if",
"self",
".",
"should_report_state",
":",
"await",
"self",
".",
"async_enable_proactive_mode",
"(",
")",
"else",
":",
"await",
"self",
".",
"async_disable_proactive_mode",
"(",
")",
"# 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",
"(",
")",
"return",
"# If user has filter in config.yaml, don't sync.",
"if",
"not",
"self",
".",
"_config",
"[",
"CONF_FILTER",
"]",
".",
"empty_filter",
":",
"return",
"# If entity prefs are the same, don't sync.",
"if",
"(",
"self",
".",
"_cur_entity_prefs",
"is",
"prefs",
".",
"alexa_entity_configs",
"and",
"self",
".",
"_cur_default_expose",
"is",
"prefs",
".",
"alexa_default_expose",
")",
":",
"return",
"if",
"self",
".",
"_alexa_sync_unsub",
":",
"self",
".",
"_alexa_sync_unsub",
"(",
")",
"self",
".",
"_alexa_sync_unsub",
"=",
"None",
"if",
"self",
".",
"_cur_default_expose",
"is",
"not",
"prefs",
".",
"alexa_default_expose",
":",
"await",
"self",
".",
"async_sync_entities",
"(",
")",
"return",
"self",
".",
"_alexa_sync_unsub",
"=",
"async_call_later",
"(",
"self",
".",
"hass",
",",
"SYNC_DELAY",
",",
"self",
".",
"_sync_prefs",
")"
] | [
142,
4
] | [
176,
9
] | python | en | ['en', 'en', 'en'] | True |
AlexaConfig._sync_prefs | (self, _now) | Sync the updated preferences to Alexa. | Sync the updated preferences to Alexa. | async def _sync_prefs(self, _now):
"""Sync the updated preferences to Alexa."""
self._alexa_sync_unsub = None
old_prefs = self._cur_entity_prefs
new_prefs = self._prefs.alexa_entity_configs
seen = set()
to_update = []
to_remove = []
for entity_id, info in old_prefs.items():
seen.add(entity_id)
old_expose = info.get(PREF_SHOULD_EXPOSE)
if entity_id in new_prefs:
new_expose = new_prefs[entity_id].get(PREF_SHOULD_EXPOSE)
else:
new_expose = None
if old_expose == new_expose:
continue
if new_expose:
to_update.append(entity_id)
else:
to_remove.append(entity_id)
# Now all the ones that are in new prefs but never were in old prefs
for entity_id, info in new_prefs.items():
if entity_id in seen:
continue
new_expose = info.get(PREF_SHOULD_EXPOSE)
if new_expose is None:
continue
# Only test if we should expose. It can never be a remove action,
# as it didn't exist in old prefs object.
if new_expose:
to_update.append(entity_id)
# We only set the prefs when update is successful, that way we will
# retry when next change comes in.
if await self._sync_helper(to_update, to_remove):
self._cur_entity_prefs = new_prefs | [
"async",
"def",
"_sync_prefs",
"(",
"self",
",",
"_now",
")",
":",
"self",
".",
"_alexa_sync_unsub",
"=",
"None",
"old_prefs",
"=",
"self",
".",
"_cur_entity_prefs",
"new_prefs",
"=",
"self",
".",
"_prefs",
".",
"alexa_entity_configs",
"seen",
"=",
"set",
"(",
")",
"to_update",
"=",
"[",
"]",
"to_remove",
"=",
"[",
"]",
"for",
"entity_id",
",",
"info",
"in",
"old_prefs",
".",
"items",
"(",
")",
":",
"seen",
".",
"add",
"(",
"entity_id",
")",
"old_expose",
"=",
"info",
".",
"get",
"(",
"PREF_SHOULD_EXPOSE",
")",
"if",
"entity_id",
"in",
"new_prefs",
":",
"new_expose",
"=",
"new_prefs",
"[",
"entity_id",
"]",
".",
"get",
"(",
"PREF_SHOULD_EXPOSE",
")",
"else",
":",
"new_expose",
"=",
"None",
"if",
"old_expose",
"==",
"new_expose",
":",
"continue",
"if",
"new_expose",
":",
"to_update",
".",
"append",
"(",
"entity_id",
")",
"else",
":",
"to_remove",
".",
"append",
"(",
"entity_id",
")",
"# Now all the ones that are in new prefs but never were in old prefs",
"for",
"entity_id",
",",
"info",
"in",
"new_prefs",
".",
"items",
"(",
")",
":",
"if",
"entity_id",
"in",
"seen",
":",
"continue",
"new_expose",
"=",
"info",
".",
"get",
"(",
"PREF_SHOULD_EXPOSE",
")",
"if",
"new_expose",
"is",
"None",
":",
"continue",
"# Only test if we should expose. It can never be a remove action,",
"# as it didn't exist in old prefs object.",
"if",
"new_expose",
":",
"to_update",
".",
"append",
"(",
"entity_id",
")",
"# We only set the prefs when update is successful, that way we will",
"# retry when next change comes in.",
"if",
"await",
"self",
".",
"_sync_helper",
"(",
"to_update",
",",
"to_remove",
")",
":",
"self",
".",
"_cur_entity_prefs",
"=",
"new_prefs"
] | [
178,
4
] | [
223,
46
] | python | en | ['en', 'en', 'en'] | True |
AlexaConfig.async_sync_entities | (self) | Sync all entities to Alexa. | Sync all entities to Alexa. | async def async_sync_entities(self):
"""Sync all entities to Alexa."""
# Remove any pending sync
if self._alexa_sync_unsub:
self._alexa_sync_unsub()
self._alexa_sync_unsub = None
to_update = []
to_remove = []
for entity in alexa_entities.async_get_entities(self.hass, self):
if self.should_expose(entity.entity_id):
to_update.append(entity.entity_id)
else:
to_remove.append(entity.entity_id)
return await self._sync_helper(to_update, to_remove) | [
"async",
"def",
"async_sync_entities",
"(",
"self",
")",
":",
"# Remove any pending sync",
"if",
"self",
".",
"_alexa_sync_unsub",
":",
"self",
".",
"_alexa_sync_unsub",
"(",
")",
"self",
".",
"_alexa_sync_unsub",
"=",
"None",
"to_update",
"=",
"[",
"]",
"to_remove",
"=",
"[",
"]",
"for",
"entity",
"in",
"alexa_entities",
".",
"async_get_entities",
"(",
"self",
".",
"hass",
",",
"self",
")",
":",
"if",
"self",
".",
"should_expose",
"(",
"entity",
".",
"entity_id",
")",
":",
"to_update",
".",
"append",
"(",
"entity",
".",
"entity_id",
")",
"else",
":",
"to_remove",
".",
"append",
"(",
"entity",
".",
"entity_id",
")",
"return",
"await",
"self",
".",
"_sync_helper",
"(",
"to_update",
",",
"to_remove",
")"
] | [
225,
4
] | [
241,
60
] | python | en | ['en', 'mg', 'en'] | True |
AlexaConfig._sync_helper | (self, to_update, to_remove) | Sync entities to Alexa.
Return boolean if it was successful.
| Sync entities to Alexa. | async def _sync_helper(self, to_update, to_remove) -> bool:
"""Sync entities to Alexa.
Return boolean if it was successful.
"""
if not to_update and not to_remove:
return True
# Make sure it's valid.
await self.async_get_access_token()
tasks = []
if to_update:
tasks.append(
alexa_state_report.async_send_add_or_update_message(
self.hass, self, to_update
)
)
if to_remove:
tasks.append(
alexa_state_report.async_send_delete_message(self.hass, self, to_remove)
)
try:
with async_timeout.timeout(10):
await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED)
return True
except asyncio.TimeoutError:
_LOGGER.warning("Timeout trying to sync entities to Alexa")
return False
except aiohttp.ClientError as err:
_LOGGER.warning("Error trying to sync entities to Alexa: %s", err)
return False | [
"async",
"def",
"_sync_helper",
"(",
"self",
",",
"to_update",
",",
"to_remove",
")",
"->",
"bool",
":",
"if",
"not",
"to_update",
"and",
"not",
"to_remove",
":",
"return",
"True",
"# Make sure it's valid.",
"await",
"self",
".",
"async_get_access_token",
"(",
")",
"tasks",
"=",
"[",
"]",
"if",
"to_update",
":",
"tasks",
".",
"append",
"(",
"alexa_state_report",
".",
"async_send_add_or_update_message",
"(",
"self",
".",
"hass",
",",
"self",
",",
"to_update",
")",
")",
"if",
"to_remove",
":",
"tasks",
".",
"append",
"(",
"alexa_state_report",
".",
"async_send_delete_message",
"(",
"self",
".",
"hass",
",",
"self",
",",
"to_remove",
")",
")",
"try",
":",
"with",
"async_timeout",
".",
"timeout",
"(",
"10",
")",
":",
"await",
"asyncio",
".",
"wait",
"(",
"tasks",
",",
"return_when",
"=",
"asyncio",
".",
"ALL_COMPLETED",
")",
"return",
"True",
"except",
"asyncio",
".",
"TimeoutError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Timeout trying to sync entities to Alexa\"",
")",
"return",
"False",
"except",
"aiohttp",
".",
"ClientError",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error trying to sync entities to Alexa: %s\"",
",",
"err",
")",
"return",
"False"
] | [
243,
4
] | [
280,
24
] | python | en | ['en', 'el-Latn', 'en'] | True |
AlexaConfig._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
entity_id = event.data["entity_id"]
if not self.should_expose(entity_id):
return
action = event.data["action"]
to_update = []
to_remove = []
if action == "create":
to_update.append(entity_id)
elif action == "remove":
to_remove.append(entity_id)
elif action == "update" and bool(
set(event.data["changes"]) & entity_registry.ENTITY_DESCRIBING_ATTRIBUTES
):
to_update.append(entity_id)
if "old_entity_id" in event.data:
to_remove.append(event.data["old_entity_id"])
try:
await self._sync_helper(to_update, to_remove)
except alexa_errors.NoTokenAvailable:
pass | [
"async",
"def",
"_handle_entity_registry_updated",
"(",
"self",
",",
"event",
")",
":",
"if",
"not",
"self",
".",
"enabled",
"or",
"not",
"self",
".",
"_cloud",
".",
"is_logged_in",
":",
"return",
"entity_id",
"=",
"event",
".",
"data",
"[",
"\"entity_id\"",
"]",
"if",
"not",
"self",
".",
"should_expose",
"(",
"entity_id",
")",
":",
"return",
"action",
"=",
"event",
".",
"data",
"[",
"\"action\"",
"]",
"to_update",
"=",
"[",
"]",
"to_remove",
"=",
"[",
"]",
"if",
"action",
"==",
"\"create\"",
":",
"to_update",
".",
"append",
"(",
"entity_id",
")",
"elif",
"action",
"==",
"\"remove\"",
":",
"to_remove",
".",
"append",
"(",
"entity_id",
")",
"elif",
"action",
"==",
"\"update\"",
"and",
"bool",
"(",
"set",
"(",
"event",
".",
"data",
"[",
"\"changes\"",
"]",
")",
"&",
"entity_registry",
".",
"ENTITY_DESCRIBING_ATTRIBUTES",
")",
":",
"to_update",
".",
"append",
"(",
"entity_id",
")",
"if",
"\"old_entity_id\"",
"in",
"event",
".",
"data",
":",
"to_remove",
".",
"append",
"(",
"event",
".",
"data",
"[",
"\"old_entity_id\"",
"]",
")",
"try",
":",
"await",
"self",
".",
"_sync_helper",
"(",
"to_update",
",",
"to_remove",
")",
"except",
"alexa_errors",
".",
"NoTokenAvailable",
":",
"pass"
] | [
282,
4
] | [
310,
16
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up WeMo binary sensors. | Set up WeMo binary sensors. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up WeMo binary sensors."""
entities = []
async def _discovered_wemo(device):
"""Handle a discovered Wemo device."""
entity = WemoHumidifier(device)
entities.append(entity)
async_add_entities([entity])
async_dispatcher_connect(hass, f"{WEMO_DOMAIN}.fan", _discovered_wemo)
await asyncio.gather(
*[
_discovered_wemo(device)
for device in hass.data[WEMO_DOMAIN]["pending"].pop("fan")
]
)
def service_handle(service):
"""Handle the WeMo humidifier services."""
entity_ids = service.data.get(ATTR_ENTITY_ID)
humidifiers = [entity for entity in entities if entity.entity_id in entity_ids]
if service.service == SERVICE_SET_HUMIDITY:
target_humidity = service.data.get(ATTR_TARGET_HUMIDITY)
for humidifier in humidifiers:
humidifier.set_humidity(target_humidity)
elif service.service == SERVICE_RESET_FILTER_LIFE:
for humidifier in humidifiers:
humidifier.reset_filter_life()
# Register service(s)
hass.services.async_register(
WEMO_DOMAIN,
SERVICE_SET_HUMIDITY,
service_handle,
schema=SET_HUMIDITY_SCHEMA,
)
hass.services.async_register(
WEMO_DOMAIN,
SERVICE_RESET_FILTER_LIFE,
service_handle,
schema=RESET_FILTER_LIFE_SCHEMA,
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"[",
"]",
"async",
"def",
"_discovered_wemo",
"(",
"device",
")",
":",
"\"\"\"Handle a discovered Wemo device.\"\"\"",
"entity",
"=",
"WemoHumidifier",
"(",
"device",
")",
"entities",
".",
"append",
"(",
"entity",
")",
"async_add_entities",
"(",
"[",
"entity",
"]",
")",
"async_dispatcher_connect",
"(",
"hass",
",",
"f\"{WEMO_DOMAIN}.fan\"",
",",
"_discovered_wemo",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"_discovered_wemo",
"(",
"device",
")",
"for",
"device",
"in",
"hass",
".",
"data",
"[",
"WEMO_DOMAIN",
"]",
"[",
"\"pending\"",
"]",
".",
"pop",
"(",
"\"fan\"",
")",
"]",
")",
"def",
"service_handle",
"(",
"service",
")",
":",
"\"\"\"Handle the WeMo humidifier services.\"\"\"",
"entity_ids",
"=",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_ENTITY_ID",
")",
"humidifiers",
"=",
"[",
"entity",
"for",
"entity",
"in",
"entities",
"if",
"entity",
".",
"entity_id",
"in",
"entity_ids",
"]",
"if",
"service",
".",
"service",
"==",
"SERVICE_SET_HUMIDITY",
":",
"target_humidity",
"=",
"service",
".",
"data",
".",
"get",
"(",
"ATTR_TARGET_HUMIDITY",
")",
"for",
"humidifier",
"in",
"humidifiers",
":",
"humidifier",
".",
"set_humidity",
"(",
"target_humidity",
")",
"elif",
"service",
".",
"service",
"==",
"SERVICE_RESET_FILTER_LIFE",
":",
"for",
"humidifier",
"in",
"humidifiers",
":",
"humidifier",
".",
"reset_filter_life",
"(",
")",
"# Register service(s)",
"hass",
".",
"services",
".",
"async_register",
"(",
"WEMO_DOMAIN",
",",
"SERVICE_SET_HUMIDITY",
",",
"service_handle",
",",
"schema",
"=",
"SET_HUMIDITY_SCHEMA",
",",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"WEMO_DOMAIN",
",",
"SERVICE_RESET_FILTER_LIFE",
",",
"service_handle",
",",
"schema",
"=",
"RESET_FILTER_LIFE_SCHEMA",
",",
")"
] | [
95,
0
] | [
142,
5
] | python | en | ['en', 'bs', 'en'] | True |
WemoHumidifier.__init__ | (self, device) | Initialize the WeMo switch. | Initialize the WeMo switch. | def __init__(self, device):
"""Initialize the WeMo switch."""
self.wemo = device
self._state = None
self._available = True
self._update_lock = None
self._fan_mode = None
self._target_humidity = None
self._current_humidity = None
self._water_level = None
self._filter_life = None
self._filter_expired = None
self._last_fan_on_mode = WEMO_FAN_MEDIUM
self._model_name = self.wemo.model_name
self._name = self.wemo.name
self._serialnumber = self.wemo.serialnumber | [
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"wemo",
"=",
"device",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_available",
"=",
"True",
"self",
".",
"_update_lock",
"=",
"None",
"self",
".",
"_fan_mode",
"=",
"None",
"self",
".",
"_target_humidity",
"=",
"None",
"self",
".",
"_current_humidity",
"=",
"None",
"self",
".",
"_water_level",
"=",
"None",
"self",
".",
"_filter_life",
"=",
"None",
"self",
".",
"_filter_expired",
"=",
"None",
"self",
".",
"_last_fan_on_mode",
"=",
"WEMO_FAN_MEDIUM",
"self",
".",
"_model_name",
"=",
"self",
".",
"wemo",
".",
"model_name",
"self",
".",
"_name",
"=",
"self",
".",
"wemo",
".",
"name",
"self",
".",
"_serialnumber",
"=",
"self",
".",
"wemo",
".",
"serialnumber"
] | [
148,
4
] | [
163,
51
] | python | en | ['en', 'pl', 'en'] | True |
WemoHumidifier._subscription_callback | (self, _device, _type, _params) | Update the state by the Wemo device. | Update the state by the Wemo device. | def _subscription_callback(self, _device, _type, _params):
"""Update the state by the Wemo device."""
_LOGGER.info("Subscription update for %s", self.name)
updated = self.wemo.subscription_update(_type, _params)
self.hass.add_job(self._async_locked_subscription_callback(not updated)) | [
"def",
"_subscription_callback",
"(",
"self",
",",
"_device",
",",
"_type",
",",
"_params",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Subscription update for %s\"",
",",
"self",
".",
"name",
")",
"updated",
"=",
"self",
".",
"wemo",
".",
"subscription_update",
"(",
"_type",
",",
"_params",
")",
"self",
".",
"hass",
".",
"add_job",
"(",
"self",
".",
"_async_locked_subscription_callback",
"(",
"not",
"updated",
")",
")"
] | [
165,
4
] | [
169,
80
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier._async_locked_subscription_callback | (self, force_update) | Handle an update from a subscription. | Handle an update from a subscription. | async def _async_locked_subscription_callback(self, force_update):
"""Handle an update from a subscription."""
# If an update is in progress, we don't do anything
if self._update_lock.locked():
return
await self._async_locked_update(force_update)
self.async_write_ha_state() | [
"async",
"def",
"_async_locked_subscription_callback",
"(",
"self",
",",
"force_update",
")",
":",
"# If an update is in progress, we don't do anything",
"if",
"self",
".",
"_update_lock",
".",
"locked",
"(",
")",
":",
"return",
"await",
"self",
".",
"_async_locked_update",
"(",
"force_update",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
171,
4
] | [
178,
35
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.unique_id | (self) | Return the ID of this WeMo humidifier. | Return the ID of this WeMo humidifier. | def unique_id(self):
"""Return the ID of this WeMo humidifier."""
return self._serialnumber | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_serialnumber"
] | [
181,
4
] | [
183,
33
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.name | (self) | Return the name of the humidifier if any. | Return the name of the humidifier if any. | def name(self):
"""Return the name of the humidifier if any."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
186,
4
] | [
188,
25
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.is_on | (self) | Return true if switch is on. Standby is on. | Return true if switch is on. Standby is on. | def is_on(self):
"""Return true if switch is on. Standby is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
191,
4
] | [
193,
26
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.available | (self) | Return true if switch is available. | Return true if switch is available. | def available(self):
"""Return true if switch is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
196,
4
] | [
198,
30
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.device_info | (self) | Return the device info. | Return the device info. | def device_info(self):
"""Return the device info."""
return {
"name": self._name,
"identifiers": {(WEMO_DOMAIN, self._serialnumber)},
"model": self._model_name,
"manufacturer": "Belkin",
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"name\"",
":",
"self",
".",
"_name",
",",
"\"identifiers\"",
":",
"{",
"(",
"WEMO_DOMAIN",
",",
"self",
".",
"_serialnumber",
")",
"}",
",",
"\"model\"",
":",
"self",
".",
"_model_name",
",",
"\"manufacturer\"",
":",
"\"Belkin\"",
",",
"}"
] | [
201,
4
] | [
208,
9
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.icon | (self) | Return the icon of device based on its type. | Return the icon of device based on its type. | def icon(self):
"""Return the icon of device based on its type."""
return "mdi:water-percent" | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"\"mdi:water-percent\""
] | [
211,
4
] | [
213,
34
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.device_state_attributes | (self) | Return device specific state attributes. | Return device specific state attributes. | def device_state_attributes(self):
"""Return device specific state attributes."""
return {
ATTR_CURRENT_HUMIDITY: self._current_humidity,
ATTR_TARGET_HUMIDITY: self._target_humidity,
ATTR_FAN_MODE: self._fan_mode,
ATTR_WATER_LEVEL: self._water_level,
ATTR_FILTER_LIFE: self._filter_life,
ATTR_FILTER_EXPIRED: self._filter_expired,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_CURRENT_HUMIDITY",
":",
"self",
".",
"_current_humidity",
",",
"ATTR_TARGET_HUMIDITY",
":",
"self",
".",
"_target_humidity",
",",
"ATTR_FAN_MODE",
":",
"self",
".",
"_fan_mode",
",",
"ATTR_WATER_LEVEL",
":",
"self",
".",
"_water_level",
",",
"ATTR_FILTER_LIFE",
":",
"self",
".",
"_filter_life",
",",
"ATTR_FILTER_EXPIRED",
":",
"self",
".",
"_filter_expired",
",",
"}"
] | [
216,
4
] | [
225,
9
] | python | en | ['fr', 'en', 'en'] | True |
WemoHumidifier.speed | (self) | Return the current speed. | Return the current speed. | def speed(self) -> str:
"""Return the current speed."""
return WEMO_FAN_SPEED_TO_HASS.get(self._fan_mode) | [
"def",
"speed",
"(",
"self",
")",
"->",
"str",
":",
"return",
"WEMO_FAN_SPEED_TO_HASS",
".",
"get",
"(",
"self",
".",
"_fan_mode",
")"
] | [
228,
4
] | [
230,
57
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.speed_list | (self) | Get the list of available speeds. | Get the list of available speeds. | def speed_list(self) -> list:
"""Get the list of available speeds."""
return SUPPORTED_SPEEDS | [
"def",
"speed_list",
"(",
"self",
")",
"->",
"list",
":",
"return",
"SUPPORTED_SPEEDS"
] | [
233,
4
] | [
235,
31
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORTED_FEATURES | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"SUPPORTED_FEATURES"
] | [
238,
4
] | [
240,
33
] | python | en | ['da', 'en', 'en'] | True |
WemoHumidifier.async_added_to_hass | (self) | Wemo humidifier added to Home Assistant. | Wemo humidifier added to Home Assistant. | async def async_added_to_hass(self):
"""Wemo humidifier added to Home Assistant."""
# Define inside async context so we know our event loop
self._update_lock = asyncio.Lock()
registry = self.hass.data[WEMO_DOMAIN]["registry"]
await self.hass.async_add_executor_job(registry.register, self.wemo)
registry.on(self.wemo, None, self._subscription_callback) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"# Define inside async context so we know our event loop",
"self",
".",
"_update_lock",
"=",
"asyncio",
".",
"Lock",
"(",
")",
"registry",
"=",
"self",
".",
"hass",
".",
"data",
"[",
"WEMO_DOMAIN",
"]",
"[",
"\"registry\"",
"]",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"registry",
".",
"register",
",",
"self",
".",
"wemo",
")",
"registry",
".",
"on",
"(",
"self",
".",
"wemo",
",",
"None",
",",
"self",
".",
"_subscription_callback",
")"
] | [
242,
4
] | [
249,
65
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.async_update | (self) | Update WeMo state.
Wemo has an aggressive retry logic that sometimes can take over a
minute to return. If we don't get a state after 5 seconds, assume the
Wemo humidifier is unreachable. If update goes through, it will be made
available again.
| Update WeMo state. | async def async_update(self):
"""Update WeMo state.
Wemo has an aggressive retry logic that sometimes can take over a
minute to return. If we don't get a state after 5 seconds, assume the
Wemo humidifier is unreachable. If update goes through, it will be made
available again.
"""
# If an update is in progress, we don't do anything
if self._update_lock.locked():
return
try:
with async_timeout.timeout(5):
await asyncio.shield(self._async_locked_update(True))
except asyncio.TimeoutError:
_LOGGER.warning("Lost connection to %s", self.name)
self._available = False | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"# If an update is in progress, we don't do anything",
"if",
"self",
".",
"_update_lock",
".",
"locked",
"(",
")",
":",
"return",
"try",
":",
"with",
"async_timeout",
".",
"timeout",
"(",
"5",
")",
":",
"await",
"asyncio",
".",
"shield",
"(",
"self",
".",
"_async_locked_update",
"(",
"True",
")",
")",
"except",
"asyncio",
".",
"TimeoutError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Lost connection to %s\"",
",",
"self",
".",
"name",
")",
"self",
".",
"_available",
"=",
"False"
] | [
251,
4
] | [
268,
35
] | python | en | ['en', 'sn', 'en'] | True |
WemoHumidifier._async_locked_update | (self, force_update) | Try updating within an async lock. | Try updating within an async lock. | async def _async_locked_update(self, force_update):
"""Try updating within an async lock."""
async with self._update_lock:
await self.hass.async_add_executor_job(self._update, force_update) | [
"async",
"def",
"_async_locked_update",
"(",
"self",
",",
"force_update",
")",
":",
"async",
"with",
"self",
".",
"_update_lock",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_update",
",",
"force_update",
")"
] | [
270,
4
] | [
273,
78
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier._update | (self, force_update=True) | Update the device state. | Update the device state. | def _update(self, force_update=True):
"""Update the device state."""
try:
self._state = self.wemo.get_state(force_update)
self._fan_mode = self.wemo.fan_mode_string
self._target_humidity = self.wemo.desired_humidity_percent
self._current_humidity = self.wemo.current_humidity_percent
self._water_level = self.wemo.water_level_string
self._filter_life = self.wemo.filter_life_percent
self._filter_expired = self.wemo.filter_expired
if self.wemo.fan_mode != WEMO_FAN_OFF:
self._last_fan_on_mode = self.wemo.fan_mode
if not self._available:
_LOGGER.info("Reconnected to %s", self.name)
self._available = True
except (AttributeError, ActionException) as err:
_LOGGER.warning("Could not update status for %s (%s)", self.name, err)
self._available = False
self.wemo.reconnect_with_device() | [
"def",
"_update",
"(",
"self",
",",
"force_update",
"=",
"True",
")",
":",
"try",
":",
"self",
".",
"_state",
"=",
"self",
".",
"wemo",
".",
"get_state",
"(",
"force_update",
")",
"self",
".",
"_fan_mode",
"=",
"self",
".",
"wemo",
".",
"fan_mode_string",
"self",
".",
"_target_humidity",
"=",
"self",
".",
"wemo",
".",
"desired_humidity_percent",
"self",
".",
"_current_humidity",
"=",
"self",
".",
"wemo",
".",
"current_humidity_percent",
"self",
".",
"_water_level",
"=",
"self",
".",
"wemo",
".",
"water_level_string",
"self",
".",
"_filter_life",
"=",
"self",
".",
"wemo",
".",
"filter_life_percent",
"self",
".",
"_filter_expired",
"=",
"self",
".",
"wemo",
".",
"filter_expired",
"if",
"self",
".",
"wemo",
".",
"fan_mode",
"!=",
"WEMO_FAN_OFF",
":",
"self",
".",
"_last_fan_on_mode",
"=",
"self",
".",
"wemo",
".",
"fan_mode",
"if",
"not",
"self",
".",
"_available",
":",
"_LOGGER",
".",
"info",
"(",
"\"Reconnected to %s\"",
",",
"self",
".",
"name",
")",
"self",
".",
"_available",
"=",
"True",
"except",
"(",
"AttributeError",
",",
"ActionException",
")",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Could not update status for %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"wemo",
".",
"reconnect_with_device",
"(",
")"
] | [
275,
4
] | [
296,
45
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.turn_on | (self, speed: str = None, **kwargs) | Turn the switch on. | Turn the switch on. | def turn_on(self, speed: str = None, **kwargs) -> None:
"""Turn the switch on."""
if speed is None:
try:
self.wemo.set_state(self._last_fan_on_mode)
except ActionException as err:
_LOGGER.warning("Error while turning on device %s (%s)", self.name, err)
self._available = False
else:
self.set_speed(speed)
self.schedule_update_ha_state() | [
"def",
"turn_on",
"(",
"self",
",",
"speed",
":",
"str",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"if",
"speed",
"is",
"None",
":",
"try",
":",
"self",
".",
"wemo",
".",
"set_state",
"(",
"self",
".",
"_last_fan_on_mode",
")",
"except",
"ActionException",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error while turning on device %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"else",
":",
"self",
".",
"set_speed",
"(",
"speed",
")",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
298,
4
] | [
309,
39
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | def turn_off(self, **kwargs) -> None:
"""Turn the switch off."""
try:
self.wemo.set_state(WEMO_FAN_OFF)
except ActionException as err:
_LOGGER.warning("Error while turning off device %s (%s)", self.name, err)
self._available = False
self.schedule_update_ha_state() | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
"->",
"None",
":",
"try",
":",
"self",
".",
"wemo",
".",
"set_state",
"(",
"WEMO_FAN_OFF",
")",
"except",
"ActionException",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error while turning off device %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
311,
4
] | [
319,
39
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.set_speed | (self, speed: str) | Set the fan_mode of the Humidifier. | Set the fan_mode of the Humidifier. | def set_speed(self, speed: str) -> None:
"""Set the fan_mode of the Humidifier."""
try:
self.wemo.set_state(HASS_FAN_SPEED_TO_WEMO.get(speed))
except ActionException as err:
_LOGGER.warning(
"Error while setting speed of device %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state() | [
"def",
"set_speed",
"(",
"self",
",",
"speed",
":",
"str",
")",
"->",
"None",
":",
"try",
":",
"self",
".",
"wemo",
".",
"set_state",
"(",
"HASS_FAN_SPEED_TO_WEMO",
".",
"get",
"(",
"speed",
")",
")",
"except",
"ActionException",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error while setting speed of device %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
321,
4
] | [
331,
39
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.set_humidity | (self, humidity: float) | Set the target humidity level for the Humidifier. | Set the target humidity level for the Humidifier. | def set_humidity(self, humidity: float) -> None:
"""Set the target humidity level for the Humidifier."""
if humidity < 50:
target_humidity = WEMO_HUMIDITY_45
elif 50 <= humidity < 55:
target_humidity = WEMO_HUMIDITY_50
elif 55 <= humidity < 60:
target_humidity = WEMO_HUMIDITY_55
elif 60 <= humidity < 100:
target_humidity = WEMO_HUMIDITY_60
elif humidity >= 100:
target_humidity = WEMO_HUMIDITY_100
try:
self.wemo.set_humidity(target_humidity)
except ActionException as err:
_LOGGER.warning(
"Error while setting humidity of device: %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state() | [
"def",
"set_humidity",
"(",
"self",
",",
"humidity",
":",
"float",
")",
"->",
"None",
":",
"if",
"humidity",
"<",
"50",
":",
"target_humidity",
"=",
"WEMO_HUMIDITY_45",
"elif",
"50",
"<=",
"humidity",
"<",
"55",
":",
"target_humidity",
"=",
"WEMO_HUMIDITY_50",
"elif",
"55",
"<=",
"humidity",
"<",
"60",
":",
"target_humidity",
"=",
"WEMO_HUMIDITY_55",
"elif",
"60",
"<=",
"humidity",
"<",
"100",
":",
"target_humidity",
"=",
"WEMO_HUMIDITY_60",
"elif",
"humidity",
">=",
"100",
":",
"target_humidity",
"=",
"WEMO_HUMIDITY_100",
"try",
":",
"self",
".",
"wemo",
".",
"set_humidity",
"(",
"target_humidity",
")",
"except",
"ActionException",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error while setting humidity of device: %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
333,
4
] | [
354,
39
] | python | en | ['en', 'en', 'en'] | True |
WemoHumidifier.reset_filter_life | (self) | Reset the filter life to 100%. | Reset the filter life to 100%. | def reset_filter_life(self) -> None:
"""Reset the filter life to 100%."""
try:
self.wemo.reset_filter_life()
except ActionException as err:
_LOGGER.warning(
"Error while resetting filter life on device: %s (%s)", self.name, err
)
self._available = False
self.schedule_update_ha_state() | [
"def",
"reset_filter_life",
"(",
"self",
")",
"->",
"None",
":",
"try",
":",
"self",
".",
"wemo",
".",
"reset_filter_life",
"(",
")",
"except",
"ActionException",
"as",
"err",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Error while resetting filter life on device: %s (%s)\"",
",",
"self",
".",
"name",
",",
"err",
")",
"self",
".",
"_available",
"=",
"False",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
356,
4
] | [
366,
39
] | python | en | ['en', 'en', 'en'] | True |
register_device | (hass, api_key, name, device_id, device_ids, device_names) | Register services for each join device listed. | Register services for each join device listed. | def register_device(hass, api_key, name, device_id, device_ids, device_names):
"""Register services for each join device listed."""
def ring_service(service):
"""Service to ring devices."""
ring_device(
api_key=api_key,
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
)
def set_wallpaper_service(service):
"""Service to set wallpaper on devices."""
set_wallpaper(
api_key=api_key,
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
url=service.data.get("url"),
)
def send_file_service(service):
"""Service to send files to devices."""
send_file(
api_key=api_key,
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
url=service.data.get("url"),
)
def send_url_service(service):
"""Service to open url on devices."""
send_url(
api_key=api_key,
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
url=service.data.get("url"),
)
def send_tasker_service(service):
"""Service to open url on devices."""
send_notification(
api_key=api_key,
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
text=service.data.get("command"),
)
def send_sms_service(service):
"""Service to send sms from devices."""
send_sms(
device_id=device_id,
device_ids=device_ids,
device_names=device_names,
sms_number=service.data.get("number"),
sms_text=service.data.get("message"),
api_key=api_key,
)
hass.services.register(DOMAIN, f"{name}ring", ring_service)
hass.services.register(DOMAIN, f"{name}set_wallpaper", set_wallpaper_service)
hass.services.register(DOMAIN, f"{name}send_sms", send_sms_service)
hass.services.register(DOMAIN, f"{name}send_file", send_file_service)
hass.services.register(DOMAIN, f"{name}send_url", send_url_service)
hass.services.register(DOMAIN, f"{name}send_tasker", send_tasker_service) | [
"def",
"register_device",
"(",
"hass",
",",
"api_key",
",",
"name",
",",
"device_id",
",",
"device_ids",
",",
"device_names",
")",
":",
"def",
"ring_service",
"(",
"service",
")",
":",
"\"\"\"Service to ring devices.\"\"\"",
"ring_device",
"(",
"api_key",
"=",
"api_key",
",",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
")",
"def",
"set_wallpaper_service",
"(",
"service",
")",
":",
"\"\"\"Service to set wallpaper on devices.\"\"\"",
"set_wallpaper",
"(",
"api_key",
"=",
"api_key",
",",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
"url",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"url\"",
")",
",",
")",
"def",
"send_file_service",
"(",
"service",
")",
":",
"\"\"\"Service to send files to devices.\"\"\"",
"send_file",
"(",
"api_key",
"=",
"api_key",
",",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
"url",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"url\"",
")",
",",
")",
"def",
"send_url_service",
"(",
"service",
")",
":",
"\"\"\"Service to open url on devices.\"\"\"",
"send_url",
"(",
"api_key",
"=",
"api_key",
",",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
"url",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"url\"",
")",
",",
")",
"def",
"send_tasker_service",
"(",
"service",
")",
":",
"\"\"\"Service to open url on devices.\"\"\"",
"send_notification",
"(",
"api_key",
"=",
"api_key",
",",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
"text",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"command\"",
")",
",",
")",
"def",
"send_sms_service",
"(",
"service",
")",
":",
"\"\"\"Service to send sms from devices.\"\"\"",
"send_sms",
"(",
"device_id",
"=",
"device_id",
",",
"device_ids",
"=",
"device_ids",
",",
"device_names",
"=",
"device_names",
",",
"sms_number",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"number\"",
")",
",",
"sms_text",
"=",
"service",
".",
"data",
".",
"get",
"(",
"\"message\"",
")",
",",
"api_key",
"=",
"api_key",
",",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}ring\"",
",",
"ring_service",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}set_wallpaper\"",
",",
"set_wallpaper_service",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}send_sms\"",
",",
"send_sms_service",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}send_file\"",
",",
"send_file_service",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}send_url\"",
",",
"send_url_service",
")",
"hass",
".",
"services",
".",
"register",
"(",
"DOMAIN",
",",
"f\"{name}send_tasker\"",
",",
"send_tasker_service",
")"
] | [
44,
0
] | [
112,
77
] | python | en | ['en', 'en', 'en'] | True |
setup | (hass, config) | Set up the Join services. | Set up the Join services. | def setup(hass, config):
"""Set up the Join services."""
for device in config[DOMAIN]:
api_key = device.get(CONF_API_KEY)
device_id = device.get(CONF_DEVICE_ID)
device_ids = device.get(CONF_DEVICE_IDS)
device_names = device.get(CONF_DEVICE_NAMES)
name = device.get(CONF_NAME)
name = f"{name.lower().replace(' ', '_')}_" if name else ""
if api_key:
if not get_devices(api_key):
_LOGGER.error("Error connecting to Join, check API key")
return False
if device_id is None and device_ids is None and device_names is None:
_LOGGER.error(
"No device was provided. Please specify device_id"
", device_ids, or device_names"
)
return False
register_device(hass, api_key, name, device_id, device_ids, device_names)
return True | [
"def",
"setup",
"(",
"hass",
",",
"config",
")",
":",
"for",
"device",
"in",
"config",
"[",
"DOMAIN",
"]",
":",
"api_key",
"=",
"device",
".",
"get",
"(",
"CONF_API_KEY",
")",
"device_id",
"=",
"device",
".",
"get",
"(",
"CONF_DEVICE_ID",
")",
"device_ids",
"=",
"device",
".",
"get",
"(",
"CONF_DEVICE_IDS",
")",
"device_names",
"=",
"device",
".",
"get",
"(",
"CONF_DEVICE_NAMES",
")",
"name",
"=",
"device",
".",
"get",
"(",
"CONF_NAME",
")",
"name",
"=",
"f\"{name.lower().replace(' ', '_')}_\"",
"if",
"name",
"else",
"\"\"",
"if",
"api_key",
":",
"if",
"not",
"get_devices",
"(",
"api_key",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Error connecting to Join, check API key\"",
")",
"return",
"False",
"if",
"device_id",
"is",
"None",
"and",
"device_ids",
"is",
"None",
"and",
"device_names",
"is",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"No device was provided. Please specify device_id\"",
"\", device_ids, or device_names\"",
")",
"return",
"False",
"register_device",
"(",
"hass",
",",
"api_key",
",",
"name",
",",
"device_id",
",",
"device_ids",
",",
"device_names",
")",
"return",
"True"
] | [
115,
0
] | [
137,
15
] | python | en | ['en', 'en', 'en'] | True |
Channels.__init__ | (self, zha_device: zha_typing.ZhaDeviceType) | Initialize instance. | Initialize instance. | def __init__(self, zha_device: zha_typing.ZhaDeviceType) -> None:
"""Initialize instance."""
self._pools: List[zha_typing.ChannelPoolType] = []
self._power_config = None
self._identify = None
self._semaphore = asyncio.Semaphore(3)
self._unique_id = str(zha_device.ieee)
self._zdo_channel = base.ZDOChannel(zha_device.device.endpoints[0], zha_device)
self._zha_device = zha_device | [
"def",
"__init__",
"(",
"self",
",",
"zha_device",
":",
"zha_typing",
".",
"ZhaDeviceType",
")",
"->",
"None",
":",
"self",
".",
"_pools",
":",
"List",
"[",
"zha_typing",
".",
"ChannelPoolType",
"]",
"=",
"[",
"]",
"self",
".",
"_power_config",
"=",
"None",
"self",
".",
"_identify",
"=",
"None",
"self",
".",
"_semaphore",
"=",
"asyncio",
".",
"Semaphore",
"(",
"3",
")",
"self",
".",
"_unique_id",
"=",
"str",
"(",
"zha_device",
".",
"ieee",
")",
"self",
".",
"_zdo_channel",
"=",
"base",
".",
"ZDOChannel",
"(",
"zha_device",
".",
"device",
".",
"endpoints",
"[",
"0",
"]",
",",
"zha_device",
")",
"self",
".",
"_zha_device",
"=",
"zha_device"
] | [
38,
4
] | [
46,
37
] | python | en | ['en', 'en', 'it'] | False |
Channels.pools | (self) | Return channel pools list. | Return channel pools list. | def pools(self) -> List["ChannelPool"]:
"""Return channel pools list."""
return self._pools | [
"def",
"pools",
"(",
"self",
")",
"->",
"List",
"[",
"\"ChannelPool\"",
"]",
":",
"return",
"self",
".",
"_pools"
] | [
49,
4
] | [
51,
26
] | python | en | ['it', 'et', 'en'] | False |
Channels.power_configuration_ch | (self) | Return power configuration channel. | Return power configuration channel. | def power_configuration_ch(self) -> zha_typing.ChannelType:
"""Return power configuration channel."""
return self._power_config | [
"def",
"power_configuration_ch",
"(",
"self",
")",
"->",
"zha_typing",
".",
"ChannelType",
":",
"return",
"self",
".",
"_power_config"
] | [
54,
4
] | [
56,
33
] | python | en | ['en', 'fr', 'en'] | True |
Channels.power_configuration_ch | (self, channel: zha_typing.ChannelType) | Power configuration channel setter. | Power configuration channel setter. | def power_configuration_ch(self, channel: zha_typing.ChannelType) -> None:
"""Power configuration channel setter."""
if self._power_config is None:
self._power_config = channel | [
"def",
"power_configuration_ch",
"(",
"self",
",",
"channel",
":",
"zha_typing",
".",
"ChannelType",
")",
"->",
"None",
":",
"if",
"self",
".",
"_power_config",
"is",
"None",
":",
"self",
".",
"_power_config",
"=",
"channel"
] | [
59,
4
] | [
62,
40
] | python | en | ['it', 'fr', 'en'] | False |
Channels.identify_ch | (self) | Return power configuration channel. | Return power configuration channel. | def identify_ch(self) -> zha_typing.ChannelType:
"""Return power configuration channel."""
return self._identify | [
"def",
"identify_ch",
"(",
"self",
")",
"->",
"zha_typing",
".",
"ChannelType",
":",
"return",
"self",
".",
"_identify"
] | [
65,
4
] | [
67,
29
] | python | en | ['en', 'fr', 'en'] | True |
Channels.identify_ch | (self, channel: zha_typing.ChannelType) | Power configuration channel setter. | Power configuration channel setter. | def identify_ch(self, channel: zha_typing.ChannelType) -> None:
"""Power configuration channel setter."""
if self._identify is None:
self._identify = channel | [
"def",
"identify_ch",
"(",
"self",
",",
"channel",
":",
"zha_typing",
".",
"ChannelType",
")",
"->",
"None",
":",
"if",
"self",
".",
"_identify",
"is",
"None",
":",
"self",
".",
"_identify",
"=",
"channel"
] | [
70,
4
] | [
73,
36
] | python | en | ['it', 'fr', 'en'] | False |
Channels.semaphore | (self) | Return semaphore for concurrent tasks. | Return semaphore for concurrent tasks. | def semaphore(self) -> asyncio.Semaphore:
"""Return semaphore for concurrent tasks."""
return self._semaphore | [
"def",
"semaphore",
"(",
"self",
")",
"->",
"asyncio",
".",
"Semaphore",
":",
"return",
"self",
".",
"_semaphore"
] | [
76,
4
] | [
78,
30
] | python | en | ['en', 'no', 'en'] | True |
Channels.zdo_channel | (self) | Return ZDO channel. | Return ZDO channel. | def zdo_channel(self) -> zha_typing.ZDOChannelType:
"""Return ZDO channel."""
return self._zdo_channel | [
"def",
"zdo_channel",
"(",
"self",
")",
"->",
"zha_typing",
".",
"ZDOChannelType",
":",
"return",
"self",
".",
"_zdo_channel"
] | [
81,
4
] | [
83,
32
] | python | en | ['en', 'kk', 'en'] | True |
Channels.zha_device | (self) | Return parent zha device. | Return parent zha device. | def zha_device(self) -> zha_typing.ZhaDeviceType:
"""Return parent zha device."""
return self._zha_device | [
"def",
"zha_device",
"(",
"self",
")",
"->",
"zha_typing",
".",
"ZhaDeviceType",
":",
"return",
"self",
".",
"_zha_device"
] | [
86,
4
] | [
88,
31
] | python | br | ['br', 'fr', 'en'] | False |
Channels.unique_id | (self) | Return the unique id for this channel. | Return the unique id for this channel. | def unique_id(self):
"""Return the unique id for this channel."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
91,
4
] | [
93,
30
] | python | en | ['en', 'en', 'en'] | True |
Channels.zigbee_signature | (self) | Get the zigbee signatures for the pools in channels. | Get the zigbee signatures for the pools in channels. | def zigbee_signature(self) -> Dict[int, Dict[str, Any]]:
"""Get the zigbee signatures for the pools in channels."""
return {
signature[0]: signature[1]
for signature in [pool.zigbee_signature for pool in self.pools]
} | [
"def",
"zigbee_signature",
"(",
"self",
")",
"->",
"Dict",
"[",
"int",
",",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
":",
"return",
"{",
"signature",
"[",
"0",
"]",
":",
"signature",
"[",
"1",
"]",
"for",
"signature",
"in",
"[",
"pool",
".",
"zigbee_signature",
"for",
"pool",
"in",
"self",
".",
"pools",
"]",
"}"
] | [
96,
4
] | [
101,
9
] | python | en | ['en', 'en', 'en'] | True |
Channels.new | (cls, zha_device: zha_typing.ZhaDeviceType) | Create new instance. | Create new instance. | def new(cls, zha_device: zha_typing.ZhaDeviceType) -> "Channels":
"""Create new instance."""
channels = cls(zha_device)
for ep_id in sorted(zha_device.device.endpoints):
channels.add_pool(ep_id)
return channels | [
"def",
"new",
"(",
"cls",
",",
"zha_device",
":",
"zha_typing",
".",
"ZhaDeviceType",
")",
"->",
"\"Channels\"",
":",
"channels",
"=",
"cls",
"(",
"zha_device",
")",
"for",
"ep_id",
"in",
"sorted",
"(",
"zha_device",
".",
"device",
".",
"endpoints",
")",
":",
"channels",
".",
"add_pool",
"(",
"ep_id",
")",
"return",
"channels"
] | [
104,
4
] | [
109,
23
] | python | en | ['en', 'en', 'en'] | True |
Channels.add_pool | (self, ep_id: int) | Add channels for a specific endpoint. | Add channels for a specific endpoint. | def add_pool(self, ep_id: int) -> None:
"""Add channels for a specific endpoint."""
if ep_id == 0:
return
self._pools.append(ChannelPool.new(self, ep_id)) | [
"def",
"add_pool",
"(",
"self",
",",
"ep_id",
":",
"int",
")",
"->",
"None",
":",
"if",
"ep_id",
"==",
"0",
":",
"return",
"self",
".",
"_pools",
".",
"append",
"(",
"ChannelPool",
".",
"new",
"(",
"self",
",",
"ep_id",
")",
")"
] | [
111,
4
] | [
115,
56
] | python | en | ['en', 'en', 'en'] | True |
Channels.async_initialize | (self, from_cache: bool = False) | Initialize claimed channels. | Initialize claimed channels. | async def async_initialize(self, from_cache: bool = False) -> None:
"""Initialize claimed channels."""
await self.zdo_channel.async_initialize(from_cache)
self.zdo_channel.debug("'async_initialize' stage succeeded")
await asyncio.gather(
*(pool.async_initialize(from_cache) for pool in self.pools)
) | [
"async",
"def",
"async_initialize",
"(",
"self",
",",
"from_cache",
":",
"bool",
"=",
"False",
")",
"->",
"None",
":",
"await",
"self",
".",
"zdo_channel",
".",
"async_initialize",
"(",
"from_cache",
")",
"self",
".",
"zdo_channel",
".",
"debug",
"(",
"\"'async_initialize' stage succeeded\"",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"pool",
".",
"async_initialize",
"(",
"from_cache",
")",
"for",
"pool",
"in",
"self",
".",
"pools",
")",
")"
] | [
117,
4
] | [
123,
9
] | python | en | ['sv', 'en', 'en'] | True |
Channels.async_configure | (self) | Configure claimed channels. | Configure claimed channels. | async def async_configure(self) -> None:
"""Configure claimed channels."""
await self.zdo_channel.async_configure()
self.zdo_channel.debug("'async_configure' stage succeeded")
await asyncio.gather(*(pool.async_configure() for pool in self.pools)) | [
"async",
"def",
"async_configure",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"zdo_channel",
".",
"async_configure",
"(",
")",
"self",
".",
"zdo_channel",
".",
"debug",
"(",
"\"'async_configure' stage succeeded\"",
")",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"pool",
".",
"async_configure",
"(",
")",
"for",
"pool",
"in",
"self",
".",
"pools",
")",
")"
] | [
125,
4
] | [
129,
78
] | python | en | ['sv', 'en', 'en'] | True |
Channels.async_new_entity | (
self,
component: str,
entity_class: zha_typing.CALLABLE_T,
unique_id: str,
channels: List[zha_typing.ChannelType],
) | Signal new entity addition. | Signal new entity addition. | def async_new_entity(
self,
component: str,
entity_class: zha_typing.CALLABLE_T,
unique_id: str,
channels: List[zha_typing.ChannelType],
):
"""Signal new entity addition."""
if self.zha_device.status == zha_core_device.DeviceStatus.INITIALIZED:
return
self.zha_device.hass.data[const.DATA_ZHA][component].append(
(entity_class, (unique_id, self.zha_device, channels))
) | [
"def",
"async_new_entity",
"(",
"self",
",",
"component",
":",
"str",
",",
"entity_class",
":",
"zha_typing",
".",
"CALLABLE_T",
",",
"unique_id",
":",
"str",
",",
"channels",
":",
"List",
"[",
"zha_typing",
".",
"ChannelType",
"]",
",",
")",
":",
"if",
"self",
".",
"zha_device",
".",
"status",
"==",
"zha_core_device",
".",
"DeviceStatus",
".",
"INITIALIZED",
":",
"return",
"self",
".",
"zha_device",
".",
"hass",
".",
"data",
"[",
"const",
".",
"DATA_ZHA",
"]",
"[",
"component",
"]",
".",
"append",
"(",
"(",
"entity_class",
",",
"(",
"unique_id",
",",
"self",
".",
"zha_device",
",",
"channels",
")",
")",
")"
] | [
132,
4
] | [
145,
9
] | python | en | ['en', 'cy', 'en'] | True |
Channels.async_send_signal | (self, signal: str, *args: Any) | Send a signal through hass dispatcher. | Send a signal through hass dispatcher. | def async_send_signal(self, signal: str, *args: Any) -> None:
"""Send a signal through hass dispatcher."""
async_dispatcher_send(self.zha_device.hass, signal, *args) | [
"def",
"async_send_signal",
"(",
"self",
",",
"signal",
":",
"str",
",",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"async_dispatcher_send",
"(",
"self",
".",
"zha_device",
".",
"hass",
",",
"signal",
",",
"*",
"args",
")"
] | [
148,
4
] | [
150,
66
] | python | en | ['en', 'lb', 'en'] | True |
Channels.zha_send_event | (self, event_data: Dict[str, Union[str, int]]) | Relay events to hass. | Relay events to hass. | def zha_send_event(self, event_data: Dict[str, Union[str, int]]) -> None:
"""Relay events to hass."""
self.zha_device.hass.bus.async_fire(
"zha_event",
{
const.ATTR_DEVICE_IEEE: str(self.zha_device.ieee),
const.ATTR_UNIQUE_ID: self.unique_id,
ATTR_DEVICE_ID: self.zha_device.device_id,
**event_data,
},
) | [
"def",
"zha_send_event",
"(",
"self",
",",
"event_data",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"str",
",",
"int",
"]",
"]",
")",
"->",
"None",
":",
"self",
".",
"zha_device",
".",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"\"zha_event\"",
",",
"{",
"const",
".",
"ATTR_DEVICE_IEEE",
":",
"str",
"(",
"self",
".",
"zha_device",
".",
"ieee",
")",
",",
"const",
".",
"ATTR_UNIQUE_ID",
":",
"self",
".",
"unique_id",
",",
"ATTR_DEVICE_ID",
":",
"self",
".",
"zha_device",
".",
"device_id",
",",
"*",
"*",
"event_data",
",",
"}",
",",
")"
] | [
153,
4
] | [
163,
9
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.__init__ | (self, channels: Channels, ep_id: int) | Initialize instance. | Initialize instance. | def __init__(self, channels: Channels, ep_id: int):
"""Initialize instance."""
self._all_channels: ChannelsDict = {}
self._channels: Channels = channels
self._claimed_channels: ChannelsDict = {}
self._id: int = ep_id
self._client_channels: Dict[str, zha_typing.ClientChannelType] = {}
self._unique_id: str = f"{channels.unique_id}-{ep_id}" | [
"def",
"__init__",
"(",
"self",
",",
"channels",
":",
"Channels",
",",
"ep_id",
":",
"int",
")",
":",
"self",
".",
"_all_channels",
":",
"ChannelsDict",
"=",
"{",
"}",
"self",
".",
"_channels",
":",
"Channels",
"=",
"channels",
"self",
".",
"_claimed_channels",
":",
"ChannelsDict",
"=",
"{",
"}",
"self",
".",
"_id",
":",
"int",
"=",
"ep_id",
"self",
".",
"_client_channels",
":",
"Dict",
"[",
"str",
",",
"zha_typing",
".",
"ClientChannelType",
"]",
"=",
"{",
"}",
"self",
".",
"_unique_id",
":",
"str",
"=",
"f\"{channels.unique_id}-{ep_id}\""
] | [
169,
4
] | [
176,
62
] | python | en | ['en', 'en', 'it'] | False |
ChannelPool.all_channels | (self) | All server channels of an endpoint. | All server channels of an endpoint. | def all_channels(self) -> ChannelsDict:
"""All server channels of an endpoint."""
return self._all_channels | [
"def",
"all_channels",
"(",
"self",
")",
"->",
"ChannelsDict",
":",
"return",
"self",
".",
"_all_channels"
] | [
179,
4
] | [
181,
33
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.claimed_channels | (self) | Channels in use. | Channels in use. | def claimed_channels(self) -> ChannelsDict:
"""Channels in use."""
return self._claimed_channels | [
"def",
"claimed_channels",
"(",
"self",
")",
"->",
"ChannelsDict",
":",
"return",
"self",
".",
"_claimed_channels"
] | [
184,
4
] | [
186,
37
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.client_channels | (self) | Return a dict of client channels. | Return a dict of client channels. | def client_channels(self) -> Dict[str, zha_typing.ClientChannelType]:
"""Return a dict of client channels."""
return self._client_channels | [
"def",
"client_channels",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"zha_typing",
".",
"ClientChannelType",
"]",
":",
"return",
"self",
".",
"_client_channels"
] | [
189,
4
] | [
191,
36
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.endpoint | (self) | Return endpoint of zigpy device. | Return endpoint of zigpy device. | def endpoint(self) -> zha_typing.ZigpyEndpointType:
"""Return endpoint of zigpy device."""
return self._channels.zha_device.device.endpoints[self.id] | [
"def",
"endpoint",
"(",
"self",
")",
"->",
"zha_typing",
".",
"ZigpyEndpointType",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"device",
".",
"endpoints",
"[",
"self",
".",
"id",
"]"
] | [
194,
4
] | [
196,
66
] | python | en | ['nl', 'en', 'en'] | True |
ChannelPool.id | (self) | Return endpoint id. | Return endpoint id. | def id(self) -> int:
"""Return endpoint id."""
return self._id | [
"def",
"id",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_id"
] | [
199,
4
] | [
201,
23
] | python | en | ['nl', 'en', 'en'] | True |
ChannelPool.nwk | (self) | Device NWK for logging. | Device NWK for logging. | def nwk(self) -> int:
"""Device NWK for logging."""
return self._channels.zha_device.nwk | [
"def",
"nwk",
"(",
"self",
")",
"->",
"int",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"nwk"
] | [
204,
4
] | [
206,
44
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.is_mains_powered | (self) | Device is_mains_powered. | Device is_mains_powered. | def is_mains_powered(self) -> bool:
"""Device is_mains_powered."""
return self._channels.zha_device.is_mains_powered | [
"def",
"is_mains_powered",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"is_mains_powered"
] | [
209,
4
] | [
211,
57
] | python | en | ['en', 'en', 'en'] | False |
ChannelPool.manufacturer | (self) | Return device manufacturer. | Return device manufacturer. | def manufacturer(self) -> Optional[str]:
"""Return device manufacturer."""
return self._channels.zha_device.manufacturer | [
"def",
"manufacturer",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"manufacturer"
] | [
214,
4
] | [
216,
53
] | python | da | ['fr', 'da', 'en'] | False |
ChannelPool.manufacturer_code | (self) | Return device manufacturer. | Return device manufacturer. | def manufacturer_code(self) -> Optional[int]:
"""Return device manufacturer."""
return self._channels.zha_device.manufacturer_code | [
"def",
"manufacturer_code",
"(",
"self",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"manufacturer_code"
] | [
219,
4
] | [
221,
58
] | python | da | ['fr', 'da', 'en'] | False |
ChannelPool.hass | (self) | Return hass. | Return hass. | def hass(self):
"""Return hass."""
return self._channels.zha_device.hass | [
"def",
"hass",
"(",
"self",
")",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"hass"
] | [
224,
4
] | [
226,
45
] | python | en | ['en', 'sn', 'en'] | False |
ChannelPool.model | (self) | Return device model. | Return device model. | def model(self) -> Optional[str]:
"""Return device model."""
return self._channels.zha_device.model | [
"def",
"model",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"model"
] | [
229,
4
] | [
231,
46
] | python | en | ['es', 'sl', 'en'] | False |
ChannelPool.skip_configuration | (self) | Return True if device does not require channel configuration. | Return True if device does not require channel configuration. | def skip_configuration(self) -> bool:
"""Return True if device does not require channel configuration."""
return self._channels.zha_device.skip_configuration | [
"def",
"skip_configuration",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_channels",
".",
"zha_device",
".",
"skip_configuration"
] | [
234,
4
] | [
236,
59
] | python | en | ['fr', 'en', 'en'] | True |
ChannelPool.unique_id | (self) | Return the unique id for this channel. | Return the unique id for this channel. | def unique_id(self):
"""Return the unique id for this channel."""
return self._unique_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
239,
4
] | [
241,
30
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.zigbee_signature | (self) | Get the zigbee signature for the endpoint this pool represents. | Get the zigbee signature for the endpoint this pool represents. | def zigbee_signature(self) -> Tuple[int, Dict[str, Any]]:
"""Get the zigbee signature for the endpoint this pool represents."""
return (
self.endpoint.endpoint_id,
{
const.ATTR_PROFILE_ID: self.endpoint.profile_id,
const.ATTR_DEVICE_TYPE: f"0x{self.endpoint.device_type:04x}"
if self.endpoint.device_type is not None
else "",
const.ATTR_IN_CLUSTERS: [
f"0x{cluster_id:04x}"
for cluster_id in sorted(self.endpoint.in_clusters)
],
const.ATTR_OUT_CLUSTERS: [
f"0x{cluster_id:04x}"
for cluster_id in sorted(self.endpoint.out_clusters)
],
},
) | [
"def",
"zigbee_signature",
"(",
"self",
")",
"->",
"Tuple",
"[",
"int",
",",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
":",
"return",
"(",
"self",
".",
"endpoint",
".",
"endpoint_id",
",",
"{",
"const",
".",
"ATTR_PROFILE_ID",
":",
"self",
".",
"endpoint",
".",
"profile_id",
",",
"const",
".",
"ATTR_DEVICE_TYPE",
":",
"f\"0x{self.endpoint.device_type:04x}\"",
"if",
"self",
".",
"endpoint",
".",
"device_type",
"is",
"not",
"None",
"else",
"\"\"",
",",
"const",
".",
"ATTR_IN_CLUSTERS",
":",
"[",
"f\"0x{cluster_id:04x}\"",
"for",
"cluster_id",
"in",
"sorted",
"(",
"self",
".",
"endpoint",
".",
"in_clusters",
")",
"]",
",",
"const",
".",
"ATTR_OUT_CLUSTERS",
":",
"[",
"f\"0x{cluster_id:04x}\"",
"for",
"cluster_id",
"in",
"sorted",
"(",
"self",
".",
"endpoint",
".",
"out_clusters",
")",
"]",
",",
"}",
",",
")"
] | [
244,
4
] | [
262,
9
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.new | (cls, channels: Channels, ep_id: int) | Create new channels for an endpoint. | Create new channels for an endpoint. | def new(cls, channels: Channels, ep_id: int) -> "ChannelPool":
"""Create new channels for an endpoint."""
pool = cls(channels, ep_id)
pool.add_all_channels()
pool.add_client_channels()
zha_disc.PROBE.discover_entities(pool)
return pool | [
"def",
"new",
"(",
"cls",
",",
"channels",
":",
"Channels",
",",
"ep_id",
":",
"int",
")",
"->",
"\"ChannelPool\"",
":",
"pool",
"=",
"cls",
"(",
"channels",
",",
"ep_id",
")",
"pool",
".",
"add_all_channels",
"(",
")",
"pool",
".",
"add_client_channels",
"(",
")",
"zha_disc",
".",
"PROBE",
".",
"discover_entities",
"(",
"pool",
")",
"return",
"pool"
] | [
265,
4
] | [
271,
19
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.add_all_channels | (self) | Create and add channels for all input clusters. | Create and add channels for all input clusters. | def add_all_channels(self) -> None:
"""Create and add channels for all input clusters."""
for cluster_id, cluster in self.endpoint.in_clusters.items():
channel_class = zha_regs.ZIGBEE_CHANNEL_REGISTRY.get(
cluster_id, base.ZigbeeChannel
)
# really ugly hack to deal with xiaomi using the door lock cluster
# incorrectly.
if (
hasattr(cluster, "ep_attribute")
and cluster_id == zigpy.zcl.clusters.closures.DoorLock.cluster_id
and cluster.ep_attribute == "multistate_input"
):
channel_class = general.MultistateInput
# end of ugly hack
channel = channel_class(cluster, self)
if channel.name == const.CHANNEL_POWER_CONFIGURATION:
if (
self._channels.power_configuration_ch
or self._channels.zha_device.is_mains_powered
):
# on power configuration channel per device
continue
self._channels.power_configuration_ch = channel
elif channel.name == const.CHANNEL_IDENTIFY:
self._channels.identify_ch = channel
self.all_channels[channel.id] = channel | [
"def",
"add_all_channels",
"(",
"self",
")",
"->",
"None",
":",
"for",
"cluster_id",
",",
"cluster",
"in",
"self",
".",
"endpoint",
".",
"in_clusters",
".",
"items",
"(",
")",
":",
"channel_class",
"=",
"zha_regs",
".",
"ZIGBEE_CHANNEL_REGISTRY",
".",
"get",
"(",
"cluster_id",
",",
"base",
".",
"ZigbeeChannel",
")",
"# really ugly hack to deal with xiaomi using the door lock cluster",
"# incorrectly.",
"if",
"(",
"hasattr",
"(",
"cluster",
",",
"\"ep_attribute\"",
")",
"and",
"cluster_id",
"==",
"zigpy",
".",
"zcl",
".",
"clusters",
".",
"closures",
".",
"DoorLock",
".",
"cluster_id",
"and",
"cluster",
".",
"ep_attribute",
"==",
"\"multistate_input\"",
")",
":",
"channel_class",
"=",
"general",
".",
"MultistateInput",
"# end of ugly hack",
"channel",
"=",
"channel_class",
"(",
"cluster",
",",
"self",
")",
"if",
"channel",
".",
"name",
"==",
"const",
".",
"CHANNEL_POWER_CONFIGURATION",
":",
"if",
"(",
"self",
".",
"_channels",
".",
"power_configuration_ch",
"or",
"self",
".",
"_channels",
".",
"zha_device",
".",
"is_mains_powered",
")",
":",
"# on power configuration channel per device",
"continue",
"self",
".",
"_channels",
".",
"power_configuration_ch",
"=",
"channel",
"elif",
"channel",
".",
"name",
"==",
"const",
".",
"CHANNEL_IDENTIFY",
":",
"self",
".",
"_channels",
".",
"identify_ch",
"=",
"channel",
"self",
".",
"all_channels",
"[",
"channel",
".",
"id",
"]",
"=",
"channel"
] | [
274,
4
] | [
301,
51
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.add_client_channels | (self) | Create client channels for all output clusters if in the registry. | Create client channels for all output clusters if in the registry. | def add_client_channels(self) -> None:
"""Create client channels for all output clusters if in the registry."""
for cluster_id, channel_class in zha_regs.CLIENT_CHANNELS_REGISTRY.items():
cluster = self.endpoint.out_clusters.get(cluster_id)
if cluster is not None:
channel = channel_class(cluster, self)
self.client_channels[channel.id] = channel | [
"def",
"add_client_channels",
"(",
"self",
")",
"->",
"None",
":",
"for",
"cluster_id",
",",
"channel_class",
"in",
"zha_regs",
".",
"CLIENT_CHANNELS_REGISTRY",
".",
"items",
"(",
")",
":",
"cluster",
"=",
"self",
".",
"endpoint",
".",
"out_clusters",
".",
"get",
"(",
"cluster_id",
")",
"if",
"cluster",
"is",
"not",
"None",
":",
"channel",
"=",
"channel_class",
"(",
"cluster",
",",
"self",
")",
"self",
".",
"client_channels",
"[",
"channel",
".",
"id",
"]",
"=",
"channel"
] | [
304,
4
] | [
310,
58
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.async_initialize | (self, from_cache: bool = False) | Initialize claimed channels. | Initialize claimed channels. | async def async_initialize(self, from_cache: bool = False) -> None:
"""Initialize claimed channels."""
await self._execute_channel_tasks("async_initialize", from_cache) | [
"async",
"def",
"async_initialize",
"(",
"self",
",",
"from_cache",
":",
"bool",
"=",
"False",
")",
"->",
"None",
":",
"await",
"self",
".",
"_execute_channel_tasks",
"(",
"\"async_initialize\"",
",",
"from_cache",
")"
] | [
312,
4
] | [
314,
73
] | python | en | ['sv', 'en', 'en'] | True |
ChannelPool.async_configure | (self) | Configure claimed channels. | Configure claimed channels. | async def async_configure(self) -> None:
"""Configure claimed channels."""
await self._execute_channel_tasks("async_configure") | [
"async",
"def",
"async_configure",
"(",
"self",
")",
"->",
"None",
":",
"await",
"self",
".",
"_execute_channel_tasks",
"(",
"\"async_configure\"",
")"
] | [
316,
4
] | [
318,
60
] | python | en | ['sv', 'en', 'en'] | True |
ChannelPool._execute_channel_tasks | (self, func_name: str, *args: Any) | Add a throttled channel task and swallow exceptions. | Add a throttled channel task and swallow exceptions. | async def _execute_channel_tasks(self, func_name: str, *args: Any) -> None:
"""Add a throttled channel task and swallow exceptions."""
async def _throttle(coro):
async with self._channels.semaphore:
return await coro
channels = [*self.claimed_channels.values(), *self.client_channels.values()]
tasks = [_throttle(getattr(ch, func_name)(*args)) for ch in channels]
results = await asyncio.gather(*tasks, return_exceptions=True)
for channel, outcome in zip(channels, results):
if isinstance(outcome, Exception):
channel.warning("'%s' stage failed: %s", func_name, str(outcome))
continue
channel.debug("'%s' stage succeeded", func_name) | [
"async",
"def",
"_execute_channel_tasks",
"(",
"self",
",",
"func_name",
":",
"str",
",",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"async",
"def",
"_throttle",
"(",
"coro",
")",
":",
"async",
"with",
"self",
".",
"_channels",
".",
"semaphore",
":",
"return",
"await",
"coro",
"channels",
"=",
"[",
"*",
"self",
".",
"claimed_channels",
".",
"values",
"(",
")",
",",
"*",
"self",
".",
"client_channels",
".",
"values",
"(",
")",
"]",
"tasks",
"=",
"[",
"_throttle",
"(",
"getattr",
"(",
"ch",
",",
"func_name",
")",
"(",
"*",
"args",
")",
")",
"for",
"ch",
"in",
"channels",
"]",
"results",
"=",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"tasks",
",",
"return_exceptions",
"=",
"True",
")",
"for",
"channel",
",",
"outcome",
"in",
"zip",
"(",
"channels",
",",
"results",
")",
":",
"if",
"isinstance",
"(",
"outcome",
",",
"Exception",
")",
":",
"channel",
".",
"warning",
"(",
"\"'%s' stage failed: %s\"",
",",
"func_name",
",",
"str",
"(",
"outcome",
")",
")",
"continue",
"channel",
".",
"debug",
"(",
"\"'%s' stage succeeded\"",
",",
"func_name",
")"
] | [
320,
4
] | [
334,
60
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.async_new_entity | (
self,
component: str,
entity_class: zha_typing.CALLABLE_T,
unique_id: str,
channels: List[zha_typing.ChannelType],
) | Signal new entity addition. | Signal new entity addition. | def async_new_entity(
self,
component: str,
entity_class: zha_typing.CALLABLE_T,
unique_id: str,
channels: List[zha_typing.ChannelType],
):
"""Signal new entity addition."""
self._channels.async_new_entity(component, entity_class, unique_id, channels) | [
"def",
"async_new_entity",
"(",
"self",
",",
"component",
":",
"str",
",",
"entity_class",
":",
"zha_typing",
".",
"CALLABLE_T",
",",
"unique_id",
":",
"str",
",",
"channels",
":",
"List",
"[",
"zha_typing",
".",
"ChannelType",
"]",
",",
")",
":",
"self",
".",
"_channels",
".",
"async_new_entity",
"(",
"component",
",",
"entity_class",
",",
"unique_id",
",",
"channels",
")"
] | [
337,
4
] | [
345,
85
] | python | en | ['en', 'cy', 'en'] | True |
ChannelPool.async_send_signal | (self, signal: str, *args: Any) | Send a signal through hass dispatcher. | Send a signal through hass dispatcher. | def async_send_signal(self, signal: str, *args: Any) -> None:
"""Send a signal through hass dispatcher."""
self._channels.async_send_signal(signal, *args) | [
"def",
"async_send_signal",
"(",
"self",
",",
"signal",
":",
"str",
",",
"*",
"args",
":",
"Any",
")",
"->",
"None",
":",
"self",
".",
"_channels",
".",
"async_send_signal",
"(",
"signal",
",",
"*",
"args",
")"
] | [
348,
4
] | [
350,
55
] | python | en | ['en', 'lb', 'en'] | True |
ChannelPool.claim_channels | (self, channels: List[zha_typing.ChannelType]) | Claim a channel. | Claim a channel. | def claim_channels(self, channels: List[zha_typing.ChannelType]) -> None:
"""Claim a channel."""
self.claimed_channels.update({ch.id: ch for ch in channels}) | [
"def",
"claim_channels",
"(",
"self",
",",
"channels",
":",
"List",
"[",
"zha_typing",
".",
"ChannelType",
"]",
")",
"->",
"None",
":",
"self",
".",
"claimed_channels",
".",
"update",
"(",
"{",
"ch",
".",
"id",
":",
"ch",
"for",
"ch",
"in",
"channels",
"}",
")"
] | [
353,
4
] | [
355,
68
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.unclaimed_channels | (self) | Return a list of available (unclaimed) channels. | Return a list of available (unclaimed) channels. | def unclaimed_channels(self) -> List[zha_typing.ChannelType]:
"""Return a list of available (unclaimed) channels."""
claimed = set(self.claimed_channels)
available = set(self.all_channels)
return [self.all_channels[chan_id] for chan_id in (available - claimed)] | [
"def",
"unclaimed_channels",
"(",
"self",
")",
"->",
"List",
"[",
"zha_typing",
".",
"ChannelType",
"]",
":",
"claimed",
"=",
"set",
"(",
"self",
".",
"claimed_channels",
")",
"available",
"=",
"set",
"(",
"self",
".",
"all_channels",
")",
"return",
"[",
"self",
".",
"all_channels",
"[",
"chan_id",
"]",
"for",
"chan_id",
"in",
"(",
"available",
"-",
"claimed",
")",
"]"
] | [
358,
4
] | [
362,
80
] | python | en | ['en', 'en', 'en'] | True |
ChannelPool.zha_send_event | (self, event_data: Dict[str, Union[str, int]]) | Relay events to hass. | Relay events to hass. | def zha_send_event(self, event_data: Dict[str, Union[str, int]]) -> None:
"""Relay events to hass."""
self._channels.zha_send_event(
{
const.ATTR_UNIQUE_ID: self.unique_id,
const.ATTR_ENDPOINT_ID: self.id,
**event_data,
}
) | [
"def",
"zha_send_event",
"(",
"self",
",",
"event_data",
":",
"Dict",
"[",
"str",
",",
"Union",
"[",
"str",
",",
"int",
"]",
"]",
")",
"->",
"None",
":",
"self",
".",
"_channels",
".",
"zha_send_event",
"(",
"{",
"const",
".",
"ATTR_UNIQUE_ID",
":",
"self",
".",
"unique_id",
",",
"const",
".",
"ATTR_ENDPOINT_ID",
":",
"self",
".",
"id",
",",
"*",
"*",
"event_data",
",",
"}",
")"
] | [
365,
4
] | [
373,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, entry) | Set up an entry. | Set up an entry. | async def async_setup_entry(hass, entry):
"""Set up an entry."""
component: Optional[EntityComponent] = hass.data.get(DOMAIN)
if component is None:
component = hass.data[DOMAIN] = EntityComponent(LOGGER, DOMAIN, hass)
return await component.async_setup_entry(entry) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
")",
":",
"component",
":",
"Optional",
"[",
"EntityComponent",
"]",
"=",
"hass",
".",
"data",
".",
"get",
"(",
"DOMAIN",
")",
"if",
"component",
"is",
"None",
":",
"component",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"EntityComponent",
"(",
"LOGGER",
",",
"DOMAIN",
",",
"hass",
")",
"return",
"await",
"component",
".",
"async_setup_entry",
"(",
"entry",
")"
] | [
18,
0
] | [
25,
51
] | python | en | ['en', 'en', 'en'] | True |
async_unload_entry | (hass, entry) | Unload an entry. | Unload an entry. | async def async_unload_entry(hass, entry):
"""Unload an entry."""
return await hass.data[DOMAIN].async_unload_entry(entry) | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
",",
"entry",
")",
":",
"return",
"await",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"async_unload_entry",
"(",
"entry",
")"
] | [
28,
0
] | [
30,
60
] | python | en | ['en', 'en', 'en'] | True |
BaseTrackerEntity.battery_level | (self) | Return the battery level of the device.
Percentage from 0-100.
| Return the battery level of the device. | def battery_level(self):
"""Return the battery level of the device.
Percentage from 0-100.
"""
return None | [
"def",
"battery_level",
"(",
"self",
")",
":",
"return",
"None"
] | [
37,
4
] | [
42,
19
] | python | en | ['en', 'en', 'en'] | True |
BaseTrackerEntity.source_type | (self) | Return the source type, eg gps or router, of the device. | Return the source type, eg gps or router, of the device. | def source_type(self):
"""Return the source type, eg gps or router, of the device."""
raise NotImplementedError | [
"def",
"source_type",
"(",
"self",
")",
":",
"raise",
"NotImplementedError"
] | [
45,
4
] | [
47,
33
] | python | en | ['en', 'en', 'en'] | True |
BaseTrackerEntity.state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def state_attributes(self):
"""Return the device state attributes."""
attr = {ATTR_SOURCE_TYPE: self.source_type}
if self.battery_level:
attr[ATTR_BATTERY_LEVEL] = self.battery_level
return attr | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"attr",
"=",
"{",
"ATTR_SOURCE_TYPE",
":",
"self",
".",
"source_type",
"}",
"if",
"self",
".",
"battery_level",
":",
"attr",
"[",
"ATTR_BATTERY_LEVEL",
"]",
"=",
"self",
".",
"battery_level",
"return",
"attr"
] | [
50,
4
] | [
57,
19
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.should_poll | (self) | No polling for entities that have location pushed. | No polling for entities that have location pushed. | def should_poll(self):
"""No polling for entities that have location pushed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
64,
4
] | [
66,
20
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.force_update | (self) | All updates need to be written to the state machine if we're not polling. | All updates need to be written to the state machine if we're not polling. | def force_update(self):
"""All updates need to be written to the state machine if we're not polling."""
return not self.should_poll | [
"def",
"force_update",
"(",
"self",
")",
":",
"return",
"not",
"self",
".",
"should_poll"
] | [
69,
4
] | [
71,
35
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.location_accuracy | (self) | Return the location accuracy of the device.
Value in meters.
| Return the location accuracy of the device. | def location_accuracy(self):
"""Return the location accuracy of the device.
Value in meters.
"""
return 0 | [
"def",
"location_accuracy",
"(",
"self",
")",
":",
"return",
"0"
] | [
74,
4
] | [
79,
16
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.location_name | (self) | Return a location name for the current location of the device. | Return a location name for the current location of the device. | def location_name(self) -> str:
"""Return a location name for the current location of the device."""
return None | [
"def",
"location_name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"None"
] | [
82,
4
] | [
84,
19
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.latitude | (self) | Return latitude value of the device. | Return latitude value of the device. | def latitude(self) -> float:
"""Return latitude value of the device."""
return NotImplementedError | [
"def",
"latitude",
"(",
"self",
")",
"->",
"float",
":",
"return",
"NotImplementedError"
] | [
87,
4
] | [
89,
34
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.longitude | (self) | Return longitude value of the device. | Return longitude value of the device. | def longitude(self) -> float:
"""Return longitude value of the device."""
return NotImplementedError | [
"def",
"longitude",
"(",
"self",
")",
"->",
"float",
":",
"return",
"NotImplementedError"
] | [
92,
4
] | [
94,
34
] | python | en | ['en', 'zu', 'en'] | True |
TrackerEntity.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
if self.location_name:
return self.location_name
if self.latitude is not None:
zone_state = zone.async_active_zone(
self.hass, self.latitude, self.longitude, self.location_accuracy
)
if zone_state is None:
state = STATE_NOT_HOME
elif zone_state.entity_id == zone.ENTITY_ID_HOME:
state = STATE_HOME
else:
state = zone_state.name
return state
return None | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"location_name",
":",
"return",
"self",
".",
"location_name",
"if",
"self",
".",
"latitude",
"is",
"not",
"None",
":",
"zone_state",
"=",
"zone",
".",
"async_active_zone",
"(",
"self",
".",
"hass",
",",
"self",
".",
"latitude",
",",
"self",
".",
"longitude",
",",
"self",
".",
"location_accuracy",
")",
"if",
"zone_state",
"is",
"None",
":",
"state",
"=",
"STATE_NOT_HOME",
"elif",
"zone_state",
".",
"entity_id",
"==",
"zone",
".",
"ENTITY_ID_HOME",
":",
"state",
"=",
"STATE_HOME",
"else",
":",
"state",
"=",
"zone_state",
".",
"name",
"return",
"state",
"return",
"None"
] | [
97,
4
] | [
114,
19
] | python | en | ['en', 'en', 'en'] | True |
TrackerEntity.state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def state_attributes(self):
"""Return the device state attributes."""
attr = {}
attr.update(super().state_attributes)
if self.latitude is not None:
attr[ATTR_LATITUDE] = self.latitude
attr[ATTR_LONGITUDE] = self.longitude
attr[ATTR_GPS_ACCURACY] = self.location_accuracy
return attr | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"attr",
"=",
"{",
"}",
"attr",
".",
"update",
"(",
"super",
"(",
")",
".",
"state_attributes",
")",
"if",
"self",
".",
"latitude",
"is",
"not",
"None",
":",
"attr",
"[",
"ATTR_LATITUDE",
"]",
"=",
"self",
".",
"latitude",
"attr",
"[",
"ATTR_LONGITUDE",
"]",
"=",
"self",
".",
"longitude",
"attr",
"[",
"ATTR_GPS_ACCURACY",
"]",
"=",
"self",
".",
"location_accuracy",
"return",
"attr"
] | [
117,
4
] | [
126,
19
] | python | en | ['en', 'en', 'en'] | True |
ScannerEntity.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
if self.is_connected:
return STATE_HOME
return STATE_NOT_HOME | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"is_connected",
":",
"return",
"STATE_HOME",
"return",
"STATE_NOT_HOME"
] | [
133,
4
] | [
137,
29
] | python | en | ['en', 'en', 'en'] | True |
ScannerEntity.is_connected | (self) | Return true if the device is connected to the network. | Return true if the device is connected to the network. | def is_connected(self):
"""Return true if the device is connected to the network."""
raise NotImplementedError | [
"def",
"is_connected",
"(",
"self",
")",
":",
"raise",
"NotImplementedError"
] | [
140,
4
] | [
142,
33
] | python | en | ['en', 'en', 'en'] | True |
async_setup_scanner | (hass, config, async_see, discovery_info=None) | Set up the MySensors device scanner. | Set up the MySensors device scanner. | async def async_setup_scanner(hass, config, async_see, discovery_info=None):
"""Set up the MySensors device scanner."""
new_devices = mysensors.setup_mysensors_platform(
hass,
DOMAIN,
discovery_info,
MySensorsDeviceScanner,
device_args=(hass, async_see),
)
if not new_devices:
return False
for device in new_devices:
gateway_id = id(device.gateway)
dev_id = (gateway_id, device.node_id, device.child_id, device.value_type)
async_dispatcher_connect(
hass,
mysensors.const.CHILD_CALLBACK.format(*dev_id),
device.async_update_callback,
)
async_dispatcher_connect(
hass,
mysensors.const.NODE_CALLBACK.format(gateway_id, device.node_id),
device.async_update_callback,
)
return True | [
"async",
"def",
"async_setup_scanner",
"(",
"hass",
",",
"config",
",",
"async_see",
",",
"discovery_info",
"=",
"None",
")",
":",
"new_devices",
"=",
"mysensors",
".",
"setup_mysensors_platform",
"(",
"hass",
",",
"DOMAIN",
",",
"discovery_info",
",",
"MySensorsDeviceScanner",
",",
"device_args",
"=",
"(",
"hass",
",",
"async_see",
")",
",",
")",
"if",
"not",
"new_devices",
":",
"return",
"False",
"for",
"device",
"in",
"new_devices",
":",
"gateway_id",
"=",
"id",
"(",
"device",
".",
"gateway",
")",
"dev_id",
"=",
"(",
"gateway_id",
",",
"device",
".",
"node_id",
",",
"device",
".",
"child_id",
",",
"device",
".",
"value_type",
")",
"async_dispatcher_connect",
"(",
"hass",
",",
"mysensors",
".",
"const",
".",
"CHILD_CALLBACK",
".",
"format",
"(",
"*",
"dev_id",
")",
",",
"device",
".",
"async_update_callback",
",",
")",
"async_dispatcher_connect",
"(",
"hass",
",",
"mysensors",
".",
"const",
".",
"NODE_CALLBACK",
".",
"format",
"(",
"gateway_id",
",",
"device",
".",
"node_id",
")",
",",
"device",
".",
"async_update_callback",
",",
")",
"return",
"True"
] | [
7,
0
] | [
33,
15
] | python | en | ['en', 'en', 'en'] | True |
MySensorsDeviceScanner.__init__ | (self, hass, async_see, *args) | Set up instance. | Set up instance. | def __init__(self, hass, async_see, *args):
"""Set up instance."""
super().__init__(*args)
self.async_see = async_see
self.hass = hass | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"async_see",
",",
"*",
"args",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"*",
"args",
")",
"self",
".",
"async_see",
"=",
"async_see",
"self",
".",
"hass",
"=",
"hass"
] | [
39,
4
] | [
43,
24
] | python | en | ['en', 'da', 'en'] | True |
MySensorsDeviceScanner._async_update_callback | (self) | Update the device. | Update the device. | async def _async_update_callback(self):
"""Update the device."""
await self.async_update()
node = self.gateway.sensors[self.node_id]
child = node.children[self.child_id]
position = child.values[self.value_type]
latitude, longitude, _ = position.split(",")
await self.async_see(
dev_id=slugify(self.name),
host_name=self.name,
gps=(latitude, longitude),
battery=node.battery_level,
attributes=self.device_state_attributes,
) | [
"async",
"def",
"_async_update_callback",
"(",
"self",
")",
":",
"await",
"self",
".",
"async_update",
"(",
")",
"node",
"=",
"self",
".",
"gateway",
".",
"sensors",
"[",
"self",
".",
"node_id",
"]",
"child",
"=",
"node",
".",
"children",
"[",
"self",
".",
"child_id",
"]",
"position",
"=",
"child",
".",
"values",
"[",
"self",
".",
"value_type",
"]",
"latitude",
",",
"longitude",
",",
"_",
"=",
"position",
".",
"split",
"(",
"\",\"",
")",
"await",
"self",
".",
"async_see",
"(",
"dev_id",
"=",
"slugify",
"(",
"self",
".",
"name",
")",
",",
"host_name",
"=",
"self",
".",
"name",
",",
"gps",
"=",
"(",
"latitude",
",",
"longitude",
")",
",",
"battery",
"=",
"node",
".",
"battery_level",
",",
"attributes",
"=",
"self",
".",
"device_state_attributes",
",",
")"
] | [
45,
4
] | [
59,
9
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the ATEN PE switch. | Set up the ATEN PE switch. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the ATEN PE switch."""
node = config[CONF_HOST]
serv = config[CONF_PORT]
dev = AtenPE(
node=node,
serv=serv,
community=config[CONF_COMMUNITY],
username=config[CONF_USERNAME],
authkey=config.get(CONF_AUTH_KEY),
privkey=config.get(CONF_PRIV_KEY),
)
try:
await hass.async_add_executor_job(dev.initialize)
mac = await dev.deviceMAC()
outlets = dev.outlets()
except AtenPEError as exc:
_LOGGER.error("Failed to initialize %s:%s: %s", node, serv, str(exc))
raise PlatformNotReady from exc
switches = []
async for outlet in outlets:
switches.append(AtenSwitch(dev, mac, outlet.id, outlet.name))
async_add_entities(switches) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"node",
"=",
"config",
"[",
"CONF_HOST",
"]",
"serv",
"=",
"config",
"[",
"CONF_PORT",
"]",
"dev",
"=",
"AtenPE",
"(",
"node",
"=",
"node",
",",
"serv",
"=",
"serv",
",",
"community",
"=",
"config",
"[",
"CONF_COMMUNITY",
"]",
",",
"username",
"=",
"config",
"[",
"CONF_USERNAME",
"]",
",",
"authkey",
"=",
"config",
".",
"get",
"(",
"CONF_AUTH_KEY",
")",
",",
"privkey",
"=",
"config",
".",
"get",
"(",
"CONF_PRIV_KEY",
")",
",",
")",
"try",
":",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"dev",
".",
"initialize",
")",
"mac",
"=",
"await",
"dev",
".",
"deviceMAC",
"(",
")",
"outlets",
"=",
"dev",
".",
"outlets",
"(",
")",
"except",
"AtenPEError",
"as",
"exc",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to initialize %s:%s: %s\"",
",",
"node",
",",
"serv",
",",
"str",
"(",
"exc",
")",
")",
"raise",
"PlatformNotReady",
"from",
"exc",
"switches",
"=",
"[",
"]",
"async",
"for",
"outlet",
"in",
"outlets",
":",
"switches",
".",
"append",
"(",
"AtenSwitch",
"(",
"dev",
",",
"mac",
",",
"outlet",
".",
"id",
",",
"outlet",
".",
"name",
")",
")",
"async_add_entities",
"(",
"switches",
")"
] | [
37,
0
] | [
63,
32
] | python | en | ['en', 'en', 'en'] | True |
AtenSwitch.__init__ | (self, device, mac, outlet, name) | Initialize an ATEN PE switch. | Initialize an ATEN PE switch. | def __init__(self, device, mac, outlet, name):
"""Initialize an ATEN PE switch."""
self._device = device
self._mac = mac
self._outlet = outlet
self._name = name or f"Outlet {outlet}"
self._enabled = False
self._outlet_power = 0.0 | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"mac",
",",
"outlet",
",",
"name",
")",
":",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_mac",
"=",
"mac",
"self",
".",
"_outlet",
"=",
"outlet",
"self",
".",
"_name",
"=",
"name",
"or",
"f\"Outlet {outlet}\"",
"self",
".",
"_enabled",
"=",
"False",
"self",
".",
"_outlet_power",
"=",
"0.0"
] | [
69,
4
] | [
76,
32
] | python | en | ['en', 'zh-Latn', 'en'] | True |
AtenSwitch.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._mac}-{self._outlet}" | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"{self._mac}-{self._outlet}\""
] | [
79,
4
] | [
81,
44
] | python | ca | ['fr', 'ca', 'en'] | False |
AtenSwitch.name | (self) | Return the name of the entity. | Return the name of the entity. | def name(self) -> str:
"""Return the name of the entity."""
return self._name | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_name"
] | [
84,
4
] | [
86,
25
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.