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 |
---|---|---|---|---|---|---|---|---|---|---|---|
SlideCover.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_ID: self._id} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_ID",
":",
"self",
".",
"_id",
"}"
] | [
57,
4
] | [
59,
34
] | python | en | ['fr', 'en', 'en'] | True |
SlideCover.is_opening | (self) | Return if the cover is opening or not. | Return if the cover is opening or not. | def is_opening(self):
"""Return if the cover is opening or not."""
return self._slide["state"] == STATE_OPENING | [
"def",
"is_opening",
"(",
"self",
")",
":",
"return",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"==",
"STATE_OPENING"
] | [
62,
4
] | [
64,
52
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.is_closing | (self) | Return if the cover is closing or not. | Return if the cover is closing or not. | def is_closing(self):
"""Return if the cover is closing or not."""
return self._slide["state"] == STATE_CLOSING | [
"def",
"is_closing",
"(",
"self",
")",
":",
"return",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"==",
"STATE_CLOSING"
] | [
67,
4
] | [
69,
52
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.is_closed | (self) | Return None if status is unknown, True if closed, else False. | Return None if status is unknown, True if closed, else False. | def is_closed(self):
"""Return None if status is unknown, True if closed, else False."""
if self._slide["state"] is None:
return None
return self._slide["state"] == STATE_CLOSED | [
"def",
"is_closed",
"(",
"self",
")",
":",
"if",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"is",
"None",
":",
"return",
"None",
"return",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"==",
"STATE_CLOSED"
] | [
72,
4
] | [
76,
51
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.available | (self) | Return False if state is not available. | Return False if state is not available. | def available(self):
"""Return False if state is not available."""
return self._slide["online"] | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_slide",
"[",
"\"online\"",
"]"
] | [
79,
4
] | [
81,
36
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.assumed_state | (self) | Let HA know the integration is assumed state. | Let HA know the integration is assumed state. | def assumed_state(self):
"""Let HA know the integration is assumed state."""
return True | [
"def",
"assumed_state",
"(",
"self",
")",
":",
"return",
"True"
] | [
84,
4
] | [
86,
19
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.device_class | (self) | Return the device class of the cover. | Return the device class of the cover. | def device_class(self):
"""Return the device class of the cover."""
return DEVICE_CLASS_CURTAIN | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_CURTAIN"
] | [
89,
4
] | [
91,
35
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.current_cover_position | (self) | Return the current position of cover shutter. | Return the current position of cover shutter. | def current_cover_position(self):
"""Return the current position of cover shutter."""
pos = self._slide["pos"]
if pos is not None:
if (1 - pos) <= DEFAULT_OFFSET or pos <= DEFAULT_OFFSET:
pos = round(pos)
if not self._invert:
pos = 1 - pos
pos = int(pos * 100)
return pos | [
"def",
"current_cover_position",
"(",
"self",
")",
":",
"pos",
"=",
"self",
".",
"_slide",
"[",
"\"pos\"",
"]",
"if",
"pos",
"is",
"not",
"None",
":",
"if",
"(",
"1",
"-",
"pos",
")",
"<=",
"DEFAULT_OFFSET",
"or",
"pos",
"<=",
"DEFAULT_OFFSET",
":",
"pos",
"=",
"round",
"(",
"pos",
")",
"if",
"not",
"self",
".",
"_invert",
":",
"pos",
"=",
"1",
"-",
"pos",
"pos",
"=",
"int",
"(",
"pos",
"*",
"100",
")",
"return",
"pos"
] | [
94,
4
] | [
103,
18
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.async_open_cover | (self, **kwargs) | Open the cover. | Open the cover. | async def async_open_cover(self, **kwargs):
"""Open the cover."""
self._slide["state"] = STATE_OPENING
await self._api.slide_open(self._id) | [
"async",
"def",
"async_open_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"=",
"STATE_OPENING",
"await",
"self",
".",
"_api",
".",
"slide_open",
"(",
"self",
".",
"_id",
")"
] | [
105,
4
] | [
108,
44
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.async_close_cover | (self, **kwargs) | Close the cover. | Close the cover. | async def async_close_cover(self, **kwargs):
"""Close the cover."""
self._slide["state"] = STATE_CLOSING
await self._api.slide_close(self._id) | [
"async",
"def",
"async_close_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"=",
"STATE_CLOSING",
"await",
"self",
".",
"_api",
".",
"slide_close",
"(",
"self",
".",
"_id",
")"
] | [
110,
4
] | [
113,
45
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.async_stop_cover | (self, **kwargs) | Stop the cover. | Stop the cover. | async def async_stop_cover(self, **kwargs):
"""Stop the cover."""
await self._api.slide_stop(self._id) | [
"async",
"def",
"async_stop_cover",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"_api",
".",
"slide_stop",
"(",
"self",
".",
"_id",
")"
] | [
115,
4
] | [
117,
44
] | python | en | ['en', 'en', 'en'] | True |
SlideCover.async_set_cover_position | (self, **kwargs) | Move the cover to a specific position. | Move the cover to a specific position. | async def async_set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
position = kwargs[ATTR_POSITION] / 100
if not self._invert:
position = 1 - position
if self._slide["pos"] is not None:
if position > self._slide["pos"]:
self._slide["state"] = STATE_CLOSING
else:
self._slide["state"] = STATE_OPENING
await self._api.slide_set_position(self._id, position) | [
"async",
"def",
"async_set_cover_position",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"position",
"=",
"kwargs",
"[",
"ATTR_POSITION",
"]",
"/",
"100",
"if",
"not",
"self",
".",
"_invert",
":",
"position",
"=",
"1",
"-",
"position",
"if",
"self",
".",
"_slide",
"[",
"\"pos\"",
"]",
"is",
"not",
"None",
":",
"if",
"position",
">",
"self",
".",
"_slide",
"[",
"\"pos\"",
"]",
":",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"=",
"STATE_CLOSING",
"else",
":",
"self",
".",
"_slide",
"[",
"\"state\"",
"]",
"=",
"STATE_OPENING",
"await",
"self",
".",
"_api",
".",
"slide_set_position",
"(",
"self",
".",
"_id",
",",
"position",
")"
] | [
119,
4
] | [
131,
62
] | python | en | ['en', 'en', 'en'] | True |
test_version_sensor | (hass) | Test the Version sensor. | Test the Version sensor. | async def test_version_sensor(hass):
"""Test the Version sensor."""
config = {"sensor": {"platform": "version"}}
assert await async_setup_component(hass, "sensor", config) | [
"async",
"def",
"test_version_sensor",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"version\"",
"}",
"}",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")"
] | [
8,
0
] | [
12,
62
] | python | en | ['en', 'da', 'en'] | True |
test_version | (hass) | Test the Version sensor. | Test the Version sensor. | async def test_version(hass):
"""Test the Version sensor."""
config = {"sensor": {"platform": "version", "name": "test"}}
with patch("homeassistant.const.__version__", MOCK_VERSION):
assert await async_setup_component(hass, "sensor", config)
await hass.async_block_till_done()
state = hass.states.get("sensor.test")
assert state.state == "10.0" | [
"async",
"def",
"test_version",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"\"sensor\"",
":",
"{",
"\"platform\"",
":",
"\"version\"",
",",
"\"name\"",
":",
"\"test\"",
"}",
"}",
"with",
"patch",
"(",
"\"homeassistant.const.__version__\"",
",",
"MOCK_VERSION",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.test\"",
")",
"assert",
"state",
".",
"state",
"==",
"\"10.0\""
] | [
15,
0
] | [
25,
32
] | python | en | ['en', 'da', 'en'] | True |
config_entry | () | Create a mock GDACS config entry. | Create a mock GDACS config entry. | def config_entry():
"""Create a mock GDACS config entry."""
return MockConfigEntry(
domain=DOMAIN,
data={
CONF_LATITUDE: -41.2,
CONF_LONGITUDE: 174.7,
CONF_RADIUS: 25,
CONF_UNIT_SYSTEM: "metric",
CONF_SCAN_INTERVAL: 300.0,
CONF_CATEGORIES: [],
},
title="-41.2, 174.7",
unique_id="-41.2, 174.7",
) | [
"def",
"config_entry",
"(",
")",
":",
"return",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"CONF_LATITUDE",
":",
"-",
"41.2",
",",
"CONF_LONGITUDE",
":",
"174.7",
",",
"CONF_RADIUS",
":",
"25",
",",
"CONF_UNIT_SYSTEM",
":",
"\"metric\"",
",",
"CONF_SCAN_INTERVAL",
":",
"300.0",
",",
"CONF_CATEGORIES",
":",
"[",
"]",
",",
"}",
",",
"title",
"=",
"\"-41.2, 174.7\"",
",",
"unique_id",
"=",
"\"-41.2, 174.7\"",
",",
")"
] | [
16,
0
] | [
30,
5
] | python | en | ['en', 'gl', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Arlo Alarm Control Panels. | Set up the Arlo Alarm Control Panels. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Arlo Alarm Control Panels."""
arlo = hass.data[DATA_ARLO]
if not arlo.base_stations:
return
home_mode_name = config[CONF_HOME_MODE_NAME]
away_mode_name = config[CONF_AWAY_MODE_NAME]
night_mode_name = config[CONF_NIGHT_MODE_NAME]
base_stations = []
for base_station in arlo.base_stations:
base_stations.append(
ArloBaseStation(
base_station, home_mode_name, away_mode_name, night_mode_name
)
)
add_entities(base_stations, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"arlo",
"=",
"hass",
".",
"data",
"[",
"DATA_ARLO",
"]",
"if",
"not",
"arlo",
".",
"base_stations",
":",
"return",
"home_mode_name",
"=",
"config",
"[",
"CONF_HOME_MODE_NAME",
"]",
"away_mode_name",
"=",
"config",
"[",
"CONF_AWAY_MODE_NAME",
"]",
"night_mode_name",
"=",
"config",
"[",
"CONF_NIGHT_MODE_NAME",
"]",
"base_stations",
"=",
"[",
"]",
"for",
"base_station",
"in",
"arlo",
".",
"base_stations",
":",
"base_stations",
".",
"append",
"(",
"ArloBaseStation",
"(",
"base_station",
",",
"home_mode_name",
",",
"away_mode_name",
",",
"night_mode_name",
")",
")",
"add_entities",
"(",
"base_stations",
",",
"True",
")"
] | [
48,
0
] | [
65,
37
] | python | en | ['en', 'ja', 'en'] | True |
ArloBaseStation.__init__ | (self, data, home_mode_name, away_mode_name, night_mode_name) | Initialize the alarm control panel. | Initialize the alarm control panel. | def __init__(self, data, home_mode_name, away_mode_name, night_mode_name):
"""Initialize the alarm control panel."""
self._base_station = data
self._home_mode_name = home_mode_name
self._away_mode_name = away_mode_name
self._night_mode_name = night_mode_name
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"home_mode_name",
",",
"away_mode_name",
",",
"night_mode_name",
")",
":",
"self",
".",
"_base_station",
"=",
"data",
"self",
".",
"_home_mode_name",
"=",
"home_mode_name",
"self",
".",
"_away_mode_name",
"=",
"away_mode_name",
"self",
".",
"_night_mode_name",
"=",
"night_mode_name",
"self",
".",
"_state",
"=",
"None"
] | [
71,
4
] | [
77,
26
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation.icon | (self) | Return icon. | Return icon. | def icon(self):
"""Return icon."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
80,
4
] | [
82,
19
] | python | en | ['en', 'la', 'en'] | False |
ArloBaseStation.async_added_to_hass | (self) | Register callbacks. | Register callbacks. | async def async_added_to_hass(self):
"""Register callbacks."""
self.async_on_remove(
async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_ARLO, self._update_callback
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_ARLO",
",",
"self",
".",
"_update_callback",
")",
")"
] | [
84,
4
] | [
90,
9
] | python | en | ['en', 'no', 'en'] | False |
ArloBaseStation._update_callback | (self) | Call update method. | Call update method. | def _update_callback(self):
"""Call update method."""
self.async_schedule_update_ha_state(True) | [
"def",
"_update_callback",
"(",
"self",
")",
":",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
93,
4
] | [
95,
49
] | python | en | ['en', 'sn', 'en'] | True |
ArloBaseStation.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
98,
4
] | [
100,
26
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | SUPPORT_ALARM_ARM_NIGHT | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"SUPPORT_ALARM_ARM_HOME",
"|",
"SUPPORT_ALARM_ARM_AWAY",
"|",
"SUPPORT_ALARM_ARM_NIGHT"
] | [
103,
4
] | [
105,
88
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation.update | (self) | Update the state of the device. | Update the state of the device. | def update(self):
"""Update the state of the device."""
_LOGGER.debug("Updating Arlo Alarm Control Panel %s", self.name)
mode = self._base_station.mode
if mode:
self._state = self._get_state_from_mode(mode)
else:
self._state = None | [
"def",
"update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Updating Arlo Alarm Control Panel %s\"",
",",
"self",
".",
"name",
")",
"mode",
"=",
"self",
".",
"_base_station",
".",
"mode",
"if",
"mode",
":",
"self",
".",
"_state",
"=",
"self",
".",
"_get_state_from_mode",
"(",
"mode",
")",
"else",
":",
"self",
".",
"_state",
"=",
"None"
] | [
107,
4
] | [
114,
30
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation.alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | def alarm_disarm(self, code=None):
"""Send disarm command."""
self._base_station.mode = DISARMED | [
"def",
"alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"_base_station",
".",
"mode",
"=",
"DISARMED"
] | [
116,
4
] | [
118,
42
] | python | en | ['en', 'pt', 'en'] | True |
ArloBaseStation.alarm_arm_away | (self, code=None) | Send arm away command. Uses custom mode. | Send arm away command. Uses custom mode. | def alarm_arm_away(self, code=None):
"""Send arm away command. Uses custom mode."""
self._base_station.mode = self._away_mode_name | [
"def",
"alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"_base_station",
".",
"mode",
"=",
"self",
".",
"_away_mode_name"
] | [
120,
4
] | [
122,
54
] | python | en | ['en', 'pt', 'en'] | True |
ArloBaseStation.alarm_arm_home | (self, code=None) | Send arm home command. Uses custom mode. | Send arm home command. Uses custom mode. | def alarm_arm_home(self, code=None):
"""Send arm home command. Uses custom mode."""
self._base_station.mode = self._home_mode_name | [
"def",
"alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"_base_station",
".",
"mode",
"=",
"self",
".",
"_home_mode_name"
] | [
124,
4
] | [
126,
54
] | python | en | ['en', 'pt', 'en'] | True |
ArloBaseStation.alarm_arm_night | (self, code=None) | Send arm night command. Uses custom mode. | Send arm night command. Uses custom mode. | def alarm_arm_night(self, code=None):
"""Send arm night command. Uses custom mode."""
self._base_station.mode = self._night_mode_name | [
"def",
"alarm_arm_night",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"self",
".",
"_base_station",
".",
"mode",
"=",
"self",
".",
"_night_mode_name"
] | [
128,
4
] | [
130,
55
] | python | en | ['en', 'pt', 'en'] | True |
ArloBaseStation.name | (self) | Return the name of the base station. | Return the name of the base station. | def name(self):
"""Return the name of the base station."""
return self._base_station.name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_base_station",
".",
"name"
] | [
133,
4
] | [
135,
38
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
"device_id": self._base_station.device_id,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
",",
"\"device_id\"",
":",
"self",
".",
"_base_station",
".",
"device_id",
",",
"}"
] | [
138,
4
] | [
143,
9
] | python | en | ['en', 'en', 'en'] | True |
ArloBaseStation._get_state_from_mode | (self, mode) | Convert Arlo mode to Home Assistant state. | Convert Arlo mode to Home Assistant state. | def _get_state_from_mode(self, mode):
"""Convert Arlo mode to Home Assistant state."""
if mode == ARMED:
return STATE_ALARM_ARMED_AWAY
if mode == DISARMED:
return STATE_ALARM_DISARMED
if mode == self._home_mode_name:
return STATE_ALARM_ARMED_HOME
if mode == self._away_mode_name:
return STATE_ALARM_ARMED_AWAY
if mode == self._night_mode_name:
return STATE_ALARM_ARMED_NIGHT
return mode | [
"def",
"_get_state_from_mode",
"(",
"self",
",",
"mode",
")",
":",
"if",
"mode",
"==",
"ARMED",
":",
"return",
"STATE_ALARM_ARMED_AWAY",
"if",
"mode",
"==",
"DISARMED",
":",
"return",
"STATE_ALARM_DISARMED",
"if",
"mode",
"==",
"self",
".",
"_home_mode_name",
":",
"return",
"STATE_ALARM_ARMED_HOME",
"if",
"mode",
"==",
"self",
".",
"_away_mode_name",
":",
"return",
"STATE_ALARM_ARMED_AWAY",
"if",
"mode",
"==",
"self",
".",
"_night_mode_name",
":",
"return",
"STATE_ALARM_ARMED_NIGHT",
"return",
"mode"
] | [
145,
4
] | [
157,
19
] | python | en | ['en', 'en', 'en'] | True |
detect_radios | (dev_path: str) | Probe all radio types on the device port. | Probe all radio types on the device port. | async def detect_radios(dev_path: str) -> Optional[Dict[str, Any]]:
"""Probe all radio types on the device port."""
for radio in RadioType:
dev_config = radio.controller.SCHEMA_DEVICE({CONF_DEVICE_PATH: dev_path})
if await radio.controller.probe(dev_config):
return {CONF_RADIO_TYPE: radio.name, CONF_DEVICE: dev_config}
return None | [
"async",
"def",
"detect_radios",
"(",
"dev_path",
":",
"str",
")",
"->",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
":",
"for",
"radio",
"in",
"RadioType",
":",
"dev_config",
"=",
"radio",
".",
"controller",
".",
"SCHEMA_DEVICE",
"(",
"{",
"CONF_DEVICE_PATH",
":",
"dev_path",
"}",
")",
"if",
"await",
"radio",
".",
"controller",
".",
"probe",
"(",
"dev_config",
")",
":",
"return",
"{",
"CONF_RADIO_TYPE",
":",
"radio",
".",
"name",
",",
"CONF_DEVICE",
":",
"dev_config",
"}",
"return",
"None"
] | [
125,
0
] | [
132,
15
] | python | en | ['en', 'en', 'en'] | True |
get_serial_by_id | (dev_path: str) | Return a /dev/serial/by-id match for given device if available. | Return a /dev/serial/by-id match for given device if available. | def get_serial_by_id(dev_path: str) -> str:
"""Return a /dev/serial/by-id match for given device if available."""
by_id = "/dev/serial/by-id"
if not os.path.isdir(by_id):
return dev_path
for path in (entry.path for entry in os.scandir(by_id) if entry.is_symlink()):
if os.path.realpath(path) == dev_path:
return path
return dev_path | [
"def",
"get_serial_by_id",
"(",
"dev_path",
":",
"str",
")",
"->",
"str",
":",
"by_id",
"=",
"\"/dev/serial/by-id\"",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"by_id",
")",
":",
"return",
"dev_path",
"for",
"path",
"in",
"(",
"entry",
".",
"path",
"for",
"entry",
"in",
"os",
".",
"scandir",
"(",
"by_id",
")",
"if",
"entry",
".",
"is_symlink",
"(",
")",
")",
":",
"if",
"os",
".",
"path",
".",
"realpath",
"(",
"path",
")",
"==",
"dev_path",
":",
"return",
"path",
"return",
"dev_path"
] | [
135,
0
] | [
144,
19
] | python | en | ['en', 'en', 'en'] | True |
ZhaFlowHandler.__init__ | (self) | Initialize flow instance. | Initialize flow instance. | def __init__(self):
"""Initialize flow instance."""
self._device_path = None
self._radio_type = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"_device_path",
"=",
"None",
"self",
".",
"_radio_type",
"=",
"None"
] | [
31,
4
] | [
34,
31
] | python | en | ['en', 'pl', 'en'] | True |
ZhaFlowHandler.async_step_user | (self, user_input=None) | Handle a zha config flow start. | Handle a zha config flow start. | async def async_step_user(self, user_input=None):
"""Handle a zha config flow start."""
if self._async_current_entries():
return self.async_abort(reason="single_instance_allowed")
ports = await self.hass.async_add_executor_job(serial.tools.list_ports.comports)
list_of_ports = [
f"{p}, s/n: {p.serial_number or 'n/a'}"
+ (f" - {p.manufacturer}" if p.manufacturer else "")
for p in ports
]
list_of_ports.append(CONF_MANUAL_PATH)
if user_input is not None:
user_selection = user_input[CONF_DEVICE_PATH]
if user_selection == CONF_MANUAL_PATH:
return await self.async_step_pick_radio()
port = ports[list_of_ports.index(user_selection)]
dev_path = await self.hass.async_add_executor_job(
get_serial_by_id, port.device
)
auto_detected_data = await detect_radios(dev_path)
if auto_detected_data is not None:
title = f"{port.description}, s/n: {port.serial_number or 'n/a'}"
title += f" - {port.manufacturer}" if port.manufacturer else ""
return self.async_create_entry(
title=title,
data=auto_detected_data,
)
# did not detect anything
self._device_path = dev_path
return await self.async_step_pick_radio()
schema = vol.Schema({vol.Required(CONF_DEVICE_PATH): vol.In(list_of_ports)})
return self.async_show_form(step_id="user", data_schema=schema) | [
"async",
"def",
"async_step_user",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"self",
".",
"_async_current_entries",
"(",
")",
":",
"return",
"self",
".",
"async_abort",
"(",
"reason",
"=",
"\"single_instance_allowed\"",
")",
"ports",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"serial",
".",
"tools",
".",
"list_ports",
".",
"comports",
")",
"list_of_ports",
"=",
"[",
"f\"{p}, s/n: {p.serial_number or 'n/a'}\"",
"+",
"(",
"f\" - {p.manufacturer}\"",
"if",
"p",
".",
"manufacturer",
"else",
"\"\"",
")",
"for",
"p",
"in",
"ports",
"]",
"list_of_ports",
".",
"append",
"(",
"CONF_MANUAL_PATH",
")",
"if",
"user_input",
"is",
"not",
"None",
":",
"user_selection",
"=",
"user_input",
"[",
"CONF_DEVICE_PATH",
"]",
"if",
"user_selection",
"==",
"CONF_MANUAL_PATH",
":",
"return",
"await",
"self",
".",
"async_step_pick_radio",
"(",
")",
"port",
"=",
"ports",
"[",
"list_of_ports",
".",
"index",
"(",
"user_selection",
")",
"]",
"dev_path",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"get_serial_by_id",
",",
"port",
".",
"device",
")",
"auto_detected_data",
"=",
"await",
"detect_radios",
"(",
"dev_path",
")",
"if",
"auto_detected_data",
"is",
"not",
"None",
":",
"title",
"=",
"f\"{port.description}, s/n: {port.serial_number or 'n/a'}\"",
"title",
"+=",
"f\" - {port.manufacturer}\"",
"if",
"port",
".",
"manufacturer",
"else",
"\"\"",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"title",
",",
"data",
"=",
"auto_detected_data",
",",
")",
"# did not detect anything",
"self",
".",
"_device_path",
"=",
"dev_path",
"return",
"await",
"self",
".",
"async_step_pick_radio",
"(",
")",
"schema",
"=",
"vol",
".",
"Schema",
"(",
"{",
"vol",
".",
"Required",
"(",
"CONF_DEVICE_PATH",
")",
":",
"vol",
".",
"In",
"(",
"list_of_ports",
")",
"}",
")",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"user\"",
",",
"data_schema",
"=",
"schema",
")"
] | [
36,
4
] | [
72,
71
] | python | br | ['br', 'lb', 'it'] | False |
ZhaFlowHandler.async_step_pick_radio | (self, user_input=None) | Select radio type. | Select radio type. | async def async_step_pick_radio(self, user_input=None):
"""Select radio type."""
if user_input is not None:
self._radio_type = RadioType.get_by_description(user_input[CONF_RADIO_TYPE])
return await self.async_step_port_config()
schema = {vol.Required(CONF_RADIO_TYPE): vol.In(sorted(RadioType.list()))}
return self.async_show_form(
step_id="pick_radio",
data_schema=vol.Schema(schema),
) | [
"async",
"def",
"async_step_pick_radio",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"_radio_type",
"=",
"RadioType",
".",
"get_by_description",
"(",
"user_input",
"[",
"CONF_RADIO_TYPE",
"]",
")",
"return",
"await",
"self",
".",
"async_step_port_config",
"(",
")",
"schema",
"=",
"{",
"vol",
".",
"Required",
"(",
"CONF_RADIO_TYPE",
")",
":",
"vol",
".",
"In",
"(",
"sorted",
"(",
"RadioType",
".",
"list",
"(",
")",
")",
")",
"}",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"pick_radio\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"schema",
")",
",",
")"
] | [
74,
4
] | [
85,
9
] | python | en | ['es', 'sr', 'en'] | False |
ZhaFlowHandler.async_step_port_config | (self, user_input=None) | Enter port settings specific for this type of radio. | Enter port settings specific for this type of radio. | async def async_step_port_config(self, user_input=None):
"""Enter port settings specific for this type of radio."""
errors = {}
app_cls = RadioType[self._radio_type].controller
if user_input is not None:
self._device_path = user_input.get(CONF_DEVICE_PATH)
if await app_cls.probe(user_input):
serial_by_id = await self.hass.async_add_executor_job(
get_serial_by_id, user_input[CONF_DEVICE_PATH]
)
user_input[CONF_DEVICE_PATH] = serial_by_id
return self.async_create_entry(
title=user_input[CONF_DEVICE_PATH],
data={CONF_DEVICE: user_input, CONF_RADIO_TYPE: self._radio_type},
)
errors["base"] = "cannot_connect"
schema = {
vol.Required(
CONF_DEVICE_PATH, default=self._device_path or vol.UNDEFINED
): str
}
radio_schema = app_cls.SCHEMA_DEVICE.schema
if isinstance(radio_schema, vol.Schema):
radio_schema = radio_schema.schema
for param, value in radio_schema.items():
if param in SUPPORTED_PORT_SETTINGS:
schema[param] = value
return self.async_show_form(
step_id="port_config",
data_schema=vol.Schema(schema),
errors=errors,
) | [
"async",
"def",
"async_step_port_config",
"(",
"self",
",",
"user_input",
"=",
"None",
")",
":",
"errors",
"=",
"{",
"}",
"app_cls",
"=",
"RadioType",
"[",
"self",
".",
"_radio_type",
"]",
".",
"controller",
"if",
"user_input",
"is",
"not",
"None",
":",
"self",
".",
"_device_path",
"=",
"user_input",
".",
"get",
"(",
"CONF_DEVICE_PATH",
")",
"if",
"await",
"app_cls",
".",
"probe",
"(",
"user_input",
")",
":",
"serial_by_id",
"=",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"get_serial_by_id",
",",
"user_input",
"[",
"CONF_DEVICE_PATH",
"]",
")",
"user_input",
"[",
"CONF_DEVICE_PATH",
"]",
"=",
"serial_by_id",
"return",
"self",
".",
"async_create_entry",
"(",
"title",
"=",
"user_input",
"[",
"CONF_DEVICE_PATH",
"]",
",",
"data",
"=",
"{",
"CONF_DEVICE",
":",
"user_input",
",",
"CONF_RADIO_TYPE",
":",
"self",
".",
"_radio_type",
"}",
",",
")",
"errors",
"[",
"\"base\"",
"]",
"=",
"\"cannot_connect\"",
"schema",
"=",
"{",
"vol",
".",
"Required",
"(",
"CONF_DEVICE_PATH",
",",
"default",
"=",
"self",
".",
"_device_path",
"or",
"vol",
".",
"UNDEFINED",
")",
":",
"str",
"}",
"radio_schema",
"=",
"app_cls",
".",
"SCHEMA_DEVICE",
".",
"schema",
"if",
"isinstance",
"(",
"radio_schema",
",",
"vol",
".",
"Schema",
")",
":",
"radio_schema",
"=",
"radio_schema",
".",
"schema",
"for",
"param",
",",
"value",
"in",
"radio_schema",
".",
"items",
"(",
")",
":",
"if",
"param",
"in",
"SUPPORTED_PORT_SETTINGS",
":",
"schema",
"[",
"param",
"]",
"=",
"value",
"return",
"self",
".",
"async_show_form",
"(",
"step_id",
"=",
"\"port_config\"",
",",
"data_schema",
"=",
"vol",
".",
"Schema",
"(",
"schema",
")",
",",
"errors",
"=",
"errors",
",",
")"
] | [
87,
4
] | [
122,
9
] | python | en | ['en', 'en', 'en'] | True |
async_describe_on_off_states | (
hass: HomeAssistantType, registry: GroupIntegrationRegistry
) | Describe group on off states. | Describe group on off states. | def async_describe_on_off_states(
hass: HomeAssistantType, registry: GroupIntegrationRegistry
) -> None:
"""Describe group on off states."""
registry.exclude_domain() | [
"def",
"async_describe_on_off_states",
"(",
"hass",
":",
"HomeAssistantType",
",",
"registry",
":",
"GroupIntegrationRegistry",
")",
"->",
"None",
":",
"registry",
".",
"exclude_domain",
"(",
")"
] | [
9,
0
] | [
13,
29
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistant, config: dict) | Set up the OpenWeatherMap component. | Set up the OpenWeatherMap component. | async def async_setup(hass: HomeAssistant, config: dict) -> bool:
"""Set up the OpenWeatherMap component."""
hass.data.setdefault(DOMAIN, {})
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistant",
",",
"config",
":",
"dict",
")",
"->",
"bool",
":",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"return",
"True"
] | [
34,
0
] | [
37,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistant, config_entry: ConfigEntry) | Set up OpenWeatherMap as config entry. | Set up OpenWeatherMap as config entry. | async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Set up OpenWeatherMap as config entry."""
name = config_entry.data[CONF_NAME]
api_key = config_entry.data[CONF_API_KEY]
latitude = config_entry.data.get(CONF_LATITUDE, hass.config.latitude)
longitude = config_entry.data.get(CONF_LONGITUDE, hass.config.longitude)
forecast_mode = _get_config_value(config_entry, CONF_MODE)
language = _get_config_value(config_entry, CONF_LANGUAGE)
config_dict = _get_owm_config(language)
owm = OWM(api_key, config_dict).weather_manager()
weather_coordinator = WeatherUpdateCoordinator(
owm, latitude, longitude, forecast_mode, hass
)
await weather_coordinator.async_refresh()
if not weather_coordinator.last_update_success:
raise ConfigEntryNotReady
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][config_entry.entry_id] = {
ENTRY_NAME: name,
ENTRY_WEATHER_COORDINATOR: weather_coordinator,
}
for component in COMPONENTS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, component)
)
update_listener = config_entry.add_update_listener(async_update_options)
hass.data[DOMAIN][config_entry.entry_id][UPDATE_LISTENER] = update_listener
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
")",
":",
"name",
"=",
"config_entry",
".",
"data",
"[",
"CONF_NAME",
"]",
"api_key",
"=",
"config_entry",
".",
"data",
"[",
"CONF_API_KEY",
"]",
"latitude",
"=",
"config_entry",
".",
"data",
".",
"get",
"(",
"CONF_LATITUDE",
",",
"hass",
".",
"config",
".",
"latitude",
")",
"longitude",
"=",
"config_entry",
".",
"data",
".",
"get",
"(",
"CONF_LONGITUDE",
",",
"hass",
".",
"config",
".",
"longitude",
")",
"forecast_mode",
"=",
"_get_config_value",
"(",
"config_entry",
",",
"CONF_MODE",
")",
"language",
"=",
"_get_config_value",
"(",
"config_entry",
",",
"CONF_LANGUAGE",
")",
"config_dict",
"=",
"_get_owm_config",
"(",
"language",
")",
"owm",
"=",
"OWM",
"(",
"api_key",
",",
"config_dict",
")",
".",
"weather_manager",
"(",
")",
"weather_coordinator",
"=",
"WeatherUpdateCoordinator",
"(",
"owm",
",",
"latitude",
",",
"longitude",
",",
"forecast_mode",
",",
"hass",
")",
"await",
"weather_coordinator",
".",
"async_refresh",
"(",
")",
"if",
"not",
"weather_coordinator",
".",
"last_update_success",
":",
"raise",
"ConfigEntryNotReady",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"=",
"{",
"ENTRY_NAME",
":",
"name",
",",
"ENTRY_WEATHER_COORDINATOR",
":",
"weather_coordinator",
",",
"}",
"for",
"component",
"in",
"COMPONENTS",
":",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"config_entry",
",",
"component",
")",
")",
"update_listener",
"=",
"config_entry",
".",
"add_update_listener",
"(",
"async_update_options",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"[",
"UPDATE_LISTENER",
"]",
"=",
"update_listener",
"return",
"True"
] | [
40,
0
] | [
75,
15
] | python | en | ['en', 'en', 'en'] | True |
async_migrate_entry | (hass, entry) | Migrate old entry. | Migrate old entry. | async def async_migrate_entry(hass, entry):
"""Migrate old entry."""
config_entries = hass.config_entries
data = entry.data
version = entry.version
_LOGGER.debug("Migrating OpenWeatherMap entry from version %s", version)
if version == 1:
mode = data[CONF_MODE]
if mode == FORECAST_MODE_FREE_DAILY:
mode = FORECAST_MODE_ONECALL_DAILY
new_data = {**data, CONF_MODE: mode}
version = entry.version = CONFIG_FLOW_VERSION
config_entries.async_update_entry(entry, data=new_data)
_LOGGER.info("Migration to version %s successful", version)
return True | [
"async",
"def",
"async_migrate_entry",
"(",
"hass",
",",
"entry",
")",
":",
"config_entries",
"=",
"hass",
".",
"config_entries",
"data",
"=",
"entry",
".",
"data",
"version",
"=",
"entry",
".",
"version",
"_LOGGER",
".",
"debug",
"(",
"\"Migrating OpenWeatherMap entry from version %s\"",
",",
"version",
")",
"if",
"version",
"==",
"1",
":",
"mode",
"=",
"data",
"[",
"CONF_MODE",
"]",
"if",
"mode",
"==",
"FORECAST_MODE_FREE_DAILY",
":",
"mode",
"=",
"FORECAST_MODE_ONECALL_DAILY",
"new_data",
"=",
"{",
"*",
"*",
"data",
",",
"CONF_MODE",
":",
"mode",
"}",
"version",
"=",
"entry",
".",
"version",
"=",
"CONFIG_FLOW_VERSION",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"new_data",
")",
"_LOGGER",
".",
"info",
"(",
"\"Migration to version %s successful\"",
",",
"version",
")",
"return",
"True"
] | [
78,
0
] | [
97,
15
] | python | en | ['en', 'en', 'en'] | True |
async_update_options | (hass: HomeAssistant, config_entry: ConfigEntry) | Update options. | Update options. | async def async_update_options(hass: HomeAssistant, config_entry: ConfigEntry):
"""Update options."""
await hass.config_entries.async_reload(config_entry.entry_id) | [
"async",
"def",
"async_update_options",
"(",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_reload",
"(",
"config_entry",
".",
"entry_id",
")"
] | [
100,
0
] | [
102,
65
] | python | en | ['en', 'en', 'en'] | False |
async_unload_entry | (hass: HomeAssistant, config_entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry):
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[
hass.config_entries.async_forward_entry_unload(config_entry, component)
for component in COMPONENTS
]
)
)
if unload_ok:
update_listener = hass.data[DOMAIN][config_entry.entry_id][UPDATE_LISTENER]
update_listener()
hass.data[DOMAIN].pop(config_entry.entry_id)
return unload_ok | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"config_entry",
":",
"ConfigEntry",
")",
":",
"unload_ok",
"=",
"all",
"(",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"[",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"config_entry",
",",
"component",
")",
"for",
"component",
"in",
"COMPONENTS",
"]",
")",
")",
"if",
"unload_ok",
":",
"update_listener",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"[",
"UPDATE_LISTENER",
"]",
"update_listener",
"(",
")",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"config_entry",
".",
"entry_id",
")",
"return",
"unload_ok"
] | [
105,
0
] | [
120,
20
] | python | en | ['en', 'es', 'en'] | True |
_get_owm_config | (language) | Get OpenWeatherMap configuration and add language to it. | Get OpenWeatherMap configuration and add language to it. | def _get_owm_config(language):
"""Get OpenWeatherMap configuration and add language to it."""
config_dict = get_default_config()
config_dict["language"] = language
return config_dict | [
"def",
"_get_owm_config",
"(",
"language",
")",
":",
"config_dict",
"=",
"get_default_config",
"(",
")",
"config_dict",
"[",
"\"language\"",
"]",
"=",
"language",
"return",
"config_dict"
] | [
133,
0
] | [
137,
22
] | python | en | ['en', 'en', 'en'] | True |
process_timestamp | (ts) | Process a timestamp into datetime object. | Process a timestamp into datetime object. | def process_timestamp(ts):
"""Process a timestamp into datetime object."""
if ts is None:
return None
if ts.tzinfo is None:
return ts.replace(tzinfo=dt_util.UTC)
return dt_util.as_utc(ts) | [
"def",
"process_timestamp",
"(",
"ts",
")",
":",
"if",
"ts",
"is",
"None",
":",
"return",
"None",
"if",
"ts",
".",
"tzinfo",
"is",
"None",
":",
"return",
"ts",
".",
"replace",
"(",
"tzinfo",
"=",
"dt_util",
".",
"UTC",
")",
"return",
"dt_util",
".",
"as_utc",
"(",
"ts",
")"
] | [
209,
0
] | [
216,
29
] | python | cs | ['pt', 'cs', 'en'] | False |
process_timestamp_to_utc_isoformat | (ts) | Process a timestamp into UTC isotime. | Process a timestamp into UTC isotime. | def process_timestamp_to_utc_isoformat(ts):
"""Process a timestamp into UTC isotime."""
if ts is None:
return None
if ts.tzinfo == dt_util.UTC:
return ts.isoformat()
if ts.tzinfo is None:
return f"{ts.isoformat()}{DB_TIMEZONE}"
return ts.astimezone(dt_util.UTC).isoformat() | [
"def",
"process_timestamp_to_utc_isoformat",
"(",
"ts",
")",
":",
"if",
"ts",
"is",
"None",
":",
"return",
"None",
"if",
"ts",
".",
"tzinfo",
"==",
"dt_util",
".",
"UTC",
":",
"return",
"ts",
".",
"isoformat",
"(",
")",
"if",
"ts",
".",
"tzinfo",
"is",
"None",
":",
"return",
"f\"{ts.isoformat()}{DB_TIMEZONE}\"",
"return",
"ts",
".",
"astimezone",
"(",
"dt_util",
".",
"UTC",
")",
".",
"isoformat",
"(",
")"
] | [
219,
0
] | [
227,
49
] | python | en | ['en', 'mk', 'en'] | True |
Events.from_event | (event, event_data=None) | Create an event database object from a native event. | Create an event database object from a native event. | def from_event(event, event_data=None):
"""Create an event database object from a native event."""
return Events(
event_type=event.event_type,
event_data=event_data or json.dumps(event.data, cls=JSONEncoder),
origin=str(event.origin.value),
time_fired=event.time_fired,
context_id=event.context.id,
context_user_id=event.context.user_id,
context_parent_id=event.context.parent_id,
) | [
"def",
"from_event",
"(",
"event",
",",
"event_data",
"=",
"None",
")",
":",
"return",
"Events",
"(",
"event_type",
"=",
"event",
".",
"event_type",
",",
"event_data",
"=",
"event_data",
"or",
"json",
".",
"dumps",
"(",
"event",
".",
"data",
",",
"cls",
"=",
"JSONEncoder",
")",
",",
"origin",
"=",
"str",
"(",
"event",
".",
"origin",
".",
"value",
")",
",",
"time_fired",
"=",
"event",
".",
"time_fired",
",",
"context_id",
"=",
"event",
".",
"context",
".",
"id",
",",
"context_user_id",
"=",
"event",
".",
"context",
".",
"user_id",
",",
"context_parent_id",
"=",
"event",
".",
"context",
".",
"parent_id",
",",
")"
] | [
62,
4
] | [
72,
9
] | python | en | ['en', 'en', 'en'] | True |
Events.to_native | (self, validate_entity_id=True) | Convert to a natve HA Event. | Convert to a natve HA Event. | def to_native(self, validate_entity_id=True):
"""Convert to a natve HA Event."""
context = Context(
id=self.context_id,
user_id=self.context_user_id,
parent_id=self.context_parent_id,
)
try:
return Event(
self.event_type,
json.loads(self.event_data),
EventOrigin(self.origin),
process_timestamp(self.time_fired),
context=context,
)
except ValueError:
# When json.loads fails
_LOGGER.exception("Error converting to event: %s", self)
return None | [
"def",
"to_native",
"(",
"self",
",",
"validate_entity_id",
"=",
"True",
")",
":",
"context",
"=",
"Context",
"(",
"id",
"=",
"self",
".",
"context_id",
",",
"user_id",
"=",
"self",
".",
"context_user_id",
",",
"parent_id",
"=",
"self",
".",
"context_parent_id",
",",
")",
"try",
":",
"return",
"Event",
"(",
"self",
".",
"event_type",
",",
"json",
".",
"loads",
"(",
"self",
".",
"event_data",
")",
",",
"EventOrigin",
"(",
"self",
".",
"origin",
")",
",",
"process_timestamp",
"(",
"self",
".",
"time_fired",
")",
",",
"context",
"=",
"context",
",",
")",
"except",
"ValueError",
":",
"# When json.loads fails",
"_LOGGER",
".",
"exception",
"(",
"\"Error converting to event: %s\"",
",",
"self",
")",
"return",
"None"
] | [
74,
4
] | [
92,
23
] | python | ca | ['en', 'ca', 'pt'] | False |
States.from_event | (event) | Create object from a state_changed event. | Create object from a state_changed event. | def from_event(event):
"""Create object from a state_changed event."""
entity_id = event.data["entity_id"]
state = event.data.get("new_state")
dbstate = States(entity_id=entity_id)
# State got deleted
if state is None:
dbstate.state = ""
dbstate.domain = split_entity_id(entity_id)[0]
dbstate.attributes = "{}"
dbstate.last_changed = event.time_fired
dbstate.last_updated = event.time_fired
else:
dbstate.domain = state.domain
dbstate.state = state.state
dbstate.attributes = json.dumps(dict(state.attributes), cls=JSONEncoder)
dbstate.last_changed = state.last_changed
dbstate.last_updated = state.last_updated
return dbstate | [
"def",
"from_event",
"(",
"event",
")",
":",
"entity_id",
"=",
"event",
".",
"data",
"[",
"\"entity_id\"",
"]",
"state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",
")",
"dbstate",
"=",
"States",
"(",
"entity_id",
"=",
"entity_id",
")",
"# State got deleted",
"if",
"state",
"is",
"None",
":",
"dbstate",
".",
"state",
"=",
"\"\"",
"dbstate",
".",
"domain",
"=",
"split_entity_id",
"(",
"entity_id",
")",
"[",
"0",
"]",
"dbstate",
".",
"attributes",
"=",
"\"{}\"",
"dbstate",
".",
"last_changed",
"=",
"event",
".",
"time_fired",
"dbstate",
".",
"last_updated",
"=",
"event",
".",
"time_fired",
"else",
":",
"dbstate",
".",
"domain",
"=",
"state",
".",
"domain",
"dbstate",
".",
"state",
"=",
"state",
".",
"state",
"dbstate",
".",
"attributes",
"=",
"json",
".",
"dumps",
"(",
"dict",
"(",
"state",
".",
"attributes",
")",
",",
"cls",
"=",
"JSONEncoder",
")",
"dbstate",
".",
"last_changed",
"=",
"state",
".",
"last_changed",
"dbstate",
".",
"last_updated",
"=",
"state",
".",
"last_updated",
"return",
"dbstate"
] | [
119,
4
] | [
140,
22
] | python | en | ['en', 'en', 'en'] | True |
States.to_native | (self, validate_entity_id=True) | Convert to an HA state object. | Convert to an HA state object. | def to_native(self, validate_entity_id=True):
"""Convert to an HA state object."""
try:
return State(
self.entity_id,
self.state,
json.loads(self.attributes),
process_timestamp(self.last_changed),
process_timestamp(self.last_updated),
# Join the events table on event_id to get the context instead
# as it will always be there for state_changed events
context=Context(id=None),
validate_entity_id=validate_entity_id,
)
except ValueError:
# When json.loads fails
_LOGGER.exception("Error converting row to state: %s", self)
return None | [
"def",
"to_native",
"(",
"self",
",",
"validate_entity_id",
"=",
"True",
")",
":",
"try",
":",
"return",
"State",
"(",
"self",
".",
"entity_id",
",",
"self",
".",
"state",
",",
"json",
".",
"loads",
"(",
"self",
".",
"attributes",
")",
",",
"process_timestamp",
"(",
"self",
".",
"last_changed",
")",
",",
"process_timestamp",
"(",
"self",
".",
"last_updated",
")",
",",
"# Join the events table on event_id to get the context instead",
"# as it will always be there for state_changed events",
"context",
"=",
"Context",
"(",
"id",
"=",
"None",
")",
",",
"validate_entity_id",
"=",
"validate_entity_id",
",",
")",
"except",
"ValueError",
":",
"# When json.loads fails",
"_LOGGER",
".",
"exception",
"(",
"\"Error converting row to state: %s\"",
",",
"self",
")",
"return",
"None"
] | [
142,
4
] | [
159,
23
] | python | en | ['en', 'en', 'en'] | True |
RecorderRuns.entity_ids | (self, point_in_time=None) | Return the entity ids that existed in this run.
Specify point_in_time if you want to know which existed at that point
in time inside the run.
| Return the entity ids that existed in this run. | def entity_ids(self, point_in_time=None):
"""Return the entity ids that existed in this run.
Specify point_in_time if you want to know which existed at that point
in time inside the run.
"""
session = Session.object_session(self)
assert session is not None, "RecorderRuns need to be persisted"
query = session.query(distinct(States.entity_id)).filter(
States.last_updated >= self.start
)
if point_in_time is not None:
query = query.filter(States.last_updated < point_in_time)
elif self.end is not None:
query = query.filter(States.last_updated < self.end)
return [row[0] for row in query] | [
"def",
"entity_ids",
"(",
"self",
",",
"point_in_time",
"=",
"None",
")",
":",
"session",
"=",
"Session",
".",
"object_session",
"(",
"self",
")",
"assert",
"session",
"is",
"not",
"None",
",",
"\"RecorderRuns need to be persisted\"",
"query",
"=",
"session",
".",
"query",
"(",
"distinct",
"(",
"States",
".",
"entity_id",
")",
")",
".",
"filter",
"(",
"States",
".",
"last_updated",
">=",
"self",
".",
"start",
")",
"if",
"point_in_time",
"is",
"not",
"None",
":",
"query",
"=",
"query",
".",
"filter",
"(",
"States",
".",
"last_updated",
"<",
"point_in_time",
")",
"elif",
"self",
".",
"end",
"is",
"not",
"None",
":",
"query",
"=",
"query",
".",
"filter",
"(",
"States",
".",
"last_updated",
"<",
"self",
".",
"end",
")",
"return",
"[",
"row",
"[",
"0",
"]",
"for",
"row",
"in",
"query",
"]"
] | [
174,
4
] | [
193,
40
] | python | en | ['en', 'en', 'en'] | True |
RecorderRuns.to_native | (self, validate_entity_id=True) | Return self, native format is this model. | Return self, native format is this model. | def to_native(self, validate_entity_id=True):
"""Return self, native format is this model."""
return self | [
"def",
"to_native",
"(",
"self",
",",
"validate_entity_id",
"=",
"True",
")",
":",
"return",
"self"
] | [
195,
4
] | [
197,
19
] | python | en | ['en', 'en', 'en'] | True |
get_gateway_from_config_entry | (hass, config_entry) | Return gateway with a matching bridge id. | Return gateway with a matching bridge id. | def get_gateway_from_config_entry(hass, config_entry):
"""Return gateway with a matching bridge id."""
return hass.data[DOMAIN][config_entry.unique_id] | [
"def",
"get_gateway_from_config_entry",
"(",
"hass",
",",
"config_entry",
")",
":",
"return",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"unique_id",
"]"
] | [
34,
0
] | [
36,
52
] | python | en | ['en', 'cy', 'en'] | True |
get_gateway | (
hass, config, async_add_device_callback, async_connection_status_callback
) | Create a gateway object and verify configuration. | Create a gateway object and verify configuration. | async def get_gateway(
hass, config, async_add_device_callback, async_connection_status_callback
) -> DeconzSession:
"""Create a gateway object and verify configuration."""
session = aiohttp_client.async_get_clientsession(hass)
deconz = DeconzSession(
session,
config[CONF_HOST],
config[CONF_PORT],
config[CONF_API_KEY],
async_add_device=async_add_device_callback,
connection_status=async_connection_status_callback,
)
try:
with async_timeout.timeout(10):
await deconz.initialize()
return deconz
except errors.Unauthorized as err:
LOGGER.warning("Invalid key for deCONZ at %s", config[CONF_HOST])
raise AuthenticationRequired from err
except (asyncio.TimeoutError, errors.RequestError) as err:
LOGGER.error("Error connecting to deCONZ gateway at %s", config[CONF_HOST])
raise CannotConnect from err | [
"async",
"def",
"get_gateway",
"(",
"hass",
",",
"config",
",",
"async_add_device_callback",
",",
"async_connection_status_callback",
")",
"->",
"DeconzSession",
":",
"session",
"=",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
"hass",
")",
"deconz",
"=",
"DeconzSession",
"(",
"session",
",",
"config",
"[",
"CONF_HOST",
"]",
",",
"config",
"[",
"CONF_PORT",
"]",
",",
"config",
"[",
"CONF_API_KEY",
"]",
",",
"async_add_device",
"=",
"async_add_device_callback",
",",
"connection_status",
"=",
"async_connection_status_callback",
",",
")",
"try",
":",
"with",
"async_timeout",
".",
"timeout",
"(",
"10",
")",
":",
"await",
"deconz",
".",
"initialize",
"(",
")",
"return",
"deconz",
"except",
"errors",
".",
"Unauthorized",
"as",
"err",
":",
"LOGGER",
".",
"warning",
"(",
"\"Invalid key for deCONZ at %s\"",
",",
"config",
"[",
"CONF_HOST",
"]",
")",
"raise",
"AuthenticationRequired",
"from",
"err",
"except",
"(",
"asyncio",
".",
"TimeoutError",
",",
"errors",
".",
"RequestError",
")",
"as",
"err",
":",
"LOGGER",
".",
"error",
"(",
"\"Error connecting to deCONZ gateway at %s\"",
",",
"config",
"[",
"CONF_HOST",
"]",
")",
"raise",
"CannotConnect",
"from",
"err"
] | [
274,
0
] | [
299,
36
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.__init__ | (self, hass, config_entry) | Initialize the system. | Initialize the system. | def __init__(self, hass, config_entry) -> None:
"""Initialize the system."""
self.hass = hass
self.config_entry = config_entry
self.api = None
self.available = True
self.ignore_state_updates = False
self.deconz_ids = {}
self.entities = {}
self.events = []
self.listeners = []
self._current_option_allow_clip_sensor = self.option_allow_clip_sensor
self._current_option_allow_deconz_groups = self.option_allow_deconz_groups | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config_entry",
")",
"->",
"None",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"config_entry",
"=",
"config_entry",
"self",
".",
"api",
"=",
"None",
"self",
".",
"available",
"=",
"True",
"self",
".",
"ignore_state_updates",
"=",
"False",
"self",
".",
"deconz_ids",
"=",
"{",
"}",
"self",
".",
"entities",
"=",
"{",
"}",
"self",
".",
"events",
"=",
"[",
"]",
"self",
".",
"listeners",
"=",
"[",
"]",
"self",
".",
"_current_option_allow_clip_sensor",
"=",
"self",
".",
"option_allow_clip_sensor",
"self",
".",
"_current_option_allow_deconz_groups",
"=",
"self",
".",
"option_allow_deconz_groups"
] | [
42,
4
] | [
58,
82
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.bridgeid | (self) | Return the unique identifier of the gateway. | Return the unique identifier of the gateway. | def bridgeid(self) -> str:
"""Return the unique identifier of the gateway."""
return self.config_entry.unique_id | [
"def",
"bridgeid",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"config_entry",
".",
"unique_id"
] | [
61,
4
] | [
63,
42
] | python | en | ['en', 'fr', 'en'] | True |
DeconzGateway.host | (self) | Return the host of the gateway. | Return the host of the gateway. | def host(self) -> str:
"""Return the host of the gateway."""
return self.config_entry.data[CONF_HOST] | [
"def",
"host",
"(",
"self",
")",
"->",
"str",
":",
"return",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_HOST",
"]"
] | [
66,
4
] | [
68,
48
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.master | (self) | Gateway which is used with deCONZ services without defining id. | Gateway which is used with deCONZ services without defining id. | def master(self) -> bool:
"""Gateway which is used with deCONZ services without defining id."""
return self.config_entry.options[CONF_MASTER_GATEWAY] | [
"def",
"master",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
"[",
"CONF_MASTER_GATEWAY",
"]"
] | [
71,
4
] | [
73,
61
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.option_allow_clip_sensor | (self) | Allow loading clip sensor from gateway. | Allow loading clip sensor from gateway. | def option_allow_clip_sensor(self) -> bool:
"""Allow loading clip sensor from gateway."""
return self.config_entry.options.get(
CONF_ALLOW_CLIP_SENSOR, DEFAULT_ALLOW_CLIP_SENSOR
) | [
"def",
"option_allow_clip_sensor",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_ALLOW_CLIP_SENSOR",
",",
"DEFAULT_ALLOW_CLIP_SENSOR",
")"
] | [
78,
4
] | [
82,
9
] | python | en | ['en', 'fy', 'en'] | True |
DeconzGateway.option_allow_deconz_groups | (self) | Allow loading deCONZ groups from gateway. | Allow loading deCONZ groups from gateway. | def option_allow_deconz_groups(self) -> bool:
"""Allow loading deCONZ groups from gateway."""
return self.config_entry.options.get(
CONF_ALLOW_DECONZ_GROUPS, DEFAULT_ALLOW_DECONZ_GROUPS
) | [
"def",
"option_allow_deconz_groups",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_ALLOW_DECONZ_GROUPS",
",",
"DEFAULT_ALLOW_DECONZ_GROUPS",
")"
] | [
85,
4
] | [
89,
9
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.option_allow_new_devices | (self) | Allow automatic adding of new devices. | Allow automatic adding of new devices. | def option_allow_new_devices(self) -> bool:
"""Allow automatic adding of new devices."""
return self.config_entry.options.get(
CONF_ALLOW_NEW_DEVICES, DEFAULT_ALLOW_NEW_DEVICES
) | [
"def",
"option_allow_new_devices",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"config_entry",
".",
"options",
".",
"get",
"(",
"CONF_ALLOW_NEW_DEVICES",
",",
"DEFAULT_ALLOW_NEW_DEVICES",
")"
] | [
92,
4
] | [
96,
9
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.signal_reachable | (self) | Gateway specific event to signal a change in connection status. | Gateway specific event to signal a change in connection status. | def signal_reachable(self) -> str:
"""Gateway specific event to signal a change in connection status."""
return f"deconz-reachable-{self.bridgeid}" | [
"def",
"signal_reachable",
"(",
"self",
")",
"->",
"str",
":",
"return",
"f\"deconz-reachable-{self.bridgeid}\""
] | [
101,
4
] | [
103,
50
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.async_signal_new_device | (self, device_type) | Gateway specific event to signal new device. | Gateway specific event to signal new device. | def async_signal_new_device(self, device_type) -> str:
"""Gateway specific event to signal new device."""
new_device = {
NEW_GROUP: f"deconz_new_group_{self.bridgeid}",
NEW_LIGHT: f"deconz_new_light_{self.bridgeid}",
NEW_SCENE: f"deconz_new_scene_{self.bridgeid}",
NEW_SENSOR: f"deconz_new_sensor_{self.bridgeid}",
}
return new_device[device_type] | [
"def",
"async_signal_new_device",
"(",
"self",
",",
"device_type",
")",
"->",
"str",
":",
"new_device",
"=",
"{",
"NEW_GROUP",
":",
"f\"deconz_new_group_{self.bridgeid}\"",
",",
"NEW_LIGHT",
":",
"f\"deconz_new_light_{self.bridgeid}\"",
",",
"NEW_SCENE",
":",
"f\"deconz_new_scene_{self.bridgeid}\"",
",",
"NEW_SENSOR",
":",
"f\"deconz_new_sensor_{self.bridgeid}\"",
",",
"}",
"return",
"new_device",
"[",
"device_type",
"]"
] | [
106,
4
] | [
114,
38
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.async_connection_status_callback | (self, available) | Handle signals of gateway connection status. | Handle signals of gateway connection status. | def async_connection_status_callback(self, available) -> None:
"""Handle signals of gateway connection status."""
self.available = available
self.ignore_state_updates = False
async_dispatcher_send(self.hass, self.signal_reachable, True) | [
"def",
"async_connection_status_callback",
"(",
"self",
",",
"available",
")",
"->",
"None",
":",
"self",
".",
"available",
"=",
"available",
"self",
".",
"ignore_state_updates",
"=",
"False",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"self",
".",
"signal_reachable",
",",
"True",
")"
] | [
119,
4
] | [
123,
69
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.async_add_device_callback | (self, device_type, device) | Handle event of new device creation in deCONZ. | Handle event of new device creation in deCONZ. | def async_add_device_callback(self, device_type, device) -> None:
"""Handle event of new device creation in deCONZ."""
if not self.option_allow_new_devices:
return
if not isinstance(device, list):
device = [device]
async_dispatcher_send(
self.hass, self.async_signal_new_device(device_type), device
) | [
"def",
"async_add_device_callback",
"(",
"self",
",",
"device_type",
",",
"device",
")",
"->",
"None",
":",
"if",
"not",
"self",
".",
"option_allow_new_devices",
":",
"return",
"if",
"not",
"isinstance",
"(",
"device",
",",
"list",
")",
":",
"device",
"=",
"[",
"device",
"]",
"async_dispatcher_send",
"(",
"self",
".",
"hass",
",",
"self",
".",
"async_signal_new_device",
"(",
"device_type",
")",
",",
"device",
")"
] | [
126,
4
] | [
136,
9
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.async_update_device_registry | (self) | Update device registry. | Update device registry. | async def async_update_device_registry(self) -> None:
"""Update device registry."""
device_registry = await self.hass.helpers.device_registry.async_get_registry()
# Host device
device_registry.async_get_or_create(
config_entry_id=self.config_entry.entry_id,
connections={(CONNECTION_NETWORK_MAC, self.api.config.mac)},
)
# Gateway service
device_registry.async_get_or_create(
config_entry_id=self.config_entry.entry_id,
identifiers={(DOMAIN, self.api.config.bridgeid)},
manufacturer="Dresden Elektronik",
model=self.api.config.modelid,
name=self.api.config.name,
sw_version=self.api.config.swversion,
via_device=(CONNECTION_NETWORK_MAC, self.api.config.mac),
) | [
"async",
"def",
"async_update_device_registry",
"(",
"self",
")",
"->",
"None",
":",
"device_registry",
"=",
"await",
"self",
".",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"# Host device",
"device_registry",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"self",
".",
"config_entry",
".",
"entry_id",
",",
"connections",
"=",
"{",
"(",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"api",
".",
"config",
".",
"mac",
")",
"}",
",",
")",
"# Gateway service",
"device_registry",
".",
"async_get_or_create",
"(",
"config_entry_id",
"=",
"self",
".",
"config_entry",
".",
"entry_id",
",",
"identifiers",
"=",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"api",
".",
"config",
".",
"bridgeid",
")",
"}",
",",
"manufacturer",
"=",
"\"Dresden Elektronik\"",
",",
"model",
"=",
"self",
".",
"api",
".",
"config",
".",
"modelid",
",",
"name",
"=",
"self",
".",
"api",
".",
"config",
".",
"name",
",",
"sw_version",
"=",
"self",
".",
"api",
".",
"config",
".",
"swversion",
",",
"via_device",
"=",
"(",
"CONNECTION_NETWORK_MAC",
",",
"self",
".",
"api",
".",
"config",
".",
"mac",
")",
",",
")"
] | [
138,
4
] | [
157,
9
] | python | en | ['fr', 'fy', 'en'] | False |
DeconzGateway.async_setup | (self) | Set up a deCONZ gateway. | Set up a deCONZ gateway. | async def async_setup(self) -> bool:
"""Set up a deCONZ gateway."""
try:
self.api = await get_gateway(
self.hass,
self.config_entry.data,
self.async_add_device_callback,
self.async_connection_status_callback,
)
except CannotConnect as err:
raise ConfigEntryNotReady from err
except Exception as err: # pylint: disable=broad-except
LOGGER.error("Error connecting with deCONZ gateway: %s", err)
return False
for component in SUPPORTED_PLATFORMS:
self.hass.async_create_task(
self.hass.config_entries.async_forward_entry_setup(
self.config_entry, component
)
)
self.hass.async_create_task(async_setup_events(self))
self.api.start()
self.config_entry.add_update_listener(self.async_config_entry_updated)
return True | [
"async",
"def",
"async_setup",
"(",
"self",
")",
"->",
"bool",
":",
"try",
":",
"self",
".",
"api",
"=",
"await",
"get_gateway",
"(",
"self",
".",
"hass",
",",
"self",
".",
"config_entry",
".",
"data",
",",
"self",
".",
"async_add_device_callback",
",",
"self",
".",
"async_connection_status_callback",
",",
")",
"except",
"CannotConnect",
"as",
"err",
":",
"raise",
"ConfigEntryNotReady",
"from",
"err",
"except",
"Exception",
"as",
"err",
":",
"# pylint: disable=broad-except",
"LOGGER",
".",
"error",
"(",
"\"Error connecting with deCONZ gateway: %s\"",
",",
"err",
")",
"return",
"False",
"for",
"component",
"in",
"SUPPORTED_PLATFORMS",
":",
"self",
".",
"hass",
".",
"async_create_task",
"(",
"self",
".",
"hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"self",
".",
"config_entry",
",",
"component",
")",
")",
"self",
".",
"hass",
".",
"async_create_task",
"(",
"async_setup_events",
"(",
"self",
")",
")",
"self",
".",
"api",
".",
"start",
"(",
")",
"self",
".",
"config_entry",
".",
"add_update_listener",
"(",
"self",
".",
"async_config_entry_updated",
")",
"return",
"True"
] | [
159,
4
] | [
189,
19
] | python | en | ['en', 'lb', 'en'] | True |
DeconzGateway.async_config_entry_updated | (hass, entry) | Handle signals of config entry being updated.
This is a static method because a class method (bound method), can not be used with weak references.
Causes for this is either discovery updating host address or config entry options changing.
| Handle signals of config entry being updated. | async def async_config_entry_updated(hass, entry) -> None:
"""Handle signals of config entry being updated.
This is a static method because a class method (bound method), can not be used with weak references.
Causes for this is either discovery updating host address or config entry options changing.
"""
gateway = get_gateway_from_config_entry(hass, entry)
if gateway.api.host != gateway.host:
gateway.api.close()
gateway.api.host = gateway.host
gateway.api.start()
return
await gateway.options_updated() | [
"async",
"def",
"async_config_entry_updated",
"(",
"hass",
",",
"entry",
")",
"->",
"None",
":",
"gateway",
"=",
"get_gateway_from_config_entry",
"(",
"hass",
",",
"entry",
")",
"if",
"gateway",
".",
"api",
".",
"host",
"!=",
"gateway",
".",
"host",
":",
"gateway",
".",
"api",
".",
"close",
"(",
")",
"gateway",
".",
"api",
".",
"host",
"=",
"gateway",
".",
"host",
"gateway",
".",
"api",
".",
"start",
"(",
")",
"return",
"await",
"gateway",
".",
"options_updated",
"(",
")"
] | [
192,
4
] | [
206,
39
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.options_updated | (self) | Manage entities affected by config entry options. | Manage entities affected by config entry options. | async def options_updated(self):
"""Manage entities affected by config entry options."""
deconz_ids = []
if self._current_option_allow_clip_sensor != self.option_allow_clip_sensor:
self._current_option_allow_clip_sensor = self.option_allow_clip_sensor
sensors = [
sensor
for sensor in self.api.sensors.values()
if sensor.type.startswith("CLIP")
]
if self.option_allow_clip_sensor:
self.async_add_device_callback(NEW_SENSOR, sensors)
else:
deconz_ids += [sensor.deconz_id for sensor in sensors]
if self._current_option_allow_deconz_groups != self.option_allow_deconz_groups:
self._current_option_allow_deconz_groups = self.option_allow_deconz_groups
groups = list(self.api.groups.values())
if self.option_allow_deconz_groups:
self.async_add_device_callback(NEW_GROUP, groups)
else:
deconz_ids += [group.deconz_id for group in groups]
entity_registry = await self.hass.helpers.entity_registry.async_get_registry()
for entity_id, deconz_id in self.deconz_ids.items():
if deconz_id in deconz_ids and entity_registry.async_is_registered(
entity_id
):
# Removing an entity from the entity registry will also remove them
# from Home Assistant
entity_registry.async_remove(entity_id) | [
"async",
"def",
"options_updated",
"(",
"self",
")",
":",
"deconz_ids",
"=",
"[",
"]",
"if",
"self",
".",
"_current_option_allow_clip_sensor",
"!=",
"self",
".",
"option_allow_clip_sensor",
":",
"self",
".",
"_current_option_allow_clip_sensor",
"=",
"self",
".",
"option_allow_clip_sensor",
"sensors",
"=",
"[",
"sensor",
"for",
"sensor",
"in",
"self",
".",
"api",
".",
"sensors",
".",
"values",
"(",
")",
"if",
"sensor",
".",
"type",
".",
"startswith",
"(",
"\"CLIP\"",
")",
"]",
"if",
"self",
".",
"option_allow_clip_sensor",
":",
"self",
".",
"async_add_device_callback",
"(",
"NEW_SENSOR",
",",
"sensors",
")",
"else",
":",
"deconz_ids",
"+=",
"[",
"sensor",
".",
"deconz_id",
"for",
"sensor",
"in",
"sensors",
"]",
"if",
"self",
".",
"_current_option_allow_deconz_groups",
"!=",
"self",
".",
"option_allow_deconz_groups",
":",
"self",
".",
"_current_option_allow_deconz_groups",
"=",
"self",
".",
"option_allow_deconz_groups",
"groups",
"=",
"list",
"(",
"self",
".",
"api",
".",
"groups",
".",
"values",
"(",
")",
")",
"if",
"self",
".",
"option_allow_deconz_groups",
":",
"self",
".",
"async_add_device_callback",
"(",
"NEW_GROUP",
",",
"groups",
")",
"else",
":",
"deconz_ids",
"+=",
"[",
"group",
".",
"deconz_id",
"for",
"group",
"in",
"groups",
"]",
"entity_registry",
"=",
"await",
"self",
".",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"for",
"entity_id",
",",
"deconz_id",
"in",
"self",
".",
"deconz_ids",
".",
"items",
"(",
")",
":",
"if",
"deconz_id",
"in",
"deconz_ids",
"and",
"entity_registry",
".",
"async_is_registered",
"(",
"entity_id",
")",
":",
"# Removing an entity from the entity registry will also remove them",
"# from Home Assistant",
"entity_registry",
".",
"async_remove",
"(",
"entity_id",
")"
] | [
208,
4
] | [
244,
55
] | python | en | ['en', 'en', 'en'] | True |
DeconzGateway.shutdown | (self, event) | Wrap the call to deconz.close.
Used as an argument to EventBus.async_listen_once.
| Wrap the call to deconz.close. | def shutdown(self, event) -> None:
"""Wrap the call to deconz.close.
Used as an argument to EventBus.async_listen_once.
"""
self.api.close() | [
"def",
"shutdown",
"(",
"self",
",",
"event",
")",
"->",
"None",
":",
"self",
".",
"api",
".",
"close",
"(",
")"
] | [
247,
4
] | [
252,
24
] | python | en | ['en', 'pt', 'en'] | True |
DeconzGateway.async_reset | (self) | Reset this gateway to default state. | Reset this gateway to default state. | async def async_reset(self):
"""Reset this gateway to default state."""
self.api.async_connection_status_callback = None
self.api.close()
for component in SUPPORTED_PLATFORMS:
await self.hass.config_entries.async_forward_entry_unload(
self.config_entry, component
)
for unsub_dispatcher in self.listeners:
unsub_dispatcher()
self.listeners = []
async_unload_events(self)
self.deconz_ids = {}
return True | [
"async",
"def",
"async_reset",
"(",
"self",
")",
":",
"self",
".",
"api",
".",
"async_connection_status_callback",
"=",
"None",
"self",
".",
"api",
".",
"close",
"(",
")",
"for",
"component",
"in",
"SUPPORTED_PLATFORMS",
":",
"await",
"self",
".",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"self",
".",
"config_entry",
",",
"component",
")",
"for",
"unsub_dispatcher",
"in",
"self",
".",
"listeners",
":",
"unsub_dispatcher",
"(",
")",
"self",
".",
"listeners",
"=",
"[",
"]",
"async_unload_events",
"(",
"self",
")",
"self",
".",
"deconz_ids",
"=",
"{",
"}",
"return",
"True"
] | [
254,
4
] | [
271,
19
] | python | en | ['en', 'en', 'en'] | True |
update_probability | (prior, prob_given_true, prob_given_false) | Update probability using Bayes' rule. | Update probability using Bayes' rule. | def update_probability(prior, prob_given_true, prob_given_false):
"""Update probability using Bayes' rule."""
numerator = prob_given_true * prior
denominator = numerator + prob_given_false * (1 - prior)
return numerator / denominator | [
"def",
"update_probability",
"(",
"prior",
",",
"prob_given_true",
",",
"prob_given_false",
")",
":",
"numerator",
"=",
"prob_given_true",
"*",
"prior",
"denominator",
"=",
"numerator",
"+",
"prob_given_false",
"*",
"(",
"1",
"-",
"prior",
")",
"return",
"numerator",
"/",
"denominator"
] | [
102,
0
] | [
106,
34
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Bayesian Binary sensor. | Set up the Bayesian Binary sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Bayesian Binary sensor."""
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)
name = config[CONF_NAME]
observations = config[CONF_OBSERVATIONS]
prior = config[CONF_PRIOR]
probability_threshold = config[CONF_PROBABILITY_THRESHOLD]
device_class = config.get(CONF_DEVICE_CLASS)
async_add_entities(
[
BayesianBinarySensor(
name, prior, observations, probability_threshold, device_class
)
]
) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"await",
"async_setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"observations",
"=",
"config",
"[",
"CONF_OBSERVATIONS",
"]",
"prior",
"=",
"config",
"[",
"CONF_PRIOR",
"]",
"probability_threshold",
"=",
"config",
"[",
"CONF_PROBABILITY_THRESHOLD",
"]",
"device_class",
"=",
"config",
".",
"get",
"(",
"CONF_DEVICE_CLASS",
")",
"async_add_entities",
"(",
"[",
"BayesianBinarySensor",
"(",
"name",
",",
"prior",
",",
"observations",
",",
"probability_threshold",
",",
"device_class",
")",
"]",
")"
] | [
109,
0
] | [
125,
5
] | python | en | ['en', 'haw', 'en'] | True |
BayesianBinarySensor.__init__ | (self, name, prior, observations, probability_threshold, device_class) | Initialize the Bayesian sensor. | Initialize the Bayesian sensor. | def __init__(self, name, prior, observations, probability_threshold, device_class):
"""Initialize the Bayesian sensor."""
self._name = name
self._observations = observations
self._probability_threshold = probability_threshold
self._device_class = device_class
self._deviation = False
self._callbacks = []
self.prior = prior
self.probability = prior
self.current_observations = OrderedDict({})
self.observations_by_entity = self._build_observations_by_entity()
self.observations_by_template = self._build_observations_by_template()
self.observation_handlers = {
"numeric_state": self._process_numeric_state,
"state": self._process_state,
} | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"prior",
",",
"observations",
",",
"probability_threshold",
",",
"device_class",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_observations",
"=",
"observations",
"self",
".",
"_probability_threshold",
"=",
"probability_threshold",
"self",
".",
"_device_class",
"=",
"device_class",
"self",
".",
"_deviation",
"=",
"False",
"self",
".",
"_callbacks",
"=",
"[",
"]",
"self",
".",
"prior",
"=",
"prior",
"self",
".",
"probability",
"=",
"prior",
"self",
".",
"current_observations",
"=",
"OrderedDict",
"(",
"{",
"}",
")",
"self",
".",
"observations_by_entity",
"=",
"self",
".",
"_build_observations_by_entity",
"(",
")",
"self",
".",
"observations_by_template",
"=",
"self",
".",
"_build_observations_by_template",
"(",
")",
"self",
".",
"observation_handlers",
"=",
"{",
"\"numeric_state\"",
":",
"self",
".",
"_process_numeric_state",
",",
"\"state\"",
":",
"self",
".",
"_process_state",
",",
"}"
] | [
131,
4
] | [
151,
9
] | python | en | ['en', 'zh-Latn', 'en'] | True |
BayesianBinarySensor.async_added_to_hass | (self) |
Call when entity about to be added.
All relevant update logic for instance attributes occurs within this closure.
Other methods in this class are designed to avoid directly modifying instance
attributes, by instead focusing on returning relevant data back to this method.
The goal of this method is to ensure that `self.current_observations` and `self.probability`
are set on a best-effort basis when this entity is register with hass.
In addition, this method must register the state listener defined within, which
will be called any time a relevant entity changes its state.
|
Call when entity about to be added. | async def async_added_to_hass(self):
"""
Call when entity about to be added.
All relevant update logic for instance attributes occurs within this closure.
Other methods in this class are designed to avoid directly modifying instance
attributes, by instead focusing on returning relevant data back to this method.
The goal of this method is to ensure that `self.current_observations` and `self.probability`
are set on a best-effort basis when this entity is register with hass.
In addition, this method must register the state listener defined within, which
will be called any time a relevant entity changes its state.
"""
@callback
def async_threshold_sensor_state_listener(event):
"""
Handle sensor state changes.
When a state changes, we must update our list of current observations,
then calculate the new probability.
"""
new_state = event.data.get("new_state")
if new_state is None or new_state.state == STATE_UNKNOWN:
return
entity = event.data.get("entity_id")
self.current_observations.update(self._record_entity_observations(entity))
self.async_set_context(event.context)
self._recalculate_and_write_state()
self.async_on_remove(
async_track_state_change_event(
self.hass,
list(self.observations_by_entity),
async_threshold_sensor_state_listener,
)
)
@callback
def _async_template_result_changed(event, updates):
track_template_result = updates.pop()
template = track_template_result.template
result = track_template_result.result
entity = event and event.data.get("entity_id")
if isinstance(result, TemplateError):
_LOGGER.error(
"TemplateError('%s') "
"while processing template '%s' "
"in entity '%s'",
result,
template,
self.entity_id,
)
should_trigger = False
else:
should_trigger = result_as_boolean(result)
for obs in self.observations_by_template[template]:
if should_trigger:
obs_entry = {"entity_id": entity, **obs}
else:
obs_entry = None
self.current_observations[obs["id"]] = obs_entry
if event:
self.async_set_context(event.context)
self._recalculate_and_write_state()
for template in self.observations_by_template:
info = async_track_template_result(
self.hass,
[TrackTemplate(template, None)],
_async_template_result_changed,
)
self._callbacks.append(info)
self.async_on_remove(info.async_remove)
info.async_refresh()
self.current_observations.update(self._initialize_current_observations())
self.probability = self._calculate_new_probability()
self._deviation = bool(self.probability >= self._probability_threshold) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"@",
"callback",
"def",
"async_threshold_sensor_state_listener",
"(",
"event",
")",
":",
"\"\"\"\n Handle sensor state changes.\n\n When a state changes, we must update our list of current observations,\n then calculate the new probability.\n \"\"\"",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",
")",
"if",
"new_state",
"is",
"None",
"or",
"new_state",
".",
"state",
"==",
"STATE_UNKNOWN",
":",
"return",
"entity",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"entity_id\"",
")",
"self",
".",
"current_observations",
".",
"update",
"(",
"self",
".",
"_record_entity_observations",
"(",
"entity",
")",
")",
"self",
".",
"async_set_context",
"(",
"event",
".",
"context",
")",
"self",
".",
"_recalculate_and_write_state",
"(",
")",
"self",
".",
"async_on_remove",
"(",
"async_track_state_change_event",
"(",
"self",
".",
"hass",
",",
"list",
"(",
"self",
".",
"observations_by_entity",
")",
",",
"async_threshold_sensor_state_listener",
",",
")",
")",
"@",
"callback",
"def",
"_async_template_result_changed",
"(",
"event",
",",
"updates",
")",
":",
"track_template_result",
"=",
"updates",
".",
"pop",
"(",
")",
"template",
"=",
"track_template_result",
".",
"template",
"result",
"=",
"track_template_result",
".",
"result",
"entity",
"=",
"event",
"and",
"event",
".",
"data",
".",
"get",
"(",
"\"entity_id\"",
")",
"if",
"isinstance",
"(",
"result",
",",
"TemplateError",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"TemplateError('%s') \"",
"\"while processing template '%s' \"",
"\"in entity '%s'\"",
",",
"result",
",",
"template",
",",
"self",
".",
"entity_id",
",",
")",
"should_trigger",
"=",
"False",
"else",
":",
"should_trigger",
"=",
"result_as_boolean",
"(",
"result",
")",
"for",
"obs",
"in",
"self",
".",
"observations_by_template",
"[",
"template",
"]",
":",
"if",
"should_trigger",
":",
"obs_entry",
"=",
"{",
"\"entity_id\"",
":",
"entity",
",",
"*",
"*",
"obs",
"}",
"else",
":",
"obs_entry",
"=",
"None",
"self",
".",
"current_observations",
"[",
"obs",
"[",
"\"id\"",
"]",
"]",
"=",
"obs_entry",
"if",
"event",
":",
"self",
".",
"async_set_context",
"(",
"event",
".",
"context",
")",
"self",
".",
"_recalculate_and_write_state",
"(",
")",
"for",
"template",
"in",
"self",
".",
"observations_by_template",
":",
"info",
"=",
"async_track_template_result",
"(",
"self",
".",
"hass",
",",
"[",
"TrackTemplate",
"(",
"template",
",",
"None",
")",
"]",
",",
"_async_template_result_changed",
",",
")",
"self",
".",
"_callbacks",
".",
"append",
"(",
"info",
")",
"self",
".",
"async_on_remove",
"(",
"info",
".",
"async_remove",
")",
"info",
".",
"async_refresh",
"(",
")",
"self",
".",
"current_observations",
".",
"update",
"(",
"self",
".",
"_initialize_current_observations",
"(",
")",
")",
"self",
".",
"probability",
"=",
"self",
".",
"_calculate_new_probability",
"(",
")",
"self",
".",
"_deviation",
"=",
"bool",
"(",
"self",
".",
"probability",
">=",
"self",
".",
"_probability_threshold",
")"
] | [
153,
4
] | [
240,
79
] | python | en | ['en', 'error', 'th'] | False |
BayesianBinarySensor._build_observations_by_entity | (self) |
Build and return data structure of the form below.
{
"sensor.sensor1": [{"id": 0, ...}, {"id": 1, ...}],
"sensor.sensor2": [{"id": 2, ...}],
...
}
Each "observation" must be recognized uniquely, and it should be possible
for all relevant observations to be looked up via their `entity_id`.
|
Build and return data structure of the form below. | def _build_observations_by_entity(self):
"""
Build and return data structure of the form below.
{
"sensor.sensor1": [{"id": 0, ...}, {"id": 1, ...}],
"sensor.sensor2": [{"id": 2, ...}],
...
}
Each "observation" must be recognized uniquely, and it should be possible
for all relevant observations to be looked up via their `entity_id`.
"""
observations_by_entity = {}
for ind, obs in enumerate(self._observations):
obs["id"] = ind
if "entity_id" not in obs:
continue
entity_ids = [obs["entity_id"]]
for e_id in entity_ids:
observations_by_entity.setdefault(e_id, []).append(obs)
return observations_by_entity | [
"def",
"_build_observations_by_entity",
"(",
"self",
")",
":",
"observations_by_entity",
"=",
"{",
"}",
"for",
"ind",
",",
"obs",
"in",
"enumerate",
"(",
"self",
".",
"_observations",
")",
":",
"obs",
"[",
"\"id\"",
"]",
"=",
"ind",
"if",
"\"entity_id\"",
"not",
"in",
"obs",
":",
"continue",
"entity_ids",
"=",
"[",
"obs",
"[",
"\"entity_id\"",
"]",
"]",
"for",
"e_id",
"in",
"entity_ids",
":",
"observations_by_entity",
".",
"setdefault",
"(",
"e_id",
",",
"[",
"]",
")",
".",
"append",
"(",
"obs",
")",
"return",
"observations_by_entity"
] | [
284,
4
] | [
310,
37
] | python | en | ['en', 'error', 'th'] | False |
BayesianBinarySensor._build_observations_by_template | (self) |
Build and return data structure of the form below.
{
"template": [{"id": 0, ...}, {"id": 1, ...}],
"template2": [{"id": 2, ...}],
...
}
Each "observation" must be recognized uniquely, and it should be possible
for all relevant observations to be looked up via their `template`.
|
Build and return data structure of the form below. | def _build_observations_by_template(self):
"""
Build and return data structure of the form below.
{
"template": [{"id": 0, ...}, {"id": 1, ...}],
"template2": [{"id": 2, ...}],
...
}
Each "observation" must be recognized uniquely, and it should be possible
for all relevant observations to be looked up via their `template`.
"""
observations_by_template = {}
for ind, obs in enumerate(self._observations):
obs["id"] = ind
if "value_template" not in obs:
continue
template = obs.get(CONF_VALUE_TEMPLATE)
observations_by_template.setdefault(template, []).append(obs)
return observations_by_template | [
"def",
"_build_observations_by_template",
"(",
"self",
")",
":",
"observations_by_template",
"=",
"{",
"}",
"for",
"ind",
",",
"obs",
"in",
"enumerate",
"(",
"self",
".",
"_observations",
")",
":",
"obs",
"[",
"\"id\"",
"]",
"=",
"ind",
"if",
"\"value_template\"",
"not",
"in",
"obs",
":",
"continue",
"template",
"=",
"obs",
".",
"get",
"(",
"CONF_VALUE_TEMPLATE",
")",
"observations_by_template",
".",
"setdefault",
"(",
"template",
",",
"[",
"]",
")",
".",
"append",
"(",
"obs",
")",
"return",
"observations_by_template"
] | [
312,
4
] | [
336,
39
] | python | en | ['en', 'error', 'th'] | False |
BayesianBinarySensor._process_numeric_state | (self, entity_observation) | Return True if numeric condition is met. | Return True if numeric condition is met. | def _process_numeric_state(self, entity_observation):
"""Return True if numeric condition is met."""
entity = entity_observation["entity_id"]
return condition.async_numeric_state(
self.hass,
entity,
entity_observation.get("below"),
entity_observation.get("above"),
None,
entity_observation,
) | [
"def",
"_process_numeric_state",
"(",
"self",
",",
"entity_observation",
")",
":",
"entity",
"=",
"entity_observation",
"[",
"\"entity_id\"",
"]",
"return",
"condition",
".",
"async_numeric_state",
"(",
"self",
".",
"hass",
",",
"entity",
",",
"entity_observation",
".",
"get",
"(",
"\"below\"",
")",
",",
"entity_observation",
".",
"get",
"(",
"\"above\"",
")",
",",
"None",
",",
"entity_observation",
",",
")"
] | [
338,
4
] | [
349,
9
] | python | en | ['en', 'la', 'en'] | True |
BayesianBinarySensor._process_state | (self, entity_observation) | Return True if state conditions are met. | Return True if state conditions are met. | def _process_state(self, entity_observation):
"""Return True if state conditions are met."""
entity = entity_observation["entity_id"]
return condition.state(self.hass, entity, entity_observation.get("to_state")) | [
"def",
"_process_state",
"(",
"self",
",",
"entity_observation",
")",
":",
"entity",
"=",
"entity_observation",
"[",
"\"entity_id\"",
"]",
"return",
"condition",
".",
"state",
"(",
"self",
".",
"hass",
",",
"entity",
",",
"entity_observation",
".",
"get",
"(",
"\"to_state\"",
")",
")"
] | [
351,
4
] | [
355,
85
] | python | en | ['en', 'en', 'en'] | True |
BayesianBinarySensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
358,
4
] | [
360,
25
] | python | en | ['en', 'mi', 'en'] | True |
BayesianBinarySensor.is_on | (self) | Return true if sensor is on. | Return true if sensor is on. | def is_on(self):
"""Return true if sensor is on."""
return self._deviation | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_deviation"
] | [
363,
4
] | [
365,
30
] | python | en | ['en', 'et', 'en'] | True |
BayesianBinarySensor.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
368,
4
] | [
370,
20
] | python | en | ['en', 'en', 'en'] | True |
BayesianBinarySensor.device_class | (self) | Return the sensor class of the sensor. | Return the sensor class of the sensor. | def device_class(self):
"""Return the sensor class of the sensor."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_class"
] | [
373,
4
] | [
375,
33
] | python | en | ['en', 'sq', 'en'] | True |
BayesianBinarySensor.device_state_attributes | (self) | Return the state attributes of the sensor. | Return the state attributes of the sensor. | def device_state_attributes(self):
"""Return the state attributes of the sensor."""
attr_observations_list = [
obs.copy() for obs in self.current_observations.values() if obs is not None
]
for item in attr_observations_list:
item.pop("value_template", None)
return {
ATTR_OBSERVATIONS: attr_observations_list,
ATTR_OCCURRED_OBSERVATION_ENTITIES: list(
{
obs.get("entity_id")
for obs in self.current_observations.values()
if obs is not None and obs.get("entity_id") is not None
}
),
ATTR_PROBABILITY: round(self.probability, 2),
ATTR_PROBABILITY_THRESHOLD: self._probability_threshold,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attr_observations_list",
"=",
"[",
"obs",
".",
"copy",
"(",
")",
"for",
"obs",
"in",
"self",
".",
"current_observations",
".",
"values",
"(",
")",
"if",
"obs",
"is",
"not",
"None",
"]",
"for",
"item",
"in",
"attr_observations_list",
":",
"item",
".",
"pop",
"(",
"\"value_template\"",
",",
"None",
")",
"return",
"{",
"ATTR_OBSERVATIONS",
":",
"attr_observations_list",
",",
"ATTR_OCCURRED_OBSERVATION_ENTITIES",
":",
"list",
"(",
"{",
"obs",
".",
"get",
"(",
"\"entity_id\"",
")",
"for",
"obs",
"in",
"self",
".",
"current_observations",
".",
"values",
"(",
")",
"if",
"obs",
"is",
"not",
"None",
"and",
"obs",
".",
"get",
"(",
"\"entity_id\"",
")",
"is",
"not",
"None",
"}",
")",
",",
"ATTR_PROBABILITY",
":",
"round",
"(",
"self",
".",
"probability",
",",
"2",
")",
",",
"ATTR_PROBABILITY_THRESHOLD",
":",
"self",
".",
"_probability_threshold",
",",
"}"
] | [
378,
4
] | [
399,
9
] | python | en | ['en', 'en', 'en'] | True |
BayesianBinarySensor.async_update | (self) | Get the latest data and update the states. | Get the latest data and update the states. | async def async_update(self):
"""Get the latest data and update the states."""
if not self._callbacks:
self._recalculate_and_write_state()
return
# Force recalc of the templates. The states will
# update automatically.
for call in self._callbacks:
call.async_refresh() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_callbacks",
":",
"self",
".",
"_recalculate_and_write_state",
"(",
")",
"return",
"# Force recalc of the templates. The states will",
"# update automatically.",
"for",
"call",
"in",
"self",
".",
"_callbacks",
":",
"call",
".",
"async_refresh",
"(",
")"
] | [
401,
4
] | [
409,
32
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up Homekit fans. | Set up Homekit fans. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up Homekit fans."""
hkid = config_entry.data["AccessoryPairingID"]
conn = hass.data[KNOWN_DEVICES][hkid]
@callback
def async_add_service(service):
entity_class = ENTITY_TYPES.get(service.short_type)
if not entity_class:
return False
info = {"aid": service.accessory.aid, "iid": service.iid}
async_add_entities([entity_class(conn, info)], True)
return True
conn.add_listener(async_add_service) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"hkid",
"=",
"config_entry",
".",
"data",
"[",
"\"AccessoryPairingID\"",
"]",
"conn",
"=",
"hass",
".",
"data",
"[",
"KNOWN_DEVICES",
"]",
"[",
"hkid",
"]",
"@",
"callback",
"def",
"async_add_service",
"(",
"service",
")",
":",
"entity_class",
"=",
"ENTITY_TYPES",
".",
"get",
"(",
"service",
".",
"short_type",
")",
"if",
"not",
"entity_class",
":",
"return",
"False",
"info",
"=",
"{",
"\"aid\"",
":",
"service",
".",
"accessory",
".",
"aid",
",",
"\"iid\"",
":",
"service",
".",
"iid",
"}",
"async_add_entities",
"(",
"[",
"entity_class",
"(",
"conn",
",",
"info",
")",
"]",
",",
"True",
")",
"return",
"True",
"conn",
".",
"add_listener",
"(",
"async_add_service",
")"
] | [
169,
0
] | [
183,
40
] | python | en | ['en', 'lb', 'en'] | True |
BaseHomeKitFan.get_characteristic_types | (self) | Define the homekit characteristics the entity cares about. | Define the homekit characteristics the entity cares about. | def get_characteristic_types(self):
"""Define the homekit characteristics the entity cares about."""
return [
CharacteristicsTypes.SWING_MODE,
CharacteristicsTypes.ROTATION_DIRECTION,
CharacteristicsTypes.ROTATION_SPEED,
self.on_characteristic,
] | [
"def",
"get_characteristic_types",
"(",
"self",
")",
":",
"return",
"[",
"CharacteristicsTypes",
".",
"SWING_MODE",
",",
"CharacteristicsTypes",
".",
"ROTATION_DIRECTION",
",",
"CharacteristicsTypes",
".",
"ROTATION_SPEED",
",",
"self",
".",
"on_characteristic",
",",
"]"
] | [
43,
4
] | [
50,
9
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.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.service.value(self.on_characteristic) == 1 | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"service",
".",
"value",
"(",
"self",
".",
"on_characteristic",
")",
"==",
"1"
] | [
53,
4
] | [
55,
62
] | python | en | ['en', 'fy', 'en'] | True |
BaseHomeKitFan.speed | (self) | Return the current speed. | Return the current speed. | def speed(self):
"""Return the current speed."""
if not self.is_on:
return SPEED_OFF
rotation_speed = self.service.value(CharacteristicsTypes.ROTATION_SPEED)
if rotation_speed > SPEED_TO_PCNT[SPEED_MEDIUM]:
return SPEED_HIGH
if rotation_speed > SPEED_TO_PCNT[SPEED_LOW]:
return SPEED_MEDIUM
if rotation_speed > SPEED_TO_PCNT[SPEED_OFF]:
return SPEED_LOW
return SPEED_OFF | [
"def",
"speed",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_on",
":",
"return",
"SPEED_OFF",
"rotation_speed",
"=",
"self",
".",
"service",
".",
"value",
"(",
"CharacteristicsTypes",
".",
"ROTATION_SPEED",
")",
"if",
"rotation_speed",
">",
"SPEED_TO_PCNT",
"[",
"SPEED_MEDIUM",
"]",
":",
"return",
"SPEED_HIGH",
"if",
"rotation_speed",
">",
"SPEED_TO_PCNT",
"[",
"SPEED_LOW",
"]",
":",
"return",
"SPEED_MEDIUM",
"if",
"rotation_speed",
">",
"SPEED_TO_PCNT",
"[",
"SPEED_OFF",
"]",
":",
"return",
"SPEED_LOW",
"return",
"SPEED_OFF"
] | [
58,
4
] | [
74,
24
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.speed_list | (self) | Get the list of available speeds. | Get the list of available speeds. | def speed_list(self):
"""Get the list of available speeds."""
if self.supported_features & SUPPORT_SET_SPEED:
return [SPEED_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH]
return [] | [
"def",
"speed_list",
"(",
"self",
")",
":",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_SET_SPEED",
":",
"return",
"[",
"SPEED_OFF",
",",
"SPEED_LOW",
",",
"SPEED_MEDIUM",
",",
"SPEED_HIGH",
"]",
"return",
"[",
"]"
] | [
77,
4
] | [
81,
17
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.current_direction | (self) | Return the current direction of the fan. | Return the current direction of the fan. | def current_direction(self):
"""Return the current direction of the fan."""
direction = self.service.value(CharacteristicsTypes.ROTATION_DIRECTION)
return HK_DIRECTION_TO_HA[direction] | [
"def",
"current_direction",
"(",
"self",
")",
":",
"direction",
"=",
"self",
".",
"service",
".",
"value",
"(",
"CharacteristicsTypes",
".",
"ROTATION_DIRECTION",
")",
"return",
"HK_DIRECTION_TO_HA",
"[",
"direction",
"]"
] | [
84,
4
] | [
87,
44
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.oscillating | (self) | Return whether or not the fan is currently oscillating. | Return whether or not the fan is currently oscillating. | def oscillating(self):
"""Return whether or not the fan is currently oscillating."""
oscillating = self.service.value(CharacteristicsTypes.SWING_MODE)
return oscillating == 1 | [
"def",
"oscillating",
"(",
"self",
")",
":",
"oscillating",
"=",
"self",
".",
"service",
".",
"value",
"(",
"CharacteristicsTypes",
".",
"SWING_MODE",
")",
"return",
"oscillating",
"==",
"1"
] | [
90,
4
] | [
93,
31
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
features = 0
if self.service.has(CharacteristicsTypes.ROTATION_DIRECTION):
features |= SUPPORT_DIRECTION
if self.service.has(CharacteristicsTypes.ROTATION_SPEED):
features |= SUPPORT_SET_SPEED
if self.service.has(CharacteristicsTypes.SWING_MODE):
features |= SUPPORT_OSCILLATE
return features | [
"def",
"supported_features",
"(",
"self",
")",
":",
"features",
"=",
"0",
"if",
"self",
".",
"service",
".",
"has",
"(",
"CharacteristicsTypes",
".",
"ROTATION_DIRECTION",
")",
":",
"features",
"|=",
"SUPPORT_DIRECTION",
"if",
"self",
".",
"service",
".",
"has",
"(",
"CharacteristicsTypes",
".",
"ROTATION_SPEED",
")",
":",
"features",
"|=",
"SUPPORT_SET_SPEED",
"if",
"self",
".",
"service",
".",
"has",
"(",
"CharacteristicsTypes",
".",
"SWING_MODE",
")",
":",
"features",
"|=",
"SUPPORT_OSCILLATE",
"return",
"features"
] | [
96,
4
] | [
109,
23
] | python | en | ['da', 'en', 'en'] | True |
BaseHomeKitFan.async_set_direction | (self, direction) | Set the direction of the fan. | Set the direction of the fan. | async def async_set_direction(self, direction):
"""Set the direction of the fan."""
await self.async_put_characteristics(
{CharacteristicsTypes.ROTATION_DIRECTION: DIRECTION_TO_HK[direction]}
) | [
"async",
"def",
"async_set_direction",
"(",
"self",
",",
"direction",
")",
":",
"await",
"self",
".",
"async_put_characteristics",
"(",
"{",
"CharacteristicsTypes",
".",
"ROTATION_DIRECTION",
":",
"DIRECTION_TO_HK",
"[",
"direction",
"]",
"}",
")"
] | [
111,
4
] | [
115,
9
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.async_set_speed | (self, speed) | Set the speed of the fan. | Set the speed of the fan. | async def async_set_speed(self, speed):
"""Set the speed of the fan."""
if speed == SPEED_OFF:
return await self.async_turn_off()
await self.async_put_characteristics(
{CharacteristicsTypes.ROTATION_SPEED: SPEED_TO_PCNT[speed]}
) | [
"async",
"def",
"async_set_speed",
"(",
"self",
",",
"speed",
")",
":",
"if",
"speed",
"==",
"SPEED_OFF",
":",
"return",
"await",
"self",
".",
"async_turn_off",
"(",
")",
"await",
"self",
".",
"async_put_characteristics",
"(",
"{",
"CharacteristicsTypes",
".",
"ROTATION_SPEED",
":",
"SPEED_TO_PCNT",
"[",
"speed",
"]",
"}",
")"
] | [
117,
4
] | [
124,
9
] | python | en | ['en', 'en', 'en'] | True |
BaseHomeKitFan.async_oscillate | (self, oscillating: bool) | Oscillate the fan. | Oscillate the fan. | async def async_oscillate(self, oscillating: bool):
"""Oscillate the fan."""
await self.async_put_characteristics(
{CharacteristicsTypes.SWING_MODE: 1 if oscillating else 0}
) | [
"async",
"def",
"async_oscillate",
"(",
"self",
",",
"oscillating",
":",
"bool",
")",
":",
"await",
"self",
".",
"async_put_characteristics",
"(",
"{",
"CharacteristicsTypes",
".",
"SWING_MODE",
":",
"1",
"if",
"oscillating",
"else",
"0",
"}",
")"
] | [
126,
4
] | [
130,
9
] | python | en | ['en', 'fy', 'en'] | True |
BaseHomeKitFan.async_turn_on | (self, speed=None, **kwargs) | Turn the specified fan on. | Turn the specified fan on. | async def async_turn_on(self, speed=None, **kwargs):
"""Turn the specified fan on."""
characteristics = {}
if not self.is_on:
characteristics[self.on_characteristic] = True
if self.supported_features & SUPPORT_SET_SPEED and speed:
characteristics[CharacteristicsTypes.ROTATION_SPEED] = SPEED_TO_PCNT[speed]
if characteristics:
await self.async_put_characteristics(characteristics) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"speed",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"characteristics",
"=",
"{",
"}",
"if",
"not",
"self",
".",
"is_on",
":",
"characteristics",
"[",
"self",
".",
"on_characteristic",
"]",
"=",
"True",
"if",
"self",
".",
"supported_features",
"&",
"SUPPORT_SET_SPEED",
"and",
"speed",
":",
"characteristics",
"[",
"CharacteristicsTypes",
".",
"ROTATION_SPEED",
"]",
"=",
"SPEED_TO_PCNT",
"[",
"speed",
"]",
"if",
"characteristics",
":",
"await",
"self",
".",
"async_put_characteristics",
"(",
"characteristics",
")"
] | [
132,
4
] | [
144,
65
] | python | en | ['en', 'fy', 'en'] | True |
BaseHomeKitFan.async_turn_off | (self, **kwargs) | Turn the specified fan off. | Turn the specified fan off. | async def async_turn_off(self, **kwargs):
"""Turn the specified fan off."""
await self.async_put_characteristics({self.on_characteristic: False}) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"await",
"self",
".",
"async_put_characteristics",
"(",
"{",
"self",
".",
"on_characteristic",
":",
"False",
"}",
")"
] | [
146,
4
] | [
148,
77
] | python | en | ['en', 'fy', 'en'] | True |
test_form | (hass) | Test we get the form. | Test we get the form. | async def test_form(hass):
"""Test we get the form."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["errors"] == {}
with patch(
"homeassistant.components.volumio.config_flow.Volumio.get_system_info",
return_value=TEST_SYSTEM_INFO,
), patch(
"homeassistant.components.volumio.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.volumio.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
TEST_CONNECTION,
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == "TestVolumio"
assert result2["data"] == {**TEST_SYSTEM_INFO, **TEST_CONNECTION}
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_form",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"}",
"with",
"patch",
"(",
"\"homeassistant.components.volumio.config_flow.Volumio.get_system_info\"",
",",
"return_value",
"=",
"TEST_SYSTEM_INFO",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup\"",
",",
"return_value",
"=",
"True",
")",
"as",
"mock_setup",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup_entry\"",
",",
"return_value",
"=",
"True",
",",
")",
"as",
"mock_setup_entry",
":",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"TEST_CONNECTION",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result2",
"[",
"\"title\"",
"]",
"==",
"\"TestVolumio\"",
"assert",
"result2",
"[",
"\"data\"",
"]",
"==",
"{",
"*",
"*",
"TEST_SYSTEM_INFO",
",",
"*",
"*",
"TEST_CONNECTION",
"}",
"assert",
"len",
"(",
"mock_setup",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
31,
0
] | [
59,
48
] | python | en | ['en', 'en', 'en'] | True |
test_form_updates_unique_id | (hass) | Test a duplicate id aborts and updates existing entry. | Test a duplicate id aborts and updates existing entry. | async def test_form_updates_unique_id(hass):
"""Test a duplicate id aborts and updates existing entry."""
entry = MockConfigEntry(
domain=DOMAIN,
unique_id=TEST_SYSTEM_INFO["id"],
data={
"host": "dummy",
"port": 11,
"name": "dummy",
"id": TEST_SYSTEM_INFO["id"],
},
)
entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(
"homeassistant.components.volumio.config_flow.Volumio.get_system_info",
return_value=TEST_SYSTEM_INFO,
), patch("homeassistant.components.volumio.async_setup", return_value=True), patch(
"homeassistant.components.volumio.async_setup_entry",
return_value=True,
):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
TEST_CONNECTION,
)
await hass.async_block_till_done()
assert result2["type"] == "abort"
assert result2["reason"] == "already_configured"
assert entry.data == {**TEST_SYSTEM_INFO, **TEST_CONNECTION} | [
"async",
"def",
"test_form_updates_unique_id",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"unique_id",
"=",
"TEST_SYSTEM_INFO",
"[",
"\"id\"",
"]",
",",
"data",
"=",
"{",
"\"host\"",
":",
"\"dummy\"",
",",
"\"port\"",
":",
"11",
",",
"\"name\"",
":",
"\"dummy\"",
",",
"\"id\"",
":",
"TEST_SYSTEM_INFO",
"[",
"\"id\"",
"]",
",",
"}",
",",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"with",
"patch",
"(",
"\"homeassistant.components.volumio.config_flow.Volumio.get_system_info\"",
",",
"return_value",
"=",
"TEST_SYSTEM_INFO",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup\"",
",",
"return_value",
"=",
"True",
")",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup_entry\"",
",",
"return_value",
"=",
"True",
",",
")",
":",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"TEST_CONNECTION",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"abort\"",
"assert",
"result2",
"[",
"\"reason\"",
"]",
"==",
"\"already_configured\"",
"assert",
"entry",
".",
"data",
"==",
"{",
"*",
"*",
"TEST_SYSTEM_INFO",
",",
"*",
"*",
"TEST_CONNECTION",
"}"
] | [
62,
0
] | [
96,
64
] | python | en | ['en', 'en', 'en'] | True |
test_empty_system_info | (hass) | Test old volumio versions with empty system info. | Test old volumio versions with empty system info. | async def test_empty_system_info(hass):
"""Test old volumio versions with empty system info."""
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
assert result["type"] == "form"
assert result["errors"] == {}
with patch(
"homeassistant.components.volumio.config_flow.Volumio.get_system_info",
return_value={},
), patch(
"homeassistant.components.volumio.async_setup", return_value=True
) as mock_setup, patch(
"homeassistant.components.volumio.async_setup_entry",
return_value=True,
) as mock_setup_entry:
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
TEST_CONNECTION,
)
await hass.async_block_till_done()
assert result2["type"] == "create_entry"
assert result2["title"] == TEST_CONNECTION["host"]
assert result2["data"] == {
"host": TEST_CONNECTION["host"],
"port": TEST_CONNECTION["port"],
"name": TEST_CONNECTION["host"],
"id": None,
}
assert len(mock_setup.mock_calls) == 1
assert len(mock_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_empty_system_info",
"(",
"hass",
")",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_USER",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"\"form\"",
"assert",
"result",
"[",
"\"errors\"",
"]",
"==",
"{",
"}",
"with",
"patch",
"(",
"\"homeassistant.components.volumio.config_flow.Volumio.get_system_info\"",
",",
"return_value",
"=",
"{",
"}",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup\"",
",",
"return_value",
"=",
"True",
")",
"as",
"mock_setup",
",",
"patch",
"(",
"\"homeassistant.components.volumio.async_setup_entry\"",
",",
"return_value",
"=",
"True",
",",
")",
"as",
"mock_setup_entry",
":",
"result2",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"TEST_CONNECTION",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result2",
"[",
"\"type\"",
"]",
"==",
"\"create_entry\"",
"assert",
"result2",
"[",
"\"title\"",
"]",
"==",
"TEST_CONNECTION",
"[",
"\"host\"",
"]",
"assert",
"result2",
"[",
"\"data\"",
"]",
"==",
"{",
"\"host\"",
":",
"TEST_CONNECTION",
"[",
"\"host\"",
"]",
",",
"\"port\"",
":",
"TEST_CONNECTION",
"[",
"\"port\"",
"]",
",",
"\"name\"",
":",
"TEST_CONNECTION",
"[",
"\"host\"",
"]",
",",
"\"id\"",
":",
"None",
",",
"}",
"assert",
"len",
"(",
"mock_setup",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
99,
0
] | [
132,
48
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.