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 |
---|---|---|---|---|---|---|---|---|---|---|---|
HomematicipMotionDetector.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_MOTION | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_MOTION"
] | [
301,
4
] | [
303,
34
] | python | en | ['en', 'en', 'en'] | True |
HomematicipMotionDetector.is_on | (self) | Return true if motion is detected. | Return true if motion is detected. | def is_on(self) -> bool:
"""Return true if motion is detected."""
return self._device.motionDetected | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"motionDetected"
] | [
306,
4
] | [
308,
42
] | python | en | ['en', 'en', 'en'] | True |
HomematicipPresenceDetector.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_PRESENCE | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_PRESENCE"
] | [
315,
4
] | [
317,
36
] | python | en | ['en', 'en', 'en'] | True |
HomematicipPresenceDetector.is_on | (self) | Return true if presence is detected. | Return true if presence is detected. | def is_on(self) -> bool:
"""Return true if presence is detected."""
return self._device.presenceDetected | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"presenceDetected"
] | [
320,
4
] | [
322,
44
] | python | en | ['en', 'af', 'en'] | True |
HomematicipSmokeDetector.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_SMOKE | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_SMOKE"
] | [
329,
4
] | [
331,
33
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSmokeDetector.is_on | (self) | Return true if smoke is detected. | Return true if smoke is detected. | def is_on(self) -> bool:
"""Return true if smoke is detected."""
if self._device.smokeDetectorAlarmType:
return (
self._device.smokeDetectorAlarmType
== SmokeDetectorAlarmType.PRIMARY_ALARM
)
return False | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"self",
".",
"_device",
".",
"smokeDetectorAlarmType",
":",
"return",
"(",
"self",
".",
"_device",
".",
"smokeDetectorAlarmType",
"==",
"SmokeDetectorAlarmType",
".",
"PRIMARY_ALARM",
")",
"return",
"False"
] | [
334,
4
] | [
341,
20
] | python | en | ['en', 'af', 'en'] | True |
HomematicipWaterDetector.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_MOISTURE | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_MOISTURE"
] | [
348,
4
] | [
350,
36
] | python | en | ['en', 'en', 'en'] | True |
HomematicipWaterDetector.is_on | (self) | Return true, if moisture or waterlevel is detected. | Return true, if moisture or waterlevel is detected. | def is_on(self) -> bool:
"""Return true, if moisture or waterlevel is detected."""
return self._device.moistureDetected or self._device.waterlevelDetected | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"moistureDetected",
"or",
"self",
".",
"_device",
".",
"waterlevelDetected"
] | [
353,
4
] | [
355,
79
] | python | en | ['en', 'af', 'en'] | True |
HomematicipStormSensor.__init__ | (self, hap: HomematicipHAP, device) | Initialize storm sensor. | Initialize storm sensor. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize storm sensor."""
super().__init__(hap, device, "Storm") | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"\"Storm\"",
")"
] | [
361,
4
] | [
363,
46
] | python | en | ['en', 'pt', 'en'] | True |
HomematicipStormSensor.icon | (self) | Return the icon. | Return the icon. | def icon(self) -> str:
"""Return the icon."""
return "mdi:weather-windy" if self.is_on else "mdi:pinwheel-outline" | [
"def",
"icon",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"mdi:weather-windy\"",
"if",
"self",
".",
"is_on",
"else",
"\"mdi:pinwheel-outline\""
] | [
366,
4
] | [
368,
76
] | python | en | ['en', 'sr', 'en'] | True |
HomematicipStormSensor.is_on | (self) | Return true, if storm is detected. | Return true, if storm is detected. | def is_on(self) -> bool:
"""Return true, if storm is detected."""
return self._device.storm | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"storm"
] | [
371,
4
] | [
373,
33
] | python | en | ['en', 'af', 'en'] | True |
HomematicipRainSensor.__init__ | (self, hap: HomematicipHAP, device) | Initialize rain sensor. | Initialize rain sensor. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize rain sensor."""
super().__init__(hap, device, "Raining") | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"\"Raining\"",
")"
] | [
379,
4
] | [
381,
48
] | python | en | ['en', 'eu', 'en'] | True |
HomematicipRainSensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_MOISTURE | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_MOISTURE"
] | [
384,
4
] | [
386,
36
] | python | en | ['en', 'en', 'en'] | True |
HomematicipRainSensor.is_on | (self) | Return true, if it is raining. | Return true, if it is raining. | def is_on(self) -> bool:
"""Return true, if it is raining."""
return self._device.raining | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"raining"
] | [
389,
4
] | [
391,
35
] | python | en | ['en', 'mt', 'en'] | True |
HomematicipSunshineSensor.__init__ | (self, hap: HomematicipHAP, device) | Initialize sunshine sensor. | Initialize sunshine sensor. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize sunshine sensor."""
super().__init__(hap, device, post="Sunshine") | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"post",
"=",
"\"Sunshine\"",
")"
] | [
397,
4
] | [
399,
54
] | python | en | ['en', 'zu', 'it'] | False |
HomematicipSunshineSensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_LIGHT | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_LIGHT"
] | [
402,
4
] | [
404,
33
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSunshineSensor.is_on | (self) | Return true if sun is shining. | Return true if sun is shining. | def is_on(self) -> bool:
"""Return true if sun is shining."""
return self._device.sunshine | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"sunshine"
] | [
407,
4
] | [
409,
36
] | python | en | ['en', 'fy', 'en'] | True |
HomematicipSunshineSensor.device_state_attributes | (self) | Return the state attributes of the illuminance sensor. | Return the state attributes of the illuminance sensor. | def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the illuminance sensor."""
state_attr = super().device_state_attributes
today_sunshine_duration = getattr(self._device, "todaySunshineDuration", None)
if today_sunshine_duration:
state_attr[ATTR_TODAY_SUNSHINE_DURATION] = today_sunshine_duration
return state_attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"state_attr",
"=",
"super",
"(",
")",
".",
"device_state_attributes",
"today_sunshine_duration",
"=",
"getattr",
"(",
"self",
".",
"_device",
",",
"\"todaySunshineDuration\"",
",",
"None",
")",
"if",
"today_sunshine_duration",
":",
"state_attr",
"[",
"ATTR_TODAY_SUNSHINE_DURATION",
"]",
"=",
"today_sunshine_duration",
"return",
"state_attr"
] | [
412,
4
] | [
420,
25
] | python | en | ['en', 'sq', 'en'] | True |
HomematicipBatterySensor.__init__ | (self, hap: HomematicipHAP, device) | Initialize battery sensor. | Initialize battery sensor. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize battery sensor."""
super().__init__(hap, device, post="Battery") | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"post",
"=",
"\"Battery\"",
")"
] | [
426,
4
] | [
428,
53
] | python | en | ['en', 'fy', 'en'] | True |
HomematicipBatterySensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_BATTERY | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_BATTERY"
] | [
431,
4
] | [
433,
35
] | python | en | ['en', 'en', 'en'] | True |
HomematicipBatterySensor.is_on | (self) | Return true if battery is low. | Return true if battery is low. | def is_on(self) -> bool:
"""Return true if battery is low."""
return self._device.lowBat | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"self",
".",
"_device",
".",
"lowBat"
] | [
436,
4
] | [
438,
34
] | python | en | ['en', 'fy', 'en'] | True |
HomematicipPluggableMainsFailureSurveillanceSensor.__init__ | (self, hap: HomematicipHAP, device) | Initialize pluggable mains failure surveillance sensor. | Initialize pluggable mains failure surveillance sensor. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize pluggable mains failure surveillance sensor."""
super().__init__(hap, device) | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
")"
] | [
446,
4
] | [
448,
37
] | python | fr | ['fr', 'fr', 'en'] | True |
HomematicipPluggableMainsFailureSurveillanceSensor.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_POWER | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_POWER"
] | [
451,
4
] | [
453,
33
] | python | en | ['en', 'en', 'en'] | True |
HomematicipPluggableMainsFailureSurveillanceSensor.is_on | (self) | Return true if power mains fails. | Return true if power mains fails. | def is_on(self) -> bool:
"""Return true if power mains fails."""
return not self._device.powerMainsFailure | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"not",
"self",
".",
"_device",
".",
"powerMainsFailure"
] | [
456,
4
] | [
458,
49
] | python | en | ['en', 'gd', 'en'] | True |
HomematicipSecurityZoneSensorGroup.__init__ | (self, hap: HomematicipHAP, device, post: str = "SecurityZone") | Initialize security zone group. | Initialize security zone group. | def __init__(self, hap: HomematicipHAP, device, post: str = "SecurityZone") -> None:
"""Initialize security zone group."""
device.modelType = f"HmIP-{post}"
super().__init__(hap, device, post=post) | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
",",
"post",
":",
"str",
"=",
"\"SecurityZone\"",
")",
"->",
"None",
":",
"device",
".",
"modelType",
"=",
"f\"HmIP-{post}\"",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"post",
"=",
"post",
")"
] | [
464,
4
] | [
467,
48
] | python | en | ['pl', 'en', 'en'] | True |
HomematicipSecurityZoneSensorGroup.device_class | (self) | Return the class of this sensor. | Return the class of this sensor. | def device_class(self) -> str:
"""Return the class of this sensor."""
return DEVICE_CLASS_SAFETY | [
"def",
"device_class",
"(",
"self",
")",
"->",
"str",
":",
"return",
"DEVICE_CLASS_SAFETY"
] | [
470,
4
] | [
472,
34
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSecurityZoneSensorGroup.available | (self) | Security-Group available. | Security-Group available. | def available(self) -> bool:
"""Security-Group available."""
# A security-group must be available, and should not be affected by
# the individual availability of group members.
return True | [
"def",
"available",
"(",
"self",
")",
"->",
"bool",
":",
"# A security-group must be available, and should not be affected by",
"# the individual availability of group members.",
"return",
"True"
] | [
475,
4
] | [
479,
19
] | python | en | ['fr', 'en', 'en'] | False |
HomematicipSecurityZoneSensorGroup.device_state_attributes | (self) | Return the state attributes of the security zone group. | Return the state attributes of the security zone group. | def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the security zone group."""
state_attr = super().device_state_attributes
for attr, attr_key in GROUP_ATTRIBUTES.items():
attr_value = getattr(self._device, attr, None)
if attr_value:
state_attr[attr_key] = attr_value
window_state = getattr(self._device, "windowState", None)
if window_state and window_state != WindowState.CLOSED:
state_attr[ATTR_WINDOW_STATE] = str(window_state)
return state_attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"state_attr",
"=",
"super",
"(",
")",
".",
"device_state_attributes",
"for",
"attr",
",",
"attr_key",
"in",
"GROUP_ATTRIBUTES",
".",
"items",
"(",
")",
":",
"attr_value",
"=",
"getattr",
"(",
"self",
".",
"_device",
",",
"attr",
",",
"None",
")",
"if",
"attr_value",
":",
"state_attr",
"[",
"attr_key",
"]",
"=",
"attr_value",
"window_state",
"=",
"getattr",
"(",
"self",
".",
"_device",
",",
"\"windowState\"",
",",
"None",
")",
"if",
"window_state",
"and",
"window_state",
"!=",
"WindowState",
".",
"CLOSED",
":",
"state_attr",
"[",
"ATTR_WINDOW_STATE",
"]",
"=",
"str",
"(",
"window_state",
")",
"return",
"state_attr"
] | [
482,
4
] | [
495,
25
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSecurityZoneSensorGroup.is_on | (self) | Return true if security issue detected. | Return true if security issue detected. | def is_on(self) -> bool:
"""Return true if security issue detected."""
if (
self._device.motionDetected
or self._device.presenceDetected
or self._device.unreach
or self._device.sabotage
):
return True
if (
self._device.windowState is not None
and self._device.windowState != WindowState.CLOSED
):
return True
return False | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"if",
"(",
"self",
".",
"_device",
".",
"motionDetected",
"or",
"self",
".",
"_device",
".",
"presenceDetected",
"or",
"self",
".",
"_device",
".",
"unreach",
"or",
"self",
".",
"_device",
".",
"sabotage",
")",
":",
"return",
"True",
"if",
"(",
"self",
".",
"_device",
".",
"windowState",
"is",
"not",
"None",
"and",
"self",
".",
"_device",
".",
"windowState",
"!=",
"WindowState",
".",
"CLOSED",
")",
":",
"return",
"True",
"return",
"False"
] | [
498,
4
] | [
513,
20
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSecuritySensorGroup.__init__ | (self, hap: HomematicipHAP, device) | Initialize security group. | Initialize security group. | def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize security group."""
super().__init__(hap, device, post="Sensors") | [
"def",
"__init__",
"(",
"self",
",",
"hap",
":",
"HomematicipHAP",
",",
"device",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hap",
",",
"device",
",",
"post",
"=",
"\"Sensors\"",
")"
] | [
521,
4
] | [
523,
53
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSecuritySensorGroup.device_state_attributes | (self) | Return the state attributes of the security group. | Return the state attributes of the security group. | def device_state_attributes(self) -> Dict[str, Any]:
"""Return the state attributes of the security group."""
state_attr = super().device_state_attributes
smoke_detector_at = getattr(self._device, "smokeDetectorAlarmType", None)
if smoke_detector_at:
if smoke_detector_at == SmokeDetectorAlarmType.PRIMARY_ALARM:
state_attr[ATTR_SMOKE_DETECTOR_ALARM] = str(smoke_detector_at)
if smoke_detector_at == SmokeDetectorAlarmType.INTRUSION_ALARM:
state_attr[ATTR_INTRUSION_ALARM] = str(smoke_detector_at)
return state_attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"state_attr",
"=",
"super",
"(",
")",
".",
"device_state_attributes",
"smoke_detector_at",
"=",
"getattr",
"(",
"self",
".",
"_device",
",",
"\"smokeDetectorAlarmType\"",
",",
"None",
")",
"if",
"smoke_detector_at",
":",
"if",
"smoke_detector_at",
"==",
"SmokeDetectorAlarmType",
".",
"PRIMARY_ALARM",
":",
"state_attr",
"[",
"ATTR_SMOKE_DETECTOR_ALARM",
"]",
"=",
"str",
"(",
"smoke_detector_at",
")",
"if",
"smoke_detector_at",
"==",
"SmokeDetectorAlarmType",
".",
"INTRUSION_ALARM",
":",
"state_attr",
"[",
"ATTR_INTRUSION_ALARM",
"]",
"=",
"str",
"(",
"smoke_detector_at",
")",
"return",
"state_attr"
] | [
526,
4
] | [
536,
25
] | python | en | ['en', 'en', 'en'] | True |
HomematicipSecuritySensorGroup.is_on | (self) | Return true if safety issue detected. | Return true if safety issue detected. | def is_on(self) -> bool:
"""Return true if safety issue detected."""
parent_is_on = super().is_on
if parent_is_on:
return True
if (
self._device.powerMainsFailure
or self._device.moistureDetected
or self._device.waterlevelDetected
or self._device.lowBat
or self._device.dutyCycle
):
return True
if (
self._device.smokeDetectorAlarmType is not None
and self._device.smokeDetectorAlarmType != SmokeDetectorAlarmType.IDLE_OFF
):
return True
return False | [
"def",
"is_on",
"(",
"self",
")",
"->",
"bool",
":",
"parent_is_on",
"=",
"super",
"(",
")",
".",
"is_on",
"if",
"parent_is_on",
":",
"return",
"True",
"if",
"(",
"self",
".",
"_device",
".",
"powerMainsFailure",
"or",
"self",
".",
"_device",
".",
"moistureDetected",
"or",
"self",
".",
"_device",
".",
"waterlevelDetected",
"or",
"self",
".",
"_device",
".",
"lowBat",
"or",
"self",
".",
"_device",
".",
"dutyCycle",
")",
":",
"return",
"True",
"if",
"(",
"self",
".",
"_device",
".",
"smokeDetectorAlarmType",
"is",
"not",
"None",
"and",
"self",
".",
"_device",
".",
"smokeDetectorAlarmType",
"!=",
"SmokeDetectorAlarmType",
".",
"IDLE_OFF",
")",
":",
"return",
"True",
"return",
"False"
] | [
539,
4
] | [
560,
20
] | python | en | ['en', 'en', 'en'] | True |
mock_pushbullet | () | Mock pushbullet. | Mock pushbullet. | def mock_pushbullet():
"""Mock pushbullet."""
with patch.object(
PushBullet,
"_get_data",
return_value=json.loads(load_fixture("pushbullet_devices.json")),
):
yield | [
"def",
"mock_pushbullet",
"(",
")",
":",
"with",
"patch",
".",
"object",
"(",
"PushBullet",
",",
"\"_get_data\"",
",",
"return_value",
"=",
"json",
".",
"loads",
"(",
"load_fixture",
"(",
"\"pushbullet_devices.json\"",
")",
")",
",",
")",
":",
"yield"
] | [
14,
0
] | [
21,
13
] | python | en | ['en', 'sv', 'en'] | False |
test_pushbullet_config | (hass, mock_pushbullet) | Test setup. | Test setup. | async def test_pushbullet_config(hass, mock_pushbullet):
"""Test setup."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN] | [
"async",
"def",
"test_pushbullet_config",
"(",
"hass",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]"
] | [
24,
0
] | [
36,
39
] | python | en | ['en', 'haw', 'en'] | False |
test_pushbullet_config_bad | (hass) | Test set up the platform with bad/missing configuration. | Test set up the platform with bad/missing configuration. | async def test_pushbullet_config_bad(hass):
"""Test set up the platform with bad/missing configuration."""
config = {notify.DOMAIN: {"platform": "pushbullet"}}
with assert_setup_component(0) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert not handle_config[notify.DOMAIN] | [
"async",
"def",
"test_pushbullet_config_bad",
"(",
"hass",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"platform\"",
":",
"\"pushbullet\"",
"}",
"}",
"with",
"assert_setup_component",
"(",
"0",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"not",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]"
] | [
39,
0
] | [
45,
43
] | python | en | ['en', 'da', 'en'] | True |
test_pushbullet_push_default | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_default(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {"title": "Test Title", "message": "Test Message"}
await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done()
assert requests_mock.called
assert requests_mock.call_count == 1
expected_body = {"body": "Test Message", "title": "Test Title", "type": "note"}
assert requests_mock.last_request.json() == expected_body | [
"async",
"def",
"test_pushbullet_push_default",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"requests_mock",
".",
"called",
"assert",
"requests_mock",
".",
"call_count",
"==",
"1",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
"}",
"assert",
"requests_mock",
".",
"last_request",
".",
"json",
"(",
")",
"==",
"expected_body"
] | [
48,
0
] | [
74,
61
] | python | en | ['en', 'en', 'en'] | True |
test_pushbullet_push_device | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_device(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {
"title": "Test Title",
"message": "Test Message",
"target": ["device/DESKTOP"],
}
await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done()
assert requests_mock.called
assert requests_mock.call_count == 1
expected_body = {
"body": "Test Message",
"device_iden": "identity1",
"title": "Test Title",
"type": "note",
}
assert requests_mock.last_request.json() == expected_body | [
"async",
"def",
"test_pushbullet_push_device",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
",",
"\"target\"",
":",
"[",
"\"device/DESKTOP\"",
"]",
",",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"requests_mock",
".",
"called",
"assert",
"requests_mock",
".",
"call_count",
"==",
"1",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"device_iden\"",
":",
"\"identity1\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"last_request",
".",
"json",
"(",
")",
"==",
"expected_body"
] | [
77,
0
] | [
112,
61
] | python | en | ['en', 'en', 'en'] | True |
test_pushbullet_push_devices | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_devices(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {
"title": "Test Title",
"message": "Test Message",
"target": ["device/DESKTOP", "device/My iPhone"],
}
await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done()
assert requests_mock.called
assert requests_mock.call_count == 2
assert len(requests_mock.request_history) == 2
expected_body = {
"body": "Test Message",
"device_iden": "identity1",
"title": "Test Title",
"type": "note",
}
assert requests_mock.request_history[0].json() == expected_body
expected_body = {
"body": "Test Message",
"device_iden": "identity2",
"title": "Test Title",
"type": "note",
}
assert requests_mock.request_history[1].json() == expected_body | [
"async",
"def",
"test_pushbullet_push_devices",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
",",
"\"target\"",
":",
"[",
"\"device/DESKTOP\"",
",",
"\"device/My iPhone\"",
"]",
",",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"requests_mock",
".",
"called",
"assert",
"requests_mock",
".",
"call_count",
"==",
"2",
"assert",
"len",
"(",
"requests_mock",
".",
"request_history",
")",
"==",
"2",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"device_iden\"",
":",
"\"identity1\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"request_history",
"[",
"0",
"]",
".",
"json",
"(",
")",
"==",
"expected_body",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"device_iden\"",
":",
"\"identity2\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"request_history",
"[",
"1",
"]",
".",
"json",
"(",
")",
"==",
"expected_body"
] | [
115,
0
] | [
158,
67
] | python | en | ['en', 'en', 'en'] | True |
test_pushbullet_push_email | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_email(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {
"title": "Test Title",
"message": "Test Message",
"target": ["email/[email protected]"],
}
await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done()
assert requests_mock.called
assert requests_mock.call_count == 1
assert len(requests_mock.request_history) == 1
expected_body = {
"body": "Test Message",
"email": "[email protected]",
"title": "Test Title",
"type": "note",
}
assert requests_mock.request_history[0].json() == expected_body | [
"async",
"def",
"test_pushbullet_push_email",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
",",
"\"target\"",
":",
"[",
"\"email/[email protected]\"",
"]",
",",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"requests_mock",
".",
"called",
"assert",
"requests_mock",
".",
"call_count",
"==",
"1",
"assert",
"len",
"(",
"requests_mock",
".",
"request_history",
")",
"==",
"1",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"email\"",
":",
"\"[email protected]\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"request_history",
"[",
"0",
"]",
".",
"json",
"(",
")",
"==",
"expected_body"
] | [
161,
0
] | [
197,
67
] | python | en | ['en', 'en', 'en'] | True |
test_pushbullet_push_mixed | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_mixed(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {
"title": "Test Title",
"message": "Test Message",
"target": ["device/DESKTOP", "email/[email protected]"],
}
await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done()
assert requests_mock.called
assert requests_mock.call_count == 2
assert len(requests_mock.request_history) == 2
expected_body = {
"body": "Test Message",
"device_iden": "identity1",
"title": "Test Title",
"type": "note",
}
assert requests_mock.request_history[0].json() == expected_body
expected_body = {
"body": "Test Message",
"email": "[email protected]",
"title": "Test Title",
"type": "note",
}
assert requests_mock.request_history[1].json() == expected_body | [
"async",
"def",
"test_pushbullet_push_mixed",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
",",
"\"target\"",
":",
"[",
"\"device/DESKTOP\"",
",",
"\"email/[email protected]\"",
"]",
",",
"}",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"requests_mock",
".",
"called",
"assert",
"requests_mock",
".",
"call_count",
"==",
"2",
"assert",
"len",
"(",
"requests_mock",
".",
"request_history",
")",
"==",
"2",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"device_iden\"",
":",
"\"identity1\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"request_history",
"[",
"0",
"]",
".",
"json",
"(",
")",
"==",
"expected_body",
"expected_body",
"=",
"{",
"\"body\"",
":",
"\"Test Message\"",
",",
"\"email\"",
":",
"\"[email protected]\"",
",",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"type\"",
":",
"\"note\"",
",",
"}",
"assert",
"requests_mock",
".",
"request_history",
"[",
"1",
"]",
".",
"json",
"(",
")",
"==",
"expected_body"
] | [
200,
0
] | [
243,
67
] | python | en | ['en', 'en', 'en'] | True |
test_pushbullet_push_no_file | (hass, requests_mock, mock_pushbullet) | Test pushbullet push to default target. | Test pushbullet push to default target. | async def test_pushbullet_push_no_file(hass, requests_mock, mock_pushbullet):
"""Test pushbullet push to default target."""
config = {
notify.DOMAIN: {
"name": "test",
"platform": "pushbullet",
"api_key": "MYFAKEKEY",
}
}
with assert_setup_component(1) as handle_config:
assert await async_setup_component(hass, notify.DOMAIN, config)
await hass.async_block_till_done()
assert handle_config[notify.DOMAIN]
requests_mock.register_uri(
"POST",
"https://api.pushbullet.com/v2/pushes",
status_code=200,
json={"mock_response": "Ok"},
)
data = {
"title": "Test Title",
"message": "Test Message",
"target": ["device/DESKTOP", "device/My iPhone"],
"data": {"file": "not_a_file"},
}
assert not await hass.services.async_call(notify.DOMAIN, "test", data)
await hass.async_block_till_done() | [
"async",
"def",
"test_pushbullet_push_no_file",
"(",
"hass",
",",
"requests_mock",
",",
"mock_pushbullet",
")",
":",
"config",
"=",
"{",
"notify",
".",
"DOMAIN",
":",
"{",
"\"name\"",
":",
"\"test\"",
",",
"\"platform\"",
":",
"\"pushbullet\"",
",",
"\"api_key\"",
":",
"\"MYFAKEKEY\"",
",",
"}",
"}",
"with",
"assert_setup_component",
"(",
"1",
")",
"as",
"handle_config",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"notify",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"handle_config",
"[",
"notify",
".",
"DOMAIN",
"]",
"requests_mock",
".",
"register_uri",
"(",
"\"POST\"",
",",
"\"https://api.pushbullet.com/v2/pushes\"",
",",
"status_code",
"=",
"200",
",",
"json",
"=",
"{",
"\"mock_response\"",
":",
"\"Ok\"",
"}",
",",
")",
"data",
"=",
"{",
"\"title\"",
":",
"\"Test Title\"",
",",
"\"message\"",
":",
"\"Test Message\"",
",",
"\"target\"",
":",
"[",
"\"device/DESKTOP\"",
",",
"\"device/My iPhone\"",
"]",
",",
"\"data\"",
":",
"{",
"\"file\"",
":",
"\"not_a_file\"",
"}",
",",
"}",
"assert",
"not",
"await",
"hass",
".",
"services",
".",
"async_call",
"(",
"notify",
".",
"DOMAIN",
",",
"\"test\"",
",",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
246,
0
] | [
272,
38
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the uptime sensor platform. | Set up the uptime sensor platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the uptime sensor platform."""
name = config.get(CONF_NAME)
units = config.get(CONF_UNIT_OF_MEASUREMENT)
async_add_entities([UptimeSensor(name, units)], True) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"units",
"=",
"config",
".",
"get",
"(",
"CONF_UNIT_OF_MEASUREMENT",
")",
"async_add_entities",
"(",
"[",
"UptimeSensor",
"(",
"name",
",",
"units",
")",
"]",
",",
"True",
")"
] | [
27,
0
] | [
32,
57
] | python | en | ['en', 'da', 'en'] | True |
UptimeSensor.__init__ | (self, name, unit) | Initialize the uptime sensor. | Initialize the uptime sensor. | def __init__(self, name, unit):
"""Initialize the uptime sensor."""
self._name = name
self._unit = unit
self.initial = dt_util.now()
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"unit",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_unit",
"=",
"unit",
"self",
".",
"initial",
"=",
"dt_util",
".",
"now",
"(",
")",
"self",
".",
"_state",
"=",
"None"
] | [
38,
4
] | [
43,
26
] | python | en | ['en', 'en', 'en'] | True |
UptimeSensor.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"
] | [
46,
4
] | [
48,
25
] | python | en | ['en', 'mi', 'en'] | True |
UptimeSensor.icon | (self) | Icon to display in the front end. | Icon to display in the front end. | def icon(self):
"""Icon to display in the front end."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
51,
4
] | [
53,
19
] | python | en | ['en', 'en', 'en'] | True |
UptimeSensor.unit_of_measurement | (self) | Return the unit of measurement the value is expressed in. | Return the unit of measurement the value is expressed in. | def unit_of_measurement(self):
"""Return the unit of measurement the value is expressed in."""
return self._unit | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit"
] | [
56,
4
] | [
58,
25
] | python | en | ['en', 'en', 'en'] | True |
UptimeSensor.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"
] | [
61,
4
] | [
63,
26
] | python | en | ['en', 'en', 'en'] | True |
UptimeSensor.async_update | (self) | Update the state of the sensor. | Update the state of the sensor. | async def async_update(self):
"""Update the state of the sensor."""
delta = dt_util.now() - self.initial
div_factor = 3600
if self.unit_of_measurement == "days":
div_factor *= 24
elif self.unit_of_measurement == "minutes":
div_factor /= 60
elif self.unit_of_measurement == "seconds":
div_factor /= 3600
delta = delta.total_seconds() / div_factor
self._state = round(delta, 2)
_LOGGER.debug("New value: %s", delta) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"delta",
"=",
"dt_util",
".",
"now",
"(",
")",
"-",
"self",
".",
"initial",
"div_factor",
"=",
"3600",
"if",
"self",
".",
"unit_of_measurement",
"==",
"\"days\"",
":",
"div_factor",
"*=",
"24",
"elif",
"self",
".",
"unit_of_measurement",
"==",
"\"minutes\"",
":",
"div_factor",
"/=",
"60",
"elif",
"self",
".",
"unit_of_measurement",
"==",
"\"seconds\"",
":",
"div_factor",
"/=",
"3600",
"delta",
"=",
"delta",
".",
"total_seconds",
"(",
")",
"/",
"div_factor",
"self",
".",
"_state",
"=",
"round",
"(",
"delta",
",",
"2",
")",
"_LOGGER",
".",
"debug",
"(",
"\"New value: %s\"",
",",
"delta",
")"
] | [
65,
4
] | [
79,
45
] | python | en | ['en', 'en', 'en'] | True |
TestCimScenarios.test_order_export | (self) | order.tick, order.src_port_idx, order.dest_port_idx, order.quantity | order.tick, order.src_port_idx, order.dest_port_idx, order.quantity | def test_order_export(self):
"""order.tick, order.src_port_idx, order.dest_port_idx, order.quantity"""
Order = namedtuple("Order", ["tick", "src_port_idx", "dest_port_idx", "quantity"])
exportor = PortOrderExporter(True)
for i in range(5):
exportor.add(Order(0, 0, 1, i + 1))
out_folder = tempfile.gettempdir()
exportor.dump(out_folder)
with open(f"{out_folder}/orders.csv") as fp:
reader = csv.DictReader(fp)
row = 0
for line in reader:
self.assertEqual(row+1, int(line["quantity"]))
row += 1 | [
"def",
"test_order_export",
"(",
"self",
")",
":",
"Order",
"=",
"namedtuple",
"(",
"\"Order\"",
",",
"[",
"\"tick\"",
",",
"\"src_port_idx\"",
",",
"\"dest_port_idx\"",
",",
"\"quantity\"",
"]",
")",
"exportor",
"=",
"PortOrderExporter",
"(",
"True",
")",
"for",
"i",
"in",
"range",
"(",
"5",
")",
":",
"exportor",
".",
"add",
"(",
"Order",
"(",
"0",
",",
"0",
",",
"1",
",",
"i",
"+",
"1",
")",
")",
"out_folder",
"=",
"tempfile",
".",
"gettempdir",
"(",
")",
"exportor",
".",
"dump",
"(",
"out_folder",
")",
"with",
"open",
"(",
"f\"{out_folder}/orders.csv\"",
")",
"as",
"fp",
":",
"reader",
"=",
"csv",
".",
"DictReader",
"(",
"fp",
")",
"row",
"=",
"0",
"for",
"line",
"in",
"reader",
":",
"self",
".",
"assertEqual",
"(",
"row",
"+",
"1",
",",
"int",
"(",
"line",
"[",
"\"quantity\"",
"]",
")",
")",
"row",
"+=",
"1"
] | [
474,
4
] | [
494,
24
] | python | en | ['en', 'ca', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up Xbox media_player from a config entry. | Set up Xbox media_player from a config entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Xbox media_player from a config entry."""
client: XboxLiveClient = hass.data[DOMAIN][entry.entry_id]["client"]
consoles: SmartglassConsoleList = hass.data[DOMAIN][entry.entry_id]["consoles"]
coordinator: XboxUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
"coordinator"
]
async_add_entities(
[XboxRemote(client, console, coordinator) for console in consoles.result]
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"client",
":",
"XboxLiveClient",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"client\"",
"]",
"consoles",
":",
"SmartglassConsoleList",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"consoles\"",
"]",
"coordinator",
":",
"XboxUpdateCoordinator",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"coordinator\"",
"]",
"async_add_entities",
"(",
"[",
"XboxRemote",
"(",
"client",
",",
"console",
",",
"coordinator",
")",
"for",
"console",
"in",
"consoles",
".",
"result",
"]",
")"
] | [
25,
0
] | [
35,
5
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.__init__ | (
self,
client: XboxLiveClient,
console: SmartglassConsole,
coordinator: XboxUpdateCoordinator,
) | Initialize the Xbox Media Player. | Initialize the Xbox Media Player. | def __init__(
self,
client: XboxLiveClient,
console: SmartglassConsole,
coordinator: XboxUpdateCoordinator,
) -> None:
"""Initialize the Xbox Media Player."""
super().__init__(coordinator)
self.client: XboxLiveClient = client
self._console: SmartglassConsole = console | [
"def",
"__init__",
"(",
"self",
",",
"client",
":",
"XboxLiveClient",
",",
"console",
":",
"SmartglassConsole",
",",
"coordinator",
":",
"XboxUpdateCoordinator",
",",
")",
"->",
"None",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"coordinator",
")",
"self",
".",
"client",
":",
"XboxLiveClient",
"=",
"client",
"self",
".",
"_console",
":",
"SmartglassConsole",
"=",
"console"
] | [
41,
4
] | [
50,
50
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.name | (self) | Return the device name. | Return the device name. | def name(self):
"""Return the device name."""
return f"{self._console.name} Remote" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._console.name} Remote\""
] | [
53,
4
] | [
55,
45
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.unique_id | (self) | Console device ID. | Console device ID. | def unique_id(self):
"""Console device ID."""
return self._console.id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_console",
".",
"id"
] | [
58,
4
] | [
60,
31
] | python | en | ['fr', 'en', 'en'] | True |
XboxRemote.data | (self) | Return coordinator data for this console. | Return coordinator data for this console. | def data(self) -> ConsoleData:
"""Return coordinator data for this console."""
return self.coordinator.data.consoles[self._console.id] | [
"def",
"data",
"(",
"self",
")",
"->",
"ConsoleData",
":",
"return",
"self",
".",
"coordinator",
".",
"data",
".",
"consoles",
"[",
"self",
".",
"_console",
".",
"id",
"]"
] | [
63,
4
] | [
65,
63
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.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.data.status.power_state == PowerState.On | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"data",
".",
"status",
".",
"power_state",
"==",
"PowerState",
".",
"On"
] | [
68,
4
] | [
70,
60
] | python | en | ['en', 'fy', 'en'] | True |
XboxRemote.async_turn_on | (self, **kwargs: Any) | Turn the Xbox on. | Turn the Xbox on. | async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the Xbox on."""
await self.client.smartglass.wake_up(self._console.id) | [
"async",
"def",
"async_turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"await",
"self",
".",
"client",
".",
"smartglass",
".",
"wake_up",
"(",
"self",
".",
"_console",
".",
"id",
")"
] | [
72,
4
] | [
74,
62
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.async_turn_off | (self, **kwargs: Any) | Turn the Xbox off. | Turn the Xbox off. | async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the Xbox off."""
await self.client.smartglass.turn_off(self._console.id) | [
"async",
"def",
"async_turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"await",
"self",
".",
"client",
".",
"smartglass",
".",
"turn_off",
"(",
"self",
".",
"_console",
".",
"id",
")"
] | [
76,
4
] | [
78,
63
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.async_send_command | (self, command: Iterable[str], **kwargs: Any) | Send controller or text input to the Xbox. | Send controller or text input to the Xbox. | async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None:
"""Send controller or text input to the Xbox."""
num_repeats = kwargs[ATTR_NUM_REPEATS]
delay = kwargs.get(ATTR_DELAY_SECS, DEFAULT_DELAY_SECS)
for _ in range(num_repeats):
for single_command in command:
try:
button = InputKeyType(single_command)
await self.client.smartglass.press_button(self._console.id, button)
except ValueError:
await self.client.smartglass.insert_text(
self._console.id, single_command
)
await asyncio.sleep(delay) | [
"async",
"def",
"async_send_command",
"(",
"self",
",",
"command",
":",
"Iterable",
"[",
"str",
"]",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"None",
":",
"num_repeats",
"=",
"kwargs",
"[",
"ATTR_NUM_REPEATS",
"]",
"delay",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_DELAY_SECS",
",",
"DEFAULT_DELAY_SECS",
")",
"for",
"_",
"in",
"range",
"(",
"num_repeats",
")",
":",
"for",
"single_command",
"in",
"command",
":",
"try",
":",
"button",
"=",
"InputKeyType",
"(",
"single_command",
")",
"await",
"self",
".",
"client",
".",
"smartglass",
".",
"press_button",
"(",
"self",
".",
"_console",
".",
"id",
",",
"button",
")",
"except",
"ValueError",
":",
"await",
"self",
".",
"client",
".",
"smartglass",
".",
"insert_text",
"(",
"self",
".",
"_console",
".",
"id",
",",
"single_command",
")",
"await",
"asyncio",
".",
"sleep",
"(",
"delay",
")"
] | [
80,
4
] | [
94,
42
] | python | en | ['en', 'en', 'en'] | True |
XboxRemote.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."""
# Turns "XboxOneX" into "Xbox One X" for display
matches = re.finditer(
".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)",
self._console.console_type,
)
model = " ".join([m.group(0) for m in matches])
return {
"identifiers": {(DOMAIN, self._console.id)},
"name": self._console.name,
"manufacturer": "Microsoft",
"model": model,
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"# Turns \"XboxOneX\" into \"Xbox One X\" for display",
"matches",
"=",
"re",
".",
"finditer",
"(",
"\".+?(?:(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|$)\"",
",",
"self",
".",
"_console",
".",
"console_type",
",",
")",
"model",
"=",
"\" \"",
".",
"join",
"(",
"[",
"m",
".",
"group",
"(",
"0",
")",
"for",
"m",
"in",
"matches",
"]",
")",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_console",
".",
"id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"_console",
".",
"name",
",",
"\"manufacturer\"",
":",
"\"Microsoft\"",
",",
"\"model\"",
":",
"model",
",",
"}"
] | [
97,
4
] | [
111,
9
] | python | en | ['ro', 'fr', 'en'] | False |
mock_dev_track | (mock_device_tracker_conf) | Mock device tracker config loading. | Mock device tracker config loading. | def mock_dev_track(mock_device_tracker_conf):
"""Mock device tracker config loading.""" | [
"def",
"mock_dev_track",
"(",
"mock_device_tracker_conf",
")",
":"
] | [
24,
0
] | [
25,
45
] | python | en | ['da', 'en', 'en'] | True |
traccar_client | (loop, hass, aiohttp_client) | Mock client for Traccar (unauthenticated). | Mock client for Traccar (unauthenticated). | async def traccar_client(loop, hass, aiohttp_client):
"""Mock client for Traccar (unauthenticated)."""
assert await async_setup_component(hass, "persistent_notification", {})
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
await hass.async_block_till_done()
with patch("homeassistant.components.device_tracker.legacy.update_config"):
return await aiohttp_client(hass.http.app) | [
"async",
"def",
"traccar_client",
"(",
"loop",
",",
"hass",
",",
"aiohttp_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"persistent_notification\"",
",",
"{",
"}",
")",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"}",
"}",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"with",
"patch",
"(",
"\"homeassistant.components.device_tracker.legacy.update_config\"",
")",
":",
"return",
"await",
"aiohttp_client",
"(",
"hass",
".",
"http",
".",
"app",
")"
] | [
29,
0
] | [
38,
50
] | python | en | ['en', 'en', 'en'] | True |
setup_zones | (loop, hass) | Set up Zone config in HA. | Set up Zone config in HA. | async def setup_zones(loop, hass):
"""Set up Zone config in HA."""
assert await async_setup_component(
hass,
zone.DOMAIN,
{
"zone": {
"name": "Home",
"latitude": HOME_LATITUDE,
"longitude": HOME_LONGITUDE,
"radius": 100,
}
},
)
await hass.async_block_till_done() | [
"async",
"def",
"setup_zones",
"(",
"loop",
",",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"zone",
".",
"DOMAIN",
",",
"{",
"\"zone\"",
":",
"{",
"\"name\"",
":",
"\"Home\"",
",",
"\"latitude\"",
":",
"HOME_LATITUDE",
",",
"\"longitude\"",
":",
"HOME_LONGITUDE",
",",
"\"radius\"",
":",
"100",
",",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")"
] | [
42,
0
] | [
56,
38
] | python | en | ['en', 'en', 'en'] | True |
webhook_id_fixture | (hass, client) | Initialize the Traccar component and get the webhook_id. | Initialize the Traccar component and get the webhook_id. | async def webhook_id_fixture(hass, client):
"""Initialize the Traccar component and get the webhook_id."""
await async_process_ha_core_config(
hass,
{"external_url": "http://example.com"},
)
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": "user"}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM, result
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
await hass.async_block_till_done()
return result["result"].data["webhook_id"] | [
"async",
"def",
"webhook_id_fixture",
"(",
"hass",
",",
"client",
")",
":",
"await",
"async_process_ha_core_config",
"(",
"hass",
",",
"{",
"\"external_url\"",
":",
"\"http://example.com\"",
"}",
",",
")",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_init",
"(",
"DOMAIN",
",",
"context",
"=",
"{",
"\"source\"",
":",
"\"user\"",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_FORM",
",",
"result",
"result",
"=",
"await",
"hass",
".",
"config_entries",
".",
"flow",
".",
"async_configure",
"(",
"result",
"[",
"\"flow_id\"",
"]",
",",
"{",
"}",
")",
"assert",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"return",
"result",
"[",
"\"result\"",
"]",
".",
"data",
"[",
"\"webhook_id\"",
"]"
] | [
60,
0
] | [
75,
46
] | python | en | ['en', 'en', 'en'] | True |
test_missing_data | (hass, client, webhook_id) | Test missing data. | Test missing data. | async def test_missing_data(hass, client, webhook_id):
"""Test missing data."""
url = f"/api/webhook/{webhook_id}"
data = {"lat": "1.0", "lon": "1.1", "id": "123"}
# No data
req = await client.post(url)
await hass.async_block_till_done()
assert req.status == HTTP_UNPROCESSABLE_ENTITY
# No latitude
copy = data.copy()
del copy["lat"]
req = await client.post(url, params=copy)
await hass.async_block_till_done()
assert req.status == HTTP_UNPROCESSABLE_ENTITY
# No device
copy = data.copy()
del copy["id"]
req = await client.post(url, params=copy)
await hass.async_block_till_done()
assert req.status == HTTP_UNPROCESSABLE_ENTITY | [
"async",
"def",
"test_missing_data",
"(",
"hass",
",",
"client",
",",
"webhook_id",
")",
":",
"url",
"=",
"f\"/api/webhook/{webhook_id}\"",
"data",
"=",
"{",
"\"lat\"",
":",
"\"1.0\"",
",",
"\"lon\"",
":",
"\"1.1\"",
",",
"\"id\"",
":",
"\"123\"",
"}",
"# No data",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_UNPROCESSABLE_ENTITY",
"# No latitude",
"copy",
"=",
"data",
".",
"copy",
"(",
")",
"del",
"copy",
"[",
"\"lat\"",
"]",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"copy",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_UNPROCESSABLE_ENTITY",
"# No device",
"copy",
"=",
"data",
".",
"copy",
"(",
")",
"del",
"copy",
"[",
"\"id\"",
"]",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"copy",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_UNPROCESSABLE_ENTITY"
] | [
78,
0
] | [
100,
50
] | python | de | ['de', 'no', 'en'] | False |
test_enter_and_exit | (hass, client, webhook_id) | Test when there is a known zone. | Test when there is a known zone. | async def test_enter_and_exit(hass, client, webhook_id):
"""Test when there is a known zone."""
url = f"/api/webhook/{webhook_id}"
data = {"lat": str(HOME_LATITUDE), "lon": str(HOME_LONGITUDE), "id": "123"}
# Enter the Home
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
assert STATE_HOME == state_name
# Enter Home again
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
assert STATE_HOME == state_name
data["lon"] = 0
data["lat"] = 0
# Enter Somewhere else
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
assert STATE_NOT_HOME == state_name
dev_reg = await hass.helpers.device_registry.async_get_registry()
assert len(dev_reg.devices) == 1
ent_reg = await hass.helpers.entity_registry.async_get_registry()
assert len(ent_reg.entities) == 1 | [
"async",
"def",
"test_enter_and_exit",
"(",
"hass",
",",
"client",
",",
"webhook_id",
")",
":",
"url",
"=",
"f\"/api/webhook/{webhook_id}\"",
"data",
"=",
"{",
"\"lat\"",
":",
"str",
"(",
"HOME_LATITUDE",
")",
",",
"\"lon\"",
":",
"str",
"(",
"HOME_LONGITUDE",
")",
",",
"\"id\"",
":",
"\"123\"",
"}",
"# Enter the Home",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state_name",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
".",
"state",
"assert",
"STATE_HOME",
"==",
"state_name",
"# Enter Home again",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state_name",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
".",
"state",
"assert",
"STATE_HOME",
"==",
"state_name",
"data",
"[",
"\"lon\"",
"]",
"=",
"0",
"data",
"[",
"\"lat\"",
"]",
"=",
"0",
"# Enter Somewhere else",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state_name",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
".",
"state",
"assert",
"STATE_NOT_HOME",
"==",
"state_name",
"dev_reg",
"=",
"await",
"hass",
".",
"helpers",
".",
"device_registry",
".",
"async_get_registry",
"(",
")",
"assert",
"len",
"(",
"dev_reg",
".",
"devices",
")",
"==",
"1",
"ent_reg",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"assert",
"len",
"(",
"ent_reg",
".",
"entities",
")",
"==",
"1"
] | [
103,
0
] | [
142,
37
] | python | en | ['en', 'en', 'en'] | True |
test_enter_with_attrs | (hass, client, webhook_id) | Test when additional attributes are present. | Test when additional attributes are present. | async def test_enter_with_attrs(hass, client, webhook_id):
"""Test when additional attributes are present."""
url = f"/api/webhook/{webhook_id}"
data = {
"timestamp": 123456789,
"lat": "1.0",
"lon": "1.1",
"id": "123",
"accuracy": "10.5",
"batt": 10,
"speed": 100,
"bearing": "105.32",
"altitude": 102,
}
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
assert state.state == STATE_NOT_HOME
assert state.attributes["gps_accuracy"] == 10.5
assert state.attributes["battery_level"] == 10.0
assert state.attributes["speed"] == 100.0
assert state.attributes["bearing"] == 105.32
assert state.attributes["altitude"] == 102.0
data = {
"lat": str(HOME_LATITUDE),
"lon": str(HOME_LONGITUDE),
"id": "123",
"accuracy": 123,
"batt": 23,
"speed": 23,
"bearing": 123,
"altitude": 123,
}
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"]))
assert state.state == STATE_HOME
assert state.attributes["gps_accuracy"] == 123
assert state.attributes["battery_level"] == 23
assert state.attributes["speed"] == 23
assert state.attributes["bearing"] == 123
assert state.attributes["altitude"] == 123 | [
"async",
"def",
"test_enter_with_attrs",
"(",
"hass",
",",
"client",
",",
"webhook_id",
")",
":",
"url",
"=",
"f\"/api/webhook/{webhook_id}\"",
"data",
"=",
"{",
"\"timestamp\"",
":",
"123456789",
",",
"\"lat\"",
":",
"\"1.0\"",
",",
"\"lon\"",
":",
"\"1.1\"",
",",
"\"id\"",
":",
"\"123\"",
",",
"\"accuracy\"",
":",
"\"10.5\"",
",",
"\"batt\"",
":",
"10",
",",
"\"speed\"",
":",
"100",
",",
"\"bearing\"",
":",
"\"105.32\"",
",",
"\"altitude\"",
":",
"102",
",",
"}",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_NOT_HOME",
"assert",
"state",
".",
"attributes",
"[",
"\"gps_accuracy\"",
"]",
"==",
"10.5",
"assert",
"state",
".",
"attributes",
"[",
"\"battery_level\"",
"]",
"==",
"10.0",
"assert",
"state",
".",
"attributes",
"[",
"\"speed\"",
"]",
"==",
"100.0",
"assert",
"state",
".",
"attributes",
"[",
"\"bearing\"",
"]",
"==",
"105.32",
"assert",
"state",
".",
"attributes",
"[",
"\"altitude\"",
"]",
"==",
"102.0",
"data",
"=",
"{",
"\"lat\"",
":",
"str",
"(",
"HOME_LATITUDE",
")",
",",
"\"lon\"",
":",
"str",
"(",
"HOME_LONGITUDE",
")",
",",
"\"id\"",
":",
"\"123\"",
",",
"\"accuracy\"",
":",
"123",
",",
"\"batt\"",
":",
"23",
",",
"\"speed\"",
":",
"23",
",",
"\"bearing\"",
":",
"123",
",",
"\"altitude\"",
":",
"123",
",",
"}",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_HOME",
"assert",
"state",
".",
"attributes",
"[",
"\"gps_accuracy\"",
"]",
"==",
"123",
"assert",
"state",
".",
"attributes",
"[",
"\"battery_level\"",
"]",
"==",
"23",
"assert",
"state",
".",
"attributes",
"[",
"\"speed\"",
"]",
"==",
"23",
"assert",
"state",
".",
"attributes",
"[",
"\"bearing\"",
"]",
"==",
"123",
"assert",
"state",
".",
"attributes",
"[",
"\"altitude\"",
"]",
"==",
"123"
] | [
145,
0
] | [
191,
46
] | python | en | ['en', 'en', 'en'] | True |
test_two_devices | (hass, client, webhook_id) | Test updating two different devices. | Test updating two different devices. | async def test_two_devices(hass, client, webhook_id):
"""Test updating two different devices."""
url = f"/api/webhook/{webhook_id}"
data_device_1 = {"lat": "1.0", "lon": "1.1", "id": "device_1"}
# Exit Home
req = await client.post(url, params=data_device_1)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["id"]))
assert state.state == "not_home"
# Enter Home
data_device_2 = dict(data_device_1)
data_device_2["lat"] = str(HOME_LATITUDE)
data_device_2["lon"] = str(HOME_LONGITUDE)
data_device_2["id"] = "device_2"
req = await client.post(url, params=data_device_2)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_2["id"]))
assert state.state == "home"
state = hass.states.get("{}.{}".format(DEVICE_TRACKER_DOMAIN, data_device_1["id"]))
assert state.state == "not_home" | [
"async",
"def",
"test_two_devices",
"(",
"hass",
",",
"client",
",",
"webhook_id",
")",
":",
"url",
"=",
"f\"/api/webhook/{webhook_id}\"",
"data_device_1",
"=",
"{",
"\"lat\"",
":",
"\"1.0\"",
",",
"\"lon\"",
":",
"\"1.1\"",
",",
"\"id\"",
":",
"\"device_1\"",
"}",
"# Exit Home",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data_device_1",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data_device_1",
"[",
"\"id\"",
"]",
")",
")",
"assert",
"state",
".",
"state",
"==",
"\"not_home\"",
"# Enter Home",
"data_device_2",
"=",
"dict",
"(",
"data_device_1",
")",
"data_device_2",
"[",
"\"lat\"",
"]",
"=",
"str",
"(",
"HOME_LATITUDE",
")",
"data_device_2",
"[",
"\"lon\"",
"]",
"=",
"str",
"(",
"HOME_LONGITUDE",
")",
"data_device_2",
"[",
"\"id\"",
"]",
"=",
"\"device_2\"",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data_device_2",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data_device_2",
"[",
"\"id\"",
"]",
")",
")",
"assert",
"state",
".",
"state",
"==",
"\"home\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data_device_1",
"[",
"\"id\"",
"]",
")",
")",
"assert",
"state",
".",
"state",
"==",
"\"not_home\""
] | [
194,
0
] | [
220,
36
] | python | en | ['en', 'en', 'en'] | True |
test_load_unload_entry | (hass, client, webhook_id) | Test that the appropriate dispatch signals are added and removed. | Test that the appropriate dispatch signals are added and removed. | async def test_load_unload_entry(hass, client, webhook_id):
"""Test that the appropriate dispatch signals are added and removed."""
url = f"/api/webhook/{webhook_id}"
data = {"lat": str(HOME_LATITUDE), "lon": str(HOME_LONGITUDE), "id": "123"}
# Enter the Home
req = await client.post(url, params=data)
await hass.async_block_till_done()
assert req.status == HTTP_OK
state_name = hass.states.get(
"{}.{}".format(DEVICE_TRACKER_DOMAIN, data["id"])
).state
assert STATE_HOME == state_name
assert len(hass.data[DATA_DISPATCHER][TRACKER_UPDATE]) == 1
entry = hass.config_entries.async_entries(DOMAIN)[0]
assert await traccar.async_unload_entry(hass, entry)
await hass.async_block_till_done()
assert not hass.data[DATA_DISPATCHER][TRACKER_UPDATE] | [
"async",
"def",
"test_load_unload_entry",
"(",
"hass",
",",
"client",
",",
"webhook_id",
")",
":",
"url",
"=",
"f\"/api/webhook/{webhook_id}\"",
"data",
"=",
"{",
"\"lat\"",
":",
"str",
"(",
"HOME_LATITUDE",
")",
",",
"\"lon\"",
":",
"str",
"(",
"HOME_LONGITUDE",
")",
",",
"\"id\"",
":",
"\"123\"",
"}",
"# Enter the Home",
"req",
"=",
"await",
"client",
".",
"post",
"(",
"url",
",",
"params",
"=",
"data",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"req",
".",
"status",
"==",
"HTTP_OK",
"state_name",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"{}.{}\"",
".",
"format",
"(",
"DEVICE_TRACKER_DOMAIN",
",",
"data",
"[",
"\"id\"",
"]",
")",
")",
".",
"state",
"assert",
"STATE_HOME",
"==",
"state_name",
"assert",
"len",
"(",
"hass",
".",
"data",
"[",
"DATA_DISPATCHER",
"]",
"[",
"TRACKER_UPDATE",
"]",
")",
"==",
"1",
"entry",
"=",
"hass",
".",
"config_entries",
".",
"async_entries",
"(",
"DOMAIN",
")",
"[",
"0",
"]",
"assert",
"await",
"traccar",
".",
"async_unload_entry",
"(",
"hass",
",",
"entry",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"not",
"hass",
".",
"data",
"[",
"DATA_DISPATCHER",
"]",
"[",
"TRACKER_UPDATE",
"]"
] | [
226,
0
] | [
245,
57
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the departure sensor. | Set up the departure sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the departure sensor."""
httpsession = async_get_clientsession(hass)
train_api = TrafikverketTrain(httpsession, config[CONF_API_KEY])
sensors = []
station_cache = {}
for train in config[CONF_TRAINS]:
try:
trainstops = [train[CONF_FROM], train[CONF_TO]]
for station in trainstops:
if station not in station_cache:
station_cache[station] = await train_api.async_get_train_station(
station
)
except ValueError as station_error:
if "Invalid authentication" in station_error.args[0]:
_LOGGER.error("Unable to set up up component: %s", station_error)
return
_LOGGER.error(
"Problem when trying station %s to %s. Error: %s ",
train[CONF_FROM],
train[CONF_TO],
station_error,
)
continue
sensor = TrainSensor(
train_api,
train[CONF_NAME],
station_cache[train[CONF_FROM]],
station_cache[train[CONF_TO]],
train[CONF_WEEKDAY],
train.get(CONF_TIME),
)
sensors.append(sensor)
async_add_entities(sensors, update_before_add=True) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"httpsession",
"=",
"async_get_clientsession",
"(",
"hass",
")",
"train_api",
"=",
"TrafikverketTrain",
"(",
"httpsession",
",",
"config",
"[",
"CONF_API_KEY",
"]",
")",
"sensors",
"=",
"[",
"]",
"station_cache",
"=",
"{",
"}",
"for",
"train",
"in",
"config",
"[",
"CONF_TRAINS",
"]",
":",
"try",
":",
"trainstops",
"=",
"[",
"train",
"[",
"CONF_FROM",
"]",
",",
"train",
"[",
"CONF_TO",
"]",
"]",
"for",
"station",
"in",
"trainstops",
":",
"if",
"station",
"not",
"in",
"station_cache",
":",
"station_cache",
"[",
"station",
"]",
"=",
"await",
"train_api",
".",
"async_get_train_station",
"(",
"station",
")",
"except",
"ValueError",
"as",
"station_error",
":",
"if",
"\"Invalid authentication\"",
"in",
"station_error",
".",
"args",
"[",
"0",
"]",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unable to set up up component: %s\"",
",",
"station_error",
")",
"return",
"_LOGGER",
".",
"error",
"(",
"\"Problem when trying station %s to %s. Error: %s \"",
",",
"train",
"[",
"CONF_FROM",
"]",
",",
"train",
"[",
"CONF_TO",
"]",
",",
"station_error",
",",
")",
"continue",
"sensor",
"=",
"TrainSensor",
"(",
"train_api",
",",
"train",
"[",
"CONF_NAME",
"]",
",",
"station_cache",
"[",
"train",
"[",
"CONF_FROM",
"]",
"]",
",",
"station_cache",
"[",
"train",
"[",
"CONF_TO",
"]",
"]",
",",
"train",
"[",
"CONF_WEEKDAY",
"]",
",",
"train",
".",
"get",
"(",
"CONF_TIME",
")",
",",
")",
"sensors",
".",
"append",
"(",
"sensor",
")",
"async_add_entities",
"(",
"sensors",
",",
"update_before_add",
"=",
"True",
")"
] | [
57,
0
] | [
94,
55
] | python | en | ['en', 'da', 'en'] | True |
next_weekday | (fromdate, weekday) | Return the date of the next time a specific weekday happen. | Return the date of the next time a specific weekday happen. | def next_weekday(fromdate, weekday):
"""Return the date of the next time a specific weekday happen."""
days_ahead = weekday - fromdate.weekday()
if days_ahead <= 0:
days_ahead += 7
return fromdate + timedelta(days_ahead) | [
"def",
"next_weekday",
"(",
"fromdate",
",",
"weekday",
")",
":",
"days_ahead",
"=",
"weekday",
"-",
"fromdate",
".",
"weekday",
"(",
")",
"if",
"days_ahead",
"<=",
"0",
":",
"days_ahead",
"+=",
"7",
"return",
"fromdate",
"+",
"timedelta",
"(",
"days_ahead",
")"
] | [
97,
0
] | [
102,
43
] | python | en | ['en', 'en', 'en'] | True |
next_departuredate | (departure) | Calculate the next departuredate from an array input of short days. | Calculate the next departuredate from an array input of short days. | def next_departuredate(departure):
"""Calculate the next departuredate from an array input of short days."""
today_date = date.today()
today_weekday = date.weekday(today_date)
if WEEKDAYS[today_weekday] in departure:
return today_date
for day in departure:
next_departure = WEEKDAYS.index(day)
if next_departure > today_weekday:
return next_weekday(today_date, next_departure)
return next_weekday(today_date, WEEKDAYS.index(departure[0])) | [
"def",
"next_departuredate",
"(",
"departure",
")",
":",
"today_date",
"=",
"date",
".",
"today",
"(",
")",
"today_weekday",
"=",
"date",
".",
"weekday",
"(",
"today_date",
")",
"if",
"WEEKDAYS",
"[",
"today_weekday",
"]",
"in",
"departure",
":",
"return",
"today_date",
"for",
"day",
"in",
"departure",
":",
"next_departure",
"=",
"WEEKDAYS",
".",
"index",
"(",
"day",
")",
"if",
"next_departure",
">",
"today_weekday",
":",
"return",
"next_weekday",
"(",
"today_date",
",",
"next_departure",
")",
"return",
"next_weekday",
"(",
"today_date",
",",
"WEEKDAYS",
".",
"index",
"(",
"departure",
"[",
"0",
"]",
")",
")"
] | [
105,
0
] | [
115,
65
] | python | en | ['en', 'lb', 'en'] | True |
TrainSensor.__init__ | (self, train_api, name, from_station, to_station, weekday, time) | Initialize the sensor. | Initialize the sensor. | def __init__(self, train_api, name, from_station, to_station, weekday, time):
"""Initialize the sensor."""
self._train_api = train_api
self._name = name
self._from_station = from_station
self._to_station = to_station
self._weekday = weekday
self._time = time
self._state = None
self._departure_state = None
self._delay_in_minutes = None | [
"def",
"__init__",
"(",
"self",
",",
"train_api",
",",
"name",
",",
"from_station",
",",
"to_station",
",",
"weekday",
",",
"time",
")",
":",
"self",
".",
"_train_api",
"=",
"train_api",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_from_station",
"=",
"from_station",
"self",
".",
"_to_station",
"=",
"to_station",
"self",
".",
"_weekday",
"=",
"weekday",
"self",
".",
"_time",
"=",
"time",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_departure_state",
"=",
"None",
"self",
".",
"_delay_in_minutes",
"=",
"None"
] | [
121,
4
] | [
131,
37
] | python | en | ['en', 'en', 'en'] | True |
TrainSensor.async_update | (self) | Retrieve latest state. | Retrieve latest state. | async def async_update(self):
"""Retrieve latest state."""
if self._time is not None:
departure_day = next_departuredate(self._weekday)
when = datetime.combine(departure_day, self._time)
try:
self._state = await self._train_api.async_get_train_stop(
self._from_station, self._to_station, when
)
except ValueError as output_error:
_LOGGER.error(
"Departure %s encountered a problem: %s", when, output_error
)
else:
when = datetime.now()
self._state = await self._train_api.async_get_next_train_stop(
self._from_station, self._to_station, when
)
self._departure_state = self._state.get_state().name
self._delay_in_minutes = self._state.get_delay_time() | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"if",
"self",
".",
"_time",
"is",
"not",
"None",
":",
"departure_day",
"=",
"next_departuredate",
"(",
"self",
".",
"_weekday",
")",
"when",
"=",
"datetime",
".",
"combine",
"(",
"departure_day",
",",
"self",
".",
"_time",
")",
"try",
":",
"self",
".",
"_state",
"=",
"await",
"self",
".",
"_train_api",
".",
"async_get_train_stop",
"(",
"self",
".",
"_from_station",
",",
"self",
".",
"_to_station",
",",
"when",
")",
"except",
"ValueError",
"as",
"output_error",
":",
"_LOGGER",
".",
"error",
"(",
"\"Departure %s encountered a problem: %s\"",
",",
"when",
",",
"output_error",
")",
"else",
":",
"when",
"=",
"datetime",
".",
"now",
"(",
")",
"self",
".",
"_state",
"=",
"await",
"self",
".",
"_train_api",
".",
"async_get_next_train_stop",
"(",
"self",
".",
"_from_station",
",",
"self",
".",
"_to_station",
",",
"when",
")",
"self",
".",
"_departure_state",
"=",
"self",
".",
"_state",
".",
"get_state",
"(",
")",
".",
"name",
"self",
".",
"_delay_in_minutes",
"=",
"self",
".",
"_state",
".",
"get_delay_time",
"(",
")"
] | [
133,
4
] | [
152,
61
] | python | en | ['es', 'sk', 'en'] | False |
TrainSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
if self._state is None:
return None
state = self._state
other_information = None
if state.other_information is not None:
other_information = ", ".join(state.other_information)
deviations = None
if state.deviations is not None:
deviations = ", ".join(state.deviations)
if self._delay_in_minutes is not None:
self._delay_in_minutes = self._delay_in_minutes.total_seconds() / 60
return {
ATTR_DEPARTURE_STATE: self._departure_state,
ATTR_CANCELED: state.canceled,
ATTR_DELAY_TIME: self._delay_in_minutes,
ATTR_PLANNED_TIME: state.advertised_time_at_location,
ATTR_ESTIMATED_TIME: state.estimated_time_at_location,
ATTR_ACTUAL_TIME: state.time_at_location,
ATTR_OTHER_INFORMATION: other_information,
ATTR_DEVIATIONS: deviations,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"is",
"None",
":",
"return",
"None",
"state",
"=",
"self",
".",
"_state",
"other_information",
"=",
"None",
"if",
"state",
".",
"other_information",
"is",
"not",
"None",
":",
"other_information",
"=",
"\", \"",
".",
"join",
"(",
"state",
".",
"other_information",
")",
"deviations",
"=",
"None",
"if",
"state",
".",
"deviations",
"is",
"not",
"None",
":",
"deviations",
"=",
"\", \"",
".",
"join",
"(",
"state",
".",
"deviations",
")",
"if",
"self",
".",
"_delay_in_minutes",
"is",
"not",
"None",
":",
"self",
".",
"_delay_in_minutes",
"=",
"self",
".",
"_delay_in_minutes",
".",
"total_seconds",
"(",
")",
"/",
"60",
"return",
"{",
"ATTR_DEPARTURE_STATE",
":",
"self",
".",
"_departure_state",
",",
"ATTR_CANCELED",
":",
"state",
".",
"canceled",
",",
"ATTR_DELAY_TIME",
":",
"self",
".",
"_delay_in_minutes",
",",
"ATTR_PLANNED_TIME",
":",
"state",
".",
"advertised_time_at_location",
",",
"ATTR_ESTIMATED_TIME",
":",
"state",
".",
"estimated_time_at_location",
",",
"ATTR_ACTUAL_TIME",
":",
"state",
".",
"time_at_location",
",",
"ATTR_OTHER_INFORMATION",
":",
"other_information",
",",
"ATTR_DEVIATIONS",
":",
"deviations",
",",
"}"
] | [
155,
4
] | [
177,
9
] | python | en | ['en', 'en', 'en'] | True |
TrainSensor.device_class | (self) | Return the device class. | Return the device class. | def device_class(self):
"""Return the device class."""
return DEVICE_CLASS_TIMESTAMP | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"DEVICE_CLASS_TIMESTAMP"
] | [
180,
4
] | [
182,
37
] | python | en | ['en', 'en', 'en'] | True |
TrainSensor.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"
] | [
185,
4
] | [
187,
25
] | python | en | ['en', 'mi', 'en'] | True |
TrainSensor.icon | (self) | Return the icon for the frontend. | Return the icon for the frontend. | def icon(self):
"""Return the icon for the frontend."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
190,
4
] | [
192,
19
] | python | en | ['en', 'en', 'en'] | True |
TrainSensor.state | (self) | Return the departure state. | Return the departure state. | def state(self):
"""Return the departure state."""
state = self._state
if state is not None:
if state.time_at_location is not None:
return state.time_at_location
if state.estimated_time_at_location is not None:
return state.estimated_time_at_location
return state.advertised_time_at_location
return None | [
"def",
"state",
"(",
"self",
")",
":",
"state",
"=",
"self",
".",
"_state",
"if",
"state",
"is",
"not",
"None",
":",
"if",
"state",
".",
"time_at_location",
"is",
"not",
"None",
":",
"return",
"state",
".",
"time_at_location",
"if",
"state",
".",
"estimated_time_at_location",
"is",
"not",
"None",
":",
"return",
"state",
".",
"estimated_time_at_location",
"return",
"state",
".",
"advertised_time_at_location",
"return",
"None"
] | [
195,
4
] | [
204,
19
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.__init__ | (self, device: HomeConnectDevice, desc: str) | Initialize the entity. | Initialize the entity. | def __init__(self, device: HomeConnectDevice, desc: str) -> None:
"""Initialize the entity."""
self.device = device
self.desc = desc
self._name = f"{self.device.appliance.name} {desc}" | [
"def",
"__init__",
"(",
"self",
",",
"device",
":",
"HomeConnectDevice",
",",
"desc",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"device",
"=",
"device",
"self",
".",
"desc",
"=",
"desc",
"self",
".",
"_name",
"=",
"f\"{self.device.appliance.name} {desc}\""
] | [
17,
4
] | [
21,
59
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.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_ENTITIES, self._update_callback
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"self",
".",
"async_on_remove",
"(",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"SIGNAL_UPDATE_ENTITIES",
",",
"self",
".",
"_update_callback",
")",
")"
] | [
23,
4
] | [
29,
9
] | python | en | ['en', 'no', 'en'] | False |
HomeConnectEntity._update_callback | (self, ha_id) | Update data. | Update data. | def _update_callback(self, ha_id):
"""Update data."""
if ha_id == self.device.appliance.haId:
self.async_entity_update() | [
"def",
"_update_callback",
"(",
"self",
",",
"ha_id",
")",
":",
"if",
"ha_id",
"==",
"self",
".",
"device",
".",
"appliance",
".",
"haId",
":",
"self",
".",
"async_entity_update",
"(",
")"
] | [
32,
4
] | [
35,
38
] | python | co | ['fr', 'co', 'en'] | False |
HomeConnectEntity.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
38,
4
] | [
40,
20
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.name | (self) | Return the name of the node (used for Entity_ID). | Return the name of the node (used for Entity_ID). | def name(self):
"""Return the name of the node (used for Entity_ID)."""
return self._name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_name"
] | [
43,
4
] | [
45,
25
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.unique_id | (self) | Return the unique id base on the id returned by Home Connect and the entity name. | Return the unique id base on the id returned by Home Connect and the entity name. | def unique_id(self):
"""Return the unique id base on the id returned by Home Connect and the entity name."""
return f"{self.device.appliance.haId}-{self.desc}" | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"f\"{self.device.appliance.haId}-{self.desc}\""
] | [
48,
4
] | [
50,
58
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.device_info | (self) | Return info about the device. | Return info about the device. | def device_info(self):
"""Return info about the device."""
return {
"identifiers": {(DOMAIN, self.device.appliance.haId)},
"name": self.device.appliance.name,
"manufacturer": self.device.appliance.brand,
"model": self.device.appliance.vib,
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"device",
".",
"appliance",
".",
"haId",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"device",
".",
"appliance",
".",
"name",
",",
"\"manufacturer\"",
":",
"self",
".",
"device",
".",
"appliance",
".",
"brand",
",",
"\"model\"",
":",
"self",
".",
"device",
".",
"appliance",
".",
"vib",
",",
"}"
] | [
53,
4
] | [
60,
9
] | python | en | ['en', 'en', 'en'] | True |
HomeConnectEntity.async_entity_update | (self) | Update the entity. | Update the entity. | def async_entity_update(self):
"""Update the entity."""
_LOGGER.debug("Entity update triggered on %s", self)
self.async_schedule_update_ha_state(True) | [
"def",
"async_entity_update",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Entity update triggered on %s\"",
",",
"self",
")",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
63,
4
] | [
66,
49
] | python | en | ['en', 'en', 'en'] | True |
install_multiple_zeroconf_catcher | (hass_zc) | Wrap the Zeroconf class to return the shared instance if multiple instances are detected. | Wrap the Zeroconf class to return the shared instance if multiple instances are detected. | def install_multiple_zeroconf_catcher(hass_zc) -> None:
"""Wrap the Zeroconf class to return the shared instance if multiple instances are detected."""
def new_zeroconf_new(self, *k, **kw):
_report(
"attempted to create another Zeroconf instance. Please use the shared Zeroconf via await homeassistant.components.zeroconf.async_get_instance(hass)",
)
return hass_zc
def new_zeroconf_init(self, *k, **kw):
return
zeroconf.Zeroconf.__new__ = new_zeroconf_new
zeroconf.Zeroconf.__init__ = new_zeroconf_init | [
"def",
"install_multiple_zeroconf_catcher",
"(",
"hass_zc",
")",
"->",
"None",
":",
"def",
"new_zeroconf_new",
"(",
"self",
",",
"*",
"k",
",",
"*",
"*",
"kw",
")",
":",
"_report",
"(",
"\"attempted to create another Zeroconf instance. Please use the shared Zeroconf via await homeassistant.components.zeroconf.async_get_instance(hass)\"",
",",
")",
"return",
"hass_zc",
"def",
"new_zeroconf_init",
"(",
"self",
",",
"*",
"k",
",",
"*",
"*",
"kw",
")",
":",
"return",
"zeroconf",
".",
"Zeroconf",
".",
"__new__",
"=",
"new_zeroconf_new",
"zeroconf",
".",
"Zeroconf",
".",
"__init__",
"=",
"new_zeroconf_init"
] | [
15,
0
] | [
28,
50
] | python | en | ['en', 'en', 'en'] | True |
_report | (what: str) | Report incorrect usage.
Async friendly.
| Report incorrect usage. | def _report(what: str) -> None:
"""Report incorrect usage.
Async friendly.
"""
integration_frame = None
try:
integration_frame = get_integration_frame(exclude_integrations={"zeroconf"})
except MissingIntegrationFrame:
pass
if not integration_frame:
_LOGGER.warning(
"Detected code that %s. Please report this issue.", what, stack_info=True
)
return
report_integration(what, integration_frame) | [
"def",
"_report",
"(",
"what",
":",
"str",
")",
"->",
"None",
":",
"integration_frame",
"=",
"None",
"try",
":",
"integration_frame",
"=",
"get_integration_frame",
"(",
"exclude_integrations",
"=",
"{",
"\"zeroconf\"",
"}",
")",
"except",
"MissingIntegrationFrame",
":",
"pass",
"if",
"not",
"integration_frame",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Detected code that %s. Please report this issue.\"",
",",
"what",
",",
"stack_info",
"=",
"True",
")",
"return",
"report_integration",
"(",
"what",
",",
"integration_frame",
")"
] | [
31,
0
] | [
49,
47
] | python | en | ['en', 'en', 'en'] | True |
_device_id_validator | (config) | Ensure that inverters have default id 1 and other devices 0. | Ensure that inverters have default id 1 and other devices 0. | def _device_id_validator(config):
"""Ensure that inverters have default id 1 and other devices 0."""
config = copy.deepcopy(config)
for cond in config[CONF_MONITORED_CONDITIONS]:
if CONF_DEVICE not in cond:
if cond[CONF_SENSOR_TYPE] == TYPE_INVERTER:
cond[CONF_DEVICE] = DEFAULT_INVERTER
else:
cond[CONF_DEVICE] = DEFAULT_DEVICE
return config | [
"def",
"_device_id_validator",
"(",
"config",
")",
":",
"config",
"=",
"copy",
".",
"deepcopy",
"(",
"config",
")",
"for",
"cond",
"in",
"config",
"[",
"CONF_MONITORED_CONDITIONS",
"]",
":",
"if",
"CONF_DEVICE",
"not",
"in",
"cond",
":",
"if",
"cond",
"[",
"CONF_SENSOR_TYPE",
"]",
"==",
"TYPE_INVERTER",
":",
"cond",
"[",
"CONF_DEVICE",
"]",
"=",
"DEFAULT_INVERTER",
"else",
":",
"cond",
"[",
"CONF_DEVICE",
"]",
"=",
"DEFAULT_DEVICE",
"return",
"config"
] | [
41,
0
] | [
50,
17
] | python | en | ['en', 'en', 'en'] | True |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up of Fronius platform. | Set up of Fronius platform. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up of Fronius platform."""
session = async_get_clientsession(hass)
fronius = Fronius(session, config[CONF_RESOURCE])
scan_interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
adapters = []
# Creates all adapters for monitored conditions
for condition in config[CONF_MONITORED_CONDITIONS]:
device = condition[CONF_DEVICE]
sensor_type = condition[CONF_SENSOR_TYPE]
scope = condition[CONF_SCOPE]
name = f"Fronius {condition[CONF_SENSOR_TYPE].replace('_', ' ').capitalize()} {device if scope == SCOPE_DEVICE else SCOPE_SYSTEM} {config[CONF_RESOURCE]}"
if sensor_type == TYPE_INVERTER:
if scope == SCOPE_SYSTEM:
adapter_cls = FroniusInverterSystem
else:
adapter_cls = FroniusInverterDevice
elif sensor_type == TYPE_METER:
if scope == SCOPE_SYSTEM:
adapter_cls = FroniusMeterSystem
else:
adapter_cls = FroniusMeterDevice
elif sensor_type == TYPE_POWER_FLOW:
adapter_cls = FroniusPowerFlow
else:
adapter_cls = FroniusStorage
adapters.append(adapter_cls(fronius, name, device, async_add_entities))
# Creates a lamdba that fetches an update when called
def adapter_data_fetcher(data_adapter):
async def fetch_data(*_):
await data_adapter.async_update()
return fetch_data
# Set up the fetching in a fixed interval for each adapter
for adapter in adapters:
fetch = adapter_data_fetcher(adapter)
# fetch data once at set-up
await fetch()
async_track_time_interval(hass, fetch, scan_interval) | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"session",
"=",
"async_get_clientsession",
"(",
"hass",
")",
"fronius",
"=",
"Fronius",
"(",
"session",
",",
"config",
"[",
"CONF_RESOURCE",
"]",
")",
"scan_interval",
"=",
"config",
".",
"get",
"(",
"CONF_SCAN_INTERVAL",
",",
"DEFAULT_SCAN_INTERVAL",
")",
"adapters",
"=",
"[",
"]",
"# Creates all adapters for monitored conditions",
"for",
"condition",
"in",
"config",
"[",
"CONF_MONITORED_CONDITIONS",
"]",
":",
"device",
"=",
"condition",
"[",
"CONF_DEVICE",
"]",
"sensor_type",
"=",
"condition",
"[",
"CONF_SENSOR_TYPE",
"]",
"scope",
"=",
"condition",
"[",
"CONF_SCOPE",
"]",
"name",
"=",
"f\"Fronius {condition[CONF_SENSOR_TYPE].replace('_', ' ').capitalize()} {device if scope == SCOPE_DEVICE else SCOPE_SYSTEM} {config[CONF_RESOURCE]}\"",
"if",
"sensor_type",
"==",
"TYPE_INVERTER",
":",
"if",
"scope",
"==",
"SCOPE_SYSTEM",
":",
"adapter_cls",
"=",
"FroniusInverterSystem",
"else",
":",
"adapter_cls",
"=",
"FroniusInverterDevice",
"elif",
"sensor_type",
"==",
"TYPE_METER",
":",
"if",
"scope",
"==",
"SCOPE_SYSTEM",
":",
"adapter_cls",
"=",
"FroniusMeterSystem",
"else",
":",
"adapter_cls",
"=",
"FroniusMeterDevice",
"elif",
"sensor_type",
"==",
"TYPE_POWER_FLOW",
":",
"adapter_cls",
"=",
"FroniusPowerFlow",
"else",
":",
"adapter_cls",
"=",
"FroniusStorage",
"adapters",
".",
"append",
"(",
"adapter_cls",
"(",
"fronius",
",",
"name",
",",
"device",
",",
"async_add_entities",
")",
")",
"# Creates a lamdba that fetches an update when called",
"def",
"adapter_data_fetcher",
"(",
"data_adapter",
")",
":",
"async",
"def",
"fetch_data",
"(",
"*",
"_",
")",
":",
"await",
"data_adapter",
".",
"async_update",
"(",
")",
"return",
"fetch_data",
"# Set up the fetching in a fixed interval for each adapter",
"for",
"adapter",
"in",
"adapters",
":",
"fetch",
"=",
"adapter_data_fetcher",
"(",
"adapter",
")",
"# fetch data once at set-up",
"await",
"fetch",
"(",
")",
"async_track_time_interval",
"(",
"hass",
",",
"fetch",
",",
"scan_interval",
")"
] | [
77,
0
] | [
120,
61
] | python | en | ['en', 'jv', 'en'] | True |
FroniusAdapter.__init__ | (self, bridge, name, device, add_entities) | Initialize the sensor. | Initialize the sensor. | def __init__(self, bridge, name, device, add_entities):
"""Initialize the sensor."""
self.bridge = bridge
self._name = name
self._device = device
self._fetched = {}
self.sensors = set()
self._registered_sensors = set()
self._add_entities = add_entities | [
"def",
"__init__",
"(",
"self",
",",
"bridge",
",",
"name",
",",
"device",
",",
"add_entities",
")",
":",
"self",
".",
"bridge",
"=",
"bridge",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_fetched",
"=",
"{",
"}",
"self",
".",
"sensors",
"=",
"set",
"(",
")",
"self",
".",
"_registered_sensors",
"=",
"set",
"(",
")",
"self",
".",
"_add_entities",
"=",
"add_entities"
] | [
126,
4
] | [
135,
41
] | python | en | ['en', 'en', 'en'] | True |
FroniusAdapter.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"
] | [
138,
4
] | [
140,
25
] | python | en | ['en', 'mi', 'en'] | True |
FroniusAdapter.data | (self) | Return the state attributes. | Return the state attributes. | def data(self):
"""Return the state attributes."""
return self._fetched | [
"def",
"data",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fetched"
] | [
143,
4
] | [
145,
28
] | python | en | ['en', 'en', 'en'] | True |
FroniusAdapter.async_update | (self) | Retrieve and update latest state. | Retrieve and update latest state. | async def async_update(self):
"""Retrieve and update latest state."""
values = {}
try:
values = await self._update()
except ConnectionError:
_LOGGER.error("Failed to update: connection error")
except ValueError:
_LOGGER.error(
"Failed to update: invalid response returned."
"Maybe the configured device is not supported"
)
if not values:
return
attributes = self._fetched
# Copy data of current fronius device
for key, entry in values.items():
# If the data is directly a sensor
if "value" in entry:
attributes[key] = entry
self._fetched = attributes
# Add discovered value fields as sensors
# because some fields are only sent temporarily
new_sensors = []
for key in attributes:
if key not in self.sensors:
self.sensors.add(key)
_LOGGER.info("Discovered %s, adding as sensor", key)
new_sensors.append(FroniusTemplateSensor(self, key))
self._add_entities(new_sensors, True)
# Schedule an update for all included sensors
for sensor in self._registered_sensors:
sensor.async_schedule_update_ha_state(True) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"values",
"=",
"{",
"}",
"try",
":",
"values",
"=",
"await",
"self",
".",
"_update",
"(",
")",
"except",
"ConnectionError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to update: connection error\"",
")",
"except",
"ValueError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Failed to update: invalid response returned.\"",
"\"Maybe the configured device is not supported\"",
")",
"if",
"not",
"values",
":",
"return",
"attributes",
"=",
"self",
".",
"_fetched",
"# Copy data of current fronius device",
"for",
"key",
",",
"entry",
"in",
"values",
".",
"items",
"(",
")",
":",
"# If the data is directly a sensor",
"if",
"\"value\"",
"in",
"entry",
":",
"attributes",
"[",
"key",
"]",
"=",
"entry",
"self",
".",
"_fetched",
"=",
"attributes",
"# Add discovered value fields as sensors",
"# because some fields are only sent temporarily",
"new_sensors",
"=",
"[",
"]",
"for",
"key",
"in",
"attributes",
":",
"if",
"key",
"not",
"in",
"self",
".",
"sensors",
":",
"self",
".",
"sensors",
".",
"add",
"(",
"key",
")",
"_LOGGER",
".",
"info",
"(",
"\"Discovered %s, adding as sensor\"",
",",
"key",
")",
"new_sensors",
".",
"append",
"(",
"FroniusTemplateSensor",
"(",
"self",
",",
"key",
")",
")",
"self",
".",
"_add_entities",
"(",
"new_sensors",
",",
"True",
")",
"# Schedule an update for all included sensors",
"for",
"sensor",
"in",
"self",
".",
"_registered_sensors",
":",
"sensor",
".",
"async_schedule_update_ha_state",
"(",
"True",
")"
] | [
147,
4
] | [
182,
55
] | python | en | ['en', 'en', 'en'] | True |
FroniusAdapter._update | (self) | Return values of interest. | Return values of interest. | async def _update(self):
"""Return values of interest.""" | [
"async",
"def",
"_update",
"(",
"self",
")",
":"
] | [
184,
4
] | [
185,
40
] | python | en | ['en', 'no', 'en'] | True |
FroniusAdapter.register | (self, sensor) | Register child sensor for update subscriptions. | Register child sensor for update subscriptions. | async def register(self, sensor):
"""Register child sensor for update subscriptions."""
self._registered_sensors.add(sensor) | [
"async",
"def",
"register",
"(",
"self",
",",
"sensor",
")",
":",
"self",
".",
"_registered_sensors",
".",
"add",
"(",
"sensor",
")"
] | [
187,
4
] | [
189,
44
] | python | en | ['en', 'no', 'en'] | True |
FroniusInverterSystem._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_system_inverter_data() | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_system_inverter_data",
"(",
")"
] | [
195,
4
] | [
197,
63
] | python | en | ['en', 'en', 'en'] | True |
FroniusInverterDevice._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_inverter_data(self._device) | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_inverter_data",
"(",
"self",
".",
"_device",
")"
] | [
203,
4
] | [
205,
68
] | python | en | ['en', 'en', 'en'] | True |
FroniusStorage._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_storage_data(self._device) | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_storage_data",
"(",
"self",
".",
"_device",
")"
] | [
211,
4
] | [
213,
67
] | python | en | ['en', 'en', 'en'] | True |
FroniusMeterSystem._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_system_meter_data() | [
"async",
"def",
"_update",
"(",
"self",
")",
":",
"return",
"await",
"self",
".",
"bridge",
".",
"current_system_meter_data",
"(",
")"
] | [
219,
4
] | [
221,
60
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.