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 |
---|---|---|---|---|---|---|---|---|---|---|---|
test_template_vars_error | (hass) | Test template vars. | Test template vars. | async def test_template_vars_error(hass):
"""Test template vars."""
var = cv.SCRIPT_VARIABLES_SCHEMA({"hello": "{{ canont.work }}"})
with pytest.raises(template.TemplateError):
var.async_render(hass, None) | [
"async",
"def",
"test_template_vars_error",
"(",
"hass",
")",
":",
"var",
"=",
"cv",
".",
"SCRIPT_VARIABLES_SCHEMA",
"(",
"{",
"\"hello\"",
":",
"\"{{ canont.work }}\"",
"}",
")",
"with",
"pytest",
".",
"raises",
"(",
"template",
".",
"TemplateError",
")",
":",
"var",
".",
"async_render",
"(",
"hass",
",",
"None",
")"
] | [
107,
0
] | [
111,
36
] | python | en | ['en', 'et', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the August sensors. | Set up the August sensors. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the August sensors."""
powerwall_data = hass.data[DOMAIN][config_entry.entry_id]
coordinator = powerwall_data[POWERWALL_COORDINATOR]
site_info = powerwall_data[POWERWALL_API_SITE_INFO]
device_type = powerwall_data[POWERWALL_API_DEVICE_TYPE]
status = powerwall_data[POWERWALL_API_STATUS]
powerwalls_serial_numbers = powerwall_data[POWERWALL_API_SERIAL_NUMBERS]
entities = []
for sensor_class in (
PowerWallRunningSensor,
PowerWallGridStatusSensor,
PowerWallConnectedSensor,
PowerWallChargingStatusSensor,
):
entities.append(
sensor_class(
coordinator, site_info, status, device_type, powerwalls_serial_numbers
)
)
async_add_entities(entities, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"powerwall_data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"coordinator",
"=",
"powerwall_data",
"[",
"POWERWALL_COORDINATOR",
"]",
"site_info",
"=",
"powerwall_data",
"[",
"POWERWALL_API_SITE_INFO",
"]",
"device_type",
"=",
"powerwall_data",
"[",
"POWERWALL_API_DEVICE_TYPE",
"]",
"status",
"=",
"powerwall_data",
"[",
"POWERWALL_API_STATUS",
"]",
"powerwalls_serial_numbers",
"=",
"powerwall_data",
"[",
"POWERWALL_API_SERIAL_NUMBERS",
"]",
"entities",
"=",
"[",
"]",
"for",
"sensor_class",
"in",
"(",
"PowerWallRunningSensor",
",",
"PowerWallGridStatusSensor",
",",
"PowerWallConnectedSensor",
",",
"PowerWallChargingStatusSensor",
",",
")",
":",
"entities",
".",
"append",
"(",
"sensor_class",
"(",
"coordinator",
",",
"site_info",
",",
"status",
",",
"device_type",
",",
"powerwalls_serial_numbers",
")",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
")"
] | [
24,
0
] | [
47,
38
] | python | en | ['en', 'en', 'en'] | True |
PowerWallRunningSensor.name | (self) | Device Name. | Device Name. | def name(self):
"""Device Name."""
return "Powerwall Status" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"\"Powerwall Status\""
] | [
54,
4
] | [
56,
33
] | python | en | ['en', 'en', 'en'] | False |
PowerWallRunningSensor.device_class | (self) | Device Class. | Device Class. | def device_class(self):
"""Device Class."""
return DEVICE_CLASS_POWER | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_POWER"
] | [
59,
4
] | [
61,
33
] | python | en | ['en', 'zh', 'en'] | False |
PowerWallRunningSensor.unique_id | (self) | Device Uniqueid. | Device Uniqueid. | def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_running" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.base_unique_id}_running\""
] | [
64,
4
] | [
66,
47
] | python | fr | ['fr', 'fr', 'en'] | False |
PowerWallRunningSensor.is_on | (self) | Get the powerwall running state. | Get the powerwall running state. | def is_on(self):
"""Get the powerwall running state."""
return self.coordinator.data[POWERWALL_API_SITEMASTER].is_running | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"POWERWALL_API_SITEMASTER",
"]",
".",
"is_running"
] | [
69,
4
] | [
71,
73
] | python | en | ['en', 'sn', 'en'] | True |
PowerWallConnectedSensor.name | (self) | Device Name. | Device Name. | def name(self):
"""Device Name."""
return "Powerwall Connected to Tesla" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"\"Powerwall Connected to Tesla\""
] | [
78,
4
] | [
80,
45
] | python | en | ['en', 'en', 'en'] | False |
PowerWallConnectedSensor.device_class | (self) | Device Class. | Device Class. | def device_class(self):
"""Device Class."""
return DEVICE_CLASS_CONNECTIVITY | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_CONNECTIVITY"
] | [
83,
4
] | [
85,
40
] | python | en | ['en', 'zh', 'en'] | False |
PowerWallConnectedSensor.unique_id | (self) | Device Uniqueid. | Device Uniqueid. | def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_connected_to_tesla" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.base_unique_id}_connected_to_tesla\""
] | [
88,
4
] | [
90,
58
] | python | fr | ['fr', 'fr', 'en'] | False |
PowerWallConnectedSensor.is_on | (self) | Get the powerwall connected to tesla state. | Get the powerwall connected to tesla state. | def is_on(self):
"""Get the powerwall connected to tesla state."""
return self.coordinator.data[POWERWALL_API_SITEMASTER].is_connected_to_tesla | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"POWERWALL_API_SITEMASTER",
"]",
".",
"is_connected_to_tesla"
] | [
93,
4
] | [
95,
84
] | python | en | ['en', 'en', 'en'] | True |
PowerWallGridStatusSensor.name | (self) | Device Name. | Device Name. | def name(self):
"""Device Name."""
return "Grid Status" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"\"Grid Status\""
] | [
102,
4
] | [
104,
28
] | python | en | ['en', 'en', 'en'] | False |
PowerWallGridStatusSensor.device_class | (self) | Device Class. | Device Class. | def device_class(self):
"""Device Class."""
return DEVICE_CLASS_POWER | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_POWER"
] | [
107,
4
] | [
109,
33
] | python | en | ['en', 'zh', 'en'] | False |
PowerWallGridStatusSensor.unique_id | (self) | Device Uniqueid. | Device Uniqueid. | def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_grid_status" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.base_unique_id}_grid_status\""
] | [
112,
4
] | [
114,
51
] | python | fr | ['fr', 'fr', 'en'] | False |
PowerWallGridStatusSensor.is_on | (self) | Grid is online. | Grid is online. | def is_on(self):
"""Grid is online."""
return self.coordinator.data[POWERWALL_API_GRID_STATUS] == GridStatus.CONNECTED | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"POWERWALL_API_GRID_STATUS",
"]",
"==",
"GridStatus",
".",
"CONNECTED"
] | [
117,
4
] | [
119,
87
] | python | en | ['en', 'af', 'en'] | True |
PowerWallChargingStatusSensor.name | (self) | Device Name. | Device Name. | def name(self):
"""Device Name."""
return "Powerwall Charging" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"\"Powerwall Charging\""
] | [
126,
4
] | [
128,
35
] | python | en | ['en', 'en', 'en'] | False |
PowerWallChargingStatusSensor.device_class | (self) | Device Class. | Device Class. | def device_class(self):
"""Device Class."""
return DEVICE_CLASS_BATTERY_CHARGING | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_BATTERY_CHARGING"
] | [
131,
4
] | [
133,
44
] | python | en | ['en', 'zh', 'en'] | False |
PowerWallChargingStatusSensor.unique_id | (self) | Device Uniqueid. | Device Uniqueid. | def unique_id(self):
"""Device Uniqueid."""
return f"{self.base_unique_id}_powerwall_charging" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.base_unique_id}_powerwall_charging\""
] | [
136,
4
] | [
138,
58
] | python | fr | ['fr', 'fr', 'en'] | False |
PowerWallChargingStatusSensor.is_on | (self) | Powerwall is charging. | Powerwall is charging. | def is_on(self):
"""Powerwall is charging."""
# is_sending_to returns true for values greater than 100 watts
return self.coordinator.data[POWERWALL_API_METERS].battery.is_sending_to() | [
"def",
"is_on",
"(",
"self",
")",
":",
"# is_sending_to returns true for values greater than 100 watts",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"POWERWALL_API_METERS",
"]",
".",
"battery",
".",
"is_sending_to",
"(",
")"
] | [
141,
4
] | [
144,
82
] | python | en | ['en', 'af', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up the GeoNet NZ Quakes Feed platform. | Set up the GeoNet NZ Quakes Feed platform. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the GeoNet NZ Quakes Feed platform."""
manager = hass.data[DOMAIN][FEED][entry.entry_id]
sensor = GeonetnzQuakesSensor(entry.entry_id, entry.unique_id, entry.title, manager)
async_add_entities([sensor])
_LOGGER.debug("Sensor setup done") | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"manager",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"FEED",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"sensor",
"=",
"GeonetnzQuakesSensor",
"(",
"entry",
".",
"entry_id",
",",
"entry",
".",
"unique_id",
",",
"entry",
".",
"title",
",",
"manager",
")",
"async_add_entities",
"(",
"[",
"sensor",
"]",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Sensor setup done\"",
")"
] | [
28,
0
] | [
33,
38
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.__init__ | (self, config_entry_id, config_unique_id, config_title, manager) | Initialize entity. | Initialize entity. | def __init__(self, config_entry_id, config_unique_id, config_title, manager):
"""Initialize entity."""
self._config_entry_id = config_entry_id
self._config_unique_id = config_unique_id
self._config_title = config_title
self._manager = manager
self._status = None
self._last_update = None
self._last_update_successful = None
self._last_timestamp = None
self._total = None
self._created = None
self._updated = None
self._removed = None
self._remove_signal_status = None | [
"def",
"__init__",
"(",
"self",
",",
"config_entry_id",
",",
"config_unique_id",
",",
"config_title",
",",
"manager",
")",
":",
"self",
".",
"_config_entry_id",
"=",
"config_entry_id",
"self",
".",
"_config_unique_id",
"=",
"config_unique_id",
"self",
".",
"_config_title",
"=",
"config_title",
"self",
".",
"_manager",
"=",
"manager",
"self",
".",
"_status",
"=",
"None",
"self",
".",
"_last_update",
"=",
"None",
"self",
".",
"_last_update_successful",
"=",
"None",
"self",
".",
"_last_timestamp",
"=",
"None",
"self",
".",
"_total",
"=",
"None",
"self",
".",
"_created",
"=",
"None",
"self",
".",
"_updated",
"=",
"None",
"self",
".",
"_removed",
"=",
"None",
"self",
".",
"_remove_signal_status",
"=",
"None"
] | [
39,
4
] | [
53,
41
] | python | es | ['es', 'pl', 'it'] | False |
GeonetnzQuakesSensor.async_added_to_hass | (self) | Call when entity is added to hass. | Call when entity is added to hass. | async def async_added_to_hass(self):
"""Call when entity is added to hass."""
self._remove_signal_status = async_dispatcher_connect(
self.hass,
f"geonetnz_quakes_status_{self._config_entry_id}",
self._update_status_callback,
)
_LOGGER.debug("Waiting for updates %s", self._config_entry_id)
# First update is manual because of how the feed entity manager is updated.
await self.async_update() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"_remove_signal_status",
"=",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"f\"geonetnz_quakes_status_{self._config_entry_id}\"",
",",
"self",
".",
"_update_status_callback",
",",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Waiting for updates %s\"",
",",
"self",
".",
"_config_entry_id",
")",
"# First update is manual because of how the feed entity manager is updated.",
"await",
"self",
".",
"async_update",
"(",
")"
] | [
55,
4
] | [
64,
33
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.async_will_remove_from_hass | (self) | Call when entity will be removed from hass. | Call when entity will be removed from hass. | async def async_will_remove_from_hass(self) -> None:
"""Call when entity will be removed from hass."""
if self._remove_signal_status:
self._remove_signal_status() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
"->",
"None",
":",
"if",
"self",
".",
"_remove_signal_status",
":",
"self",
".",
"_remove_signal_status",
"(",
")"
] | [
66,
4
] | [
69,
40
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor._update_status_callback | (self) | Call status update method. | Call status update method. | def _update_status_callback(self):
"""Call status update method."""
_LOGGER.debug("Received status update for %s", self._config_entry_id)
self.async_schedule_update_ha_state(True) | [
"def",
"_update_status_callback",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Received status update for %s\"",
",",
"self",
".",
"_config_entry_id",
")",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
72,
4
] | [
75,
49
] | python | en | ['en', 'sn', 'en'] | True |
GeonetnzQuakesSensor.should_poll | (self) | No polling needed for GeoNet NZ Quakes status sensor. | No polling needed for GeoNet NZ Quakes status sensor. | def should_poll(self):
"""No polling needed for GeoNet NZ Quakes status sensor."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
78,
4
] | [
80,
20
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.async_update | (self) | Update this entity from the data held in the feed manager. | Update this entity from the data held in the feed manager. | async def async_update(self):
"""Update this entity from the data held in the feed manager."""
_LOGGER.debug("Updating %s", self._config_entry_id)
if self._manager:
status_info = self._manager.status_info()
if status_info:
self._update_from_status_info(status_info) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Updating %s\"",
",",
"self",
".",
"_config_entry_id",
")",
"if",
"self",
".",
"_manager",
":",
"status_info",
"=",
"self",
".",
"_manager",
".",
"status_info",
"(",
")",
"if",
"status_info",
":",
"self",
".",
"_update_from_status_info",
"(",
"status_info",
")"
] | [
82,
4
] | [
88,
58
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor._update_from_status_info | (self, status_info) | Update the internal state from the provided information. | Update the internal state from the provided information. | def _update_from_status_info(self, status_info):
"""Update the internal state from the provided information."""
self._status = status_info.status
self._last_update = (
dt.as_utc(status_info.last_update) if status_info.last_update else None
)
if status_info.last_update_successful:
self._last_update_successful = dt.as_utc(status_info.last_update_successful)
else:
self._last_update_successful = None
self._last_timestamp = status_info.last_timestamp
self._total = status_info.total
self._created = status_info.created
self._updated = status_info.updated
self._removed = status_info.removed | [
"def",
"_update_from_status_info",
"(",
"self",
",",
"status_info",
")",
":",
"self",
".",
"_status",
"=",
"status_info",
".",
"status",
"self",
".",
"_last_update",
"=",
"(",
"dt",
".",
"as_utc",
"(",
"status_info",
".",
"last_update",
")",
"if",
"status_info",
".",
"last_update",
"else",
"None",
")",
"if",
"status_info",
".",
"last_update_successful",
":",
"self",
".",
"_last_update_successful",
"=",
"dt",
".",
"as_utc",
"(",
"status_info",
".",
"last_update_successful",
")",
"else",
":",
"self",
".",
"_last_update_successful",
"=",
"None",
"self",
".",
"_last_timestamp",
"=",
"status_info",
".",
"last_timestamp",
"self",
".",
"_total",
"=",
"status_info",
".",
"total",
"self",
".",
"_created",
"=",
"status_info",
".",
"created",
"self",
".",
"_updated",
"=",
"status_info",
".",
"updated",
"self",
".",
"_removed",
"=",
"status_info",
".",
"removed"
] | [
90,
4
] | [
104,
43
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._total | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_total"
] | [
107,
4
] | [
109,
26
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.unique_id | (self) | Return a unique ID containing latitude/longitude. | Return a unique ID containing latitude/longitude. | def unique_id(self) -> str:
"""Return a unique ID containing latitude/longitude."""
return self._config_unique_id | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"_config_unique_id"
] | [
112,
4
] | [
114,
37
] | python | ca | ['ca', 'la', 'en'] | False |
GeonetnzQuakesSensor.name | (self) | Return the name of the entity. | Return the name of the entity. | def name(self) -> Optional[str]:
"""Return the name of the entity."""
return f"GeoNet NZ Quakes ({self._config_title})" | [
"def",
"name",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"f\"GeoNet NZ Quakes ({self._config_title})\""
] | [
117,
4
] | [
119,
57
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return DEFAULT_ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"DEFAULT_ICON"
] | [
122,
4
] | [
124,
27
] | python | en | ['en', 'en', 'en'] | True |
GeonetnzQuakesSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return DEFAULT_UNIT_OF_MEASUREMENT | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"DEFAULT_UNIT_OF_MEASUREMENT"
] | [
127,
4
] | [
129,
42
] | python | en | ['en', 'la', 'en'] | True |
GeonetnzQuakesSensor.device_state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def device_state_attributes(self):
"""Return the device state attributes."""
attributes = {}
for key, value in (
(ATTR_STATUS, self._status),
(ATTR_LAST_UPDATE, self._last_update),
(ATTR_LAST_UPDATE_SUCCESSFUL, self._last_update_successful),
(ATTR_LAST_TIMESTAMP, self._last_timestamp),
(ATTR_CREATED, self._created),
(ATTR_UPDATED, self._updated),
(ATTR_REMOVED, self._removed),
):
if value or isinstance(value, bool):
attributes[key] = value
return attributes | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attributes",
"=",
"{",
"}",
"for",
"key",
",",
"value",
"in",
"(",
"(",
"ATTR_STATUS",
",",
"self",
".",
"_status",
")",
",",
"(",
"ATTR_LAST_UPDATE",
",",
"self",
".",
"_last_update",
")",
",",
"(",
"ATTR_LAST_UPDATE_SUCCESSFUL",
",",
"self",
".",
"_last_update_successful",
")",
",",
"(",
"ATTR_LAST_TIMESTAMP",
",",
"self",
".",
"_last_timestamp",
")",
",",
"(",
"ATTR_CREATED",
",",
"self",
".",
"_created",
")",
",",
"(",
"ATTR_UPDATED",
",",
"self",
".",
"_updated",
")",
",",
"(",
"ATTR_REMOVED",
",",
"self",
".",
"_removed",
")",
",",
")",
":",
"if",
"value",
"or",
"isinstance",
"(",
"value",
",",
"bool",
")",
":",
"attributes",
"[",
"key",
"]",
"=",
"value",
"return",
"attributes"
] | [
132,
4
] | [
146,
25
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Emby platform. | Set up the Emby platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Emby platform."""
host = config.get(CONF_HOST)
key = config.get(CONF_API_KEY)
port = config.get(CONF_PORT)
ssl = config[CONF_SSL]
if port is None:
port = DEFAULT_SSL_PORT if ssl else DEFAULT_PORT
_LOGGER.debug("Setting up Emby server at: %s:%s", host, port)
emby = EmbyServer(host, key, port, ssl, hass.loop)
active_emby_devices = {}
inactive_emby_devices = {}
@callback
def device_update_callback(data):
"""Handle devices which are added to Emby."""
new_devices = []
active_devices = []
for dev_id in emby.devices:
active_devices.append(dev_id)
if (
dev_id not in active_emby_devices
and dev_id not in inactive_emby_devices
):
new = EmbyDevice(emby, dev_id)
active_emby_devices[dev_id] = new
new_devices.append(new)
elif dev_id in inactive_emby_devices:
if emby.devices[dev_id].state != "Off":
add = inactive_emby_devices.pop(dev_id)
active_emby_devices[dev_id] = add
_LOGGER.debug("Showing %s, item: %s", dev_id, add)
add.set_available(True)
if new_devices:
_LOGGER.debug("Adding new devices: %s", new_devices)
async_add_entities(new_devices, True)
@callback
def device_removal_callback(data):
"""Handle the removal of devices from Emby."""
if data in active_emby_devices:
rem = active_emby_devices.pop(data)
inactive_emby_devices[data] = rem
_LOGGER.debug("Inactive %s, item: %s", data, rem)
rem.set_available(False)
@callback
def start_emby(event):
"""Start Emby connection."""
emby.start()
async def stop_emby(event):
"""Stop Emby connection."""
await emby.stop()
emby.add_new_devices_callback(device_update_callback)
emby.add_stale_devices_callback(device_removal_callback)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_emby)
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, stop_emby) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"key",
"=",
"config",
".",
"get",
"(",
"CONF_API_KEY",
")",
"port",
"=",
"config",
".",
"get",
"(",
"CONF_PORT",
")",
"ssl",
"=",
"config",
"[",
"CONF_SSL",
"]",
"if",
"port",
"is",
"None",
":",
"port",
"=",
"DEFAULT_SSL_PORT",
"if",
"ssl",
"else",
"DEFAULT_PORT",
"_LOGGER",
".",
"debug",
"(",
"\"Setting up Emby server at: %s:%s\"",
",",
"host",
",",
"port",
")",
"emby",
"=",
"EmbyServer",
"(",
"host",
",",
"key",
",",
"port",
",",
"ssl",
",",
"hass",
".",
"loop",
")",
"active_emby_devices",
"=",
"{",
"}",
"inactive_emby_devices",
"=",
"{",
"}",
"@",
"callback",
"def",
"device_update_callback",
"(",
"data",
")",
":",
"\"\"\"Handle devices which are added to Emby.\"\"\"",
"new_devices",
"=",
"[",
"]",
"active_devices",
"=",
"[",
"]",
"for",
"dev_id",
"in",
"emby",
".",
"devices",
":",
"active_devices",
".",
"append",
"(",
"dev_id",
")",
"if",
"(",
"dev_id",
"not",
"in",
"active_emby_devices",
"and",
"dev_id",
"not",
"in",
"inactive_emby_devices",
")",
":",
"new",
"=",
"EmbyDevice",
"(",
"emby",
",",
"dev_id",
")",
"active_emby_devices",
"[",
"dev_id",
"]",
"=",
"new",
"new_devices",
".",
"append",
"(",
"new",
")",
"elif",
"dev_id",
"in",
"inactive_emby_devices",
":",
"if",
"emby",
".",
"devices",
"[",
"dev_id",
"]",
".",
"state",
"!=",
"\"Off\"",
":",
"add",
"=",
"inactive_emby_devices",
".",
"pop",
"(",
"dev_id",
")",
"active_emby_devices",
"[",
"dev_id",
"]",
"=",
"add",
"_LOGGER",
".",
"debug",
"(",
"\"Showing %s, item: %s\"",
",",
"dev_id",
",",
"add",
")",
"add",
".",
"set_available",
"(",
"True",
")",
"if",
"new_devices",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Adding new devices: %s\"",
",",
"new_devices",
")",
"async_add_entities",
"(",
"new_devices",
",",
"True",
")",
"@",
"callback",
"def",
"device_removal_callback",
"(",
"data",
")",
":",
"\"\"\"Handle the removal of devices from Emby.\"\"\"",
"if",
"data",
"in",
"active_emby_devices",
":",
"rem",
"=",
"active_emby_devices",
".",
"pop",
"(",
"data",
")",
"inactive_emby_devices",
"[",
"data",
"]",
"=",
"rem",
"_LOGGER",
".",
"debug",
"(",
"\"Inactive %s, item: %s\"",
",",
"data",
",",
"rem",
")",
"rem",
".",
"set_available",
"(",
"False",
")",
"@",
"callback",
"def",
"start_emby",
"(",
"event",
")",
":",
"\"\"\"Start Emby connection.\"\"\"",
"emby",
".",
"start",
"(",
")",
"async",
"def",
"stop_emby",
"(",
"event",
")",
":",
"\"\"\"Stop Emby connection.\"\"\"",
"await",
"emby",
".",
"stop",
"(",
")",
"emby",
".",
"add_new_devices_callback",
"(",
"device_update_callback",
")",
"emby",
".",
"add_stale_devices_callback",
"(",
"device_removal_callback",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_START",
",",
"start_emby",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"stop_emby",
")"
] | [
65,
0
] | [
131,
67
] | python | en | ['en', 'da', 'en'] | True |
EmbyDevice.__init__ | (self, emby, device_id) | Initialize the Emby device. | Initialize the Emby device. | def __init__(self, emby, device_id):
"""Initialize the Emby device."""
_LOGGER.debug("New Emby Device initialized with ID: %s", device_id)
self.emby = emby
self.device_id = device_id
self.device = self.emby.devices[self.device_id]
self._available = True
self.media_status_last_position = None
self.media_status_received = None | [
"def",
"__init__",
"(",
"self",
",",
"emby",
",",
"device_id",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"New Emby Device initialized with ID: %s\"",
",",
"device_id",
")",
"self",
".",
"emby",
"=",
"emby",
"self",
".",
"device_id",
"=",
"device_id",
"self",
".",
"device",
"=",
"self",
".",
"emby",
".",
"devices",
"[",
"self",
".",
"device_id",
"]",
"self",
".",
"_available",
"=",
"True",
"self",
".",
"media_status_last_position",
"=",
"None",
"self",
".",
"media_status_received",
"=",
"None"
] | [
137,
4
] | [
147,
41
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.async_added_to_hass | (self) | Register callback. | Register callback. | async def async_added_to_hass(self):
"""Register callback."""
self.emby.add_update_callback(self.async_update_callback, self.device_id) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"emby",
".",
"add_update_callback",
"(",
"self",
".",
"async_update_callback",
",",
"self",
".",
"device_id",
")"
] | [
149,
4
] | [
151,
81
] | python | en | ['en', 'no', 'en'] | False |
EmbyDevice.async_update_callback | (self, msg) | Handle device updates. | Handle device updates. | def async_update_callback(self, msg):
"""Handle device updates."""
# Check if we should update progress
if self.device.media_position:
if self.device.media_position != self.media_status_last_position:
self.media_status_last_position = self.device.media_position
self.media_status_received = dt_util.utcnow()
elif not self.device.is_nowplaying:
# No position, but we have an old value and are still playing
self.media_status_last_position = None
self.media_status_received = None
self.async_write_ha_state() | [
"def",
"async_update_callback",
"(",
"self",
",",
"msg",
")",
":",
"# Check if we should update progress",
"if",
"self",
".",
"device",
".",
"media_position",
":",
"if",
"self",
".",
"device",
".",
"media_position",
"!=",
"self",
".",
"media_status_last_position",
":",
"self",
".",
"media_status_last_position",
"=",
"self",
".",
"device",
".",
"media_position",
"self",
".",
"media_status_received",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"elif",
"not",
"self",
".",
"device",
".",
"is_nowplaying",
":",
"# No position, but we have an old value and are still playing",
"self",
".",
"media_status_last_position",
"=",
"None",
"self",
".",
"media_status_received",
"=",
"None",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
154,
4
] | [
166,
35
] | python | en | ['fr', 'sr', 'en'] | False |
EmbyDevice.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
169,
4
] | [
171,
30
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.set_available | (self, value) | Set available property. | Set available property. | def set_available(self, value):
"""Set available property."""
self._available = value | [
"def",
"set_available",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_available",
"=",
"value"
] | [
173,
4
] | [
175,
31
] | python | en | ['fr', 'en', 'en'] | True |
EmbyDevice.unique_id | (self) | Return the id of this emby client. | Return the id of this emby client. | def unique_id(self):
"""Return the id of this emby client."""
return self.device_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"device_id"
] | [
178,
4
] | [
180,
29
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.supports_remote_control | (self) | Return control ability. | Return control ability. | def supports_remote_control(self):
"""Return control ability."""
return self.device.supports_remote_control | [
"def",
"supports_remote_control",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"supports_remote_control"
] | [
183,
4
] | [
185,
50
] | python | en | ['en', 'cy', 'en'] | True |
EmbyDevice.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return f"Emby {self.device.name}" or DEVICE_DEFAULT_NAME | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"Emby {self.device.name}\"",
"or",
"DEVICE_DEFAULT_NAME"
] | [
188,
4
] | [
190,
64
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.should_poll | (self) | Return True if entity has to be polled for state. | Return True if entity has to be polled for state. | def should_poll(self):
"""Return True if entity has to be polled for state."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
193,
4
] | [
195,
20
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
state = self.device.state
if state == "Paused":
return STATE_PAUSED
if state == "Playing":
return STATE_PLAYING
if state == "Idle":
return STATE_IDLE
if state == "Off":
return STATE_OFF | [
"def",
"state",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"device",
".",
"state",
"if",
"state",
"==",
"\"Paused\"",
":",
"return",
"STATE_PAUSED",
"if",
"state",
"==",
"\"Playing\"",
":",
"return",
"STATE_PLAYING",
"if",
"state",
"==",
"\"Idle\"",
":",
"return",
"STATE_IDLE",
"if",
"state",
"==",
"\"Off\"",
":",
"return",
"STATE_OFF"
] | [
198,
4
] | [
208,
28
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.app_name | (self) | Return current user as app_name. | Return current user as app_name. | def app_name(self):
"""Return current user as app_name."""
# Ideally the media_player object would have a user property.
return self.device.username | [
"def",
"app_name",
"(",
"self",
")",
":",
"# Ideally the media_player object would have a user property.",
"return",
"self",
".",
"device",
".",
"username"
] | [
211,
4
] | [
214,
35
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_content_id | (self) | Content ID of current playing media. | Content ID of current playing media. | def media_content_id(self):
"""Content ID of current playing media."""
return self.device.media_id | [
"def",
"media_content_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_id"
] | [
217,
4
] | [
219,
35
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_content_type | (self) | Content type of current playing media. | Content type of current playing media. | def media_content_type(self):
"""Content type of current playing media."""
media_type = self.device.media_type
if media_type == "Episode":
return MEDIA_TYPE_TVSHOW
if media_type == "Movie":
return MEDIA_TYPE_MOVIE
if media_type == "Trailer":
return MEDIA_TYPE_TRAILER
if media_type == "Music":
return MEDIA_TYPE_MUSIC
if media_type == "Video":
return MEDIA_TYPE_GENERIC_VIDEO
if media_type == "Audio":
return MEDIA_TYPE_MUSIC
if media_type == "TvChannel":
return MEDIA_TYPE_CHANNEL
return None | [
"def",
"media_content_type",
"(",
"self",
")",
":",
"media_type",
"=",
"self",
".",
"device",
".",
"media_type",
"if",
"media_type",
"==",
"\"Episode\"",
":",
"return",
"MEDIA_TYPE_TVSHOW",
"if",
"media_type",
"==",
"\"Movie\"",
":",
"return",
"MEDIA_TYPE_MOVIE",
"if",
"media_type",
"==",
"\"Trailer\"",
":",
"return",
"MEDIA_TYPE_TRAILER",
"if",
"media_type",
"==",
"\"Music\"",
":",
"return",
"MEDIA_TYPE_MUSIC",
"if",
"media_type",
"==",
"\"Video\"",
":",
"return",
"MEDIA_TYPE_GENERIC_VIDEO",
"if",
"media_type",
"==",
"\"Audio\"",
":",
"return",
"MEDIA_TYPE_MUSIC",
"if",
"media_type",
"==",
"\"TvChannel\"",
":",
"return",
"MEDIA_TYPE_CHANNEL",
"return",
"None"
] | [
222,
4
] | [
239,
19
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_duration | (self) | Return the duration of current playing media in seconds. | Return the duration of current playing media in seconds. | def media_duration(self):
"""Return the duration of current playing media in seconds."""
return self.device.media_runtime | [
"def",
"media_duration",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_runtime"
] | [
242,
4
] | [
244,
40
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_position | (self) | Return the position of current playing media in seconds. | Return the position of current playing media in seconds. | def media_position(self):
"""Return the position of current playing media in seconds."""
return self.media_status_last_position | [
"def",
"media_position",
"(",
"self",
")",
":",
"return",
"self",
".",
"media_status_last_position"
] | [
247,
4
] | [
249,
46
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_position_updated_at | (self) |
When was the position of the current playing media valid.
Returns value from homeassistant.util.dt.utcnow().
|
When was the position of the current playing media valid. | def media_position_updated_at(self):
"""
When was the position of the current playing media valid.
Returns value from homeassistant.util.dt.utcnow().
"""
return self.media_status_received | [
"def",
"media_position_updated_at",
"(",
"self",
")",
":",
"return",
"self",
".",
"media_status_received"
] | [
252,
4
] | [
258,
41
] | python | en | ['en', 'error', 'th'] | False |
EmbyDevice.media_image_url | (self) | Return the image URL of current playing media. | Return the image URL of current playing media. | def media_image_url(self):
"""Return the image URL of current playing media."""
return self.device.media_image_url | [
"def",
"media_image_url",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_image_url"
] | [
261,
4
] | [
263,
42
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_title | (self) | Return the title of current playing media. | Return the title of current playing media. | def media_title(self):
"""Return the title of current playing media."""
return self.device.media_title | [
"def",
"media_title",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_title"
] | [
266,
4
] | [
268,
38
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_season | (self) | Season of current playing media (TV Show only). | Season of current playing media (TV Show only). | def media_season(self):
"""Season of current playing media (TV Show only)."""
return self.device.media_season | [
"def",
"media_season",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_season"
] | [
271,
4
] | [
273,
39
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_series_title | (self) | Return the title of the series of current playing media (TV). | Return the title of the series of current playing media (TV). | def media_series_title(self):
"""Return the title of the series of current playing media (TV)."""
return self.device.media_series_title | [
"def",
"media_series_title",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_series_title"
] | [
276,
4
] | [
278,
45
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_episode | (self) | Return the episode of current playing media (TV only). | Return the episode of current playing media (TV only). | def media_episode(self):
"""Return the episode of current playing media (TV only)."""
return self.device.media_episode | [
"def",
"media_episode",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_episode"
] | [
281,
4
] | [
283,
40
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_album_name | (self) | Return the album name of current playing media (Music only). | Return the album name of current playing media (Music only). | def media_album_name(self):
"""Return the album name of current playing media (Music only)."""
return self.device.media_album_name | [
"def",
"media_album_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_album_name"
] | [
286,
4
] | [
288,
43
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_artist | (self) | Return the artist of current playing media (Music track only). | Return the artist of current playing media (Music track only). | def media_artist(self):
"""Return the artist of current playing media (Music track only)."""
return self.device.media_artist | [
"def",
"media_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_artist"
] | [
291,
4
] | [
293,
39
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.media_album_artist | (self) | Return the album artist of current playing media (Music only). | Return the album artist of current playing media (Music only). | def media_album_artist(self):
"""Return the album artist of current playing media (Music only)."""
return self.device.media_album_artist | [
"def",
"media_album_artist",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"media_album_artist"
] | [
296,
4
] | [
298,
45
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.supported_features | (self) | Flag media player features that are supported. | Flag media player features that are supported. | def supported_features(self):
"""Flag media player features that are supported."""
if self.supports_remote_control:
return SUPPORT_EMBY
return 0 | [
"def",
"supported_features",
"(",
"self",
")",
":",
"if",
"self",
".",
"supports_remote_control",
":",
"return",
"SUPPORT_EMBY",
"return",
"0"
] | [
301,
4
] | [
305,
16
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.async_media_play | (self) | Play media. | Play media. | async def async_media_play(self):
"""Play media."""
await self.device.media_play() | [
"async",
"def",
"async_media_play",
"(",
"self",
")",
":",
"await",
"self",
".",
"device",
".",
"media_play",
"(",
")"
] | [
307,
4
] | [
309,
38
] | python | en | ['en', 'sv', 'en'] | False |
EmbyDevice.async_media_pause | (self) | Pause the media player. | Pause the media player. | async def async_media_pause(self):
"""Pause the media player."""
await self.device.media_pause() | [
"async",
"def",
"async_media_pause",
"(",
"self",
")",
":",
"await",
"self",
".",
"device",
".",
"media_pause",
"(",
")"
] | [
311,
4
] | [
313,
39
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.async_media_stop | (self) | Stop the media player. | Stop the media player. | async def async_media_stop(self):
"""Stop the media player."""
await self.device.media_stop() | [
"async",
"def",
"async_media_stop",
"(",
"self",
")",
":",
"await",
"self",
".",
"device",
".",
"media_stop",
"(",
")"
] | [
315,
4
] | [
317,
38
] | python | en | ['en', 'en', 'en'] | True |
EmbyDevice.async_media_next_track | (self) | Send next track command. | Send next track command. | async def async_media_next_track(self):
"""Send next track command."""
await self.device.media_next() | [
"async",
"def",
"async_media_next_track",
"(",
"self",
")",
":",
"await",
"self",
".",
"device",
".",
"media_next",
"(",
")"
] | [
319,
4
] | [
321,
38
] | python | en | ['en', 'pt', 'en'] | True |
EmbyDevice.async_media_previous_track | (self) | Send next track command. | Send next track command. | async def async_media_previous_track(self):
"""Send next track command."""
await self.device.media_previous() | [
"async",
"def",
"async_media_previous_track",
"(",
"self",
")",
":",
"await",
"self",
".",
"device",
".",
"media_previous",
"(",
")"
] | [
323,
4
] | [
325,
42
] | python | en | ['en', 'pt', 'en'] | True |
EmbyDevice.async_media_seek | (self, position) | Send seek command. | Send seek command. | async def async_media_seek(self, position):
"""Send seek command."""
await self.device.media_seek(position) | [
"async",
"def",
"async_media_seek",
"(",
"self",
",",
"position",
")",
":",
"await",
"self",
".",
"device",
".",
"media_seek",
"(",
"position",
")"
] | [
327,
4
] | [
329,
46
] | python | en | ['en', 'ig', 'en'] | True |
zigpy_device | (zigpy_device_mock) | Device tracker zigpy device. | Device tracker zigpy device. | def zigpy_device(zigpy_device_mock):
"""Device tracker zigpy device."""
def _dev(with_basic_channel: bool = True):
in_clusters = [general.OnOff.cluster_id]
if with_basic_channel:
in_clusters.append(general.Basic.cluster_id)
endpoints = {
3: {
"in_clusters": in_clusters,
"out_clusters": [],
"device_type": zigpy.profiles.zha.DeviceType.ON_OFF_SWITCH,
}
}
return zigpy_device_mock(endpoints)
return _dev | [
"def",
"zigpy_device",
"(",
"zigpy_device_mock",
")",
":",
"def",
"_dev",
"(",
"with_basic_channel",
":",
"bool",
"=",
"True",
")",
":",
"in_clusters",
"=",
"[",
"general",
".",
"OnOff",
".",
"cluster_id",
"]",
"if",
"with_basic_channel",
":",
"in_clusters",
".",
"append",
"(",
"general",
".",
"Basic",
".",
"cluster_id",
")",
"endpoints",
"=",
"{",
"3",
":",
"{",
"\"in_clusters\"",
":",
"in_clusters",
",",
"\"out_clusters\"",
":",
"[",
"]",
",",
"\"device_type\"",
":",
"zigpy",
".",
"profiles",
".",
"zha",
".",
"DeviceType",
".",
"ON_OFF_SWITCH",
",",
"}",
"}",
"return",
"zigpy_device_mock",
"(",
"endpoints",
")",
"return",
"_dev"
] | [
21,
0
] | [
38,
15
] | python | cs | ['nl', 'cs', 'en'] | False |
zigpy_device_mains | (zigpy_device_mock) | Device tracker zigpy device. | Device tracker zigpy device. | def zigpy_device_mains(zigpy_device_mock):
"""Device tracker zigpy device."""
def _dev(with_basic_channel: bool = True):
in_clusters = [general.OnOff.cluster_id]
if with_basic_channel:
in_clusters.append(general.Basic.cluster_id)
endpoints = {
3: {
"in_clusters": in_clusters,
"out_clusters": [],
"device_type": zigpy.profiles.zha.DeviceType.ON_OFF_SWITCH,
}
}
return zigpy_device_mock(
endpoints, node_descriptor=b"\x02@\x84_\x11\x7fd\x00\x00,d\x00\x00"
)
return _dev | [
"def",
"zigpy_device_mains",
"(",
"zigpy_device_mock",
")",
":",
"def",
"_dev",
"(",
"with_basic_channel",
":",
"bool",
"=",
"True",
")",
":",
"in_clusters",
"=",
"[",
"general",
".",
"OnOff",
".",
"cluster_id",
"]",
"if",
"with_basic_channel",
":",
"in_clusters",
".",
"append",
"(",
"general",
".",
"Basic",
".",
"cluster_id",
")",
"endpoints",
"=",
"{",
"3",
":",
"{",
"\"in_clusters\"",
":",
"in_clusters",
",",
"\"out_clusters\"",
":",
"[",
"]",
",",
"\"device_type\"",
":",
"zigpy",
".",
"profiles",
".",
"zha",
".",
"DeviceType",
".",
"ON_OFF_SWITCH",
",",
"}",
"}",
"return",
"zigpy_device_mock",
"(",
"endpoints",
",",
"node_descriptor",
"=",
"b\"\\x02@\\x84_\\x11\\x7fd\\x00\\x00,d\\x00\\x00\"",
")",
"return",
"_dev"
] | [
42,
0
] | [
61,
15
] | python | cs | ['nl', 'cs', 'en'] | False |
device_with_basic_channel | (zigpy_device_mains) | Return a zha device with a basic channel present. | Return a zha device with a basic channel present. | def device_with_basic_channel(zigpy_device_mains):
"""Return a zha device with a basic channel present."""
return zigpy_device_mains(with_basic_channel=True) | [
"def",
"device_with_basic_channel",
"(",
"zigpy_device_mains",
")",
":",
"return",
"zigpy_device_mains",
"(",
"with_basic_channel",
"=",
"True",
")"
] | [
65,
0
] | [
67,
54
] | python | en | ['en', 'en', 'en'] | True |
device_without_basic_channel | (zigpy_device) | Return a zha device with a basic channel present. | Return a zha device with a basic channel present. | def device_without_basic_channel(zigpy_device):
"""Return a zha device with a basic channel present."""
return zigpy_device(with_basic_channel=False) | [
"def",
"device_without_basic_channel",
"(",
"zigpy_device",
")",
":",
"return",
"zigpy_device",
"(",
"with_basic_channel",
"=",
"False",
")"
] | [
71,
0
] | [
73,
49
] | python | en | ['en', 'en', 'en'] | True |
ota_zha_device | (zha_device_restored, zigpy_device_mock) | ZHA device with OTA cluster fixture. | ZHA device with OTA cluster fixture. | async def ota_zha_device(zha_device_restored, zigpy_device_mock):
"""ZHA device with OTA cluster fixture."""
zigpy_dev = zigpy_device_mock(
{
1: {
"in_clusters": [general.Basic.cluster_id],
"out_clusters": [general.Ota.cluster_id],
"device_type": 0x1234,
}
},
"00:11:22:33:44:55:66:77",
"test manufacturer",
"test model",
)
zha_device = await zha_device_restored(zigpy_dev)
return zha_device | [
"async",
"def",
"ota_zha_device",
"(",
"zha_device_restored",
",",
"zigpy_device_mock",
")",
":",
"zigpy_dev",
"=",
"zigpy_device_mock",
"(",
"{",
"1",
":",
"{",
"\"in_clusters\"",
":",
"[",
"general",
".",
"Basic",
".",
"cluster_id",
"]",
",",
"\"out_clusters\"",
":",
"[",
"general",
".",
"Ota",
".",
"cluster_id",
"]",
",",
"\"device_type\"",
":",
"0x1234",
",",
"}",
"}",
",",
"\"00:11:22:33:44:55:66:77\"",
",",
"\"test manufacturer\"",
",",
"\"test model\"",
",",
")",
"zha_device",
"=",
"await",
"zha_device_restored",
"(",
"zigpy_dev",
")",
"return",
"zha_device"
] | [
77,
0
] | [
93,
21
] | python | en | ['en', 'en', 'en'] | True |
_send_time_changed | (hass, seconds) | Send a time changed event. | Send a time changed event. | def _send_time_changed(hass, seconds):
"""Send a time changed event."""
now = dt_util.utcnow() + timedelta(seconds=seconds)
async_fire_time_changed(hass, now) | [
"def",
"_send_time_changed",
"(",
"hass",
",",
"seconds",
")",
":",
"now",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"seconds",
")",
"async_fire_time_changed",
"(",
"hass",
",",
"now",
")"
] | [
96,
0
] | [
99,
38
] | python | en | ['en', 'en', 'en'] | True |
test_check_available_success | (
hass, device_with_basic_channel, zha_device_restored
) | Check device availability success on 1st try. | Check device availability success on 1st try. | async def test_check_available_success(
hass, device_with_basic_channel, zha_device_restored
):
"""Check device availability success on 1st try."""
# pylint: disable=protected-access
zha_device = await zha_device_restored(device_with_basic_channel)
await async_enable_traffic(hass, [zha_device])
basic_ch = device_with_basic_channel.endpoints[3].basic
basic_ch.read_attributes.reset_mock()
device_with_basic_channel.last_seen = None
assert zha_device.available is True
_send_time_changed(hass, zha_core_device.CONSIDER_UNAVAILABLE_MAINS + 2)
await hass.async_block_till_done()
assert zha_device.available is False
assert basic_ch.read_attributes.await_count == 0
device_with_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_MAINS - 2
)
_seens = [time.time(), device_with_basic_channel.last_seen]
def _update_last_seen(*args, **kwargs):
device_with_basic_channel.last_seen = _seens.pop()
basic_ch.read_attributes.side_effect = _update_last_seen
# successfully ping zigpy device, but zha_device is not yet available
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 1
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is False
# There was traffic from the device: pings, but not yet available
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 2
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is False
# There was traffic from the device: don't try to ping, marked as available
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 2
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is True | [
"async",
"def",
"test_check_available_success",
"(",
"hass",
",",
"device_with_basic_channel",
",",
"zha_device_restored",
")",
":",
"# pylint: disable=protected-access",
"zha_device",
"=",
"await",
"zha_device_restored",
"(",
"device_with_basic_channel",
")",
"await",
"async_enable_traffic",
"(",
"hass",
",",
"[",
"zha_device",
"]",
")",
"basic_ch",
"=",
"device_with_basic_channel",
".",
"endpoints",
"[",
"3",
"]",
".",
"basic",
"basic_ch",
".",
"read_attributes",
".",
"reset_mock",
"(",
")",
"device_with_basic_channel",
".",
"last_seen",
"=",
"None",
"assert",
"zha_device",
".",
"available",
"is",
"True",
"_send_time_changed",
"(",
"hass",
",",
"zha_core_device",
".",
"CONSIDER_UNAVAILABLE_MAINS",
"+",
"2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"zha_device",
".",
"available",
"is",
"False",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"0",
"device_with_basic_channel",
".",
"last_seen",
"=",
"(",
"time",
".",
"time",
"(",
")",
"-",
"zha_core_device",
".",
"CONSIDER_UNAVAILABLE_MAINS",
"-",
"2",
")",
"_seens",
"=",
"[",
"time",
".",
"time",
"(",
")",
",",
"device_with_basic_channel",
".",
"last_seen",
"]",
"def",
"_update_last_seen",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"device_with_basic_channel",
".",
"last_seen",
"=",
"_seens",
".",
"pop",
"(",
")",
"basic_ch",
".",
"read_attributes",
".",
"side_effect",
"=",
"_update_last_seen",
"# successfully ping zigpy device, but zha_device is not yet available",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"1",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"False",
"# There was traffic from the device: pings, but not yet available",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"2",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"False",
"# There was traffic from the device: don't try to ping, marked as available",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"2",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"True"
] | [
106,
0
] | [
153,
39
] | python | en | ['en', 'en', 'en'] | True |
test_check_available_unsuccessful | (
hass, device_with_basic_channel, zha_device_restored
) | Check device availability all tries fail. | Check device availability all tries fail. | async def test_check_available_unsuccessful(
hass, device_with_basic_channel, zha_device_restored
):
"""Check device availability all tries fail."""
# pylint: disable=protected-access
zha_device = await zha_device_restored(device_with_basic_channel)
await async_enable_traffic(hass, [zha_device])
basic_ch = device_with_basic_channel.endpoints[3].basic
assert zha_device.available is True
assert basic_ch.read_attributes.await_count == 0
device_with_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_MAINS - 2
)
# unsuccessfuly ping zigpy device, but zha_device is still available
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 1
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is True
# still no traffic, but zha_device is still available
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 2
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is True
# not even trying to update, device is unavailble
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert basic_ch.read_attributes.await_count == 2
assert basic_ch.read_attributes.await_args[0][0] == ["manufacturer"]
assert zha_device.available is False | [
"async",
"def",
"test_check_available_unsuccessful",
"(",
"hass",
",",
"device_with_basic_channel",
",",
"zha_device_restored",
")",
":",
"# pylint: disable=protected-access",
"zha_device",
"=",
"await",
"zha_device_restored",
"(",
"device_with_basic_channel",
")",
"await",
"async_enable_traffic",
"(",
"hass",
",",
"[",
"zha_device",
"]",
")",
"basic_ch",
"=",
"device_with_basic_channel",
".",
"endpoints",
"[",
"3",
"]",
".",
"basic",
"assert",
"zha_device",
".",
"available",
"is",
"True",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"0",
"device_with_basic_channel",
".",
"last_seen",
"=",
"(",
"time",
".",
"time",
"(",
")",
"-",
"zha_core_device",
".",
"CONSIDER_UNAVAILABLE_MAINS",
"-",
"2",
")",
"# unsuccessfuly ping zigpy device, but zha_device is still available",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"1",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"True",
"# still no traffic, but zha_device is still available",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"2",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"True",
"# not even trying to update, device is unavailble",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_count",
"==",
"2",
"assert",
"basic_ch",
".",
"read_attributes",
".",
"await_args",
"[",
"0",
"]",
"[",
"0",
"]",
"==",
"[",
"\"manufacturer\"",
"]",
"assert",
"zha_device",
".",
"available",
"is",
"False"
] | [
160,
0
] | [
196,
40
] | python | en | ['en', 'ga', 'en'] | True |
test_check_available_no_basic_channel | (
hass, device_without_basic_channel, zha_device_restored, caplog
) | Check device availability for a device without basic cluster. | Check device availability for a device without basic cluster. | async def test_check_available_no_basic_channel(
hass, device_without_basic_channel, zha_device_restored, caplog
):
"""Check device availability for a device without basic cluster."""
# pylint: disable=protected-access
zha_device = await zha_device_restored(device_without_basic_channel)
await async_enable_traffic(hass, [zha_device])
assert zha_device.available is True
device_without_basic_channel.last_seen = (
time.time() - zha_core_device.CONSIDER_UNAVAILABLE_BATTERY - 2
)
assert "does not have a mandatory basic cluster" not in caplog.text
_send_time_changed(hass, 91)
await hass.async_block_till_done()
assert zha_device.available is False
assert "does not have a mandatory basic cluster" in caplog.text | [
"async",
"def",
"test_check_available_no_basic_channel",
"(",
"hass",
",",
"device_without_basic_channel",
",",
"zha_device_restored",
",",
"caplog",
")",
":",
"# pylint: disable=protected-access",
"zha_device",
"=",
"await",
"zha_device_restored",
"(",
"device_without_basic_channel",
")",
"await",
"async_enable_traffic",
"(",
"hass",
",",
"[",
"zha_device",
"]",
")",
"assert",
"zha_device",
".",
"available",
"is",
"True",
"device_without_basic_channel",
".",
"last_seen",
"=",
"(",
"time",
".",
"time",
"(",
")",
"-",
"zha_core_device",
".",
"CONSIDER_UNAVAILABLE_BATTERY",
"-",
"2",
")",
"assert",
"\"does not have a mandatory basic cluster\"",
"not",
"in",
"caplog",
".",
"text",
"_send_time_changed",
"(",
"hass",
",",
"91",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"zha_device",
".",
"available",
"is",
"False",
"assert",
"\"does not have a mandatory basic cluster\"",
"in",
"caplog",
".",
"text"
] | [
203,
0
] | [
222,
67
] | python | en | ['en', 'en', 'en'] | True |
test_ota_sw_version | (hass, ota_zha_device) | Test device entry gets sw_version updated via OTA channel. | Test device entry gets sw_version updated via OTA channel. | async def test_ota_sw_version(hass, ota_zha_device):
"""Test device entry gets sw_version updated via OTA channel."""
ota_ch = ota_zha_device.channels.pools[0].client_channels["1:0x0019"]
dev_registry = await ha_dev_reg.async_get_registry(hass)
entry = dev_registry.async_get(ota_zha_device.device_id)
assert entry.sw_version is None
cluster = ota_ch.cluster
hdr = make_zcl_header(1, global_command=False)
sw_version = 0x2345
cluster.handle_message(hdr, [1, 2, 3, sw_version, None])
await hass.async_block_till_done()
entry = dev_registry.async_get(ota_zha_device.device_id)
assert int(entry.sw_version, base=16) == sw_version | [
"async",
"def",
"test_ota_sw_version",
"(",
"hass",
",",
"ota_zha_device",
")",
":",
"ota_ch",
"=",
"ota_zha_device",
".",
"channels",
".",
"pools",
"[",
"0",
"]",
".",
"client_channels",
"[",
"\"1:0x0019\"",
"]",
"dev_registry",
"=",
"await",
"ha_dev_reg",
".",
"async_get_registry",
"(",
"hass",
")",
"entry",
"=",
"dev_registry",
".",
"async_get",
"(",
"ota_zha_device",
".",
"device_id",
")",
"assert",
"entry",
".",
"sw_version",
"is",
"None",
"cluster",
"=",
"ota_ch",
".",
"cluster",
"hdr",
"=",
"make_zcl_header",
"(",
"1",
",",
"global_command",
"=",
"False",
")",
"sw_version",
"=",
"0x2345",
"cluster",
".",
"handle_message",
"(",
"hdr",
",",
"[",
"1",
",",
"2",
",",
"3",
",",
"sw_version",
",",
"None",
"]",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"entry",
"=",
"dev_registry",
".",
"async_get",
"(",
"ota_zha_device",
".",
"device_id",
")",
"assert",
"int",
"(",
"entry",
".",
"sw_version",
",",
"base",
"=",
"16",
")",
"==",
"sw_version"
] | [
225,
0
] | [
239,
55
] | python | en | ['en', 'en', 'en'] | True |
test_device_restore_availability | (
hass, request, device, last_seen_delta, is_available, zha_device_restored
) | Test initial availability for restored devices. | Test initial availability for restored devices. | async def test_device_restore_availability(
hass, request, device, last_seen_delta, is_available, zha_device_restored
):
"""Test initial availability for restored devices."""
zigpy_device = request.getfixturevalue(device)()
zha_device = await zha_device_restored(
zigpy_device, last_seen=time.time() - last_seen_delta
)
entity_id = "switch.fakemanufacturer_fakemodel_e769900a_on_off"
await hass.async_block_till_done()
# ensure the switch entity was created
assert hass.states.get(entity_id).state is not None
assert zha_device.available is is_available
if is_available:
assert hass.states.get(entity_id).state == STATE_OFF
else:
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE | [
"async",
"def",
"test_device_restore_availability",
"(",
"hass",
",",
"request",
",",
"device",
",",
"last_seen_delta",
",",
"is_available",
",",
"zha_device_restored",
")",
":",
"zigpy_device",
"=",
"request",
".",
"getfixturevalue",
"(",
"device",
")",
"(",
")",
"zha_device",
"=",
"await",
"zha_device_restored",
"(",
"zigpy_device",
",",
"last_seen",
"=",
"time",
".",
"time",
"(",
")",
"-",
"last_seen_delta",
")",
"entity_id",
"=",
"\"switch.fakemanufacturer_fakemodel_e769900a_on_off\"",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"# ensure the switch entity was created",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"is",
"not",
"None",
"assert",
"zha_device",
".",
"available",
"is",
"is_available",
"if",
"is_available",
":",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"==",
"STATE_OFF",
"else",
":",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
284,
0
] | [
302,
68
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Lutron Caseta switch platform.
Adds switches from the Caseta bridge associated with the config_entry as
switch entities.
| Set up the Lutron Caseta switch platform. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Lutron Caseta switch platform.
Adds switches from the Caseta bridge associated with the config_entry as
switch entities.
"""
entities = []
bridge = hass.data[CASETA_DOMAIN][config_entry.entry_id]
switch_devices = bridge.get_devices_by_domain(DOMAIN)
for switch_device in switch_devices:
entity = LutronCasetaLight(switch_device, bridge)
entities.append(entity)
async_add_entities(entities, True)
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"[",
"]",
"bridge",
"=",
"hass",
".",
"data",
"[",
"CASETA_DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"switch_devices",
"=",
"bridge",
".",
"get_devices_by_domain",
"(",
"DOMAIN",
")",
"for",
"switch_device",
"in",
"switch_devices",
":",
"entity",
"=",
"LutronCasetaLight",
"(",
"switch_device",
",",
"bridge",
")",
"entities",
".",
"append",
"(",
"entity",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
")",
"return",
"True"
] | [
10,
0
] | [
26,
15
] | python | en | ['en', 'zu', 'en'] | True |
LutronCasetaLight.async_turn_on | (self, **kwargs) | Turn the switch on. | Turn the switch on. | async def async_turn_on(self, **kwargs):
"""Turn the switch on."""
await self._smartbridge.turn_on(self.device_id) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_smartbridge",
".",
"turn_on",
"(",
"self",
".",
"device_id",
")"
] | [
32,
4
] | [
34,
55
] | python | en | ['en', 'en', 'en'] | True |
LutronCasetaLight.async_turn_off | (self, **kwargs) | Turn the switch off. | Turn the switch off. | async def async_turn_off(self, **kwargs):
"""Turn the switch off."""
await self._smartbridge.turn_off(self.device_id) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_smartbridge",
".",
"turn_off",
"(",
"self",
".",
"device_id",
")"
] | [
36,
4
] | [
38,
56
] | python | en | ['en', 'en', 'en'] | True |
LutronCasetaLight.is_on | (self) | Return true if device is on. | Return true if device is on. | def is_on(self):
"""Return true if device is on."""
return self._device["current_state"] > 0 | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
"[",
"\"current_state\"",
"]",
">",
"0"
] | [
41,
4
] | [
43,
48
] | python | en | ['en', 'fy', 'en'] | True |
LutronCasetaLight.async_update | (self) | Update when forcing a refresh of the device. | Update when forcing a refresh of the device. | async def async_update(self):
"""Update when forcing a refresh of the device."""
self._device = self._smartbridge.get_device_by_id(self.device_id)
_LOGGER.debug(self._device) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"self",
".",
"_device",
"=",
"self",
".",
"_smartbridge",
".",
"get_device_by_id",
"(",
"self",
".",
"device_id",
")",
"_LOGGER",
".",
"debug",
"(",
"self",
".",
"_device",
")"
] | [
45,
4
] | [
48,
35
] | python | en | ['en', 'en', 'en'] | True |
make_filter | (callsigns: list) | Make a server-side filter from a list of callsigns. | Make a server-side filter from a list of callsigns. | def make_filter(callsigns: list) -> str:
"""Make a server-side filter from a list of callsigns."""
return " ".join(f"b/{sign.upper()}" for sign in callsigns) | [
"def",
"make_filter",
"(",
"callsigns",
":",
"list",
")",
"->",
"str",
":",
"return",
"\" \"",
".",
"join",
"(",
"f\"b/{sign.upper()}\"",
"for",
"sign",
"in",
"callsigns",
")"
] | [
57,
0
] | [
59,
62
] | python | en | ['en', 'en', 'en'] | True |
gps_accuracy | (gps, posambiguity: int) | Calculate the GPS accuracy based on APRS posambiguity. | Calculate the GPS accuracy based on APRS posambiguity. | def gps_accuracy(gps, posambiguity: int) -> int:
"""Calculate the GPS accuracy based on APRS posambiguity."""
pos_a_map = {0: 0, 1: 1 / 600, 2: 1 / 60, 3: 1 / 6, 4: 1}
if posambiguity in pos_a_map:
degrees = pos_a_map[posambiguity]
gps2 = (gps[0], gps[1] + degrees)
dist_m = geopy.distance.distance(gps, gps2).m
accuracy = round(dist_m)
else:
message = f"APRS position ambiguity must be 0-4, not '{posambiguity}'."
raise ValueError(message)
return accuracy | [
"def",
"gps_accuracy",
"(",
"gps",
",",
"posambiguity",
":",
"int",
")",
"->",
"int",
":",
"pos_a_map",
"=",
"{",
"0",
":",
"0",
",",
"1",
":",
"1",
"/",
"600",
",",
"2",
":",
"1",
"/",
"60",
",",
"3",
":",
"1",
"/",
"6",
",",
"4",
":",
"1",
"}",
"if",
"posambiguity",
"in",
"pos_a_map",
":",
"degrees",
"=",
"pos_a_map",
"[",
"posambiguity",
"]",
"gps2",
"=",
"(",
"gps",
"[",
"0",
"]",
",",
"gps",
"[",
"1",
"]",
"+",
"degrees",
")",
"dist_m",
"=",
"geopy",
".",
"distance",
".",
"distance",
"(",
"gps",
",",
"gps2",
")",
".",
"m",
"accuracy",
"=",
"round",
"(",
"dist_m",
")",
"else",
":",
"message",
"=",
"f\"APRS position ambiguity must be 0-4, not '{posambiguity}'.\"",
"raise",
"ValueError",
"(",
"message",
")",
"return",
"accuracy"
] | [
62,
0
] | [
77,
19
] | python | en | ['en', 'en', 'en'] | True |
setup_scanner | (hass, config, see, discovery_info=None) | Set up the APRS tracker. | Set up the APRS tracker. | def setup_scanner(hass, config, see, discovery_info=None):
"""Set up the APRS tracker."""
callsigns = config.get(CONF_CALLSIGNS)
server_filter = make_filter(callsigns)
callsign = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
host = config.get(CONF_HOST)
timeout = config.get(CONF_TIMEOUT)
aprs_listener = AprsListenerThread(callsign, password, host, server_filter, see)
def aprs_disconnect(event):
"""Stop the APRS connection."""
aprs_listener.stop()
aprs_listener.start()
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, aprs_disconnect)
if not aprs_listener.start_event.wait(timeout):
_LOGGER.error("Timeout waiting for APRS to connect")
return
if not aprs_listener.start_success:
_LOGGER.error(aprs_listener.start_message)
return
_LOGGER.debug(aprs_listener.start_message)
return True | [
"def",
"setup_scanner",
"(",
"hass",
",",
"config",
",",
"see",
",",
"discovery_info",
"=",
"None",
")",
":",
"callsigns",
"=",
"config",
".",
"get",
"(",
"CONF_CALLSIGNS",
")",
"server_filter",
"=",
"make_filter",
"(",
"callsigns",
")",
"callsign",
"=",
"config",
".",
"get",
"(",
"CONF_USERNAME",
")",
"password",
"=",
"config",
".",
"get",
"(",
"CONF_PASSWORD",
")",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",
"timeout",
"=",
"config",
".",
"get",
"(",
"CONF_TIMEOUT",
")",
"aprs_listener",
"=",
"AprsListenerThread",
"(",
"callsign",
",",
"password",
",",
"host",
",",
"server_filter",
",",
"see",
")",
"def",
"aprs_disconnect",
"(",
"event",
")",
":",
"\"\"\"Stop the APRS connection.\"\"\"",
"aprs_listener",
".",
"stop",
"(",
")",
"aprs_listener",
".",
"start",
"(",
")",
"hass",
".",
"bus",
".",
"listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"aprs_disconnect",
")",
"if",
"not",
"aprs_listener",
".",
"start_event",
".",
"wait",
"(",
"timeout",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Timeout waiting for APRS to connect\"",
")",
"return",
"if",
"not",
"aprs_listener",
".",
"start_success",
":",
"_LOGGER",
".",
"error",
"(",
"aprs_listener",
".",
"start_message",
")",
"return",
"_LOGGER",
".",
"debug",
"(",
"aprs_listener",
".",
"start_message",
")",
"return",
"True"
] | [
80,
0
] | [
107,
15
] | python | en | ['en', 'en', 'en'] | True |
AprsListenerThread.__init__ | (
self, callsign: str, password: str, host: str, server_filter: str, see
) | Initialize the class. | Initialize the class. | def __init__(
self, callsign: str, password: str, host: str, server_filter: str, see
):
"""Initialize the class."""
super().__init__()
self.callsign = callsign
self.host = host
self.start_event = threading.Event()
self.see = see
self.server_filter = server_filter
self.start_message = ""
self.start_success = False
self.ais = aprslib.IS(
self.callsign, passwd=password, host=self.host, port=FILTER_PORT
) | [
"def",
"__init__",
"(",
"self",
",",
"callsign",
":",
"str",
",",
"password",
":",
"str",
",",
"host",
":",
"str",
",",
"server_filter",
":",
"str",
",",
"see",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
")",
"self",
".",
"callsign",
"=",
"callsign",
"self",
".",
"host",
"=",
"host",
"self",
".",
"start_event",
"=",
"threading",
".",
"Event",
"(",
")",
"self",
".",
"see",
"=",
"see",
"self",
".",
"server_filter",
"=",
"server_filter",
"self",
".",
"start_message",
"=",
"\"\"",
"self",
".",
"start_success",
"=",
"False",
"self",
".",
"ais",
"=",
"aprslib",
".",
"IS",
"(",
"self",
".",
"callsign",
",",
"passwd",
"=",
"password",
",",
"host",
"=",
"self",
".",
"host",
",",
"port",
"=",
"FILTER_PORT",
")"
] | [
113,
4
] | [
129,
9
] | python | en | ['en', 'en', 'en'] | True |
AprsListenerThread.start_complete | (self, success: bool, message: str) | Complete startup process. | Complete startup process. | def start_complete(self, success: bool, message: str):
"""Complete startup process."""
self.start_message = message
self.start_success = success
self.start_event.set() | [
"def",
"start_complete",
"(",
"self",
",",
"success",
":",
"bool",
",",
"message",
":",
"str",
")",
":",
"self",
".",
"start_message",
"=",
"message",
"self",
".",
"start_success",
"=",
"success",
"self",
".",
"start_event",
".",
"set",
"(",
")"
] | [
131,
4
] | [
135,
30
] | python | en | ['en', 'en', 'en'] | True |
AprsListenerThread.run | (self) | Connect to APRS and listen for data. | Connect to APRS and listen for data. | def run(self):
"""Connect to APRS and listen for data."""
self.ais.set_filter(self.server_filter)
try:
_LOGGER.info(
"Opening connection to %s with callsign %s", self.host, self.callsign
)
self.ais.connect()
self.start_complete(
True, f"Connected to {self.host} with callsign {self.callsign}."
)
self.ais.consumer(callback=self.rx_msg, immortal=True)
except (AprsConnectionError, LoginError) as err:
self.start_complete(False, str(err))
except OSError:
_LOGGER.info(
"Closing connection to %s with callsign %s", self.host, self.callsign
) | [
"def",
"run",
"(",
"self",
")",
":",
"self",
".",
"ais",
".",
"set_filter",
"(",
"self",
".",
"server_filter",
")",
"try",
":",
"_LOGGER",
".",
"info",
"(",
"\"Opening connection to %s with callsign %s\"",
",",
"self",
".",
"host",
",",
"self",
".",
"callsign",
")",
"self",
".",
"ais",
".",
"connect",
"(",
")",
"self",
".",
"start_complete",
"(",
"True",
",",
"f\"Connected to {self.host} with callsign {self.callsign}.\"",
")",
"self",
".",
"ais",
".",
"consumer",
"(",
"callback",
"=",
"self",
".",
"rx_msg",
",",
"immortal",
"=",
"True",
")",
"except",
"(",
"AprsConnectionError",
",",
"LoginError",
")",
"as",
"err",
":",
"self",
".",
"start_complete",
"(",
"False",
",",
"str",
"(",
"err",
")",
")",
"except",
"OSError",
":",
"_LOGGER",
".",
"info",
"(",
"\"Closing connection to %s with callsign %s\"",
",",
"self",
".",
"host",
",",
"self",
".",
"callsign",
")"
] | [
137,
4
] | [
155,
13
] | python | en | ['en', 'en', 'en'] | True |
AprsListenerThread.stop | (self) | Close the connection to the APRS network. | Close the connection to the APRS network. | def stop(self):
"""Close the connection to the APRS network."""
self.ais.close() | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"ais",
".",
"close",
"(",
")"
] | [
157,
4
] | [
159,
24
] | python | en | ['en', 'en', 'en'] | True |
AprsListenerThread.rx_msg | (self, msg: dict) | Receive message and process if position. | Receive message and process if position. | def rx_msg(self, msg: dict):
"""Receive message and process if position."""
_LOGGER.debug("APRS message received: %s", str(msg))
if msg[ATTR_FORMAT] in MSG_FORMATS:
dev_id = slugify(msg[ATTR_FROM])
lat = msg[ATTR_LATITUDE]
lon = msg[ATTR_LONGITUDE]
attrs = {}
if ATTR_POS_AMBIGUITY in msg:
pos_amb = msg[ATTR_POS_AMBIGUITY]
try:
attrs[ATTR_GPS_ACCURACY] = gps_accuracy((lat, lon), pos_amb)
except ValueError:
_LOGGER.warning(
"APRS message contained invalid posambiguity: %s", str(pos_amb)
)
for attr in [ATTR_ALTITUDE, ATTR_COMMENT, ATTR_COURSE, ATTR_SPEED]:
if attr in msg:
attrs[attr] = msg[attr]
self.see(dev_id=dev_id, gps=(lat, lon), attributes=attrs) | [
"def",
"rx_msg",
"(",
"self",
",",
"msg",
":",
"dict",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"APRS message received: %s\"",
",",
"str",
"(",
"msg",
")",
")",
"if",
"msg",
"[",
"ATTR_FORMAT",
"]",
"in",
"MSG_FORMATS",
":",
"dev_id",
"=",
"slugify",
"(",
"msg",
"[",
"ATTR_FROM",
"]",
")",
"lat",
"=",
"msg",
"[",
"ATTR_LATITUDE",
"]",
"lon",
"=",
"msg",
"[",
"ATTR_LONGITUDE",
"]",
"attrs",
"=",
"{",
"}",
"if",
"ATTR_POS_AMBIGUITY",
"in",
"msg",
":",
"pos_amb",
"=",
"msg",
"[",
"ATTR_POS_AMBIGUITY",
"]",
"try",
":",
"attrs",
"[",
"ATTR_GPS_ACCURACY",
"]",
"=",
"gps_accuracy",
"(",
"(",
"lat",
",",
"lon",
")",
",",
"pos_amb",
")",
"except",
"ValueError",
":",
"_LOGGER",
".",
"warning",
"(",
"\"APRS message contained invalid posambiguity: %s\"",
",",
"str",
"(",
"pos_amb",
")",
")",
"for",
"attr",
"in",
"[",
"ATTR_ALTITUDE",
",",
"ATTR_COMMENT",
",",
"ATTR_COURSE",
",",
"ATTR_SPEED",
"]",
":",
"if",
"attr",
"in",
"msg",
":",
"attrs",
"[",
"attr",
"]",
"=",
"msg",
"[",
"attr",
"]",
"self",
".",
"see",
"(",
"dev_id",
"=",
"dev_id",
",",
"gps",
"=",
"(",
"lat",
",",
"lon",
")",
",",
"attributes",
"=",
"attrs",
")"
] | [
161,
4
] | [
182,
69
] | python | en | ['en', 'en', 'en'] | True |
StarlineAccount.__init__ | (self, hass: HomeAssistant, config_entry: ConfigEntry) | Initialize StarLine account. | Initialize StarLine account. | def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry):
"""Initialize StarLine account."""
self._hass: HomeAssistant = hass
self._config_entry: ConfigEntry = config_entry
self._update_interval: int = DEFAULT_SCAN_INTERVAL
self._unsubscribe_auto_updater: Optional[Callable] = None
self._api: StarlineApi = StarlineApi(
config_entry.data[DATA_USER_ID], config_entry.data[DATA_SLNET_TOKEN]
) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
")",
":",
"self",
".",
"_hass",
":",
"HomeAssistant",
"=",
"hass",
"self",
".",
"_config_entry",
":",
"ConfigEntry",
"=",
"config_entry",
"self",
".",
"_update_interval",
":",
"int",
"=",
"DEFAULT_SCAN_INTERVAL",
"self",
".",
"_unsubscribe_auto_updater",
":",
"Optional",
"[",
"Callable",
"]",
"=",
"None",
"self",
".",
"_api",
":",
"StarlineApi",
"=",
"StarlineApi",
"(",
"config_entry",
".",
"data",
"[",
"DATA_USER_ID",
"]",
",",
"config_entry",
".",
"data",
"[",
"DATA_SLNET_TOKEN",
"]",
")"
] | [
24,
4
] | [
32,
9
] | python | en | ['en', 'en', 'en'] | True |
StarlineAccount._check_slnet_token | (self) | Check SLNet token expiration and update if needed. | Check SLNet token expiration and update if needed. | def _check_slnet_token(self) -> None:
"""Check SLNet token expiration and update if needed."""
now = datetime.now().timestamp()
slnet_token_expires = self._config_entry.data[DATA_EXPIRES]
if now + self._update_interval > slnet_token_expires:
self._update_slnet_token() | [
"def",
"_check_slnet_token",
"(",
"self",
")",
"->",
"None",
":",
"now",
"=",
"datetime",
".",
"now",
"(",
")",
".",
"timestamp",
"(",
")",
"slnet_token_expires",
"=",
"self",
".",
"_config_entry",
".",
"data",
"[",
"DATA_EXPIRES",
"]",
"if",
"now",
"+",
"self",
".",
"_update_interval",
">",
"slnet_token_expires",
":",
"self",
".",
"_update_slnet_token",
"(",
")"
] | [
34,
4
] | [
40,
38
] | python | en | ['en', 'en', 'en'] | True |
StarlineAccount._update_slnet_token | (self) | Update SLNet token. | Update SLNet token. | def _update_slnet_token(self) -> None:
"""Update SLNet token."""
slid_token = self._config_entry.data[DATA_SLID_TOKEN]
try:
slnet_token, slnet_token_expires, user_id = self._api.get_user_id(
slid_token
)
self._api.set_slnet_token(slnet_token)
self._api.set_user_id(user_id)
self._hass.config_entries.async_update_entry(
self._config_entry,
data={
**self._config_entry.data,
DATA_SLNET_TOKEN: slnet_token,
DATA_EXPIRES: slnet_token_expires,
DATA_USER_ID: user_id,
},
)
except Exception as err: # pylint: disable=broad-except
_LOGGER.error("Error updating SLNet token: %s", err) | [
"def",
"_update_slnet_token",
"(",
"self",
")",
"->",
"None",
":",
"slid_token",
"=",
"self",
".",
"_config_entry",
".",
"data",
"[",
"DATA_SLID_TOKEN",
"]",
"try",
":",
"slnet_token",
",",
"slnet_token_expires",
",",
"user_id",
"=",
"self",
".",
"_api",
".",
"get_user_id",
"(",
"slid_token",
")",
"self",
".",
"_api",
".",
"set_slnet_token",
"(",
"slnet_token",
")",
"self",
".",
"_api",
".",
"set_user_id",
"(",
"user_id",
")",
"self",
".",
"_hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"self",
".",
"_config_entry",
",",
"data",
"=",
"{",
"*",
"*",
"self",
".",
"_config_entry",
".",
"data",
",",
"DATA_SLNET_TOKEN",
":",
"slnet_token",
",",
"DATA_EXPIRES",
":",
"slnet_token_expires",
",",
"DATA_USER_ID",
":",
"user_id",
",",
"}",
",",
")",
"except",
"Exception",
"as",
"err",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"error",
"(",
"\"Error updating SLNet token: %s\"",
",",
"err",
")"
] | [
42,
4
] | [
62,
64
] | python | nl | ['nl', 'nl', 'en'] | True |
StarlineAccount._update_data | (self) | Update StarLine data. | Update StarLine data. | def _update_data(self):
"""Update StarLine data."""
self._check_slnet_token()
self._api.update() | [
"def",
"_update_data",
"(",
"self",
")",
":",
"self",
".",
"_check_slnet_token",
"(",
")",
"self",
".",
"_api",
".",
"update",
"(",
")"
] | [
64,
4
] | [
67,
26
] | python | de | ['it', 'de', 'en'] | False |
StarlineAccount.api | (self) | Return the instance of the API. | Return the instance of the API. | def api(self) -> StarlineApi:
"""Return the instance of the API."""
return self._api | [
"def",
"api",
"(",
"self",
")",
"->",
"StarlineApi",
":",
"return",
"self",
".",
"_api"
] | [
70,
4
] | [
72,
24
] | python | en | ['en', 'en', 'en'] | True |
StarlineAccount.update | (self, unused=None) | Update StarLine data. | Update StarLine data. | async def update(self, unused=None):
"""Update StarLine data."""
await self._hass.async_add_executor_job(self._update_data) | [
"async",
"def",
"update",
"(",
"self",
",",
"unused",
"=",
"None",
")",
":",
"await",
"self",
".",
"_hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_update_data",
")"
] | [
74,
4
] | [
76,
66
] | python | de | ['it', 'de', 'en'] | False |
StarlineAccount.set_update_interval | (self, interval: int) | Set StarLine API update interval. | Set StarLine API update interval. | def set_update_interval(self, interval: int) -> None:
"""Set StarLine API update interval."""
_LOGGER.debug("Setting update interval: %ds", interval)
self._update_interval = interval
if self._unsubscribe_auto_updater is not None:
self._unsubscribe_auto_updater()
delta = timedelta(seconds=interval)
self._unsubscribe_auto_updater = async_track_time_interval(
self._hass, self.update, delta
) | [
"def",
"set_update_interval",
"(",
"self",
",",
"interval",
":",
"int",
")",
"->",
"None",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting update interval: %ds\"",
",",
"interval",
")",
"self",
".",
"_update_interval",
"=",
"interval",
"if",
"self",
".",
"_unsubscribe_auto_updater",
"is",
"not",
"None",
":",
"self",
".",
"_unsubscribe_auto_updater",
"(",
")",
"delta",
"=",
"timedelta",
"(",
"seconds",
"=",
"interval",
")",
"self",
".",
"_unsubscribe_auto_updater",
"=",
"async_track_time_interval",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"update",
",",
"delta",
")"
] | [
78,
4
] | [
88,
9
] | python | en | ['en', 'bs', 'en'] | True |
StarlineAccount.unload | (self) | Unload StarLine API. | Unload StarLine API. | def unload(self):
"""Unload StarLine API."""
_LOGGER.debug("Unloading StarLine API.")
if self._unsubscribe_auto_updater is not None:
self._unsubscribe_auto_updater()
self._unsubscribe_auto_updater = None | [
"def",
"unload",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Unloading StarLine API.\"",
")",
"if",
"self",
".",
"_unsubscribe_auto_updater",
"is",
"not",
"None",
":",
"self",
".",
"_unsubscribe_auto_updater",
"(",
")",
"self",
".",
"_unsubscribe_auto_updater",
"=",
"None"
] | [
90,
4
] | [
95,
49
] | python | en | ['en', 'bs', 'en'] | True |
StarlineAccount.device_info | (device: StarlineDevice) | Device information for entities. | Device information for entities. | def device_info(device: StarlineDevice) -> Dict[str, Any]:
"""Device information for entities."""
return {
"identifiers": {(DOMAIN, device.device_id)},
"manufacturer": "StarLine",
"name": device.name,
"sw_version": device.fw_version,
"model": device.typename,
} | [
"def",
"device_info",
"(",
"device",
":",
"StarlineDevice",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"device",
".",
"device_id",
")",
"}",
",",
"\"manufacturer\"",
":",
"\"StarLine\"",
",",
"\"name\"",
":",
"device",
".",
"name",
",",
"\"sw_version\"",
":",
"device",
".",
"fw_version",
",",
"\"model\"",
":",
"device",
".",
"typename",
",",
"}"
] | [
98,
4
] | [
106,
9
] | python | en | ['da', 'en', 'en'] | True |
StarlineAccount.gps_attrs | (device: StarlineDevice) | Attributes for device tracker. | Attributes for device tracker. | def gps_attrs(device: StarlineDevice) -> Dict[str, Any]:
"""Attributes for device tracker."""
return {
"updated": datetime.utcfromtimestamp(device.position["ts"]).isoformat(),
"online": device.online,
} | [
"def",
"gps_attrs",
"(",
"device",
":",
"StarlineDevice",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"{",
"\"updated\"",
":",
"datetime",
".",
"utcfromtimestamp",
"(",
"device",
".",
"position",
"[",
"\"ts\"",
"]",
")",
".",
"isoformat",
"(",
")",
",",
"\"online\"",
":",
"device",
".",
"online",
",",
"}"
] | [
109,
4
] | [
114,
9
] | python | en | ['da', 'en', 'en'] | True |
StarlineAccount.balance_attrs | (device: StarlineDevice) | Attributes for balance sensor. | Attributes for balance sensor. | def balance_attrs(device: StarlineDevice) -> Dict[str, Any]:
"""Attributes for balance sensor."""
return {
"operator": device.balance.get("operator"),
"state": device.balance.get("state"),
"updated": device.balance.get("ts"),
} | [
"def",
"balance_attrs",
"(",
"device",
":",
"StarlineDevice",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"{",
"\"operator\"",
":",
"device",
".",
"balance",
".",
"get",
"(",
"\"operator\"",
")",
",",
"\"state\"",
":",
"device",
".",
"balance",
".",
"get",
"(",
"\"state\"",
")",
",",
"\"updated\"",
":",
"device",
".",
"balance",
".",
"get",
"(",
"\"ts\"",
")",
",",
"}"
] | [
117,
4
] | [
123,
9
] | python | en | ['en', 'ceb', 'en'] | True |
StarlineAccount.gsm_attrs | (device: StarlineDevice) | Attributes for GSM sensor. | Attributes for GSM sensor. | def gsm_attrs(device: StarlineDevice) -> Dict[str, Any]:
"""Attributes for GSM sensor."""
return {
"raw": device.gsm_level,
"imei": device.imei,
"phone": device.phone,
"online": device.online,
} | [
"def",
"gsm_attrs",
"(",
"device",
":",
"StarlineDevice",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"{",
"\"raw\"",
":",
"device",
".",
"gsm_level",
",",
"\"imei\"",
":",
"device",
".",
"imei",
",",
"\"phone\"",
":",
"device",
".",
"phone",
",",
"\"online\"",
":",
"device",
".",
"online",
",",
"}"
] | [
126,
4
] | [
133,
9
] | python | en | ['en', 'pt', '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.