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 |
---|---|---|---|---|---|---|---|---|---|---|---|
FroniusMeterDevice._update | (self) | Get the values for the current state. | Get the values for the current state. | async def _update(self):
"""Get the values for the current state."""
return await self.bridge.current_meter_data(self._device) | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_meter_data",
"(",
"self",
".",
"_device",
")"
] | [
227,
4
] | [
229,
65
] | python | en | ['en', 'en', 'en'] | True |
FroniusPowerFlow._update | (self) | Get the values for the current state. | Get the values for the current state. | async def _update(self):
"""Get the values for the current state."""
return await self.bridge.current_power_flow() | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_power_flow",
"(",
")"
] | [
235,
4
] | [
237,
53
] | python | en | ['en', 'en', 'en'] | True |
FroniusTemplateSensor.__init__ | (self, parent: FroniusAdapter, name) | Initialize a singular value sensor. | Initialize a singular value sensor. | def __init__(self, parent: FroniusAdapter, name):
"""Initialize a singular value sensor."""
self._name = name
self.parent = parent
self._state = None
self._unit = None | [
"def",
"__init__",
"(",
"self",
",",
"parent",
":",
"FroniusAdapter",
",",
"name",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"parent",
"=",
"parent",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_unit",
"=",
"None"
] | [
243,
4
] | [
248,
25
] | python | en | ['es', 'pt', 'en'] | False |
FroniusTemplateSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self._name.replace('_', ' ').capitalize()} {self.parent.name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name.replace('_', ' ').capitalize()} {self.parent.name}\""
] | [
251,
4
] | [
253,
80
] | python | en | ['en', 'mi', 'en'] | True |
FroniusTemplateSensor.state | (self) | Return the current state. | Return the current state. | def state(self):
"""Return the current state."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
256,
4
] | [
258,
26
] | python | en | ['en', 'en', 'en'] | True |
FroniusTemplateSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit"
] | [
261,
4
] | [
263,
25
] | python | en | ['en', 'la', 'en'] | True |
FroniusTemplateSensor.should_poll | (self) | Device should not be polled, returns False. | Device should not be polled, returns False. | def should_poll(self):
"""Device should not be polled, returns False."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
266,
4
] | [
268,
20
] | python | en | ['en', 'en', 'en'] | True |
FroniusTemplateSensor.async_update | (self) | Update the internal state. | Update the internal state. | async def async_update(self):
"""Update the internal state."""
state = self.parent.data.get(self._name)
self._state = state.get("value")
self._unit = state.get("unit") | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"parent",
".",
"data",
".",
"get",
"(",
"self",
".",
"_name",
")",
"self",
".",
"_state",
"=",
"state",
".",
"get",
"(",
"\"value\"",
")",
"self",
".",
"_unit",
"=",
"state",
".",
"get",
"(",
"\"unit\"",
")"
] | [
270,
4
] | [
274,
38
] | python | en | ['en', 'en', 'en'] | True |
FroniusTemplateSensor.async_added_to_hass | (self) | Register at parent component for updates. | Register at parent component for updates. | async def async_added_to_hass(self):
"""Register at parent component for updates."""
await self.parent.register(self) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"await",
"self",
".",
"parent",
".",
"register",
"(",
"self",
")"
] | [
276,
4
] | [
278,
40
] | python | da | ['da', 'da', 'en'] | True |
FroniusTemplateSensor.__hash__ | (self) | Hash sensor by hashing its name. | Hash sensor by hashing its name. | def __hash__(self):
"""Hash sensor by hashing its name."""
return hash(self.name) | [
"def",
"__hash__",
"(",
"self",
")",
":",
"return",
"hash",
"(",
"self",
".",
"name",
")"
] | [
280,
4
] | [
282,
30
] | python | en | ['en', 'zh-Latn', 'en'] | True |
async_see | (
hass: HomeAssistantType,
mac: str = None,
dev_id: str = None,
host_name: str = None,
location_name: str = None,
gps: GPSType = None,
gps_accuracy=None,
battery: int = None,
attributes: dict = None,
) | Call service to notify you see device. | Call service to notify you see device. | def async_see(
hass: HomeAssistantType,
mac: str = None,
dev_id: str = None,
host_name: str = None,
location_name: str = None,
gps: GPSType = None,
gps_accuracy=None,
battery: int = None,
attributes: dict = None,
):
"""Call service to notify you see device."""
data = {
key: value
for key, value in (
(ATTR_MAC, mac),
(ATTR_DEV_ID, dev_id),
(ATTR_HOST_NAME, host_name),
(ATTR_LOCATION_NAME, location_name),
(ATTR_GPS, gps),
(ATTR_GPS_ACCURACY, gps_accuracy),
(ATTR_BATTERY, battery),
)
if value is not None
}
if attributes:
data[ATTR_ATTRIBUTES] = attributes
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SEE, data)) | [
"def",
"async_see",
"(",
"hass",
":",
"HomeAssistantType",
",",
"mac",
":",
"str",
"=",
"None",
",",
"dev_id",
":",
"str",
"=",
"None",
",",
"host_name",
":",
"str",
"=",
"None",
",",
"location_name",
":",
"str",
"=",
"None",
",",
"gps",
":",
"GPSType",
"=",
"None",
",",
"gps_accuracy",
"=",
"None",
",",
"battery",
":",
"int",
"=",
"None",
",",
"attributes",
":",
"dict",
"=",
"None",
",",
")",
":",
"data",
"=",
"{",
"key",
":",
"value",
"for",
"key",
",",
"value",
"in",
"(",
"(",
"ATTR_MAC",
",",
"mac",
")",
",",
"(",
"ATTR_DEV_ID",
",",
"dev_id",
")",
",",
"(",
"ATTR_HOST_NAME",
",",
"host_name",
")",
",",
"(",
"ATTR_LOCATION_NAME",
",",
"location_name",
")",
",",
"(",
"ATTR_GPS",
",",
"gps",
")",
",",
"(",
"ATTR_GPS_ACCURACY",
",",
"gps_accuracy",
")",
",",
"(",
"ATTR_BATTERY",
",",
"battery",
")",
",",
")",
"if",
"value",
"is",
"not",
"None",
"}",
"if",
"attributes",
":",
"data",
"[",
"ATTR_ATTRIBUTES",
"]",
"=",
"attributes",
"hass",
".",
"async_add_job",
"(",
"hass",
".",
"services",
".",
"async_call",
"(",
"DOMAIN",
",",
"SERVICE_SEE",
",",
"data",
")",
")"
] | [
24,
0
] | [
51,
75
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the binary sensors from a config entry. | Set up the binary sensors from a config entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the binary sensors from a config entry."""
board_api = hass.data[DOMAIN][config_entry.entry_id]
input_count = config_entry.data["input_count"]
binary_sensors = []
async def async_update_data():
"""Fetch data from API endpoint of board."""
async with async_timeout.timeout(5):
return await board_api.get_inputs()
coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
name="binary_sensor",
update_method=async_update_data,
update_interval=timedelta(seconds=DEFAULT_POLLING_INTERVAL_SEC),
)
await coordinator.async_refresh()
for i in range(1, int(input_count) + 1):
binary_sensors.append(
ProgettihwswBinarySensor(
coordinator,
f"Input #{i}",
setup_input(board_api, i),
)
)
async_add_entities(binary_sensors) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"board_api",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"input_count",
"=",
"config_entry",
".",
"data",
"[",
"\"input_count\"",
"]",
"binary_sensors",
"=",
"[",
"]",
"async",
"def",
"async_update_data",
"(",
")",
":",
"\"\"\"Fetch data from API endpoint of board.\"\"\"",
"async",
"with",
"async_timeout",
".",
"timeout",
"(",
"5",
")",
":",
"return",
"await",
"board_api",
".",
"get_inputs",
"(",
")",
"coordinator",
"=",
"DataUpdateCoordinator",
"(",
"hass",
",",
"_LOGGER",
",",
"name",
"=",
"\"binary_sensor\"",
",",
"update_method",
"=",
"async_update_data",
",",
"update_interval",
"=",
"timedelta",
"(",
"seconds",
"=",
"DEFAULT_POLLING_INTERVAL_SEC",
")",
",",
")",
"await",
"coordinator",
".",
"async_refresh",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"int",
"(",
"input_count",
")",
"+",
"1",
")",
":",
"binary_sensors",
".",
"append",
"(",
"ProgettihwswBinarySensor",
"(",
"coordinator",
",",
"f\"Input #{i}\"",
",",
"setup_input",
"(",
"board_api",
",",
"i",
")",
",",
")",
")",
"async_add_entities",
"(",
"binary_sensors",
")"
] | [
20,
0
] | [
49,
38
] | python | en | ['en', 'en', 'en'] | True |
ProgettihwswBinarySensor.__init__ | (self, coordinator, name, sensor: Input) | Set initializing values. | Set initializing values. | def __init__(self, coordinator, name, sensor: Input):
"""Set initializing values."""
super().__init__(coordinator)
self._name = name
self._sensor = sensor | [
"def",
"__init__",
"(",
"self",
",",
"coordinator",
",",
"name",
",",
"sensor",
":",
"Input",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_sensor",
"=",
"sensor"
] | [
55,
4
] | [
59,
29
] | python | en | ['nl', 'zu', 'en'] | False |
ProgettihwswBinarySensor.name | (self) | Return the sensor name. | Return the sensor name. | def name(self):
"""Return the sensor name."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
62,
4
] | [
64,
25
] | python | en | ['en', 'mi', 'en'] | True |
ProgettihwswBinarySensor.is_on | (self) | Get sensor state. | Get sensor state. | def is_on(self):
"""Get sensor state."""
return self.coordinator.data[self._sensor.id] | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
"[",
"self",
".",
"_sensor",
".",
"id",
"]"
] | [
67,
4
] | [
69,
53
] | python | en | ['en', 'bs', 'en'] | True |
async_extract_config | (hass, config) | Extract device tracker config and split between legacy and modern. | Extract device tracker config and split between legacy and modern. | async def async_extract_config(hass, config):
"""Extract device tracker config and split between legacy and modern."""
legacy = []
for platform in await asyncio.gather(
*(
async_create_platform_type(hass, config, p_type, p_config)
for p_type, p_config in config_per_platform(config, DOMAIN)
)
):
if platform is None:
continue
if platform.type == PLATFORM_TYPE_LEGACY:
legacy.append(platform)
else:
raise ValueError(
f"Unable to determine type for {platform.name}: {platform.type}"
)
return legacy | [
"async",
"def",
"async_extract_config",
"(",
"hass",
",",
"config",
")",
":",
"legacy",
"=",
"[",
"]",
"for",
"platform",
"in",
"await",
"asyncio",
".",
"gather",
"(",
"*",
"(",
"async_create_platform_type",
"(",
"hass",
",",
"config",
",",
"p_type",
",",
"p_config",
")",
"for",
"p_type",
",",
"p_config",
"in",
"config_per_platform",
"(",
"config",
",",
"DOMAIN",
")",
")",
")",
":",
"if",
"platform",
"is",
"None",
":",
"continue",
"if",
"platform",
".",
"type",
"==",
"PLATFORM_TYPE_LEGACY",
":",
"legacy",
".",
"append",
"(",
"platform",
")",
"else",
":",
"raise",
"ValueError",
"(",
"f\"Unable to determine type for {platform.name}: {platform.type}\"",
")",
"return",
"legacy"
] | [
94,
0
] | [
114,
17
] | python | en | ['en', 'en', 'en'] | True |
async_create_platform_type | (
hass, config, p_type, p_config
) | Determine type of platform. | Determine type of platform. | async def async_create_platform_type(
hass, config, p_type, p_config
) -> Optional[DeviceTrackerPlatform]:
"""Determine type of platform."""
platform = await async_prepare_setup_platform(hass, config, DOMAIN, p_type)
if platform is None:
return None
return DeviceTrackerPlatform(p_type, platform, p_config) | [
"async",
"def",
"async_create_platform_type",
"(",
"hass",
",",
"config",
",",
"p_type",
",",
"p_config",
")",
"->",
"Optional",
"[",
"DeviceTrackerPlatform",
"]",
":",
"platform",
"=",
"await",
"async_prepare_setup_platform",
"(",
"hass",
",",
"config",
",",
"DOMAIN",
",",
"p_type",
")",
"if",
"platform",
"is",
"None",
":",
"return",
"None",
"return",
"DeviceTrackerPlatform",
"(",
"p_type",
",",
"platform",
",",
"p_config",
")"
] | [
117,
0
] | [
126,
60
] | python | en | ['en', 'de', 'en'] | True |
async_setup_scanner_platform | (
hass: HomeAssistantType,
config: ConfigType,
scanner: Any,
async_see_device: Callable,
platform: str,
) | Set up the connect scanner-based platform to device tracker.
This method must be run in the event loop.
| Set up the connect scanner-based platform to device tracker. | def async_setup_scanner_platform(
hass: HomeAssistantType,
config: ConfigType,
scanner: Any,
async_see_device: Callable,
platform: str,
):
"""Set up the connect scanner-based platform to device tracker.
This method must be run in the event loop.
"""
interval = config.get(CONF_SCAN_INTERVAL, SCAN_INTERVAL)
update_lock = asyncio.Lock()
scanner.hass = hass
# Initial scan of each mac we also tell about host name for config
seen: Any = set()
async def async_device_tracker_scan(now: dt_util.dt.datetime):
"""Handle interval matches."""
if update_lock.locked():
LOGGER.warning(
"Updating device list from %s took longer than the scheduled "
"scan interval %s",
platform,
interval,
)
return
async with update_lock:
found_devices = await scanner.async_scan_devices()
for mac in found_devices:
if mac in seen:
host_name = None
else:
host_name = await scanner.async_get_device_name(mac)
seen.add(mac)
try:
extra_attributes = await scanner.async_get_extra_attributes(mac)
except NotImplementedError:
extra_attributes = {}
kwargs = {
"mac": mac,
"host_name": host_name,
"source_type": SOURCE_TYPE_ROUTER,
"attributes": {
"scanner": scanner.__class__.__name__,
**extra_attributes,
},
}
zone_home = hass.states.get(hass.components.zone.ENTITY_ID_HOME)
if zone_home:
kwargs["gps"] = [
zone_home.attributes[ATTR_LATITUDE],
zone_home.attributes[ATTR_LONGITUDE],
]
kwargs["gps_accuracy"] = 0
hass.async_create_task(async_see_device(**kwargs))
async_track_time_interval(hass, async_device_tracker_scan, interval)
hass.async_create_task(async_device_tracker_scan(None)) | [
"def",
"async_setup_scanner_platform",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"ConfigType",
",",
"scanner",
":",
"Any",
",",
"async_see_device",
":",
"Callable",
",",
"platform",
":",
"str",
",",
")",
":",
"interval",
"=",
"config",
".",
"get",
"(",
"CONF_SCAN_INTERVAL",
",",
"SCAN_INTERVAL",
")",
"update_lock",
"=",
"asyncio",
".",
"Lock",
"(",
")",
"scanner",
".",
"hass",
"=",
"hass",
"# Initial scan of each mac we also tell about host name for config",
"seen",
":",
"Any",
"=",
"set",
"(",
")",
"async",
"def",
"async_device_tracker_scan",
"(",
"now",
":",
"dt_util",
".",
"dt",
".",
"datetime",
")",
":",
"\"\"\"Handle interval matches.\"\"\"",
"if",
"update_lock",
".",
"locked",
"(",
")",
":",
"LOGGER",
".",
"warning",
"(",
"\"Updating device list from %s took longer than the scheduled \"",
"\"scan interval %s\"",
",",
"platform",
",",
"interval",
",",
")",
"return",
"async",
"with",
"update_lock",
":",
"found_devices",
"=",
"await",
"scanner",
".",
"async_scan_devices",
"(",
")",
"for",
"mac",
"in",
"found_devices",
":",
"if",
"mac",
"in",
"seen",
":",
"host_name",
"=",
"None",
"else",
":",
"host_name",
"=",
"await",
"scanner",
".",
"async_get_device_name",
"(",
"mac",
")",
"seen",
".",
"add",
"(",
"mac",
")",
"try",
":",
"extra_attributes",
"=",
"await",
"scanner",
".",
"async_get_extra_attributes",
"(",
"mac",
")",
"except",
"NotImplementedError",
":",
"extra_attributes",
"=",
"{",
"}",
"kwargs",
"=",
"{",
"\"mac\"",
":",
"mac",
",",
"\"host_name\"",
":",
"host_name",
",",
"\"source_type\"",
":",
"SOURCE_TYPE_ROUTER",
",",
"\"attributes\"",
":",
"{",
"\"scanner\"",
":",
"scanner",
".",
"__class__",
".",
"__name__",
",",
"*",
"*",
"extra_attributes",
",",
"}",
",",
"}",
"zone_home",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"hass",
".",
"components",
".",
"zone",
".",
"ENTITY_ID_HOME",
")",
"if",
"zone_home",
":",
"kwargs",
"[",
"\"gps\"",
"]",
"=",
"[",
"zone_home",
".",
"attributes",
"[",
"ATTR_LATITUDE",
"]",
",",
"zone_home",
".",
"attributes",
"[",
"ATTR_LONGITUDE",
"]",
",",
"]",
"kwargs",
"[",
"\"gps_accuracy\"",
"]",
"=",
"0",
"hass",
".",
"async_create_task",
"(",
"async_see_device",
"(",
"*",
"*",
"kwargs",
")",
")",
"async_track_time_interval",
"(",
"hass",
",",
"async_device_tracker_scan",
",",
"interval",
")",
"hass",
".",
"async_create_task",
"(",
"async_device_tracker_scan",
"(",
"None",
")",
")"
] | [
130,
0
] | [
195,
59
] | python | en | ['en', 'en', 'en'] | True |
problem3_3 | (month, day, year) | Takes date of form mm/dd/yyyy and writes it in form June 17, 2016
Example3_3: problem3_3(6, 17, 2016) gives June 17, 2016 | Takes date of form mm/dd/yyyy and writes it in form June 17, 2016
Example3_3: problem3_3(6, 17, 2016) gives June 17, 2016 | def problem3_3(month, day, year):
""" Takes date of form mm/dd/yyyy and writes it in form June 17, 2016
Example3_3: problem3_3(6, 17, 2016) gives June 17, 2016 """
mappping = {1:'January',
2:"Febuary",
3:"March",
4:"April",
5:"May",
6:"June",
7:"July",
8:"August",
9:"September",
10:"October",
11:"November",
12:"December"
}
print('{} {}, {}'.format(mappping[month], day, year)) | [
"def",
"problem3_3",
"(",
"month",
",",
"day",
",",
"year",
")",
":",
"mappping",
"=",
"{",
"1",
":",
"'January'",
",",
"2",
":",
"\"Febuary\"",
",",
"3",
":",
"\"March\"",
",",
"4",
":",
"\"April\"",
",",
"5",
":",
"\"May\"",
",",
"6",
":",
"\"June\"",
",",
"7",
":",
"\"July\"",
",",
"8",
":",
"\"August\"",
",",
"9",
":",
"\"September\"",
",",
"10",
":",
"\"October\"",
",",
"11",
":",
"\"November\"",
",",
"12",
":",
"\"December\"",
"}",
"print",
"(",
"'{} {}, {}'",
".",
"format",
"(",
"mappping",
"[",
"month",
"]",
",",
"day",
",",
"year",
")",
")"
] | [
24,
0
] | [
40,
57
] | python | en | ['en', 'en', 'en'] | True |
test_reproduce_group | (hass) | Test reproduce_state with group. | Test reproduce_state with group. | async def test_reproduce_group(hass):
"""Test reproduce_state with group."""
context = Context()
def clone_state(state, entity_id):
"""Return a cloned state with different entity_id."""
return State(
entity_id,
state.state,
state.attributes,
last_changed=state.last_changed,
last_updated=state.last_updated,
context=state.context,
)
with patch(
"homeassistant.components.group.reproduce_state.async_reproduce_state"
) as fun:
fun.return_value = Future()
fun.return_value.set_result(None)
hass.states.async_set(
"group.test",
"off",
{"entity_id": ["light.test1", "light.test2", "switch.test1"]},
)
hass.states.async_set("light.test1", "off")
hass.states.async_set("light.test2", "off")
hass.states.async_set("switch.test1", "off")
state = State("group.test", "on")
await async_reproduce_states(hass, [state], context=context)
fun.assert_called_once_with(
hass,
[
clone_state(state, "light.test1"),
clone_state(state, "light.test2"),
clone_state(state, "switch.test1"),
],
context=context,
reproduce_options=None,
) | [
"async",
"def",
"test_reproduce_group",
"(",
"hass",
")",
":",
"context",
"=",
"Context",
"(",
")",
"def",
"clone_state",
"(",
"state",
",",
"entity_id",
")",
":",
"\"\"\"Return a cloned state with different entity_id.\"\"\"",
"return",
"State",
"(",
"entity_id",
",",
"state",
".",
"state",
",",
"state",
".",
"attributes",
",",
"last_changed",
"=",
"state",
".",
"last_changed",
",",
"last_updated",
"=",
"state",
".",
"last_updated",
",",
"context",
"=",
"state",
".",
"context",
",",
")",
"with",
"patch",
"(",
"\"homeassistant.components.group.reproduce_state.async_reproduce_state\"",
")",
"as",
"fun",
":",
"fun",
".",
"return_value",
"=",
"Future",
"(",
")",
"fun",
".",
"return_value",
".",
"set_result",
"(",
"None",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"group.test\"",
",",
"\"off\"",
",",
"{",
"\"entity_id\"",
":",
"[",
"\"light.test1\"",
",",
"\"light.test2\"",
",",
"\"switch.test1\"",
"]",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.test1\"",
",",
"\"off\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.test2\"",
",",
"\"off\"",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"switch.test1\"",
",",
"\"off\"",
")",
"state",
"=",
"State",
"(",
"\"group.test\"",
",",
"\"on\"",
")",
"await",
"async_reproduce_states",
"(",
"hass",
",",
"[",
"state",
"]",
",",
"context",
"=",
"context",
")",
"fun",
".",
"assert_called_once_with",
"(",
"hass",
",",
"[",
"clone_state",
"(",
"state",
",",
"\"light.test1\"",
")",
",",
"clone_state",
"(",
"state",
",",
"\"light.test2\"",
")",
",",
"clone_state",
"(",
"state",
",",
"\"switch.test1\"",
")",
",",
"]",
",",
"context",
"=",
"context",
",",
"reproduce_options",
"=",
"None",
",",
")"
] | [
10,
0
] | [
53,
9
] | python | en | ['en', 'en', 'en'] | True |
suggest_recipe | (query) |
Quick wrapper for KNNRecommender.recommend()
:param query:
:return:
|
Quick wrapper for KNNRecommender.recommend()
:param query:
:return:
| def suggest_recipe(query):
"""
Quick wrapper for KNNRecommender.recommend()
:param query:
:return:
"""
corpus = HTMLPickledCorpusReader('../mini_food_corpus_proc')
docs = list(corpus.docs())
titles = list(corpus.titles())
tree = BallTreeRecommender(k=3)
tree.fit_transform(docs)
results = tree.query(query)
return [titles[result] for result in results] | [
"def",
"suggest_recipe",
"(",
"query",
")",
":",
"corpus",
"=",
"HTMLPickledCorpusReader",
"(",
"'../mini_food_corpus_proc'",
")",
"docs",
"=",
"list",
"(",
"corpus",
".",
"docs",
"(",
")",
")",
"titles",
"=",
"list",
"(",
"corpus",
".",
"titles",
"(",
")",
")",
"tree",
"=",
"BallTreeRecommender",
"(",
"k",
"=",
"3",
")",
"tree",
".",
"fit_transform",
"(",
"docs",
")",
"results",
"=",
"tree",
".",
"query",
"(",
"query",
")",
"return",
"[",
"titles",
"[",
"result",
"]",
"for",
"result",
"in",
"results",
"]"
] | [
210,
0
] | [
222,
49
] | python | en | ['en', 'error', 'th'] | False |
KNNTransformer.__init__ | (self, k=3, **kwargs) |
Note: tried LSHForest, still too slow
:param k:
:param kwargs:
|
Note: tried LSHForest, still too slow
:param k:
:param kwargs:
| def __init__(self, k=3, **kwargs):
"""
Note: tried LSHForest, still too slow
:param k:
:param kwargs:
"""
self.model = NearestNeighbors(n_neighbors=k, **kwargs) | [
"def",
"__init__",
"(",
"self",
",",
"k",
"=",
"3",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"model",
"=",
"NearestNeighbors",
"(",
"n_neighbors",
"=",
"k",
",",
"*",
"*",
"kwargs",
")"
] | [
26,
4
] | [
32,
62
] | python | en | ['en', 'error', 'th'] | False |
KNNRecommender.load | (self) |
Load a pickled vectorizer and vectorized corpus from disk,
if they exist.
|
Load a pickled vectorizer and vectorized corpus from disk,
if they exist.
| def load(self):
"""
Load a pickled vectorizer and vectorized corpus from disk,
if they exist.
"""
if os.path.exists(self.vect_path):
joblib.load(open(self.vect_path, 'rb'))
joblib.load(open(self.lex_path, 'rb'))
else:
self.vectorizer = False
self.lexicon = None | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"vect_path",
")",
":",
"joblib",
".",
"load",
"(",
"open",
"(",
"self",
".",
"vect_path",
",",
"'rb'",
")",
")",
"joblib",
".",
"load",
"(",
"open",
"(",
"self",
".",
"lex_path",
",",
"'rb'",
")",
")",
"else",
":",
"self",
".",
"vectorizer",
"=",
"False",
"self",
".",
"lexicon",
"=",
"None"
] | [
95,
4
] | [
105,
31
] | python | en | ['en', 'error', 'th'] | False |
KNNRecommender.save | (self) |
It takes a long time to fit, so just do it once!
|
It takes a long time to fit, so just do it once!
| def save(self):
"""
It takes a long time to fit, so just do it once!
"""
joblib.dump(self.vect, open(self.vect_path, 'wb'))
joblib.dump(self.lexicon, open(self.lex_path, 'wb')) | [
"def",
"save",
"(",
"self",
")",
":",
"joblib",
".",
"dump",
"(",
"self",
".",
"vect",
",",
"open",
"(",
"self",
".",
"vect_path",
",",
"'wb'",
")",
")",
"joblib",
".",
"dump",
"(",
"self",
".",
"lexicon",
",",
"open",
"(",
"self",
".",
"lex_path",
",",
"'wb'",
")",
")"
] | [
107,
4
] | [
112,
60
] | python | en | ['en', 'error', 'th'] | False |
KNNRecommender.recommend | (self, terms) |
Given input list of ingredient terms,
return the k closest matching recipes.
:param terms: list of strings
:return: list of document indices of documents
|
Given input list of ingredient terms,
return the k closest matching recipes. | def recommend(self, terms):
"""
Given input list of ingredient terms,
return the k closest matching recipes.
:param terms: list of strings
:return: list of document indices of documents
"""
vect_doc = self.vect.transform(wordpunct_tokenize(terms))
distance_matches = self.knn.transform(vect_doc)
# the result is a list with a 2-tuple of arrays
matches = distance_matches[0][1][0]
# the matches are the indices of documents
return matches | [
"def",
"recommend",
"(",
"self",
",",
"terms",
")",
":",
"vect_doc",
"=",
"self",
".",
"vect",
".",
"transform",
"(",
"wordpunct_tokenize",
"(",
"terms",
")",
")",
"distance_matches",
"=",
"self",
".",
"knn",
".",
"transform",
"(",
"vect_doc",
")",
"# the result is a list with a 2-tuple of arrays",
"matches",
"=",
"distance_matches",
"[",
"0",
"]",
"[",
"1",
"]",
"[",
"0",
"]",
"# the matches are the indices of documents",
"return",
"matches"
] | [
132,
4
] | [
145,
22
] | python | en | ['en', 'error', 'th'] | False |
BallTreeRecommender.load | (self) |
Load a pickled transformer and tree from disk,
if they exist.
|
Load a pickled transformer and tree from disk,
if they exist.
| def load(self):
"""
Load a pickled transformer and tree from disk,
if they exist.
"""
if os.path.exists(self.trans_path):
self.transformer = joblib.load(open(self.trans_path, 'rb'))
self.tree = joblib.load(open(self.tree_path, 'rb'))
else:
self.transformer = False
self.tree = None | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"trans_path",
")",
":",
"self",
".",
"transformer",
"=",
"joblib",
".",
"load",
"(",
"open",
"(",
"self",
".",
"trans_path",
",",
"'rb'",
")",
")",
"self",
".",
"tree",
"=",
"joblib",
".",
"load",
"(",
"open",
"(",
"self",
".",
"tree_path",
",",
"'rb'",
")",
")",
"else",
":",
"self",
".",
"transformer",
"=",
"False",
"self",
".",
"tree",
"=",
"None"
] | [
160,
4
] | [
170,
28
] | python | en | ['en', 'error', 'th'] | False |
BallTreeRecommender.save | (self) |
It takes a long time to fit, so just do it once!
|
It takes a long time to fit, so just do it once!
| def save(self):
"""
It takes a long time to fit, so just do it once!
"""
joblib.dump(self.transformer, open(self.trans_path, 'wb'))
joblib.dump(self.tree, open(self.tree_path, 'wb')) | [
"def",
"save",
"(",
"self",
")",
":",
"joblib",
".",
"dump",
"(",
"self",
".",
"transformer",
",",
"open",
"(",
"self",
".",
"trans_path",
",",
"'wb'",
")",
")",
"joblib",
".",
"dump",
"(",
"self",
".",
"tree",
",",
"open",
"(",
"self",
".",
"tree_path",
",",
"'wb'",
")",
")"
] | [
172,
4
] | [
177,
58
] | python | en | ['en', 'error', 'th'] | False |
BallTreeRecommender.query | (self, terms) |
Given input list of ingredient terms,
return the k closest matching recipes.
:param terms: list of strings
:return: list of document indices of documents
|
Given input list of ingredient terms,
return the k closest matching recipes. | def query(self, terms):
"""
Given input list of ingredient terms,
return the k closest matching recipes.
:param terms: list of strings
:return: list of document indices of documents
"""
vect_doc = self.transformer.named_steps['transform'].fit_transform(
wordpunct_tokenize(terms)
)
dists, inds = self.tree.query(vect_doc, k=self.k)
return inds[0] | [
"def",
"query",
"(",
"self",
",",
"terms",
")",
":",
"vect_doc",
"=",
"self",
".",
"transformer",
".",
"named_steps",
"[",
"'transform'",
"]",
".",
"fit_transform",
"(",
"wordpunct_tokenize",
"(",
"terms",
")",
")",
"dists",
",",
"inds",
"=",
"self",
".",
"tree",
".",
"query",
"(",
"vect_doc",
",",
"k",
"=",
"self",
".",
"k",
")",
"return",
"inds",
"[",
"0",
"]"
] | [
195,
4
] | [
207,
22
] | python | en | ['en', 'error', 'th'] | False |
async_setup_entry | (
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
) | Set up the sensor config entry. | Set up the sensor config entry. | async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: Callable[[List[Entity], bool], None],
) -> None:
"""Set up the sensor config entry."""
entities = await async_create_entities(
hass, entry, WithingsHealthBinarySensor, BINARY_SENSOR_DOMAIN
)
async_add_entities(entities, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistant",
",",
"entry",
":",
"ConfigEntry",
",",
"async_add_entities",
":",
"Callable",
"[",
"[",
"List",
"[",
"Entity",
"]",
",",
"bool",
"]",
",",
"None",
"]",
",",
")",
"->",
"None",
":",
"entities",
"=",
"await",
"async_create_entities",
"(",
"hass",
",",
"entry",
",",
"WithingsHealthBinarySensor",
",",
"BINARY_SENSOR_DOMAIN",
")",
"async_add_entities",
"(",
"entities",
",",
"True",
")"
] | [
15,
0
] | [
25,
38
] | python | en | ['en', 'pt', 'en'] | True |
WithingsHealthBinarySensor.is_on | (self) | Return true if the binary sensor is on. | Return true if the binary sensor is on. | def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return self._state_data | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_state_data"
] | [
32,
4
] | [
34,
31
] | python | en | ['en', 'fy', 'en'] | True |
WithingsHealthBinarySensor.device_class | (self) | Provide the device class. | Provide the device class. | def device_class(self) -> str:
"""Provide the device class."""
return DEVICE_CLASS_OCCUPANCY | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_OCCUPANCY"
] | [
37,
4
] | [
39,
37
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_no_domain_config | (hass: HomeAssistant) | Test setup without configuration is noop. | Test setup without configuration is noop. | async def test_async_setup_no_domain_config(hass: HomeAssistant):
"""Test setup without configuration is noop."""
result = await async_setup_component(hass, DOMAIN, {})
assert result is True
assert DOMAIN not in hass.data | [
"async",
"def",
"test_async_setup_no_domain_config",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"result",
"=",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"}",
")",
"assert",
"result",
"is",
"True",
"assert",
"DOMAIN",
"not",
"in",
"hass",
".",
"data"
] | [
12,
0
] | [
17,
34
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_imports_from_config | (hass: HomeAssistant) | Test that specifying config will setup an entry. | Test that specifying config will setup an entry. | async def test_async_setup_imports_from_config(hass: HomeAssistant):
"""Test that specifying config will setup an entry."""
with patch(
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
) as mock_loadCloudData, patch(
"homeassistant.components.plum_lightpad.async_setup_entry",
return_value=True,
) as mock_async_setup_entry:
result = await async_setup_component(
hass,
DOMAIN,
{
DOMAIN: {
"username": "test-plum-username",
"password": "test-plum-password",
}
},
)
await hass.async_block_till_done()
assert result is True
assert len(mock_loadCloudData.mock_calls) == 1
assert len(mock_async_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_async_setup_imports_from_config",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData\"",
")",
"as",
"mock_loadCloudData",
",",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.async_setup_entry\"",
",",
"return_value",
"=",
"True",
",",
")",
"as",
"mock_async_setup_entry",
":",
"result",
"=",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"\"username\"",
":",
"\"test-plum-username\"",
",",
"\"password\"",
":",
"\"test-plum-password\"",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result",
"is",
"True",
"assert",
"len",
"(",
"mock_loadCloudData",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_async_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
20,
0
] | [
42,
54
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry_sets_up_light | (hass: HomeAssistant) | Test that configuring entry sets up light domain. | Test that configuring entry sets up light domain. | async def test_async_setup_entry_sets_up_light(hass: HomeAssistant):
"""Test that configuring entry sets up light domain."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"username": "test-plum-username", "password": "test-plum-password"},
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData"
) as mock_loadCloudData, patch(
"homeassistant.components.plum_lightpad.light.async_setup_entry"
) as mock_light_async_setup_entry:
result = await hass.config_entries.async_setup(config_entry.entry_id)
assert result is True
await hass.async_block_till_done()
assert len(mock_loadCloudData.mock_calls) == 1
assert len(mock_light_async_setup_entry.mock_calls) == 1 | [
"async",
"def",
"test_async_setup_entry_sets_up_light",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"\"username\"",
":",
"\"test-plum-username\"",
",",
"\"password\"",
":",
"\"test-plum-password\"",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData\"",
")",
"as",
"mock_loadCloudData",
",",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.light.async_setup_entry\"",
")",
"as",
"mock_light_async_setup_entry",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"is",
"True",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"mock_loadCloudData",
".",
"mock_calls",
")",
"==",
"1",
"assert",
"len",
"(",
"mock_light_async_setup_entry",
".",
"mock_calls",
")",
"==",
"1"
] | [
45,
0
] | [
64,
60
] | python | en | ['en', 'en', 'en'] | True |
test_async_setup_entry_handles_auth_error | (hass: HomeAssistant) | Test that configuring entry handles Plum Cloud authentication error. | Test that configuring entry handles Plum Cloud authentication error. | async def test_async_setup_entry_handles_auth_error(hass: HomeAssistant):
"""Test that configuring entry handles Plum Cloud authentication error."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"username": "test-plum-username", "password": "test-plum-password"},
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData",
side_effect=ContentTypeError(Mock(), None),
), patch(
"homeassistant.components.plum_lightpad.light.async_setup_entry"
) as mock_light_async_setup_entry:
result = await hass.config_entries.async_setup(config_entry.entry_id)
assert result is False
assert len(mock_light_async_setup_entry.mock_calls) == 0 | [
"async",
"def",
"test_async_setup_entry_handles_auth_error",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"\"username\"",
":",
"\"test-plum-username\"",
",",
"\"password\"",
":",
"\"test-plum-password\"",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData\"",
",",
"side_effect",
"=",
"ContentTypeError",
"(",
"Mock",
"(",
")",
",",
"None",
")",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.light.async_setup_entry\"",
")",
"as",
"mock_light_async_setup_entry",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"is",
"False",
"assert",
"len",
"(",
"mock_light_async_setup_entry",
".",
"mock_calls",
")",
"==",
"0"
] | [
67,
0
] | [
84,
60
] | python | en | ['en', 'fr', 'en'] | True |
test_async_setup_entry_handles_http_error | (hass: HomeAssistant) | Test that configuring entry handles HTTP error. | Test that configuring entry handles HTTP error. | async def test_async_setup_entry_handles_http_error(hass: HomeAssistant):
"""Test that configuring entry handles HTTP error."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data={"username": "test-plum-username", "password": "test-plum-password"},
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData",
side_effect=HTTPError,
), patch(
"homeassistant.components.plum_lightpad.light.async_setup_entry"
) as mock_light_async_setup_entry:
result = await hass.config_entries.async_setup(config_entry.entry_id)
assert result is False
assert len(mock_light_async_setup_entry.mock_calls) == 0 | [
"async",
"def",
"test_async_setup_entry_handles_http_error",
"(",
"hass",
":",
"HomeAssistant",
")",
":",
"config_entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"\"username\"",
":",
"\"test-plum-username\"",
",",
"\"password\"",
":",
"\"test-plum-password\"",
"}",
",",
")",
"config_entry",
".",
"add_to_hass",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.utils.Plum.loadCloudData\"",
",",
"side_effect",
"=",
"HTTPError",
",",
")",
",",
"patch",
"(",
"\"homeassistant.components.plum_lightpad.light.async_setup_entry\"",
")",
"as",
"mock_light_async_setup_entry",
":",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"config_entry",
".",
"entry_id",
")",
"assert",
"result",
"is",
"False",
"assert",
"len",
"(",
"mock_light_async_setup_entry",
".",
"mock_calls",
")",
"==",
"0"
] | [
87,
0
] | [
104,
60
] | python | en | ['en', 'en', 'en'] | True |
mock_hub | (config, response) | Extensively mock out a verisure hub. | Extensively mock out a verisure hub. | def mock_hub(config, response):
"""Extensively mock out a verisure hub."""
hub_prefix = "homeassistant.components.verisure.binary_sensor.hub"
verisure_prefix = "verisure.Session"
with patch(verisure_prefix) as session, patch(hub_prefix) as hub:
session.login.return_value = True
hub.config = config["verisure"]
hub.get.return_value = response
hub.get_first.return_value = response.get("ethernetConnectedNow", None)
yield hub | [
"def",
"mock_hub",
"(",
"config",
",",
"response",
")",
":",
"hub_prefix",
"=",
"\"homeassistant.components.verisure.binary_sensor.hub\"",
"verisure_prefix",
"=",
"\"verisure.Session\"",
"with",
"patch",
"(",
"verisure_prefix",
")",
"as",
"session",
",",
"patch",
"(",
"hub_prefix",
")",
"as",
"hub",
":",
"session",
".",
"login",
".",
"return_value",
"=",
"True",
"hub",
".",
"config",
"=",
"config",
"[",
"\"verisure\"",
"]",
"hub",
".",
"get",
".",
"return_value",
"=",
"response",
"hub",
".",
"get_first",
".",
"return_value",
"=",
"response",
".",
"get",
"(",
"\"ethernetConnectedNow\"",
",",
"None",
")",
"yield",
"hub"
] | [
25,
0
] | [
36,
17
] | python | en | ['en', 'en', 'en'] | True |
setup_verisure | (hass, config, response) | Set up mock verisure. | Set up mock verisure. | async def setup_verisure(hass, config, response):
"""Set up mock verisure."""
with mock_hub(config, response):
await async_setup_component(hass, VERISURE_DOMAIN, config)
await hass.async_block_till_done() | [
"async",
"def",
"setup_verisure",
"(",
"hass",
",",
"config",
",",
"response",
")",
":",
"with",
"mock_hub",
"(",
"config",
",",
"response",
")",
":",
"await",
"async_setup_component",
"(",
"hass",
",",
"VERISURE_DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
39,
0
] | [
43,
42
] | python | en | ['en', 'da', 'en'] | True |
test_verisure_no_ethernet_status | (hass) | Test no data from API. | Test no data from API. | async def test_verisure_no_ethernet_status(hass):
"""Test no data from API."""
await setup_verisure(hass, CONFIG, {})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE | [
"async",
"def",
"test_verisure_no_ethernet_status",
"(",
"hass",
")",
":",
"await",
"setup_verisure",
"(",
"hass",
",",
"CONFIG",
",",
"{",
"}",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"entity_id",
"=",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
")",
"[",
"0",
"]",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
46,
0
] | [
51,
64
] | python | en | ['en', 'en', 'en'] | True |
test_verisure_ethernet_status_disconnected | (hass) | Test disconnected. | Test disconnected. | async def test_verisure_ethernet_status_disconnected(hass):
"""Test disconnected."""
await setup_verisure(hass, CONFIG, {"ethernetConnectedNow": False})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == "off" | [
"async",
"def",
"test_verisure_ethernet_status_disconnected",
"(",
"hass",
")",
":",
"await",
"setup_verisure",
"(",
"hass",
",",
"CONFIG",
",",
"{",
"\"ethernetConnectedNow\"",
":",
"False",
"}",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"entity_id",
"=",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
")",
"[",
"0",
"]",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"==",
"\"off\""
] | [
54,
0
] | [
59,
52
] | python | en | ['fr', 'en', 'en'] | False |
test_verisure_ethernet_status_connected | (hass) | Test connected. | Test connected. | async def test_verisure_ethernet_status_connected(hass):
"""Test connected."""
await setup_verisure(hass, CONFIG, {"ethernetConnectedNow": True})
assert len(hass.states.async_all()) == 1
entity_id = hass.states.async_entity_ids()[0]
assert hass.states.get(entity_id).state == "on" | [
"async",
"def",
"test_verisure_ethernet_status_connected",
"(",
"hass",
")",
":",
"await",
"setup_verisure",
"(",
"hass",
",",
"CONFIG",
",",
"{",
"\"ethernetConnectedNow\"",
":",
"True",
"}",
")",
"assert",
"len",
"(",
"hass",
".",
"states",
".",
"async_all",
"(",
")",
")",
"==",
"1",
"entity_id",
"=",
"hass",
".",
"states",
".",
"async_entity_ids",
"(",
")",
"[",
"0",
"]",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"entity_id",
")",
".",
"state",
"==",
"\"on\""
] | [
62,
0
] | [
67,
51
] | python | en | ['en', 'en', 'en'] | False |
init | (empty=False) | Initialize the platform with entities. | Initialize the platform with entities. | def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
{}
if empty
else {
device_class: MockBinarySensor(
name=f"{device_class} sensor",
is_on=True,
unique_id=f"unique_{device_class}",
device_class=device_class,
)
for device_class in DEVICE_CLASSES
}
) | [
"def",
"init",
"(",
"empty",
"=",
"False",
")",
":",
"global",
"ENTITIES",
"ENTITIES",
"=",
"(",
"{",
"}",
"if",
"empty",
"else",
"{",
"device_class",
":",
"MockBinarySensor",
"(",
"name",
"=",
"f\"{device_class} sensor\"",
",",
"is_on",
"=",
"True",
",",
"unique_id",
"=",
"f\"unique_{device_class}\"",
",",
"device_class",
"=",
"device_class",
",",
")",
"for",
"device_class",
"in",
"DEVICE_CLASSES",
"}",
")"
] | [
12,
0
] | [
28,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (
hass, config, async_add_entities_callback, discovery_info=None
) | Return mock entities. | Return mock entities. | async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(list(ENTITIES.values())) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities_callback",
",",
"discovery_info",
"=",
"None",
")",
":",
"async_add_entities_callback",
"(",
"list",
"(",
"ENTITIES",
".",
"values",
"(",
")",
")",
")"
] | [
31,
0
] | [
35,
56
] | python | af | ['nl', 'af', 'en'] | False |
MockBinarySensor.is_on | (self) | Return true if the binary sensor is on. | Return true if the binary sensor is on. | def is_on(self):
"""Return true if the binary sensor is on."""
return self._handle("is_on") | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_handle",
"(",
"\"is_on\"",
")"
] | [
42,
4
] | [
44,
36
] | python | en | ['en', 'fy', 'en'] | True |
MockBinarySensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self):
"""Return the class of this sensor."""
return self._handle("device_class") | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_handle",
"(",
"\"device_class\"",
")"
] | [
47,
4
] | [
49,
43
] | python | en | ['en', 'en', 'en'] | True |
test_islamic_prayer_times_sensors | (hass, legacy_patchable_time) | Test minimum Islamic prayer times configuration. | Test minimum Islamic prayer times configuration. | async def test_islamic_prayer_times_sensors(hass, legacy_patchable_time):
"""Test minimum Islamic prayer times configuration."""
entry = MockConfigEntry(domain=islamic_prayer_times.DOMAIN, data={})
entry.add_to_hass(hass)
with patch(
"prayer_times_calculator.PrayerTimesCalculator.fetch_prayer_times",
return_value=PRAYER_TIMES,
), patch("homeassistant.util.dt.now", return_value=NOW):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
for prayer in PRAYER_TIMES:
assert (
hass.states.get(
f"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}"
).state
== PRAYER_TIMES_TIMESTAMPS[prayer].astimezone(dt_util.UTC).isoformat()
) | [
"async",
"def",
"test_islamic_prayer_times_sensors",
"(",
"hass",
",",
"legacy_patchable_time",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"islamic_prayer_times",
".",
"DOMAIN",
",",
"data",
"=",
"{",
"}",
")",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"with",
"patch",
"(",
"\"prayer_times_calculator.PrayerTimesCalculator.fetch_prayer_times\"",
",",
"return_value",
"=",
"PRAYER_TIMES",
",",
")",
",",
"patch",
"(",
"\"homeassistant.util.dt.now\"",
",",
"return_value",
"=",
"NOW",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"for",
"prayer",
"in",
"PRAYER_TIMES",
":",
"assert",
"(",
"hass",
".",
"states",
".",
"get",
"(",
"f\"sensor.{prayer}_{islamic_prayer_times.const.SENSOR_TYPES[prayer]}\"",
")",
".",
"state",
"==",
"PRAYER_TIMES_TIMESTAMPS",
"[",
"prayer",
"]",
".",
"astimezone",
"(",
"dt_util",
".",
"UTC",
")",
".",
"isoformat",
"(",
")",
")"
] | [
10,
0
] | [
28,
13
] | python | en | ['en', 'zh', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the FRITZ!Box monitor sensors. | Set up the FRITZ!Box monitor sensors. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the FRITZ!Box monitor sensors."""
name = config[CONF_NAME]
host = config[CONF_HOST]
try:
fstatus = FritzStatus(address=host)
except (ValueError, TypeError, FritzConnectionException):
fstatus = None
if fstatus is None:
_LOGGER.error("Failed to establish connection to FRITZ!Box: %s", host)
return 1
_LOGGER.info("Successfully connected to FRITZ!Box")
add_entities([FritzboxMonitorSensor(name, fstatus)], True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"host",
"=",
"config",
"[",
"CONF_HOST",
"]",
"try",
":",
"fstatus",
"=",
"FritzStatus",
"(",
"address",
"=",
"host",
")",
"except",
"(",
"ValueError",
",",
"TypeError",
",",
"FritzConnectionException",
")",
":",
"fstatus",
"=",
"None",
"if",
"fstatus",
"is",
"None",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to establish connection to FRITZ!Box: %s\"",
",",
"host",
")",
"return",
"1",
"_LOGGER",
".",
"info",
"(",
"\"Successfully connected to FRITZ!Box\"",
")",
"add_entities",
"(",
"[",
"FritzboxMonitorSensor",
"(",
"name",
",",
"fstatus",
")",
"]",
",",
"True",
")"
] | [
46,
0
] | [
61,
62
] | python | en | ['en', 'fil', 'en'] | True |
FritzboxMonitorSensor.__init__ | (self, name, fstatus) | Initialize the sensor. | Initialize the sensor. | def __init__(self, name, fstatus):
"""Initialize the sensor."""
self._name = name
self._fstatus = fstatus
self._state = STATE_UNAVAILABLE
self._is_linked = self._is_connected = None
self._external_ip = self._uptime = None
self._bytes_sent = self._bytes_received = None
self._transmission_rate_up = None
self._transmission_rate_down = None
self._max_byte_rate_up = self._max_byte_rate_down = None | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"fstatus",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_fstatus",
"=",
"fstatus",
"self",
".",
"_state",
"=",
"STATE_UNAVAILABLE",
"self",
".",
"_is_linked",
"=",
"self",
".",
"_is_connected",
"=",
"None",
"self",
".",
"_external_ip",
"=",
"self",
".",
"_uptime",
"=",
"None",
"self",
".",
"_bytes_sent",
"=",
"self",
".",
"_bytes_received",
"=",
"None",
"self",
".",
"_transmission_rate_up",
"=",
"None",
"self",
".",
"_transmission_rate_down",
"=",
"None",
"self",
".",
"_max_byte_rate_up",
"=",
"self",
".",
"_max_byte_rate_down",
"=",
"None"
] | [
67,
4
] | [
77,
64
] | python | en | ['en', 'en', 'en'] | True |
FritzboxMonitorSensor.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.rstrip() | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name",
".",
"rstrip",
"(",
")"
] | [
80,
4
] | [
82,
34
] | python | en | ['en', 'mi', 'en'] | True |
FritzboxMonitorSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
85,
4
] | [
87,
19
] | python | en | ['en', 'en', 'en'] | True |
FritzboxMonitorSensor.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"
] | [
90,
4
] | [
92,
26
] | python | en | ['en', 'en', 'en'] | True |
FritzboxMonitorSensor.state_attributes | (self) | Return the device state attributes. | Return the device state attributes. | def state_attributes(self):
"""Return the device state attributes."""
# Don't return attributes if FritzBox is unreachable
if self._state == STATE_UNAVAILABLE:
return {}
return {
ATTR_IS_LINKED: self._is_linked,
ATTR_IS_CONNECTED: self._is_connected,
ATTR_EXTERNAL_IP: self._external_ip,
ATTR_UPTIME: self._uptime,
ATTR_BYTES_SENT: self._bytes_sent,
ATTR_BYTES_RECEIVED: self._bytes_received,
ATTR_TRANSMISSION_RATE_UP: self._transmission_rate_up,
ATTR_TRANSMISSION_RATE_DOWN: self._transmission_rate_down,
ATTR_MAX_BYTE_RATE_UP: self._max_byte_rate_up,
ATTR_MAX_BYTE_RATE_DOWN: self._max_byte_rate_down,
} | [
"def",
"state_attributes",
"(",
"self",
")",
":",
"# Don't return attributes if FritzBox is unreachable",
"if",
"self",
".",
"_state",
"==",
"STATE_UNAVAILABLE",
":",
"return",
"{",
"}",
"return",
"{",
"ATTR_IS_LINKED",
":",
"self",
".",
"_is_linked",
",",
"ATTR_IS_CONNECTED",
":",
"self",
".",
"_is_connected",
",",
"ATTR_EXTERNAL_IP",
":",
"self",
".",
"_external_ip",
",",
"ATTR_UPTIME",
":",
"self",
".",
"_uptime",
",",
"ATTR_BYTES_SENT",
":",
"self",
".",
"_bytes_sent",
",",
"ATTR_BYTES_RECEIVED",
":",
"self",
".",
"_bytes_received",
",",
"ATTR_TRANSMISSION_RATE_UP",
":",
"self",
".",
"_transmission_rate_up",
",",
"ATTR_TRANSMISSION_RATE_DOWN",
":",
"self",
".",
"_transmission_rate_down",
",",
"ATTR_MAX_BYTE_RATE_UP",
":",
"self",
".",
"_max_byte_rate_up",
",",
"ATTR_MAX_BYTE_RATE_DOWN",
":",
"self",
".",
"_max_byte_rate_down",
",",
"}"
] | [
95,
4
] | [
111,
9
] | python | en | ['en', 'en', 'en'] | True |
FritzboxMonitorSensor.update | (self) | Retrieve information from the FritzBox. | Retrieve information from the FritzBox. | def update(self):
"""Retrieve information from the FritzBox."""
try:
self._is_linked = self._fstatus.is_linked
self._is_connected = self._fstatus.is_connected
self._external_ip = self._fstatus.external_ip
self._uptime = self._fstatus.uptime
self._bytes_sent = self._fstatus.bytes_sent
self._bytes_received = self._fstatus.bytes_received
transmission_rate = self._fstatus.transmission_rate
self._transmission_rate_up = transmission_rate[0]
self._transmission_rate_down = transmission_rate[1]
self._max_byte_rate_up = self._fstatus.max_byte_rate[0]
self._max_byte_rate_down = self._fstatus.max_byte_rate[1]
self._state = STATE_ONLINE if self._is_connected else STATE_OFFLINE
except RequestException as err:
self._state = STATE_UNAVAILABLE
_LOGGER.warning("Could not reach FRITZ!Box: %s", err) | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_is_linked",
"=",
"self",
".",
"_fstatus",
".",
"is_linked",
"self",
".",
"_is_connected",
"=",
"self",
".",
"_fstatus",
".",
"is_connected",
"self",
".",
"_external_ip",
"=",
"self",
".",
"_fstatus",
".",
"external_ip",
"self",
".",
"_uptime",
"=",
"self",
".",
"_fstatus",
".",
"uptime",
"self",
".",
"_bytes_sent",
"=",
"self",
".",
"_fstatus",
".",
"bytes_sent",
"self",
".",
"_bytes_received",
"=",
"self",
".",
"_fstatus",
".",
"bytes_received",
"transmission_rate",
"=",
"self",
".",
"_fstatus",
".",
"transmission_rate",
"self",
".",
"_transmission_rate_up",
"=",
"transmission_rate",
"[",
"0",
"]",
"self",
".",
"_transmission_rate_down",
"=",
"transmission_rate",
"[",
"1",
"]",
"self",
".",
"_max_byte_rate_up",
"=",
"self",
".",
"_fstatus",
".",
"max_byte_rate",
"[",
"0",
"]",
"self",
".",
"_max_byte_rate_down",
"=",
"self",
".",
"_fstatus",
".",
"max_byte_rate",
"[",
"1",
"]",
"self",
".",
"_state",
"=",
"STATE_ONLINE",
"if",
"self",
".",
"_is_connected",
"else",
"STATE_OFFLINE",
"except",
"RequestException",
"as",
"err",
":",
"self",
".",
"_state",
"=",
"STATE_UNAVAILABLE",
"_LOGGER",
".",
"warning",
"(",
"\"Could not reach FRITZ!Box: %s\"",
",",
"err",
")"
] | [
114,
4
] | [
131,
65
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Bbox sensor. | Set up the Bbox sensor. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Bbox sensor."""
# Create a data fetcher to support all of the configured sensors. Then make
# the first call to init the data.
try:
bbox_data = BboxData()
bbox_data.update()
except requests.exceptions.HTTPError as error:
_LOGGER.error(error)
return False
name = config[CONF_NAME]
sensors = []
for variable in config[CONF_MONITORED_VARIABLES]:
if variable == "uptime":
sensors.append(BboxUptimeSensor(bbox_data, variable, name))
else:
sensors.append(BboxSensor(bbox_data, variable, name))
add_entities(sensors, True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"# Create a data fetcher to support all of the configured sensors. Then make",
"# the first call to init the data.",
"try",
":",
"bbox_data",
"=",
"BboxData",
"(",
")",
"bbox_data",
".",
"update",
"(",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"error",
")",
"return",
"False",
"name",
"=",
"config",
"[",
"CONF_NAME",
"]",
"sensors",
"=",
"[",
"]",
"for",
"variable",
"in",
"config",
"[",
"CONF_MONITORED_VARIABLES",
"]",
":",
"if",
"variable",
"==",
"\"uptime\"",
":",
"sensors",
".",
"append",
"(",
"BboxUptimeSensor",
"(",
"bbox_data",
",",
"variable",
",",
"name",
")",
")",
"else",
":",
"sensors",
".",
"append",
"(",
"BboxSensor",
"(",
"bbox_data",
",",
"variable",
",",
"name",
")",
")",
"add_entities",
"(",
"sensors",
",",
"True",
")"
] | [
65,
0
] | [
85,
31
] | python | en | ['en', 'bg', 'en'] | True |
BboxUptimeSensor.__init__ | (self, bbox_data, sensor_type, name) | Initialize the sensor. | Initialize the sensor. | def __init__(self, bbox_data, sensor_type, name):
"""Initialize the sensor."""
self.client_name = name
self.type = sensor_type
self._name = SENSOR_TYPES[sensor_type][0]
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self._icon = SENSOR_TYPES[sensor_type][2]
self.bbox_data = bbox_data
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"bbox_data",
",",
"sensor_type",
",",
"name",
")",
":",
"self",
".",
"client_name",
"=",
"name",
"self",
".",
"type",
"=",
"sensor_type",
"self",
".",
"_name",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"0",
"]",
"self",
".",
"_unit_of_measurement",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"1",
"]",
"self",
".",
"_icon",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"2",
"]",
"self",
".",
"bbox_data",
"=",
"bbox_data",
"self",
".",
"_state",
"=",
"None"
] | [
91,
4
] | [
99,
26
] | python | en | ['en', 'en', 'en'] | True |
BboxUptimeSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self.client_name} {self._name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self.client_name} {self._name}\""
] | [
102,
4
] | [
104,
49
] | python | en | ['en', 'mi', 'en'] | True |
BboxUptimeSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
107,
4
] | [
109,
26
] | python | en | ['en', 'en', 'en'] | True |
BboxUptimeSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
112,
4
] | [
114,
25
] | python | en | ['en', 'en', 'en'] | True |
BboxUptimeSensor.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} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
"}"
] | [
117,
4
] | [
119,
46
] | python | en | ['en', 'en', 'en'] | True |
BboxUptimeSensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self):
"""Return the class of this sensor."""
return DEVICE_CLASS_TIMESTAMP | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_TIMESTAMP"
] | [
122,
4
] | [
124,
37
] | python | en | ['en', 'en', 'en'] | True |
BboxUptimeSensor.update | (self) | Get the latest data from Bbox and update the state. | Get the latest data from Bbox and update the state. | def update(self):
"""Get the latest data from Bbox and update the state."""
self.bbox_data.update()
uptime = utcnow() - timedelta(
seconds=self.bbox_data.router_infos["device"]["uptime"]
)
self._state = uptime.replace(microsecond=0).isoformat() | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"bbox_data",
".",
"update",
"(",
")",
"uptime",
"=",
"utcnow",
"(",
")",
"-",
"timedelta",
"(",
"seconds",
"=",
"self",
".",
"bbox_data",
".",
"router_infos",
"[",
"\"device\"",
"]",
"[",
"\"uptime\"",
"]",
")",
"self",
".",
"_state",
"=",
"uptime",
".",
"replace",
"(",
"microsecond",
"=",
"0",
")",
".",
"isoformat",
"(",
")"
] | [
126,
4
] | [
132,
63
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.__init__ | (self, bbox_data, sensor_type, name) | Initialize the sensor. | Initialize the sensor. | def __init__(self, bbox_data, sensor_type, name):
"""Initialize the sensor."""
self.client_name = name
self.type = sensor_type
self._name = SENSOR_TYPES[sensor_type][0]
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
self._icon = SENSOR_TYPES[sensor_type][2]
self.bbox_data = bbox_data
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"bbox_data",
",",
"sensor_type",
",",
"name",
")",
":",
"self",
".",
"client_name",
"=",
"name",
"self",
".",
"type",
"=",
"sensor_type",
"self",
".",
"_name",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"0",
"]",
"self",
".",
"_unit_of_measurement",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"1",
"]",
"self",
".",
"_icon",
"=",
"SENSOR_TYPES",
"[",
"sensor_type",
"]",
"[",
"2",
"]",
"self",
".",
"bbox_data",
"=",
"bbox_data",
"self",
".",
"_state",
"=",
"None"
] | [
138,
4
] | [
146,
26
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self.client_name} {self._name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self.client_name} {self._name}\""
] | [
149,
4
] | [
151,
49
] | python | en | ['en', 'mi', 'en'] | True |
BboxSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
154,
4
] | [
156,
26
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.unit_of_measurement | (self) | Return the unit of measurement of this entity, if any. | Return the unit of measurement of this entity, if any. | def unit_of_measurement(self):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
159,
4
] | [
161,
40
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
164,
4
] | [
166,
25
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.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} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_ATTRIBUTION",
":",
"ATTRIBUTION",
"}"
] | [
169,
4
] | [
171,
46
] | python | en | ['en', 'en', 'en'] | True |
BboxSensor.update | (self) | Get the latest data from Bbox and update the state. | Get the latest data from Bbox and update the state. | def update(self):
"""Get the latest data from Bbox and update the state."""
self.bbox_data.update()
if self.type == "down_max_bandwidth":
self._state = round(self.bbox_data.data["rx"]["maxBandwidth"] / 1000, 2)
elif self.type == "up_max_bandwidth":
self._state = round(self.bbox_data.data["tx"]["maxBandwidth"] / 1000, 2)
elif self.type == "current_down_bandwidth":
self._state = round(self.bbox_data.data["rx"]["bandwidth"] / 1000, 2)
elif self.type == "current_up_bandwidth":
self._state = round(self.bbox_data.data["tx"]["bandwidth"] / 1000, 2)
elif self.type == "number_of_reboots":
self._state = self.bbox_data.router_infos["device"]["numberofboots"] | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"bbox_data",
".",
"update",
"(",
")",
"if",
"self",
".",
"type",
"==",
"\"down_max_bandwidth\"",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"bbox_data",
".",
"data",
"[",
"\"rx\"",
"]",
"[",
"\"maxBandwidth\"",
"]",
"/",
"1000",
",",
"2",
")",
"elif",
"self",
".",
"type",
"==",
"\"up_max_bandwidth\"",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"bbox_data",
".",
"data",
"[",
"\"tx\"",
"]",
"[",
"\"maxBandwidth\"",
"]",
"/",
"1000",
",",
"2",
")",
"elif",
"self",
".",
"type",
"==",
"\"current_down_bandwidth\"",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"bbox_data",
".",
"data",
"[",
"\"rx\"",
"]",
"[",
"\"bandwidth\"",
"]",
"/",
"1000",
",",
"2",
")",
"elif",
"self",
".",
"type",
"==",
"\"current_up_bandwidth\"",
":",
"self",
".",
"_state",
"=",
"round",
"(",
"self",
".",
"bbox_data",
".",
"data",
"[",
"\"tx\"",
"]",
"[",
"\"bandwidth\"",
"]",
"/",
"1000",
",",
"2",
")",
"elif",
"self",
".",
"type",
"==",
"\"number_of_reboots\"",
":",
"self",
".",
"_state",
"=",
"self",
".",
"bbox_data",
".",
"router_infos",
"[",
"\"device\"",
"]",
"[",
"\"numberofboots\"",
"]"
] | [
173,
4
] | [
185,
80
] | python | en | ['en', 'en', 'en'] | True |
BboxData.__init__ | (self) | Initialize the data object. | Initialize the data object. | def __init__(self):
"""Initialize the data object."""
self.data = None
self.router_infos = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"data",
"=",
"None",
"self",
".",
"router_infos",
"=",
"None"
] | [
191,
4
] | [
194,
32
] | python | en | ['en', 'en', 'en'] | True |
BboxData.update | (self) | Get the latest data from the Bbox. | Get the latest data from the Bbox. | def update(self):
"""Get the latest data from the Bbox."""
try:
box = pybbox.Bbox()
self.data = box.get_ip_stats()
self.router_infos = box.get_bbox_info()
except requests.exceptions.HTTPError as error:
_LOGGER.error(error)
self.data = None
self.router_infos = None
return False | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"box",
"=",
"pybbox",
".",
"Bbox",
"(",
")",
"self",
".",
"data",
"=",
"box",
".",
"get_ip_stats",
"(",
")",
"self",
".",
"router_infos",
"=",
"box",
".",
"get_bbox_info",
"(",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"error",
":",
"_LOGGER",
".",
"error",
"(",
"error",
")",
"self",
".",
"data",
"=",
"None",
"self",
".",
"router_infos",
"=",
"None",
"return",
"False"
] | [
197,
4
] | [
208,
24
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config) | Set up the Minut Point component. | Set up the Minut Point component. | async def async_setup(hass, config):
"""Set up the Minut Point component."""
if DOMAIN not in config:
return True
conf = config[DOMAIN]
config_flow.register_flow_implementation(
hass, DOMAIN, conf[CONF_CLIENT_ID], conf[CONF_CLIENT_SECRET]
)
hass.async_create_task(
hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}
)
)
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"if",
"DOMAIN",
"not",
"in",
"config",
":",
"return",
"True",
"conf",
"=",
"config",
"[",
"DOMAIN",
"]",
"config_flow",
".",
"register_flow_implementation",
"(",
"hass",
",",
"DOMAIN",
",",
"conf",
"[",
"CONF_CLIENT_ID",
"]",
",",
"conf",
"[",
"CONF_CLIENT_SECRET",
"]",
")",
"hass",
".",
"async_create_task",
"(",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"config_entries",
".",
"SOURCE_IMPORT",
"}",
")",
")",
"return",
"True"
] | [
54,
0
] | [
71,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass: HomeAssistantType, entry: ConfigEntry) | Set up Point from a config entry. | Set up Point from a config entry. | async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Set up Point from a config entry."""
async def token_saver(token, **kwargs):
_LOGGER.debug("Saving updated token %s", token)
hass.config_entries.async_update_entry(
entry, data={**entry.data, CONF_TOKEN: token}
)
session = PointSession(
hass.helpers.aiohttp_client.async_get_clientsession(),
entry.data["refresh_args"][CONF_CLIENT_ID],
entry.data["refresh_args"][CONF_CLIENT_SECRET],
token=entry.data[CONF_TOKEN],
token_saver=token_saver,
)
try:
await session.ensure_active_token()
except Exception: # pylint: disable=broad-except
_LOGGER.error("Authentication Error")
return False
hass.data[DATA_CONFIG_ENTRY_LOCK] = asyncio.Lock()
hass.data[CONFIG_ENTRY_IS_SETUP] = set()
await async_setup_webhook(hass, entry, session)
client = MinutPointClient(hass, entry, session)
hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: client})
hass.async_create_task(client.update())
return True | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"async",
"def",
"token_saver",
"(",
"token",
",",
"*",
"*",
"kwargs",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Saving updated token %s\"",
",",
"token",
")",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"{",
"*",
"*",
"entry",
".",
"data",
",",
"CONF_TOKEN",
":",
"token",
"}",
")",
"session",
"=",
"PointSession",
"(",
"hass",
".",
"helpers",
".",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
")",
",",
"entry",
".",
"data",
"[",
"\"refresh_args\"",
"]",
"[",
"CONF_CLIENT_ID",
"]",
",",
"entry",
".",
"data",
"[",
"\"refresh_args\"",
"]",
"[",
"CONF_CLIENT_SECRET",
"]",
",",
"token",
"=",
"entry",
".",
"data",
"[",
"CONF_TOKEN",
"]",
",",
"token_saver",
"=",
"token_saver",
",",
")",
"try",
":",
"await",
"session",
".",
"ensure_active_token",
"(",
")",
"except",
"Exception",
":",
"# pylint: disable=broad-except",
"_LOGGER",
".",
"error",
"(",
"\"Authentication Error\"",
")",
"return",
"False",
"hass",
".",
"data",
"[",
"DATA_CONFIG_ENTRY_LOCK",
"]",
"=",
"asyncio",
".",
"Lock",
"(",
")",
"hass",
".",
"data",
"[",
"CONFIG_ENTRY_IS_SETUP",
"]",
"=",
"set",
"(",
")",
"await",
"async_setup_webhook",
"(",
"hass",
",",
"entry",
",",
"session",
")",
"client",
"=",
"MinutPointClient",
"(",
"hass",
",",
"entry",
",",
"session",
")",
"hass",
".",
"data",
".",
"setdefault",
"(",
"DOMAIN",
",",
"{",
"}",
")",
".",
"update",
"(",
"{",
"entry",
".",
"entry_id",
":",
"client",
"}",
")",
"hass",
".",
"async_create_task",
"(",
"client",
".",
"update",
"(",
")",
")",
"return",
"True"
] | [
74,
0
] | [
104,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_webhook | (hass: HomeAssistantType, entry: ConfigEntry, session) | Set up a webhook to handle binary sensor events. | Set up a webhook to handle binary sensor events. | async def async_setup_webhook(hass: HomeAssistantType, entry: ConfigEntry, session):
"""Set up a webhook to handle binary sensor events."""
if CONF_WEBHOOK_ID not in entry.data:
webhook_id = hass.components.webhook.async_generate_id()
webhook_url = hass.components.webhook.async_generate_url(webhook_id)
_LOGGER.info("Registering new webhook at: %s", webhook_url)
hass.config_entries.async_update_entry(
entry,
data={
**entry.data,
CONF_WEBHOOK_ID: webhook_id,
CONF_WEBHOOK_URL: webhook_url,
},
)
await session.update_webhook(
entry.data[CONF_WEBHOOK_URL],
entry.data[CONF_WEBHOOK_ID],
["*"],
)
hass.components.webhook.async_register(
DOMAIN, "Point", entry.data[CONF_WEBHOOK_ID], handle_webhook
) | [
"async",
"def",
"async_setup_webhook",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
",",
"session",
")",
":",
"if",
"CONF_WEBHOOK_ID",
"not",
"in",
"entry",
".",
"data",
":",
"webhook_id",
"=",
"hass",
".",
"components",
".",
"webhook",
".",
"async_generate_id",
"(",
")",
"webhook_url",
"=",
"hass",
".",
"components",
".",
"webhook",
".",
"async_generate_url",
"(",
"webhook_id",
")",
"_LOGGER",
".",
"info",
"(",
"\"Registering new webhook at: %s\"",
",",
"webhook_url",
")",
"hass",
".",
"config_entries",
".",
"async_update_entry",
"(",
"entry",
",",
"data",
"=",
"{",
"*",
"*",
"entry",
".",
"data",
",",
"CONF_WEBHOOK_ID",
":",
"webhook_id",
",",
"CONF_WEBHOOK_URL",
":",
"webhook_url",
",",
"}",
",",
")",
"await",
"session",
".",
"update_webhook",
"(",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_URL",
"]",
",",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
",",
"[",
"\"*\"",
"]",
",",
")",
"hass",
".",
"components",
".",
"webhook",
".",
"async_register",
"(",
"DOMAIN",
",",
"\"Point\"",
",",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
",",
"handle_webhook",
")"
] | [
107,
0
] | [
130,
5
] | python | en | ['en', 'haw', 'en'] | True |
async_unload_entry | (hass: HomeAssistantType, entry: ConfigEntry) | Unload a config entry. | Unload a config entry. | async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry):
"""Unload a config entry."""
hass.components.webhook.async_unregister(entry.data[CONF_WEBHOOK_ID])
session = hass.data[DOMAIN].pop(entry.entry_id)
await session.remove_webhook()
for component in ("binary_sensor", "sensor"):
await hass.config_entries.async_forward_entry_unload(entry, component)
if not hass.data[DOMAIN]:
hass.data.pop(DOMAIN)
return True | [
"async",
"def",
"async_unload_entry",
"(",
"hass",
":",
"HomeAssistantType",
",",
"entry",
":",
"ConfigEntry",
")",
":",
"hass",
".",
"components",
".",
"webhook",
".",
"async_unregister",
"(",
"entry",
".",
"data",
"[",
"CONF_WEBHOOK_ID",
"]",
")",
"session",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"pop",
"(",
"entry",
".",
"entry_id",
")",
"await",
"session",
".",
"remove_webhook",
"(",
")",
"for",
"component",
"in",
"(",
"\"binary_sensor\"",
",",
"\"sensor\"",
")",
":",
"await",
"hass",
".",
"config_entries",
".",
"async_forward_entry_unload",
"(",
"entry",
",",
"component",
")",
"if",
"not",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
":",
"hass",
".",
"data",
".",
"pop",
"(",
"DOMAIN",
")",
"return",
"True"
] | [
133,
0
] | [
145,
15
] | python | en | ['en', 'es', 'en'] | True |
handle_webhook | (hass, webhook_id, request) | Handle webhook callback. | Handle webhook callback. | async def handle_webhook(hass, webhook_id, request):
"""Handle webhook callback."""
try:
data = await request.json()
_LOGGER.debug("Webhook %s: %s", webhook_id, data)
except ValueError:
return None
if isinstance(data, dict):
data["webhook_id"] = webhook_id
async_dispatcher_send(hass, SIGNAL_WEBHOOK, data, data.get("hook_id"))
hass.bus.async_fire(EVENT_RECEIVED, data) | [
"async",
"def",
"handle_webhook",
"(",
"hass",
",",
"webhook_id",
",",
"request",
")",
":",
"try",
":",
"data",
"=",
"await",
"request",
".",
"json",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Webhook %s: %s\"",
",",
"webhook_id",
",",
"data",
")",
"except",
"ValueError",
":",
"return",
"None",
"if",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"data",
"[",
"\"webhook_id\"",
"]",
"=",
"webhook_id",
"async_dispatcher_send",
"(",
"hass",
",",
"SIGNAL_WEBHOOK",
",",
"data",
",",
"data",
".",
"get",
"(",
"\"hook_id\"",
")",
")",
"hass",
".",
"bus",
".",
"async_fire",
"(",
"EVENT_RECEIVED",
",",
"data",
")"
] | [
148,
0
] | [
159,
45
] | python | en | ['en', 'xh', 'en'] | True |
MinutPointClient.__init__ | (self, hass: HomeAssistantType, config_entry: ConfigEntry, session) | Initialize the Minut data object. | Initialize the Minut data object. | def __init__(self, hass: HomeAssistantType, config_entry: ConfigEntry, session):
"""Initialize the Minut data object."""
self._known_devices = set()
self._known_homes = set()
self._hass = hass
self._config_entry = config_entry
self._is_available = True
self._client = session
async_track_time_interval(self._hass, self.update, SCAN_INTERVAL) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistantType",
",",
"config_entry",
":",
"ConfigEntry",
",",
"session",
")",
":",
"self",
".",
"_known_devices",
"=",
"set",
"(",
")",
"self",
".",
"_known_homes",
"=",
"set",
"(",
")",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"_config_entry",
"=",
"config_entry",
"self",
".",
"_is_available",
"=",
"True",
"self",
".",
"_client",
"=",
"session",
"async_track_time_interval",
"(",
"self",
".",
"_hass",
",",
"self",
".",
"update",
",",
"SCAN_INTERVAL",
")"
] | [
165,
4
] | [
174,
73
] | python | en | ['en', 'en', 'en'] | True |
MinutPointClient.update | (self, *args) | Periodically poll the cloud for current state. | Periodically poll the cloud for current state. | async def update(self, *args):
"""Periodically poll the cloud for current state."""
await self._sync() | [
"async",
"def",
"update",
"(",
"self",
",",
"*",
"args",
")",
":",
"await",
"self",
".",
"_sync",
"(",
")"
] | [
176,
4
] | [
178,
26
] | python | en | ['en', 'en', 'en'] | True |
MinutPointClient._sync | (self) | Update local list of devices. | Update local list of devices. | async def _sync(self):
"""Update local list of devices."""
if not await self._client.update() and self._is_available:
self._is_available = False
_LOGGER.warning("Device is unavailable")
async_dispatcher_send(self._hass, SIGNAL_UPDATE_ENTITY)
return
async def new_device(device_id, component):
"""Load new device."""
config_entries_key = f"{component}.{DOMAIN}"
async with self._hass.data[DATA_CONFIG_ENTRY_LOCK]:
if config_entries_key not in self._hass.data[CONFIG_ENTRY_IS_SETUP]:
await self._hass.config_entries.async_forward_entry_setup(
self._config_entry, component
)
self._hass.data[CONFIG_ENTRY_IS_SETUP].add(config_entries_key)
async_dispatcher_send(
self._hass, POINT_DISCOVERY_NEW.format(component, DOMAIN), device_id
)
self._is_available = True
for home_id in self._client.homes:
if home_id not in self._known_homes:
await new_device(home_id, "alarm_control_panel")
self._known_homes.add(home_id)
for device in self._client.devices:
if device.device_id not in self._known_devices:
for component in ("sensor", "binary_sensor"):
await new_device(device.device_id, component)
self._known_devices.add(device.device_id)
async_dispatcher_send(self._hass, SIGNAL_UPDATE_ENTITY) | [
"async",
"def",
"_sync",
"(",
"self",
")",
":",
"if",
"not",
"await",
"self",
".",
"_client",
".",
"update",
"(",
")",
"and",
"self",
".",
"_is_available",
":",
"self",
".",
"_is_available",
"=",
"False",
"_LOGGER",
".",
"warning",
"(",
"\"Device is unavailable\"",
")",
"async_dispatcher_send",
"(",
"self",
".",
"_hass",
",",
"SIGNAL_UPDATE_ENTITY",
")",
"return",
"async",
"def",
"new_device",
"(",
"device_id",
",",
"component",
")",
":",
"\"\"\"Load new device.\"\"\"",
"config_entries_key",
"=",
"f\"{component}.{DOMAIN}\"",
"async",
"with",
"self",
".",
"_hass",
".",
"data",
"[",
"DATA_CONFIG_ENTRY_LOCK",
"]",
":",
"if",
"config_entries_key",
"not",
"in",
"self",
".",
"_hass",
".",
"data",
"[",
"CONFIG_ENTRY_IS_SETUP",
"]",
":",
"await",
"self",
".",
"_hass",
".",
"config_entries",
".",
"async_forward_entry_setup",
"(",
"self",
".",
"_config_entry",
",",
"component",
")",
"self",
".",
"_hass",
".",
"data",
"[",
"CONFIG_ENTRY_IS_SETUP",
"]",
".",
"add",
"(",
"config_entries_key",
")",
"async_dispatcher_send",
"(",
"self",
".",
"_hass",
",",
"POINT_DISCOVERY_NEW",
".",
"format",
"(",
"component",
",",
"DOMAIN",
")",
",",
"device_id",
")",
"self",
".",
"_is_available",
"=",
"True",
"for",
"home_id",
"in",
"self",
".",
"_client",
".",
"homes",
":",
"if",
"home_id",
"not",
"in",
"self",
".",
"_known_homes",
":",
"await",
"new_device",
"(",
"home_id",
",",
"\"alarm_control_panel\"",
")",
"self",
".",
"_known_homes",
".",
"add",
"(",
"home_id",
")",
"for",
"device",
"in",
"self",
".",
"_client",
".",
"devices",
":",
"if",
"device",
".",
"device_id",
"not",
"in",
"self",
".",
"_known_devices",
":",
"for",
"component",
"in",
"(",
"\"sensor\"",
",",
"\"binary_sensor\"",
")",
":",
"await",
"new_device",
"(",
"device",
".",
"device_id",
",",
"component",
")",
"self",
".",
"_known_devices",
".",
"add",
"(",
"device",
".",
"device_id",
")",
"async_dispatcher_send",
"(",
"self",
".",
"_hass",
",",
"SIGNAL_UPDATE_ENTITY",
")"
] | [
180,
4
] | [
212,
63
] | python | en | ['en', 'en', 'en'] | True |
MinutPointClient.device | (self, device_id) | Return device representation. | Return device representation. | def device(self, device_id):
"""Return device representation."""
return self._client.device(device_id) | [
"def",
"device",
"(",
"self",
",",
"device_id",
")",
":",
"return",
"self",
".",
"_client",
".",
"device",
"(",
"device_id",
")"
] | [
214,
4
] | [
216,
45
] | python | en | ['es', 'it', 'en'] | False |
MinutPointClient.is_available | (self, device_id) | Return device availability. | Return device availability. | def is_available(self, device_id):
"""Return device availability."""
if not self._is_available:
return False
return device_id in self._client.device_ids | [
"def",
"is_available",
"(",
"self",
",",
"device_id",
")",
":",
"if",
"not",
"self",
".",
"_is_available",
":",
"return",
"False",
"return",
"device_id",
"in",
"self",
".",
"_client",
".",
"device_ids"
] | [
218,
4
] | [
222,
51
] | python | en | ['fr', 'ga', 'en'] | False |
MinutPointClient.remove_webhook | (self) | Remove the session webhook. | Remove the session webhook. | async def remove_webhook(self):
"""Remove the session webhook."""
return await self._client.remove_webhook() | [
"async",
"def",
"remove_webhook",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"_client",
".",
"remove_webhook",
"(",
")"
] | [
224,
4
] | [
226,
50
] | python | en | ['en', 'en', 'en'] | True |
MinutPointClient.homes | (self) | Return known homes. | Return known homes. | def homes(self):
"""Return known homes."""
return self._client.homes | [
"def",
"homes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_client",
".",
"homes"
] | [
229,
4
] | [
231,
33
] | python | en | ['en', 'en', 'en'] | True |
MinutPointClient.async_alarm_disarm | (self, home_id) | Send alarm disarm command. | Send alarm disarm command. | async def async_alarm_disarm(self, home_id):
"""Send alarm disarm command."""
return await self._client.alarm_disarm(home_id) | [
"async",
"def",
"async_alarm_disarm",
"(",
"self",
",",
"home_id",
")",
":",
"return",
"await",
"self",
".",
"_client",
".",
"alarm_disarm",
"(",
"home_id",
")"
] | [
233,
4
] | [
235,
55
] | python | en | ['en', 'fa', 'en'] | True |
MinutPointClient.async_alarm_arm | (self, home_id) | Send alarm arm command. | Send alarm arm command. | async def async_alarm_arm(self, home_id):
"""Send alarm arm command."""
return await self._client.alarm_arm(home_id) | [
"async",
"def",
"async_alarm_arm",
"(",
"self",
",",
"home_id",
")",
":",
"return",
"await",
"self",
".",
"_client",
".",
"alarm_arm",
"(",
"home_id",
")"
] | [
237,
4
] | [
239,
52
] | python | en | ['en', 'sr', 'en'] | True |
MinutPointEntity.__init__ | (self, point_client, device_id, device_class) | Initialize the entity. | Initialize the entity. | def __init__(self, point_client, device_id, device_class):
"""Initialize the entity."""
self._async_unsub_dispatcher_connect = None
self._client = point_client
self._id = device_id
self._name = self.device.name
self._device_class = device_class
self._updated = utc_from_timestamp(0)
self._value = None | [
"def",
"__init__",
"(",
"self",
",",
"point_client",
",",
"device_id",
",",
"device_class",
")",
":",
"self",
".",
"_async_unsub_dispatcher_connect",
"=",
"None",
"self",
".",
"_client",
"=",
"point_client",
"self",
".",
"_id",
"=",
"device_id",
"self",
".",
"_name",
"=",
"self",
".",
"device",
".",
"name",
"self",
".",
"_device_class",
"=",
"device_class",
"self",
".",
"_updated",
"=",
"utc_from_timestamp",
"(",
"0",
")",
"self",
".",
"_value",
"=",
"None"
] | [
245,
4
] | [
253,
26
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.__str__ | (self) | Return string representation of device. | Return string representation of device. | def __str__(self):
"""Return string representation of device."""
return f"MinutPoint {self.name}" | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"f\"MinutPoint {self.name}\""
] | [
255,
4
] | [
257,
40
] | python | en | ['en', 'sl', 'en'] | True |
MinutPointEntity.async_added_to_hass | (self) | Call when entity is added to hass. | Call when entity is added to hass. | async def async_added_to_hass(self):
"""Call when entity is added to hass."""
_LOGGER.debug("Created device %s", self)
self._async_unsub_dispatcher_connect = async_dispatcher_connect(
self.hass, SIGNAL_UPDATE_ENTITY, self._update_callback
)
await self._update_callback() | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Created device %s\"",
",",
"self",
")",
"self",
".",
"_async_unsub_dispatcher_connect",
"=",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_ENTITY",
",",
"self",
".",
"_update_callback",
")",
"await",
"self",
".",
"_update_callback",
"(",
")"
] | [
259,
4
] | [
265,
37
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.async_will_remove_from_hass | (self) | Disconnect dispatcher listener when removed. | Disconnect dispatcher listener when removed. | async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listener when removed."""
if self._async_unsub_dispatcher_connect:
self._async_unsub_dispatcher_connect() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"if",
"self",
".",
"_async_unsub_dispatcher_connect",
":",
"self",
".",
"_async_unsub_dispatcher_connect",
"(",
")"
] | [
267,
4
] | [
270,
50
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity._update_callback | (self) | Update the value of the sensor. | Update the value of the sensor. | async def _update_callback(self):
"""Update the value of the sensor.""" | [
"async",
"def",
"_update_callback",
"(",
"self",
")",
":"
] | [
272,
4
] | [
273,
45
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.available | (self) | Return true if device is not offline. | Return true if device is not offline. | def available(self):
"""Return true if device is not offline."""
return self._client.is_available(self.device_id) | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_client",
".",
"is_available",
"(",
"self",
".",
"device_id",
")"
] | [
276,
4
] | [
278,
56
] | python | en | ['en', 'fy', 'en'] | True |
MinutPointEntity.device | (self) | Return the representation of the device. | Return the representation of the device. | def device(self):
"""Return the representation of the device."""
return self._client.device(self.device_id) | [
"def",
"device",
"(",
"self",
")",
":",
"return",
"self",
".",
"_client",
".",
"device",
"(",
"self",
".",
"device_id",
")"
] | [
281,
4
] | [
283,
50
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.device_class | (self) | Return the device class. | Return the device class. | def device_class(self):
"""Return the device class."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_class"
] | [
286,
4
] | [
288,
33
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.device_id | (self) | Return the id of the device. | Return the id of the device. | def device_id(self):
"""Return the id of the device."""
return self._id | [
"def",
"device_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_id"
] | [
291,
4
] | [
293,
23
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.device_state_attributes | (self) | Return status of device. | Return status of device. | def device_state_attributes(self):
"""Return status of device."""
attrs = self.device.device_status
attrs["last_heard_from"] = as_local(self.last_update).strftime(
"%Y-%m-%d %H:%M:%S"
)
return attrs | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attrs",
"=",
"self",
".",
"device",
".",
"device_status",
"attrs",
"[",
"\"last_heard_from\"",
"]",
"=",
"as_local",
"(",
"self",
".",
"last_update",
")",
".",
"strftime",
"(",
"\"%Y-%m-%d %H:%M:%S\"",
")",
"return",
"attrs"
] | [
296,
4
] | [
302,
20
] | python | en | ['en', 'ja', 'en'] | True |
MinutPointEntity.device_info | (self) | Return a device description for device registry. | Return a device description for device registry. | def device_info(self):
"""Return a device description for device registry."""
device = self.device.device
return {
"connections": {("mac", device["device_mac"])},
"identifieres": device["device_id"],
"manufacturer": "Minut",
"model": f"Point v{device['hardware_version']}",
"name": device["description"],
"sw_version": device["firmware"]["installed"],
"via_device": (DOMAIN, device["home"]),
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"device",
"=",
"self",
".",
"device",
".",
"device",
"return",
"{",
"\"connections\"",
":",
"{",
"(",
"\"mac\"",
",",
"device",
"[",
"\"device_mac\"",
"]",
")",
"}",
",",
"\"identifieres\"",
":",
"device",
"[",
"\"device_id\"",
"]",
",",
"\"manufacturer\"",
":",
"\"Minut\"",
",",
"\"model\"",
":",
"f\"Point v{device['hardware_version']}\"",
",",
"\"name\"",
":",
"device",
"[",
"\"description\"",
"]",
",",
"\"sw_version\"",
":",
"device",
"[",
"\"firmware\"",
"]",
"[",
"\"installed\"",
"]",
",",
"\"via_device\"",
":",
"(",
"DOMAIN",
",",
"device",
"[",
"\"home\"",
"]",
")",
",",
"}"
] | [
305,
4
] | [
316,
9
] | python | en | ['ro', 'fr', 'en'] | False |
MinutPointEntity.name | (self) | Return the display name of this device. | Return the display name of this device. | def name(self):
"""Return the display name of this device."""
return f"{self._name} {self.device_class.capitalize()}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name} {self.device_class.capitalize()}\""
] | [
319,
4
] | [
321,
63
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.is_updated | (self) | Return true if sensor have been updated. | Return true if sensor have been updated. | def is_updated(self):
"""Return true if sensor have been updated."""
return self.last_update > self._updated | [
"def",
"is_updated",
"(",
"self",
")",
":",
"return",
"self",
".",
"last_update",
">",
"self",
".",
"_updated"
] | [
324,
4
] | [
326,
47
] | python | en | ['en', 'nl', 'en'] | True |
MinutPointEntity.last_update | (self) | Return the last_update time for the device. | Return the last_update time for the device. | def last_update(self):
"""Return the last_update time for the device."""
last_update = parse_datetime(self.device.last_update)
return last_update | [
"def",
"last_update",
"(",
"self",
")",
":",
"last_update",
"=",
"parse_datetime",
"(",
"self",
".",
"device",
".",
"last_update",
")",
"return",
"last_update"
] | [
329,
4
] | [
332,
26
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.should_poll | (self) | No polling needed for point. | No polling needed for point. | def should_poll(self):
"""No polling needed for point."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
335,
4
] | [
337,
20
] | python | en | ['en', 'en', 'en'] | True |
MinutPointEntity.unique_id | (self) | Return the unique id of the sensor. | Return the unique id of the sensor. | def unique_id(self):
"""Return the unique id of the sensor."""
return f"point.{self._id}-{self.device_class}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"point.{self._id}-{self.device_class}\""
] | [
340,
4
] | [
342,
54
] | python | en | ['en', 'la', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.