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 list | start_point list | end_point list | language stringclasses 1 value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2 values |
|---|---|---|---|---|---|---|---|---|---|---|---|
test_turn_on_fan_without_speed | (hass: core.HomeAssistant) | Tests that turn on command delegates to turn on API. | Tests that turn on command delegates to turn on API. | async def test_turn_on_fan_without_speed(hass: core.HomeAssistant):
"""Tests that turn on command delegates to turn on API."""
await setup_platform(
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_turn_on, patch_bond_device_state():
await turn_fan_on(hass, "fan.name_1")
mock_turn_on.assert_called_with("test-device-id", Action.turn_on()) | [
"async",
"def",
"test_turn_on_fan_without_speed",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")"... | [
137,
0
] | [
146,
71
] | python | en | ['en', 'en', 'en'] | True |
test_turn_on_fan_with_off_speed | (hass: core.HomeAssistant) | Tests that turn on command delegates to turn off API. | Tests that turn on command delegates to turn off API. | async def test_turn_on_fan_with_off_speed(hass: core.HomeAssistant):
"""Tests that turn on command delegates to turn off API."""
await setup_platform(
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_turn_off, patch_bond_device_state():
await turn_fan_on(hass, "fan.name_1", fan.SPEED_OFF)
mock_turn_off.assert_called_with("test-device-id", Action.turn_off()) | [
"async",
"def",
"test_turn_on_fan_with_off_speed",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")... | [
149,
0
] | [
158,
73
] | python | en | ['en', 'en', 'en'] | True |
test_set_speed_off | (hass: core.HomeAssistant) | Tests that set_speed(off) command delegates to turn off API. | Tests that set_speed(off) command delegates to turn off API. | async def test_set_speed_off(hass: core.HomeAssistant):
"""Tests that set_speed(off) command delegates to turn off API."""
await setup_platform(
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_turn_off, patch_bond_device_state():
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_SET_SPEED,
service_data={ATTR_ENTITY_ID: "fan.name_1", ATTR_SPEED: SPEED_OFF},
blocking=True,
)
await hass.async_block_till_done()
mock_turn_off.assert_called_with("test-device-id", Action.turn_off()) | [
"async",
"def",
"test_set_speed_off",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"with",
... | [
161,
0
] | [
176,
73
] | python | en | ['en', 'en', 'en'] | True |
test_turn_off_fan | (hass: core.HomeAssistant) | Tests that turn off command delegates to API. | Tests that turn off command delegates to API. | async def test_turn_off_fan(hass: core.HomeAssistant):
"""Tests that turn off command delegates to API."""
await setup_platform(
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_turn_off, patch_bond_device_state():
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: "fan.name_1"},
blocking=True,
)
await hass.async_block_till_done()
mock_turn_off.assert_called_once_with("test-device-id", Action.turn_off()) | [
"async",
"def",
"test_turn_off_fan",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"with",
... | [
179,
0
] | [
194,
78
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_fan_on | (hass: core.HomeAssistant) | Tests that update command sets correct state when Bond API reports fan power is on. | Tests that update command sets correct state when Bond API reports fan power is on. | async def test_update_reports_fan_on(hass: core.HomeAssistant):
"""Tests that update command sets correct state when Bond API reports fan power is on."""
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
with patch_bond_device_state(return_value={"power": 1, "speed": 1}):
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert hass.states.get("fan.name_1").state == "on" | [
"async",
"def",
"test_update_reports_fan_on",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"return_valu... | [
197,
0
] | [
205,
54
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_fan_off | (hass: core.HomeAssistant) | Tests that update command sets correct state when Bond API reports fan power is off. | Tests that update command sets correct state when Bond API reports fan power is off. | async def test_update_reports_fan_off(hass: core.HomeAssistant):
"""Tests that update command sets correct state when Bond API reports fan power is off."""
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
with patch_bond_device_state(return_value={"power": 0, "speed": 1}):
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert hass.states.get("fan.name_1").state == "off" | [
"async",
"def",
"test_update_reports_fan_off",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"return_val... | [
208,
0
] | [
216,
55
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_direction_forward | (hass: core.HomeAssistant) | Tests that update command sets correct direction when Bond API reports fan direction is forward. | Tests that update command sets correct direction when Bond API reports fan direction is forward. | async def test_update_reports_direction_forward(hass: core.HomeAssistant):
"""Tests that update command sets correct direction when Bond API reports fan direction is forward."""
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
with patch_bond_device_state(return_value={"direction": Direction.FORWARD}):
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert hass.states.get("fan.name_1").attributes[ATTR_DIRECTION] == DIRECTION_FORWARD | [
"async",
"def",
"test_update_reports_direction_forward",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"... | [
219,
0
] | [
227,
88
] | python | en | ['en', 'en', 'en'] | True |
test_update_reports_direction_reverse | (hass: core.HomeAssistant) | Tests that update command sets correct direction when Bond API reports fan direction is reverse. | Tests that update command sets correct direction when Bond API reports fan direction is reverse. | async def test_update_reports_direction_reverse(hass: core.HomeAssistant):
"""Tests that update command sets correct direction when Bond API reports fan direction is reverse."""
await setup_platform(hass, FAN_DOMAIN, ceiling_fan("name-1"))
with patch_bond_device_state(return_value={"direction": Direction.REVERSE}):
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
await hass.async_block_till_done()
assert hass.states.get("fan.name_1").attributes[ATTR_DIRECTION] == DIRECTION_REVERSE | [
"async",
"def",
"test_update_reports_direction_reverse",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
")",
"with",
"patch_bond_device_state",
"(",
"... | [
230,
0
] | [
238,
88
] | python | en | ['en', 'en', 'en'] | True |
test_set_fan_direction | (hass: core.HomeAssistant) | Tests that set direction command delegates to API. | Tests that set direction command delegates to API. | async def test_set_fan_direction(hass: core.HomeAssistant):
"""Tests that set direction command delegates to API."""
await setup_platform(
hass, FAN_DOMAIN, ceiling_fan("name-1"), bond_device_id="test-device-id"
)
with patch_bond_action() as mock_set_direction, patch_bond_device_state():
await hass.services.async_call(
FAN_DOMAIN,
SERVICE_SET_DIRECTION,
{ATTR_ENTITY_ID: "fan.name_1", ATTR_DIRECTION: DIRECTION_FORWARD},
blocking=True,
)
await hass.async_block_till_done()
mock_set_direction.assert_called_once_with(
"test-device-id", Action.set_direction(Direction.FORWARD)
) | [
"async",
"def",
"test_set_fan_direction",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"setup_platform",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"bond_device_id",
"=",
"\"test-device-id\"",
")",
"wit... | [
241,
0
] | [
258,
5
] | python | en | ['en', 'en', 'en'] | True |
test_fan_available | (hass: core.HomeAssistant) | Tests that available state is updated based on API errors. | Tests that available state is updated based on API errors. | async def test_fan_available(hass: core.HomeAssistant):
"""Tests that available state is updated based on API errors."""
await help_test_entity_available(
hass, FAN_DOMAIN, ceiling_fan("name-1"), "fan.name_1"
) | [
"async",
"def",
"test_fan_available",
"(",
"hass",
":",
"core",
".",
"HomeAssistant",
")",
":",
"await",
"help_test_entity_available",
"(",
"hass",
",",
"FAN_DOMAIN",
",",
"ceiling_fan",
"(",
"\"name-1\"",
")",
",",
"\"fan.name_1\"",
")"
] | [
261,
0
] | [
265,
5
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up tellduslive sensors dynamically. | Set up tellduslive sensors dynamically. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up tellduslive sensors dynamically."""
async def async_discover_sensor(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[tellduslive.DOMAIN]
async_add_entities([TelldusLiveSensor(client, device_id)])
async_dispatcher_connect(
hass,
tellduslive.TELLDUS_DISCOVERY_NEW.format(sensor.DOMAIN, tellduslive.DOMAIN),
async_discover_sensor,
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"async",
"def",
"async_discover_sensor",
"(",
"device_id",
")",
":",
"\"\"\"Discover and add a discovered sensor.\"\"\"",
"client",
"=",
"hass",
".",
"data",
"[... | [
58,
0
] | [
70,
5
] | python | en | ['en', 'hu', 'en'] | True |
TelldusLiveSensor.device_id | (self) | Return id of the device. | Return id of the device. | def device_id(self):
"""Return id of the device."""
return self._id[0] | [
"def",
"device_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_id",
"[",
"0",
"]"
] | [
77,
4
] | [
79,
26
] | python | en | ['en', 'en', 'en'] | True |
TelldusLiveSensor._type | (self) | Return the type of the sensor. | Return the type of the sensor. | def _type(self):
"""Return the type of the sensor."""
return self._id[1] | [
"def",
"_type",
"(",
"self",
")",
":",
"return",
"self",
".",
"_id",
"[",
"1",
"]"
] | [
82,
4
] | [
84,
26
] | python | en | ['en', 'no', 'en'] | True |
TelldusLiveSensor._value | (self) | Return value of the sensor. | Return value of the sensor. | def _value(self):
"""Return value of the sensor."""
return self.device.value(*self._id[1:]) | [
"def",
"_value",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"value",
"(",
"*",
"self",
".",
"_id",
"[",
"1",
":",
"]",
")"
] | [
87,
4
] | [
89,
47
] | python | en | ['en', 'no', 'en'] | True |
TelldusLiveSensor._value_as_temperature | (self) | Return the value as temperature. | Return the value as temperature. | def _value_as_temperature(self):
"""Return the value as temperature."""
return round(float(self._value), 1) | [
"def",
"_value_as_temperature",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"_value",
")",
",",
"1",
")"
] | [
92,
4
] | [
94,
43
] | python | en | ['en', 'la', 'en'] | True |
TelldusLiveSensor._value_as_luminance | (self) | Return the value as luminance. | Return the value as luminance. | def _value_as_luminance(self):
"""Return the value as luminance."""
return round(float(self._value), 1) | [
"def",
"_value_as_luminance",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"_value",
")",
",",
"1",
")"
] | [
97,
4
] | [
99,
43
] | python | en | ['en', 'no', 'en'] | True |
TelldusLiveSensor._value_as_humidity | (self) | Return the value as humidity. | Return the value as humidity. | def _value_as_humidity(self):
"""Return the value as humidity."""
return int(round(float(self._value))) | [
"def",
"_value_as_humidity",
"(",
"self",
")",
":",
"return",
"int",
"(",
"round",
"(",
"float",
"(",
"self",
".",
"_value",
")",
")",
")"
] | [
102,
4
] | [
104,
45
] | python | en | ['en', 'en', 'en'] | True |
TelldusLiveSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return "{} {}".format(super().name, self.quantity_name or "").strip() | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"\"{} {}\"",
".",
"format",
"(",
"super",
"(",
")",
".",
"name",
",",
"self",
".",
"quantity_name",
"or",
"\"\"",
")",
".",
"strip",
"(",
")"
] | [
107,
4
] | [
109,
77
] | python | en | ['en', 'mi', 'en'] | True |
TelldusLiveSensor.state | (self) | Return the state of the sensor. | Return the state of the sensor. | def state(self):
"""Return the state of the sensor."""
if not self.available:
return None
if self._type == SENSOR_TYPE_TEMPERATURE:
return self._value_as_temperature
if self._type == SENSOR_TYPE_HUMIDITY:
return self._value_as_humidity
if self._type == SENSOR_TYPE_LUMINANCE:
return self._value_as_luminance
return self._value | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"available",
":",
"return",
"None",
"if",
"self",
".",
"_type",
"==",
"SENSOR_TYPE_TEMPERATURE",
":",
"return",
"self",
".",
"_value_as_temperature",
"if",
"self",
".",
"_type",
"==",
"SENSOR... | [
112,
4
] | [
122,
26
] | python | en | ['en', 'en', 'en'] | True |
TelldusLiveSensor.quantity_name | (self) | Name of quantity. | Name of quantity. | def quantity_name(self):
"""Name of quantity."""
return SENSOR_TYPES[self._type][0] if self._type in SENSOR_TYPES else None | [
"def",
"quantity_name",
"(",
"self",
")",
":",
"return",
"SENSOR_TYPES",
"[",
"self",
".",
"_type",
"]",
"[",
"0",
"]",
"if",
"self",
".",
"_type",
"in",
"SENSOR_TYPES",
"else",
"None"
] | [
125,
4
] | [
127,
82
] | python | en | ['en', 'la', 'en'] | True |
TelldusLiveSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return SENSOR_TYPES[self._type][1] if self._type in SENSOR_TYPES else None | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"SENSOR_TYPES",
"[",
"self",
".",
"_type",
"]",
"[",
"1",
"]",
"if",
"self",
".",
"_type",
"in",
"SENSOR_TYPES",
"else",
"None"
] | [
130,
4
] | [
132,
82
] | python | en | ['en', 'la', 'en'] | True |
TelldusLiveSensor.icon | (self) | Return the icon. | Return the icon. | def icon(self):
"""Return the icon."""
return SENSOR_TYPES[self._type][2] if self._type in SENSOR_TYPES else None | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"SENSOR_TYPES",
"[",
"self",
".",
"_type",
"]",
"[",
"2",
"]",
"if",
"self",
".",
"_type",
"in",
"SENSOR_TYPES",
"else",
"None"
] | [
135,
4
] | [
137,
82
] | python | en | ['en', 'sr', 'en'] | True |
TelldusLiveSensor.device_class | (self) | Return the device class. | Return the device class. | def device_class(self):
"""Return the device class."""
return SENSOR_TYPES[self._type][3] if self._type in SENSOR_TYPES else None | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"SENSOR_TYPES",
"[",
"self",
".",
"_type",
"]",
"[",
"3",
"]",
"if",
"self",
".",
"_type",
"in",
"SENSOR_TYPES",
"else",
"None"
] | [
140,
4
] | [
142,
82
] | python | en | ['en', 'en', 'en'] | True |
TelldusLiveSensor.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self) -> str:
"""Return a unique ID."""
return "{}-{}-{}".format(*self._id) | [
"def",
"unique_id",
"(",
"self",
")",
"->",
"str",
":",
"return",
"\"{}-{}-{}\"",
".",
"format",
"(",
"*",
"self",
".",
"_id",
")"
] | [
145,
4
] | [
147,
43
] | python | ca | ['fr', 'ca', 'en'] | False |
async_setup_entry | (hass, config, async_add_entities) | Initialize a Spider thermostat. | Initialize a Spider thermostat. | async def async_setup_entry(hass, config, async_add_entities):
"""Initialize a Spider thermostat."""
api = hass.data[DOMAIN][config.entry_id]
async_add_entities(
[
SpiderPowerPlug(api, entity)
for entity in await hass.async_add_executor_job(api.get_power_plugs)
]
) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")",
":",
"api",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config",
".",
"entry_id",
"]",
"async_add_entities",
"(",
"[",
"SpiderPowerPlug",
"(",
"api",
"... | [
6,
0
] | [
14,
5
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.__init__ | (self, api, power_plug) | Initialize the Vera device. | Initialize the Vera device. | def __init__(self, api, power_plug):
"""Initialize the Vera device."""
self.api = api
self.power_plug = power_plug | [
"def",
"__init__",
"(",
"self",
",",
"api",
",",
"power_plug",
")",
":",
"self",
".",
"api",
"=",
"api",
"self",
".",
"power_plug",
"=",
"power_plug"
] | [
20,
4
] | [
23,
36
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.unique_id | (self) | Return the ID of this switch. | Return the ID of this switch. | def unique_id(self):
"""Return the ID of this switch."""
return self.power_plug.id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"power_plug",
".",
"id"
] | [
26,
4
] | [
28,
33
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.name | (self) | Return the name of the switch if any. | Return the name of the switch if any. | def name(self):
"""Return the name of the switch if any."""
return self.power_plug.name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"power_plug",
".",
"name"
] | [
31,
4
] | [
33,
35
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.current_power_w | (self) | Return the current power usage in W. | Return the current power usage in W. | def current_power_w(self):
"""Return the current power usage in W."""
return round(self.power_plug.current_energy_consumption) | [
"def",
"current_power_w",
"(",
"self",
")",
":",
"return",
"round",
"(",
"self",
".",
"power_plug",
".",
"current_energy_consumption",
")"
] | [
36,
4
] | [
38,
64
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.today_energy_kwh | (self) | Return the current power usage in Kwh. | Return the current power usage in Kwh. | def today_energy_kwh(self):
"""Return the current power usage in Kwh."""
return round(self.power_plug.today_energy_consumption / 1000, 2) | [
"def",
"today_energy_kwh",
"(",
"self",
")",
":",
"return",
"round",
"(",
"self",
".",
"power_plug",
".",
"today_energy_consumption",
"/",
"1000",
",",
"2",
")"
] | [
41,
4
] | [
43,
72
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.is_on | (self) | Return true if switch is on. Standby is on. | Return true if switch is on. Standby is on. | def is_on(self):
"""Return true if switch is on. Standby is on."""
return self.power_plug.is_on | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"power_plug",
".",
"is_on"
] | [
46,
4
] | [
48,
36
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.available | (self) | Return true if switch is available. | Return true if switch is available. | def available(self):
"""Return true if switch is available."""
return self.power_plug.is_available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"power_plug",
".",
"is_available"
] | [
51,
4
] | [
53,
43
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.turn_on | (self, **kwargs) | Turn device on. | Turn device on. | def turn_on(self, **kwargs):
"""Turn device on."""
self.power_plug.turn_on() | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"power_plug",
".",
"turn_on",
"(",
")"
] | [
55,
4
] | [
57,
33
] | python | en | ['es', 'en', 'en'] | True |
SpiderPowerPlug.turn_off | (self, **kwargs) | Turn device off. | Turn device off. | def turn_off(self, **kwargs):
"""Turn device off."""
self.power_plug.turn_off() | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"power_plug",
".",
"turn_off",
"(",
")"
] | [
59,
4
] | [
61,
34
] | python | en | ['en', 'en', 'en'] | True |
SpiderPowerPlug.update | (self) | Get the latest data. | Get the latest data. | def update(self):
"""Get the latest data."""
self.power_plug = self.api.get_power_plug(self.unique_id) | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"power_plug",
"=",
"self",
".",
"api",
".",
"get_power_plug",
"(",
"self",
".",
"unique_id",
")"
] | [
63,
4
] | [
65,
65
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass) | Init mfa setup flow manager. | Init mfa setup flow manager. | async def async_setup(hass):
"""Init mfa setup flow manager."""
hass.data[DATA_SETUP_FLOW_MGR] = MfaFlowManager(hass)
hass.components.websocket_api.async_register_command(
WS_TYPE_SETUP_MFA, websocket_setup_mfa, SCHEMA_WS_SETUP_MFA
)
hass.components.websocket_api.async_register_command(
WS_TYPE_DEPOSE_MFA, websocket_depose_mfa, SCHEMA_WS_DEPOSE_MFA
) | [
"async",
"def",
"async_setup",
"(",
"hass",
")",
":",
"hass",
".",
"data",
"[",
"DATA_SETUP_FLOW_MGR",
"]",
"=",
"MfaFlowManager",
"(",
"hass",
")",
"hass",
".",
"components",
".",
"websocket_api",
".",
"async_register_command",
"(",
"WS_TYPE_SETUP_MFA",
",",
... | [
48,
0
] | [
58,
5
] | python | en | ['en', 'en', 'en'] | True |
websocket_setup_mfa | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Return a setup flow for mfa auth module. | Return a setup flow for mfa auth module. | def websocket_setup_mfa(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Return a setup flow for mfa auth module."""
async def async_setup_flow(msg):
"""Return a setup flow for mfa auth module."""
flow_manager = hass.data[DATA_SETUP_FLOW_MGR]
flow_id = msg.get("flow_id")
if flow_id is not None:
result = await flow_manager.async_configure(flow_id, msg.get("user_input"))
connection.send_message(
websocket_api.result_message(msg["id"], _prepare_result_json(result))
)
return
mfa_module_id = msg.get("mfa_module_id")
mfa_module = hass.auth.get_auth_mfa_module(mfa_module_id)
if mfa_module is None:
connection.send_message(
websocket_api.error_message(
msg["id"], "no_module", f"MFA module {mfa_module_id} is not found"
)
)
return
result = await flow_manager.async_init(
mfa_module_id, data={"user_id": connection.user.id}
)
connection.send_message(
websocket_api.result_message(msg["id"], _prepare_result_json(result))
)
hass.async_create_task(async_setup_flow(msg)) | [
"def",
"websocket_setup_mfa",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"async",
"def",
"async_setup_flow",
"(",
"msg",
")",
":",
"\"\"\"Return a setup flow for mfa auth module.\"\"\"",
"... | [
63,
0
] | [
98,
49
] | python | en | ['en', 'gd', 'en'] | True |
websocket_depose_mfa | (
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
) | Remove user from mfa module. | Remove user from mfa module. | def websocket_depose_mfa(
hass: HomeAssistant, connection: websocket_api.ActiveConnection, msg
):
"""Remove user from mfa module."""
async def async_depose(msg):
"""Remove user from mfa auth module."""
mfa_module_id = msg["mfa_module_id"]
try:
await hass.auth.async_disable_user_mfa(
connection.user, msg["mfa_module_id"]
)
except ValueError as err:
connection.send_message(
websocket_api.error_message(
msg["id"],
"disable_failed",
f"Cannot disable MFA Module {mfa_module_id}: {err}",
)
)
return
connection.send_message(websocket_api.result_message(msg["id"], "done"))
hass.async_create_task(async_depose(msg)) | [
"def",
"websocket_depose_mfa",
"(",
"hass",
":",
"HomeAssistant",
",",
"connection",
":",
"websocket_api",
".",
"ActiveConnection",
",",
"msg",
")",
":",
"async",
"def",
"async_depose",
"(",
"msg",
")",
":",
"\"\"\"Remove user from mfa auth module.\"\"\"",
"mfa_module... | [
103,
0
] | [
127,
45
] | python | en | ['en', 'it', 'en'] | True |
_prepare_result_json | (result) | Convert result to JSON. | Convert result to JSON. | def _prepare_result_json(result):
"""Convert result to JSON."""
if result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
data = result.copy()
return data
if result["type"] != data_entry_flow.RESULT_TYPE_FORM:
return result
data = result.copy()
schema = data["data_schema"]
if schema is None:
data["data_schema"] = []
else:
data["data_schema"] = voluptuous_serialize.convert(schema)
return data | [
"def",
"_prepare_result_json",
"(",
"result",
")",
":",
"if",
"result",
"[",
"\"type\"",
"]",
"==",
"data_entry_flow",
".",
"RESULT_TYPE_CREATE_ENTRY",
":",
"data",
"=",
"result",
".",
"copy",
"(",
")",
"return",
"data",
"if",
"result",
"[",
"\"type\"",
"]",... | [
130,
0
] | [
147,
15
] | python | en | ['en', 'en', 'en'] | True |
MfaFlowManager.async_create_flow | (self, handler_key, *, context, data) | Create a setup flow. handler is a mfa module. | Create a setup flow. handler is a mfa module. | async def async_create_flow(self, handler_key, *, context, data):
"""Create a setup flow. handler is a mfa module."""
mfa_module = self.hass.auth.get_auth_mfa_module(handler_key)
if mfa_module is None:
raise ValueError(f"Mfa module {handler_key} is not found")
user_id = data.pop("user_id")
return await mfa_module.async_setup_flow(user_id) | [
"async",
"def",
"async_create_flow",
"(",
"self",
",",
"handler_key",
",",
"*",
",",
"context",
",",
"data",
")",
":",
"mfa_module",
"=",
"self",
".",
"hass",
".",
"auth",
".",
"get_auth_mfa_module",
"(",
"handler_key",
")",
"if",
"mfa_module",
"is",
"None... | [
33,
4
] | [
40,
57
] | python | en | ['en', 'gd', 'en'] | True |
MfaFlowManager.async_finish_flow | (self, flow, result) | Complete an mfs setup flow. | Complete an mfs setup flow. | async def async_finish_flow(self, flow, result):
"""Complete an mfs setup flow."""
_LOGGER.debug("flow_result: %s", result)
return result | [
"async",
"def",
"async_finish_flow",
"(",
"self",
",",
"flow",
",",
"result",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"flow_result: %s\"",
",",
"result",
")",
"return",
"result"
] | [
42,
4
] | [
45,
21
] | python | en | ['en', 'lb', 'en'] | True |
test_setup_with_config | (hass) | Test the platform setup with configuration. | Test the platform setup with configuration. | async def test_setup_with_config(hass):
"""Test the platform setup with configuration."""
assert await async_setup_component(hass, "sensor", {"wsdot": config}) | [
"async",
"def",
"test_setup_with_config",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"sensor\"",
",",
"{",
"\"wsdot\"",
":",
"config",
"}",
")"
] | [
26,
0
] | [
28,
73
] | python | en | ['en', 'en', 'en'] | True |
test_setup | (hass, requests_mock) | Test for operational WSDOT sensor with proper attributes. | Test for operational WSDOT sensor with proper attributes. | async def test_setup(hass, requests_mock):
"""Test for operational WSDOT sensor with proper attributes."""
entities = []
def add_entities(new_entities, update_before_add=False):
"""Mock add entities."""
if update_before_add:
for entity in new_entities:
entity.update()
for entity in new_entities:
entities.append(entity)
uri = re.compile(RESOURCE + "*")
requests_mock.get(uri, text=load_fixture("wsdot.json"))
wsdot.setup_platform(hass, config, add_entities)
assert len(entities) == 1
sensor = entities[0]
assert sensor.name == "I90 EB"
assert sensor.state == 11
assert (
sensor.device_state_attributes[ATTR_DESCRIPTION]
== "Downtown Seattle to Downtown Bellevue via I-90"
)
assert sensor.device_state_attributes[ATTR_TIME_UPDATED] == datetime(
2017, 1, 21, 15, 10, tzinfo=timezone(timedelta(hours=-8))
) | [
"async",
"def",
"test_setup",
"(",
"hass",
",",
"requests_mock",
")",
":",
"entities",
"=",
"[",
"]",
"def",
"add_entities",
"(",
"new_entities",
",",
"update_before_add",
"=",
"False",
")",
":",
"\"\"\"Mock add entities.\"\"\"",
"if",
"update_before_add",
":",
... | [
31,
0
] | [
57,
5
] | python | en | ['en', 'en', 'en'] | True |
async_pulse | (hass, ihc_controller, ihc_id: int) | Send a short on/off pulse to an IHC controller resource. | Send a short on/off pulse to an IHC controller resource. | async def async_pulse(hass, ihc_controller, ihc_id: int):
"""Send a short on/off pulse to an IHC controller resource."""
await async_set_bool(hass, ihc_controller, ihc_id, True)
await asyncio.sleep(0.1)
await async_set_bool(hass, ihc_controller, ihc_id, False) | [
"async",
"def",
"async_pulse",
"(",
"hass",
",",
"ihc_controller",
",",
"ihc_id",
":",
"int",
")",
":",
"await",
"async_set_bool",
"(",
"hass",
",",
"ihc_controller",
",",
"ihc_id",
",",
"True",
")",
"await",
"asyncio",
".",
"sleep",
"(",
"0.1",
")",
"aw... | [
7,
0
] | [
11,
61
] | python | en | ['en', 'en', 'en'] | True |
async_set_bool | (hass, ihc_controller, ihc_id: int, value: bool) | Set a bool value on an IHC controller resource. | Set a bool value on an IHC controller resource. | def async_set_bool(hass, ihc_controller, ihc_id: int, value: bool):
"""Set a bool value on an IHC controller resource."""
return hass.async_add_executor_job(
ihc_controller.set_runtime_value_bool, ihc_id, value
) | [
"def",
"async_set_bool",
"(",
"hass",
",",
"ihc_controller",
",",
"ihc_id",
":",
"int",
",",
"value",
":",
"bool",
")",
":",
"return",
"hass",
".",
"async_add_executor_job",
"(",
"ihc_controller",
".",
"set_runtime_value_bool",
",",
"ihc_id",
",",
"value",
")"... | [
15,
0
] | [
19,
5
] | python | en | ['en', 'en', 'en'] | True |
async_set_int | (hass, ihc_controller, ihc_id: int, value: int) | Set a int value on an IHC controller resource. | Set a int value on an IHC controller resource. | def async_set_int(hass, ihc_controller, ihc_id: int, value: int):
"""Set a int value on an IHC controller resource."""
return hass.async_add_executor_job(
ihc_controller.set_runtime_value_int, ihc_id, value
) | [
"def",
"async_set_int",
"(",
"hass",
",",
"ihc_controller",
",",
"ihc_id",
":",
"int",
",",
"value",
":",
"int",
")",
":",
"return",
"hass",
".",
"async_add_executor_job",
"(",
"ihc_controller",
".",
"set_runtime_value_int",
",",
"ihc_id",
",",
"value",
")"
] | [
23,
0
] | [
27,
5
] | python | en | ['en', 'en', 'en'] | True |
mock_http | (hass) | Mock the http component. | Mock the http component. | def mock_http(hass):
"""Mock the http component."""
hass.http = Mock() | [
"def",
"mock_http",
"(",
"hass",
")",
":",
"hass",
".",
"http",
"=",
"Mock",
"(",
")"
] | [
227,
0
] | [
229,
22
] | python | en | ['en', 'en', 'en'] | True |
mock_dav_client | () | Mock the dav client. | Mock the dav client. | def mock_dav_client():
"""Mock the dav client."""
patch_dav_client = patch(
"caldav.DAVClient", return_value=_mocked_dav_client("First", "Second")
)
with patch_dav_client as dav_client:
yield dav_client | [
"def",
"mock_dav_client",
"(",
")",
":",
"patch_dav_client",
"=",
"patch",
"(",
"\"caldav.DAVClient\"",
",",
"return_value",
"=",
"_mocked_dav_client",
"(",
"\"First\"",
",",
"\"Second\"",
")",
")",
"with",
"patch_dav_client",
"as",
"dav_client",
":",
"yield",
"da... | [
233,
0
] | [
239,
24
] | python | en | ['en', 'no', 'en'] | True |
mock_private_cal | () | Mock a private calendar. | Mock a private calendar. | def mock_private_cal():
"""Mock a private calendar."""
_calendar = _mock_calendar("Private")
calendars = [_calendar]
client = _mocked_dav_client(calendars=calendars)
patch_dav_client = patch("caldav.DAVClient", return_value=client)
with patch_dav_client:
yield _calendar | [
"def",
"mock_private_cal",
"(",
")",
":",
"_calendar",
"=",
"_mock_calendar",
"(",
"\"Private\"",
")",
"calendars",
"=",
"[",
"_calendar",
"]",
"client",
"=",
"_mocked_dav_client",
"(",
"calendars",
"=",
"calendars",
")",
"patch_dav_client",
"=",
"patch",
"(",
... | [
243,
0
] | [
250,
23
] | python | co | ['ro', 'co', 'en'] | False |
_local_datetime | (hours, minutes) | Build a datetime object for testing in the correct timezone. | Build a datetime object for testing in the correct timezone. | def _local_datetime(hours, minutes):
"""Build a datetime object for testing in the correct timezone."""
return dt.as_local(datetime.datetime(2017, 11, 27, hours, minutes, 0)) | [
"def",
"_local_datetime",
"(",
"hours",
",",
"minutes",
")",
":",
"return",
"dt",
".",
"as_local",
"(",
"datetime",
".",
"datetime",
"(",
"2017",
",",
"11",
",",
"27",
",",
"hours",
",",
"minutes",
",",
"0",
")",
")"
] | [
253,
0
] | [
255,
74
] | python | en | ['en', 'en', 'en'] | True |
_mocked_dav_client | (*names, calendars=None) | Mock requests.get invocations. | Mock requests.get invocations. | def _mocked_dav_client(*names, calendars=None):
"""Mock requests.get invocations."""
if calendars is None:
calendars = [_mock_calendar(name) for name in names]
principal = Mock()
principal.calendars = MagicMock(return_value=calendars)
client = Mock()
client.principal = MagicMock(return_value=principal)
return client | [
"def",
"_mocked_dav_client",
"(",
"*",
"names",
",",
"calendars",
"=",
"None",
")",
":",
"if",
"calendars",
"is",
"None",
":",
"calendars",
"=",
"[",
"_mock_calendar",
"(",
"name",
")",
"for",
"name",
"in",
"names",
"]",
"principal",
"=",
"Mock",
"(",
... | [
258,
0
] | [
267,
17
] | python | en | ['en', 'nl', 'en'] | True |
test_setup_component | (hass, mock_dav_client) | Test setup component with calendars. | Test setup component with calendars. | async def test_setup_component(hass, mock_dav_client):
"""Test setup component with calendars."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.first")
assert state.name == "First"
state = hass.states.get("calendar.second")
assert state.name == "Second" | [
"async",
"def",
"test_setup_component",
"(",
"hass",
",",
"mock_dav_client",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_block_till_d... | [
281,
0
] | [
289,
33
] | python | en | ['en', 'en', 'en'] | True |
test_setup_component_with_no_calendar_matching | (hass, mock_dav_client) | Test setup component with wrong calendar. | Test setup component with wrong calendar. | async def test_setup_component_with_no_calendar_matching(hass, mock_dav_client):
"""Test setup component with wrong calendar."""
config = dict(CALDAV_CONFIG)
config["calendars"] = ["none"]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
all_calendar_states = hass.states.async_entity_ids("calendar")
assert not all_calendar_states | [
"async",
"def",
"test_setup_component_with_no_calendar_matching",
"(",
"hass",
",",
"mock_dav_client",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"calendars\"",
"]",
"=",
"[",
"\"none\"",
"]",
"assert",
"await",
"async_setup_compone... | [
292,
0
] | [
301,
34
] | python | en | ['en', 'en', 'en'] | True |
test_setup_component_with_a_calendar_match | (hass, mock_dav_client) | Test setup component with right calendar. | Test setup component with right calendar. | async def test_setup_component_with_a_calendar_match(hass, mock_dav_client):
"""Test setup component with right calendar."""
config = dict(CALDAV_CONFIG)
config["calendars"] = ["Second"]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
all_calendar_states = hass.states.async_entity_ids("calendar")
assert len(all_calendar_states) == 1
state = hass.states.get("calendar.second")
assert state.name == "Second" | [
"async",
"def",
"test_setup_component_with_a_calendar_match",
"(",
"hass",
",",
"mock_dav_client",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"calendars\"",
"]",
"=",
"[",
"\"Second\"",
"]",
"assert",
"await",
"async_setup_component... | [
304,
0
] | [
315,
33
] | python | en | ['en', 'en', 'en'] | True |
test_setup_component_with_one_custom_calendar | (hass, mock_dav_client) | Test setup component with custom calendars. | Test setup component with custom calendars. | async def test_setup_component_with_one_custom_calendar(hass, mock_dav_client):
"""Test setup component with custom calendars."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "HomeOffice", "calendar": "Second", "search": "HomeOffice"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
all_calendar_states = hass.states.async_entity_ids("calendar")
assert len(all_calendar_states) == 1
state = hass.states.get("calendar.second_homeoffice")
assert state.name == "HomeOffice" | [
"async",
"def",
"test_setup_component_with_one_custom_calendar",
"(",
"hass",
",",
"mock_dav_client",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"HomeOffice\"",
",",
"\"... | [
318,
0
] | [
331,
37
] | python | en | ['en', 'pt', 'en'] | True |
test_ongoing_event | (mock_now, hass, calendar) | Test that the ongoing event is returned. | Test that the ongoing event is returned. | async def test_ongoing_event(mock_now, hass, calendar):
"""Test that the ongoing event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a normal event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy",
} | [
"async",
"def",
"test_ongoing_event",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_... | [
335,
0
] | [
352,
5
] | python | en | ['en', 'en', 'en'] | True |
test_just_ended_event | (mock_now, hass, calendar) | Test that the next ongoing event is returned. | Test that the next ongoing event is returned. | async def test_just_ended_event(mock_now, hass, calendar):
"""Test that the next ongoing event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a normal event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy",
} | [
"async",
"def",
"test_just_ended_event",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"asy... | [
356,
0
] | [
373,
5
] | python | en | ['en', 'en', 'en'] | True |
test_ongoing_event_different_tz | (mock_now, hass, calendar) | Test that the ongoing event with another timezone is returned. | Test that the ongoing event with another timezone is returned. | async def test_ongoing_event_different_tz(mock_now, hass, calendar):
"""Test that the ongoing event with another timezone is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "Enjoy the sun",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 16:30:00",
"description": "Sunny day",
"end_time": "2017-11-27 17:30:00",
"location": "San Francisco",
} | [
"async",
"def",
"test_ongoing_event_different_tz",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
"... | [
377,
0
] | [
394,
5
] | python | en | ['en', 'en', 'en'] | True |
test_ongoing_floating_event_returned | (mock_now, hass, calendar) | Test that floating events without timezones work. | Test that floating events without timezones work. | async def test_ongoing_floating_event_returned(mock_now, hass, calendar):
"""Test that floating events without timezones work."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
print(dt.DEFAULT_TIME_ZONE)
print(state)
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a floating Event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 19:00:00",
"end_time": "2017-11-27 20:00:00",
"location": "Hamburg",
"description": "What a day",
} | [
"async",
"def",
"test_ongoing_floating_event_returned",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass"... | [
398,
0
] | [
417,
5
] | python | en | ['en', 'en', 'en'] | True |
test_ongoing_event_with_offset | (mock_now, hass, calendar) | Test that the offset is taken into account. | Test that the offset is taken into account. | async def test_ongoing_event_with_offset(mock_now, hass, calendar):
"""Test that the offset is taken into account."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is an offset event",
"all_day": False,
"offset_reached": True,
"start_time": "2017-11-27 10:00:00",
"end_time": "2017-11-27 11:00:00",
"location": "Hamburg",
"description": "Surprisingly shiny",
} | [
"async",
"def",
"test_ongoing_event_with_offset",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".... | [
421,
0
] | [
438,
5
] | python | en | ['en', 'en', 'en'] | True |
test_matching_filter | (mock_now, hass, calendar) | Test that the matching event is returned. | Test that the matching event is returned. | async def test_matching_filter(mock_now, hass, calendar):
"""Test that the matching event is returned."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "Private", "calendar": "Private", "search": "This is a normal event"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a normal event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy",
} | [
"async",
"def",
"test_matching_filter",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"calendar\"",
... | [
442,
0
] | [
464,
5
] | python | en | ['en', 'en', 'en'] | True |
test_matching_filter_real_regexp | (mock_now, hass, calendar) | Test that the event matching the regexp is returned. | Test that the event matching the regexp is returned. | async def test_matching_filter_real_regexp(mock_now, hass, calendar):
"""Test that the event matching the regexp is returned."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "Private", "calendar": "Private", "search": r".*rainy"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a normal event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 17:00:00",
"end_time": "2017-11-27 18:00:00",
"location": "Hamburg",
"description": "Surprisingly rainy",
} | [
"async",
"def",
"test_matching_filter_real_regexp",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"ca... | [
468,
0
] | [
490,
5
] | python | en | ['en', 'en', 'en'] | True |
test_filter_matching_past_event | (mock_now, hass, calendar) | Test that the matching past event is not returned. | Test that the matching past event is not returned. | async def test_filter_matching_past_event(mock_now, hass, calendar):
"""Test that the matching past event is not returned."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "Private", "calendar": "Private", "search": "This is a normal event"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == "off" | [
"async",
"def",
"test_filter_matching_past_event",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"cal... | [
494,
0
] | [
506,
31
] | python | en | ['en', 'en', 'en'] | True |
test_no_result_with_filtering | (mock_now, hass, calendar) | Test that nothing is returned since nothing matches. | Test that nothing is returned since nothing matches. | async def test_no_result_with_filtering(mock_now, hass, calendar):
"""Test that nothing is returned since nothing matches."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{
"name": "Private",
"calendar": "Private",
"search": "This is a non-existing event",
}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == "off" | [
"async",
"def",
"test_no_result_with_filtering",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"calen... | [
510,
0
] | [
526,
31
] | python | en | ['en', 'en', 'en'] | True |
test_all_day_event_returned | (mock_now, hass, calendar) | Test that the event lasting the whole day is returned. | Test that the event lasting the whole day is returned. | async def test_all_day_event_returned(mock_now, hass, calendar):
"""Test that the event lasting the whole day is returned."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "Private", "calendar": "Private", "search": ".*"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is an all day event",
"all_day": True,
"offset_reached": False,
"start_time": "2017-11-27 00:00:00",
"end_time": "2017-11-28 00:00:00",
"location": "Hamburg",
"description": "What a beautiful day",
} | [
"async",
"def",
"test_all_day_event_returned",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"calenda... | [
530,
0
] | [
552,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule | (mock_now, hass, calendar) | Test that the future recurring event is returned. | Test that the future recurring event is returned. | async def test_event_rrule(mock_now, hass, calendar):
"""Test that the future recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 22:00:00",
"end_time": "2017-11-27 22:30:00",
"location": "Hamburg",
"description": "Every day for a while",
} | [
"async",
"def",
"test_event_rrule",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"async_bl... | [
556,
0
] | [
573,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_ongoing | (mock_now, hass, calendar) | Test that the current recurring event is returned. | Test that the current recurring event is returned. | async def test_event_rrule_ongoing(mock_now, hass, calendar):
"""Test that the current recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring event",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 22:00:00",
"end_time": "2017-11-27 22:30:00",
"location": "Hamburg",
"description": "Every day for a while",
} | [
"async",
"def",
"test_event_rrule_ongoing",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"... | [
577,
0
] | [
594,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_duration | (mock_now, hass, calendar) | Test that the future recurring event is returned. | Test that the future recurring event is returned. | async def test_event_rrule_duration(mock_now, hass, calendar):
"""Test that the future recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring event with a duration",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 23:00:00",
"end_time": "2017-11-27 23:30:00",
"location": "Hamburg",
"description": "Every day for a while as well",
} | [
"async",
"def",
"test_event_rrule_duration",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
... | [
598,
0
] | [
615,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_duration_ongoing | (mock_now, hass, calendar) | Test that the ongoing recurring event is returned. | Test that the ongoing recurring event is returned. | async def test_event_rrule_duration_ongoing(mock_now, hass, calendar):
"""Test that the ongoing recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring event with a duration",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 23:00:00",
"end_time": "2017-11-27 23:30:00",
"location": "Hamburg",
"description": "Every day for a while as well",
} | [
"async",
"def",
"test_event_rrule_duration_ongoing",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
... | [
619,
0
] | [
636,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_endless | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_endless(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring event that never ends",
"all_day": False,
"offset_reached": False,
"start_time": "2017-11-27 23:45:00",
"end_time": "2017-11-27 23:59:59",
"location": "Hamburg",
"description": "Every day forever",
} | [
"async",
"def",
"test_event_rrule_endless",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
".",
"... | [
640,
0
] | [
657,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_all_day | (mock_now, hass, calendar) | Test that the recurring all day event is returned. | Test that the recurring all day event is returned. | async def test_event_rrule_all_day(mock_now, hass, calendar):
"""Test that the recurring all day event is returned."""
config = dict(CALDAV_CONFIG)
config["custom_calendars"] = [
{"name": "Private", "calendar": "Private", "search": ".*"}
]
assert await async_setup_component(hass, "calendar", {"calendar": config})
await hass.async_block_till_done()
state = hass.states.get("calendar.private_private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is a recurring all day event",
"all_day": True,
"offset_reached": False,
"start_time": "2016-12-01 00:00:00",
"end_time": "2016-12-02 00:00:00",
"location": "Hamburg",
"description": "Groundhog Day",
} | [
"async",
"def",
"test_event_rrule_all_day",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"config",
"=",
"dict",
"(",
"CALDAV_CONFIG",
")",
"config",
"[",
"\"custom_calendars\"",
"]",
"=",
"[",
"{",
"\"name\"",
":",
"\"Private\"",
",",
"\"calendar\"... | [
664,
0
] | [
686,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_hourly_on_first | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_hourly_on_first(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is an hourly recurring event",
"all_day": False,
"offset_reached": False,
"start_time": "2015-11-27 00:00:00",
"end_time": "2015-11-27 00:30:00",
"location": "Hamburg",
"description": "The bell tolls for thee",
} | [
"async",
"def",
"test_event_rrule_hourly_on_first",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
... | [
693,
0
] | [
710,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_hourly_on_last | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_hourly_on_last(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_ON
assert dict(state.attributes) == {
"friendly_name": "Private",
"message": "This is an hourly recurring event",
"all_day": False,
"offset_reached": False,
"start_time": "2015-11-27 11:00:00",
"end_time": "2015-11-27 11:30:00",
"location": "Hamburg",
"description": "The bell tolls for thee",
} | [
"async",
"def",
"test_event_rrule_hourly_on_last",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
"... | [
717,
0
] | [
734,
5
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_hourly_off_first | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_hourly_off_first(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF | [
"async",
"def",
"test_event_rrule_hourly_off_first",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
... | [
741,
0
] | [
748,
35
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_hourly_off_last | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_hourly_off_last(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF | [
"async",
"def",
"test_event_rrule_hourly_off_last",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
... | [
755,
0
] | [
762,
35
] | python | en | ['en', 'en', 'en'] | True |
test_event_rrule_hourly_ended | (mock_now, hass, calendar) | Test that the endless recurring event is returned. | Test that the endless recurring event is returned. | async def test_event_rrule_hourly_ended(mock_now, hass, calendar):
"""Test that the endless recurring event is returned."""
assert await async_setup_component(hass, "calendar", {"calendar": CALDAV_CONFIG})
await hass.async_block_till_done()
state = hass.states.get("calendar.private")
assert state.name == calendar.name
assert state.state == STATE_OFF | [
"async",
"def",
"test_event_rrule_hourly_ended",
"(",
"mock_now",
",",
"hass",
",",
"calendar",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"\"calendar\"",
",",
"{",
"\"calendar\"",
":",
"CALDAV_CONFIG",
"}",
")",
"await",
"hass",
"."... | [
769,
0
] | [
776,
35
] | python | en | ['en', 'en', 'en'] | True |
save_randomly_initialized_version | (config_name: str, save_dir: str, **config_kwargs) | Save a randomly initialized version of a model using a pretrained config.
Args:
config_name: which config to use
save_dir: where to save the resulting model and tokenizer
config_kwargs: Passed to AutoConfig
Usage::
save_randomly_initialized_version("facebook/bart-large-cnn", "distilbart_random_cnn_6_3", encoder_layers=6, decoder_layers=3, num_beams=3)
| Save a randomly initialized version of a model using a pretrained config.
Args:
config_name: which config to use
save_dir: where to save the resulting model and tokenizer
config_kwargs: Passed to AutoConfig | def save_randomly_initialized_version(config_name: str, save_dir: str, **config_kwargs):
"""Save a randomly initialized version of a model using a pretrained config.
Args:
config_name: which config to use
save_dir: where to save the resulting model and tokenizer
config_kwargs: Passed to AutoConfig
Usage::
save_randomly_initialized_version("facebook/bart-large-cnn", "distilbart_random_cnn_6_3", encoder_layers=6, decoder_layers=3, num_beams=3)
"""
cfg = AutoConfig.from_pretrained(config_name, **config_kwargs)
model = AutoModelForSeq2SeqLM.from_config(cfg)
model.save_pretrained(save_dir)
AutoTokenizer.from_pretrained(config_name).save_pretrained(save_dir)
return model | [
"def",
"save_randomly_initialized_version",
"(",
"config_name",
":",
"str",
",",
"save_dir",
":",
"str",
",",
"*",
"*",
"config_kwargs",
")",
":",
"cfg",
"=",
"AutoConfig",
".",
"from_pretrained",
"(",
"config_name",
",",
"*",
"*",
"config_kwargs",
")",
"model... | [
20,
0
] | [
34,
16
] | python | en | ['en', 'en', 'en'] | True |
client_fixture | () | Patch of client library for tests. | Patch of client library for tests. | def client_fixture():
"""Patch of client library for tests."""
with patch(
"homeassistant.components.webostv.WebOsClient", autospec=True
) as mock_client_class:
client = mock_client_class.return_value
client.software_info = {"device_id": "a1:b1:c1:d1:e1:f1"}
client.client_key = "0123456789"
yield client | [
"def",
"client_fixture",
"(",
")",
":",
"with",
"patch",
"(",
"\"homeassistant.components.webostv.WebOsClient\"",
",",
"autospec",
"=",
"True",
")",
"as",
"mock_client_class",
":",
"client",
"=",
"mock_client_class",
".",
"return_value",
"client",
".",
"software_info"... | [
38,
0
] | [
46,
20
] | python | en | ['en', 'en', 'en'] | True |
setup_webostv | (hass) | Initialize webostv and media_player for tests. | Initialize webostv and media_player for tests. | async def setup_webostv(hass):
"""Initialize webostv and media_player for tests."""
assert await async_setup_component(
hass,
DOMAIN,
{DOMAIN: {CONF_HOST: "fake", CONF_NAME: NAME}},
)
await hass.async_block_till_done() | [
"async",
"def",
"setup_webostv",
"(",
"hass",
")",
":",
"assert",
"await",
"async_setup_component",
"(",
"hass",
",",
"DOMAIN",
",",
"{",
"DOMAIN",
":",
"{",
"CONF_HOST",
":",
"\"fake\"",
",",
"CONF_NAME",
":",
"NAME",
"}",
"}",
",",
")",
"await",
"hass"... | [
49,
0
] | [
56,
38
] | python | en | ['en', 'en', 'en'] | True |
test_mute | (hass, client) | Test simple service call. | Test simple service call. | async def test_mute(hass, client):
"""Test simple service call."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_MEDIA_VOLUME_MUTED: True,
}
await hass.services.async_call(media_player.DOMAIN, SERVICE_VOLUME_MUTE, data)
await hass.async_block_till_done()
client.set_mute.assert_called_once() | [
"async",
"def",
"test_mute",
"(",
"hass",
",",
"client",
")",
":",
"await",
"setup_webostv",
"(",
"hass",
")",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_MEDIA_VOLUME_MUTED",
":",
"True",
",",
"}",
"await",
"hass",
".",
"services",
".... | [
59,
0
] | [
71,
40
] | python | en | ['en', 'en', 'en'] | True |
test_select_source_with_empty_source_list | (hass, client) | Ensure we don't call client methods when we don't have sources. | Ensure we don't call client methods when we don't have sources. | async def test_select_source_with_empty_source_list(hass, client):
"""Ensure we don't call client methods when we don't have sources."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_INPUT_SOURCE: "nonexistent",
}
await hass.services.async_call(media_player.DOMAIN, SERVICE_SELECT_SOURCE, data)
await hass.async_block_till_done()
client.launch_app.assert_not_called()
client.set_input.assert_not_called() | [
"async",
"def",
"test_select_source_with_empty_source_list",
"(",
"hass",
",",
"client",
")",
":",
"await",
"setup_webostv",
"(",
"hass",
")",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_INPUT_SOURCE",
":",
"\"nonexistent\"",
",",
"}",
"await"... | [
74,
0
] | [
87,
40
] | python | en | ['en', 'en', 'en'] | True |
test_button | (hass, client) | Test generic button functionality. | Test generic button functionality. | async def test_button(hass, client):
"""Test generic button functionality."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_BUTTON: "test",
}
await hass.services.async_call(DOMAIN, SERVICE_BUTTON, data)
await hass.async_block_till_done()
client.button.assert_called_once()
client.button.assert_called_with("test") | [
"async",
"def",
"test_button",
"(",
"hass",
",",
"client",
")",
":",
"await",
"setup_webostv",
"(",
"hass",
")",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_BUTTON",
":",
"\"test\"",
",",
"}",
"await",
"hass",
".",
"services",
".",
"... | [
90,
0
] | [
103,
44
] | python | en | ['en', 'en', 'en'] | True |
test_command | (hass, client) | Test generic command functionality. | Test generic command functionality. | async def test_command(hass, client):
"""Test generic command functionality."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_COMMAND: "test",
}
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
await hass.async_block_till_done()
client.request.assert_called_with("test", payload=None) | [
"async",
"def",
"test_command",
"(",
"hass",
",",
"client",
")",
":",
"await",
"setup_webostv",
"(",
"hass",
")",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_COMMAND",
":",
"\"test\"",
",",
"}",
"await",
"hass",
".",
"services",
".",
... | [
106,
0
] | [
117,
59
] | python | en | ['en', 'en', 'en'] | True |
test_command_with_optional_arg | (hass, client) | Test generic command functionality. | Test generic command functionality. | async def test_command_with_optional_arg(hass, client):
"""Test generic command functionality."""
await setup_webostv(hass)
data = {
ATTR_ENTITY_ID: ENTITY_ID,
ATTR_COMMAND: "test",
ATTR_PAYLOAD: {"target": "https://www.google.com"},
}
await hass.services.async_call(DOMAIN, SERVICE_COMMAND, data)
await hass.async_block_till_done()
client.request.assert_called_with(
"test", payload={"target": "https://www.google.com"}
) | [
"async",
"def",
"test_command_with_optional_arg",
"(",
"hass",
",",
"client",
")",
":",
"await",
"setup_webostv",
"(",
"hass",
")",
"data",
"=",
"{",
"ATTR_ENTITY_ID",
":",
"ENTITY_ID",
",",
"ATTR_COMMAND",
":",
"\"test\"",
",",
"ATTR_PAYLOAD",
":",
"{",
"\"ta... | [
120,
0
] | [
134,
5
] | python | en | ['en', 'en', 'en'] | True |
test_get_device_detects_dimmer | (mock_openzwave) | Test get_device returns a normal dimmer. | Test get_device returns a normal dimmer. | def test_get_device_detects_dimmer(mock_openzwave):
"""Test get_device returns a normal dimmer."""
node = MockNode()
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert isinstance(device, light.ZwaveDimmer)
assert device.supported_features == SUPPORT_BRIGHTNESS | [
"def",
"test_get_device_detects_dimmer",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")... | [
31,
0
] | [
39,
58
] | python | en | ['en', 'en', 'en'] | True |
test_get_device_detects_colorlight | (mock_openzwave) | Test get_device returns a color light. | Test get_device returns a color light. | def test_get_device_detects_colorlight(mock_openzwave):
"""Test get_device returns a color light."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert isinstance(device, light.ZwaveColorLight)
assert device.supported_features == SUPPORT_BRIGHTNESS | SUPPORT_COLOR | [
"def",
"test_get_device_detects_colorlight",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"... | [
42,
0
] | [
50,
74
] | python | en | ['en', 'da', 'en'] | True |
test_get_device_detects_zw098 | (mock_openzwave) | Test get_device returns a zw098 color light. | Test get_device returns a zw098 color light. | def test_get_device_detects_zw098(mock_openzwave):
"""Test get_device returns a zw098 color light."""
node = MockNode(
manufacturer_id="0086",
product_id="0062",
command_classes=[const.COMMAND_CLASS_SWITCH_COLOR],
)
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert isinstance(device, light.ZwaveColorLight)
assert device.supported_features == (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
) | [
"def",
"test_get_device_detects_zw098",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"0086\"",
",",
"product_id",
"=",
"\"0062\"",
",",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
",",
"... | [
53,
0
] | [
66,
5
] | python | en | ['en', 'en', 'en'] | True |
test_get_device_detects_rgbw_light | (mock_openzwave) | Test get_device returns a color light. | Test get_device returns a color light. | def test_get_device_detects_rgbw_light(mock_openzwave):
"""Test get_device returns a color light."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
color_channels = MockValue(data=0x1D, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
device.value_added()
assert isinstance(device, light.ZwaveColorLight)
assert device.supported_features == (
SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_WHITE_VALUE
) | [
"def",
"test_get_device_detects_rgbw_light",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"... | [
69,
0
] | [
82,
5
] | python | en | ['en', 'da', 'en'] | True |
test_dimmer_turn_on | (mock_openzwave) | Test turning on a dimmable Z-Wave light. | Test turning on a dimmable Z-Wave light. | def test_dimmer_turn_on(mock_openzwave):
"""Test turning on a dimmable Z-Wave light."""
node = MockNode()
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
device.turn_on()
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 255
node.reset_mock()
device.turn_on(**{ATTR_BRIGHTNESS: 224})
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 87 # round(224 / 255 * 99)
node.reset_mock()
device.turn_on(**{ATTR_BRIGHTNESS: 120})
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 47 # round(120 / 255 * 99)
with patch.object(light, "_LOGGER", MagicMock()) as mock_logger:
device.turn_on(**{ATTR_TRANSITION: 35})
assert mock_logger.debug.called
assert node.set_dimmer.called
msg, entity_id = mock_logger.debug.mock_calls[0][1]
assert entity_id == device.entity_id | [
"def",
"test_dimmer_turn_on",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")",
"devic... | [
85,
0
] | [
124,
44
] | python | en | ['en', 'en', 'en'] | True |
test_dimmer_min_brightness | (mock_openzwave) | Test turning on a dimmable Z-Wave light to its minimum brightness. | Test turning on a dimmable Z-Wave light to its minimum brightness. | def test_dimmer_min_brightness(mock_openzwave):
"""Test turning on a dimmable Z-Wave light to its minimum brightness."""
node = MockNode()
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert not device.is_on
device.turn_on(**{ATTR_BRIGHTNESS: 1})
assert device.is_on
assert device.brightness == 1
device.turn_on(**{ATTR_BRIGHTNESS: 0})
assert device.is_on
assert device.brightness == 0 | [
"def",
"test_dimmer_min_brightness",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")",
... | [
127,
0
] | [
144,
33
] | python | en | ['en', 'en', 'en'] | True |
test_dimmer_transitions | (mock_openzwave) | Test dimming transition on a dimmable Z-Wave light. | Test dimming transition on a dimmable Z-Wave light. | def test_dimmer_transitions(mock_openzwave):
"""Test dimming transition on a dimmable Z-Wave light."""
node = MockNode()
value = MockValue(data=0, node=node)
duration = MockValue(data=0, node=node)
values = MockLightValues(primary=value, dimming_duration=duration)
device = light.get_device(node=node, values=values, node_config={})
assert device.supported_features == SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
# Test turn_on
# Factory Default
device.turn_on()
assert duration.data == 0xFF
# Seconds transition
device.turn_on(**{ATTR_TRANSITION: 45})
assert duration.data == 45
# Minutes transition
device.turn_on(**{ATTR_TRANSITION: 245})
assert duration.data == 0x83
# Clipped transition
device.turn_on(**{ATTR_TRANSITION: 10000})
assert duration.data == 0xFE
# Test turn_off
# Factory Default
device.turn_off()
assert duration.data == 0xFF
# Seconds transition
device.turn_off(**{ATTR_TRANSITION: 45})
assert duration.data == 45
# Minutes transition
device.turn_off(**{ATTR_TRANSITION: 245})
assert duration.data == 0x83
# Clipped transition
device.turn_off(**{ATTR_TRANSITION: 10000})
assert duration.data == 0xFE | [
"def",
"test_dimmer_transitions",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"duration",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"="... | [
147,
0
] | [
188,
32
] | python | en | ['id', 'en', 'en'] | True |
test_dimmer_turn_off | (mock_openzwave) | Test turning off a dimmable Z-Wave light. | Test turning off a dimmable Z-Wave light. | def test_dimmer_turn_off(mock_openzwave):
"""Test turning off a dimmable Z-Wave light."""
node = MockNode()
value = MockValue(data=46, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
device.turn_off()
assert node.set_dimmer.called
value_id, brightness = node.set_dimmer.mock_calls[0][1]
assert value_id == value.value_id
assert brightness == 0 | [
"def",
"test_dimmer_turn_off",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"46",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")",
"dev... | [
191,
0
] | [
203,
26
] | python | en | ['en', 'en', 'en'] | True |
test_dimmer_value_changed | (mock_openzwave) | Test value changed for dimmer lights. | Test value changed for dimmer lights. | def test_dimmer_value_changed(mock_openzwave):
"""Test value changed for dimmer lights."""
node = MockNode()
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert not device.is_on
value.data = 46
value_changed(value)
assert device.is_on
assert device.brightness == 118 | [
"def",
"test_dimmer_value_changed",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")",
... | [
206,
0
] | [
219,
35
] | python | en | ['en', 'en', 'en'] | True |
test_dimmer_refresh_value | (mock_openzwave) | Test value changed for dimmer lights. | Test value changed for dimmer lights. | def test_dimmer_refresh_value(mock_openzwave):
"""Test value changed for dimmer lights."""
node = MockNode()
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(
node=node,
values=values,
node_config={zwave.CONF_REFRESH_VALUE: True, zwave.CONF_REFRESH_DELAY: 5},
)
assert not device.is_on
with patch.object(light, "Timer") as mock_timer:
value.data = 46
value_changed(value)
assert not device.is_on
assert mock_timer.called
assert len(mock_timer.mock_calls) == 2
timeout, callback = mock_timer.mock_calls[0][1][:2]
assert timeout == 5
assert mock_timer().start.called
assert len(mock_timer().start.mock_calls) == 1
with patch.object(light, "Timer") as mock_timer_2:
value_changed(value)
assert not device.is_on
assert mock_timer().cancel.called
assert len(mock_timer_2.mock_calls) == 2
timeout, callback = mock_timer_2.mock_calls[0][1][:2]
assert timeout == 5
assert mock_timer_2().start.called
assert len(mock_timer_2().start.mock_calls) == 1
callback()
assert device.is_on
assert device.brightness == 118 | [
"def",
"test_dimmer_refresh_value",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"values",
"=",
"MockLightValues",
"(",
"primary",
"=",
"value",
")",
... | [
222,
0
] | [
259,
43
] | python | en | ['en', 'en', 'en'] | True |
test_set_hs_color | (mock_openzwave) | Test setting zwave light color. | Test setting zwave light color. | def test_set_hs_color(mock_openzwave):
"""Test setting zwave light color."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
# Supports RGB only
color_channels = MockValue(data=0x1C, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
assert color.data == "#0000000000"
device.turn_on(**{ATTR_HS_COLOR: (30, 50)})
assert color.data == "#ffbf7f0000" | [
"def",
"test_set_hs_color",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
"... | [
262,
0
] | [
276,
38
] | python | da | ['de', 'da', 'en'] | False |
test_set_white_value | (mock_openzwave) | Test setting zwave light color. | Test setting zwave light color. | def test_set_white_value(mock_openzwave):
"""Test setting zwave light color."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
# Supports RGBW
color_channels = MockValue(data=0x1D, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
assert color.data == "#0000000000"
device.turn_on(**{ATTR_WHITE_VALUE: 200})
assert color.data == "#ffffffc800" | [
"def",
"test_set_white_value",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
... | [
279,
0
] | [
293,
38
] | python | da | ['de', 'da', 'en'] | False |
test_disable_white_if_set_color | (mock_openzwave) |
Test that _white is set to 0 if turn_on with ATTR_HS_COLOR.
See Issue #13930 - many RGBW ZWave bulbs will only activate the RGB LED to
produce color if _white is set to zero.
|
Test that _white is set to 0 if turn_on with ATTR_HS_COLOR. | def test_disable_white_if_set_color(mock_openzwave):
"""
Test that _white is set to 0 if turn_on with ATTR_HS_COLOR.
See Issue #13930 - many RGBW ZWave bulbs will only activate the RGB LED to
produce color if _white is set to zero.
"""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
# Supports RGB only
color_channels = MockValue(data=0x1C, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
device._white = 234
assert color.data == "#0000000000"
assert device.white_value == 234
device.turn_on(**{ATTR_HS_COLOR: (30, 50)})
assert device.white_value == 0
assert color.data == "#ffbf7f0000" | [
"def",
"test_disable_white_if_set_color",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"nod... | [
296,
0
] | [
318,
38
] | python | en | ['en', 'error', 'th'] | False |
test_zw098_set_color_temp | (mock_openzwave) | Test setting zwave light color. | Test setting zwave light color. | def test_zw098_set_color_temp(mock_openzwave):
"""Test setting zwave light color."""
node = MockNode(
manufacturer_id="0086",
product_id="0062",
command_classes=[const.COMMAND_CLASS_SWITCH_COLOR],
)
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
# Supports RGB, warm white, cold white
color_channels = MockValue(data=0x1F, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
assert color.data == "#0000000000"
device.turn_on(**{ATTR_COLOR_TEMP: 200})
assert color.data == "#00000000ff"
device.turn_on(**{ATTR_COLOR_TEMP: 400})
assert color.data == "#000000ff00" | [
"def",
"test_zw098_set_color_temp",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"manufacturer_id",
"=",
"\"0086\"",
",",
"product_id",
"=",
"\"0062\"",
",",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
",",
")",
... | [
321,
0
] | [
343,
38
] | python | da | ['de', 'da', 'en'] | False |
test_rgb_not_supported | (mock_openzwave) | Test value changed for rgb lights. | Test value changed for rgb lights. | def test_rgb_not_supported(mock_openzwave):
"""Test value changed for rgb lights."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
color = MockValue(data="#0000000000", node=node)
# Supports color temperature only
color_channels = MockValue(data=0x01, node=node)
values = MockLightValues(primary=value, color=color, color_channels=color_channels)
device = light.get_device(node=node, values=values, node_config={})
assert device.hs_color is None | [
"def",
"test_rgb_not_supported",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")"... | [
346,
0
] | [
356,
34
] | python | en | ['en', 'en', 'en'] | True |
test_no_color_value | (mock_openzwave) | Test value changed for rgb lights. | Test value changed for rgb lights. | def test_no_color_value(mock_openzwave):
"""Test value changed for rgb lights."""
node = MockNode(command_classes=[const.COMMAND_CLASS_SWITCH_COLOR])
value = MockValue(data=0, node=node)
values = MockLightValues(primary=value)
device = light.get_device(node=node, values=values, node_config={})
assert device.hs_color is None | [
"def",
"test_no_color_value",
"(",
"mock_openzwave",
")",
":",
"node",
"=",
"MockNode",
"(",
"command_classes",
"=",
"[",
"const",
".",
"COMMAND_CLASS_SWITCH_COLOR",
"]",
")",
"value",
"=",
"MockValue",
"(",
"data",
"=",
"0",
",",
"node",
"=",
"node",
")",
... | [
359,
0
] | [
366,
34
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.