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 |
---|---|---|---|---|---|---|---|---|---|---|---|
OpenThermClimate.update_options | (self, entry) | Update climate entity options. | Update climate entity options. | def update_options(self, entry):
"""Update climate entity options."""
self.floor_temp = entry.options[CONF_FLOOR_TEMP]
self.temp_precision = entry.options[CONF_PRECISION]
self.async_write_ha_state() | [
"def",
"update_options",
"(",
"self",
",",
"entry",
")",
":",
"self",
".",
"floor_temp",
"=",
"entry",
".",
"options",
"[",
"CONF_FLOOR_TEMP",
"]",
"self",
".",
"temp_precision",
"=",
"entry",
".",
"options",
"[",
"CONF_PRECISION",
"]",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
78,
4
] | [
82,
35
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.async_added_to_hass | (self) | Connect to the OpenTherm Gateway device. | Connect to the OpenTherm Gateway device. | async def async_added_to_hass(self):
"""Connect to the OpenTherm Gateway device."""
_LOGGER.debug("Added OpenTherm Gateway climate device %s", self.friendly_name)
self._unsub_updates = async_dispatcher_connect(
self.hass, self._gateway.update_signal, self.receive_report
)
self._unsub_options = async_dispatcher_connect(
self.hass, self._gateway.options_update_signal, self.update_options
) | [
"async",
"def",
"async_added_to_hass",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Added OpenTherm Gateway climate device %s\"",
",",
"self",
".",
"friendly_name",
")",
"self",
".",
"_unsub_updates",
"=",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_gateway",
".",
"update_signal",
",",
"self",
".",
"receive_report",
")",
"self",
".",
"_unsub_options",
"=",
"async_dispatcher_connect",
"(",
"self",
".",
"hass",
",",
"self",
".",
"_gateway",
".",
"options_update_signal",
",",
"self",
".",
"update_options",
")"
] | [
84,
4
] | [
92,
9
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.async_will_remove_from_hass | (self) | Unsubscribe from updates from the component. | Unsubscribe from updates from the component. | async def async_will_remove_from_hass(self):
"""Unsubscribe from updates from the component."""
_LOGGER.debug("Removing OpenTherm Gateway climate %s", self.friendly_name)
self._unsub_options()
self._unsub_updates() | [
"async",
"def",
"async_will_remove_from_hass",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Removing OpenTherm Gateway climate %s\"",
",",
"self",
".",
"friendly_name",
")",
"self",
".",
"_unsub_options",
"(",
")",
"self",
".",
"_unsub_updates",
"(",
")"
] | [
94,
4
] | [
98,
29
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.receive_report | (self, status) | Receive and handle a new report from the Gateway. | Receive and handle a new report from the Gateway. | def receive_report(self, status):
"""Receive and handle a new report from the Gateway."""
self._available = bool(status)
ch_active = status.get(gw_vars.DATA_SLAVE_CH_ACTIVE)
flame_on = status.get(gw_vars.DATA_SLAVE_FLAME_ON)
cooling_active = status.get(gw_vars.DATA_SLAVE_COOLING_ACTIVE)
if ch_active and flame_on:
self._current_operation = CURRENT_HVAC_HEAT
self._hvac_mode = HVAC_MODE_HEAT
elif cooling_active:
self._current_operation = CURRENT_HVAC_COOL
self._hvac_mode = HVAC_MODE_COOL
else:
self._current_operation = CURRENT_HVAC_IDLE
self._current_temperature = status.get(gw_vars.DATA_ROOM_TEMP)
temp_upd = status.get(gw_vars.DATA_ROOM_SETPOINT)
if self._target_temperature != temp_upd:
self._new_target_temperature = None
self._target_temperature = temp_upd
# GPIO mode 5: 0 == Away
# GPIO mode 6: 1 == Away
gpio_a_state = status.get(gw_vars.OTGW_GPIO_A)
if gpio_a_state == 5:
self._away_mode_a = 0
elif gpio_a_state == 6:
self._away_mode_a = 1
else:
self._away_mode_a = None
gpio_b_state = status.get(gw_vars.OTGW_GPIO_B)
if gpio_b_state == 5:
self._away_mode_b = 0
elif gpio_b_state == 6:
self._away_mode_b = 1
else:
self._away_mode_b = None
if self._away_mode_a is not None:
self._away_state_a = (
status.get(gw_vars.OTGW_GPIO_A_STATE) == self._away_mode_a
)
if self._away_mode_b is not None:
self._away_state_b = (
status.get(gw_vars.OTGW_GPIO_B_STATE) == self._away_mode_b
)
self.async_write_ha_state() | [
"def",
"receive_report",
"(",
"self",
",",
"status",
")",
":",
"self",
".",
"_available",
"=",
"bool",
"(",
"status",
")",
"ch_active",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"DATA_SLAVE_CH_ACTIVE",
")",
"flame_on",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"DATA_SLAVE_FLAME_ON",
")",
"cooling_active",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"DATA_SLAVE_COOLING_ACTIVE",
")",
"if",
"ch_active",
"and",
"flame_on",
":",
"self",
".",
"_current_operation",
"=",
"CURRENT_HVAC_HEAT",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_HEAT",
"elif",
"cooling_active",
":",
"self",
".",
"_current_operation",
"=",
"CURRENT_HVAC_COOL",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_COOL",
"else",
":",
"self",
".",
"_current_operation",
"=",
"CURRENT_HVAC_IDLE",
"self",
".",
"_current_temperature",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"DATA_ROOM_TEMP",
")",
"temp_upd",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"DATA_ROOM_SETPOINT",
")",
"if",
"self",
".",
"_target_temperature",
"!=",
"temp_upd",
":",
"self",
".",
"_new_target_temperature",
"=",
"None",
"self",
".",
"_target_temperature",
"=",
"temp_upd",
"# GPIO mode 5: 0 == Away",
"# GPIO mode 6: 1 == Away",
"gpio_a_state",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"OTGW_GPIO_A",
")",
"if",
"gpio_a_state",
"==",
"5",
":",
"self",
".",
"_away_mode_a",
"=",
"0",
"elif",
"gpio_a_state",
"==",
"6",
":",
"self",
".",
"_away_mode_a",
"=",
"1",
"else",
":",
"self",
".",
"_away_mode_a",
"=",
"None",
"gpio_b_state",
"=",
"status",
".",
"get",
"(",
"gw_vars",
".",
"OTGW_GPIO_B",
")",
"if",
"gpio_b_state",
"==",
"5",
":",
"self",
".",
"_away_mode_b",
"=",
"0",
"elif",
"gpio_b_state",
"==",
"6",
":",
"self",
".",
"_away_mode_b",
"=",
"1",
"else",
":",
"self",
".",
"_away_mode_b",
"=",
"None",
"if",
"self",
".",
"_away_mode_a",
"is",
"not",
"None",
":",
"self",
".",
"_away_state_a",
"=",
"(",
"status",
".",
"get",
"(",
"gw_vars",
".",
"OTGW_GPIO_A_STATE",
")",
"==",
"self",
".",
"_away_mode_a",
")",
"if",
"self",
".",
"_away_mode_b",
"is",
"not",
"None",
":",
"self",
".",
"_away_state_b",
"=",
"(",
"status",
".",
"get",
"(",
"gw_vars",
".",
"OTGW_GPIO_B_STATE",
")",
"==",
"self",
".",
"_away_mode_b",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
101,
4
] | [
147,
35
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.available | (self) | Return availability of the sensor. | Return availability of the sensor. | def available(self):
"""Return availability of the sensor."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
150,
4
] | [
152,
30
] | python | en | ['en', 'ga', 'en'] | True |
OpenThermClimate.name | (self) | Return the friendly name. | Return the friendly name. | def name(self):
"""Return the friendly name."""
return self.friendly_name | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"friendly_name"
] | [
155,
4
] | [
157,
33
] | python | en | ['en', 'ig', 'en'] | True |
OpenThermClimate.device_info | (self) | Return device info. | Return device info. | def device_info(self):
"""Return device info."""
return {
"identifiers": {(DOMAIN, self._gateway.gw_id)},
"name": self._gateway.name,
"manufacturer": "Schelte Bron",
"model": "OpenTherm Gateway",
"sw_version": self._gateway.gw_version,
} | [
"def",
"device_info",
"(",
"self",
")",
":",
"return",
"{",
"\"identifiers\"",
":",
"{",
"(",
"DOMAIN",
",",
"self",
".",
"_gateway",
".",
"gw_id",
")",
"}",
",",
"\"name\"",
":",
"self",
".",
"_gateway",
".",
"name",
",",
"\"manufacturer\"",
":",
"\"Schelte Bron\"",
",",
"\"model\"",
":",
"\"OpenTherm Gateway\"",
",",
"\"sw_version\"",
":",
"self",
".",
"_gateway",
".",
"gw_version",
",",
"}"
] | [
160,
4
] | [
168,
9
] | python | en | ['es', 'hr', 'en'] | False |
OpenThermClimate.unique_id | (self) | Return a unique ID. | Return a unique ID. | def unique_id(self):
"""Return a unique ID."""
return self._gateway.gw_id | [
"def",
"unique_id",
"(",
"self",
")",
":",
"return",
"self",
".",
"_gateway",
".",
"gw_id"
] | [
171,
4
] | [
173,
34
] | python | ca | ['fr', 'ca', 'en'] | False |
OpenThermClimate.precision | (self) | Return the precision of the system. | Return the precision of the system. | def precision(self):
"""Return the precision of the system."""
if self.temp_precision is not None and self.temp_precision != 0:
return self.temp_precision
if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
return PRECISION_HALVES
return PRECISION_WHOLE | [
"def",
"precision",
"(",
"self",
")",
":",
"if",
"self",
".",
"temp_precision",
"is",
"not",
"None",
"and",
"self",
".",
"temp_precision",
"!=",
"0",
":",
"return",
"self",
".",
"temp_precision",
"if",
"self",
".",
"hass",
".",
"config",
".",
"units",
".",
"temperature_unit",
"==",
"TEMP_CELSIUS",
":",
"return",
"PRECISION_HALVES",
"return",
"PRECISION_WHOLE"
] | [
176,
4
] | [
182,
30
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.should_poll | (self) | Disable polling for this entity. | Disable polling for this entity. | def should_poll(self):
"""Disable polling for this entity."""
return False | [
"def",
"should_poll",
"(",
"self",
")",
":",
"return",
"False"
] | [
185,
4
] | [
187,
20
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.temperature_unit | (self) | Return the unit of measurement used by the platform. | Return the unit of measurement used by the platform. | def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"TEMP_CELSIUS"
] | [
190,
4
] | [
192,
27
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.hvac_action | (self) | Return current HVAC operation. | Return current HVAC operation. | def hvac_action(self):
"""Return current HVAC operation."""
return self._current_operation | [
"def",
"hvac_action",
"(",
"self",
")",
":",
"return",
"self",
".",
"_current_operation"
] | [
195,
4
] | [
197,
38
] | python | en | ['en', 'bg', 'en'] | True |
OpenThermClimate.hvac_mode | (self) | Return current HVAC mode. | Return current HVAC mode. | def hvac_mode(self):
"""Return current HVAC mode."""
return self._hvac_mode | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hvac_mode"
] | [
200,
4
] | [
202,
30
] | python | en | ['en', 'co', 'en'] | True |
OpenThermClimate.hvac_modes | (self) | Return available HVAC modes. | Return available HVAC modes. | def hvac_modes(self):
"""Return available HVAC modes."""
return [] | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"[",
"]"
] | [
205,
4
] | [
207,
17
] | python | en | ['fr', 'hi-Latn', 'en'] | False |
OpenThermClimate.set_hvac_mode | (self, hvac_mode) | Set the HVAC mode. | Set the HVAC mode. | def set_hvac_mode(self, hvac_mode):
"""Set the HVAC mode."""
_LOGGER.warning("Changing HVAC mode is not supported") | [
"def",
"set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Changing HVAC mode is not supported\"",
")"
] | [
209,
4
] | [
211,
62
] | python | en | ['en', 'pt', 'en'] | True |
OpenThermClimate.current_temperature | (self) | Return the current temperature. | Return the current temperature. | def current_temperature(self):
"""Return the current temperature."""
if self._current_temperature is None:
return
if self.floor_temp is True:
if self.precision == PRECISION_HALVES:
return int(2 * self._current_temperature) / 2
if self.precision == PRECISION_TENTHS:
return int(10 * self._current_temperature) / 10
return int(self._current_temperature)
return self._current_temperature | [
"def",
"current_temperature",
"(",
"self",
")",
":",
"if",
"self",
".",
"_current_temperature",
"is",
"None",
":",
"return",
"if",
"self",
".",
"floor_temp",
"is",
"True",
":",
"if",
"self",
".",
"precision",
"==",
"PRECISION_HALVES",
":",
"return",
"int",
"(",
"2",
"*",
"self",
".",
"_current_temperature",
")",
"/",
"2",
"if",
"self",
".",
"precision",
"==",
"PRECISION_TENTHS",
":",
"return",
"int",
"(",
"10",
"*",
"self",
".",
"_current_temperature",
")",
"/",
"10",
"return",
"int",
"(",
"self",
".",
"_current_temperature",
")",
"return",
"self",
".",
"_current_temperature"
] | [
214,
4
] | [
224,
40
] | python | en | ['en', 'la', 'en'] | True |
OpenThermClimate.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."""
return self._new_target_temperature or self._target_temperature | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_new_target_temperature",
"or",
"self",
".",
"_target_temperature"
] | [
227,
4
] | [
229,
71
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.target_temperature_step | (self) | Return the supported step of target temperature. | Return the supported step of target temperature. | def target_temperature_step(self):
"""Return the supported step of target temperature."""
return self.precision | [
"def",
"target_temperature_step",
"(",
"self",
")",
":",
"return",
"self",
".",
"precision"
] | [
232,
4
] | [
234,
29
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.preset_mode | (self) | Return current preset mode. | Return current preset mode. | def preset_mode(self):
"""Return current preset mode."""
if self._away_state_a or self._away_state_b:
return PRESET_AWAY
return PRESET_NONE | [
"def",
"preset_mode",
"(",
"self",
")",
":",
"if",
"self",
".",
"_away_state_a",
"or",
"self",
".",
"_away_state_b",
":",
"return",
"PRESET_AWAY",
"return",
"PRESET_NONE"
] | [
237,
4
] | [
241,
26
] | python | en | ['en', 'ca', 'en'] | True |
OpenThermClimate.preset_modes | (self) | Available preset modes to set. | Available preset modes to set. | def preset_modes(self):
"""Available preset modes to set."""
return [] | [
"def",
"preset_modes",
"(",
"self",
")",
":",
"return",
"[",
"]"
] | [
244,
4
] | [
246,
17
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.set_preset_mode | (self, preset_mode) | Set the preset mode. | Set the preset mode. | def set_preset_mode(self, preset_mode):
"""Set the preset mode."""
_LOGGER.warning("Changing preset mode is not supported") | [
"def",
"set_preset_mode",
"(",
"self",
",",
"preset_mode",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Changing preset mode is not supported\"",
")"
] | [
248,
4
] | [
250,
64
] | python | en | ['en', 'pt', 'en'] | True |
OpenThermClimate.async_set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
if ATTR_TEMPERATURE in kwargs:
temp = float(kwargs[ATTR_TEMPERATURE])
if temp == self.target_temperature:
return
self._new_target_temperature = await self._gateway.gateway.set_target_temp(
temp
)
self.async_write_ha_state() | [
"async",
"def",
"async_set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"ATTR_TEMPERATURE",
"in",
"kwargs",
":",
"temp",
"=",
"float",
"(",
"kwargs",
"[",
"ATTR_TEMPERATURE",
"]",
")",
"if",
"temp",
"==",
"self",
".",
"target_temperature",
":",
"return",
"self",
".",
"_new_target_temperature",
"=",
"await",
"self",
".",
"_gateway",
".",
"gateway",
".",
"set_target_temp",
"(",
"temp",
")",
"self",
".",
"async_write_ha_state",
"(",
")"
] | [
252,
4
] | [
261,
39
] | python | en | ['en', 'ca', 'en'] | True |
OpenThermClimate.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"
] | [
264,
4
] | [
266,
28
] | python | en | ['en', 'en', 'en'] | True |
OpenThermClimate.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self):
"""Return the minimum temperature."""
return 1 | [
"def",
"min_temp",
"(",
"self",
")",
":",
"return",
"1"
] | [
269,
4
] | [
271,
16
] | python | en | ['en', 'la', 'en'] | True |
OpenThermClimate.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self):
"""Return the maximum temperature."""
return 30 | [
"def",
"max_temp",
"(",
"self",
")",
":",
"return",
"30"
] | [
274,
4
] | [
276,
17
] | python | en | ['en', 'la', 'en'] | True |
mock_real_ip | (app) | Inject middleware to mock real IP.
Returns a function to set the real IP.
| Inject middleware to mock real IP. | def mock_real_ip(app):
"""Inject middleware to mock real IP.
Returns a function to set the real IP.
"""
ip_to_mock = None
def set_ip_to_mock(value):
nonlocal ip_to_mock
ip_to_mock = value
@web.middleware
async def mock_real_ip(request, handler):
"""Mock Real IP middleware."""
nonlocal ip_to_mock
request = request.clone(remote=ip_to_mock)
return await handler(request)
async def real_ip_startup(app):
"""Startup of real ip."""
app.middlewares.insert(0, mock_real_ip)
app.on_startup.append(real_ip_startup)
return set_ip_to_mock | [
"def",
"mock_real_ip",
"(",
"app",
")",
":",
"ip_to_mock",
"=",
"None",
"def",
"set_ip_to_mock",
"(",
"value",
")",
":",
"nonlocal",
"ip_to_mock",
"ip_to_mock",
"=",
"value",
"@",
"web",
".",
"middleware",
"async",
"def",
"mock_real_ip",
"(",
"request",
",",
"handler",
")",
":",
"\"\"\"Mock Real IP middleware.\"\"\"",
"nonlocal",
"ip_to_mock",
"request",
"=",
"request",
".",
"clone",
"(",
"remote",
"=",
"ip_to_mock",
")",
"return",
"await",
"handler",
"(",
"request",
")",
"async",
"def",
"real_ip_startup",
"(",
"app",
")",
":",
"\"\"\"Startup of real ip.\"\"\"",
"app",
".",
"middlewares",
".",
"insert",
"(",
"0",
",",
"mock_real_ip",
")",
"app",
".",
"on_startup",
".",
"append",
"(",
"real_ip_startup",
")",
"return",
"set_ip_to_mock"
] | [
7,
0
] | [
33,
25
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the XS1 thermostat platform. | Set up the XS1 thermostat platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the XS1 thermostat platform."""
actuators = hass.data[COMPONENT_DOMAIN][ACTUATORS]
sensors = hass.data[COMPONENT_DOMAIN][SENSORS]
thermostat_entities = []
for actuator in actuators:
if actuator.type() == ActuatorType.TEMPERATURE:
# Search for a matching sensor (by name)
actuator_name = actuator.name()
matching_sensor = None
for sensor in sensors:
if actuator_name in sensor.name():
matching_sensor = sensor
break
thermostat_entities.append(XS1ThermostatEntity(actuator, matching_sensor))
add_entities(thermostat_entities) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"actuators",
"=",
"hass",
".",
"data",
"[",
"COMPONENT_DOMAIN",
"]",
"[",
"ACTUATORS",
"]",
"sensors",
"=",
"hass",
".",
"data",
"[",
"COMPONENT_DOMAIN",
"]",
"[",
"SENSORS",
"]",
"thermostat_entities",
"=",
"[",
"]",
"for",
"actuator",
"in",
"actuators",
":",
"if",
"actuator",
".",
"type",
"(",
")",
"==",
"ActuatorType",
".",
"TEMPERATURE",
":",
"# Search for a matching sensor (by name)",
"actuator_name",
"=",
"actuator",
".",
"name",
"(",
")",
"matching_sensor",
"=",
"None",
"for",
"sensor",
"in",
"sensors",
":",
"if",
"actuator_name",
"in",
"sensor",
".",
"name",
"(",
")",
":",
"matching_sensor",
"=",
"sensor",
"break",
"thermostat_entities",
".",
"append",
"(",
"XS1ThermostatEntity",
"(",
"actuator",
",",
"matching_sensor",
")",
")",
"add_entities",
"(",
"thermostat_entities",
")"
] | [
18,
0
] | [
37,
37
] | python | en | ['en', 'cs', 'en'] | True |
XS1ThermostatEntity.__init__ | (self, device, sensor) | Initialize the actuator. | Initialize the actuator. | def __init__(self, device, sensor):
"""Initialize the actuator."""
super().__init__(device)
self.sensor = sensor | [
"def",
"__init__",
"(",
"self",
",",
"device",
",",
"sensor",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"device",
")",
"self",
".",
"sensor",
"=",
"sensor"
] | [
43,
4
] | [
46,
28
] | python | en | ['en', 'en', 'en'] | True |
XS1ThermostatEntity.name | (self) | Return the name of the device if any. | Return the name of the device if any. | def name(self):
"""Return the name of the device if any."""
return self.device.name() | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"name",
"(",
")"
] | [
49,
4
] | [
51,
33
] | python | en | ['en', 'en', 'en'] | True |
XS1ThermostatEntity.supported_features | (self) | Flag supported features. | Flag supported features. | def supported_features(self):
"""Flag supported features."""
return SUPPORT_TARGET_TEMPERATURE | [
"def",
"supported_features",
"(",
"self",
")",
":",
"return",
"SUPPORT_TARGET_TEMPERATURE"
] | [
54,
4
] | [
56,
41
] | python | en | ['da', 'en', 'en'] | True |
XS1ThermostatEntity.hvac_mode | (self) | Return hvac operation ie. heat, cool mode.
Need to be one of HVAC_MODE_*.
| Return hvac operation ie. heat, cool mode. | def hvac_mode(self):
"""Return hvac operation ie. heat, cool mode.
Need to be one of HVAC_MODE_*.
"""
return HVAC_MODE_HEAT | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"return",
"HVAC_MODE_HEAT"
] | [
59,
4
] | [
64,
29
] | python | bg | ['en', 'bg', 'bg'] | True |
XS1ThermostatEntity.hvac_modes | (self) | Return the list of available hvac operation modes.
Need to be a subset of HVAC_MODES.
| Return the list of available hvac operation modes. | def hvac_modes(self):
"""Return the list of available hvac operation modes.
Need to be a subset of HVAC_MODES.
"""
return SUPPORT_HVAC | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"SUPPORT_HVAC"
] | [
67,
4
] | [
72,
27
] | python | en | ['en', 'en', 'en'] | True |
XS1ThermostatEntity.current_temperature | (self) | Return the current temperature. | Return the current temperature. | def current_temperature(self):
"""Return the current temperature."""
if self.sensor is None:
return None
return self.sensor.value() | [
"def",
"current_temperature",
"(",
"self",
")",
":",
"if",
"self",
".",
"sensor",
"is",
"None",
":",
"return",
"None",
"return",
"self",
".",
"sensor",
".",
"value",
"(",
")"
] | [
75,
4
] | [
80,
34
] | python | en | ['en', 'la', 'en'] | True |
XS1ThermostatEntity.temperature_unit | (self) | Return the unit of measurement used by the platform. | Return the unit of measurement used by the platform. | def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return self.device.unit() | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"unit",
"(",
")"
] | [
83,
4
] | [
85,
33
] | python | en | ['en', 'en', 'en'] | True |
XS1ThermostatEntity.target_temperature | (self) | Return the current target temperature. | Return the current target temperature. | def target_temperature(self):
"""Return the current target temperature."""
return self.device.new_value() | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"device",
".",
"new_value",
"(",
")"
] | [
88,
4
] | [
90,
38
] | python | en | ['en', 'la', 'en'] | True |
XS1ThermostatEntity.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self):
"""Return the minimum temperature."""
return MIN_TEMP | [
"def",
"min_temp",
"(",
"self",
")",
":",
"return",
"MIN_TEMP"
] | [
93,
4
] | [
95,
23
] | python | en | ['en', 'la', 'en'] | True |
XS1ThermostatEntity.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self):
"""Return the maximum temperature."""
return MAX_TEMP | [
"def",
"max_temp",
"(",
"self",
")",
":",
"return",
"MAX_TEMP"
] | [
98,
4
] | [
100,
23
] | python | en | ['en', 'la', 'en'] | True |
XS1ThermostatEntity.set_temperature | (self, **kwargs) | Set new target temperature. | Set new target temperature. | def set_temperature(self, **kwargs):
"""Set new target temperature."""
temp = kwargs.get(ATTR_TEMPERATURE)
self.device.set_value(temp)
if self.sensor is not None:
self.schedule_update_ha_state() | [
"def",
"set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"temp",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"self",
".",
"device",
".",
"set_value",
"(",
"temp",
")",
"if",
"self",
".",
"sensor",
"is",
"not",
"None",
":",
"self",
".",
"schedule_update_ha_state",
"(",
")"
] | [
102,
4
] | [
109,
43
] | python | en | ['en', 'ca', 'en'] | True |
XS1ThermostatEntity.set_hvac_mode | (self, hvac_mode) | Set new target hvac mode. | Set new target hvac mode. | def set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode.""" | [
"def",
"set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":"
] | [
111,
4
] | [
112,
39
] | python | da | ['da', 'su', 'en'] | False |
XS1ThermostatEntity.async_update | (self) | Also update the sensor when available. | Also update the sensor when available. | async def async_update(self):
"""Also update the sensor when available."""
await super().async_update()
if self.sensor is not None:
await self.hass.async_add_executor_job(self.sensor.update) | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"super",
"(",
")",
".",
"async_update",
"(",
")",
"if",
"self",
".",
"sensor",
"is",
"not",
"None",
":",
"await",
"self",
".",
"hass",
".",
"async_add_executor_job",
"(",
"self",
".",
"sensor",
".",
"update",
")"
] | [
114,
4
] | [
118,
70
] | python | en | ['en', 'en', 'en'] | True |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Verisure platform. | Set up the Verisure platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Verisure platform."""
alarms = []
if int(hub.config.get(CONF_ALARM, 1)):
hub.update_overview()
alarms.append(VerisureAlarm())
add_entities(alarms) | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"alarms",
"=",
"[",
"]",
"if",
"int",
"(",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_ALARM",
",",
"1",
")",
")",
":",
"hub",
".",
"update_overview",
"(",
")",
"alarms",
".",
"append",
"(",
"VerisureAlarm",
"(",
")",
")",
"add_entities",
"(",
"alarms",
")"
] | [
20,
0
] | [
26,
24
] | python | en | ['en', 'lv', 'en'] | True |
set_arm_state | (state, code=None) | Send set arm state command. | Send set arm state command. | def set_arm_state(state, code=None):
"""Send set arm state command."""
transaction_id = hub.session.set_arm_state(code, state)[
"armStateChangeTransactionId"
]
_LOGGER.info("verisure set arm state %s", state)
transaction = {}
while "result" not in transaction:
sleep(0.5)
transaction = hub.session.get_arm_state_transaction(transaction_id)
hub.update_overview(no_throttle=True) | [
"def",
"set_arm_state",
"(",
"state",
",",
"code",
"=",
"None",
")",
":",
"transaction_id",
"=",
"hub",
".",
"session",
".",
"set_arm_state",
"(",
"code",
",",
"state",
")",
"[",
"\"armStateChangeTransactionId\"",
"]",
"_LOGGER",
".",
"info",
"(",
"\"verisure set arm state %s\"",
",",
"state",
")",
"transaction",
"=",
"{",
"}",
"while",
"\"result\"",
"not",
"in",
"transaction",
":",
"sleep",
"(",
"0.5",
")",
"transaction",
"=",
"hub",
".",
"session",
".",
"get_arm_state_transaction",
"(",
"transaction_id",
")",
"hub",
".",
"update_overview",
"(",
"no_throttle",
"=",
"True",
")"
] | [
29,
0
] | [
39,
41
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.__init__ | (self) | Initialize the Verisure alarm panel. | Initialize the Verisure alarm panel. | def __init__(self):
"""Initialize the Verisure alarm panel."""
self._state = None
self._digits = hub.config.get(CONF_CODE_DIGITS)
self._changed_by = None | [
"def",
"__init__",
"(",
"self",
")",
":",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_digits",
"=",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_CODE_DIGITS",
")",
"self",
".",
"_changed_by",
"=",
"None"
] | [
45,
4
] | [
49,
31
] | python | en | ['en', 'ro', 'en'] | True |
VerisureAlarm.name | (self) | Return the name of the device. | Return the name of the device. | def name(self):
"""Return the name of the device."""
giid = hub.config.get(CONF_GIID)
if giid is not None:
aliass = {i["giid"]: i["alias"] for i in hub.session.installations}
if giid in aliass:
return "{} alarm".format(aliass[giid])
_LOGGER.error("Verisure installation giid not found: %s", giid)
return "{} alarm".format(hub.session.installations[0]["alias"]) | [
"def",
"name",
"(",
"self",
")",
":",
"giid",
"=",
"hub",
".",
"config",
".",
"get",
"(",
"CONF_GIID",
")",
"if",
"giid",
"is",
"not",
"None",
":",
"aliass",
"=",
"{",
"i",
"[",
"\"giid\"",
"]",
":",
"i",
"[",
"\"alias\"",
"]",
"for",
"i",
"in",
"hub",
".",
"session",
".",
"installations",
"}",
"if",
"giid",
"in",
"aliass",
":",
"return",
"\"{} alarm\"",
".",
"format",
"(",
"aliass",
"[",
"giid",
"]",
")",
"_LOGGER",
".",
"error",
"(",
"\"Verisure installation giid not found: %s\"",
",",
"giid",
")",
"return",
"\"{} alarm\"",
".",
"format",
"(",
"hub",
".",
"session",
".",
"installations",
"[",
"0",
"]",
"[",
"\"alias\"",
"]",
")"
] | [
52,
4
] | [
62,
71
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.state | (self) | Return the state of the device. | Return the state of the device. | def state(self):
"""Return the state of the device."""
return self._state | [
"def",
"state",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
65,
4
] | [
67,
26
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.supported_features | (self) | Return the list of supported features. | Return the list of supported features. | def supported_features(self) -> int:
"""Return the list of supported features."""
return SUPPORT_ALARM_ARM_HOME | SUPPORT_ALARM_ARM_AWAY | [
"def",
"supported_features",
"(",
"self",
")",
"->",
"int",
":",
"return",
"SUPPORT_ALARM_ARM_HOME",
"|",
"SUPPORT_ALARM_ARM_AWAY"
] | [
70,
4
] | [
72,
62
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.code_format | (self) | Return one or more digits/characters. | Return one or more digits/characters. | def code_format(self):
"""Return one or more digits/characters."""
return alarm.FORMAT_NUMBER | [
"def",
"code_format",
"(",
"self",
")",
":",
"return",
"alarm",
".",
"FORMAT_NUMBER"
] | [
75,
4
] | [
77,
34
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.changed_by | (self) | Return the last change triggered by. | Return the last change triggered by. | def changed_by(self):
"""Return the last change triggered by."""
return self._changed_by | [
"def",
"changed_by",
"(",
"self",
")",
":",
"return",
"self",
".",
"_changed_by"
] | [
80,
4
] | [
82,
31
] | python | en | ['en', 'en', 'en'] | True |
VerisureAlarm.update | (self) | Update alarm status. | Update alarm status. | def update(self):
"""Update alarm status."""
hub.update_overview()
status = hub.get_first("$.armState.statusType")
if status == "DISARMED":
self._state = STATE_ALARM_DISARMED
elif status == "ARMED_HOME":
self._state = STATE_ALARM_ARMED_HOME
elif status == "ARMED_AWAY":
self._state = STATE_ALARM_ARMED_AWAY
elif status != "PENDING":
_LOGGER.error("Unknown alarm state %s", status)
self._changed_by = hub.get_first("$.armState.name") | [
"def",
"update",
"(",
"self",
")",
":",
"hub",
".",
"update_overview",
"(",
")",
"status",
"=",
"hub",
".",
"get_first",
"(",
"\"$.armState.statusType\"",
")",
"if",
"status",
"==",
"\"DISARMED\"",
":",
"self",
".",
"_state",
"=",
"STATE_ALARM_DISARMED",
"elif",
"status",
"==",
"\"ARMED_HOME\"",
":",
"self",
".",
"_state",
"=",
"STATE_ALARM_ARMED_HOME",
"elif",
"status",
"==",
"\"ARMED_AWAY\"",
":",
"self",
".",
"_state",
"=",
"STATE_ALARM_ARMED_AWAY",
"elif",
"status",
"!=",
"\"PENDING\"",
":",
"_LOGGER",
".",
"error",
"(",
"\"Unknown alarm state %s\"",
",",
"status",
")",
"self",
".",
"_changed_by",
"=",
"hub",
".",
"get_first",
"(",
"\"$.armState.name\"",
")"
] | [
84,
4
] | [
96,
59
] | python | en | ['tr', 'la', 'en'] | False |
VerisureAlarm.alarm_disarm | (self, code=None) | Send disarm command. | Send disarm command. | def alarm_disarm(self, code=None):
"""Send disarm command."""
set_arm_state("DISARMED", code) | [
"def",
"alarm_disarm",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"set_arm_state",
"(",
"\"DISARMED\"",
",",
"code",
")"
] | [
98,
4
] | [
100,
39
] | python | en | ['en', 'pt', 'en'] | True |
VerisureAlarm.alarm_arm_home | (self, code=None) | Send arm home command. | Send arm home command. | def alarm_arm_home(self, code=None):
"""Send arm home command."""
set_arm_state("ARMED_HOME", code) | [
"def",
"alarm_arm_home",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"set_arm_state",
"(",
"\"ARMED_HOME\"",
",",
"code",
")"
] | [
102,
4
] | [
104,
41
] | python | en | ['en', 'pt', 'en'] | True |
VerisureAlarm.alarm_arm_away | (self, code=None) | Send arm away command. | Send arm away command. | def alarm_arm_away(self, code=None):
"""Send arm away command."""
set_arm_state("ARMED_AWAY", code) | [
"def",
"alarm_arm_away",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"set_arm_state",
"(",
"\"ARMED_AWAY\"",
",",
"code",
")"
] | [
106,
4
] | [
108,
41
] | python | en | ['en', 'en', 'en'] | True |
async_setup_entry | (hass, config_entry, async_add_entities) | Set up the AEH-W4A1 climate platform. | Set up the AEH-W4A1 climate platform. | async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the AEH-W4A1 climate platform."""
# Priority 1: manual config
if hass.data[DOMAIN].get(CONF_IP_ADDRESS):
devices = hass.data[DOMAIN][CONF_IP_ADDRESS]
else:
# Priority 2: scanned interfaces
devices = await AehW4a1().discovery()
entities = [_build_entity(device) for device in devices]
async_add_entities(entities, True) | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config_entry",
",",
"async_add_entities",
")",
":",
"# Priority 1: manual config",
"if",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
".",
"get",
"(",
"CONF_IP_ADDRESS",
")",
":",
"devices",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"CONF_IP_ADDRESS",
"]",
"else",
":",
"# Priority 2: scanned interfaces",
"devices",
"=",
"await",
"AehW4a1",
"(",
")",
".",
"discovery",
"(",
")",
"entities",
"=",
"[",
"_build_entity",
"(",
"device",
")",
"for",
"device",
"in",
"devices",
"]",
"async_add_entities",
"(",
"entities",
",",
"True",
")"
] | [
133,
0
] | [
143,
38
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.__init__ | (self, device) | Initialize the climate device. | Initialize the climate device. | def __init__(self, device):
"""Initialize the climate device."""
self._unique_id = device
self._device = AehW4a1(device)
self._hvac_modes = HVAC_MODES
self._fan_modes = FAN_MODES
self._swing_modes = SWING_MODES
self._preset_modes = PRESET_MODES
self._available = None
self._on = None
self._temperature_unit = None
self._current_temperature = None
self._target_temperature = None
self._hvac_mode = None
self._fan_mode = None
self._swing_mode = None
self._preset_mode = None
self._previous_state = None | [
"def",
"__init__",
"(",
"self",
",",
"device",
")",
":",
"self",
".",
"_unique_id",
"=",
"device",
"self",
".",
"_device",
"=",
"AehW4a1",
"(",
"device",
")",
"self",
".",
"_hvac_modes",
"=",
"HVAC_MODES",
"self",
".",
"_fan_modes",
"=",
"FAN_MODES",
"self",
".",
"_swing_modes",
"=",
"SWING_MODES",
"self",
".",
"_preset_modes",
"=",
"PRESET_MODES",
"self",
".",
"_available",
"=",
"None",
"self",
".",
"_on",
"=",
"None",
"self",
".",
"_temperature_unit",
"=",
"None",
"self",
".",
"_current_temperature",
"=",
"None",
"self",
".",
"_target_temperature",
"=",
"None",
"self",
".",
"_hvac_mode",
"=",
"None",
"self",
".",
"_fan_mode",
"=",
"None",
"self",
".",
"_swing_mode",
"=",
"None",
"self",
".",
"_preset_mode",
"=",
"None",
"self",
".",
"_previous_state",
"=",
"None"
] | [
149,
4
] | [
166,
35
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.async_update | (self) | Pull state from AEH-W4A1. | Pull state from AEH-W4A1. | async def async_update(self):
"""Pull state from AEH-W4A1."""
try:
status = await self._device.command("status_102_0")
except pyaehw4a1.exceptions.ConnectionError as library_error:
_LOGGER.warning(
"Unexpected error of %s: %s", self._unique_id, library_error
)
self._available = False
return
self._available = True
self._on = status["run_status"]
if status["temperature_Fahrenheit"] == "0":
self._temperature_unit = TEMP_CELSIUS
else:
self._temperature_unit = TEMP_FAHRENHEIT
self._current_temperature = int(status["indoor_temperature_status"], 2)
if self._on == "1":
device_mode = status["mode_status"]
self._hvac_mode = AC_TO_HA_STATE[device_mode]
fan_mode = status["wind_status"]
self._fan_mode = AC_TO_HA_FAN_MODES[fan_mode]
swing_mode = f'{status["up_down"]}{status["left_right"]}'
self._swing_mode = AC_TO_HA_SWING[swing_mode]
if self._hvac_mode in (HVAC_MODE_COOL, HVAC_MODE_HEAT):
self._target_temperature = int(status["indoor_temperature_setting"], 2)
else:
self._target_temperature = None
if status["efficient"] == "1":
self._preset_mode = PRESET_BOOST
elif status["low_electricity"] == "1":
self._preset_mode = PRESET_ECO
elif status["sleep_status"] == "0000001":
self._preset_mode = PRESET_SLEEP
elif status["sleep_status"] == "0000010":
self._preset_mode = "sleep_2"
elif status["sleep_status"] == "0000011":
self._preset_mode = "sleep_3"
elif status["sleep_status"] == "0000100":
self._preset_mode = "sleep_4"
else:
self._preset_mode = PRESET_NONE
else:
self._hvac_mode = HVAC_MODE_OFF
self._fan_mode = None
self._swing_mode = None
self._target_temperature = None
self._preset_mode = None | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"try",
":",
"status",
"=",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"status_102_0\"",
")",
"except",
"pyaehw4a1",
".",
"exceptions",
".",
"ConnectionError",
"as",
"library_error",
":",
"_LOGGER",
".",
"warning",
"(",
"\"Unexpected error of %s: %s\"",
",",
"self",
".",
"_unique_id",
",",
"library_error",
")",
"self",
".",
"_available",
"=",
"False",
"return",
"self",
".",
"_available",
"=",
"True",
"self",
".",
"_on",
"=",
"status",
"[",
"\"run_status\"",
"]",
"if",
"status",
"[",
"\"temperature_Fahrenheit\"",
"]",
"==",
"\"0\"",
":",
"self",
".",
"_temperature_unit",
"=",
"TEMP_CELSIUS",
"else",
":",
"self",
".",
"_temperature_unit",
"=",
"TEMP_FAHRENHEIT",
"self",
".",
"_current_temperature",
"=",
"int",
"(",
"status",
"[",
"\"indoor_temperature_status\"",
"]",
",",
"2",
")",
"if",
"self",
".",
"_on",
"==",
"\"1\"",
":",
"device_mode",
"=",
"status",
"[",
"\"mode_status\"",
"]",
"self",
".",
"_hvac_mode",
"=",
"AC_TO_HA_STATE",
"[",
"device_mode",
"]",
"fan_mode",
"=",
"status",
"[",
"\"wind_status\"",
"]",
"self",
".",
"_fan_mode",
"=",
"AC_TO_HA_FAN_MODES",
"[",
"fan_mode",
"]",
"swing_mode",
"=",
"f'{status[\"up_down\"]}{status[\"left_right\"]}'",
"self",
".",
"_swing_mode",
"=",
"AC_TO_HA_SWING",
"[",
"swing_mode",
"]",
"if",
"self",
".",
"_hvac_mode",
"in",
"(",
"HVAC_MODE_COOL",
",",
"HVAC_MODE_HEAT",
")",
":",
"self",
".",
"_target_temperature",
"=",
"int",
"(",
"status",
"[",
"\"indoor_temperature_setting\"",
"]",
",",
"2",
")",
"else",
":",
"self",
".",
"_target_temperature",
"=",
"None",
"if",
"status",
"[",
"\"efficient\"",
"]",
"==",
"\"1\"",
":",
"self",
".",
"_preset_mode",
"=",
"PRESET_BOOST",
"elif",
"status",
"[",
"\"low_electricity\"",
"]",
"==",
"\"1\"",
":",
"self",
".",
"_preset_mode",
"=",
"PRESET_ECO",
"elif",
"status",
"[",
"\"sleep_status\"",
"]",
"==",
"\"0000001\"",
":",
"self",
".",
"_preset_mode",
"=",
"PRESET_SLEEP",
"elif",
"status",
"[",
"\"sleep_status\"",
"]",
"==",
"\"0000010\"",
":",
"self",
".",
"_preset_mode",
"=",
"\"sleep_2\"",
"elif",
"status",
"[",
"\"sleep_status\"",
"]",
"==",
"\"0000011\"",
":",
"self",
".",
"_preset_mode",
"=",
"\"sleep_3\"",
"elif",
"status",
"[",
"\"sleep_status\"",
"]",
"==",
"\"0000100\"",
":",
"self",
".",
"_preset_mode",
"=",
"\"sleep_4\"",
"else",
":",
"self",
".",
"_preset_mode",
"=",
"PRESET_NONE",
"else",
":",
"self",
".",
"_hvac_mode",
"=",
"HVAC_MODE_OFF",
"self",
".",
"_fan_mode",
"=",
"None",
"self",
".",
"_swing_mode",
"=",
"None",
"self",
".",
"_target_temperature",
"=",
"None",
"self",
".",
"_preset_mode",
"=",
"None"
] | [
168,
4
] | [
224,
36
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.available | (self) | Return True if entity is available. | Return True if entity is available. | def available(self):
"""Return True if entity is available."""
return self._available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"_available"
] | [
227,
4
] | [
229,
30
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.name | (self) | Return the name of the climate device. | Return the name of the climate device. | def name(self):
"""Return the name of the climate device."""
return self._unique_id | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unique_id"
] | [
232,
4
] | [
234,
30
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.temperature_unit | (self) | Return the unit of measurement. | Return the unit of measurement. | def temperature_unit(self):
"""Return the unit of measurement."""
return self._temperature_unit | [
"def",
"temperature_unit",
"(",
"self",
")",
":",
"return",
"self",
".",
"_temperature_unit"
] | [
237,
4
] | [
239,
37
] | python | en | ['en', 'la', 'en'] | True |
ClimateAehW4a1.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"
] | [
242,
4
] | [
244,
40
] | python | en | ['en', 'la', 'en'] | True |
ClimateAehW4a1.target_temperature | (self) | Return the temperature we are trying to reach. | Return the temperature we are trying to reach. | def target_temperature(self):
"""Return the temperature we are trying to reach."""
return self._target_temperature | [
"def",
"target_temperature",
"(",
"self",
")",
":",
"return",
"self",
".",
"_target_temperature"
] | [
247,
4
] | [
249,
39
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.hvac_mode | (self) | Return hvac target hvac state. | Return hvac target hvac state. | def hvac_mode(self):
"""Return hvac target hvac state."""
return self._hvac_mode | [
"def",
"hvac_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hvac_mode"
] | [
252,
4
] | [
254,
30
] | python | en | ['en', 'hi-Latn', 'ru'] | False |
ClimateAehW4a1.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 self._hvac_modes | [
"def",
"hvac_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_hvac_modes"
] | [
257,
4
] | [
259,
31
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.fan_mode | (self) | Return the fan setting. | Return the fan setting. | def fan_mode(self):
"""Return the fan setting."""
return self._fan_mode | [
"def",
"fan_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fan_mode"
] | [
262,
4
] | [
264,
29
] | python | en | ['en', 'fy', 'en'] | True |
ClimateAehW4a1.fan_modes | (self) | Return the list of available fan modes. | Return the list of available fan modes. | def fan_modes(self):
"""Return the list of available fan modes."""
return self._fan_modes | [
"def",
"fan_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fan_modes"
] | [
267,
4
] | [
269,
30
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.preset_mode | (self) | Return the preset mode if on. | Return the preset mode if on. | def preset_mode(self):
"""Return the preset mode if on."""
return self._preset_mode | [
"def",
"preset_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_preset_mode"
] | [
272,
4
] | [
274,
32
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.preset_modes | (self) | Return the list of available preset modes. | Return the list of available preset modes. | def preset_modes(self):
"""Return the list of available preset modes."""
return self._preset_modes | [
"def",
"preset_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_preset_modes"
] | [
277,
4
] | [
279,
33
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.swing_mode | (self) | Return swing operation. | Return swing operation. | def swing_mode(self):
"""Return swing operation."""
return self._swing_mode | [
"def",
"swing_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"_swing_mode"
] | [
282,
4
] | [
284,
31
] | python | en | ['en', 'ja', 'en'] | True |
ClimateAehW4a1.swing_modes | (self) | Return the list of available fan modes. | Return the list of available fan modes. | def swing_modes(self):
"""Return the list of available fan modes."""
return self._swing_modes | [
"def",
"swing_modes",
"(",
"self",
")",
":",
"return",
"self",
".",
"_swing_modes"
] | [
287,
4
] | [
289,
32
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.min_temp | (self) | Return the minimum temperature. | Return the minimum temperature. | def min_temp(self):
"""Return the minimum temperature."""
if self._temperature_unit == TEMP_CELSIUS:
return MIN_TEMP_C
return MIN_TEMP_F | [
"def",
"min_temp",
"(",
"self",
")",
":",
"if",
"self",
".",
"_temperature_unit",
"==",
"TEMP_CELSIUS",
":",
"return",
"MIN_TEMP_C",
"return",
"MIN_TEMP_F"
] | [
292,
4
] | [
296,
25
] | python | en | ['en', 'la', 'en'] | True |
ClimateAehW4a1.max_temp | (self) | Return the maximum temperature. | Return the maximum temperature. | def max_temp(self):
"""Return the maximum temperature."""
if self._temperature_unit == TEMP_CELSIUS:
return MAX_TEMP_C
return MAX_TEMP_F | [
"def",
"max_temp",
"(",
"self",
")",
":",
"if",
"self",
".",
"_temperature_unit",
"==",
"TEMP_CELSIUS",
":",
"return",
"MAX_TEMP_C",
"return",
"MAX_TEMP_F"
] | [
299,
4
] | [
303,
25
] | python | en | ['en', 'la', 'en'] | True |
ClimateAehW4a1.precision | (self) | Return the precision of the system. | Return the precision of the system. | def precision(self):
"""Return the precision of the system."""
return PRECISION_WHOLE | [
"def",
"precision",
"(",
"self",
")",
":",
"return",
"PRECISION_WHOLE"
] | [
306,
4
] | [
308,
30
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.target_temperature_step | (self) | Return the supported step of target temperature. | Return the supported step of target temperature. | def target_temperature_step(self):
"""Return the supported step of target temperature."""
return 1 | [
"def",
"target_temperature_step",
"(",
"self",
")",
":",
"return",
"1"
] | [
311,
4
] | [
313,
16
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.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"
] | [
316,
4
] | [
318,
28
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.async_set_temperature | (self, **kwargs) | Set new target temperatures. | Set new target temperatures. | async def async_set_temperature(self, **kwargs):
"""Set new target temperatures."""
if self._on != "1":
_LOGGER.warning(
"AC at %s is off, could not set temperature", self._unique_id
)
return
temp = kwargs.get(ATTR_TEMPERATURE)
if temp is not None:
_LOGGER.debug("Setting temp of %s to %s", self._unique_id, temp)
if self._preset_mode != PRESET_NONE:
await self.async_set_preset_mode(PRESET_NONE)
if self._temperature_unit == TEMP_CELSIUS:
await self._device.command(f"temp_{int(temp)}_C")
else:
await self._device.command(f"temp_{int(temp)}_F") | [
"async",
"def",
"async_set_temperature",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"self",
".",
"_on",
"!=",
"\"1\"",
":",
"_LOGGER",
".",
"warning",
"(",
"\"AC at %s is off, could not set temperature\"",
",",
"self",
".",
"_unique_id",
")",
"return",
"temp",
"=",
"kwargs",
".",
"get",
"(",
"ATTR_TEMPERATURE",
")",
"if",
"temp",
"is",
"not",
"None",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting temp of %s to %s\"",
",",
"self",
".",
"_unique_id",
",",
"temp",
")",
"if",
"self",
".",
"_preset_mode",
"!=",
"PRESET_NONE",
":",
"await",
"self",
".",
"async_set_preset_mode",
"(",
"PRESET_NONE",
")",
"if",
"self",
".",
"_temperature_unit",
"==",
"TEMP_CELSIUS",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"f\"temp_{int(temp)}_C\"",
")",
"else",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"f\"temp_{int(temp)}_F\"",
")"
] | [
320,
4
] | [
335,
65
] | python | en | ['en', 'ca', 'en'] | True |
ClimateAehW4a1.async_set_fan_mode | (self, fan_mode) | Set new fan mode. | Set new fan mode. | async def async_set_fan_mode(self, fan_mode):
"""Set new fan mode."""
if self._on != "1":
_LOGGER.warning("AC at %s is off, could not set fan mode", self._unique_id)
return
if self._hvac_mode in (HVAC_MODE_COOL, HVAC_MODE_FAN_ONLY) and (
self._hvac_mode != HVAC_MODE_FAN_ONLY or fan_mode != FAN_AUTO
):
_LOGGER.debug("Setting fan mode of %s to %s", self._unique_id, fan_mode)
await self._device.command(HA_FAN_MODES_TO_AC[fan_mode]) | [
"async",
"def",
"async_set_fan_mode",
"(",
"self",
",",
"fan_mode",
")",
":",
"if",
"self",
".",
"_on",
"!=",
"\"1\"",
":",
"_LOGGER",
".",
"warning",
"(",
"\"AC at %s is off, could not set fan mode\"",
",",
"self",
".",
"_unique_id",
")",
"return",
"if",
"self",
".",
"_hvac_mode",
"in",
"(",
"HVAC_MODE_COOL",
",",
"HVAC_MODE_FAN_ONLY",
")",
"and",
"(",
"self",
".",
"_hvac_mode",
"!=",
"HVAC_MODE_FAN_ONLY",
"or",
"fan_mode",
"!=",
"FAN_AUTO",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting fan mode of %s to %s\"",
",",
"self",
".",
"_unique_id",
",",
"fan_mode",
")",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"HA_FAN_MODES_TO_AC",
"[",
"fan_mode",
"]",
")"
] | [
337,
4
] | [
346,
68
] | python | en | ['id', 'fy', 'en'] | False |
ClimateAehW4a1.async_set_swing_mode | (self, swing_mode) | Set new target swing operation. | Set new target swing operation. | async def async_set_swing_mode(self, swing_mode):
"""Set new target swing operation."""
if self._on != "1":
_LOGGER.warning(
"AC at %s is off, could not set swing mode", self._unique_id
)
return
_LOGGER.debug("Setting swing mode of %s to %s", self._unique_id, swing_mode)
swing_act = self._swing_mode
if swing_mode == SWING_OFF and swing_act != SWING_OFF:
if swing_act in (SWING_HORIZONTAL, SWING_BOTH):
await self._device.command("hor_dir")
if swing_act in (SWING_VERTICAL, SWING_BOTH):
await self._device.command("vert_dir")
if swing_mode == SWING_BOTH and swing_act != SWING_BOTH:
if swing_act in (SWING_OFF, SWING_HORIZONTAL):
await self._device.command("vert_swing")
if swing_act in (SWING_OFF, SWING_VERTICAL):
await self._device.command("hor_swing")
if swing_mode == SWING_VERTICAL and swing_act != SWING_VERTICAL:
if swing_act in (SWING_OFF, SWING_HORIZONTAL):
await self._device.command("vert_swing")
if swing_act in (SWING_BOTH, SWING_HORIZONTAL):
await self._device.command("hor_dir")
if swing_mode == SWING_HORIZONTAL and swing_act != SWING_HORIZONTAL:
if swing_act in (SWING_BOTH, SWING_VERTICAL):
await self._device.command("vert_dir")
if swing_act in (SWING_OFF, SWING_VERTICAL):
await self._device.command("hor_swing") | [
"async",
"def",
"async_set_swing_mode",
"(",
"self",
",",
"swing_mode",
")",
":",
"if",
"self",
".",
"_on",
"!=",
"\"1\"",
":",
"_LOGGER",
".",
"warning",
"(",
"\"AC at %s is off, could not set swing mode\"",
",",
"self",
".",
"_unique_id",
")",
"return",
"_LOGGER",
".",
"debug",
"(",
"\"Setting swing mode of %s to %s\"",
",",
"self",
".",
"_unique_id",
",",
"swing_mode",
")",
"swing_act",
"=",
"self",
".",
"_swing_mode",
"if",
"swing_mode",
"==",
"SWING_OFF",
"and",
"swing_act",
"!=",
"SWING_OFF",
":",
"if",
"swing_act",
"in",
"(",
"SWING_HORIZONTAL",
",",
"SWING_BOTH",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"hor_dir\"",
")",
"if",
"swing_act",
"in",
"(",
"SWING_VERTICAL",
",",
"SWING_BOTH",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"vert_dir\"",
")",
"if",
"swing_mode",
"==",
"SWING_BOTH",
"and",
"swing_act",
"!=",
"SWING_BOTH",
":",
"if",
"swing_act",
"in",
"(",
"SWING_OFF",
",",
"SWING_HORIZONTAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"vert_swing\"",
")",
"if",
"swing_act",
"in",
"(",
"SWING_OFF",
",",
"SWING_VERTICAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"hor_swing\"",
")",
"if",
"swing_mode",
"==",
"SWING_VERTICAL",
"and",
"swing_act",
"!=",
"SWING_VERTICAL",
":",
"if",
"swing_act",
"in",
"(",
"SWING_OFF",
",",
"SWING_HORIZONTAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"vert_swing\"",
")",
"if",
"swing_act",
"in",
"(",
"SWING_BOTH",
",",
"SWING_HORIZONTAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"hor_dir\"",
")",
"if",
"swing_mode",
"==",
"SWING_HORIZONTAL",
"and",
"swing_act",
"!=",
"SWING_HORIZONTAL",
":",
"if",
"swing_act",
"in",
"(",
"SWING_BOTH",
",",
"SWING_VERTICAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"vert_dir\"",
")",
"if",
"swing_act",
"in",
"(",
"SWING_OFF",
",",
"SWING_VERTICAL",
")",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"hor_swing\"",
")"
] | [
348,
4
] | [
381,
55
] | python | en | ['en', 'en', 'en'] | True |
ClimateAehW4a1.async_set_preset_mode | (self, preset_mode) | Set new preset mode. | Set new preset mode. | async def async_set_preset_mode(self, preset_mode):
"""Set new preset mode."""
if self._on != "1":
if preset_mode == PRESET_NONE:
return
await self.async_turn_on()
_LOGGER.debug("Setting preset mode of %s to %s", self._unique_id, preset_mode)
if preset_mode == PRESET_ECO:
await self._device.command("energysave_on")
self._previous_state = preset_mode
elif preset_mode == PRESET_BOOST:
await self._device.command("turbo_on")
self._previous_state = preset_mode
elif preset_mode == PRESET_SLEEP:
await self._device.command("sleep_1")
self._previous_state = self._hvac_mode
elif preset_mode == "sleep_2":
await self._device.command("sleep_2")
self._previous_state = self._hvac_mode
elif preset_mode == "sleep_3":
await self._device.command("sleep_3")
self._previous_state = self._hvac_mode
elif preset_mode == "sleep_4":
await self._device.command("sleep_4")
self._previous_state = self._hvac_mode
elif self._previous_state is not None:
if self._previous_state == PRESET_ECO:
await self._device.command("energysave_off")
elif self._previous_state == PRESET_BOOST:
await self._device.command("turbo_off")
elif self._previous_state in HA_STATE_TO_AC:
await self._device.command(HA_STATE_TO_AC[self._previous_state])
self._previous_state = None | [
"async",
"def",
"async_set_preset_mode",
"(",
"self",
",",
"preset_mode",
")",
":",
"if",
"self",
".",
"_on",
"!=",
"\"1\"",
":",
"if",
"preset_mode",
"==",
"PRESET_NONE",
":",
"return",
"await",
"self",
".",
"async_turn_on",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"\"Setting preset mode of %s to %s\"",
",",
"self",
".",
"_unique_id",
",",
"preset_mode",
")",
"if",
"preset_mode",
"==",
"PRESET_ECO",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"energysave_on\"",
")",
"self",
".",
"_previous_state",
"=",
"preset_mode",
"elif",
"preset_mode",
"==",
"PRESET_BOOST",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"turbo_on\"",
")",
"self",
".",
"_previous_state",
"=",
"preset_mode",
"elif",
"preset_mode",
"==",
"PRESET_SLEEP",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"sleep_1\"",
")",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_hvac_mode",
"elif",
"preset_mode",
"==",
"\"sleep_2\"",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"sleep_2\"",
")",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_hvac_mode",
"elif",
"preset_mode",
"==",
"\"sleep_3\"",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"sleep_3\"",
")",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_hvac_mode",
"elif",
"preset_mode",
"==",
"\"sleep_4\"",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"sleep_4\"",
")",
"self",
".",
"_previous_state",
"=",
"self",
".",
"_hvac_mode",
"elif",
"self",
".",
"_previous_state",
"is",
"not",
"None",
":",
"if",
"self",
".",
"_previous_state",
"==",
"PRESET_ECO",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"energysave_off\"",
")",
"elif",
"self",
".",
"_previous_state",
"==",
"PRESET_BOOST",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"\"turbo_off\"",
")",
"elif",
"self",
".",
"_previous_state",
"in",
"HA_STATE_TO_AC",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"HA_STATE_TO_AC",
"[",
"self",
".",
"_previous_state",
"]",
")",
"self",
".",
"_previous_state",
"=",
"None"
] | [
383,
4
] | [
417,
39
] | python | en | ['en', 'sr', 'en'] | True |
ClimateAehW4a1.async_set_hvac_mode | (self, hvac_mode) | Set new operation mode. | Set new operation mode. | async def async_set_hvac_mode(self, hvac_mode):
"""Set new operation mode."""
_LOGGER.debug("Setting operation mode of %s to %s", self._unique_id, hvac_mode)
if hvac_mode == HVAC_MODE_OFF:
await self.async_turn_off()
else:
await self._device.command(HA_STATE_TO_AC[hvac_mode])
if self._on != "1":
await self.async_turn_on() | [
"async",
"def",
"async_set_hvac_mode",
"(",
"self",
",",
"hvac_mode",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Setting operation mode of %s to %s\"",
",",
"self",
".",
"_unique_id",
",",
"hvac_mode",
")",
"if",
"hvac_mode",
"==",
"HVAC_MODE_OFF",
":",
"await",
"self",
".",
"async_turn_off",
"(",
")",
"else",
":",
"await",
"self",
".",
"_device",
".",
"command",
"(",
"HA_STATE_TO_AC",
"[",
"hvac_mode",
"]",
")",
"if",
"self",
".",
"_on",
"!=",
"\"1\"",
":",
"await",
"self",
".",
"async_turn_on",
"(",
")"
] | [
419,
4
] | [
427,
42
] | python | en | ['en', 'ny', 'en'] | True |
setup_request_context | (app, context) | Create request context middleware for the app. | Create request context middleware for the app. | def setup_request_context(app, context):
"""Create request context middleware for the app."""
@middleware
async def request_context_middleware(request, handler):
"""Request context middleware."""
context.set(request)
return await handler(request)
app.middlewares.append(request_context_middleware) | [
"def",
"setup_request_context",
"(",
"app",
",",
"context",
")",
":",
"@",
"middleware",
"async",
"def",
"request_context_middleware",
"(",
"request",
",",
"handler",
")",
":",
"\"\"\"Request context middleware.\"\"\"",
"context",
".",
"set",
"(",
"request",
")",
"return",
"await",
"handler",
"(",
"request",
")",
"app",
".",
"middlewares",
".",
"append",
"(",
"request_context_middleware",
")"
] | [
10,
0
] | [
19,
54
] | python | en | ['en', 'en', 'en'] | True |
hass_recorder | () | Home Assistant fixture with in-memory recorder. | Home Assistant fixture with in-memory recorder. | def hass_recorder():
"""Home Assistant fixture with in-memory recorder."""
hass = get_test_home_assistant()
def setup_recorder(config=None):
"""Set up with params."""
init_recorder_component(hass, config)
hass.start()
hass.block_till_done()
hass.data[DATA_INSTANCE].block_till_done()
return hass
yield setup_recorder
hass.stop() | [
"def",
"hass_recorder",
"(",
")",
":",
"hass",
"=",
"get_test_home_assistant",
"(",
")",
"def",
"setup_recorder",
"(",
"config",
"=",
"None",
")",
":",
"\"\"\"Set up with params.\"\"\"",
"init_recorder_component",
"(",
"hass",
",",
"config",
")",
"hass",
".",
"start",
"(",
")",
"hass",
".",
"block_till_done",
"(",
")",
"hass",
".",
"data",
"[",
"DATA_INSTANCE",
"]",
".",
"block_till_done",
"(",
")",
"return",
"hass",
"yield",
"setup_recorder",
"hass",
".",
"stop",
"(",
")"
] | [
18,
0
] | [
31,
15
] | python | en | ['en', 'en', 'en'] | True |
test_recorder_bad_commit | (hass_recorder) | Bad _commit should retry 3 times. | Bad _commit should retry 3 times. | def test_recorder_bad_commit(hass_recorder):
"""Bad _commit should retry 3 times."""
hass = hass_recorder()
def work(session):
"""Bad work."""
session.execute("select * from notthere")
with patch(
"homeassistant.components.recorder.time.sleep"
) as e_mock, util.session_scope(hass=hass) as session:
res = util.commit(session, work)
assert res is False
assert e_mock.call_count == 3 | [
"def",
"test_recorder_bad_commit",
"(",
"hass_recorder",
")",
":",
"hass",
"=",
"hass_recorder",
"(",
")",
"def",
"work",
"(",
"session",
")",
":",
"\"\"\"Bad work.\"\"\"",
"session",
".",
"execute",
"(",
"\"select * from notthere\"",
")",
"with",
"patch",
"(",
"\"homeassistant.components.recorder.time.sleep\"",
")",
"as",
"e_mock",
",",
"util",
".",
"session_scope",
"(",
"hass",
"=",
"hass",
")",
"as",
"session",
":",
"res",
"=",
"util",
".",
"commit",
"(",
"session",
",",
"work",
")",
"assert",
"res",
"is",
"False",
"assert",
"e_mock",
".",
"call_count",
"==",
"3"
] | [
34,
0
] | [
47,
33
] | python | en | ['en', 'en', 'en'] | True |
test_recorder_bad_execute | (hass_recorder) | Bad execute, retry 3 times. | Bad execute, retry 3 times. | def test_recorder_bad_execute(hass_recorder):
"""Bad execute, retry 3 times."""
from sqlalchemy.exc import SQLAlchemyError
hass_recorder()
def to_native(validate_entity_id=True):
"""Raise exception."""
raise SQLAlchemyError()
mck1 = MagicMock()
mck1.to_native = to_native
with pytest.raises(SQLAlchemyError), patch(
"homeassistant.components.recorder.time.sleep"
) as e_mock:
util.execute((mck1,), to_native=True)
assert e_mock.call_count == 2 | [
"def",
"test_recorder_bad_execute",
"(",
"hass_recorder",
")",
":",
"from",
"sqlalchemy",
".",
"exc",
"import",
"SQLAlchemyError",
"hass_recorder",
"(",
")",
"def",
"to_native",
"(",
"validate_entity_id",
"=",
"True",
")",
":",
"\"\"\"Raise exception.\"\"\"",
"raise",
"SQLAlchemyError",
"(",
")",
"mck1",
"=",
"MagicMock",
"(",
")",
"mck1",
".",
"to_native",
"=",
"to_native",
"with",
"pytest",
".",
"raises",
"(",
"SQLAlchemyError",
")",
",",
"patch",
"(",
"\"homeassistant.components.recorder.time.sleep\"",
")",
"as",
"e_mock",
":",
"util",
".",
"execute",
"(",
"(",
"mck1",
",",
")",
",",
"to_native",
"=",
"True",
")",
"assert",
"e_mock",
".",
"call_count",
"==",
"2"
] | [
50,
0
] | [
68,
33
] | python | en | ['en', 'en', 'en'] | True |
test_validate_or_move_away_sqlite_database_with_integrity_check | (
hass, tmpdir, caplog
) | Ensure a malformed sqlite database is moved away.
A quick_check is run here
| Ensure a malformed sqlite database is moved away. | def test_validate_or_move_away_sqlite_database_with_integrity_check(
hass, tmpdir, caplog
):
"""Ensure a malformed sqlite database is moved away.
A quick_check is run here
"""
db_integrity_check = True
test_dir = tmpdir.mkdir("test_validate_or_move_away_sqlite_database")
test_db_file = f"{test_dir}/broken.db"
dburl = f"{SQLITE_URL_PREFIX}{test_db_file}"
util.validate_sqlite_database(test_db_file, db_integrity_check) is True
assert os.path.exists(test_db_file) is True
assert (
util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is False
)
_corrupt_db_file(test_db_file)
assert util.validate_sqlite_database(dburl, db_integrity_check) is False
assert (
util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is False
)
assert "corrupt or malformed" in caplog.text
assert util.validate_sqlite_database(dburl, db_integrity_check) is False
assert util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is True | [
"def",
"test_validate_or_move_away_sqlite_database_with_integrity_check",
"(",
"hass",
",",
"tmpdir",
",",
"caplog",
")",
":",
"db_integrity_check",
"=",
"True",
"test_dir",
"=",
"tmpdir",
".",
"mkdir",
"(",
"\"test_validate_or_move_away_sqlite_database\"",
")",
"test_db_file",
"=",
"f\"{test_dir}/broken.db\"",
"dburl",
"=",
"f\"{SQLITE_URL_PREFIX}{test_db_file}\"",
"util",
".",
"validate_sqlite_database",
"(",
"test_db_file",
",",
"db_integrity_check",
")",
"is",
"True",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"test_db_file",
")",
"is",
"True",
"assert",
"(",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
")",
"_corrupt_db_file",
"(",
"test_db_file",
")",
"assert",
"util",
".",
"validate_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
"assert",
"(",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
")",
"assert",
"\"corrupt or malformed\"",
"in",
"caplog",
".",
"text",
"assert",
"util",
".",
"validate_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
"assert",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"True"
] | [
71,
0
] | [
104,
88
] | python | en | ['en', 'en', 'en'] | True |
test_validate_or_move_away_sqlite_database_without_integrity_check | (
hass, tmpdir, caplog
) | Ensure a malformed sqlite database is moved away.
The quick_check is skipped, but we can still find
corruption if the whole database is unreadable
| Ensure a malformed sqlite database is moved away. | def test_validate_or_move_away_sqlite_database_without_integrity_check(
hass, tmpdir, caplog
):
"""Ensure a malformed sqlite database is moved away.
The quick_check is skipped, but we can still find
corruption if the whole database is unreadable
"""
db_integrity_check = False
test_dir = tmpdir.mkdir("test_validate_or_move_away_sqlite_database")
test_db_file = f"{test_dir}/broken.db"
dburl = f"{SQLITE_URL_PREFIX}{test_db_file}"
util.validate_sqlite_database(test_db_file, db_integrity_check) is True
assert os.path.exists(test_db_file) is True
assert (
util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is False
)
_corrupt_db_file(test_db_file)
assert util.validate_sqlite_database(dburl, db_integrity_check) is False
assert (
util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is False
)
assert "corrupt or malformed" in caplog.text
assert util.validate_sqlite_database(dburl, db_integrity_check) is False
assert util.validate_or_move_away_sqlite_database(dburl, db_integrity_check) is True | [
"def",
"test_validate_or_move_away_sqlite_database_without_integrity_check",
"(",
"hass",
",",
"tmpdir",
",",
"caplog",
")",
":",
"db_integrity_check",
"=",
"False",
"test_dir",
"=",
"tmpdir",
".",
"mkdir",
"(",
"\"test_validate_or_move_away_sqlite_database\"",
")",
"test_db_file",
"=",
"f\"{test_dir}/broken.db\"",
"dburl",
"=",
"f\"{SQLITE_URL_PREFIX}{test_db_file}\"",
"util",
".",
"validate_sqlite_database",
"(",
"test_db_file",
",",
"db_integrity_check",
")",
"is",
"True",
"assert",
"os",
".",
"path",
".",
"exists",
"(",
"test_db_file",
")",
"is",
"True",
"assert",
"(",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
")",
"_corrupt_db_file",
"(",
"test_db_file",
")",
"assert",
"util",
".",
"validate_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
"assert",
"(",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
")",
"assert",
"\"corrupt or malformed\"",
"in",
"caplog",
".",
"text",
"assert",
"util",
".",
"validate_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"False",
"assert",
"util",
".",
"validate_or_move_away_sqlite_database",
"(",
"dburl",
",",
"db_integrity_check",
")",
"is",
"True"
] | [
107,
0
] | [
141,
88
] | python | en | ['en', 'en', 'en'] | True |
test_last_run_was_recently_clean | (hass_recorder) | Test we can check if the last recorder run was recently clean. | Test we can check if the last recorder run was recently clean. | def test_last_run_was_recently_clean(hass_recorder):
"""Test we can check if the last recorder run was recently clean."""
hass = hass_recorder()
cursor = hass.data[DATA_INSTANCE].engine.raw_connection().cursor()
assert util.last_run_was_recently_clean(cursor) is False
hass.data[DATA_INSTANCE]._close_run()
wait_recording_done(hass)
assert util.last_run_was_recently_clean(cursor) is True
thirty_min_future_time = dt_util.utcnow() + timedelta(minutes=30)
with patch(
"homeassistant.components.recorder.dt_util.utcnow",
return_value=thirty_min_future_time,
):
assert util.last_run_was_recently_clean(cursor) is False | [
"def",
"test_last_run_was_recently_clean",
"(",
"hass_recorder",
")",
":",
"hass",
"=",
"hass_recorder",
"(",
")",
"cursor",
"=",
"hass",
".",
"data",
"[",
"DATA_INSTANCE",
"]",
".",
"engine",
".",
"raw_connection",
"(",
")",
".",
"cursor",
"(",
")",
"assert",
"util",
".",
"last_run_was_recently_clean",
"(",
"cursor",
")",
"is",
"False",
"hass",
".",
"data",
"[",
"DATA_INSTANCE",
"]",
".",
"_close_run",
"(",
")",
"wait_recording_done",
"(",
"hass",
")",
"assert",
"util",
".",
"last_run_was_recently_clean",
"(",
"cursor",
")",
"is",
"True",
"thirty_min_future_time",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"minutes",
"=",
"30",
")",
"with",
"patch",
"(",
"\"homeassistant.components.recorder.dt_util.utcnow\"",
",",
"return_value",
"=",
"thirty_min_future_time",
",",
")",
":",
"assert",
"util",
".",
"last_run_was_recently_clean",
"(",
"cursor",
")",
"is",
"False"
] | [
144,
0
] | [
163,
64
] | python | en | ['en', 'en', 'en'] | True |
test_basic_sanity_check | (hass_recorder) | Test the basic sanity checks with a missing table. | Test the basic sanity checks with a missing table. | def test_basic_sanity_check(hass_recorder):
"""Test the basic sanity checks with a missing table."""
hass = hass_recorder()
cursor = hass.data[DATA_INSTANCE].engine.raw_connection().cursor()
assert util.basic_sanity_check(cursor) is True
cursor.execute("DROP TABLE states;")
with pytest.raises(sqlite3.DatabaseError):
util.basic_sanity_check(cursor) | [
"def",
"test_basic_sanity_check",
"(",
"hass_recorder",
")",
":",
"hass",
"=",
"hass_recorder",
"(",
")",
"cursor",
"=",
"hass",
".",
"data",
"[",
"DATA_INSTANCE",
"]",
".",
"engine",
".",
"raw_connection",
"(",
")",
".",
"cursor",
"(",
")",
"assert",
"util",
".",
"basic_sanity_check",
"(",
"cursor",
")",
"is",
"True",
"cursor",
".",
"execute",
"(",
"\"DROP TABLE states;\"",
")",
"with",
"pytest",
".",
"raises",
"(",
"sqlite3",
".",
"DatabaseError",
")",
":",
"util",
".",
"basic_sanity_check",
"(",
"cursor",
")"
] | [
166,
0
] | [
177,
39
] | python | en | ['en', 'en', 'en'] | True |
test_combined_checks | (hass_recorder) | Run Checks on the open database. | Run Checks on the open database. | def test_combined_checks(hass_recorder):
"""Run Checks on the open database."""
hass = hass_recorder()
db_integrity_check = False
cursor = hass.data[DATA_INSTANCE].engine.raw_connection().cursor()
assert (
util.run_checks_on_open_db("fake_db_path", cursor, db_integrity_check) is None
)
# We are patching recorder.util here in order
# to avoid creating the full database on disk
with patch("homeassistant.components.recorder.util.last_run_was_recently_clean"):
assert (
util.run_checks_on_open_db("fake_db_path", cursor, db_integrity_check)
is None
)
with patch(
"homeassistant.components.recorder.util.last_run_was_recently_clean",
side_effect=sqlite3.DatabaseError,
), pytest.raises(sqlite3.DatabaseError):
util.run_checks_on_open_db("fake_db_path", cursor, db_integrity_check)
cursor.execute("DROP TABLE events;")
with pytest.raises(sqlite3.DatabaseError):
util.run_checks_on_open_db("fake_db_path", cursor, db_integrity_check) | [
"def",
"test_combined_checks",
"(",
"hass_recorder",
")",
":",
"hass",
"=",
"hass_recorder",
"(",
")",
"db_integrity_check",
"=",
"False",
"cursor",
"=",
"hass",
".",
"data",
"[",
"DATA_INSTANCE",
"]",
".",
"engine",
".",
"raw_connection",
"(",
")",
".",
"cursor",
"(",
")",
"assert",
"(",
"util",
".",
"run_checks_on_open_db",
"(",
"\"fake_db_path\"",
",",
"cursor",
",",
"db_integrity_check",
")",
"is",
"None",
")",
"# We are patching recorder.util here in order",
"# to avoid creating the full database on disk",
"with",
"patch",
"(",
"\"homeassistant.components.recorder.util.last_run_was_recently_clean\"",
")",
":",
"assert",
"(",
"util",
".",
"run_checks_on_open_db",
"(",
"\"fake_db_path\"",
",",
"cursor",
",",
"db_integrity_check",
")",
"is",
"None",
")",
"with",
"patch",
"(",
"\"homeassistant.components.recorder.util.last_run_was_recently_clean\"",
",",
"side_effect",
"=",
"sqlite3",
".",
"DatabaseError",
",",
")",
",",
"pytest",
".",
"raises",
"(",
"sqlite3",
".",
"DatabaseError",
")",
":",
"util",
".",
"run_checks_on_open_db",
"(",
"\"fake_db_path\"",
",",
"cursor",
",",
"db_integrity_check",
")",
"cursor",
".",
"execute",
"(",
"\"DROP TABLE events;\"",
")",
"with",
"pytest",
".",
"raises",
"(",
"sqlite3",
".",
"DatabaseError",
")",
":",
"util",
".",
"run_checks_on_open_db",
"(",
"\"fake_db_path\"",
",",
"cursor",
",",
"db_integrity_check",
")"
] | [
180,
0
] | [
209,
78
] | python | en | ['en', 'no', 'en'] | True |
_corrupt_db_file | (test_db_file) | Corrupt an sqlite3 database file. | Corrupt an sqlite3 database file. | def _corrupt_db_file(test_db_file):
"""Corrupt an sqlite3 database file."""
f = open(test_db_file, "a")
f.write("I am a corrupt db")
f.close() | [
"def",
"_corrupt_db_file",
"(",
"test_db_file",
")",
":",
"f",
"=",
"open",
"(",
"test_db_file",
",",
"\"a\"",
")",
"f",
".",
"write",
"(",
"\"I am a corrupt db\"",
")",
"f",
".",
"close",
"(",
")"
] | [
212,
0
] | [
216,
13
] | python | da | ['en', 'da', 'it'] | False |
_validate_edit_permission | (
hass: HomeAssistantType, context: ContextType, entity_id: str
) | Use for validating user control permissions. | Use for validating user control permissions. | async def _validate_edit_permission(
hass: HomeAssistantType, context: ContextType, entity_id: str
) -> None:
"""Use for validating user control permissions."""
splited = split_entity_id(entity_id)
if splited[0] != SWITCH_DOMAIN or not splited[1].startswith(DOMAIN):
raise Unauthorized(context=context, entity_id=entity_id, permission=POLICY_EDIT)
user = await hass.auth.async_get_user(context.user_id)
if user is None:
raise UnknownUser(context=context, entity_id=entity_id, permission=POLICY_EDIT)
if not user.permissions.check_entity(entity_id, POLICY_EDIT):
raise Unauthorized(context=context, entity_id=entity_id, permission=POLICY_EDIT) | [
"async",
"def",
"_validate_edit_permission",
"(",
"hass",
":",
"HomeAssistantType",
",",
"context",
":",
"ContextType",
",",
"entity_id",
":",
"str",
")",
"->",
"None",
":",
"splited",
"=",
"split_entity_id",
"(",
"entity_id",
")",
"if",
"splited",
"[",
"0",
"]",
"!=",
"SWITCH_DOMAIN",
"or",
"not",
"splited",
"[",
"1",
"]",
".",
"startswith",
"(",
"DOMAIN",
")",
":",
"raise",
"Unauthorized",
"(",
"context",
"=",
"context",
",",
"entity_id",
"=",
"entity_id",
",",
"permission",
"=",
"POLICY_EDIT",
")",
"user",
"=",
"await",
"hass",
".",
"auth",
".",
"async_get_user",
"(",
"context",
".",
"user_id",
")",
"if",
"user",
"is",
"None",
":",
"raise",
"UnknownUser",
"(",
"context",
"=",
"context",
",",
"entity_id",
"=",
"entity_id",
",",
"permission",
"=",
"POLICY_EDIT",
")",
"if",
"not",
"user",
".",
"permissions",
".",
"check_entity",
"(",
"entity_id",
",",
"POLICY_EDIT",
")",
":",
"raise",
"Unauthorized",
"(",
"context",
"=",
"context",
",",
"entity_id",
"=",
"entity_id",
",",
"permission",
"=",
"POLICY_EDIT",
")"
] | [
80,
0
] | [
91,
88
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass: HomeAssistantType, config: Dict) | Set up the switcher component. | Set up the switcher component. | async def async_setup(hass: HomeAssistantType, config: Dict) -> bool:
"""Set up the switcher component."""
phone_id = config[DOMAIN][CONF_PHONE_ID]
device_id = config[DOMAIN][CONF_DEVICE_ID]
device_password = config[DOMAIN][CONF_DEVICE_PASSWORD]
v2bridge = SwitcherV2Bridge(hass.loop, phone_id, device_id, device_password)
await v2bridge.start()
async def async_stop_bridge(event: EventType) -> None:
"""On Home Assistant stop, gracefully stop the bridge if running."""
await v2bridge.stop()
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, async_stop_bridge)
try:
device_data = await wait_for(v2bridge.queue.get(), timeout=10.0)
except (Asyncio_TimeoutError, RuntimeError):
_LOGGER.exception("Failed to get response from device")
await v2bridge.stop()
return False
hass.data[DOMAIN] = {DATA_DEVICE: device_data}
async def async_switch_platform_discovered(
platform: str, discovery_info: DiscoveryInfoType
) -> None:
"""Use for registering services after switch platform is discovered."""
if platform != DOMAIN:
return
async def async_set_auto_off_service(service: ServiceCallType) -> None:
"""Use for handling setting device auto-off service calls."""
await _validate_edit_permission(
hass, service.context, service.data[ATTR_ENTITY_ID]
)
async with SwitcherV2Api(
hass.loop, device_data.ip_addr, phone_id, device_id, device_password
) as swapi:
await swapi.set_auto_shutdown(service.data[CONF_AUTO_OFF])
async def async_turn_on_with_timer_service(service: ServiceCallType) -> None:
"""Use for handling turning device on with a timer service calls."""
await _validate_edit_permission(
hass, service.context, service.data[ATTR_ENTITY_ID]
)
async with SwitcherV2Api(
hass.loop, device_data.ip_addr, phone_id, device_id, device_password
) as swapi:
await swapi.control_device(COMMAND_ON, service.data[CONF_TIMER_MINUTES])
hass.services.async_register(
DOMAIN,
SERVICE_SET_AUTO_OFF_NAME,
async_set_auto_off_service,
schema=SERVICE_SET_AUTO_OFF_SCHEMA,
)
hass.services.async_register(
DOMAIN,
SERVICE_TURN_ON_WITH_TIMER_NAME,
async_turn_on_with_timer_service,
schema=SERVICE_TURN_ON_WITH_TIMER_SCHEMA,
)
async_listen_platform(hass, SWITCH_DOMAIN, async_switch_platform_discovered)
hass.async_create_task(async_load_platform(hass, SWITCH_DOMAIN, DOMAIN, {}, config))
@callback
def device_updates(timestamp: Optional[datetime]) -> None:
"""Use for updating the device data from the queue."""
if v2bridge.running:
try:
device_new_data = v2bridge.queue.get_nowait()
if device_new_data:
async_dispatcher_send(
hass, SIGNAL_SWITCHER_DEVICE_UPDATE, device_new_data
)
except QueueEmpty:
pass
async_track_time_interval(hass, device_updates, timedelta(seconds=4))
return True | [
"async",
"def",
"async_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"config",
":",
"Dict",
")",
"->",
"bool",
":",
"phone_id",
"=",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_PHONE_ID",
"]",
"device_id",
"=",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_DEVICE_ID",
"]",
"device_password",
"=",
"config",
"[",
"DOMAIN",
"]",
"[",
"CONF_DEVICE_PASSWORD",
"]",
"v2bridge",
"=",
"SwitcherV2Bridge",
"(",
"hass",
".",
"loop",
",",
"phone_id",
",",
"device_id",
",",
"device_password",
")",
"await",
"v2bridge",
".",
"start",
"(",
")",
"async",
"def",
"async_stop_bridge",
"(",
"event",
":",
"EventType",
")",
"->",
"None",
":",
"\"\"\"On Home Assistant stop, gracefully stop the bridge if running.\"\"\"",
"await",
"v2bridge",
".",
"stop",
"(",
")",
"hass",
".",
"bus",
".",
"async_listen_once",
"(",
"EVENT_HOMEASSISTANT_STOP",
",",
"async_stop_bridge",
")",
"try",
":",
"device_data",
"=",
"await",
"wait_for",
"(",
"v2bridge",
".",
"queue",
".",
"get",
"(",
")",
",",
"timeout",
"=",
"10.0",
")",
"except",
"(",
"Asyncio_TimeoutError",
",",
"RuntimeError",
")",
":",
"_LOGGER",
".",
"exception",
"(",
"\"Failed to get response from device\"",
")",
"await",
"v2bridge",
".",
"stop",
"(",
")",
"return",
"False",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"=",
"{",
"DATA_DEVICE",
":",
"device_data",
"}",
"async",
"def",
"async_switch_platform_discovered",
"(",
"platform",
":",
"str",
",",
"discovery_info",
":",
"DiscoveryInfoType",
")",
"->",
"None",
":",
"\"\"\"Use for registering services after switch platform is discovered.\"\"\"",
"if",
"platform",
"!=",
"DOMAIN",
":",
"return",
"async",
"def",
"async_set_auto_off_service",
"(",
"service",
":",
"ServiceCallType",
")",
"->",
"None",
":",
"\"\"\"Use for handling setting device auto-off service calls.\"\"\"",
"await",
"_validate_edit_permission",
"(",
"hass",
",",
"service",
".",
"context",
",",
"service",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
")",
"async",
"with",
"SwitcherV2Api",
"(",
"hass",
".",
"loop",
",",
"device_data",
".",
"ip_addr",
",",
"phone_id",
",",
"device_id",
",",
"device_password",
")",
"as",
"swapi",
":",
"await",
"swapi",
".",
"set_auto_shutdown",
"(",
"service",
".",
"data",
"[",
"CONF_AUTO_OFF",
"]",
")",
"async",
"def",
"async_turn_on_with_timer_service",
"(",
"service",
":",
"ServiceCallType",
")",
"->",
"None",
":",
"\"\"\"Use for handling turning device on with a timer service calls.\"\"\"",
"await",
"_validate_edit_permission",
"(",
"hass",
",",
"service",
".",
"context",
",",
"service",
".",
"data",
"[",
"ATTR_ENTITY_ID",
"]",
")",
"async",
"with",
"SwitcherV2Api",
"(",
"hass",
".",
"loop",
",",
"device_data",
".",
"ip_addr",
",",
"phone_id",
",",
"device_id",
",",
"device_password",
")",
"as",
"swapi",
":",
"await",
"swapi",
".",
"control_device",
"(",
"COMMAND_ON",
",",
"service",
".",
"data",
"[",
"CONF_TIMER_MINUTES",
"]",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"SERVICE_SET_AUTO_OFF_NAME",
",",
"async_set_auto_off_service",
",",
"schema",
"=",
"SERVICE_SET_AUTO_OFF_SCHEMA",
",",
")",
"hass",
".",
"services",
".",
"async_register",
"(",
"DOMAIN",
",",
"SERVICE_TURN_ON_WITH_TIMER_NAME",
",",
"async_turn_on_with_timer_service",
",",
"schema",
"=",
"SERVICE_TURN_ON_WITH_TIMER_SCHEMA",
",",
")",
"async_listen_platform",
"(",
"hass",
",",
"SWITCH_DOMAIN",
",",
"async_switch_platform_discovered",
")",
"hass",
".",
"async_create_task",
"(",
"async_load_platform",
"(",
"hass",
",",
"SWITCH_DOMAIN",
",",
"DOMAIN",
",",
"{",
"}",
",",
"config",
")",
")",
"@",
"callback",
"def",
"device_updates",
"(",
"timestamp",
":",
"Optional",
"[",
"datetime",
"]",
")",
"->",
"None",
":",
"\"\"\"Use for updating the device data from the queue.\"\"\"",
"if",
"v2bridge",
".",
"running",
":",
"try",
":",
"device_new_data",
"=",
"v2bridge",
".",
"queue",
".",
"get_nowait",
"(",
")",
"if",
"device_new_data",
":",
"async_dispatcher_send",
"(",
"hass",
",",
"SIGNAL_SWITCHER_DEVICE_UPDATE",
",",
"device_new_data",
")",
"except",
"QueueEmpty",
":",
"pass",
"async_track_time_interval",
"(",
"hass",
",",
"device_updates",
",",
"timedelta",
"(",
"seconds",
"=",
"4",
")",
")",
"return",
"True"
] | [
94,
0
] | [
183,
15
] | python | en | ['en', 'en', 'en'] | True |
async_setup_auth_view | (hass: HomeAssistantType, user: User) | Auth setup. | Auth setup. | def async_setup_auth_view(hass: HomeAssistantType, user: User):
"""Auth setup."""
hassio_auth = HassIOAuth(hass, user)
hassio_password_reset = HassIOPasswordReset(hass, user)
hass.http.register_view(hassio_auth)
hass.http.register_view(hassio_password_reset) | [
"def",
"async_setup_auth_view",
"(",
"hass",
":",
"HomeAssistantType",
",",
"user",
":",
"User",
")",
":",
"hassio_auth",
"=",
"HassIOAuth",
"(",
"hass",
",",
"user",
")",
"hassio_password_reset",
"=",
"HassIOPasswordReset",
"(",
"hass",
",",
"user",
")",
"hass",
".",
"http",
".",
"register_view",
"(",
"hassio_auth",
")",
"hass",
".",
"http",
".",
"register_view",
"(",
"hassio_password_reset",
")"
] | [
25,
0
] | [
31,
50
] | python | en | ['en', 'haw', 'en'] | False |
HassIOBaseAuth.__init__ | (self, hass: HomeAssistantType, user: User) | Initialize WebView. | Initialize WebView. | def __init__(self, hass: HomeAssistantType, user: User):
"""Initialize WebView."""
self.hass = hass
self.user = user | [
"def",
"__init__",
"(",
"self",
",",
"hass",
":",
"HomeAssistantType",
",",
"user",
":",
"User",
")",
":",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"user",
"=",
"user"
] | [
37,
4
] | [
40,
24
] | python | en | ['en', 'en', 'it'] | False |
HassIOBaseAuth._check_access | (self, request: web.Request) | Check if this call is from Supervisor. | Check if this call is from Supervisor. | def _check_access(self, request: web.Request):
"""Check if this call is from Supervisor."""
# Check caller IP
hassio_ip = os.environ["HASSIO"].split(":")[0]
if ip_address(request.transport.get_extra_info("peername")[0]) != ip_address(
hassio_ip
):
_LOGGER.error("Invalid auth request from %s", request.remote)
raise HTTPUnauthorized()
# Check caller token
if request[KEY_HASS_USER].id != self.user.id:
_LOGGER.error("Invalid auth request from %s", request[KEY_HASS_USER].name)
raise HTTPUnauthorized() | [
"def",
"_check_access",
"(",
"self",
",",
"request",
":",
"web",
".",
"Request",
")",
":",
"# Check caller IP",
"hassio_ip",
"=",
"os",
".",
"environ",
"[",
"\"HASSIO\"",
"]",
".",
"split",
"(",
"\":\"",
")",
"[",
"0",
"]",
"if",
"ip_address",
"(",
"request",
".",
"transport",
".",
"get_extra_info",
"(",
"\"peername\"",
")",
"[",
"0",
"]",
")",
"!=",
"ip_address",
"(",
"hassio_ip",
")",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid auth request from %s\"",
",",
"request",
".",
"remote",
")",
"raise",
"HTTPUnauthorized",
"(",
")",
"# Check caller token",
"if",
"request",
"[",
"KEY_HASS_USER",
"]",
".",
"id",
"!=",
"self",
".",
"user",
".",
"id",
":",
"_LOGGER",
".",
"error",
"(",
"\"Invalid auth request from %s\"",
",",
"request",
"[",
"KEY_HASS_USER",
"]",
".",
"name",
")",
"raise",
"HTTPUnauthorized",
"(",
")"
] | [
42,
4
] | [
55,
36
] | python | en | ['en', 'en', 'en'] | True |
HassIOAuth.post | (self, request, data) | Handle auth requests. | Handle auth requests. | async def post(self, request, data):
"""Handle auth requests."""
self._check_access(request)
provider = auth_ha.async_get_provider(request.app["hass"])
try:
await provider.async_validate_login(
data[ATTR_USERNAME], data[ATTR_PASSWORD]
)
except auth_ha.InvalidAuth:
raise HTTPUnauthorized() from None
return web.Response(status=HTTP_OK) | [
"async",
"def",
"post",
"(",
"self",
",",
"request",
",",
"data",
")",
":",
"self",
".",
"_check_access",
"(",
"request",
")",
"provider",
"=",
"auth_ha",
".",
"async_get_provider",
"(",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
")",
"try",
":",
"await",
"provider",
".",
"async_validate_login",
"(",
"data",
"[",
"ATTR_USERNAME",
"]",
",",
"data",
"[",
"ATTR_PASSWORD",
"]",
")",
"except",
"auth_ha",
".",
"InvalidAuth",
":",
"raise",
"HTTPUnauthorized",
"(",
")",
"from",
"None",
"return",
"web",
".",
"Response",
"(",
"status",
"=",
"HTTP_OK",
")"
] | [
74,
4
] | [
86,
43
] | python | en | ['de', 'en', 'en'] | True |
HassIOPasswordReset.post | (self, request, data) | Handle password reset requests. | Handle password reset requests. | async def post(self, request, data):
"""Handle password reset requests."""
self._check_access(request)
provider = auth_ha.async_get_provider(request.app["hass"])
try:
await provider.async_change_password(
data[ATTR_USERNAME], data[ATTR_PASSWORD]
)
except auth_ha.InvalidUser as err:
raise HTTPNotFound() from err
return web.Response(status=HTTP_OK) | [
"async",
"def",
"post",
"(",
"self",
",",
"request",
",",
"data",
")",
":",
"self",
".",
"_check_access",
"(",
"request",
")",
"provider",
"=",
"auth_ha",
".",
"async_get_provider",
"(",
"request",
".",
"app",
"[",
"\"hass\"",
"]",
")",
"try",
":",
"await",
"provider",
".",
"async_change_password",
"(",
"data",
"[",
"ATTR_USERNAME",
"]",
",",
"data",
"[",
"ATTR_PASSWORD",
"]",
")",
"except",
"auth_ha",
".",
"InvalidUser",
"as",
"err",
":",
"raise",
"HTTPNotFound",
"(",
")",
"from",
"err",
"return",
"web",
".",
"Response",
"(",
"status",
"=",
"HTTP_OK",
")"
] | [
104,
4
] | [
116,
43
] | python | en | ['fr', 'nl', 'en'] | False |
test_setup | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test setup with basic config. | Test setup with basic config. | async def test_setup(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test setup with basic config."""
await setup_integration(hass, aioclient_mock)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
main = entity_registry.async_get(MAIN_ENTITY_ID)
assert hass.states.get(MAIN_ENTITY_ID)
assert main
assert main.device_class == DEVICE_CLASS_RECEIVER
assert main.unique_id == UPNP_SERIAL | [
"async",
"def",
"test_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"main",
"=",
"entity_registry",
".",
"async_get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"main",
"assert",
"main",
".",
"device_class",
"==",
"DEVICE_CLASS_RECEIVER",
"assert",
"main",
".",
"unique_id",
"==",
"UPNP_SERIAL"
] | [
76,
0
] | [
88,
40
] | python | en | ['en', 'zu', 'en'] | True |
test_idle_setup | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test setup with idle device. | Test setup with idle device. | async def test_idle_setup(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test setup with idle device."""
await setup_integration(hass, aioclient_mock, power=False)
state = hass.states.get(MAIN_ENTITY_ID)
assert state.state == STATE_STANDBY | [
"async",
"def",
"test_idle_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
",",
"power",
"=",
"False",
")",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"state",
".",
"state",
"==",
"STATE_STANDBY"
] | [
91,
0
] | [
98,
39
] | python | en | ['en', 'haw', 'en'] | True |
test_tv_setup | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test Roku TV setup. | Test Roku TV setup. | async def test_tv_setup(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test Roku TV setup."""
await setup_integration(
hass,
aioclient_mock,
device="rokutv",
app="tvinput-dtv",
host=TV_HOST,
unique_id=TV_SERIAL,
)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
tv = entity_registry.async_get(TV_ENTITY_ID)
assert hass.states.get(TV_ENTITY_ID)
assert tv
assert tv.device_class == DEVICE_CLASS_TV
assert tv.unique_id == TV_SERIAL | [
"async",
"def",
"test_tv_setup",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
",",
"device",
"=",
"\"rokutv\"",
",",
"app",
"=",
"\"tvinput-dtv\"",
",",
"host",
"=",
"TV_HOST",
",",
"unique_id",
"=",
"TV_SERIAL",
",",
")",
"entity_registry",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_registry",
"(",
")",
"tv",
"=",
"entity_registry",
".",
"async_get",
"(",
"TV_ENTITY_ID",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"TV_ENTITY_ID",
")",
"assert",
"tv",
"assert",
"tv",
".",
"device_class",
"==",
"DEVICE_CLASS_TV",
"assert",
"tv",
".",
"unique_id",
"==",
"TV_SERIAL"
] | [
101,
0
] | [
120,
36
] | python | en | ['en', 'haw', 'en'] | True |
test_availability | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test entity availability. | Test entity availability. | async def test_availability(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test entity availability."""
now = dt_util.utcnow()
future = now + timedelta(minutes=1)
with patch("homeassistant.util.dt.utcnow", return_value=now):
await setup_integration(hass, aioclient_mock)
with patch(
"homeassistant.components.roku.Roku.update", side_effect=RokuError
), patch("homeassistant.util.dt.utcnow", return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_UNAVAILABLE
future += timedelta(minutes=1)
with patch("homeassistant.util.dt.utcnow", return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert hass.states.get(MAIN_ENTITY_ID).state == STATE_HOME | [
"async",
"def",
"test_availability",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"now",
"=",
"dt_util",
".",
"utcnow",
"(",
")",
"future",
"=",
"now",
"+",
"timedelta",
"(",
"minutes",
"=",
"1",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"now",
")",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"with",
"patch",
"(",
"\"homeassistant.components.roku.Roku.update\"",
",",
"side_effect",
"=",
"RokuError",
")",
",",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"future",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"future",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
".",
"state",
"==",
"STATE_UNAVAILABLE",
"future",
"+=",
"timedelta",
"(",
"minutes",
"=",
"1",
")",
"with",
"patch",
"(",
"\"homeassistant.util.dt.utcnow\"",
",",
"return_value",
"=",
"future",
")",
":",
"async_fire_time_changed",
"(",
"hass",
",",
"future",
")",
"await",
"hass",
".",
"async_block_till_done",
"(",
")",
"assert",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
".",
"state",
"==",
"STATE_HOME"
] | [
123,
0
] | [
145,
66
] | python | en | ['en', 'ga', 'en'] | True |
test_supported_features | (
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) | Test supported features. | Test supported features. | async def test_supported_features(
hass: HomeAssistantType, aioclient_mock: AiohttpClientMocker
) -> None:
"""Test supported features."""
await setup_integration(hass, aioclient_mock)
# Features supported for Rokus
state = hass.states.get(MAIN_ENTITY_ID)
assert (
SUPPORT_PREVIOUS_TRACK
| SUPPORT_NEXT_TRACK
| SUPPORT_VOLUME_STEP
| SUPPORT_VOLUME_MUTE
| SUPPORT_SELECT_SOURCE
| SUPPORT_PAUSE
| SUPPORT_PLAY
| SUPPORT_PLAY_MEDIA
| SUPPORT_TURN_ON
| SUPPORT_TURN_OFF
| SUPPORT_BROWSE_MEDIA
== state.attributes.get("supported_features")
) | [
"async",
"def",
"test_supported_features",
"(",
"hass",
":",
"HomeAssistantType",
",",
"aioclient_mock",
":",
"AiohttpClientMocker",
")",
"->",
"None",
":",
"await",
"setup_integration",
"(",
"hass",
",",
"aioclient_mock",
")",
"# Features supported for Rokus",
"state",
"=",
"hass",
".",
"states",
".",
"get",
"(",
"MAIN_ENTITY_ID",
")",
"assert",
"(",
"SUPPORT_PREVIOUS_TRACK",
"|",
"SUPPORT_NEXT_TRACK",
"|",
"SUPPORT_VOLUME_STEP",
"|",
"SUPPORT_VOLUME_MUTE",
"|",
"SUPPORT_SELECT_SOURCE",
"|",
"SUPPORT_PAUSE",
"|",
"SUPPORT_PLAY",
"|",
"SUPPORT_PLAY_MEDIA",
"|",
"SUPPORT_TURN_ON",
"|",
"SUPPORT_TURN_OFF",
"|",
"SUPPORT_BROWSE_MEDIA",
"==",
"state",
".",
"attributes",
".",
"get",
"(",
"\"supported_features\"",
")",
")"
] | [
148,
0
] | [
169,
5
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.