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
start_step
(step_label)
Generates the HTML for the start of a step, including breadcrumbs
Generates the HTML for the start of a step, including breadcrumbs
def start_step(step_label): """Generates the HTML for the start of a step, including breadcrumbs""" if '"' in step_label: raise ValueError("step_label must not contain \" characters") step_id = slugify(step_label) out_html = """ <div class="interactive-block" id="interactive-{step_id}"> <div class="interactive-block-inner"> <div class="breadcrumbs-wrap"> <ul class="breadcrumb tutorial-step-crumbs" id="bc-ul-{step_id}" data-steplabel="{step_label}" data-stepid="{step_id}"> </ul><!--/.breadcrumb.tutorial-step-crumbs--> </div><!--/.breadcrumbs-wrap--> <div class="interactive-block-ui"> """.format(step_id=step_id, step_label=step_label) return out_html
[ "def", "start_step", "(", "step_label", ")", ":", "if", "'\"'", "in", "step_label", ":", "raise", "ValueError", "(", "\"step_label must not contain \\\" characters\"", ")", "step_id", "=", "slugify", "(", "step_label", ")", "out_html", "=", "\"\"\"\n<div class=\"interactive-block\" id=\"interactive-{step_id}\">\n <div class=\"interactive-block-inner\">\n <div class=\"breadcrumbs-wrap\">\n <ul class=\"breadcrumb tutorial-step-crumbs\" id=\"bc-ul-{step_id}\" data-steplabel=\"{step_label}\" data-stepid=\"{step_id}\">\n </ul><!--/.breadcrumb.tutorial-step-crumbs-->\n </div><!--/.breadcrumbs-wrap-->\n <div class=\"interactive-block-ui\">\n\n\"\"\"", ".", "format", "(", "step_id", "=", "step_id", ",", "step_label", "=", "step_label", ")", "return", "out_html" ]
[ 21, 0 ]
[ 39, 19 ]
python
en
['en', 'en', 'en']
True
end_step
()
Generates the HTML for the end of a step
Generates the HTML for the end of a step
def end_step(): """Generates the HTML for the end of a step""" return " </div><!--/.interactive-block-ui-->\n </div><!--/.interactive-block-inner-->\n</div><!--/.interactive-block-->"
[ "def", "end_step", "(", ")", ":", "return", "\" </div><!--/.interactive-block-ui-->\\n </div><!--/.interactive-block-inner-->\\n</div><!--/.interactive-block-->\"" ]
[ 41, 0 ]
[ 43, 128 ]
python
en
['en', 'en', 'en']
True
filter_soup
(soup, **kwargs)
Add steps to each tutorial-step-crumbs element based on the total steps in the document. Each step results in a li element such as: <li class="breadcrumb-item disabled current bc-connect"> <a href="#interactive-connect">Connect</a> </li>
Add steps to each tutorial-step-crumbs element based on the total steps in the document. Each step results in a li element such as: <li class="breadcrumb-item disabled current bc-connect"> <a href="#interactive-connect">Connect</a> </li>
def filter_soup(soup, **kwargs): """Add steps to each tutorial-step-crumbs element based on the total steps in the document. Each step results in a li element such as: <li class="breadcrumb-item disabled current bc-connect"> <a href="#interactive-connect">Connect</a> </li>""" crumb_uls = soup.find_all(class_="tutorial-step-crumbs") steps = [(el.attrs["data-stepid"], el.attrs["data-steplabel"]) for el in crumb_uls] def add_lis(parent_ul, steps, current_step_id): i = 0 for step_id, step_label in steps: li = soup.new_tag("li") li_classes = ["breadcrumb-item", "bc-{step_id}".format(step_id=step_id)] if i > 0: li_classes.append("disabled") # Steps get enabled in order by JS if step_id == current_step_id: li_classes.append("current") li.attrs['class'] = li_classes li_a = soup.new_tag("a", href="#interactive-{step_id}".format(step_id=step_id)) li_a.append(step_label) li.append(li_a) parent_ul.append(li) i += 1 for ul in crumb_uls: ul_step_id = ul.attrs["data-stepid"] add_lis(ul, steps, ul_step_id)
[ "def", "filter_soup", "(", "soup", ",", "*", "*", "kwargs", ")", ":", "crumb_uls", "=", "soup", ".", "find_all", "(", "class_", "=", "\"tutorial-step-crumbs\"", ")", "steps", "=", "[", "(", "el", ".", "attrs", "[", "\"data-stepid\"", "]", ",", "el", ".", "attrs", "[", "\"data-steplabel\"", "]", ")", "for", "el", "in", "crumb_uls", "]", "def", "add_lis", "(", "parent_ul", ",", "steps", ",", "current_step_id", ")", ":", "i", "=", "0", "for", "step_id", ",", "step_label", "in", "steps", ":", "li", "=", "soup", ".", "new_tag", "(", "\"li\"", ")", "li_classes", "=", "[", "\"breadcrumb-item\"", ",", "\"bc-{step_id}\"", ".", "format", "(", "step_id", "=", "step_id", ")", "]", "if", "i", ">", "0", ":", "li_classes", ".", "append", "(", "\"disabled\"", ")", "# Steps get enabled in order by JS", "if", "step_id", "==", "current_step_id", ":", "li_classes", ".", "append", "(", "\"current\"", ")", "li", ".", "attrs", "[", "'class'", "]", "=", "li_classes", "li_a", "=", "soup", ".", "new_tag", "(", "\"a\"", ",", "href", "=", "\"#interactive-{step_id}\"", ".", "format", "(", "step_id", "=", "step_id", ")", ")", "li_a", ".", "append", "(", "step_label", ")", "li", ".", "append", "(", "li_a", ")", "parent_ul", ".", "append", "(", "li", ")", "i", "+=", "1", "for", "ul", "in", "crumb_uls", ":", "ul_step_id", "=", "ul", ".", "attrs", "[", "\"data-stepid\"", "]", "add_lis", "(", "ul", ",", "steps", ",", "ul_step_id", ")" ]
[ 45, 0 ]
[ 72, 38 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistant, config: dict)
Set up the Tado component.
Set up the Tado component.
async def async_setup(hass: HomeAssistant, config: dict): """Set up the Tado component.""" hass.data.setdefault(DOMAIN, {}) if DOMAIN not in config: return True for conf in config[DOMAIN]: hass.async_create_task( hass.config_entries.flow.async_init( DOMAIN, context={"source": SOURCE_IMPORT}, data=conf, ) ) return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "hass", ".", "data", ".", "setdefault", "(", "DOMAIN", ",", "{", "}", ")", "if", "DOMAIN", "not", "in", "config", ":", "return", "True", "for", "conf", "in", "config", "[", "DOMAIN", "]", ":", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "SOURCE_IMPORT", "}", ",", "data", "=", "conf", ",", ")", ")", "return", "True" ]
[ 54, 0 ]
[ 71, 15 ]
python
en
['en', 'pt', 'en']
True
async_setup_entry
(hass: HomeAssistant, entry: ConfigEntry)
Set up Tado from a config entry.
Set up Tado from a config entry.
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Tado from a config entry.""" _async_import_options_from_data_if_missing(hass, entry) username = entry.data[CONF_USERNAME] password = entry.data[CONF_PASSWORD] fallback = entry.options.get(CONF_FALLBACK, True) tadoconnector = TadoConnector(hass, username, password, fallback) try: await hass.async_add_executor_job(tadoconnector.setup) except KeyError: _LOGGER.error("Failed to login to tado") return False except RuntimeError as exc: _LOGGER.error("Failed to setup tado: %s", exc) return ConfigEntryNotReady except requests.exceptions.Timeout as ex: raise ConfigEntryNotReady from ex except requests.exceptions.HTTPError as ex: if ex.response.status_code > 400 and ex.response.status_code < 500: _LOGGER.error("Failed to login to tado: %s", ex) return False raise ConfigEntryNotReady from ex # Do first update await hass.async_add_executor_job(tadoconnector.update) # Poll for updates in the background update_track = async_track_time_interval( hass, lambda now: tadoconnector.update(), SCAN_INTERVAL, ) update_listener = entry.add_update_listener(_async_update_listener) hass.data[DOMAIN][entry.entry_id] = { DATA: tadoconnector, UPDATE_TRACK: update_track, UPDATE_LISTENER: update_listener, } for component in TADO_COMPONENTS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, component) ) return True
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "_async_import_options_from_data_if_missing", "(", "hass", ",", "entry", ")", "username", "=", "entry", ".", "data", "[", "CONF_USERNAME", "]", "password", "=", "entry", ".", "data", "[", "CONF_PASSWORD", "]", "fallback", "=", "entry", ".", "options", ".", "get", "(", "CONF_FALLBACK", ",", "True", ")", "tadoconnector", "=", "TadoConnector", "(", "hass", ",", "username", ",", "password", ",", "fallback", ")", "try", ":", "await", "hass", ".", "async_add_executor_job", "(", "tadoconnector", ".", "setup", ")", "except", "KeyError", ":", "_LOGGER", ".", "error", "(", "\"Failed to login to tado\"", ")", "return", "False", "except", "RuntimeError", "as", "exc", ":", "_LOGGER", ".", "error", "(", "\"Failed to setup tado: %s\"", ",", "exc", ")", "return", "ConfigEntryNotReady", "except", "requests", ".", "exceptions", ".", "Timeout", "as", "ex", ":", "raise", "ConfigEntryNotReady", "from", "ex", "except", "requests", ".", "exceptions", ".", "HTTPError", "as", "ex", ":", "if", "ex", ".", "response", ".", "status_code", ">", "400", "and", "ex", ".", "response", ".", "status_code", "<", "500", ":", "_LOGGER", ".", "error", "(", "\"Failed to login to tado: %s\"", ",", "ex", ")", "return", "False", "raise", "ConfigEntryNotReady", "from", "ex", "# Do first update", "await", "hass", ".", "async_add_executor_job", "(", "tadoconnector", ".", "update", ")", "# Poll for updates in the background", "update_track", "=", "async_track_time_interval", "(", "hass", ",", "lambda", "now", ":", "tadoconnector", ".", "update", "(", ")", ",", "SCAN_INTERVAL", ",", ")", "update_listener", "=", "entry", ".", "add_update_listener", "(", "_async_update_listener", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "entry", ".", "entry_id", "]", "=", "{", "DATA", ":", "tadoconnector", ",", "UPDATE_TRACK", ":", "update_track", ",", "UPDATE_LISTENER", ":", "update_listener", ",", "}", "for", "component", "in", "TADO_COMPONENTS", ":", "hass", ".", "async_create_task", "(", "hass", ".", "config_entries", ".", "async_forward_entry_setup", "(", "entry", ",", "component", ")", ")", "return", "True" ]
[ 74, 0 ]
[ 124, 15 ]
python
en
['en', 'pt', 'en']
True
_async_update_listener
(hass: HomeAssistant, entry: ConfigEntry)
Handle options update.
Handle options update.
async def _async_update_listener(hass: HomeAssistant, entry: ConfigEntry): """Handle options update.""" await hass.config_entries.async_reload(entry.entry_id)
[ "async", "def", "_async_update_listener", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "await", "hass", ".", "config_entries", ".", "async_reload", "(", "entry", ".", "entry_id", ")" ]
[ 135, 0 ]
[ 137, 58 ]
python
en
['en', 'nl', 'en']
True
async_unload_entry
(hass: HomeAssistant, entry: ConfigEntry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" unload_ok = all( await asyncio.gather( *[ hass.config_entries.async_forward_entry_unload(entry, component) for component in TADO_COMPONENTS ] ) ) hass.data[DOMAIN][entry.entry_id][UPDATE_TRACK]() hass.data[DOMAIN][entry.entry_id][UPDATE_LISTENER]() if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "unload_ok", "=", "all", "(", "await", "asyncio", ".", "gather", "(", "*", "[", "hass", ".", "config_entries", ".", "async_forward_entry_unload", "(", "entry", ",", "component", ")", "for", "component", "in", "TADO_COMPONENTS", "]", ")", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "entry", ".", "entry_id", "]", "[", "UPDATE_TRACK", "]", "(", ")", "hass", ".", "data", "[", "DOMAIN", "]", "[", "entry", ".", "entry_id", "]", "[", "UPDATE_LISTENER", "]", "(", ")", "if", "unload_ok", ":", "hass", ".", "data", "[", "DOMAIN", "]", ".", "pop", "(", "entry", ".", "entry_id", ")", "return", "unload_ok" ]
[ 140, 0 ]
[ 157, 20 ]
python
en
['en', 'es', 'en']
True
TadoConnector.__init__
(self, hass, username, password, fallback)
Initialize Tado Connector.
Initialize Tado Connector.
def __init__(self, hass, username, password, fallback): """Initialize Tado Connector.""" self.hass = hass self._username = username self._password = password self._fallback = fallback self.device_id = None self.tado = None self.zones = None self.devices = None self.data = { "zone": {}, "device": {}, }
[ "def", "__init__", "(", "self", ",", "hass", ",", "username", ",", "password", ",", "fallback", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "_username", "=", "username", "self", ".", "_password", "=", "password", "self", ".", "_fallback", "=", "fallback", "self", ".", "device_id", "=", "None", "self", ".", "tado", "=", "None", "self", ".", "zones", "=", "None", "self", ".", "devices", "=", "None", "self", ".", "data", "=", "{", "\"zone\"", ":", "{", "}", ",", "\"device\"", ":", "{", "}", ",", "}" ]
[ 163, 4 ]
[ 177, 9 ]
python
en
['es', 'en', 'it']
False
TadoConnector.fallback
(self)
Return fallback flag to Smart Schedule.
Return fallback flag to Smart Schedule.
def fallback(self): """Return fallback flag to Smart Schedule.""" return self._fallback
[ "def", "fallback", "(", "self", ")", ":", "return", "self", ".", "_fallback" ]
[ 180, 4 ]
[ 182, 29 ]
python
en
['en', 'ig', 'en']
True
TadoConnector.setup
(self)
Connect to Tado and fetch the zones.
Connect to Tado and fetch the zones.
def setup(self): """Connect to Tado and fetch the zones.""" self.tado = Tado(self._username, self._password) self.tado.setDebugging(True) # Load zones and devices self.zones = self.tado.getZones() self.devices = self.tado.getMe()["homes"] self.device_id = self.devices[0]["id"]
[ "def", "setup", "(", "self", ")", ":", "self", ".", "tado", "=", "Tado", "(", "self", ".", "_username", ",", "self", ".", "_password", ")", "self", ".", "tado", ".", "setDebugging", "(", "True", ")", "# Load zones and devices", "self", ".", "zones", "=", "self", ".", "tado", ".", "getZones", "(", ")", "self", ".", "devices", "=", "self", ".", "tado", ".", "getMe", "(", ")", "[", "\"homes\"", "]", "self", ".", "device_id", "=", "self", ".", "devices", "[", "0", "]", "[", "\"id\"", "]" ]
[ 184, 4 ]
[ 191, 46 ]
python
en
['en', 'en', 'en']
True
TadoConnector.update
(self)
Update the registered zones.
Update the registered zones.
def update(self): """Update the registered zones.""" for zone in self.zones: self.update_sensor("zone", zone["id"]) for device in self.devices: self.update_sensor("device", device["id"])
[ "def", "update", "(", "self", ")", ":", "for", "zone", "in", "self", ".", "zones", ":", "self", ".", "update_sensor", "(", "\"zone\"", ",", "zone", "[", "\"id\"", "]", ")", "for", "device", "in", "self", ".", "devices", ":", "self", ".", "update_sensor", "(", "\"device\"", ",", "device", "[", "\"id\"", "]", ")" ]
[ 194, 4 ]
[ 199, 54 ]
python
en
['en', 'en', 'en']
True
TadoConnector.update_sensor
(self, sensor_type, sensor)
Update the internal data from Tado.
Update the internal data from Tado.
def update_sensor(self, sensor_type, sensor): """Update the internal data from Tado.""" _LOGGER.debug("Updating %s %s", sensor_type, sensor) try: if sensor_type == "zone": data = self.tado.getZoneState(sensor) elif sensor_type == "device": devices_data = self.tado.getDevices() if not devices_data: _LOGGER.info("There are no devices to setup on this tado account") return data = devices_data[0] else: _LOGGER.debug("Unknown sensor: %s", sensor_type) return except RuntimeError: _LOGGER.error( "Unable to connect to Tado while updating %s %s", sensor_type, sensor, ) return self.data[sensor_type][sensor] = data _LOGGER.debug( "Dispatching update to %s %s %s: %s", self.device_id, sensor_type, sensor, data, ) dispatcher_send( self.hass, SIGNAL_TADO_UPDATE_RECEIVED.format(self.device_id, sensor_type, sensor), )
[ "def", "update_sensor", "(", "self", ",", "sensor_type", ",", "sensor", ")", ":", "_LOGGER", ".", "debug", "(", "\"Updating %s %s\"", ",", "sensor_type", ",", "sensor", ")", "try", ":", "if", "sensor_type", "==", "\"zone\"", ":", "data", "=", "self", ".", "tado", ".", "getZoneState", "(", "sensor", ")", "elif", "sensor_type", "==", "\"device\"", ":", "devices_data", "=", "self", ".", "tado", ".", "getDevices", "(", ")", "if", "not", "devices_data", ":", "_LOGGER", ".", "info", "(", "\"There are no devices to setup on this tado account\"", ")", "return", "data", "=", "devices_data", "[", "0", "]", "else", ":", "_LOGGER", ".", "debug", "(", "\"Unknown sensor: %s\"", ",", "sensor_type", ")", "return", "except", "RuntimeError", ":", "_LOGGER", ".", "error", "(", "\"Unable to connect to Tado while updating %s %s\"", ",", "sensor_type", ",", "sensor", ",", ")", "return", "self", ".", "data", "[", "sensor_type", "]", "[", "sensor", "]", "=", "data", "_LOGGER", ".", "debug", "(", "\"Dispatching update to %s %s %s: %s\"", ",", "self", ".", "device_id", ",", "sensor_type", ",", "sensor", ",", "data", ",", ")", "dispatcher_send", "(", "self", ".", "hass", ",", "SIGNAL_TADO_UPDATE_RECEIVED", ".", "format", "(", "self", ".", "device_id", ",", "sensor_type", ",", "sensor", ")", ",", ")" ]
[ 201, 4 ]
[ 237, 9 ]
python
en
['en', 'en', 'en']
True
TadoConnector.get_capabilities
(self, zone_id)
Return the capabilities of the devices.
Return the capabilities of the devices.
def get_capabilities(self, zone_id): """Return the capabilities of the devices.""" return self.tado.getCapabilities(zone_id)
[ "def", "get_capabilities", "(", "self", ",", "zone_id", ")", ":", "return", "self", ".", "tado", ".", "getCapabilities", "(", "zone_id", ")" ]
[ 239, 4 ]
[ 241, 49 ]
python
en
['en', 'en', 'en']
True
TadoConnector.reset_zone_overlay
(self, zone_id)
Reset the zone back to the default operation.
Reset the zone back to the default operation.
def reset_zone_overlay(self, zone_id): """Reset the zone back to the default operation.""" self.tado.resetZoneOverlay(zone_id) self.update_sensor("zone", zone_id)
[ "def", "reset_zone_overlay", "(", "self", ",", "zone_id", ")", ":", "self", ".", "tado", ".", "resetZoneOverlay", "(", "zone_id", ")", "self", ".", "update_sensor", "(", "\"zone\"", ",", "zone_id", ")" ]
[ 243, 4 ]
[ 246, 43 ]
python
en
['en', 'en', 'en']
True
TadoConnector.set_presence
( self, presence=PRESET_HOME, )
Set the presence to home or away.
Set the presence to home or away.
def set_presence( self, presence=PRESET_HOME, ): """Set the presence to home or away.""" if presence == PRESET_AWAY: self.tado.setAway() elif presence == PRESET_HOME: self.tado.setHome()
[ "def", "set_presence", "(", "self", ",", "presence", "=", "PRESET_HOME", ",", ")", ":", "if", "presence", "==", "PRESET_AWAY", ":", "self", ".", "tado", ".", "setAway", "(", ")", "elif", "presence", "==", "PRESET_HOME", ":", "self", ".", "tado", ".", "setHome", "(", ")" ]
[ 248, 4 ]
[ 256, 31 ]
python
en
['en', 'en', 'en']
True
TadoConnector.set_zone_overlay
( self, zone_id=None, overlay_mode=None, temperature=None, duration=None, device_type="HEATING", mode=None, fan_speed=None, swing=None, )
Set a zone overlay.
Set a zone overlay.
def set_zone_overlay( self, zone_id=None, overlay_mode=None, temperature=None, duration=None, device_type="HEATING", mode=None, fan_speed=None, swing=None, ): """Set a zone overlay.""" _LOGGER.debug( "Set overlay for zone %s: overlay_mode=%s, temp=%s, duration=%s, type=%s, mode=%s fan_speed=%s swing=%s", zone_id, overlay_mode, temperature, duration, device_type, mode, fan_speed, swing, ) try: self.tado.setZoneOverlay( zone_id, overlay_mode, temperature, duration, device_type, "ON", mode, fanSpeed=fan_speed, swing=swing, ) except RequestException as exc: _LOGGER.error("Could not set zone overlay: %s", exc) self.update_sensor("zone", zone_id)
[ "def", "set_zone_overlay", "(", "self", ",", "zone_id", "=", "None", ",", "overlay_mode", "=", "None", ",", "temperature", "=", "None", ",", "duration", "=", "None", ",", "device_type", "=", "\"HEATING\"", ",", "mode", "=", "None", ",", "fan_speed", "=", "None", ",", "swing", "=", "None", ",", ")", ":", "_LOGGER", ".", "debug", "(", "\"Set overlay for zone %s: overlay_mode=%s, temp=%s, duration=%s, type=%s, mode=%s fan_speed=%s swing=%s\"", ",", "zone_id", ",", "overlay_mode", ",", "temperature", ",", "duration", ",", "device_type", ",", "mode", ",", "fan_speed", ",", "swing", ",", ")", "try", ":", "self", ".", "tado", ".", "setZoneOverlay", "(", "zone_id", ",", "overlay_mode", ",", "temperature", ",", "duration", ",", "device_type", ",", "\"ON\"", ",", "mode", ",", "fanSpeed", "=", "fan_speed", ",", "swing", "=", "swing", ",", ")", "except", "RequestException", "as", "exc", ":", "_LOGGER", ".", "error", "(", "\"Could not set zone overlay: %s\"", ",", "exc", ")", "self", ".", "update_sensor", "(", "\"zone\"", ",", "zone_id", ")" ]
[ 258, 4 ]
[ 298, 43 ]
python
en
['nl', 'en', 'en']
True
TadoConnector.set_zone_off
(self, zone_id, overlay_mode, device_type="HEATING")
Set a zone to off.
Set a zone to off.
def set_zone_off(self, zone_id, overlay_mode, device_type="HEATING"): """Set a zone to off.""" try: self.tado.setZoneOverlay( zone_id, overlay_mode, None, None, device_type, "OFF" ) except RequestException as exc: _LOGGER.error("Could not set zone overlay: %s", exc) self.update_sensor("zone", zone_id)
[ "def", "set_zone_off", "(", "self", ",", "zone_id", ",", "overlay_mode", ",", "device_type", "=", "\"HEATING\"", ")", ":", "try", ":", "self", ".", "tado", ".", "setZoneOverlay", "(", "zone_id", ",", "overlay_mode", ",", "None", ",", "None", ",", "device_type", ",", "\"OFF\"", ")", "except", "RequestException", "as", "exc", ":", "_LOGGER", ".", "error", "(", "\"Could not set zone overlay: %s\"", ",", "exc", ")", "self", ".", "update_sensor", "(", "\"zone\"", ",", "zone_id", ")" ]
[ 300, 4 ]
[ 309, 43 ]
python
en
['en', 'en', 'en']
True
is_on
(hass: HomeAssistantType, entity_id: str)
Return if the remote is on based on the statemachine.
Return if the remote is on based on the statemachine.
def is_on(hass: HomeAssistantType, entity_id: str) -> bool: """Return if the remote is on based on the statemachine.""" return hass.states.is_state(entity_id, STATE_ON)
[ "def", "is_on", "(", "hass", ":", "HomeAssistantType", ",", "entity_id", ":", "str", ")", "->", "bool", ":", "return", "hass", ".", "states", ".", "is_state", "(", "entity_id", ",", "STATE_ON", ")" ]
[ 65, 0 ]
[ 67, 52 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: HomeAssistantType, config: ConfigType)
Track states and offer events for remotes.
Track states and offer events for remotes.
async def async_setup(hass: HomeAssistantType, config: ConfigType) -> bool: """Track states and offer events for remotes.""" component = hass.data[DOMAIN] = EntityComponent( _LOGGER, DOMAIN, hass, SCAN_INTERVAL ) await component.async_setup(config) component.async_register_entity_service( SERVICE_TURN_OFF, REMOTE_SERVICE_ACTIVITY_SCHEMA, "async_turn_off" ) component.async_register_entity_service( SERVICE_TURN_ON, REMOTE_SERVICE_ACTIVITY_SCHEMA, "async_turn_on" ) component.async_register_entity_service( SERVICE_TOGGLE, REMOTE_SERVICE_ACTIVITY_SCHEMA, "async_toggle" ) component.async_register_entity_service( SERVICE_SEND_COMMAND, { vol.Required(ATTR_COMMAND): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_DEVICE): cv.string, vol.Optional( ATTR_NUM_REPEATS, default=DEFAULT_NUM_REPEATS ): cv.positive_int, vol.Optional(ATTR_DELAY_SECS): vol.Coerce(float), vol.Optional(ATTR_HOLD_SECS, default=DEFAULT_HOLD_SECS): vol.Coerce(float), }, "async_send_command", ) component.async_register_entity_service( SERVICE_LEARN_COMMAND, { vol.Optional(ATTR_DEVICE): cv.string, vol.Optional(ATTR_COMMAND): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_COMMAND_TYPE): cv.string, vol.Optional(ATTR_ALTERNATIVE): cv.boolean, vol.Optional(ATTR_TIMEOUT): cv.positive_int, }, "async_learn_command", ) component.async_register_entity_service( SERVICE_DELETE_COMMAND, { vol.Required(ATTR_COMMAND): vol.All(cv.ensure_list, [cv.string]), vol.Optional(ATTR_DEVICE): cv.string, }, "async_delete_command", ) return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistantType", ",", "config", ":", "ConfigType", ")", "->", "bool", ":", "component", "=", "hass", ".", "data", "[", "DOMAIN", "]", "=", "EntityComponent", "(", "_LOGGER", ",", "DOMAIN", ",", "hass", ",", "SCAN_INTERVAL", ")", "await", "component", ".", "async_setup", "(", "config", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_TURN_OFF", ",", "REMOTE_SERVICE_ACTIVITY_SCHEMA", ",", "\"async_turn_off\"", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_TURN_ON", ",", "REMOTE_SERVICE_ACTIVITY_SCHEMA", ",", "\"async_turn_on\"", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_TOGGLE", ",", "REMOTE_SERVICE_ACTIVITY_SCHEMA", ",", "\"async_toggle\"", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_SEND_COMMAND", ",", "{", "vol", ".", "Required", "(", "ATTR_COMMAND", ")", ":", "vol", ".", "All", "(", "cv", ".", "ensure_list", ",", "[", "cv", ".", "string", "]", ")", ",", "vol", ".", "Optional", "(", "ATTR_DEVICE", ")", ":", "cv", ".", "string", ",", "vol", ".", "Optional", "(", "ATTR_NUM_REPEATS", ",", "default", "=", "DEFAULT_NUM_REPEATS", ")", ":", "cv", ".", "positive_int", ",", "vol", ".", "Optional", "(", "ATTR_DELAY_SECS", ")", ":", "vol", ".", "Coerce", "(", "float", ")", ",", "vol", ".", "Optional", "(", "ATTR_HOLD_SECS", ",", "default", "=", "DEFAULT_HOLD_SECS", ")", ":", "vol", ".", "Coerce", "(", "float", ")", ",", "}", ",", "\"async_send_command\"", ",", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_LEARN_COMMAND", ",", "{", "vol", ".", "Optional", "(", "ATTR_DEVICE", ")", ":", "cv", ".", "string", ",", "vol", ".", "Optional", "(", "ATTR_COMMAND", ")", ":", "vol", ".", "All", "(", "cv", ".", "ensure_list", ",", "[", "cv", ".", "string", "]", ")", ",", "vol", ".", "Optional", "(", "ATTR_COMMAND_TYPE", ")", ":", "cv", ".", "string", ",", "vol", ".", "Optional", "(", "ATTR_ALTERNATIVE", ")", ":", "cv", ".", "boolean", ",", "vol", ".", "Optional", "(", "ATTR_TIMEOUT", ")", ":", "cv", ".", "positive_int", ",", "}", ",", "\"async_learn_command\"", ",", ")", "component", ".", "async_register_entity_service", "(", "SERVICE_DELETE_COMMAND", ",", "{", "vol", ".", "Required", "(", "ATTR_COMMAND", ")", ":", "vol", ".", "All", "(", "cv", ".", "ensure_list", ",", "[", "cv", ".", "string", "]", ")", ",", "vol", ".", "Optional", "(", "ATTR_DEVICE", ")", ":", "cv", ".", "string", ",", "}", ",", "\"async_delete_command\"", ",", ")", "return", "True" ]
[ 70, 0 ]
[ 124, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistantType, entry: ConfigEntry)
Set up a config entry.
Set up a config entry.
async def async_setup_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Set up a config entry.""" return await cast(EntityComponent, hass.data[DOMAIN]).async_setup_entry(entry)
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigEntry", ")", "->", "bool", ":", "return", "await", "cast", "(", "EntityComponent", ",", "hass", ".", "data", "[", "DOMAIN", "]", ")", ".", "async_setup_entry", "(", "entry", ")" ]
[ 127, 0 ]
[ 129, 82 ]
python
en
['en', 'en', 'en']
True
async_unload_entry
(hass: HomeAssistantType, entry: ConfigEntry)
Unload a config entry.
Unload a config entry.
async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> bool: """Unload a config entry.""" return await cast(EntityComponent, hass.data[DOMAIN]).async_unload_entry(entry)
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigEntry", ")", "->", "bool", ":", "return", "await", "cast", "(", "EntityComponent", ",", "hass", ".", "data", "[", "DOMAIN", "]", ")", ".", "async_unload_entry", "(", "entry", ")" ]
[ 132, 0 ]
[ 134, 83 ]
python
en
['en', 'es', 'en']
True
RemoteEntity.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self) -> int: """Flag supported features.""" return 0
[ "def", "supported_features", "(", "self", ")", "->", "int", ":", "return", "0" ]
[ 141, 4 ]
[ 143, 16 ]
python
en
['da', 'en', 'en']
True
RemoteEntity.send_command
(self, command: Iterable[str], **kwargs: Any)
Send commands to a device.
Send commands to a device.
def send_command(self, command: Iterable[str], **kwargs: Any) -> None: """Send commands to a device.""" raise NotImplementedError()
[ "def", "send_command", "(", "self", ",", "command", ":", "Iterable", "[", "str", "]", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "raise", "NotImplementedError", "(", ")" ]
[ 145, 4 ]
[ 147, 35 ]
python
en
['en', 'en', 'en']
True
RemoteEntity.async_send_command
(self, command: Iterable[str], **kwargs: Any)
Send commands to a device.
Send commands to a device.
async def async_send_command(self, command: Iterable[str], **kwargs: Any) -> None: """Send commands to a device.""" assert self.hass is not None await self.hass.async_add_executor_job( ft.partial(self.send_command, command, **kwargs) )
[ "async", "def", "async_send_command", "(", "self", ",", "command", ":", "Iterable", "[", "str", "]", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "assert", "self", ".", "hass", "is", "not", "None", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "ft", ".", "partial", "(", "self", ".", "send_command", ",", "command", ",", "*", "*", "kwargs", ")", ")" ]
[ 149, 4 ]
[ 154, 9 ]
python
en
['en', 'en', 'en']
True
RemoteEntity.learn_command
(self, **kwargs: Any)
Learn a command from a device.
Learn a command from a device.
def learn_command(self, **kwargs: Any) -> None: """Learn a command from a device.""" raise NotImplementedError()
[ "def", "learn_command", "(", "self", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "raise", "NotImplementedError", "(", ")" ]
[ 156, 4 ]
[ 158, 35 ]
python
en
['en', 'en', 'en']
True
RemoteEntity.async_learn_command
(self, **kwargs: Any)
Learn a command from a device.
Learn a command from a device.
async def async_learn_command(self, **kwargs: Any) -> None: """Learn a command from a device.""" assert self.hass is not None await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs))
[ "async", "def", "async_learn_command", "(", "self", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "assert", "self", ".", "hass", "is", "not", "None", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "ft", ".", "partial", "(", "self", ".", "learn_command", ",", "*", "*", "kwargs", ")", ")" ]
[ 160, 4 ]
[ 163, 88 ]
python
en
['en', 'en', 'en']
True
RemoteEntity.delete_command
(self, **kwargs: Any)
Delete commands from the database.
Delete commands from the database.
def delete_command(self, **kwargs: Any) -> None: """Delete commands from the database.""" raise NotImplementedError()
[ "def", "delete_command", "(", "self", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "raise", "NotImplementedError", "(", ")" ]
[ 165, 4 ]
[ 167, 35 ]
python
en
['en', 'en', 'en']
True
RemoteEntity.async_delete_command
(self, **kwargs: Any)
Delete commands from the database.
Delete commands from the database.
async def async_delete_command(self, **kwargs: Any) -> None: """Delete commands from the database.""" assert self.hass is not None await self.hass.async_add_executor_job( ft.partial(self.delete_command, **kwargs) )
[ "async", "def", "async_delete_command", "(", "self", ",", "*", "*", "kwargs", ":", "Any", ")", "->", "None", ":", "assert", "self", ".", "hass", "is", "not", "None", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "ft", ".", "partial", "(", "self", ".", "delete_command", ",", "*", "*", "kwargs", ")", ")" ]
[ 169, 4 ]
[ 174, 9 ]
python
en
['en', 'en', 'en']
True
RemoteDevice.__init_subclass__
(cls, **kwargs)
Print deprecation warning.
Print deprecation warning.
def __init_subclass__(cls, **kwargs): """Print deprecation warning.""" super().__init_subclass__(**kwargs) _LOGGER.warning( "RemoteDevice is deprecated, modify %s to extend RemoteEntity", cls.__name__, )
[ "def", "__init_subclass__", "(", "cls", ",", "*", "*", "kwargs", ")", ":", "super", "(", ")", ".", "__init_subclass__", "(", "*", "*", "kwargs", ")", "_LOGGER", ".", "warning", "(", "\"RemoteDevice is deprecated, modify %s to extend RemoteEntity\"", ",", "cls", ".", "__name__", ",", ")" ]
[ 180, 4 ]
[ 186, 9 ]
python
de
['de', 'sv', 'en']
False
async_setup_entry
( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities )
Set up AdGuard Home switch based on a config entry.
Set up AdGuard Home switch based on a config entry.
async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities ) -> None: """Set up AdGuard Home switch based on a config entry.""" adguard = hass.data[DOMAIN][DATA_ADGUARD_CLIENT] try: version = await adguard.version() except AdGuardHomeConnectionError as exception: raise PlatformNotReady from exception hass.data[DOMAIN][DATA_ADGUARD_VERION] = version switches = [ AdGuardHomeProtectionSwitch(adguard), AdGuardHomeFilteringSwitch(adguard), AdGuardHomeParentalSwitch(adguard), AdGuardHomeSafeBrowsingSwitch(adguard), AdGuardHomeSafeSearchSwitch(adguard), AdGuardHomeQueryLogSwitch(adguard), ] async_add_entities(switches, True)
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigEntry", ",", "async_add_entities", ")", "->", "None", ":", "adguard", "=", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_ADGUARD_CLIENT", "]", "try", ":", "version", "=", "await", "adguard", ".", "version", "(", ")", "except", "AdGuardHomeConnectionError", "as", "exception", ":", "raise", "PlatformNotReady", "from", "exception", "hass", ".", "data", "[", "DOMAIN", "]", "[", "DATA_ADGUARD_VERION", "]", "=", "version", "switches", "=", "[", "AdGuardHomeProtectionSwitch", "(", "adguard", ")", ",", "AdGuardHomeFilteringSwitch", "(", "adguard", ")", ",", "AdGuardHomeParentalSwitch", "(", "adguard", ")", ",", "AdGuardHomeSafeBrowsingSwitch", "(", "adguard", ")", ",", "AdGuardHomeSafeSearchSwitch", "(", "adguard", ")", ",", "AdGuardHomeQueryLogSwitch", "(", "adguard", ")", ",", "]", "async_add_entities", "(", "switches", ",", "True", ")" ]
[ 23, 0 ]
[ 44, 38 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch.__init__
( self, adguard, name: str, icon: str, key: str, enabled_default: bool = True )
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__( self, adguard, name: str, icon: str, key: str, enabled_default: bool = True ): """Initialize AdGuard Home switch.""" self._state = False self._key = key super().__init__(adguard, name, icon, enabled_default)
[ "def", "__init__", "(", "self", ",", "adguard", ",", "name", ":", "str", ",", "icon", ":", "str", ",", "key", ":", "str", ",", "enabled_default", ":", "bool", "=", "True", ")", ":", "self", ".", "_state", "=", "False", "self", ".", "_key", "=", "key", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "name", ",", "icon", ",", "enabled_default", ")" ]
[ 50, 4 ]
[ 56, 62 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch.unique_id
(self)
Return the unique ID for this sensor.
Return the unique ID for this sensor.
def unique_id(self) -> str: """Return the unique ID for this sensor.""" return "_".join( [DOMAIN, self.adguard.host, str(self.adguard.port), "switch", self._key] )
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "return", "\"_\"", ".", "join", "(", "[", "DOMAIN", ",", "self", ".", "adguard", ".", "host", ",", "str", "(", "self", ".", "adguard", ".", "port", ")", ",", "\"switch\"", ",", "self", ".", "_key", "]", ")" ]
[ 59, 4 ]
[ 63, 9 ]
python
en
['en', 'la', 'en']
True
AdGuardHomeSwitch.is_on
(self)
Return the state of the switch.
Return the state of the switch.
def is_on(self) -> bool: """Return the state of the switch.""" return self._state
[ "def", "is_on", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_state" ]
[ 66, 4 ]
[ 68, 26 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch.async_turn_off
(self, **kwargs)
Turn off the switch.
Turn off the switch.
async def async_turn_off(self, **kwargs) -> None: """Turn off the switch.""" try: await self._adguard_turn_off() except AdGuardHomeError: _LOGGER.error("An error occurred while turning off AdGuard Home switch") self._available = False
[ "async", "def", "async_turn_off", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "try", ":", "await", "self", ".", "_adguard_turn_off", "(", ")", "except", "AdGuardHomeError", ":", "_LOGGER", ".", "error", "(", "\"An error occurred while turning off AdGuard Home switch\"", ")", "self", ".", "_available", "=", "False" ]
[ 70, 4 ]
[ 76, 35 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" raise NotImplementedError()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "raise", "NotImplementedError", "(", ")" ]
[ 78, 4 ]
[ 80, 35 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch.async_turn_on
(self, **kwargs)
Turn on the switch.
Turn on the switch.
async def async_turn_on(self, **kwargs) -> None: """Turn on the switch.""" try: await self._adguard_turn_on() except AdGuardHomeError: _LOGGER.error("An error occurred while turning on AdGuard Home switch") self._available = False
[ "async", "def", "async_turn_on", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "try", ":", "await", "self", ".", "_adguard_turn_on", "(", ")", "except", "AdGuardHomeError", ":", "_LOGGER", ".", "error", "(", "\"An error occurred while turning on AdGuard Home switch\"", ")", "self", ".", "_available", "=", "False" ]
[ 82, 4 ]
[ 88, 35 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" raise NotImplementedError()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "raise", "NotImplementedError", "(", ")" ]
[ 90, 4 ]
[ 92, 35 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeProtectionSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__( adguard, "AdGuard Protection", "mdi:shield-check", "protection" )
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Protection\"", ",", "\"mdi:shield-check\"", ",", "\"protection\"", ")" ]
[ 98, 4 ]
[ 102, 9 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeProtectionSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.disable_protection()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "disable_protection", "(", ")" ]
[ 104, 4 ]
[ 106, 47 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeProtectionSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.enable_protection()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "enable_protection", "(", ")" ]
[ 108, 4 ]
[ 110, 46 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeProtectionSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.protection_enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "protection_enabled", "(", ")" ]
[ 112, 4 ]
[ 114, 61 ]
python
en
['es', 'en', 'en']
True
AdGuardHomeParentalSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__( adguard, "AdGuard Parental Control", "mdi:shield-check", "parental" )
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Parental Control\"", ",", "\"mdi:shield-check\"", ",", "\"parental\"", ")" ]
[ 120, 4 ]
[ 124, 9 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeParentalSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.parental.disable()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "parental", ".", "disable", "(", ")" ]
[ 126, 4 ]
[ 128, 45 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeParentalSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.parental.enable()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "parental", ".", "enable", "(", ")" ]
[ 130, 4 ]
[ 132, 44 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeParentalSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.parental.enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "parental", ".", "enabled", "(", ")" ]
[ 134, 4 ]
[ 136, 59 ]
python
en
['es', 'en', 'en']
True
AdGuardHomeSafeSearchSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__( adguard, "AdGuard Safe Search", "mdi:shield-check", "safesearch" )
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Safe Search\"", ",", "\"mdi:shield-check\"", ",", "\"safesearch\"", ")" ]
[ 142, 4 ]
[ 146, 9 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeSearchSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.safesearch.disable()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "safesearch", ".", "disable", "(", ")" ]
[ 148, 4 ]
[ 150, 47 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeSearchSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.safesearch.enable()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "safesearch", ".", "enable", "(", ")" ]
[ 152, 4 ]
[ 154, 46 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeSearchSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.safesearch.enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "safesearch", ".", "enabled", "(", ")" ]
[ 156, 4 ]
[ 158, 61 ]
python
en
['es', 'en', 'en']
True
AdGuardHomeSafeBrowsingSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__( adguard, "AdGuard Safe Browsing", "mdi:shield-check", "safebrowsing" )
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Safe Browsing\"", ",", "\"mdi:shield-check\"", ",", "\"safebrowsing\"", ")" ]
[ 164, 4 ]
[ 168, 9 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeBrowsingSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.safebrowsing.disable()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "safebrowsing", ".", "disable", "(", ")" ]
[ 170, 4 ]
[ 172, 49 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeBrowsingSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.safebrowsing.enable()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "safebrowsing", ".", "enable", "(", ")" ]
[ 174, 4 ]
[ 176, 48 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeSafeBrowsingSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.safebrowsing.enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "safebrowsing", ".", "enabled", "(", ")" ]
[ 178, 4 ]
[ 180, 63 ]
python
en
['es', 'en', 'en']
True
AdGuardHomeFilteringSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__(adguard, "AdGuard Filtering", "mdi:shield-check", "filtering")
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Filtering\"", ",", "\"mdi:shield-check\"", ",", "\"filtering\"", ")" ]
[ 186, 4 ]
[ 188, 87 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeFilteringSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.filtering.disable()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "filtering", ".", "disable", "(", ")" ]
[ 190, 4 ]
[ 192, 46 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeFilteringSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.filtering.enable()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "filtering", ".", "enable", "(", ")" ]
[ 194, 4 ]
[ 196, 45 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeFilteringSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.filtering.enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "filtering", ".", "enabled", "(", ")" ]
[ 198, 4 ]
[ 200, 60 ]
python
en
['es', 'en', 'en']
True
AdGuardHomeQueryLogSwitch.__init__
(self, adguard)
Initialize AdGuard Home switch.
Initialize AdGuard Home switch.
def __init__(self, adguard) -> None: """Initialize AdGuard Home switch.""" super().__init__( adguard, "AdGuard Query Log", "mdi:shield-check", "querylog", enabled_default=False, )
[ "def", "__init__", "(", "self", ",", "adguard", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "adguard", ",", "\"AdGuard Query Log\"", ",", "\"mdi:shield-check\"", ",", "\"querylog\"", ",", "enabled_default", "=", "False", ",", ")" ]
[ 206, 4 ]
[ 214, 9 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeQueryLogSwitch._adguard_turn_off
(self)
Turn off the switch.
Turn off the switch.
async def _adguard_turn_off(self) -> None: """Turn off the switch.""" await self.adguard.querylog.disable()
[ "async", "def", "_adguard_turn_off", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "querylog", ".", "disable", "(", ")" ]
[ 216, 4 ]
[ 218, 45 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeQueryLogSwitch._adguard_turn_on
(self)
Turn on the switch.
Turn on the switch.
async def _adguard_turn_on(self) -> None: """Turn on the switch.""" await self.adguard.querylog.enable()
[ "async", "def", "_adguard_turn_on", "(", "self", ")", "->", "None", ":", "await", "self", ".", "adguard", ".", "querylog", ".", "enable", "(", ")" ]
[ 220, 4 ]
[ 222, 44 ]
python
en
['en', 'en', 'en']
True
AdGuardHomeQueryLogSwitch._adguard_update
(self)
Update AdGuard Home entity.
Update AdGuard Home entity.
async def _adguard_update(self) -> None: """Update AdGuard Home entity.""" self._state = await self.adguard.querylog.enabled()
[ "async", "def", "_adguard_update", "(", "self", ")", "->", "None", ":", "self", ".", "_state", "=", "await", "self", ".", "adguard", ".", "querylog", ".", "enabled", "(", ")" ]
[ 224, 4 ]
[ 226, 59 ]
python
en
['es', 'en', 'en']
True
async_setup
(hass)
Enable the Home Assistant views.
Enable the Home Assistant views.
async def async_setup(hass): """Enable the Home Assistant views.""" hass.components.websocket_api.async_register_command(websocket_create) hass.components.websocket_api.async_register_command(websocket_delete) hass.components.websocket_api.async_register_command(websocket_change_password) hass.components.websocket_api.async_register_command( websocket_admin_change_password ) return True
[ "async", "def", "async_setup", "(", "hass", ")", ":", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_create", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_delete", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_change_password", ")", "hass", ".", "components", ".", "websocket_api", ".", "async_register_command", "(", "websocket_admin_change_password", ")", "return", "True" ]
[ 9, 0 ]
[ 17, 15 ]
python
en
['en', 'en', 'en']
True
websocket_create
(hass, connection, msg)
Create credentials and attach to a user.
Create credentials and attach to a user.
async def websocket_create(hass, connection, msg): """Create credentials and attach to a user.""" provider = auth_ha.async_get_provider(hass) user = await hass.auth.async_get_user(msg["user_id"]) if user is None: connection.send_error(msg["id"], "not_found", "User not found") return if user.system_generated: connection.send_error( msg["id"], "system_generated", "Cannot add credentials to a system generated user.", ) return try: await provider.async_add_auth(msg["username"], msg["password"]) except auth_ha.InvalidUser: connection.send_error(msg["id"], "username_exists", "Username already exists") return credentials = await provider.async_get_or_create_credentials( {"username": msg["username"]} ) await hass.auth.async_link_user(user, credentials) connection.send_result(msg["id"])
[ "async", "def", "websocket_create", "(", "hass", ",", "connection", ",", "msg", ")", ":", "provider", "=", "auth_ha", ".", "async_get_provider", "(", "hass", ")", "user", "=", "await", "hass", ".", "auth", ".", "async_get_user", "(", "msg", "[", "\"user_id\"", "]", ")", "if", "user", "is", "None", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"not_found\"", ",", "\"User not found\"", ")", "return", "if", "user", ".", "system_generated", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"system_generated\"", ",", "\"Cannot add credentials to a system generated user.\"", ",", ")", "return", "try", ":", "await", "provider", ".", "async_add_auth", "(", "msg", "[", "\"username\"", "]", ",", "msg", "[", "\"password\"", "]", ")", "except", "auth_ha", ".", "InvalidUser", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"username_exists\"", ",", "\"Username already exists\"", ")", "return", "credentials", "=", "await", "provider", ".", "async_get_or_create_credentials", "(", "{", "\"username\"", ":", "msg", "[", "\"username\"", "]", "}", ")", "await", "hass", ".", "auth", ".", "async_link_user", "(", "user", ",", "credentials", ")", "connection", ".", "send_result", "(", "msg", "[", "\"id\"", "]", ")" ]
[ 30, 0 ]
[ 58, 37 ]
python
en
['en', 'en', 'en']
True
websocket_delete
(hass, connection, msg)
Delete username and related credential.
Delete username and related credential.
async def websocket_delete(hass, connection, msg): """Delete username and related credential.""" provider = auth_ha.async_get_provider(hass) credentials = await provider.async_get_or_create_credentials( {"username": msg["username"]} ) # if not new, an existing credential exists. # Removing the credential will also remove the auth. if not credentials.is_new: await hass.auth.async_remove_credentials(credentials) connection.send_result(msg["id"]) return try: await provider.async_remove_auth(msg["username"]) except auth_ha.InvalidUser: connection.send_error( msg["id"], "auth_not_found", "Given username was not found." ) return connection.send_result(msg["id"])
[ "async", "def", "websocket_delete", "(", "hass", ",", "connection", ",", "msg", ")", ":", "provider", "=", "auth_ha", ".", "async_get_provider", "(", "hass", ")", "credentials", "=", "await", "provider", ".", "async_get_or_create_credentials", "(", "{", "\"username\"", ":", "msg", "[", "\"username\"", "]", "}", ")", "# if not new, an existing credential exists.", "# Removing the credential will also remove the auth.", "if", "not", "credentials", ".", "is_new", ":", "await", "hass", ".", "auth", ".", "async_remove_credentials", "(", "credentials", ")", "connection", ".", "send_result", "(", "msg", "[", "\"id\"", "]", ")", "return", "try", ":", "await", "provider", ".", "async_remove_auth", "(", "msg", "[", "\"username\"", "]", ")", "except", "auth_ha", ".", "InvalidUser", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"auth_not_found\"", ",", "\"Given username was not found.\"", ")", "return", "connection", ".", "send_result", "(", "msg", "[", "\"id\"", "]", ")" ]
[ 69, 0 ]
[ 92, 37 ]
python
en
['en', 'en', 'en']
True
websocket_change_password
(hass, connection, msg)
Change current user password.
Change current user password.
async def websocket_change_password(hass, connection, msg): """Change current user password.""" user = connection.user if user is None: connection.send_error(msg["id"], "user_not_found", "User not found") return provider = auth_ha.async_get_provider(hass) username = None for credential in user.credentials: if credential.auth_provider_type == provider.type: username = credential.data["username"] break if username is None: connection.send_error( msg["id"], "credentials_not_found", "Credentials not found" ) return try: await provider.async_validate_login(username, msg["current_password"]) except auth_ha.InvalidAuth: connection.send_error(msg["id"], "invalid_password", "Invalid password") return await provider.async_change_password(username, msg["new_password"]) connection.send_result(msg["id"])
[ "async", "def", "websocket_change_password", "(", "hass", ",", "connection", ",", "msg", ")", ":", "user", "=", "connection", ".", "user", "if", "user", "is", "None", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"user_not_found\"", ",", "\"User not found\"", ")", "return", "provider", "=", "auth_ha", ".", "async_get_provider", "(", "hass", ")", "username", "=", "None", "for", "credential", "in", "user", ".", "credentials", ":", "if", "credential", ".", "auth_provider_type", "==", "provider", ".", "type", ":", "username", "=", "credential", ".", "data", "[", "\"username\"", "]", "break", "if", "username", "is", "None", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"credentials_not_found\"", ",", "\"Credentials not found\"", ")", "return", "try", ":", "await", "provider", ".", "async_validate_login", "(", "username", ",", "msg", "[", "\"current_password\"", "]", ")", "except", "auth_ha", ".", "InvalidAuth", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"invalid_password\"", ",", "\"Invalid password\"", ")", "return", "await", "provider", ".", "async_change_password", "(", "username", ",", "msg", "[", "\"new_password\"", "]", ")", "connection", ".", "send_result", "(", "msg", "[", "\"id\"", "]", ")" ]
[ 103, 0 ]
[ 131, 37 ]
python
en
['fr', 'nl', 'en']
False
websocket_admin_change_password
(hass, connection, msg)
Change password of any user.
Change password of any user.
async def websocket_admin_change_password(hass, connection, msg): """Change password of any user.""" if not connection.user.is_owner: raise Unauthorized(context=connection.context(msg)) user = await hass.auth.async_get_user(msg["user_id"]) if user is None: connection.send_error(msg["id"], "user_not_found", "User not found") return provider = auth_ha.async_get_provider(hass) username = None for credential in user.credentials: if credential.auth_provider_type == provider.type: username = credential.data["username"] break if username is None: connection.send_error( msg["id"], "credentials_not_found", "Credentials not found" ) return try: await provider.async_change_password(username, msg["password"]) connection.send_result(msg["id"]) except auth_ha.InvalidUser: connection.send_error( msg["id"], "credentials_not_found", "Credentials not found" ) return
[ "async", "def", "websocket_admin_change_password", "(", "hass", ",", "connection", ",", "msg", ")", ":", "if", "not", "connection", ".", "user", ".", "is_owner", ":", "raise", "Unauthorized", "(", "context", "=", "connection", ".", "context", "(", "msg", ")", ")", "user", "=", "await", "hass", ".", "auth", ".", "async_get_user", "(", "msg", "[", "\"user_id\"", "]", ")", "if", "user", "is", "None", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"user_not_found\"", ",", "\"User not found\"", ")", "return", "provider", "=", "auth_ha", ".", "async_get_provider", "(", "hass", ")", "username", "=", "None", "for", "credential", "in", "user", ".", "credentials", ":", "if", "credential", ".", "auth_provider_type", "==", "provider", ".", "type", ":", "username", "=", "credential", ".", "data", "[", "\"username\"", "]", "break", "if", "username", "is", "None", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"credentials_not_found\"", ",", "\"Credentials not found\"", ")", "return", "try", ":", "await", "provider", ".", "async_change_password", "(", "username", ",", "msg", "[", "\"password\"", "]", ")", "connection", ".", "send_result", "(", "msg", "[", "\"id\"", "]", ")", "except", "auth_ha", ".", "InvalidUser", ":", "connection", ".", "send_error", "(", "msg", "[", "\"id\"", "]", ",", "\"credentials_not_found\"", ",", "\"Credentials not found\"", ")", "return" ]
[ 145, 0 ]
[ 177, 14 ]
python
en
['en', 'en', 'en']
True
DeviceHelper.try_bind_device
(device_info: DeviceInfo)
Try and bing with a discovered device. Note the you must bind with the device very quickly after it is discovered, or the process may not be completed correctly, raising a `CannotConnect` error.
Try and bing with a discovered device.
async def try_bind_device(device_info: DeviceInfo) -> Device: """Try and bing with a discovered device. Note the you must bind with the device very quickly after it is discovered, or the process may not be completed correctly, raising a `CannotConnect` error. """ device = Device(device_info) try: await device.bind() except DeviceNotBoundError as exception: raise CannotConnect from exception return device
[ "async", "def", "try_bind_device", "(", "device_info", ":", "DeviceInfo", ")", "->", "Device", ":", "device", "=", "Device", "(", "device_info", ")", "try", ":", "await", "device", ".", "bind", "(", ")", "except", "DeviceNotBoundError", "as", "exception", ":", "raise", "CannotConnect", "from", "exception", "return", "device" ]
[ 14, 4 ]
[ 25, 21 ]
python
en
['en', 'en', 'en']
True
DeviceHelper.find_devices
()
Gather a list of device infos from the local network.
Gather a list of device infos from the local network.
async def find_devices() -> List[DeviceInfo]: """Gather a list of device infos from the local network.""" return await Discovery.search_devices()
[ "async", "def", "find_devices", "(", ")", "->", "List", "[", "DeviceInfo", "]", ":", "return", "await", "Discovery", ".", "search_devices", "(", ")" ]
[ 28, 4 ]
[ 30, 47 ]
python
en
['en', 'en', 'en']
True
test_unload_entry
(hass, mock_simple_nws)
Test that nws setup with config yaml.
Test that nws setup with config yaml.
async def test_unload_entry(hass, mock_simple_nws): """Test that nws setup with config yaml.""" entry = MockConfigEntry( domain=DOMAIN, data=NWS_CONFIG, ) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 1 assert DOMAIN in hass.data assert len(hass.data[DOMAIN]) == 1 entries = hass.config_entries.async_entries(DOMAIN) assert len(entries) == 1 assert await hass.config_entries.async_unload(entries[0].entry_id) assert len(hass.states.async_entity_ids(WEATHER_DOMAIN)) == 0 assert DOMAIN not in hass.data
[ "async", "def", "test_unload_entry", "(", "hass", ",", "mock_simple_nws", ")", ":", "entry", "=", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "data", "=", "NWS_CONFIG", ",", ")", "entry", ".", "add_to_hass", "(", "hass", ")", "await", "hass", ".", "config_entries", ".", "async_setup", "(", "entry", ".", "entry_id", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_entity_ids", "(", "WEATHER_DOMAIN", ")", ")", "==", "1", "assert", "DOMAIN", "in", "hass", ".", "data", "assert", "len", "(", "hass", ".", "data", "[", "DOMAIN", "]", ")", "==", "1", "entries", "=", "hass", ".", "config_entries", ".", "async_entries", "(", "DOMAIN", ")", "assert", "len", "(", "entries", ")", "==", "1", "assert", "await", "hass", ".", "config_entries", ".", "async_unload", "(", "entries", "[", "0", "]", ".", "entry_id", ")", "assert", "len", "(", "hass", ".", "states", ".", "async_entity_ids", "(", "WEATHER_DOMAIN", ")", ")", "==", "0", "assert", "DOMAIN", "not", "in", "hass", ".", "data" ]
[ 8, 0 ]
[ 28, 34 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Clementine platform.
Set up the Clementine platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Clementine platform.""" host = config[CONF_HOST] port = config[CONF_PORT] token = config.get(CONF_ACCESS_TOKEN) client = ClementineRemote(host, port, token, reconnect=True) add_entities([ClementineDevice(client, config[CONF_NAME])])
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "host", "=", "config", "[", "CONF_HOST", "]", "port", "=", "config", "[", "CONF_PORT", "]", "token", "=", "config", ".", "get", "(", "CONF_ACCESS_TOKEN", ")", "client", "=", "ClementineRemote", "(", "host", ",", "port", ",", "token", ",", "reconnect", "=", "True", ")", "add_entities", "(", "[", "ClementineDevice", "(", "client", ",", "config", "[", "CONF_NAME", "]", ")", "]", ")" ]
[ 54, 0 ]
[ 63, 63 ]
python
en
['en', 'da', 'en']
True
ClementineDevice.__init__
(self, client, name)
Initialize the Clementine device.
Initialize the Clementine device.
def __init__(self, client, name): """Initialize the Clementine device.""" self._client = client self._name = name self._muted = False self._volume = 0.0 self._track_id = 0 self._last_track_id = 0 self._track_name = "" self._track_artist = "" self._track_album_name = "" self._state = None
[ "def", "__init__", "(", "self", ",", "client", ",", "name", ")", ":", "self", ".", "_client", "=", "client", "self", ".", "_name", "=", "name", "self", ".", "_muted", "=", "False", "self", ".", "_volume", "=", "0.0", "self", ".", "_track_id", "=", "0", "self", ".", "_last_track_id", "=", "0", "self", ".", "_track_name", "=", "\"\"", "self", ".", "_track_artist", "=", "\"\"", "self", ".", "_track_album_name", "=", "\"\"", "self", ".", "_state", "=", "None" ]
[ 69, 4 ]
[ 80, 26 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.update
(self)
Retrieve the latest data from the Clementine Player.
Retrieve the latest data from the Clementine Player.
def update(self): """Retrieve the latest data from the Clementine Player.""" try: client = self._client if client.state == "Playing": self._state = STATE_PLAYING elif client.state == "Paused": self._state = STATE_PAUSED elif client.state == "Disconnected": self._state = STATE_OFF else: self._state = STATE_PAUSED if client.last_update and (time.time() - client.last_update > 40): self._state = STATE_OFF self._volume = float(client.volume) if client.volume else 0.0 if client.current_track: self._track_id = client.current_track["track_id"] self._track_name = client.current_track["title"] self._track_artist = client.current_track["track_artist"] self._track_album_name = client.current_track["track_album"] except Exception: self._state = STATE_OFF raise
[ "def", "update", "(", "self", ")", ":", "try", ":", "client", "=", "self", ".", "_client", "if", "client", ".", "state", "==", "\"Playing\"", ":", "self", ".", "_state", "=", "STATE_PLAYING", "elif", "client", ".", "state", "==", "\"Paused\"", ":", "self", ".", "_state", "=", "STATE_PAUSED", "elif", "client", ".", "state", "==", "\"Disconnected\"", ":", "self", ".", "_state", "=", "STATE_OFF", "else", ":", "self", ".", "_state", "=", "STATE_PAUSED", "if", "client", ".", "last_update", "and", "(", "time", ".", "time", "(", ")", "-", "client", ".", "last_update", ">", "40", ")", ":", "self", ".", "_state", "=", "STATE_OFF", "self", ".", "_volume", "=", "float", "(", "client", ".", "volume", ")", "if", "client", ".", "volume", "else", "0.0", "if", "client", ".", "current_track", ":", "self", ".", "_track_id", "=", "client", ".", "current_track", "[", "\"track_id\"", "]", "self", ".", "_track_name", "=", "client", ".", "current_track", "[", "\"title\"", "]", "self", ".", "_track_artist", "=", "client", ".", "current_track", "[", "\"track_artist\"", "]", "self", ".", "_track_album_name", "=", "client", ".", "current_track", "[", "\"track_album\"", "]", "except", "Exception", ":", "self", ".", "_state", "=", "STATE_OFF", "raise" ]
[ 82, 4 ]
[ 109, 17 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.name
(self)
Return the name of the device.
Return the name of the device.
def name(self): """Return the name of the device.""" return self._name
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name" ]
[ 112, 4 ]
[ 114, 25 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.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" ]
[ 117, 4 ]
[ 119, 26 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.volume_level
(self)
Volume level of the media player (0..1).
Volume level of the media player (0..1).
def volume_level(self): """Volume level of the media player (0..1).""" return self._volume / 100.0
[ "def", "volume_level", "(", "self", ")", ":", "return", "self", ".", "_volume", "/", "100.0" ]
[ 122, 4 ]
[ 124, 35 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.source
(self)
Return current source name.
Return current source name.
def source(self): """Return current source name.""" source_name = "Unknown" client = self._client if client.active_playlist_id in client.playlists: source_name = client.playlists[client.active_playlist_id]["name"] return source_name
[ "def", "source", "(", "self", ")", ":", "source_name", "=", "\"Unknown\"", "client", "=", "self", ".", "_client", "if", "client", ".", "active_playlist_id", "in", "client", ".", "playlists", ":", "source_name", "=", "client", ".", "playlists", "[", "client", ".", "active_playlist_id", "]", "[", "\"name\"", "]", "return", "source_name" ]
[ 127, 4 ]
[ 133, 26 ]
python
en
['fr', 'ig', 'en']
False
ClementineDevice.source_list
(self)
List of available input sources.
List of available input sources.
def source_list(self): """List of available input sources.""" source_names = [s["name"] for s in self._client.playlists.values()] return source_names
[ "def", "source_list", "(", "self", ")", ":", "source_names", "=", "[", "s", "[", "\"name\"", "]", "for", "s", "in", "self", ".", "_client", ".", "playlists", ".", "values", "(", ")", "]", "return", "source_names" ]
[ 136, 4 ]
[ 139, 27 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.select_source
(self, source)
Select input source.
Select input source.
def select_source(self, source): """Select input source.""" client = self._client sources = [s for s in client.playlists.values() if s["name"] == source] if len(sources) == 1: client.change_song(sources[0]["id"], 0)
[ "def", "select_source", "(", "self", ",", "source", ")", ":", "client", "=", "self", ".", "_client", "sources", "=", "[", "s", "for", "s", "in", "client", ".", "playlists", ".", "values", "(", ")", "if", "s", "[", "\"name\"", "]", "==", "source", "]", "if", "len", "(", "sources", ")", "==", "1", ":", "client", ".", "change_song", "(", "sources", "[", "0", "]", "[", "\"id\"", "]", ",", "0", ")" ]
[ 141, 4 ]
[ 146, 51 ]
python
en
['fr', 'su', 'en']
False
ClementineDevice.media_content_type
(self)
Content type of current playing media.
Content type of current playing media.
def media_content_type(self): """Content type of current playing media.""" return MEDIA_TYPE_MUSIC
[ "def", "media_content_type", "(", "self", ")", ":", "return", "MEDIA_TYPE_MUSIC" ]
[ 149, 4 ]
[ 151, 31 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_title
(self)
Title of current playing media.
Title of current playing media.
def media_title(self): """Title of current playing media.""" return self._track_name
[ "def", "media_title", "(", "self", ")", ":", "return", "self", ".", "_track_name" ]
[ 154, 4 ]
[ 156, 31 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_artist
(self)
Artist of current playing media, music track only.
Artist of current playing media, music track only.
def media_artist(self): """Artist of current playing media, music track only.""" return self._track_artist
[ "def", "media_artist", "(", "self", ")", ":", "return", "self", ".", "_track_artist" ]
[ 159, 4 ]
[ 161, 33 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_album_name
(self)
Album name of current playing media, music track only.
Album name of current playing media, music track only.
def media_album_name(self): """Album name of current playing media, music track only.""" return self._track_album_name
[ "def", "media_album_name", "(", "self", ")", ":", "return", "self", ".", "_track_album_name" ]
[ 164, 4 ]
[ 166, 37 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.supported_features
(self)
Flag media player features that are supported.
Flag media player features that are supported.
def supported_features(self): """Flag media player features that are supported.""" return SUPPORT_CLEMENTINE
[ "def", "supported_features", "(", "self", ")", ":", "return", "SUPPORT_CLEMENTINE" ]
[ 169, 4 ]
[ 171, 33 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_image_hash
(self)
Hash value for media image.
Hash value for media image.
def media_image_hash(self): """Hash value for media image.""" if self._client.current_track: return self._client.current_track["track_id"] return None
[ "def", "media_image_hash", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "current_track", ":", "return", "self", ".", "_client", ".", "current_track", "[", "\"track_id\"", "]", "return", "None" ]
[ 174, 4 ]
[ 179, 19 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.async_get_media_image
(self)
Fetch media image of current playing image.
Fetch media image of current playing image.
async def async_get_media_image(self): """Fetch media image of current playing image.""" if self._client.current_track: image = bytes(self._client.current_track["art"]) return (image, "image/png") return None, None
[ "async", "def", "async_get_media_image", "(", "self", ")", ":", "if", "self", ".", "_client", ".", "current_track", ":", "image", "=", "bytes", "(", "self", ".", "_client", ".", "current_track", "[", "\"art\"", "]", ")", "return", "(", "image", ",", "\"image/png\"", ")", "return", "None", ",", "None" ]
[ 181, 4 ]
[ 187, 25 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.volume_up
(self)
Volume up the media player.
Volume up the media player.
def volume_up(self): """Volume up the media player.""" newvolume = min(self._client.volume + 4, 100) self._client.set_volume(newvolume)
[ "def", "volume_up", "(", "self", ")", ":", "newvolume", "=", "min", "(", "self", ".", "_client", ".", "volume", "+", "4", ",", "100", ")", "self", ".", "_client", ".", "set_volume", "(", "newvolume", ")" ]
[ 189, 4 ]
[ 192, 42 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.volume_down
(self)
Volume down media player.
Volume down media player.
def volume_down(self): """Volume down media player.""" newvolume = max(self._client.volume - 4, 0) self._client.set_volume(newvolume)
[ "def", "volume_down", "(", "self", ")", ":", "newvolume", "=", "max", "(", "self", ".", "_client", ".", "volume", "-", "4", ",", "0", ")", "self", ".", "_client", ".", "set_volume", "(", "newvolume", ")" ]
[ 194, 4 ]
[ 197, 42 ]
python
en
['en', 'sl', 'en']
True
ClementineDevice.mute_volume
(self, mute)
Send mute command.
Send mute command.
def mute_volume(self, mute): """Send mute command.""" self._client.set_volume(0)
[ "def", "mute_volume", "(", "self", ",", "mute", ")", ":", "self", ".", "_client", ".", "set_volume", "(", "0", ")" ]
[ 199, 4 ]
[ 201, 34 ]
python
en
['en', 'co', 'en']
True
ClementineDevice.set_volume_level
(self, volume)
Set volume level.
Set volume level.
def set_volume_level(self, volume): """Set volume level.""" self._client.set_volume(int(100 * volume))
[ "def", "set_volume_level", "(", "self", ",", "volume", ")", ":", "self", ".", "_client", ".", "set_volume", "(", "int", "(", "100", "*", "volume", ")", ")" ]
[ 203, 4 ]
[ 205, 50 ]
python
en
['fr', 'sr', 'en']
False
ClementineDevice.media_play_pause
(self)
Simulate play pause media player.
Simulate play pause media player.
def media_play_pause(self): """Simulate play pause media player.""" if self._state == STATE_PLAYING: self.media_pause() else: self.media_play()
[ "def", "media_play_pause", "(", "self", ")", ":", "if", "self", ".", "_state", "==", "STATE_PLAYING", ":", "self", ".", "media_pause", "(", ")", "else", ":", "self", ".", "media_play", "(", ")" ]
[ 207, 4 ]
[ 212, 29 ]
python
en
['en', 'en', 'it']
True
ClementineDevice.media_play
(self)
Send play command.
Send play command.
def media_play(self): """Send play command.""" self._state = STATE_PLAYING self._client.play()
[ "def", "media_play", "(", "self", ")", ":", "self", ".", "_state", "=", "STATE_PLAYING", "self", ".", "_client", ".", "play", "(", ")" ]
[ 214, 4 ]
[ 217, 27 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_pause
(self)
Send media pause command to media player.
Send media pause command to media player.
def media_pause(self): """Send media pause command to media player.""" self._state = STATE_PAUSED self._client.pause()
[ "def", "media_pause", "(", "self", ")", ":", "self", ".", "_state", "=", "STATE_PAUSED", "self", ".", "_client", ".", "pause", "(", ")" ]
[ 219, 4 ]
[ 222, 28 ]
python
en
['en', 'en', 'en']
True
ClementineDevice.media_next_track
(self)
Send next track command.
Send next track command.
def media_next_track(self): """Send next track command.""" self._client.next()
[ "def", "media_next_track", "(", "self", ")", ":", "self", ".", "_client", ".", "next", "(", ")" ]
[ 224, 4 ]
[ 226, 27 ]
python
en
['en', 'pt', 'en']
True
ClementineDevice.media_previous_track
(self)
Send the previous track command.
Send the previous track command.
def media_previous_track(self): """Send the previous track command.""" self._client.previous()
[ "def", "media_previous_track", "(", "self", ")", ":", "self", ".", "_client", ".", "previous", "(", ")" ]
[ 228, 4 ]
[ 230, 31 ]
python
en
['en', 'en', 'en']
True
test_form
(hass)
Test we get the form.
Test we get the form.
async def test_form(hass): """Test we get the form.""" await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) assert result["type"] == "form" assert result["errors"] == {} with patch("sense_energy.ASyncSenseable.authenticate", return_value=True,), patch( "homeassistant.components.sense.async_setup", return_value=True ) as mock_setup, patch( "homeassistant.components.sense.async_setup_entry", return_value=True, ) as mock_setup_entry: result2 = await hass.config_entries.flow.async_configure( result["flow_id"], {"timeout": "6", "email": "test-email", "password": "test-password"}, ) await hass.async_block_till_done() assert result2["type"] == "create_entry" assert result2["title"] == "test-email" assert result2["data"] == { "timeout": 6, "email": "test-email", "password": "test-password", } assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
[ "async", "def", "test_form", "(", "hass", ")", ":", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"persistent_notification\"", ",", "{", "}", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "assert", "result", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result", "[", "\"errors\"", "]", "==", "{", "}", "with", "patch", "(", "\"sense_energy.ASyncSenseable.authenticate\"", ",", "return_value", "=", "True", ",", ")", ",", "patch", "(", "\"homeassistant.components.sense.async_setup\"", ",", "return_value", "=", "True", ")", "as", "mock_setup", ",", "patch", "(", "\"homeassistant.components.sense.async_setup_entry\"", ",", "return_value", "=", "True", ",", ")", "as", "mock_setup_entry", ":", "result2", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"timeout\"", ":", "\"6\"", ",", "\"email\"", ":", "\"test-email\"", ",", "\"password\"", ":", "\"test-password\"", "}", ",", ")", "await", "hass", ".", "async_block_till_done", "(", ")", "assert", "result2", "[", "\"type\"", "]", "==", "\"create_entry\"", "assert", "result2", "[", "\"title\"", "]", "==", "\"test-email\"", "assert", "result2", "[", "\"data\"", "]", "==", "{", "\"timeout\"", ":", "6", ",", "\"email\"", ":", "\"test-email\"", ",", "\"password\"", ":", "\"test-password\"", ",", "}", "assert", "len", "(", "mock_setup", ".", "mock_calls", ")", "==", "1", "assert", "len", "(", "mock_setup_entry", ".", "mock_calls", ")", "==", "1" ]
[ 9, 0 ]
[ 38, 48 ]
python
en
['en', 'en', 'en']
True
test_form_invalid_auth
(hass)
Test we handle invalid auth.
Test we handle invalid auth.
async def test_form_invalid_auth(hass): """Test we handle invalid auth.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( "sense_energy.ASyncSenseable.authenticate", side_effect=SenseAuthenticationException, ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], {"timeout": "6", "email": "test-email", "password": "test-password"}, ) assert result2["type"] == "form" assert result2["errors"] == {"base": "invalid_auth"}
[ "async", "def", "test_form_invalid_auth", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "with", "patch", "(", "\"sense_energy.ASyncSenseable.authenticate\"", ",", "side_effect", "=", "SenseAuthenticationException", ",", ")", ":", "result2", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"timeout\"", ":", "\"6\"", ",", "\"email\"", ":", "\"test-email\"", ",", "\"password\"", ":", "\"test-password\"", "}", ",", ")", "assert", "result2", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result2", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "\"invalid_auth\"", "}" ]
[ 41, 0 ]
[ 57, 56 ]
python
en
['en', 'en', 'en']
True
test_form_cannot_connect
(hass)
Test we handle cannot connect error.
Test we handle cannot connect error.
async def test_form_cannot_connect(hass): """Test we handle cannot connect error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( "sense_energy.ASyncSenseable.authenticate", side_effect=SenseAPITimeoutException, ): result2 = await hass.config_entries.flow.async_configure( result["flow_id"], {"timeout": "6", "email": "test-email", "password": "test-password"}, ) assert result2["type"] == "form" assert result2["errors"] == {"base": "cannot_connect"}
[ "async", "def", "test_form_cannot_connect", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", "with", "patch", "(", "\"sense_energy.ASyncSenseable.authenticate\"", ",", "side_effect", "=", "SenseAPITimeoutException", ",", ")", ":", "result2", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_configure", "(", "result", "[", "\"flow_id\"", "]", ",", "{", "\"timeout\"", ":", "\"6\"", ",", "\"email\"", ":", "\"test-email\"", ",", "\"password\"", ":", "\"test-password\"", "}", ",", ")", "assert", "result2", "[", "\"type\"", "]", "==", "\"form\"", "assert", "result2", "[", "\"errors\"", "]", "==", "{", "\"base\"", ":", "\"cannot_connect\"", "}" ]
[ 60, 0 ]
[ 76, 58 ]
python
en
['en', 'en', 'en']
True
mock_client
(hass, hass_client)
Create http client for webhooks.
Create http client for webhooks.
def mock_client(hass, hass_client): """Create http client for webhooks.""" hass.loop.run_until_complete(async_setup_component(hass, "webhook", {})) return hass.loop.run_until_complete(hass_client())
[ "def", "mock_client", "(", "hass", ",", "hass_client", ")", ":", "hass", ".", "loop", ".", "run_until_complete", "(", "async_setup_component", "(", "hass", ",", "\"webhook\"", ",", "{", "}", ")", ")", "return", "hass", ".", "loop", ".", "run_until_complete", "(", "hass_client", "(", ")", ")" ]
[ 8, 0 ]
[ 11, 54 ]
python
en
['en', 'en', 'en']
True
test_unregistering_webhook
(hass, mock_client)
Test unregistering a webhook.
Test unregistering a webhook.
async def test_unregistering_webhook(hass, mock_client): """Test unregistering a webhook.""" hooks = [] webhook_id = hass.components.webhook.async_generate_id() async def handle(*args): """Handle webhook.""" hooks.append(args) hass.components.webhook.async_register("test", "Test hook", webhook_id, handle) resp = await mock_client.post(f"/api/webhook/{webhook_id}") assert resp.status == 200 assert len(hooks) == 1 hass.components.webhook.async_unregister(webhook_id) resp = await mock_client.post(f"/api/webhook/{webhook_id}") assert resp.status == 200 assert len(hooks) == 1
[ "async", "def", "test_unregistering_webhook", "(", "hass", ",", "mock_client", ")", ":", "hooks", "=", "[", "]", "webhook_id", "=", "hass", ".", "components", ".", "webhook", ".", "async_generate_id", "(", ")", "async", "def", "handle", "(", "*", "args", ")", ":", "\"\"\"Handle webhook.\"\"\"", "hooks", ".", "append", "(", "args", ")", "hass", ".", "components", ".", "webhook", ".", "async_register", "(", "\"test\"", ",", "\"Test hook\"", ",", "webhook_id", ",", "handle", ")", "resp", "=", "await", "mock_client", ".", "post", "(", "f\"/api/webhook/{webhook_id}\"", ")", "assert", "resp", ".", "status", "==", "200", "assert", "len", "(", "hooks", ")", "==", "1", "hass", ".", "components", ".", "webhook", ".", "async_unregister", "(", "webhook_id", ")", "resp", "=", "await", "mock_client", ".", "post", "(", "f\"/api/webhook/{webhook_id}\"", ")", "assert", "resp", ".", "status", "==", "200", "assert", "len", "(", "hooks", ")", "==", "1" ]
[ 14, 0 ]
[ 33, 26 ]
python
da
['en', 'da', 'it']
False
test_generate_webhook_url
(hass)
Test we generate a webhook url correctly.
Test we generate a webhook url correctly.
async def test_generate_webhook_url(hass): """Test we generate a webhook url correctly.""" await async_process_ha_core_config( hass, {"external_url": "https://example.com"}, ) url = hass.components.webhook.async_generate_url("some_id") assert url == "https://example.com/api/webhook/some_id"
[ "async", "def", "test_generate_webhook_url", "(", "hass", ")", ":", "await", "async_process_ha_core_config", "(", "hass", ",", "{", "\"external_url\"", ":", "\"https://example.com\"", "}", ",", ")", "url", "=", "hass", ".", "components", ".", "webhook", ".", "async_generate_url", "(", "\"some_id\"", ")", "assert", "url", "==", "\"https://example.com/api/webhook/some_id\"" ]
[ 36, 0 ]
[ 44, 59 ]
python
en
['en', 'en', 'en']
True