Search is not available for this dataset
identifier
stringlengths 1
155
| parameters
stringlengths 2
6.09k
| docstring
stringlengths 11
63.4k
| docstring_summary
stringlengths 0
63.4k
| function
stringlengths 29
99.8k
| function_tokens
sequence | start_point
sequence | end_point
sequence | language
stringclasses 1
value | docstring_language
stringlengths 2
7
| docstring_language_predictions
stringlengths 18
23
| is_langid_reliable
stringclasses 2
values |
---|---|---|---|---|---|---|---|---|---|---|---|
test_update_sensor | (hass) | Test async_update for sensor. | Test async_update for sensor. | async def test_update_sensor(hass):
"""Test async_update for sensor."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: HOST, CONF_PORT: PORT},
unique_id=f"{HOST}:{PORT}",
)
starting_time = static_datetime()
timestamp = future_timestamp(100)
with patch("homeassistant.util.dt.utcnow", return_value=starting_time), patch(
"homeassistant.components.cert_expiry.get_cert_expiry_timestamp",
return_value=timestamp,
):
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == timestamp.isoformat()
assert state.attributes.get("error") == "None"
assert state.attributes.get("is_valid")
next_update = starting_time + timedelta(hours=24)
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
"homeassistant.components.cert_expiry.get_cert_expiry_timestamp",
return_value=timestamp,
):
async_fire_time_changed(hass, utcnow() + timedelta(hours=24))
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == timestamp.isoformat()
assert state.attributes.get("error") == "None"
assert state.attributes.get("is_valid") | [
"async",
"def",
"test_update_sensor",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"HOST",
",",
"CONF_PORT",
":",
"PORT",
"}",
",",
"unique_id",
"=",
"f\"{HOST}:{PORT}\"",
",",
")",
"starting_time",
"=",
"static_datetime",
"(",
")",
"timestamp",
"=",
"future_timestamp",
"(",
"100",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"starting_time",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.get_cert_expiry_timestamp\"",
",",
"return_value",
"=",
"timestamp",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"assert",
"state",
".",
"state",
"==",
"timestamp",
".",
"isoformat",
"(",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"error\"",
")",
"==",
"\"None\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"is_valid\"",
")",
"next_update",
"=",
"starting_time",
"+",
"timedelta",
"(",
"hours",
"=",
"24",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"next_update",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.get_cert_expiry_timestamp\"",
",",
"return_value",
"=",
"timestamp",
",",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"24",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"assert",
"state",
".",
"state",
"==",
"timestamp",
".",
"isoformat",
"(",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"error\"",
")",
"==",
"\"None\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"is_valid\"",
")"
] | [
97,
0
] | [
136,
43
] | python | en | ['en', 'no', 'en'] | True |
test_update_sensor_network_errors | (hass) | Test async_update for sensor. | Test async_update for sensor. | async def test_update_sensor_network_errors(hass):
"""Test async_update for sensor."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_HOST: HOST, CONF_PORT: PORT},
unique_id=f"{HOST}:{PORT}",
)
starting_time = static_datetime()
timestamp = future_timestamp(100)
with patch("homeassistant.util.dt.utcnow", return_value=starting_time), patch(
"homeassistant.components.cert_expiry.get_cert_expiry_timestamp",
return_value=timestamp,
):
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == timestamp.isoformat()
assert state.attributes.get("error") == "None"
assert state.attributes.get("is_valid")
next_update = starting_time + timedelta(hours=24)
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
"homeassistant.components.cert_expiry.helper.get_cert",
side_effect=socket.gaierror,
):
async_fire_time_changed(hass, utcnow() + timedelta(hours=24))
await hass.async_block_till_done()
next_update = starting_time + timedelta(hours=48)
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state.state == STATE_UNAVAILABLE
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
"homeassistant.components.cert_expiry.get_cert_expiry_timestamp",
return_value=timestamp,
):
async_fire_time_changed(hass, utcnow() + timedelta(hours=48))
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state is not None
assert state.state != STATE_UNAVAILABLE
assert state.state == timestamp.isoformat()
assert state.attributes.get("error") == "None"
assert state.attributes.get("is_valid")
next_update = starting_time + timedelta(hours=72)
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
"homeassistant.components.cert_expiry.helper.get_cert",
side_effect=ssl.SSLError("something bad"),
):
async_fire_time_changed(hass, utcnow() + timedelta(hours=72))
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state is not None
assert state.state == STATE_UNKNOWN
assert state.attributes.get("error") == "something bad"
assert not state.attributes.get("is_valid")
next_update = starting_time + timedelta(hours=96)
with patch("homeassistant.util.dt.utcnow", return_value=next_update), patch(
"homeassistant.components.cert_expiry.helper.get_cert", side_effect=Exception()
):
async_fire_time_changed(hass, utcnow() + timedelta(hours=96))
await hass.async_block_till_done()
state = hass.states.get("sensor.cert_expiry_timestamp_example_com")
assert state.state == STATE_UNAVAILABLE | [
"async",
"def",
"test_update_sensor_network_errors",
"(",
"hass",
")",
":",
"entry",
"=",
"MockConfigEntry",
"(",
"domain",
"=",
"DOMAIN",
",",
"data",
"=",
"{",
"CONF_HOST",
":",
"HOST",
",",
"CONF_PORT",
":",
"PORT",
"}",
",",
"unique_id",
"=",
"f\"{HOST}:{PORT}\"",
",",
")",
"starting_time",
"=",
"static_datetime",
"(",
")",
"timestamp",
"=",
"future_timestamp",
"(",
"100",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"starting_time",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.get_cert_expiry_timestamp\"",
",",
"return_value",
"=",
"timestamp",
",",
")",
":",
"entry",
".",
"add_to_hass",
"(",
"hass",
")",
"assert",
"await",
"hass",
".",
"config_entries",
".",
"async_setup",
"(",
"entry",
".",
"entry_id",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"assert",
"state",
".",
"state",
"==",
"timestamp",
".",
"isoformat",
"(",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"error\"",
")",
"==",
"\"None\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"is_valid\"",
")",
"next_update",
"=",
"starting_time",
"+",
"timedelta",
"(",
"hours",
"=",
"24",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"next_update",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.helper.get_cert\"",
",",
"side_effect",
"=",
"socket",
".",
"gaierror",
",",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"24",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"next_update",
"=",
"starting_time",
"+",
"timedelta",
"(",
"hours",
"=",
"48",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"next_update",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.get_cert_expiry_timestamp\"",
",",
"return_value",
"=",
"timestamp",
",",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"48",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"!=",
"STATE_UNAVAILABLE",
"assert",
"state",
".",
"state",
"==",
"timestamp",
".",
"isoformat",
"(",
")",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"error\"",
")",
"==",
"\"None\"",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"is_valid\"",
")",
"next_update",
"=",
"starting_time",
"+",
"timedelta",
"(",
"hours",
"=",
"72",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"next_update",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.helper.get_cert\"",
",",
"side_effect",
"=",
"ssl",
".",
"SSLError",
"(",
"\"something bad\"",
")",
",",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"72",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"STATE_UNKNOWN",
"assert",
"state",
".",
"attributes",
".",
"get",
"(",
"\"error\"",
")",
"==",
"\"something bad\"",
"assert",
"not",
"state",
".",
"attributes",
".",
"get",
"(",
"\"is_valid\"",
")",
"next_update",
"=",
"starting_time",
"+",
"timedelta",
"(",
"hours",
"=",
"96",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"next_update",
")",
",",
"patch",
"(",
"\"homeassistant.components.cert_expiry.helper.get_cert\"",
",",
"side_effect",
"=",
"Exception",
"(",
")",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"hours",
"=",
"96",
")",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.cert_expiry_timestamp_example_com\"",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_UNAVAILABLE"
] | [
139,
0
] | [
217,
43
] | python | en | ['en', 'no', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the Fritzbox smarthome thermostat from config_entry. | Set up the Fritzbox smarthome thermostat from config_entry. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the Fritzbox smarthome thermostat from config_entry."""
entities = []
devices = hass.data[FRITZBOX_DOMAIN][CONF_DEVICES]
fritz = hass.data[FRITZBOX_DOMAIN][CONF_CONNECTIONS][config_entry.entry_id]
for device in await hass.async_add_executor_job(fritz.get_devices):
if device.has_thermostat and device.ain not in devices:
entities.append(FritzboxThermostat(device, fritz))
devices.add(device.ain)
async_add_entities(entities) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"entities",
"=",
"[",
"]",
"devices",
"=",
"hass",
".",
"data",
"[",
"FRITZBOX_DOMAIN",
"]",
"[",
"CONF_DEVICES",
"]",
"fritz",
"=",
"hass",
".",
"data",
"[",
"FRITZBOX_DOMAIN",
"]",
"[",
"CONF_CONNECTIONS",
"]",
"[",
"config_entry",
".",
"entry_id",
"]",
"for",
"device",
"in",
"await",
"hass",
".",
"async_add_executor_job",
"(",
"fritz",
".",
"get_devices",
")",
":",
"if",
"device",
".",
"has_thermostat",
"and",
"device",
".",
"ain",
"not",
"in",
"devices",
":",
"entities",
".",
"append",
"(",
"FritzboxThermostat",
"(",
"device",
",",
"fritz",
")",
")",
"devices",
".",
"add",
"(",
"device",
".",
"ain",
")",
"async_add_entities",
"(",
"entities",
")"
] | [
49,
0
] | [
60,
32
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.__init__ | (self, device, fritz) | Initialize the thermostat. | Initialize the thermostat. | def __init__(self, device, fritz):
"""Initialize the thermostat."""
self._device = device
self._fritz = fritz
self._current_temperature = self._device.actual_temperature
self._target_temperature = self._device.target_temperature
self._comfort_temperature = self._device.comfort_temperature
self._eco_temperature = self._device.eco_temperature | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"fritz",
")",
":",
"self",
".",
"_device",
"=",
"device",
"self",
".",
"_fritz",
"=",
"fritz",
"self",
".",
"_current_temperature",
"=",
"self",
".",
"_device",
".",
"actual_temperature",
"self",
".",
"_target_temperature",
"=",
"self",
".",
"_device",
".",
"target_temperature",
"self",
".",
"_comfort_temperature",
"=",
"self",
".",
"_device",
".",
"comfort_temperature",
"self",
".",
"_eco_temperature",
"=",
"self",
".",
"_device",
".",
"eco_temperature"
] | [
66,
4
] | [
73,
60
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.device_info | (self) | Return device specific attributes. | Return device specific attributes. | def device_info(self):
"""Return device specific attributes."""
return {
"name": self.name,
"identifiers": {(FRITZBOX_DOMAIN, self._device.ain)},
"manufacturer": self._device.manufacturer,
"model": self._device.productname,
"sw_version": self._device.fw_version,
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"name\"",
":",
"self",
".",
"name",
",",
"\"identifiers\"",
":",
"{",
"(",
"FRITZBOX_DOMAIN",
",",
"self",
".",
"_device",
".",
"ain",
")",
"}",
",",
"\"manufacturer\"",
":",
"self",
".",
"_device",
".",
"manufacturer",
",",
"\"model\"",
":",
"self",
".",
"_device",
".",
"productname",
",",
"\"sw_version\"",
":",
"self",
".",
"_device",
".",
"fw_version",
",",
"}"
] | [
76,
4
] | [
84,
9
] | python | en | ['fr', 'it', 'en'] | False |
FritzboxThermostat.unique_id | (self) | Return the unique ID of the device. | Return the unique ID of the device. | def unique_id(self):
"""Return the unique ID of the device."""
return self._device.ain | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"ain"
] | [
87,
4
] | [
89,
31
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_FLAGS"
] | [
92,
4
] | [
94,
28
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.available | (self) | Return if thermostat is available. | Return if thermostat is available. | def available(self):
"""Return if thermostat is available."""
return self._device.present | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"present"
] | [
97,
4
] | [
99,
35
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
return self._device.name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device",
".",
"name"
] | [
102,
4
] | [
104,
32
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.temperature_unit | (self) | Return the unit of measurement that is used. | Return the unit of measurement that is used. | def temperature_unit(self):
"""Return the unit of measurement that is used."""
return TEMP_CELSIUS | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"TEMP_CELSIUS"
] | [
107,
4
] | [
109,
27
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.precision | (self) | Return precision 0.5. | Return precision 0.5. | def precision(self):
"""Return precision 0.5."""
return PRECISION_HALVES | [
"def",
"precision",
"(",
"self",
")",
":",
"return",
"PRECISION_HALVES"
] | [
112,
4
] | [
114,
31
] | python | en | ['es', 'it', 'en'] | False |
FritzboxThermostat.current_temperature | (self) | Return the current temperature. | Return the current temperature. | def current_temperature(self):
"""Return the current temperature."""
return self._current_temperature | [
"def",
"current_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_temperature"
] | [
117,
4
] | [
119,
40
] | python | en | ['en', 'la', 'en'] | True |
FritzboxThermostat.target_temperature | (self) | Return the temperature we try to reach. | Return the temperature we try to reach. | def target_temperature(self):
"""Return the temperature we try to reach."""
if self._target_temperature == ON_API_TEMPERATURE:
return ON_REPORT_SET_TEMPERATURE
if self._target_temperature == OFF_API_TEMPERATURE:
return OFF_REPORT_SET_TEMPERATURE
return self._target_temperature | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"if",
"self",
".",
"_target_temperature",
"==",
"ON_API_TEMPERATURE",
":",
"return",
"ON_REPORT_SET_TEMPERATURE",
"if",
"self",
".",
"_target_temperature",
"==",
"OFF_API_TEMPERATURE",
":",
"return",
"OFF_REPORT_SET_TEMPERATURE",
"return",
"self",
".",
"_target_temperature"
] | [
122,
4
] | [
128,
39
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | def set_temperature(self, **kwargs):
"""Set new target temperature."""
if ATTR_HVAC_MODE in kwargs:
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
self.set_hvac_mode(hvac_mode)
elif ATTR_TEMPERATURE in kwargs:
temperature = kwargs.get(ATTR_TEMPERATURE)
self._device.set_target_temperature(temperature) | [
"def",
"set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_HVAC_MODE",
"in",
"kwargs",
":",
"hvac_mode",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_HVAC_MODE",
")",
"self",
".",
"set_hvac_mode",
"(",
"hvac_mode",
")",
"elif",
"ATTR_TEMPERATURE",
"in",
"kwargs",
":",
"temperature",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"self",
".",
"_device",
".",
"set_target_temperature",
"(",
"temperature",
")"
] | [
130,
4
] | [
137,
60
] | python | en | ['en', 'ca', 'en'] | True |
FritzboxThermostat.hvac_mode | (self) | Return the current operation mode. | Return the current operation mode. | def hvac_mode(self):
"""Return the current operation mode."""
if (
self._target_temperature == OFF_REPORT_SET_TEMPERATURE
or self._target_temperature == OFF_API_TEMPERATURE
):
return HVAC_MODE_OFF
return HVAC_MODE_HEAT | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"if",
"(",
"self",
".",
"_target_temperature",
"==",
"OFF_REPORT_SET_TEMPERATURE",
"or",
"self",
".",
"_target_temperature",
"==",
"OFF_API_TEMPERATURE",
")",
":",
"return",
"HVAC_MODE_OFF",
"return",
"HVAC_MODE_HEAT"
] | [
140,
4
] | [
148,
29
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.hvac_modes | (self) | Return the list of available operation modes. | Return the list of available operation modes. | def hvac_modes(self):
"""Return the list of available operation modes."""
return OPERATION_LIST | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"OPERATION_LIST"
] | [
151,
4
] | [
153,
29
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.set_hvac_mode | (self, hvac_mode) | Set new operation mode. | Set new operation mode. | def set_hvac_mode(self, hvac_mode):
"""Set new operation mode."""
if hvac_mode == HVAC_MODE_OFF:
self.set_temperature(temperature=OFF_REPORT_SET_TEMPERATURE)
else:
self.set_temperature(temperature=self._comfort_temperature) | [
"def",
"set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":",
"if",
"hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"self",
".",
"set_temperature",
"(",
"temperature",
"=",
"OFF_REPORT_SET_TEMPERATURE",
")",
"else",
":",
"self",
".",
"set_temperature",
"(",
"temperature",
"=",
"self",
".",
"_comfort_temperature",
")"
] | [
155,
4
] | [
160,
71
] | python | en | ['en', 'ny', 'en'] | True |
FritzboxThermostat.preset_mode | (self) | Return current preset mode. | Return current preset mode. | def preset_mode(self):
"""Return current preset mode."""
if self._target_temperature == self._comfort_temperature:
return PRESET_COMFORT
if self._target_temperature == self._eco_temperature:
return PRESET_ECO | [
"def",
"preset_mode",
"(",
"self",
")",
":",
"if",
"self",
".",
"_target_temperature",
"==",
"self",
".",
"_comfort_temperature",
":",
"return",
"PRESET_COMFORT",
"if",
"self",
".",
"_target_temperature",
"==",
"self",
".",
"_eco_temperature",
":",
"return",
"PRESET_ECO"
] | [
163,
4
] | [
168,
29
] | python | en | ['en', 'ca', 'en'] | True |
FritzboxThermostat.preset_modes | (self) | Return supported preset modes. | Return supported preset modes. | def preset_modes(self):
"""Return supported preset modes."""
return [PRESET_ECO, PRESET_COMFORT] | [
"def",
"preset_modes",
"(",
"self",
")",
":",
"return",
"[",
"PRESET_ECO",
",",
"PRESET_COMFORT",
"]"
] | [
171,
4
] | [
173,
43
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.set_preset_mode | (self, preset_mode) | Set preset mode. | Set preset mode. | def set_preset_mode(self, preset_mode):
"""Set preset mode."""
if preset_mode == PRESET_COMFORT:
self.set_temperature(temperature=self._comfort_temperature)
elif preset_mode == PRESET_ECO:
self.set_temperature(temperature=self._eco_temperature) | [
"def",
"set_preset_mode",
"(",
"self",
",",
"preset_mode",
")",
":",
"if",
"preset_mode",
"==",
"PRESET_COMFORT",
":",
"self",
".",
"set_temperature",
"(",
"temperature",
"=",
"self",
".",
"_comfort_temperature",
")",
"elif",
"preset_mode",
"==",
"PRESET_ECO",
":",
"self",
".",
"set_temperature",
"(",
"temperature",
"=",
"self",
".",
"_eco_temperature",
")"
] | [
175,
4
] | [
180,
67
] | python | de | ['de', 'pt', 'it'] | False |
FritzboxThermostat.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMPERATURE | [
"def",
"min_temp",
"(",
"self",
")",
":",
"return",
"MIN_TEMPERATURE"
] | [
183,
4
] | [
185,
30
] | python | en | ['en', 'la', 'en'] | True |
FritzboxThermostat.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMPERATURE | [
"def",
"max_temp",
"(",
"self",
")",
":",
"return",
"MAX_TEMPERATURE"
] | [
188,
4
] | [
190,
30
] | python | en | ['en', 'la', 'en'] | True |
FritzboxThermostat.device_state_attributes | (self) | Return the device specific state attributes. | Return the device specific state attributes. | def device_state_attributes(self):
"""Return the device specific state attributes."""
attrs = {
ATTR_STATE_BATTERY_LOW: self._device.battery_low,
ATTR_STATE_DEVICE_LOCKED: self._device.device_lock,
ATTR_STATE_LOCKED: self._device.lock,
}
# the following attributes are available since fritzos 7
if self._device.battery_level is not None:
attrs[ATTR_BATTERY_LEVEL] = self._device.battery_level
if self._device.holiday_active is not None:
attrs[ATTR_STATE_HOLIDAY_MODE] = self._device.holiday_active
if self._device.summer_active is not None:
attrs[ATTR_STATE_SUMMER_MODE] = self._device.summer_active
if ATTR_STATE_WINDOW_OPEN is not None:
attrs[ATTR_STATE_WINDOW_OPEN] = self._device.window_open
return attrs | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attrs",
"=",
"{",
"ATTR_STATE_BATTERY_LOW",
":",
"self",
".",
"_device",
".",
"battery_low",
",",
"ATTR_STATE_DEVICE_LOCKED",
":",
"self",
".",
"_device",
".",
"device_lock",
",",
"ATTR_STATE_LOCKED",
":",
"self",
".",
"_device",
".",
"lock",
",",
"}",
"# the following attributes are available since fritzos 7",
"if",
"self",
".",
"_device",
".",
"battery_level",
"is",
"not",
"None",
":",
"attrs",
"[",
"ATTR_BATTERY_LEVEL",
"]",
"=",
"self",
".",
"_device",
".",
"battery_level",
"if",
"self",
".",
"_device",
".",
"holiday_active",
"is",
"not",
"None",
":",
"attrs",
"[",
"ATTR_STATE_HOLIDAY_MODE",
"]",
"=",
"self",
".",
"_device",
".",
"holiday_active",
"if",
"self",
".",
"_device",
".",
"summer_active",
"is",
"not",
"None",
":",
"attrs",
"[",
"ATTR_STATE_SUMMER_MODE",
"]",
"=",
"self",
".",
"_device",
".",
"summer_active",
"if",
"ATTR_STATE_WINDOW_OPEN",
"is",
"not",
"None",
":",
"attrs",
"[",
"ATTR_STATE_WINDOW_OPEN",
"]",
"=",
"self",
".",
"_device",
".",
"window_open",
"return",
"attrs"
] | [
193,
4
] | [
211,
20
] | python | en | ['en', 'en', 'en'] | True |
FritzboxThermostat.update | (self) | Update the data from the thermostat. | Update the data from the thermostat. | def update(self):
"""Update the data from the thermostat."""
try:
self._device.update()
self._current_temperature = self._device.actual_temperature
self._target_temperature = self._device.target_temperature
self._comfort_temperature = self._device.comfort_temperature
self._eco_temperature = self._device.eco_temperature
except requests.exceptions.HTTPError as ex:
LOGGER.warning("Fritzbox connection error: %s", ex)
self._fritz.login() | [
"def",
"update",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_device",
".",
"update",
"(",
")",
"self",
".",
"_current_temperature",
"=",
"self",
".",
"_device",
".",
"actual_temperature",
"self",
".",
"_target_temperature",
"=",
"self",
".",
"_device",
".",
"target_temperature",
"self",
".",
"_comfort_temperature",
"=",
"self",
".",
"_device",
".",
"comfort_temperature",
"self",
".",
"_eco_temperature",
"=",
"self",
".",
"_device",
".",
"eco_temperature",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"ex",
":",
"LOGGER",
".",
"warning",
"(",
"\"Fritzbox connection error: %s\"",
",",
"ex",
")",
"self",
".",
"_fritz",
".",
"login",
"(",
")"
] | [
213,
4
] | [
223,
31
] | python | en | ['en', 'en', 'en'] | True |
_get_dyson_purecool_device | () | Return a valid device provide by Dyson web services. | Return a valid device provide by Dyson web services. | def _get_dyson_purecool_device():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock(spec=DysonPureCool)
load_mock_device(device)
return device | [
"def",
"_get_dyson_purecool_device",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCool",
")",
"load_mock_device",
"(",
"device",
")",
"return",
"device"
] | [
26,
0
] | [
30,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_config | () | Return a config dictionary. | Return a config dictionary. | def _get_config():
"""Return a config dictionary."""
return {
dyson_parent.DOMAIN: {
dyson_parent.CONF_USERNAME: "email",
dyson_parent.CONF_PASSWORD: "password",
dyson_parent.CONF_LANGUAGE: "GB",
dyson_parent.CONF_DEVICES: [
{"device_id": "XX-XXXXX-XX", "device_ip": "192.168.0.1"}
],
}
} | [
"def",
"_get_config",
"(",
")",
":",
"return",
"{",
"dyson_parent",
".",
"DOMAIN",
":",
"{",
"dyson_parent",
".",
"CONF_USERNAME",
":",
"\"email\"",
",",
"dyson_parent",
".",
"CONF_PASSWORD",
":",
"\"password\"",
",",
"dyson_parent",
".",
"CONF_LANGUAGE",
":",
"\"GB\"",
",",
"dyson_parent",
".",
"CONF_DEVICES",
":",
"[",
"{",
"\"device_id\"",
":",
"\"XX-XXXXX-XX\"",
",",
"\"device_ip\"",
":",
"\"192.168.0.1\"",
"}",
"]",
",",
"}",
"}"
] | [
33,
0
] | [
44,
5
] | python | en | ['en', 'pt', 'en'] | True |
_get_device_without_state | () | Return a valid device provide by Dyson web services. | Return a valid device provide by Dyson web services. | def _get_device_without_state():
"""Return a valid device provide by Dyson web services."""
device = mock.Mock(spec=DysonPureCoolLink)
device.name = "Device_name"
device.state = None
device.environmental_state = None
return device | [
"def",
"_get_device_without_state",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCoolLink",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
"=",
"None",
"device",
".",
"environmental_state",
"=",
"None",
"return",
"device"
] | [
47,
0
] | [
53,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_with_state | () | Return a valid device with state values. | Return a valid device with state values. | def _get_with_state():
"""Return a valid device with state values."""
device = mock.Mock()
load_mock_device(device)
device.name = "Device_name"
device.state.filter_life = 100
device.environmental_state.dust = 5
device.environmental_state.humidity = 45
device.environmental_state.temperature = 295
device.environmental_state.volatil_organic_compounds = 2
return device | [
"def",
"_get_with_state",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"state",
".",
"filter_life",
"=",
"100",
"device",
".",
"environmental_state",
".",
"dust",
"=",
"5",
"device",
".",
"environmental_state",
".",
"humidity",
"=",
"45",
"device",
".",
"environmental_state",
".",
"temperature",
"=",
"295",
"device",
".",
"environmental_state",
".",
"volatil_organic_compounds",
"=",
"2",
"return",
"device"
] | [
56,
0
] | [
67,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_purecool_device | () | Return a valid device with filters life state values. | Return a valid device with filters life state values. | def _get_purecool_device():
"""Return a valid device with filters life state values."""
device = mock.Mock(spec=DysonPureCool)
load_mock_device(device)
device.name = "PureCool"
device.state.carbon_filter_state = "0096"
device.state.hepa_filter_state = "0056"
device.environmental_state.dust = 5
device.environmental_state.humidity = 45
device.environmental_state.temperature = 295
device.environmental_state.volatil_organic_compounds = 2
return device | [
"def",
"_get_purecool_device",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCool",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"PureCool\"",
"device",
".",
"state",
".",
"carbon_filter_state",
"=",
"\"0096\"",
"device",
".",
"state",
".",
"hepa_filter_state",
"=",
"\"0056\"",
"device",
".",
"environmental_state",
".",
"dust",
"=",
"5",
"device",
".",
"environmental_state",
".",
"humidity",
"=",
"45",
"device",
".",
"environmental_state",
".",
"temperature",
"=",
"295",
"device",
".",
"environmental_state",
".",
"volatil_organic_compounds",
"=",
"2",
"return",
"device"
] | [
70,
0
] | [
82,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_purecool_humidify_device | () | Return a valid device with filters life state values. | Return a valid device with filters life state values. | def _get_purecool_humidify_device():
"""Return a valid device with filters life state values."""
device = mock.Mock(spec=DysonPureCool)
load_mock_device(device)
device.name = "PureCool_Humidify"
device.state.carbon_filter_state = "INV"
device.state.hepa_filter_state = "0075"
device.environmental_state.dust = 5
device.environmental_state.humidity = 45
device.environmental_state.temperature = 295
device.environmental_state.volatil_organic_compounds = 2
return device | [
"def",
"_get_purecool_humidify_device",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
"spec",
"=",
"DysonPureCool",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"PureCool_Humidify\"",
"device",
".",
"state",
".",
"carbon_filter_state",
"=",
"\"INV\"",
"device",
".",
"state",
".",
"hepa_filter_state",
"=",
"\"0075\"",
"device",
".",
"environmental_state",
".",
"dust",
"=",
"5",
"device",
".",
"environmental_state",
".",
"humidity",
"=",
"45",
"device",
".",
"environmental_state",
".",
"temperature",
"=",
"295",
"device",
".",
"environmental_state",
".",
"volatil_organic_compounds",
"=",
"2",
"return",
"device"
] | [
85,
0
] | [
97,
17
] | python | en | ['en', 'en', 'en'] | True |
_get_with_standby_monitoring | () | Return a valid device with state but with standby monitoring disable. | Return a valid device with state but with standby monitoring disable. | def _get_with_standby_monitoring():
"""Return a valid device with state but with standby monitoring disable."""
device = mock.Mock()
load_mock_device(device)
device.name = "Device_name"
device.environmental_state.humidity = 0
device.environmental_state.temperature = 0
return device | [
"def",
"_get_with_standby_monitoring",
"(",
")",
":",
"device",
"=",
"mock",
".",
"Mock",
"(",
")",
"load_mock_device",
"(",
"device",
")",
"device",
".",
"name",
"=",
"\"Device_name\"",
"device",
".",
"environmental_state",
".",
"humidity",
"=",
"0",
"device",
".",
"environmental_state",
".",
"temperature",
"=",
"0",
"return",
"device"
] | [
100,
0
] | [
108,
17
] | python | en | ['en', 'en', 'en'] | True |
test_purecool_component_setup_only_once | (devices, login, hass) | Test if entities are created only once. | Test if entities are created only once. | async def test_purecool_component_setup_only_once(devices, login, hass):
"""Test if entities are created only once."""
config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config)
await hass.async_block_till_done()
discovery.load_platform(hass, "sensor", dyson_parent.DOMAIN, {}, config)
await hass.async_block_till_done()
assert len(hass.data[dyson.DYSON_SENSOR_DEVICES]) == 4 | [
"async",
"def",
"test_purecool_component_setup_only_once",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"config",
"=",
"_get_config",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"discovery",
".",
"load_platform",
"(",
"hass",
",",
"\"sensor\"",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"{",
"}",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"len",
"(",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_SENSOR_DEVICES",
"]",
")",
"==",
"4"
] | [
300,
0
] | [
308,
58
] | python | en | ['en', 'en', 'en'] | True |
test_dyson_purecool_filter_state_sensor | (devices, login, hass) | Test filter sensor with values. | Test filter sensor with values. | async def test_dyson_purecool_filter_state_sensor(devices, login, hass):
"""Test filter sensor with values."""
config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("sensor.purecool_hepa_filter_remaining_life")
assert state is not None
assert state.state == "56"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
assert state.name == "PureCool HEPA Filter Remaining Life"
state = hass.states.get("sensor.purecool_carbon_filter_remaining_life")
assert state is not None
assert state.state == "96"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
assert state.name == "PureCool Carbon Filter Remaining Life" | [
"async",
"def",
"test_dyson_purecool_filter_state_sensor",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"config",
"=",
"_get_config",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.purecool_hepa_filter_remaining_life\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"56\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_UNIT_OF_MEASUREMENT",
"]",
"==",
"PERCENTAGE",
"assert",
"state",
".",
"name",
"==",
"\"PureCool HEPA Filter Remaining Life\"",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.purecool_carbon_filter_remaining_life\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"96\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_UNIT_OF_MEASUREMENT",
"]",
"==",
"PERCENTAGE",
"assert",
"state",
".",
"name",
"==",
"\"PureCool Carbon Filter Remaining Life\""
] | [
316,
0
] | [
332,
64
] | python | en | ['en', 'en', 'en'] | True |
test_dyson_purecool_humidify_filter_state_sensor | (devices, login, hass) | Test filter sensor with values. | Test filter sensor with values. | async def test_dyson_purecool_humidify_filter_state_sensor(devices, login, hass):
"""Test filter sensor with values."""
config = _get_config()
await async_setup_component(hass, dyson_parent.DOMAIN, config)
await hass.async_block_till_done()
state = hass.states.get("sensor.purecool_humidify_combi_filter_remaining_life")
assert state is not None
assert state.state == "75"
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE
assert state.name == "PureCool_Humidify Combi Filter Remaining Life" | [
"async",
"def",
"test_dyson_purecool_humidify_filter_state_sensor",
"(",
"devices",
",",
"login",
",",
"hass",
")",
":",
"config",
"=",
"_get_config",
"(",
")",
"await",
"async_setup_component",
"(",
"hass",
",",
"dyson_parent",
".",
"DOMAIN",
",",
"config",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"\"sensor.purecool_humidify_combi_filter_remaining_life\"",
")",
"assert",
"state",
"is",
"not",
"None",
"assert",
"state",
".",
"state",
"==",
"\"75\"",
"assert",
"state",
".",
"attributes",
"[",
"ATTR_UNIT_OF_MEASUREMENT",
"]",
"==",
"PERCENTAGE",
"assert",
"state",
".",
"name",
"==",
"\"PureCool_Humidify Combi Filter Remaining Life\""
] | [
340,
0
] | [
350,
72
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.setUp | (self) | Set up things to be run when tests are started. | Set up things to be run when tests are started. | def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.addCleanup(self.tear_down_cleanup) | [
"def",
"setUp",
"(",
"self",
")",
":",
"# pylint: disable=invalid-name",
"self",
".",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"self",
".",
"addCleanup",
"(",
"self",
".",
"tear_down_cleanup",
")"
] | [
114,
4
] | [
117,
47
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.tear_down_cleanup | (self) | Stop everything that was started. | Stop everything that was started. | def tear_down_cleanup(self):
"""Stop everything that was started."""
self.hass.stop() | [
"def",
"tear_down_cleanup",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"stop",
"(",
")"
] | [
119,
4
] | [
121,
24
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_setup_component_with_no_devices | (self) | Test setup component with no devices. | Test setup component with no devices. | def test_setup_component_with_no_devices(self):
"""Test setup component with no devices."""
self.hass.data[dyson.DYSON_DEVICES] = []
add_entities = mock.MagicMock()
dyson.setup_platform(self.hass, None, add_entities)
add_entities.assert_not_called() | [
"def",
"test_setup_component_with_no_devices",
"(",
"self",
")",
":",
"self",
".",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_DEVICES",
"]",
"=",
"[",
"]",
"add_entities",
"=",
"mock",
".",
"MagicMock",
"(",
")",
"dyson",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"None",
",",
"add_entities",
")",
"add_entities",
".",
"assert_not_called",
"(",
")"
] | [
123,
4
] | [
128,
40
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_setup_component | (self) | Test setup component with devices. | Test setup component with devices. | def test_setup_component(self):
"""Test setup component with devices."""
def _add_device(devices):
assert len(devices) == 5
assert devices[0].name == "Device_name Filter Life"
assert devices[1].name == "Device_name Dust"
assert devices[2].name == "Device_name Humidity"
assert devices[3].name == "Device_name Temperature"
assert devices[4].name == "Device_name AQI"
device_fan = _get_device_without_state()
device_non_fan = _get_with_state()
self.hass.data[dyson.DYSON_DEVICES] = [
device_fan,
device_non_fan,
]
dyson.setup_platform(self.hass, None, _add_device, mock.MagicMock()) | [
"def",
"test_setup_component",
"(",
"self",
")",
":",
"def",
"_add_device",
"(",
"devices",
")",
":",
"assert",
"len",
"(",
"devices",
")",
"==",
"5",
"assert",
"devices",
"[",
"0",
"]",
".",
"name",
"==",
"\"Device_name Filter Life\"",
"assert",
"devices",
"[",
"1",
"]",
".",
"name",
"==",
"\"Device_name Dust\"",
"assert",
"devices",
"[",
"2",
"]",
".",
"name",
"==",
"\"Device_name Humidity\"",
"assert",
"devices",
"[",
"3",
"]",
".",
"name",
"==",
"\"Device_name Temperature\"",
"assert",
"devices",
"[",
"4",
"]",
".",
"name",
"==",
"\"Device_name AQI\"",
"device_fan",
"=",
"_get_device_without_state",
"(",
")",
"device_non_fan",
"=",
"_get_with_state",
"(",
")",
"self",
".",
"hass",
".",
"data",
"[",
"dyson",
".",
"DYSON_DEVICES",
"]",
"=",
"[",
"device_fan",
",",
"device_non_fan",
",",
"]",
"dyson",
".",
"setup_platform",
"(",
"self",
".",
"hass",
",",
"None",
",",
"_add_device",
",",
"mock",
".",
"MagicMock",
"(",
")",
")"
] | [
130,
4
] | [
147,
76
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_filter_life_sensor | (self) | Test filter life sensor with no value. | Test filter life sensor with no value. | def test_dyson_filter_life_sensor(self):
"""Test filter life sensor with no value."""
sensor = dyson.DysonFilterLifeSensor(_get_device_without_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement == TIME_HOURS
assert sensor.name == "Device_name Filter Life"
assert sensor.entity_id == "sensor.dyson_1"
sensor.on_message("message") | [
"def",
"test_dyson_filter_life_sensor",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonFilterLifeSensor",
"(",
"_get_device_without_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"is",
"None",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TIME_HOURS",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Filter Life\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\"",
"sensor",
".",
"on_message",
"(",
"\"message\"",
")"
] | [
149,
4
] | [
159,
36
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_filter_life_sensor_with_values | (self) | Test filter sensor with values. | Test filter sensor with values. | def test_dyson_filter_life_sensor_with_values(self):
"""Test filter sensor with values."""
sensor = dyson.DysonFilterLifeSensor(_get_with_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 100
assert sensor.unit_of_measurement == TIME_HOURS
assert sensor.name == "Device_name Filter Life"
assert sensor.entity_id == "sensor.dyson_1"
sensor.on_message("message") | [
"def",
"test_dyson_filter_life_sensor_with_values",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonFilterLifeSensor",
"(",
"_get_with_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"100",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TIME_HOURS",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Filter Life\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\"",
"sensor",
".",
"on_message",
"(",
"\"message\"",
")"
] | [
161,
4
] | [
171,
36
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_dust_sensor | (self) | Test dust sensor with no value. | Test dust sensor with no value. | def test_dyson_dust_sensor(self):
"""Test dust sensor with no value."""
sensor = dyson.DysonDustSensor(_get_device_without_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement is None
assert sensor.name == "Device_name Dust"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_dust_sensor",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonDustSensor",
"(",
"_get_device_without_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"is",
"None",
"assert",
"sensor",
".",
"unit_of_measurement",
"is",
"None",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Dust\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
173,
4
] | [
182,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_dust_sensor_with_values | (self) | Test dust sensor with values. | Test dust sensor with values. | def test_dyson_dust_sensor_with_values(self):
"""Test dust sensor with values."""
sensor = dyson.DysonDustSensor(_get_with_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 5
assert sensor.unit_of_measurement is None
assert sensor.name == "Device_name Dust"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_dust_sensor_with_values",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonDustSensor",
"(",
"_get_with_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"5",
"assert",
"sensor",
".",
"unit_of_measurement",
"is",
"None",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Dust\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
184,
4
] | [
193,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_humidity_sensor | (self) | Test humidity sensor with no value. | Test humidity sensor with no value. | def test_dyson_humidity_sensor(self):
"""Test humidity sensor with no value."""
sensor = dyson.DysonHumiditySensor(_get_device_without_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement == PERCENTAGE
assert sensor.name == "Device_name Humidity"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_humidity_sensor",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonHumiditySensor",
"(",
"_get_device_without_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"is",
"None",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"PERCENTAGE",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Humidity\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
195,
4
] | [
204,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_humidity_sensor_with_values | (self) | Test humidity sensor with values. | Test humidity sensor with values. | def test_dyson_humidity_sensor_with_values(self):
"""Test humidity sensor with values."""
sensor = dyson.DysonHumiditySensor(_get_with_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 45
assert sensor.unit_of_measurement == PERCENTAGE
assert sensor.name == "Device_name Humidity"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_humidity_sensor_with_values",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonHumiditySensor",
"(",
"_get_with_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"45",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"PERCENTAGE",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Humidity\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
206,
4
] | [
215,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_humidity_standby_monitoring | (self) | Test humidity sensor while device is in standby monitoring. | Test humidity sensor while device is in standby monitoring. | def test_dyson_humidity_standby_monitoring(self):
"""Test humidity sensor while device is in standby monitoring."""
sensor = dyson.DysonHumiditySensor(_get_with_standby_monitoring())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == STATE_OFF
assert sensor.unit_of_measurement == PERCENTAGE
assert sensor.name == "Device_name Humidity"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_humidity_standby_monitoring",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonHumiditySensor",
"(",
"_get_with_standby_monitoring",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"STATE_OFF",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"PERCENTAGE",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Humidity\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
217,
4
] | [
226,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_temperature_sensor | (self) | Test temperature sensor with no value. | Test temperature sensor with no value. | def test_dyson_temperature_sensor(self):
"""Test temperature sensor with no value."""
sensor = dyson.DysonTemperatureSensor(_get_device_without_state(), TEMP_CELSIUS)
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_temperature_sensor",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonTemperatureSensor",
"(",
"_get_device_without_state",
"(",
")",
",",
"TEMP_CELSIUS",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"is",
"None",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TEMP_CELSIUS",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Temperature\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
228,
4
] | [
237,
51
] | python | en | ['en', 'ca', 'en'] | True |
DysonTest.test_dyson_temperature_sensor_with_values | (self) | Test temperature sensor with values. | Test temperature sensor with values. | def test_dyson_temperature_sensor_with_values(self):
"""Test temperature sensor with values."""
sensor = dyson.DysonTemperatureSensor(_get_with_state(), TEMP_CELSIUS)
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 21.9
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1"
sensor = dyson.DysonTemperatureSensor(_get_with_state(), TEMP_FAHRENHEIT)
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 71.3
assert sensor.unit_of_measurement == TEMP_FAHRENHEIT
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_temperature_sensor_with_values",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonTemperatureSensor",
"(",
"_get_with_state",
"(",
")",
",",
"TEMP_CELSIUS",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"21.9",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TEMP_CELSIUS",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Temperature\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\"",
"sensor",
"=",
"dyson",
".",
"DysonTemperatureSensor",
"(",
"_get_with_state",
"(",
")",
",",
"TEMP_FAHRENHEIT",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"71.3",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TEMP_FAHRENHEIT",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Temperature\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
239,
4
] | [
257,
51
] | python | en | ['en', 'la', 'en'] | True |
DysonTest.test_dyson_temperature_standby_monitoring | (self) | Test temperature sensor while device is in standby monitoring. | Test temperature sensor while device is in standby monitoring. | def test_dyson_temperature_standby_monitoring(self):
"""Test temperature sensor while device is in standby monitoring."""
sensor = dyson.DysonTemperatureSensor(
_get_with_standby_monitoring(), TEMP_CELSIUS
)
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == STATE_OFF
assert sensor.unit_of_measurement == TEMP_CELSIUS
assert sensor.name == "Device_name Temperature"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_temperature_standby_monitoring",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonTemperatureSensor",
"(",
"_get_with_standby_monitoring",
"(",
")",
",",
"TEMP_CELSIUS",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"STATE_OFF",
"assert",
"sensor",
".",
"unit_of_measurement",
"==",
"TEMP_CELSIUS",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name Temperature\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
259,
4
] | [
270,
51
] | python | en | ['en', 'en', 'en'] | True |
DysonTest.test_dyson_air_quality_sensor | (self) | Test air quality sensor with no value. | Test air quality sensor with no value. | def test_dyson_air_quality_sensor(self):
"""Test air quality sensor with no value."""
sensor = dyson.DysonAirQualitySensor(_get_device_without_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state is None
assert sensor.unit_of_measurement is None
assert sensor.name == "Device_name AQI"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_air_quality_sensor",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonAirQualitySensor",
"(",
"_get_device_without_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"is",
"None",
"assert",
"sensor",
".",
"unit_of_measurement",
"is",
"None",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name AQI\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
272,
4
] | [
281,
51
] | python | en | ['en', 'pt', 'en'] | True |
DysonTest.test_dyson_air_quality_sensor_with_values | (self) | Test air quality sensor with values. | Test air quality sensor with values. | def test_dyson_air_quality_sensor_with_values(self):
"""Test air quality sensor with values."""
sensor = dyson.DysonAirQualitySensor(_get_with_state())
sensor.hass = self.hass
sensor.entity_id = "sensor.dyson_1"
assert not sensor.should_poll
assert sensor.state == 2
assert sensor.unit_of_measurement is None
assert sensor.name == "Device_name AQI"
assert sensor.entity_id == "sensor.dyson_1" | [
"def",
"test_dyson_air_quality_sensor_with_values",
"(",
"self",
")",
":",
"sensor",
"=",
"dyson",
".",
"DysonAirQualitySensor",
"(",
"_get_with_state",
"(",
")",
")",
"sensor",
".",
"hass",
"=",
"self",
".",
"hass",
"sensor",
".",
"entity_id",
"=",
"\"sensor.dyson_1\"",
"assert",
"not",
"sensor",
".",
"should_poll",
"assert",
"sensor",
".",
"state",
"==",
"2",
"assert",
"sensor",
".",
"unit_of_measurement",
"is",
"None",
"assert",
"sensor",
".",
"name",
"==",
"\"Device_name AQI\"",
"assert",
"sensor",
".",
"entity_id",
"==",
"\"sensor.dyson_1\""
] | [
283,
4
] | [
292,
51
] | python | en | ['en', 'en', 'en'] | True |
patch_debounce | () | Return patch for debounce method. | Return patch for debounce method. | def patch_debounce():
"""Return patch for debounce method."""
return patch(
"homeassistant.components.homekit.accessories.debounce",
lambda f: lambda *args, **kwargs: f(*args, **kwargs),
) | [
"def",
"patch_debounce",
"(",
")",
":",
"return",
"patch",
"(",
"\"homeassistant.components.homekit.accessories.debounce\"",
",",
"lambda",
"f",
":",
"lambda",
"*",
"args",
",",
"*",
"*",
"kwargs",
":",
"f",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
",",
")"
] | [
6,
0
] | [
11,
5
] | python | en | ['en', 'nl', 'en'] | True |
mock_turbo_jpeg | (
first_width=None, second_width=None, first_height=None, second_height=None
) | Mock a TurboJPEG instance. | Mock a TurboJPEG instance. | def mock_turbo_jpeg(
first_width=None, second_width=None, first_height=None, second_height=None
):
"""Mock a TurboJPEG instance."""
mocked_turbo_jpeg = Mock()
mocked_turbo_jpeg.decode_header.side_effect = [
(first_width, first_height, 0, 0),
(second_width, second_height, 0, 0),
]
mocked_turbo_jpeg.scale_with_quality.return_value = EMPTY_8_6_JPEG
return mocked_turbo_jpeg | [
"def",
"mock_turbo_jpeg",
"(",
"first_width",
"=",
"None",
",",
"second_width",
"=",
"None",
",",
"first_height",
"=",
"None",
",",
"second_height",
"=",
"None",
")",
":",
"mocked_turbo_jpeg",
"=",
"Mock",
"(",
")",
"mocked_turbo_jpeg",
".",
"decode_header",
".",
"side_effect",
"=",
"[",
"(",
"first_width",
",",
"first_height",
",",
"0",
",",
"0",
")",
",",
"(",
"second_width",
",",
"second_height",
",",
"0",
",",
"0",
")",
",",
"]",
"mocked_turbo_jpeg",
".",
"scale_with_quality",
".",
"return_value",
"=",
"EMPTY_8_6_JPEG",
"return",
"mocked_turbo_jpeg"
] | [
14,
0
] | [
24,
28
] | python | en | ['en', 'haw', 'en'] | True |
test_intent_set_color | (hass) | Test the set color intent. | Test the set color intent. | async def test_intent_set_color(hass):
"""Test the set color intent."""
hass.states.async_set(
"light.hello_2", "off", {ATTR_SUPPORTED_FEATURES: light.SUPPORT_COLOR}
)
hass.states.async_set("switch.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
result = await hass.helpers.intent.async_handle(
"test",
intent.INTENT_SET,
{"name": {"value": "Hello"}, "color": {"value": "blue"}},
)
await hass.async_block_till_done()
assert result.speech["plain"]["speech"] == "Changed hello 2 to the color blue"
assert len(calls) == 1
call = calls[0]
assert call.domain == light.DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data.get(ATTR_ENTITY_ID) == "light.hello_2"
assert call.data.get(light.ATTR_RGB_COLOR) == (0, 0, 255) | [
"async",
"def",
"test_intent_set_color",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.hello_2\"",
",",
"\"off\"",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"light",
".",
"SUPPORT_COLOR",
"}",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"switch.hello\"",
",",
"\"off\"",
")",
"calls",
"=",
"async_mock_service",
"(",
"hass",
",",
"light",
".",
"DOMAIN",
",",
"light",
".",
"SERVICE_TURN_ON",
")",
"await",
"intent",
".",
"async_setup_intents",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"helpers",
".",
"intent",
".",
"async_handle",
"(",
"\"test\"",
",",
"intent",
".",
"INTENT_SET",
",",
"{",
"\"name\"",
":",
"{",
"\"value\"",
":",
"\"Hello\"",
"}",
",",
"\"color\"",
":",
"{",
"\"value\"",
":",
"\"blue\"",
"}",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"result",
".",
"speech",
"[",
"\"plain\"",
"]",
"[",
"\"speech\"",
"]",
"==",
"\"Changed hello 2 to the color blue\"",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"call",
"=",
"calls",
"[",
"0",
"]",
"assert",
"call",
".",
"domain",
"==",
"light",
".",
"DOMAIN",
"assert",
"call",
".",
"service",
"==",
"SERVICE_TURN_ON",
"assert",
"call",
".",
"data",
".",
"get",
"(",
"ATTR_ENTITY_ID",
")",
"==",
"\"light.hello_2\"",
"assert",
"call",
".",
"data",
".",
"get",
"(",
"light",
".",
"ATTR_RGB_COLOR",
")",
"==",
"(",
"0",
",",
"0",
",",
"255",
")"
] | [
9,
0
] | [
32,
61
] | python | en | ['en', 'fr', 'en'] | True |
test_intent_set_color_tests_feature | (hass) | Test the set color intent. | Test the set color intent. | async def test_intent_set_color_tests_feature(hass):
"""Test the set color intent."""
hass.states.async_set("light.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
try:
await hass.helpers.intent.async_handle(
"test",
intent.INTENT_SET,
{"name": {"value": "Hello"}, "color": {"value": "blue"}},
)
assert False, "handling intent should have raised"
except IntentHandleError as err:
assert str(err) == "Entity hello does not support changing colors"
assert len(calls) == 0 | [
"async",
"def",
"test_intent_set_color_tests_feature",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.hello\"",
",",
"\"off\"",
")",
"calls",
"=",
"async_mock_service",
"(",
"hass",
",",
"light",
".",
"DOMAIN",
",",
"light",
".",
"SERVICE_TURN_ON",
")",
"await",
"intent",
".",
"async_setup_intents",
"(",
"hass",
")",
"try",
":",
"await",
"hass",
".",
"helpers",
".",
"intent",
".",
"async_handle",
"(",
"\"test\"",
",",
"intent",
".",
"INTENT_SET",
",",
"{",
"\"name\"",
":",
"{",
"\"value\"",
":",
"\"Hello\"",
"}",
",",
"\"color\"",
":",
"{",
"\"value\"",
":",
"\"blue\"",
"}",
"}",
",",
")",
"assert",
"False",
",",
"\"handling intent should have raised\"",
"except",
"IntentHandleError",
"as",
"err",
":",
"assert",
"str",
"(",
"err",
")",
"==",
"\"Entity hello does not support changing colors\"",
"assert",
"len",
"(",
"calls",
")",
"==",
"0"
] | [
35,
0
] | [
51,
26
] | python | en | ['en', 'fr', 'en'] | True |
test_intent_set_color_and_brightness | (hass) | Test the set color intent. | Test the set color intent. | async def test_intent_set_color_and_brightness(hass):
"""Test the set color intent."""
hass.states.async_set(
"light.hello_2",
"off",
{ATTR_SUPPORTED_FEATURES: (light.SUPPORT_COLOR | light.SUPPORT_BRIGHTNESS)},
)
hass.states.async_set("switch.hello", "off")
calls = async_mock_service(hass, light.DOMAIN, light.SERVICE_TURN_ON)
await intent.async_setup_intents(hass)
result = await hass.helpers.intent.async_handle(
"test",
intent.INTENT_SET,
{
"name": {"value": "Hello"},
"color": {"value": "blue"},
"brightness": {"value": "20"},
},
)
await hass.async_block_till_done()
assert (
result.speech["plain"]["speech"]
== "Changed hello 2 to the color blue and 20% brightness"
)
assert len(calls) == 1
call = calls[0]
assert call.domain == light.DOMAIN
assert call.service == SERVICE_TURN_ON
assert call.data.get(ATTR_ENTITY_ID) == "light.hello_2"
assert call.data.get(light.ATTR_RGB_COLOR) == (0, 0, 255)
assert call.data.get(light.ATTR_BRIGHTNESS_PCT) == 20 | [
"async",
"def",
"test_intent_set_color_and_brightness",
"(",
"hass",
")",
":",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"light.hello_2\"",
",",
"\"off\"",
",",
"{",
"ATTR_SUPPORTED_FEATURES",
":",
"(",
"light",
".",
"SUPPORT_COLOR",
"|",
"light",
".",
"SUPPORT_BRIGHTNESS",
")",
"}",
",",
")",
"hass",
".",
"states",
".",
"async_set",
"(",
"\"switch.hello\"",
",",
"\"off\"",
")",
"calls",
"=",
"async_mock_service",
"(",
"hass",
",",
"light",
".",
"DOMAIN",
",",
"light",
".",
"SERVICE_TURN_ON",
")",
"await",
"intent",
".",
"async_setup_intents",
"(",
"hass",
")",
"result",
"=",
"await",
"hass",
".",
"helpers",
".",
"intent",
".",
"async_handle",
"(",
"\"test\"",
",",
"intent",
".",
"INTENT_SET",
",",
"{",
"\"name\"",
":",
"{",
"\"value\"",
":",
"\"Hello\"",
"}",
",",
"\"color\"",
":",
"{",
"\"value\"",
":",
"\"blue\"",
"}",
",",
"\"brightness\"",
":",
"{",
"\"value\"",
":",
"\"20\"",
"}",
",",
"}",
",",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"(",
"result",
".",
"speech",
"[",
"\"plain\"",
"]",
"[",
"\"speech\"",
"]",
"==",
"\"Changed hello 2 to the color blue and 20% brightness\"",
")",
"assert",
"len",
"(",
"calls",
")",
"==",
"1",
"call",
"=",
"calls",
"[",
"0",
"]",
"assert",
"call",
".",
"domain",
"==",
"light",
".",
"DOMAIN",
"assert",
"call",
".",
"service",
"==",
"SERVICE_TURN_ON",
"assert",
"call",
".",
"data",
".",
"get",
"(",
"ATTR_ENTITY_ID",
")",
"==",
"\"light.hello_2\"",
"assert",
"call",
".",
"data",
".",
"get",
"(",
"light",
".",
"ATTR_RGB_COLOR",
")",
"==",
"(",
"0",
",",
"0",
",",
"255",
")",
"assert",
"call",
".",
"data",
".",
"get",
"(",
"light",
".",
"ATTR_BRIGHTNESS_PCT",
")",
"==",
"20"
] | [
54,
0
] | [
87,
57
] | python | en | ['en', 'fr', 'en'] | True |
async_setup_entry | (hass, entry, async_add_entities) | Set up Velbus light based on config_entry. | Set up Velbus light based on config_entry. | async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Velbus light based on config_entry."""
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
modules_data = hass.data[DOMAIN][entry.entry_id]["light"]
entities = []
for address, channel in modules_data:
module = cntrl.get_module(address)
entities.append(VelbusLight(module, channel))
async_add_entities(entities) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"entry",
",",
"async_add_entities",
")",
":",
"cntrl",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"cntrl\"",
"]",
"modules_data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"entry",
".",
"entry_id",
"]",
"[",
"\"light\"",
"]",
"entities",
"=",
"[",
"]",
"for",
"address",
",",
"channel",
"in",
"modules_data",
":",
"module",
"=",
"cntrl",
".",
"get_module",
"(",
"address",
")",
"entities",
".",
"append",
"(",
"VelbusLight",
"(",
"module",
",",
"channel",
")",
")",
"async_add_entities",
"(",
"entities",
")"
] | [
23,
0
] | [
31,
32
] | python | en | ['en', 'en', 'en'] | True |
VelbusLight.name | (self) | Return the display name of this entity. | Return the display name of this entity. | def name(self):
"""Return the display name of this entity."""
if self._module.light_is_buttonled(self._channel):
return f"LED {self._module.get_name(self._channel)}"
return self._module.get_name(self._channel) | [
"def",
"name",
"(",
"self",
")",
":",
"if",
"self",
".",
"_module",
".",
"light_is_buttonled",
"(",
"self",
".",
"_channel",
")",
":",
"return",
"f\"LED {self._module.get_name(self._channel)}\"",
"return",
"self",
".",
"_module",
".",
"get_name",
"(",
"self",
".",
"_channel",
")"
] | [
38,
4
] | [
42,
51
] | python | en | ['en', 'en', 'en'] | True |
VelbusLight.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
if self._module.light_is_buttonled(self._channel):
return SUPPORT_FLASH
return SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION | [
"def",
"supported_features",
"(",
"self",
")",
":",
"if",
"self",
".",
"_module",
".",
"light_is_buttonled",
"(",
"self",
".",
"_channel",
")",
":",
"return",
"SUPPORT_FLASH",
"return",
"SUPPORT_BRIGHTNESS",
"|",
"SUPPORT_TRANSITION"
] | [
45,
4
] | [
49,
54
] | python | en | ['da', 'en', 'en'] | True |
VelbusLight.entity_registry_enabled_default | (self) | Disable Button LEDs by default. | Disable Button LEDs by default. | def entity_registry_enabled_default(self):
"""Disable Button LEDs by default."""
if self._module.light_is_buttonled(self._channel):
return False
return True | [
"def",
"entity_registry_enabled_default",
"(",
"self",
")",
":",
"if",
"self",
".",
"_module",
".",
"light_is_buttonled",
"(",
"self",
".",
"_channel",
")",
":",
"return",
"False",
"return",
"True"
] | [
52,
4
] | [
56,
19
] | python | en | ['en', 'fr', 'en'] | True |
VelbusLight.is_on | (self) | Return true if the light is on. | Return true if the light is on. | def is_on(self):
"""Return true if the light is on."""
return self._module.is_on(self._channel) | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_module",
".",
"is_on",
"(",
"self",
".",
"_channel",
")"
] | [
59,
4
] | [
61,
48
] | python | en | ['en', 'en', 'en'] | True |
VelbusLight.brightness | (self) | Return the brightness of the light. | Return the brightness of the light. | def brightness(self):
"""Return the brightness of the light."""
return int((self._module.get_dimmer_state(self._channel) * 255) / 100) | [
"def",
"brightness",
"(",
"self",
")",
":",
"return",
"int",
"(",
"(",
"self",
".",
"_module",
".",
"get_dimmer_state",
"(",
"self",
".",
"_channel",
")",
"*",
"255",
")",
"/",
"100",
")"
] | [
64,
4
] | [
66,
78
] | python | en | ['en', 'no', 'en'] | True |
VelbusLight.turn_on | (self, **kwargs) | Instruct the Velbus light to turn on. | Instruct the Velbus light to turn on. | def turn_on(self, **kwargs):
"""Instruct the Velbus light to turn on."""
if self._module.light_is_buttonled(self._channel):
if ATTR_FLASH in kwargs:
if kwargs[ATTR_FLASH] == FLASH_LONG:
attr, *args = "set_led_state", self._channel, "slow"
elif kwargs[ATTR_FLASH] == FLASH_SHORT:
attr, *args = "set_led_state", self._channel, "fast"
else:
attr, *args = "set_led_state", self._channel, "on"
else:
attr, *args = "set_led_state", self._channel, "on"
else:
if ATTR_BRIGHTNESS in kwargs:
# Make sure a low but non-zero value is not rounded down to zero
if kwargs[ATTR_BRIGHTNESS] == 0:
brightness = 0
else:
brightness = max(int((kwargs[ATTR_BRIGHTNESS] * 100) / 255), 1)
attr, *args = (
"set_dimmer_state",
self._channel,
brightness,
kwargs.get(ATTR_TRANSITION, 0),
)
else:
attr, *args = (
"restore_dimmer_state",
self._channel,
kwargs.get(ATTR_TRANSITION, 0),
)
try:
getattr(self._module, attr)(*args)
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_module",
".",
"light_is_buttonled",
"(",
"self",
".",
"_channel",
")",
":",
"if",
"ATTR_FLASH",
"in",
"kwargs",
":",
"if",
"kwargs",
"[",
"ATTR_FLASH",
"]",
"==",
"FLASH_LONG",
":",
"attr",
",",
"",
"*",
"args",
"=",
"\"set_led_state\"",
",",
"self",
".",
"_channel",
",",
"\"slow\"",
"elif",
"kwargs",
"[",
"ATTR_FLASH",
"]",
"==",
"FLASH_SHORT",
":",
"attr",
",",
"",
"*",
"args",
"=",
"\"set_led_state\"",
",",
"self",
".",
"_channel",
",",
"\"fast\"",
"else",
":",
"attr",
",",
"",
"*",
"args",
"=",
"\"set_led_state\"",
",",
"self",
".",
"_channel",
",",
"\"on\"",
"else",
":",
"attr",
",",
"",
"*",
"args",
"=",
"\"set_led_state\"",
",",
"self",
".",
"_channel",
",",
"\"on\"",
"else",
":",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"# Make sure a low but non-zero value is not rounded down to zero",
"if",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
"==",
"0",
":",
"brightness",
"=",
"0",
"else",
":",
"brightness",
"=",
"max",
"(",
"int",
"(",
"(",
"kwargs",
"[",
"ATTR_BRIGHTNESS",
"]",
"*",
"100",
")",
"/",
"255",
")",
",",
"1",
")",
"attr",
",",
"",
"*",
"args",
"=",
"(",
"\"set_dimmer_state\"",
",",
"self",
".",
"_channel",
",",
"brightness",
",",
"kwargs",
".",
"get",
"(",
"ATTR_TRANSITION",
",",
"0",
")",
",",
")",
"else",
":",
"attr",
",",
"",
"*",
"args",
"=",
"(",
"\"restore_dimmer_state\"",
",",
"self",
".",
"_channel",
",",
"kwargs",
".",
"get",
"(",
"ATTR_TRANSITION",
",",
"0",
")",
",",
")",
"try",
":",
"getattr",
"(",
"self",
".",
"_module",
",",
"attr",
")",
"(",
"*",
"args",
")",
"except",
"VelbusException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"A Velbus error occurred: %s\"",
",",
"err",
")"
] | [
68,
4
] | [
102,
61
] | python | en | ['en', 'en', 'en'] | True |
VelbusLight.turn_off | (self, **kwargs) | Instruct the velbus light to turn off. | Instruct the velbus light to turn off. | def turn_off(self, **kwargs):
"""Instruct the velbus light to turn off."""
if self._module.light_is_buttonled(self._channel):
attr, *args = "set_led_state", self._channel, "off"
else:
attr, *args = (
"set_dimmer_state",
self._channel,
0,
kwargs.get(ATTR_TRANSITION, 0),
)
try:
getattr(self._module, attr)(*args)
except VelbusException as err:
_LOGGER.error("A Velbus error occurred: %s", err) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_module",
".",
"light_is_buttonled",
"(",
"self",
".",
"_channel",
")",
":",
"attr",
",",
"",
"*",
"args",
"=",
"\"set_led_state\"",
",",
"self",
".",
"_channel",
",",
"\"off\"",
"else",
":",
"attr",
",",
"",
"*",
"args",
"=",
"(",
"\"set_dimmer_state\"",
",",
"self",
".",
"_channel",
",",
"0",
",",
"kwargs",
".",
"get",
"(",
"ATTR_TRANSITION",
",",
"0",
")",
",",
")",
"try",
":",
"getattr",
"(",
"self",
".",
"_module",
",",
"attr",
")",
"(",
"*",
"args",
")",
"except",
"VelbusException",
"as",
"err",
":",
"_LOGGER",
".",
"error",
"(",
"\"A Velbus error occurred: %s\"",
",",
"err",
")"
] | [
104,
4
] | [
118,
61
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Twitch platform. | Set up the Twitch platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Twitch platform."""
channels = config[CONF_CHANNELS]
client_id = config[CONF_CLIENT_ID]
oauth_token = config.get(CONF_TOKEN)
client = TwitchClient(client_id, oauth_token)
try:
client.ingests.get_server_list()
except HTTPError:
_LOGGER.error("Client ID or OAuth token is not valid")
return
channel_ids = client.users.translate_usernames_to_ids(channels)
add_entities([TwitchSensor(channel_id, client) for channel_id in channel_ids], True) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"channels",
"=",
"config",
"[",
"CONF_CHANNELS",
"]",
"client_id",
"=",
"config",
"[",
"CONF_CLIENT_ID",
"]",
"oauth_token",
"=",
"config",
".",
"get",
"(",
"CONF_TOKEN",
")",
"client",
"=",
"TwitchClient",
"(",
"client_id",
",",
"oauth_token",
")",
"try",
":",
"client",
".",
"ingests",
".",
"get_server_list",
"(",
")",
"except",
"HTTPError",
":",
"_LOGGER",
".",
"error",
"(",
"\"Client ID or OAuth token is not valid\"",
")",
"return",
"channel_ids",
"=",
"client",
".",
"users",
".",
"translate_usernames_to_ids",
"(",
"channels",
")",
"add_entities",
"(",
"[",
"TwitchSensor",
"(",
"channel_id",
",",
"client",
")",
"for",
"channel_id",
"in",
"channel_ids",
"]",
",",
"True",
")"
] | [
40,
0
] | [
55,
88
] | python | en | ['en', 'lv', 'en'] | True |
TwitchSensor.__init__ | (self, channel, client) | Initialize the sensor. | Initialize the sensor. | def __init__(self, channel, client):
"""Initialize the sensor."""
self._client = client
self._channel = channel
self._oauth_enabled = client._oauth_token is not None
self._state = None
self._preview = None
self._game = None
self._title = None
self._subscription = None
self._follow = None
self._statistics = None | [
"def",
"__init__",
"(",
"self",
",",
"channel",
",",
"client",
")",
":",
"self",
".",
"_client",
"=",
"client",
"self",
".",
"_channel",
"=",
"channel",
"self",
".",
"_oauth_enabled",
"=",
"client",
".",
"_oauth_token",
"is",
"not",
"None",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_preview",
"=",
"None",
"self",
".",
"_game",
"=",
"None",
"self",
".",
"_title",
"=",
"None",
"self",
".",
"_subscription",
"=",
"None",
"self",
".",
"_follow",
"=",
"None",
"self",
".",
"_statistics",
"=",
"None"
] | [
61,
4
] | [
72,
31
] | python | en | ['en', 'en', 'en'] | True |
TwitchSensor.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._channel.display_name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_channel",
".",
"display_name"
] | [
75,
4
] | [
77,
41
] | python | en | ['en', 'mi', 'en'] | True |
TwitchSensor.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"
] | [
80,
4
] | [
82,
26
] | python | en | ['en', 'en', 'en'] | True |
TwitchSensor.entity_picture | (self) | Return preview of current game. | Return preview of current game. | def entity_picture(self):
"""Return preview of current game."""
return self._preview | [
"def",
"entity_picture",
"(",
"self",
")",
":",
"return",
"self",
".",
"_preview"
] | [
85,
4
] | [
87,
28
] | python | en | ['en', 'en', 'en'] | True |
TwitchSensor.device_state_attributes | (self) | Return the state attributes. | Return the state attributes. | def device_state_attributes(self):
"""Return the state attributes."""
attr = dict(self._statistics)
if self._oauth_enabled:
attr.update(self._subscription)
attr.update(self._follow)
if self._state == STATE_STREAMING:
attr.update({ATTR_GAME: self._game, ATTR_TITLE: self._title})
return attr | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"attr",
"=",
"dict",
"(",
"self",
".",
"_statistics",
")",
"if",
"self",
".",
"_oauth_enabled",
":",
"attr",
".",
"update",
"(",
"self",
".",
"_subscription",
")",
"attr",
".",
"update",
"(",
"self",
".",
"_follow",
")",
"if",
"self",
".",
"_state",
"==",
"STATE_STREAMING",
":",
"attr",
".",
"update",
"(",
"{",
"ATTR_GAME",
":",
"self",
".",
"_game",
",",
"ATTR_TITLE",
":",
"self",
".",
"_title",
"}",
")",
"return",
"attr"
] | [
90,
4
] | [
100,
19
] | python | en | ['en', 'en', 'en'] | True |
TwitchSensor.unique_id | (self) | Return unique ID for this sensor. | Return unique ID for this sensor. | def unique_id(self):
"""Return unique ID for this sensor."""
return self._channel.id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_channel",
".",
"id"
] | [
103,
4
] | [
105,
31
] | python | en | ['en', 'la', 'en'] | True |
TwitchSensor.icon | (self) | Icon to use in the frontend, if any. | Icon to use in the frontend, if any. | def icon(self):
"""Icon to use in the frontend, if any."""
return ICON | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"ICON"
] | [
108,
4
] | [
110,
19
] | python | en | ['en', 'en', 'en'] | True |
TwitchSensor.update | (self) | Update device state. | Update device state. | def update(self):
"""Update device state."""
channel = self._client.channels.get_by_id(self._channel.id)
self._statistics = {
ATTR_FOLLOWING: channel.followers,
ATTR_VIEWS: channel.views,
}
if self._oauth_enabled:
user = self._client.users.get()
try:
sub = self._client.users.check_subscribed_to_channel(
user.id, self._channel.id
)
self._subscription = {
ATTR_SUBSCRIPTION: True,
ATTR_SUBSCRIPTION_SINCE: sub.created_at,
ATTR_SUBSCRIPTION_GIFTED: sub.is_gift,
}
except HTTPError:
self._subscription = {ATTR_SUBSCRIPTION: False}
try:
follow = self._client.users.check_follows_channel(
user.id, self._channel.id
)
self._follow = {ATTR_FOLLOW: True, ATTR_FOLLOW_SINCE: follow.created_at}
except HTTPError:
self._follow = {ATTR_FOLLOW: False}
stream = self._client.streams.get_stream_by_user(self._channel.id)
if stream:
self._game = stream.channel.get("game")
self._title = stream.channel.get("status")
self._preview = stream.preview.get("medium")
self._state = STATE_STREAMING
else:
self._preview = self._channel.logo
self._state = STATE_OFFLINE | [
"def",
"update",
"(",
"self",
")",
":",
"channel",
"=",
"self",
".",
"_client",
".",
"channels",
".",
"get_by_id",
"(",
"self",
".",
"_channel",
".",
"id",
")",
"self",
".",
"_statistics",
"=",
"{",
"ATTR_FOLLOWING",
":",
"channel",
".",
"followers",
",",
"ATTR_VIEWS",
":",
"channel",
".",
"views",
",",
"}",
"if",
"self",
".",
"_oauth_enabled",
":",
"user",
"=",
"self",
".",
"_client",
".",
"users",
".",
"get",
"(",
")",
"try",
":",
"sub",
"=",
"self",
".",
"_client",
".",
"users",
".",
"check_subscribed_to_channel",
"(",
"user",
".",
"id",
",",
"self",
".",
"_channel",
".",
"id",
")",
"self",
".",
"_subscription",
"=",
"{",
"ATTR_SUBSCRIPTION",
":",
"True",
",",
"ATTR_SUBSCRIPTION_SINCE",
":",
"sub",
".",
"created_at",
",",
"ATTR_SUBSCRIPTION_GIFTED",
":",
"sub",
".",
"is_gift",
",",
"}",
"except",
"HTTPError",
":",
"self",
".",
"_subscription",
"=",
"{",
"ATTR_SUBSCRIPTION",
":",
"False",
"}",
"try",
":",
"follow",
"=",
"self",
".",
"_client",
".",
"users",
".",
"check_follows_channel",
"(",
"user",
".",
"id",
",",
"self",
".",
"_channel",
".",
"id",
")",
"self",
".",
"_follow",
"=",
"{",
"ATTR_FOLLOW",
":",
"True",
",",
"ATTR_FOLLOW_SINCE",
":",
"follow",
".",
"created_at",
"}",
"except",
"HTTPError",
":",
"self",
".",
"_follow",
"=",
"{",
"ATTR_FOLLOW",
":",
"False",
"}",
"stream",
"=",
"self",
".",
"_client",
".",
"streams",
".",
"get_stream_by_user",
"(",
"self",
".",
"_channel",
".",
"id",
")",
"if",
"stream",
":",
"self",
".",
"_game",
"=",
"stream",
".",
"channel",
".",
"get",
"(",
"\"game\"",
")",
"self",
".",
"_title",
"=",
"stream",
".",
"channel",
".",
"get",
"(",
"\"status\"",
")",
"self",
".",
"_preview",
"=",
"stream",
".",
"preview",
".",
"get",
"(",
"\"medium\"",
")",
"self",
".",
"_state",
"=",
"STATE_STREAMING",
"else",
":",
"self",
".",
"_preview",
"=",
"self",
".",
"_channel",
".",
"logo",
"self",
".",
"_state",
"=",
"STATE_OFFLINE"
] | [
112,
4
] | [
152,
39
] | python | en | ['fr', 'en', 'en'] | True |
valid_integration_path | (integration_path) | Test if it's a valid integration. | Test if it's a valid integration. | def valid_integration_path(integration_path):
"""Test if it's a valid integration."""
path = pathlib.Path(integration_path)
if not path.is_dir():
raise argparse.ArgumentTypeError(f"{integration_path} is not a directory.")
return path | [
"def",
"valid_integration_path",
"(",
"integration_path",
")",
":",
"path",
"=",
"pathlib",
".",
"Path",
"(",
"integration_path",
")",
"if",
"not",
"path",
".",
"is_dir",
"(",
")",
":",
"raise",
"argparse",
".",
"ArgumentTypeError",
"(",
"f\"{integration_path} is not a directory.\"",
")",
"return",
"path"
] | [
39,
0
] | [
45,
15
] | python | en | ['en', 'en', 'en'] | True |
get_config | () | Return config. | Return config. | def get_config() -> Config:
"""Return config."""
parser = argparse.ArgumentParser(description="Hassfest")
parser.add_argument(
"--action", type=str, choices=["validate", "generate"], default=None
)
parser.add_argument(
"--integration-path",
action="append",
type=valid_integration_path,
help="Validate a single integration",
)
parser.add_argument(
"--requirements",
action="store_true",
help="Validate requirements",
)
parsed = parser.parse_args()
if parsed.action is None:
parsed.action = "validate" if parsed.integration_path else "generate"
if parsed.action == "generate" and parsed.integration_path:
raise RuntimeError(
"Generate is not allowed when limiting to specific integrations"
)
if (
not parsed.integration_path
and not pathlib.Path("requirements_all.txt").is_file()
):
raise RuntimeError("Run from Home Assistant root")
return Config(
root=pathlib.Path(".").absolute(),
specific_integrations=parsed.integration_path,
action=parsed.action,
requirements=parsed.requirements,
) | [
"def",
"get_config",
"(",
")",
"->",
"Config",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Hassfest\"",
")",
"parser",
".",
"add_argument",
"(",
"\"--action\"",
",",
"type",
"=",
"str",
",",
"choices",
"=",
"[",
"\"validate\"",
",",
"\"generate\"",
"]",
",",
"default",
"=",
"None",
")",
"parser",
".",
"add_argument",
"(",
"\"--integration-path\"",
",",
"action",
"=",
"\"append\"",
",",
"type",
"=",
"valid_integration_path",
",",
"help",
"=",
"\"Validate a single integration\"",
",",
")",
"parser",
".",
"add_argument",
"(",
"\"--requirements\"",
",",
"action",
"=",
"\"store_true\"",
",",
"help",
"=",
"\"Validate requirements\"",
",",
")",
"parsed",
"=",
"parser",
".",
"parse_args",
"(",
")",
"if",
"parsed",
".",
"action",
"is",
"None",
":",
"parsed",
".",
"action",
"=",
"\"validate\"",
"if",
"parsed",
".",
"integration_path",
"else",
"\"generate\"",
"if",
"parsed",
".",
"action",
"==",
"\"generate\"",
"and",
"parsed",
".",
"integration_path",
":",
"raise",
"RuntimeError",
"(",
"\"Generate is not allowed when limiting to specific integrations\"",
")",
"if",
"(",
"not",
"parsed",
".",
"integration_path",
"and",
"not",
"pathlib",
".",
"Path",
"(",
"\"requirements_all.txt\"",
")",
".",
"is_file",
"(",
")",
")",
":",
"raise",
"RuntimeError",
"(",
"\"Run from Home Assistant root\"",
")",
"return",
"Config",
"(",
"root",
"=",
"pathlib",
".",
"Path",
"(",
"\".\"",
")",
".",
"absolute",
"(",
")",
",",
"specific_integrations",
"=",
"parsed",
".",
"integration_path",
",",
"action",
"=",
"parsed",
".",
"action",
",",
"requirements",
"=",
"parsed",
".",
"requirements",
",",
")"
] | [
48,
0
] | [
86,
5
] | python | en | ['en', 'la', 'en'] | False |
main | () | Validate manifests. | Validate manifests. | def main():
"""Validate manifests."""
try:
config = get_config()
except RuntimeError as err:
print(err)
return 1
plugins = [*INTEGRATION_PLUGINS]
if config.requirements:
plugins.append(requirements)
if config.specific_integrations:
integrations = {}
for int_path in config.specific_integrations:
integration = Integration(int_path)
integration.load_manifest()
integrations[integration.domain] = integration
else:
integrations = Integration.load_dir(pathlib.Path("homeassistant/components"))
plugins += HASS_PLUGINS
for plugin in plugins:
try:
start = monotonic()
print(f"Validating {plugin.__name__.split('.')[-1]}...", end="", flush=True)
if plugin is requirements and not config.specific_integrations:
print()
plugin.validate(integrations, config)
print(" done in {:.2f}s".format(monotonic() - start))
except RuntimeError as err:
print()
print()
print("Error!")
print(err)
return 1
# When we generate, all errors that are fixable will be ignored,
# as generating them will be fixed.
if config.action == "generate":
general_errors = [err for err in config.errors if not err.fixable]
invalid_itg = [
itg
for itg in integrations.values()
if any(not error.fixable for error in itg.errors)
]
else:
# action == validate
general_errors = config.errors
invalid_itg = [itg for itg in integrations.values() if itg.errors]
warnings_itg = [itg for itg in integrations.values() if itg.warnings]
print()
print("Integrations:", len(integrations))
print("Invalid integrations:", len(invalid_itg))
print()
if not invalid_itg and not general_errors:
print_integrations_status(config, warnings_itg, show_fixable_errors=False)
if config.action == "generate":
for plugin in plugins:
if hasattr(plugin, "generate"):
plugin.generate(integrations, config)
return 0
if config.action == "generate":
print("Found errors. Generating files canceled.")
print()
if general_errors:
print("General errors:")
for error in general_errors:
print("*", error)
print()
invalid_itg.extend(itg for itg in warnings_itg if itg not in invalid_itg)
print_integrations_status(config, invalid_itg, show_fixable_errors=False)
return 1 | [
"def",
"main",
"(",
")",
":",
"try",
":",
"config",
"=",
"get_config",
"(",
")",
"except",
"RuntimeError",
"as",
"err",
":",
"print",
"(",
"err",
")",
"return",
"1",
"plugins",
"=",
"[",
"*",
"INTEGRATION_PLUGINS",
"]",
"if",
"config",
".",
"requirements",
":",
"plugins",
".",
"append",
"(",
"requirements",
")",
"if",
"config",
".",
"specific_integrations",
":",
"integrations",
"=",
"{",
"}",
"for",
"int_path",
"in",
"config",
".",
"specific_integrations",
":",
"integration",
"=",
"Integration",
"(",
"int_path",
")",
"integration",
".",
"load_manifest",
"(",
")",
"integrations",
"[",
"integration",
".",
"domain",
"]",
"=",
"integration",
"else",
":",
"integrations",
"=",
"Integration",
".",
"load_dir",
"(",
"pathlib",
".",
"Path",
"(",
"\"homeassistant/components\"",
")",
")",
"plugins",
"+=",
"HASS_PLUGINS",
"for",
"plugin",
"in",
"plugins",
":",
"try",
":",
"start",
"=",
"monotonic",
"(",
")",
"print",
"(",
"f\"Validating {plugin.__name__.split('.')[-1]}...\"",
",",
"end",
"=",
"\"\"",
",",
"flush",
"=",
"True",
")",
"if",
"plugin",
"is",
"requirements",
"and",
"not",
"config",
".",
"specific_integrations",
":",
"print",
"(",
")",
"plugin",
".",
"validate",
"(",
"integrations",
",",
"config",
")",
"print",
"(",
"\" done in {:.2f}s\"",
".",
"format",
"(",
"monotonic",
"(",
")",
"-",
"start",
")",
")",
"except",
"RuntimeError",
"as",
"err",
":",
"print",
"(",
")",
"print",
"(",
")",
"print",
"(",
"\"Error!\"",
")",
"print",
"(",
"err",
")",
"return",
"1",
"# When we generate, all errors that are fixable will be ignored,",
"# as generating them will be fixed.",
"if",
"config",
".",
"action",
"==",
"\"generate\"",
":",
"general_errors",
"=",
"[",
"err",
"for",
"err",
"in",
"config",
".",
"errors",
"if",
"not",
"err",
".",
"fixable",
"]",
"invalid_itg",
"=",
"[",
"itg",
"for",
"itg",
"in",
"integrations",
".",
"values",
"(",
")",
"if",
"any",
"(",
"not",
"error",
".",
"fixable",
"for",
"error",
"in",
"itg",
".",
"errors",
")",
"]",
"else",
":",
"# action == validate",
"general_errors",
"=",
"config",
".",
"errors",
"invalid_itg",
"=",
"[",
"itg",
"for",
"itg",
"in",
"integrations",
".",
"values",
"(",
")",
"if",
"itg",
".",
"errors",
"]",
"warnings_itg",
"=",
"[",
"itg",
"for",
"itg",
"in",
"integrations",
".",
"values",
"(",
")",
"if",
"itg",
".",
"warnings",
"]",
"print",
"(",
")",
"print",
"(",
"\"Integrations:\"",
",",
"len",
"(",
"integrations",
")",
")",
"print",
"(",
"\"Invalid integrations:\"",
",",
"len",
"(",
"invalid_itg",
")",
")",
"print",
"(",
")",
"if",
"not",
"invalid_itg",
"and",
"not",
"general_errors",
":",
"print_integrations_status",
"(",
"config",
",",
"warnings_itg",
",",
"show_fixable_errors",
"=",
"False",
")",
"if",
"config",
".",
"action",
"==",
"\"generate\"",
":",
"for",
"plugin",
"in",
"plugins",
":",
"if",
"hasattr",
"(",
"plugin",
",",
"\"generate\"",
")",
":",
"plugin",
".",
"generate",
"(",
"integrations",
",",
"config",
")",
"return",
"0",
"if",
"config",
".",
"action",
"==",
"\"generate\"",
":",
"print",
"(",
"\"Found errors. Generating files canceled.\"",
")",
"print",
"(",
")",
"if",
"general_errors",
":",
"print",
"(",
"\"General errors:\"",
")",
"for",
"error",
"in",
"general_errors",
":",
"print",
"(",
"\"*\"",
",",
"error",
")",
"print",
"(",
")",
"invalid_itg",
".",
"extend",
"(",
"itg",
"for",
"itg",
"in",
"warnings_itg",
"if",
"itg",
"not",
"in",
"invalid_itg",
")",
"print_integrations_status",
"(",
"config",
",",
"invalid_itg",
",",
"show_fixable_errors",
"=",
"False",
")",
"return",
"1"
] | [
89,
0
] | [
173,
12
] | python | bg | ['en', 'et', 'bg'] | False |
print_integrations_status | (config, integrations, *, show_fixable_errors=True) | Print integration status. | Print integration status. | def print_integrations_status(config, integrations, *, show_fixable_errors=True):
"""Print integration status."""
for integration in sorted(integrations, key=lambda itg: itg.domain):
extra = f" - {integration.path}" if config.specific_integrations else ""
print(f"Integration {integration.domain}{extra}:")
for error in integration.errors:
if show_fixable_errors or not error.fixable:
print("*", error)
for warning in integration.warnings:
print("*", "[WARNING]", warning)
print() | [
"def",
"print_integrations_status",
"(",
"config",
",",
"integrations",
",",
"*",
",",
"show_fixable_errors",
"=",
"True",
")",
":",
"for",
"integration",
"in",
"sorted",
"(",
"integrations",
",",
"key",
"=",
"lambda",
"itg",
":",
"itg",
".",
"domain",
")",
":",
"extra",
"=",
"f\" - {integration.path}\"",
"if",
"config",
".",
"specific_integrations",
"else",
"\"\"",
"print",
"(",
"f\"Integration {integration.domain}{extra}:\"",
")",
"for",
"error",
"in",
"integration",
".",
"errors",
":",
"if",
"show_fixable_errors",
"or",
"not",
"error",
".",
"fixable",
":",
"print",
"(",
"\"*\"",
",",
"error",
")",
"for",
"warning",
"in",
"integration",
".",
"warnings",
":",
"print",
"(",
"\"*\"",
",",
"\"[WARNING]\"",
",",
"warning",
")",
"print",
"(",
")"
] | [
176,
0
] | [
186,
15
] | python | en | ['en', 'ja', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the trend sensors. | Set up the trend sensors. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the trend sensors."""
setup_reload_service(hass, DOMAIN, PLATFORMS)
sensors = []
for device_id, device_config in config[CONF_SENSORS].items():
entity_id = device_config[ATTR_ENTITY_ID]
attribute = device_config.get(CONF_ATTRIBUTE)
device_class = device_config.get(CONF_DEVICE_CLASS)
friendly_name = device_config.get(ATTR_FRIENDLY_NAME, device_id)
invert = device_config[CONF_INVERT]
max_samples = device_config[CONF_MAX_SAMPLES]
min_gradient = device_config[CONF_MIN_GRADIENT]
sample_duration = device_config[CONF_SAMPLE_DURATION]
sensors.append(
SensorTrend(
hass,
device_id,
friendly_name,
entity_id,
attribute,
device_class,
invert,
max_samples,
min_gradient,
sample_duration,
)
)
if not sensors:
_LOGGER.error("No sensors added")
return
add_entities(sensors) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"setup_reload_service",
"(",
"hass",
",",
"DOMAIN",
",",
"PLATFORMS",
")",
"sensors",
"=",
"[",
"]",
"for",
"device_id",
",",
"device_config",
"in",
"config",
"[",
"CONF_SENSORS",
"]",
".",
"items",
"(",
")",
":",
"entity_id",
"=",
"device_config",
"[",
"ATTR_ENTITY_ID",
"]",
"attribute",
"=",
"device_config",
".",
"get",
"(",
"CONF_ATTRIBUTE",
")",
"device_class",
"=",
"device_config",
".",
"get",
"(",
"CONF_DEVICE_CLASS",
")",
"friendly_name",
"=",
"device_config",
".",
"get",
"(",
"ATTR_FRIENDLY_NAME",
",",
"device_id",
")",
"invert",
"=",
"device_config",
"[",
"CONF_INVERT",
"]",
"max_samples",
"=",
"device_config",
"[",
"CONF_MAX_SAMPLES",
"]",
"min_gradient",
"=",
"device_config",
"[",
"CONF_MIN_GRADIENT",
"]",
"sample_duration",
"=",
"device_config",
"[",
"CONF_SAMPLE_DURATION",
"]",
"sensors",
".",
"append",
"(",
"SensorTrend",
"(",
"hass",
",",
"device_id",
",",
"friendly_name",
",",
"entity_id",
",",
"attribute",
",",
"device_class",
",",
"invert",
",",
"max_samples",
",",
"min_gradient",
",",
"sample_duration",
",",
")",
")",
"if",
"not",
"sensors",
":",
"_LOGGER",
".",
"error",
"(",
"\"No sensors added\"",
")",
"return",
"add_entities",
"(",
"sensors",
")"
] | [
66,
0
] | [
100,
25
] | python | en | ['en', 'ca', 'en'] | True |
SensorTrend.__init__ | (
self,
hass,
device_id,
friendly_name,
entity_id,
attribute,
device_class,
invert,
max_samples,
min_gradient,
sample_duration,
) | Initialize the sensor. | Initialize the sensor. | def __init__(
self,
hass,
device_id,
friendly_name,
entity_id,
attribute,
device_class,
invert,
max_samples,
min_gradient,
sample_duration,
):
"""Initialize the sensor."""
self._hass = hass
self.entity_id = generate_entity_id(ENTITY_ID_FORMAT, device_id, hass=hass)
self._name = friendly_name
self._entity_id = entity_id
self._attribute = attribute
self._device_class = device_class
self._invert = invert
self._sample_duration = sample_duration
self._min_gradient = min_gradient
self._gradient = None
self._state = None
self.samples = deque(maxlen=max_samples) | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"device_id",
",",
"friendly_name",
",",
"entity_id",
",",
"attribute",
",",
"device_class",
",",
"invert",
",",
"max_samples",
",",
"min_gradient",
",",
"sample_duration",
",",
")",
":",
"self",
".",
"_hass",
"=",
"hass",
"self",
".",
"entity_id",
"=",
"generate_entity_id",
"(",
"ENTITY_ID_FORMAT",
",",
"device_id",
",",
"hass",
"=",
"hass",
")",
"self",
".",
"_name",
"=",
"friendly_name",
"self",
".",
"_entity_id",
"=",
"entity_id",
"self",
".",
"_attribute",
"=",
"attribute",
"self",
".",
"_device_class",
"=",
"device_class",
"self",
".",
"_invert",
"=",
"invert",
"self",
".",
"_sample_duration",
"=",
"sample_duration",
"self",
".",
"_min_gradient",
"=",
"min_gradient",
"self",
".",
"_gradient",
"=",
"None",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"samples",
"=",
"deque",
"(",
"maxlen",
"=",
"max_samples",
")"
] | [
106,
4
] | [
131,
48
] | python | en | ['en', 'en', 'en'] | True |
SensorTrend.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"
] | [
134,
4
] | [
136,
25
] | python | en | ['en', 'mi', 'en'] | True |
SensorTrend.is_on | (self) | Return true if sensor is on. | Return true if sensor is on. | def is_on(self):
"""Return true if sensor is on."""
return self._state | [
"def",
"is_on",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
139,
4
] | [
141,
26
] | python | en | ['en', 'et', 'en'] | True |
SensorTrend.device_class | (self) | Return the sensor class of the sensor. | Return the sensor class of the sensor. | def device_class(self):
"""Return the sensor class of the sensor."""
return self._device_class | [
"def",
"device_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"_device_class"
] | [
144,
4
] | [
146,
33
] | python | en | ['en', 'sq', 'en'] | True |
SensorTrend.device_state_attributes | (self) | Return the state attributes of the sensor. | Return the state attributes of the sensor. | def device_state_attributes(self):
"""Return the state attributes of the sensor."""
return {
ATTR_ENTITY_ID: self._entity_id,
ATTR_FRIENDLY_NAME: self._name,
ATTR_GRADIENT: self._gradient,
ATTR_INVERT: self._invert,
ATTR_MIN_GRADIENT: self._min_gradient,
ATTR_SAMPLE_COUNT: len(self.samples),
ATTR_SAMPLE_DURATION: self._sample_duration,
} | [
"def",
"device_state_attributes",
"(",
"self",
")",
":",
"return",
"{",
"ATTR_ENTITY_ID",
":",
"self",
".",
"_entity_id",
",",
"ATTR_FRIENDLY_NAME",
":",
"self",
".",
"_name",
",",
"ATTR_GRADIENT",
":",
"self",
".",
"_gradient",
",",
"ATTR_INVERT",
":",
"self",
".",
"_invert",
",",
"ATTR_MIN_GRADIENT",
":",
"self",
".",
"_min_gradient",
",",
"ATTR_SAMPLE_COUNT",
":",
"len",
"(",
"self",
".",
"samples",
")",
",",
"ATTR_SAMPLE_DURATION",
":",
"self",
".",
"_sample_duration",
",",
"}"
] | [
149,
4
] | [
159,
9
] | python | en | ['en', 'en', 'en'] | True |
SensorTrend.should_poll | (self) | No polling needed. | No polling needed. | def should_poll(self):
"""No polling needed."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
162,
4
] | [
164,
20
] | python | en | ['en', 'en', 'en'] | True |
SensorTrend.async_added_to_hass | (self) | Complete device setup after being added to hass. | Complete device setup after being added to hass. | async def async_added_to_hass(self):
"""Complete device setup after being added to hass."""
@callback
def trend_sensor_state_listener(event):
"""Handle state changes on the observed device."""
new_state = event.data.get("new_state")
if new_state is None:
return
try:
if self._attribute:
state = new_state.attributes.get(self._attribute)
else:
state = new_state.state
if state not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
sample = (new_state.last_updated.timestamp(), float(state))
self.samples.append(sample)
self.async_schedule_update_ha_state(True)
except (ValueError, TypeError) as ex:
_LOGGER.error(ex)
self.async_on_remove(
async_track_state_change_event(
self.hass, [self._entity_id], trend_sensor_state_listener
)
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"@",
"callback",
"def",
"trend_sensor_state_listener",
"(",
"event",
")",
":",
"\"\"\"Handle state changes on the observed device.\"\"\"",
"new_state",
"=",
"event",
".",
"data",
".",
"get",
"(",
"\"new_state\"",
")",
"if",
"new_state",
"is",
"None",
":",
"return",
"try",
":",
"if",
"self",
".",
"_attribute",
":",
"state",
"=",
"new_state",
".",
"attributes",
".",
"get",
"(",
"self",
".",
"_attribute",
")",
"else",
":",
"state",
"=",
"new_state",
".",
"state",
"if",
"state",
"not",
"in",
"(",
"STATE_UNKNOWN",
",",
"STATE_UNAVAILABLE",
")",
":",
"sample",
"=",
"(",
"new_state",
".",
"last_updated",
".",
"timestamp",
"(",
")",
",",
"float",
"(",
"state",
")",
")",
"self",
".",
"samples",
".",
"append",
"(",
"sample",
")",
"self",
".",
"async_schedule_update_ha_state",
"(",
"True",
")",
"except",
"(",
"ValueError",
",",
"TypeError",
")",
"as",
"ex",
":",
"_LOGGER",
".",
"error",
"(",
"ex",
")",
"self",
".",
"async_on_remove",
"(",
"async_track_state_change_event",
"(",
"self",
".",
"hass",
",",
"[",
"self",
".",
"_entity_id",
"]",
",",
"trend_sensor_state_listener",
")",
")"
] | [
166,
4
] | [
191,
9
] | python | en | ['en', 'en', 'en'] | True |
SensorTrend.async_update | (self) | Get the latest data and update the states. | Get the latest data and update the states. | async def async_update(self):
"""Get the latest data and update the states."""
# Remove outdated samples
if self._sample_duration > 0:
cutoff = utcnow().timestamp() - self._sample_duration
while self.samples and self.samples[0][0] < cutoff:
self.samples.popleft()
if len(self.samples) < 2:
return
# Calculate gradient of linear trend
await self.hass.async_add_executor_job(self._calculate_gradient)
# Update state
self._state = (
abs(self._gradient) > abs(self._min_gradient)
and math.copysign(self._gradient, self._min_gradient) == self._gradient
)
if self._invert:
self._state = not self._state | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"# Remove outdated samples",
"if",
"self",
".",
"_sample_duration",
">",
"0",
":",
"cutoff",
"=",
"utcnow",
"(",
")",
".",
"timestamp",
"(",
")",
"-",
"self",
".",
"_sample_duration",
"while",
"self",
".",
"samples",
"and",
"self",
".",
"samples",
"[",
"0",
"]",
"[",
"0",
"]",
"<",
"cutoff",
":",
"self",
".",
"samples",
".",
"popleft",
"(",
")",
"if",
"len",
"(",
"self",
".",
"samples",
")",
"<",
"2",
":",
"return",
"# Calculate gradient of linear trend",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"_calculate_gradient",
")",
"# Update state",
"self",
".",
"_state",
"=",
"(",
"abs",
"(",
"self",
".",
"_gradient",
")",
">",
"abs",
"(",
"self",
".",
"_min_gradient",
")",
"and",
"math",
".",
"copysign",
"(",
"self",
".",
"_gradient",
",",
"self",
".",
"_min_gradient",
")",
"==",
"self",
".",
"_gradient",
")",
"if",
"self",
".",
"_invert",
":",
"self",
".",
"_state",
"=",
"not",
"self",
".",
"_state"
] | [
193,
4
] | [
214,
41
] | python | en | ['en', 'en', 'en'] | True |
SensorTrend._calculate_gradient | (self) | Compute the linear trend gradient of the current samples.
This need run inside executor.
| Compute the linear trend gradient of the current samples. | def _calculate_gradient(self):
"""Compute the linear trend gradient of the current samples.
This need run inside executor.
"""
timestamps = np.array([t for t, _ in self.samples])
values = np.array([s for _, s in self.samples])
coeffs = np.polyfit(timestamps, values, 1)
self._gradient = coeffs[0] | [
"def",
"_calculate_gradient",
"(",
"self",
")",
":",
"timestamps",
"=",
"np",
".",
"array",
"(",
"[",
"t",
"for",
"t",
",",
"_",
"in",
"self",
".",
"samples",
"]",
")",
"values",
"=",
"np",
".",
"array",
"(",
"[",
"s",
"for",
"_",
",",
"s",
"in",
"self",
".",
"samples",
"]",
")",
"coeffs",
"=",
"np",
".",
"polyfit",
"(",
"timestamps",
",",
"values",
",",
"1",
")",
"self",
".",
"_gradient",
"=",
"coeffs",
"[",
"0",
"]"
] | [
216,
4
] | [
224,
34
] | python | en | ['en', 'en', 'en'] | True |
convert_pid | (value) | Convert pid from hex string to integer. | Convert pid from hex string to integer. | def convert_pid(value):
"""Convert pid from hex string to integer."""
return int(value, 16) | [
"def",
"convert_pid",
"(",
"value",
")",
":",
"return",
"int",
"(",
"value",
",",
"16",
")"
] | [
36,
0
] | [
38,
25
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Torque platform. | Set up the Torque platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Torque platform."""
vehicle = config.get(CONF_NAME)
email = config.get(CONF_EMAIL)
sensors = {}
hass.http.register_view(
TorqueReceiveDataView(email, vehicle, sensors, add_entities)
)
return True | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"vehicle",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"email",
"=",
"config",
".",
"get",
"(",
"CONF_EMAIL",
")",
"sensors",
"=",
"{",
"}",
"hass",
".",
"http",
".",
"register_view",
"(",
"TorqueReceiveDataView",
"(",
"email",
",",
"vehicle",
",",
"sensors",
",",
"add_entities",
")",
")",
"return",
"True"
] | [
41,
0
] | [
50,
15
] | python | en | ['en', 'lv', 'en'] | True |
TorqueReceiveDataView.__init__ | (self, email, vehicle, sensors, add_entities) | Initialize a Torque view. | Initialize a Torque view. | def __init__(self, email, vehicle, sensors, add_entities):
"""Initialize a Torque view."""
self.email = email
self.vehicle = vehicle
self.sensors = sensors
self.add_entities = add_entities | [
"def",
"__init__",
"(",
"self",
",",
"email",
",",
"vehicle",
",",
"sensors",
",",
"add_entities",
")",
":",
"self",
".",
"email",
"=",
"email",
"self",
".",
"vehicle",
"=",
"vehicle",
"self",
".",
"sensors",
"=",
"sensors",
"self",
".",
"add_entities",
"=",
"add_entities"
] | [
59,
4
] | [
64,
40
] | python | en | ['es', 'en', 'en'] | True |
TorqueReceiveDataView.get | (self, request) | Handle Torque data request. | Handle Torque data request. | def get(self, request):
"""Handle Torque data request."""
hass = request.app["hass"]
data = request.query
if self.email is not None and self.email != data[SENSOR_EMAIL_FIELD]:
return
names = {}
units = {}
for key in data:
is_name = NAME_KEY.match(key)
is_unit = UNIT_KEY.match(key)
is_value = VALUE_KEY.match(key)
if is_name:
pid = convert_pid(is_name.group(1))
names[pid] = data[key]
elif is_unit:
pid = convert_pid(is_unit.group(1))
temp_unit = data[key]
if "\\xC2\\xB0" in temp_unit:
temp_unit = temp_unit.replace("\\xC2\\xB0", DEGREE)
units[pid] = temp_unit
elif is_value:
pid = convert_pid(is_value.group(1))
if pid in self.sensors:
self.sensors[pid].async_on_update(data[key])
for pid in names:
if pid not in self.sensors:
self.sensors[pid] = TorqueSensor(
ENTITY_NAME_FORMAT.format(self.vehicle, names[pid]), units.get(pid)
)
hass.async_add_job(self.add_entities, [self.sensors[pid]])
return "OK!" | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"hass",
"=",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
"data",
"=",
"request",
".",
"query",
"if",
"self",
".",
"email",
"is",
"not",
"None",
"and",
"self",
".",
"email",
"!=",
"data",
"[",
"SENSOR_EMAIL_FIELD",
"]",
":",
"return",
"names",
"=",
"{",
"}",
"units",
"=",
"{",
"}",
"for",
"key",
"in",
"data",
":",
"is_name",
"=",
"NAME_KEY",
".",
"match",
"(",
"key",
")",
"is_unit",
"=",
"UNIT_KEY",
".",
"match",
"(",
"key",
")",
"is_value",
"=",
"VALUE_KEY",
".",
"match",
"(",
"key",
")",
"if",
"is_name",
":",
"pid",
"=",
"convert_pid",
"(",
"is_name",
".",
"group",
"(",
"1",
")",
")",
"names",
"[",
"pid",
"]",
"=",
"data",
"[",
"key",
"]",
"elif",
"is_unit",
":",
"pid",
"=",
"convert_pid",
"(",
"is_unit",
".",
"group",
"(",
"1",
")",
")",
"temp_unit",
"=",
"data",
"[",
"key",
"]",
"if",
"\"\\\\xC2\\\\xB0\"",
"in",
"temp_unit",
":",
"temp_unit",
"=",
"temp_unit",
".",
"replace",
"(",
"\"\\\\xC2\\\\xB0\"",
",",
"DEGREE",
")",
"units",
"[",
"pid",
"]",
"=",
"temp_unit",
"elif",
"is_value",
":",
"pid",
"=",
"convert_pid",
"(",
"is_value",
".",
"group",
"(",
"1",
")",
")",
"if",
"pid",
"in",
"self",
".",
"sensors",
":",
"self",
".",
"sensors",
"[",
"pid",
"]",
".",
"async_on_update",
"(",
"data",
"[",
"key",
"]",
")",
"for",
"pid",
"in",
"names",
":",
"if",
"pid",
"not",
"in",
"self",
".",
"sensors",
":",
"self",
".",
"sensors",
"[",
"pid",
"]",
"=",
"TorqueSensor",
"(",
"ENTITY_NAME_FORMAT",
".",
"format",
"(",
"self",
".",
"vehicle",
",",
"names",
"[",
"pid",
"]",
")",
",",
"units",
".",
"get",
"(",
"pid",
")",
")",
"hass",
".",
"async_add_job",
"(",
"self",
".",
"add_entities",
",",
"[",
"self",
".",
"sensors",
"[",
"pid",
"]",
"]",
")",
"return",
"\"OK!\""
] | [
67,
4
] | [
105,
20
] | python | en | ['fr', 'nl', 'en'] | False |
TorqueSensor.__init__ | (self, name, unit) | Initialize the sensor. | Initialize the sensor. | def __init__(self, name, unit):
"""Initialize the sensor."""
self._name = name
self._unit = unit
self._state = None | [
"def",
"__init__",
"(",
"self",
",",
"name",
",",
"unit",
")",
":",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_unit",
"=",
"unit",
"self",
".",
"_state",
"=",
"None"
] | [
111,
4
] | [
115,
26
] | python | en | ['en', 'en', 'en'] | True |
TorqueSensor.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"
] | [
118,
4
] | [
120,
25
] | python | en | ['en', 'mi', 'en'] | True |
TorqueSensor.unit_of_measurement | (self) | Return the unit of measurement. | Return the unit of measurement. | def unit_of_measurement(self):
"""Return the unit of measurement."""
return self._unit | [
"def",
"unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit"
] | [
123,
4
] | [
125,
25
] | python | en | ['en', 'la', 'en'] | True |
TorqueSensor.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"
] | [
128,
4
] | [
130,
26
] | python | en | ['en', 'en', 'en'] | True |
TorqueSensor.icon | (self) | Return the default icon of the sensor. | Return the default icon of the sensor. | def icon(self):
"""Return the default icon of the sensor."""
return "mdi:car" | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"\"mdi:car\""
] | [
133,
4
] | [
135,
24
] | python | en | ['en', 'en', 'en'] | True |
TorqueSensor.async_on_update | (self, value) | Receive an update. | Receive an update. | def async_on_update(self, value):
"""Receive an update."""
self._state = value
self.async_write_ha_state() | [
"def",
"async_on_update",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_state",
"=",
"value",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
138,
4
] | [
141,
35
] | python | en | ['en', 'lb', 'en'] | True |
CloudGoogleConfig.__init__ | (self, hass, config, cloud_user, prefs: CloudPreferences, cloud) | Initialize the Google config. | Initialize the Google config. | def __init__(self, hass, config, cloud_user, prefs: CloudPreferences, cloud):
"""Initialize the Google config."""
super().__init__(hass)
self._config = config
self._user = cloud_user
self._prefs = prefs
self._cloud = cloud
self._cur_entity_prefs = self._prefs.google_entity_configs
self._cur_default_expose = self._prefs.google_default_expose
self._sync_entities_lock = asyncio.Lock()
self._sync_on_started = False | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config",
",",
"cloud_user",
",",
"prefs",
":",
"CloudPreferences",
",",
"cloud",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"hass",
")",
"self",
".",
"_config",
"=",
"config",
"self",
".",
"_user",
"=",
"cloud_user",
"self",
".",
"_prefs",
"=",
"prefs",
"self",
".",
"_cloud",
"=",
"cloud",
"self",
".",
"_cur_entity_prefs",
"=",
"self",
".",
"_prefs",
".",
"google_entity_configs",
"self",
".",
"_cur_default_expose",
"=",
"self",
".",
"_prefs",
".",
"google_default_expose",
"self",
".",
"_sync_entities_lock",
"=",
"asyncio",
".",
"Lock",
"(",
")",
"self",
".",
"_sync_on_started",
"=",
"False"
] | [
30,
4
] | [
40,
37
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.enabled | (self) | Return if Google is enabled. | Return if Google is enabled. | def enabled(self):
"""Return if Google is enabled."""
return self._cloud.is_logged_in and self._prefs.google_enabled | [
"def",
"enabled",
"(",
"self",
")",
":",
"return",
"self",
".",
"_cloud",
".",
"is_logged_in",
"and",
"self",
".",
"_prefs",
".",
"google_enabled"
] | [
43,
4
] | [
45,
70
] | python | en | ['en', 'en', 'en'] | True |
CloudGoogleConfig.entity_config | (self) | Return entity config. | Return entity config. | def entity_config(self):
"""Return entity config."""
return self._config.get(CONF_ENTITY_CONFIG) or {} | [
"def",
"entity_config",
"(",
"self",
")",
":",
"return",
"self",
".",
"_config",
".",
"get",
"(",
"CONF_ENTITY_CONFIG",
")",
"or",
"{",
"}"
] | [
48,
4
] | [
50,
57
] | python | en | ['en', 'cy', 'en'] | True |
CloudGoogleConfig.secure_devices_pin | (self) | Return entity config. | Return entity config. | def secure_devices_pin(self):
"""Return entity config."""
return self._prefs.google_secure_devices_pin | [
"def",
"secure_devices_pin",
"(",
"self",
")",
":",
"return",
"self",
".",
"_prefs",
".",
"google_secure_devices_pin"
] | [
53,
4
] | [
55,
52
] | python | en | ['en', 'cy', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.