Search is not available for this dataset
identifier
stringlengths
1
155
parameters
stringlengths
2
6.09k
docstring
stringlengths
11
63.4k
docstring_summary
stringlengths
0
63.4k
function
stringlengths
29
99.8k
function_tokens
list
start_point
list
end_point
list
language
stringclasses
1 value
docstring_language
stringlengths
2
7
docstring_language_predictions
stringlengths
18
23
is_langid_reliable
stringclasses
2 values
test_multiple_delay_save_calls
(hass, store, hass_storage)
Test a write while a write with changing delays.
Test a write while a write with changing delays.
async def test_multiple_delay_save_calls(hass, store, hass_storage): """Test a write while a write with changing delays.""" store.async_delay_save(lambda: {"delay": "yes"}, 1) store.async_delay_save(lambda: {"delay": "yes"}, 2) store.async_delay_save(lambda: {"delay": "yes"}, 3) assert store.key no...
[ "async", "def", "test_multiple_delay_save_calls", "(", "hass", ",", "store", ",", "hass_storage", ")", ":", "store", ".", "async_delay_save", "(", "lambda", ":", "{", "\"delay\"", ":", "\"yes\"", "}", ",", "1", ")", "store", ".", "async_delay_save", "(", "la...
[ 188, 0 ]
[ 211, 34 ]
python
en
['en', 'en', 'en']
True
test_multiple_save_calls
(hass, store, hass_storage)
Test multiple write tasks.
Test multiple write tasks.
async def test_multiple_save_calls(hass, store, hass_storage): """Test multiple write tasks.""" assert store.key not in hass_storage tasks = [store.async_save({"savecount": savecount}) for savecount in range(6)] await asyncio.gather(*tasks) assert hass_storage[store.key] == { "version": MO...
[ "async", "def", "test_multiple_save_calls", "(", "hass", ",", "store", ",", "hass_storage", ")", ":", "assert", "store", ".", "key", "not", "in", "hass_storage", "tasks", "=", "[", "store", ".", "async_save", "(", "{", "\"savecount\"", ":", "savecount", "}",...
[ 214, 0 ]
[ 228, 35 ]
python
en
['mt', 'et', 'en']
False
test_migrator_no_existing_config
(hass, store, hass_storage)
Test migrator with no existing config.
Test migrator with no existing config.
async def test_migrator_no_existing_config(hass, store, hass_storage): """Test migrator with no existing config.""" with patch("os.path.isfile", return_value=False), patch.object( store, "async_load", return_value={"cur": "config"} ): data = await storage.async_migrator(hass, "old-path", sto...
[ "async", "def", "test_migrator_no_existing_config", "(", "hass", ",", "store", ",", "hass_storage", ")", ":", "with", "patch", "(", "\"os.path.isfile\"", ",", "return_value", "=", "False", ")", ",", "patch", ".", "object", "(", "store", ",", "\"async_load\"", ...
[ 231, 0 ]
[ 239, 40 ]
python
en
['en', 'en', 'en']
True
test_migrator_existing_config
(hass, store, hass_storage)
Test migrating existing config.
Test migrating existing config.
async def test_migrator_existing_config(hass, store, hass_storage): """Test migrating existing config.""" with patch("os.path.isfile", return_value=True), patch("os.remove") as mock_remove: data = await storage.async_migrator( hass, "old-path", store, old_conf_load_func=lambda _: {"old": "co...
[ "async", "def", "test_migrator_existing_config", "(", "hass", ",", "store", ",", "hass_storage", ")", ":", "with", "patch", "(", "\"os.path.isfile\"", ",", "return_value", "=", "True", ")", ",", "patch", "(", "\"os.remove\"", ")", "as", "mock_remove", ":", "da...
[ 242, 0 ]
[ 255, 5 ]
python
en
['de', 'en', 'en']
True
test_migrator_transforming_config
(hass, store, hass_storage)
Test migrating config to new format.
Test migrating config to new format.
async def test_migrator_transforming_config(hass, store, hass_storage): """Test migrating config to new format.""" async def old_conf_migrate_func(old_config): """Migrate old config to new format.""" return {"new": old_config["old"]} with patch("os.path.isfile", return_value=True), patch("...
[ "async", "def", "test_migrator_transforming_config", "(", "hass", ",", "store", ",", "hass_storage", ")", ":", "async", "def", "old_conf_migrate_func", "(", "old_config", ")", ":", "\"\"\"Migrate old config to new format.\"\"\"", "return", "{", "\"new\"", ":", "old_conf...
[ 258, 0 ]
[ 280, 5 ]
python
en
['en', 'en', 'en']
True
test_duplicate_error
(hass)
Test that errors are shown when duplicates are added.
Test that errors are shown when duplicates are added.
async def test_duplicate_error(hass): """Test that errors are shown when duplicates are added.""" conf = { CONF_IP_ADDRESS: "192.168.1.100", CONF_PASSWORD: "password", CONF_PORT: 8080, CONF_SSL: True, } MockConfigEntry(domain=DOMAIN, unique_id="192.168.1.100", data=conf)...
[ "async", "def", "test_duplicate_error", "(", "hass", ")", ":", "conf", "=", "{", "CONF_IP_ADDRESS", ":", "\"192.168.1.100\"", ",", "CONF_PASSWORD", ":", "\"password\"", ",", "CONF_PORT", ":", "8080", ",", "CONF_SSL", ":", "True", ",", "}", "MockConfigEntry", "...
[ 12, 0 ]
[ 29, 51 ]
python
en
['en', 'en', 'en']
True
test_invalid_password
(hass)
Test that an invalid password throws an error.
Test that an invalid password throws an error.
async def test_invalid_password(hass): """Test that an invalid password throws an error.""" conf = { CONF_IP_ADDRESS: "192.168.1.100", CONF_PASSWORD: "bad_password", CONF_PORT: 8080, CONF_SSL: True, } flow = config_flow.RainMachineFlowHandler() flow.hass = hass f...
[ "async", "def", "test_invalid_password", "(", "hass", ")", ":", "conf", "=", "{", "CONF_IP_ADDRESS", ":", "\"192.168.1.100\"", ",", "CONF_PASSWORD", ":", "\"bad_password\"", ",", "CONF_PORT", ":", "8080", ",", "CONF_SSL", ":", "True", ",", "}", "flow", "=", ...
[ 32, 0 ]
[ 50, 66 ]
python
en
['en', 'en', 'en']
True
test_options_flow
(hass)
Test config flow options.
Test config flow options.
async def test_options_flow(hass): """Test config flow options.""" conf = { CONF_IP_ADDRESS: "192.168.1.100", CONF_PASSWORD: "password", CONF_PORT: 8080, CONF_SSL: True, } config_entry = MockConfigEntry( domain=DOMAIN, unique_id="abcde12345", data...
[ "async", "def", "test_options_flow", "(", "hass", ")", ":", "conf", "=", "{", "CONF_IP_ADDRESS", ":", "\"192.168.1.100\"", ",", "CONF_PASSWORD", ":", "\"password\"", ",", "CONF_PORT", ":", "8080", ",", "CONF_SSL", ":", "True", ",", "}", "config_entry", "=", ...
[ 53, 0 ]
[ 84, 64 ]
python
en
['en', 'fr', 'en']
True
test_show_form
(hass)
Test that the form is served with no input.
Test that the form is served with no input.
async def test_show_form(hass): """Test that the form is served with no input.""" flow = config_flow.RainMachineFlowHandler() flow.hass = hass flow.context = {"source": SOURCE_USER} result = await flow.async_step_user(user_input=None) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM ...
[ "async", "def", "test_show_form", "(", "hass", ")", ":", "flow", "=", "config_flow", ".", "RainMachineFlowHandler", "(", ")", "flow", ".", "hass", "=", "hass", "flow", ".", "context", "=", "{", "\"source\"", ":", "SOURCE_USER", "}", "result", "=", "await",...
[ 87, 0 ]
[ 96, 38 ]
python
en
['en', 'en', 'en']
True
test_step_user
(hass)
Test that the user step works.
Test that the user step works.
async def test_step_user(hass): """Test that the user step works.""" conf = { CONF_IP_ADDRESS: "192.168.1.100", CONF_PASSWORD: "password", CONF_PORT: 8080, CONF_SSL: True, } flow = config_flow.RainMachineFlowHandler() flow.hass = hass flow.context = {"source": SO...
[ "async", "def", "test_step_user", "(", "hass", ")", ":", "conf", "=", "{", "CONF_IP_ADDRESS", ":", "\"192.168.1.100\"", ",", "CONF_PASSWORD", ":", "\"password\"", ",", "CONF_PORT", ":", "8080", ",", "CONF_SSL", ":", "True", ",", "}", "flow", "=", "config_flo...
[ 99, 0 ]
[ 126, 9 ]
python
en
['en', 'en', 'en']
True
Mutable.key
(self)
Read-only property of key.
Read-only property of key.
def key(self): """ Read-only property of key. """ return self._key
[ "def", "key", "(", "self", ")", ":", "return", "self", ".", "_key" ]
[ 63, 4 ]
[ 67, 24 ]
python
en
['en', 'error', 'th']
False
Mutable.name
(self)
After the search space is parsed, it will be the module name of the mutable.
After the search space is parsed, it will be the module name of the mutable.
def name(self): """ After the search space is parsed, it will be the module name of the mutable. """ return self._name if hasattr(self, "_name") else self._key
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_name", "if", "hasattr", "(", "self", ",", "\"_name\"", ")", "else", "self", ".", "_key" ]
[ 70, 4 ]
[ 74, 66 ]
python
en
['en', 'error', 'th']
False
LayerChoice.forward
(self, *args, **kwargs)
Returns ------- tuple of tensors Output and selection mask. If ``return_mask`` is ``False``, only output is returned.
Returns ------- tuple of tensors Output and selection mask. If ``return_mask`` is ``False``, only output is returned.
def forward(self, *args, **kwargs): """ Returns ------- tuple of tensors Output and selection mask. If ``return_mask`` is ``False``, only output is returned. """ out, mask = self.mutator.on_forward_layer_choice(self, *args, **kwargs) if self.return_mas...
[ "def", "forward", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "out", ",", "mask", "=", "self", ".", "mutator", ".", "on_forward_layer_choice", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "if", "self", ".", "...
[ 227, 4 ]
[ 237, 18 ]
python
en
['en', 'error', 'th']
False
InputChoice.forward
(self, optional_inputs)
Forward method of LayerChoice. Parameters ---------- optional_inputs : list or dict Recommended to be a dict. As a dict, inputs will be converted to a list that follows the order of ``choose_from`` in initialization. As a list, inputs must follow the semantic or...
Forward method of LayerChoice.
def forward(self, optional_inputs): """ Forward method of LayerChoice. Parameters ---------- optional_inputs : list or dict Recommended to be a dict. As a dict, inputs will be converted to a list that follows the order of ``choose_from`` in initialization...
[ "def", "forward", "(", "self", ",", "optional_inputs", ")", ":", "optional_input_list", "=", "optional_inputs", "if", "isinstance", "(", "optional_inputs", ",", "dict", ")", ":", "optional_input_list", "=", "[", "optional_inputs", "[", "tag", "]", "for", "tag", ...
[ 317, 4 ]
[ 343, 18 ]
python
en
['en', 'error', 'th']
False
run_download_docker
()
Run the Docker image to download the translations.
Run the Docker image to download the translations.
def run_download_docker(): """Run the Docker image to download the translations.""" print("Running Docker to download latest translations.") run = subprocess.run( [ "docker", "run", "-v", f"{DOWNLOAD_DIR}:/opt/dest/locale", "--rm", ...
[ "def", "run_download_docker", "(", ")", ":", "print", "(", "\"Running Docker to download latest translations.\"", ")", "run", "=", "subprocess", ".", "run", "(", "[", "\"docker\"", ",", "\"run\"", ",", "\"-v\"", ",", "f\"{DOWNLOAD_DIR}:/opt/dest/locale\"", ",", "\"--r...
[ 17, 0 ]
[ 50, 56 ]
python
en
['en', 'en', 'en']
True
save_json
(filename: str, data: Union[List, Dict])
Save JSON data to a file. Returns True on success.
Save JSON data to a file.
def save_json(filename: str, data: Union[List, Dict]): """Save JSON data to a file. Returns True on success. """ data = json.dumps(data, sort_keys=True, indent=4) with open(filename, "w", encoding="utf-8") as fdesc: fdesc.write(data) return True return False
[ "def", "save_json", "(", "filename", ":", "str", ",", "data", ":", "Union", "[", "List", ",", "Dict", "]", ")", ":", "data", "=", "json", ".", "dumps", "(", "data", ",", "sort_keys", "=", "True", ",", "indent", "=", "4", ")", "with", "open", "(",...
[ 53, 0 ]
[ 62, 16 ]
python
en
['en', 'en', 'en']
True
get_component_path
(lang, component)
Get the component translation path.
Get the component translation path.
def get_component_path(lang, component): """Get the component translation path.""" if os.path.isdir(os.path.join("homeassistant", "components", component)): return os.path.join( "homeassistant", "components", component, "translations", f"{lang}.json" ) raise ExitApp(f"Integration...
[ "def", "get_component_path", "(", "lang", ",", "component", ")", ":", "if", "os", ".", "path", ".", "isdir", "(", "os", ".", "path", ".", "join", "(", "\"homeassistant\"", ",", "\"components\"", ",", "component", ")", ")", ":", "return", "os", ".", "pa...
[ 65, 0 ]
[ 71, 87 ]
python
en
['en', 'en', 'en']
True
get_platform_path
(lang, component, platform)
Get the platform translation path.
Get the platform translation path.
def get_platform_path(lang, component, platform): """Get the platform translation path.""" return os.path.join( "homeassistant", "components", component, "translations", f"{platform}.{lang}.json", )
[ "def", "get_platform_path", "(", "lang", ",", "component", ",", "platform", ")", ":", "return", "os", ".", "path", ".", "join", "(", "\"homeassistant\"", ",", "\"components\"", ",", "component", ",", "\"translations\"", ",", "f\"{platform}.{lang}.json\"", ",", "...
[ 74, 0 ]
[ 82, 5 ]
python
en
['en', 'da', 'en']
True
get_component_translations
(translations)
Get the component level translations.
Get the component level translations.
def get_component_translations(translations): """Get the component level translations.""" translations = translations.copy() translations.pop("platform", None) return translations
[ "def", "get_component_translations", "(", "translations", ")", ":", "translations", "=", "translations", ".", "copy", "(", ")", "translations", ".", "pop", "(", "\"platform\"", ",", "None", ")", "return", "translations" ]
[ 85, 0 ]
[ 90, 23 ]
python
en
['en', 'en', 'en']
True
save_language_translations
(lang, translations)
Distribute the translations for this language.
Distribute the translations for this language.
def save_language_translations(lang, translations): """Distribute the translations for this language.""" components = translations.get("component", {}) for component, component_translations in components.items(): base_translations = get_component_translations(component_translations) if base_...
[ "def", "save_language_translations", "(", "lang", ",", "translations", ")", ":", "components", "=", "translations", ".", "get", "(", "\"component\"", ",", "{", "}", ")", "for", "component", ",", "component_translations", "in", "components", ".", "items", "(", ...
[ 93, 0 ]
[ 111, 50 ]
python
en
['en', 'en', 'en']
True
write_integration_translations
()
Write integration translations.
Write integration translations.
def write_integration_translations(): """Write integration translations.""" for lang_file in DOWNLOAD_DIR.glob("*.json"): lang = lang_file.stem translations = json.loads(lang_file.read_text()) save_language_translations(lang, translations)
[ "def", "write_integration_translations", "(", ")", ":", "for", "lang_file", "in", "DOWNLOAD_DIR", ".", "glob", "(", "\"*.json\"", ")", ":", "lang", "=", "lang_file", ".", "stem", "translations", "=", "json", ".", "loads", "(", "lang_file", ".", "read_text", ...
[ 114, 0 ]
[ 119, 54 ]
python
en
['en', 'ko', 'en']
True
delete_old_translations
()
Delete old translations.
Delete old translations.
def delete_old_translations(): """Delete old translations.""" for fil in INTEGRATIONS_DIR.glob("*/translations/*"): fil.unlink()
[ "def", "delete_old_translations", "(", ")", ":", "for", "fil", "in", "INTEGRATIONS_DIR", ".", "glob", "(", "\"*/translations/*\"", ")", ":", "fil", ".", "unlink", "(", ")" ]
[ 122, 0 ]
[ 125, 20 ]
python
en
['en', 'da', 'en']
True
run
()
Run the script.
Run the script.
def run(): """Run the script.""" DOWNLOAD_DIR.mkdir(parents=True, exist_ok=True) run_download_docker() delete_old_translations() write_integration_translations() return 0
[ "def", "run", "(", ")", ":", "DOWNLOAD_DIR", ".", "mkdir", "(", "parents", "=", "True", ",", "exist_ok", "=", "True", ")", "run_download_docker", "(", ")", "delete_old_translations", "(", ")", "write_integration_translations", "(", ")", "return", "0" ]
[ 128, 0 ]
[ 138, 12 ]
python
en
['en', 'co', 'en']
True
EntityExtractor.get_entities
(self, document)
Extract entities from a single document using the nltk.tree.ne_chunk method This method is called multiple times by the tranform method :param document: a list of lists of tuples :return entities: a list of comma-separated strings
Extract entities from a single document using the nltk.tree.ne_chunk method
def get_entities(self, document): """ Extract entities from a single document using the nltk.tree.ne_chunk method This method is called multiple times by the tranform method :param document: a list of lists of tuples :return entities: a list of comma-separated strings ...
[ "def", "get_entities", "(", "self", ",", "document", ")", ":", "entities", "=", "[", "]", "for", "paragraph", "in", "document", ":", "for", "sentence", "in", "paragraph", ":", "# classifier chunk the sentences, adds category labels, e.g. PERSON", "trees", "=", "ne_c...
[ 39, 4 ]
[ 63, 23 ]
python
en
['en', 'error', 'th']
False
EntityExtractor.transform
(self, documents)
Create a representation of the documents as a list of their entities
Create a representation of the documents as a list of their entities
def transform(self, documents): """ Create a representation of the documents as a list of their entities """ for document in documents: yield self.get_entities(document[0])
[ "def", "transform", "(", "self", ",", "documents", ")", ":", "for", "document", "in", "documents", ":", "yield", "self", ".", "get_entities", "(", "document", "[", "0", "]", ")" ]
[ 68, 4 ]
[ 73, 48 ]
python
en
['en', 'error', 'th']
False
EnOceanFlowHandler.__init__
(self)
Initialize the EnOcean config flow.
Initialize the EnOcean config flow.
def __init__(self): """Initialize the EnOcean config flow.""" self.dongle_path = None self.discovery_info = None
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "dongle_path", "=", "None", "self", ".", "discovery_info", "=", "None" ]
[ 20, 4 ]
[ 23, 34 ]
python
en
['en', 'fr', 'en']
True
EnOceanFlowHandler.async_step_import
(self, data=None)
Import a yaml configuration.
Import a yaml configuration.
async def async_step_import(self, data=None): """Import a yaml configuration.""" if not await self.validate_enocean_conf(data): LOGGER.warning( "Cannot import yaml configuration: %s is not a valid dongle path", data[CONF_DEVICE], ) ret...
[ "async", "def", "async_step_import", "(", "self", ",", "data", "=", "None", ")", ":", "if", "not", "await", "self", ".", "validate_enocean_conf", "(", "data", ")", ":", "LOGGER", ".", "warning", "(", "\"Cannot import yaml configuration: %s is not a valid dongle path...
[ 25, 4 ]
[ 35, 46 ]
python
en
['tr', 'ny', 'en']
False
EnOceanFlowHandler.async_step_user
(self, user_input=None)
Handle an EnOcean config flow start.
Handle an EnOcean config flow start.
async def async_step_user(self, user_input=None): """Handle an EnOcean config flow start.""" if self._async_current_entries(): return self.async_abort(reason="single_instance_allowed") return await self.async_step_detect()
[ "async", "def", "async_step_user", "(", "self", ",", "user_input", "=", "None", ")", ":", "if", "self", ".", "_async_current_entries", "(", ")", ":", "return", "self", ".", "async_abort", "(", "reason", "=", "\"single_instance_allowed\"", ")", "return", "await...
[ 37, 4 ]
[ 42, 45 ]
python
en
['en', 'nl', 'en']
True
EnOceanFlowHandler.async_step_detect
(self, user_input=None)
Propose a list of detected dongles.
Propose a list of detected dongles.
async def async_step_detect(self, user_input=None): """Propose a list of detected dongles.""" errors = {} if user_input is not None: if user_input[CONF_DEVICE] == self.MANUAL_PATH_VALUE: return await self.async_step_manual(None) if await self.validate_enoc...
[ "async", "def", "async_step_detect", "(", "self", ",", "user_input", "=", "None", ")", ":", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "if", "user_input", "[", "CONF_DEVICE", "]", "==", "self", ".", "MANUAL_PATH_VALUE", ":", "...
[ 44, 4 ]
[ 63, 9 ]
python
en
['en', 'en', 'en']
True
EnOceanFlowHandler.async_step_manual
(self, user_input=None)
Request manual USB dongle path.
Request manual USB dongle path.
async def async_step_manual(self, user_input=None): """Request manual USB dongle path.""" default_value = None errors = {} if user_input is not None: if await self.validate_enocean_conf(user_input): return self.create_enocean_entry(user_input) defa...
[ "async", "def", "async_step_manual", "(", "self", ",", "user_input", "=", "None", ")", ":", "default_value", "=", "None", "errors", "=", "{", "}", "if", "user_input", "is", "not", "None", ":", "if", "await", "self", ".", "validate_enocean_conf", "(", "user...
[ 65, 4 ]
[ 81, 9 ]
python
en
['ro', 'en', 'en']
True
EnOceanFlowHandler.validate_enocean_conf
(self, user_input)
Return True if the user_input contains a valid dongle path.
Return True if the user_input contains a valid dongle path.
async def validate_enocean_conf(self, user_input) -> bool: """Return True if the user_input contains a valid dongle path.""" dongle_path = user_input[CONF_DEVICE] path_is_valid = await self.hass.async_add_executor_job( dongle.validate_path, dongle_path ) return path_i...
[ "async", "def", "validate_enocean_conf", "(", "self", ",", "user_input", ")", "->", "bool", ":", "dongle_path", "=", "user_input", "[", "CONF_DEVICE", "]", "path_is_valid", "=", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "dongle", ".", "...
[ 83, 4 ]
[ 89, 28 ]
python
en
['en', 'en', 'en']
True
EnOceanFlowHandler.create_enocean_entry
(self, user_input)
Create an entry for the provided configuration.
Create an entry for the provided configuration.
def create_enocean_entry(self, user_input): """Create an entry for the provided configuration.""" return self.async_create_entry(title="EnOcean", data=user_input)
[ "def", "create_enocean_entry", "(", "self", ",", "user_input", ")", ":", "return", "self", ".", "async_create_entry", "(", "title", "=", "\"EnOcean\"", ",", "data", "=", "user_input", ")" ]
[ 91, 4 ]
[ 93, 72 ]
python
en
['en', 'en', 'en']
True
test_show_set_form
(hass)
Test that the setup form is served.
Test that the setup form is served.
async def test_show_set_form(hass): """Test that the setup form is served.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=None ) assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["step_id"] == "user"
[ "async", "def", "test_show_set_form", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ",", ...
[ 22, 0 ]
[ 29, 38 ]
python
en
['en', 'en', 'en']
True
test_connection_error
(hass, requests_mock)
Test we show user form on connection error.
Test we show user form on connection error.
async def test_connection_error(hass, requests_mock): """Test we show user form on connection error.""" requests_mock.request(ANY, ANY, exc=requests.exceptions.ConnectionError()) result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=FIXTURE_...
[ "async", "def", "test_connection_error", "(", "hass", ",", "requests_mock", ")", ":", "requests_mock", ".", "request", "(", "ANY", ",", "ANY", ",", "exc", "=", "requests", ".", "exceptions", ".", "ConnectionError", "(", ")", ")", "result", "=", "await", "h...
[ 32, 0 ]
[ 41, 57 ]
python
en
['en', 'en', 'en']
True
test_login_error
(hass, requests_mock)
Test we show user form with appropriate error on response failure.
Test we show user form with appropriate error on response failure.
async def test_login_error(hass, requests_mock): """Test we show user form with appropriate error on response failure.""" requests_mock.request( ANY, ANY, exc=UpCloudAPIError( error_code="AUTHENTICATION_FAILED", error_message="Authentication failed using the given...
[ "async", "def", "test_login_error", "(", "hass", ",", "requests_mock", ")", ":", "requests_mock", ".", "request", "(", "ANY", ",", "ANY", ",", "exc", "=", "UpCloudAPIError", "(", "error_code", "=", "\"AUTHENTICATION_FAILED\"", ",", "error_message", "=", "\"Authe...
[ 44, 0 ]
[ 60, 55 ]
python
en
['en', 'en', 'en']
True
test_success
(hass, requests_mock)
Test successful flow provides entry creation data.
Test successful flow provides entry creation data.
async def test_success(hass, requests_mock): """Test successful flow provides entry creation data.""" requests_mock.request(ANY, ANY, text='{"account":{"username":"user"}}') result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER}, data=FIXTURE_USER_...
[ "async", "def", "test_success", "(", "hass", ",", "requests_mock", ")", ":", "requests_mock", ".", "request", "(", "ANY", ",", "ANY", ",", "text", "=", "'{\"account\":{\"username\":\"user\"}}'", ")", "result", "=", "await", "hass", ".", "config_entries", ".", ...
[ 63, 0 ]
[ 72, 77 ]
python
en
['en', 'en', 'en']
True
test_options
(hass)
Test options produce expected data.
Test options produce expected data.
async def test_options(hass): """Test options produce expected data.""" config_entry = MockConfigEntry( domain=DOMAIN, data=FIXTURE_USER_INPUT, options=FIXTURE_USER_INPUT_OPTIONS ) config_entry.add_to_hass(hass) result = await hass.config_entries.options.async_init(config_entry.entry_id) ...
[ "async", "def", "test_options", "(", "hass", ")", ":", "config_entry", "=", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "data", "=", "FIXTURE_USER_INPUT", ",", "options", "=", "FIXTURE_USER_INPUT_OPTIONS", ")", "config_entry", ".", "add_to_hass", "(", ...
[ 75, 0 ]
[ 93, 5 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the Concord232 binary sensor platform.
Set up the Concord232 binary sensor platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the Concord232 binary sensor platform.""" host = config[CONF_HOST] port = config[CONF_PORT] exclude = config[CONF_EXCLUDE_ZONES] zone_types = config[CONF_ZONE_TYPES] sensors = [] try: _LOGGER.debug("Init...
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "host", "=", "config", "[", "CONF_HOST", "]", "port", "=", "config", "[", "CONF_PORT", "]", "exclude", "=", "config", "[", "CONF_EXCLUDE...
[ 47, 0 ]
[ 85, 31 ]
python
en
['en', 'pt', 'en']
True
get_opening_type
(zone)
Return the result of the type guessing from name.
Return the result of the type guessing from name.
def get_opening_type(zone): """Return the result of the type guessing from name.""" if "MOTION" in zone["name"]: return DEVICE_CLASS_MOTION if "KEY" in zone["name"]: return DEVICE_CLASS_SAFETY if "SMOKE" in zone["name"]: return DEVICE_CLASS_SMOKE if "WATER" in zone["name"]: ...
[ "def", "get_opening_type", "(", "zone", ")", ":", "if", "\"MOTION\"", "in", "zone", "[", "\"name\"", "]", ":", "return", "DEVICE_CLASS_MOTION", "if", "\"KEY\"", "in", "zone", "[", "\"name\"", "]", ":", "return", "DEVICE_CLASS_SAFETY", "if", "\"SMOKE\"", "in", ...
[ 88, 0 ]
[ 98, 31 ]
python
en
['en', 'en', 'en']
True
Concord232ZoneSensor.__init__
(self, hass, client, zone, zone_type)
Initialize the Concord232 binary sensor.
Initialize the Concord232 binary sensor.
def __init__(self, hass, client, zone, zone_type): """Initialize the Concord232 binary sensor.""" self._hass = hass self._client = client self._zone = zone self._number = zone["number"] self._zone_type = zone_type
[ "def", "__init__", "(", "self", ",", "hass", ",", "client", ",", "zone", ",", "zone_type", ")", ":", "self", ".", "_hass", "=", "hass", "self", ".", "_client", "=", "client", "self", ".", "_zone", "=", "zone", "self", ".", "_number", "=", "zone", "...
[ 104, 4 ]
[ 110, 35 ]
python
en
['en', 'it', 'en']
True
Concord232ZoneSensor.device_class
(self)
Return the class of this sensor, from DEVICE_CLASSES.
Return the class of this sensor, from DEVICE_CLASSES.
def device_class(self): """Return the class of this sensor, from DEVICE_CLASSES.""" return self._zone_type
[ "def", "device_class", "(", "self", ")", ":", "return", "self", ".", "_zone_type" ]
[ 113, 4 ]
[ 115, 30 ]
python
en
['en', 'en', 'en']
True
Concord232ZoneSensor.name
(self)
Return the name of the binary sensor.
Return the name of the binary sensor.
def name(self): """Return the name of the binary sensor.""" return self._zone["name"]
[ "def", "name", "(", "self", ")", ":", "return", "self", ".", "_zone", "[", "\"name\"", "]" ]
[ 118, 4 ]
[ 120, 33 ]
python
en
['en', 'mi', 'en']
True
Concord232ZoneSensor.is_on
(self)
Return true if the binary sensor is on.
Return true if the binary sensor is on.
def is_on(self): """Return true if the binary sensor is on.""" # True means "faulted" or "open" or "abnormal state" return bool(self._zone["state"] != "Normal")
[ "def", "is_on", "(", "self", ")", ":", "# True means \"faulted\" or \"open\" or \"abnormal state\"", "return", "bool", "(", "self", ".", "_zone", "[", "\"state\"", "]", "!=", "\"Normal\"", ")" ]
[ 123, 4 ]
[ 126, 52 ]
python
en
['en', 'fy', 'en']
True
Concord232ZoneSensor.update
(self)
Get updated stats from API.
Get updated stats from API.
def update(self): """Get updated stats from API.""" last_update = dt_util.utcnow() - self._client.last_zone_update _LOGGER.debug("Zone: %s ", self._zone) if last_update > datetime.timedelta(seconds=1): self._client.zones = self._client.list_zones() self._client.la...
[ "def", "update", "(", "self", ")", ":", "last_update", "=", "dt_util", ".", "utcnow", "(", ")", "-", "self", ".", "_client", ".", "last_zone_update", "_LOGGER", ".", "debug", "(", "\"Zone: %s \"", ",", "self", ".", "_zone", ")", "if", "last_update", ">",...
[ 128, 4 ]
[ 140, 13 ]
python
en
['en', 'en', 'en']
True
async_setup
(hass: core.HomeAssistant, config: dict)
Set up the Xiaomi Miio component.
Set up the Xiaomi Miio component.
async def async_setup(hass: core.HomeAssistant, config: dict): """Set up the Xiaomi Miio component.""" return True
[ "async", "def", "async_setup", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "return", "True" ]
[ 12, 0 ]
[ 14, 15 ]
python
en
['en', 'ca', 'en']
True
async_setup_entry
( hass: core.HomeAssistant, entry: config_entries.ConfigEntry )
Set up the Xiaomi Miio components from a config entry.
Set up the Xiaomi Miio components from a config entry.
async def async_setup_entry( hass: core.HomeAssistant, entry: config_entries.ConfigEntry ): """Set up the Xiaomi Miio components from a config entry.""" hass.data[DOMAIN] = {} if entry.data[CONF_FLOW_TYPE] == CONF_GATEWAY: if not await async_setup_gateway_entry(hass, entry): return F...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "entry", ":", "config_entries", ".", "ConfigEntry", ")", ":", "hass", ".", "data", "[", "DOMAIN", "]", "=", "{", "}", "if", "entry", ".", "data", "[", "CONF_FLOW_TY...
[ 17, 0 ]
[ 26, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_gateway_entry
( hass: core.HomeAssistant, entry: config_entries.ConfigEntry )
Set up the Xiaomi Gateway component from a config entry.
Set up the Xiaomi Gateway component from a config entry.
async def async_setup_gateway_entry( hass: core.HomeAssistant, entry: config_entries.ConfigEntry ): """Set up the Xiaomi Gateway component from a config entry.""" host = entry.data[CONF_HOST] token = entry.data[CONF_TOKEN] name = entry.title gateway_id = entry.unique_id # For backwards comp...
[ "async", "def", "async_setup_gateway_entry", "(", "hass", ":", "core", ".", "HomeAssistant", ",", "entry", ":", "config_entries", ".", "ConfigEntry", ")", ":", "host", "=", "entry", ".", "data", "[", "CONF_HOST", "]", "token", "=", "entry", ".", "data", "[...
[ 29, 0 ]
[ 68, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: Callable[[list], None], )
Set up the ISY994 light platform.
Set up the ISY994 light platform.
async def async_setup_entry( hass: HomeAssistantType, entry: ConfigEntry, async_add_entities: Callable[[list], None], ) -> bool: """Set up the ISY994 light platform.""" hass_isy_data = hass.data[ISY994_DOMAIN][entry.entry_id] isy_options = entry.options restore_light_state = isy_options.get(...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistantType", ",", "entry", ":", "ConfigEntry", ",", "async_add_entities", ":", "Callable", "[", "[", "list", "]", ",", "None", "]", ",", ")", "->", "bool", ":", "hass_isy_data", "=", "hass", "....
[ 28, 0 ]
[ 44, 36 ]
python
en
['en', 'ky', 'en']
True
ISYLightEntity.__init__
(self, node, restore_light_state)
Initialize the ISY994 light device.
Initialize the ISY994 light device.
def __init__(self, node, restore_light_state) -> None: """Initialize the ISY994 light device.""" super().__init__(node) self._last_brightness = None self._restore_light_state = restore_light_state
[ "def", "__init__", "(", "self", ",", "node", ",", "restore_light_state", ")", "->", "None", ":", "super", "(", ")", ".", "__init__", "(", "node", ")", "self", ".", "_last_brightness", "=", "None", "self", ".", "_restore_light_state", "=", "restore_light_stat...
[ 50, 4 ]
[ 54, 55 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.is_on
(self)
Get whether the ISY994 light is on.
Get whether the ISY994 light is on.
def is_on(self) -> bool: """Get whether the ISY994 light is on.""" if self._node.status == ISY_VALUE_UNKNOWN: return False return int(self._node.status) != 0
[ "def", "is_on", "(", "self", ")", "->", "bool", ":", "if", "self", ".", "_node", ".", "status", "==", "ISY_VALUE_UNKNOWN", ":", "return", "False", "return", "int", "(", "self", ".", "_node", ".", "status", ")", "!=", "0" ]
[ 57, 4 ]
[ 61, 42 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.brightness
(self)
Get the brightness of the ISY994 light.
Get the brightness of the ISY994 light.
def brightness(self) -> float: """Get the brightness of the ISY994 light.""" if self._node.status == ISY_VALUE_UNKNOWN: return None # Special Case for ISY Z-Wave Devices using % instead of 0-255: if self._node.uom == UOM_PERCENTAGE: return round(self._node.status ...
[ "def", "brightness", "(", "self", ")", "->", "float", ":", "if", "self", ".", "_node", ".", "status", "==", "ISY_VALUE_UNKNOWN", ":", "return", "None", "# Special Case for ISY Z-Wave Devices using % instead of 0-255:", "if", "self", ".", "_node", ".", "uom", "==",...
[ 64, 4 ]
[ 71, 37 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.turn_off
(self, **kwargs)
Send the turn off command to the ISY994 light device.
Send the turn off command to the ISY994 light device.
def turn_off(self, **kwargs) -> None: """Send the turn off command to the ISY994 light device.""" self._last_brightness = self.brightness if not self._node.turn_off(): _LOGGER.debug("Unable to turn off light")
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "self", ".", "_last_brightness", "=", "self", ".", "brightness", "if", "not", "self", ".", "_node", ".", "turn_off", "(", ")", ":", "_LOGGER", ".", "debug", "(", "\"Unab...
[ 73, 4 ]
[ 77, 53 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.on_update
(self, event: object)
Save brightness in the update event from the ISY994 Node.
Save brightness in the update event from the ISY994 Node.
def on_update(self, event: object) -> None: """Save brightness in the update event from the ISY994 Node.""" if self._node.status not in (0, ISY_VALUE_UNKNOWN): if self._node.uom == UOM_PERCENTAGE: self._last_brightness = round(self._node.status * 255.0 / 100.0) el...
[ "def", "on_update", "(", "self", ",", "event", ":", "object", ")", "->", "None", ":", "if", "self", ".", "_node", ".", "status", "not", "in", "(", "0", ",", "ISY_VALUE_UNKNOWN", ")", ":", "if", "self", ".", "_node", ".", "uom", "==", "UOM_PERCENTAGE"...
[ 79, 4 ]
[ 86, 32 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.turn_on
(self, brightness=None, **kwargs)
Send the turn on command to the ISY994 light device.
Send the turn on command to the ISY994 light device.
def turn_on(self, brightness=None, **kwargs) -> None: """Send the turn on command to the ISY994 light device.""" if self._restore_light_state and brightness is None and self._last_brightness: brightness = self._last_brightness # Special Case for ISY Z-Wave Devices using % instead of ...
[ "def", "turn_on", "(", "self", ",", "brightness", "=", "None", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "self", ".", "_restore_light_state", "and", "brightness", "is", "None", "and", "self", ".", "_last_brightness", ":", "brightness", "=", ...
[ 89, 4 ]
[ 97, 52 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.device_state_attributes
(self)
Return the light attributes.
Return the light attributes.
def device_state_attributes(self) -> Dict: """Return the light attributes.""" attribs = super().device_state_attributes attribs[ATTR_LAST_BRIGHTNESS] = self._last_brightness return attribs
[ "def", "device_state_attributes", "(", "self", ")", "->", "Dict", ":", "attribs", "=", "super", "(", ")", ".", "device_state_attributes", "attribs", "[", "ATTR_LAST_BRIGHTNESS", "]", "=", "self", ".", "_last_brightness", "return", "attribs" ]
[ 100, 4 ]
[ 104, 22 ]
python
en
['en', 'sq', 'en']
True
ISYLightEntity.supported_features
(self)
Flag supported features.
Flag supported features.
def supported_features(self): """Flag supported features.""" return SUPPORT_BRIGHTNESS
[ "def", "supported_features", "(", "self", ")", ":", "return", "SUPPORT_BRIGHTNESS" ]
[ 107, 4 ]
[ 109, 33 ]
python
en
['da', 'en', 'en']
True
ISYLightEntity.async_added_to_hass
(self)
Restore last_brightness on restart.
Restore last_brightness on restart.
async def async_added_to_hass(self) -> None: """Restore last_brightness on restart.""" await super().async_added_to_hass() self._last_brightness = self.brightness or 255 last_state = await self.async_get_last_state() if not last_state: return if ( ...
[ "async", "def", "async_added_to_hass", "(", "self", ")", "->", "None", ":", "await", "super", "(", ")", ".", "async_added_to_hass", "(", ")", "self", ".", "_last_brightness", "=", "self", ".", "brightness", "or", "255", "last_state", "=", "await", "self", ...
[ 111, 4 ]
[ 124, 79 ]
python
en
['en', 'sv', 'en']
True
ISYLightEntity.set_on_level
(self, value)
Set the ON Level for a device.
Set the ON Level for a device.
def set_on_level(self, value): """Set the ON Level for a device.""" self._node.set_on_level(value)
[ "def", "set_on_level", "(", "self", ",", "value", ")", ":", "self", ".", "_node", ".", "set_on_level", "(", "value", ")" ]
[ 126, 4 ]
[ 128, 38 ]
python
en
['en', 'en', 'en']
True
ISYLightEntity.set_ramp_rate
(self, value)
Set the Ramp Rate for a device.
Set the Ramp Rate for a device.
def set_ramp_rate(self, value): """Set the Ramp Rate for a device.""" self._node.set_ramp_rate(value)
[ "def", "set_ramp_rate", "(", "self", ",", "value", ")", ":", "self", ".", "_node", ".", "set_ramp_rate", "(", "value", ")" ]
[ 130, 4 ]
[ 132, 39 ]
python
en
['en', 'en', 'en']
True
test_form_and_auth
(hass)
Test we get the form.
Test we get the form.
async def test_form_and_auth(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 resul...
[ "async", "def", "test_form_and_auth", "(", "hass", ")", ":", "await", "setup", ".", "async_setup_component", "(", "hass", ",", "\"persistent_notification\"", ",", "{", "}", ")", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_in...
[ 26, 0 ]
[ 59, 48 ]
python
en
['en', 'en', 'en']
True
test_form_no_token
(hass)
Test we handle no token being returned (timeout or not authorized).
Test we handle no token being returned (timeout or not authorized).
async def test_form_no_token(hass): """Test we handle no token being returned (timeout or not authorized).""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch("homeassistant.components.roon.config_flow.TIMEOUT", 0,), patch( ...
[ "async", "def", "test_form_no_token", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ")", ...
[ 62, 0 ]
[ 83, 56 ]
python
en
['en', 'en', 'en']
True
test_form_unknown_exception
(hass)
Test we handle cannot connect error.
Test we handle cannot connect error.
async def test_form_unknown_exception(hass): """Test we handle cannot connect error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) with patch( "homeassistant.components.roon.config_flow.RoonApi", side_effect=Excep...
[ "async", "def", "test_form_unknown_exception", "(", "hass", ")", ":", "result", "=", "await", "hass", ".", "config_entries", ".", "flow", ".", "async_init", "(", "DOMAIN", ",", "context", "=", "{", "\"source\"", ":", "config_entries", ".", "SOURCE_USER", "}", ...
[ 86, 0 ]
[ 105, 51 ]
python
en
['en', 'en', 'en']
True
test_form_host_already_exists
(hass)
Test we add the host if the config exists and it isn't a duplicate.
Test we add the host if the config exists and it isn't a duplicate.
async def test_form_host_already_exists(hass): """Test we add the host if the config exists and it isn't a duplicate.""" MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "existing_host"}).add_to_hass(hass) await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config...
[ "async", "def", "test_form_host_already_exists", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "data", "=", "{", "CONF_HOST", ":", "\"existing_host\"", "}", ")", ".", "add_to_hass", "(", "hass", ")", "await", "setup", ".", "asy...
[ 108, 0 ]
[ 144, 48 ]
python
en
['en', 'en', 'en']
True
test_form_duplicate_host
(hass)
Test we don't add the host if it's a duplicate.
Test we don't add the host if it's a duplicate.
async def test_form_duplicate_host(hass): """Test we don't add the host if it's a duplicate.""" MockConfigEntry(domain=DOMAIN, data={CONF_HOST: "existing_host"}).add_to_hass(hass) await setup.async_setup_component(hass, "persistent_notification", {}) result = await hass.config_entries.flow.async_init(...
[ "async", "def", "test_form_duplicate_host", "(", "hass", ")", ":", "MockConfigEntry", "(", "domain", "=", "DOMAIN", ",", "data", "=", "{", "CONF_HOST", ":", "\"existing_host\"", "}", ")", ".", "add_to_hass", "(", "hass", ")", "await", "setup", ".", "async_se...
[ 147, 0 ]
[ 164, 59 ]
python
en
['en', 'en', 'en']
True
RoonApiMock.__init__
(self, token)
Initialize.
Initialize.
def __init__(self, token): """Initialize.""" self._token = token
[ "def", "__init__", "(", "self", ",", "token", ")", ":", "self", ".", "_token", "=", "token" ]
[ 12, 4 ]
[ 14, 27 ]
python
en
['en', 'en', 'it']
False
RoonApiMock.token
(self)
Return the auth token from the api.
Return the auth token from the api.
def token(self): """Return the auth token from the api.""" return self._token
[ "def", "token", "(", "self", ")", ":", "return", "self", ".", "_token" ]
[ 17, 4 ]
[ 19, 26 ]
python
en
['en', 'en', 'en']
True
RoonApiMock.stop
(self)
Close down the api.
Close down the api.
def stop(self): # pylint: disable=no-self-use """Close down the api.""" return
[ "def", "stop", "(", "self", ")", ":", "# pylint: disable=no-self-use", "return" ]
[ 21, 4 ]
[ 23, 14 ]
python
en
['en', 'pt', 'en']
True
convert
(src_path: str, map_location: str = "cpu", save_path: Union[str, None] = None)
Convert a pytorch_model.bin or model.pt file to torch.float16 for faster downloads, less disk space.
Convert a pytorch_model.bin or model.pt file to torch.float16 for faster downloads, less disk space.
def convert(src_path: str, map_location: str = "cpu", save_path: Union[str, None] = None) -> None: """Convert a pytorch_model.bin or model.pt file to torch.float16 for faster downloads, less disk space.""" state_dict = torch.load(src_path, map_location=map_location) for k, v in tqdm(state_dict.items()): ...
[ "def", "convert", "(", "src_path", ":", "str", ",", "map_location", ":", "str", "=", "\"cpu\"", ",", "save_path", ":", "Union", "[", "str", ",", "None", "]", "=", "None", ")", "->", "None", ":", "state_dict", "=", "torch", ".", "load", "(", "src_path...
[ 22, 0 ]
[ 31, 37 ]
python
en
['en', 'en', 'en']
True
build_relative_position
(query_size, key_size, bucket_size=-1, max_position=-1)
Build relative position according to the query and key We assume the absolute position of query :math:`P_q` is range from (0, query_size) and the absolute position of key :math:`P_k` is range from (0, key_size), The relative positions from query to key is :math:`R_{q \\rightarrow k} = P_q - P_k` ...
Build relative position according to the query and key
def build_relative_position(query_size, key_size, bucket_size=-1, max_position=-1): """ Build relative position according to the query and key We assume the absolute position of query :math:`P_q` is range from (0, query_size) and the absolute position of key :math:`P_k` is range from (0, key_size), The...
[ "def", "build_relative_position", "(", "query_size", ",", "key_size", ",", "bucket_size", "=", "-", "1", ",", "max_position", "=", "-", "1", ")", ":", "q_ids", "=", "np", ".", "arange", "(", "0", ",", "query_size", ")", "k_ids", "=", "np", ".", "arange...
[ 501, 0 ]
[ 527, 22 ]
python
en
['en', 'error', 'th']
False
StableDropout.forward
(self, x)
Call the module Args: x (:obj:`torch.tensor`): The input tensor to apply dropout
Call the module
def forward(self, x): """ Call the module Args: x (:obj:`torch.tensor`): The input tensor to apply dropout """ if self.training and self.drop_prob > 0: return XDropout.apply(x, self.get_context()) return x
[ "def", "forward", "(", "self", ",", "x", ")", ":", "if", "self", ".", "training", "and", "self", ".", "drop_prob", ">", "0", ":", "return", "XDropout", ".", "apply", "(", "x", ",", "self", ".", "get_context", "(", ")", ")", "return", "x" ]
[ 184, 4 ]
[ 193, 16 ]
python
en
['en', 'error', 'th']
False
DisentangledSelfAttention.forward
( self, hidden_states, attention_mask, return_att=False, query_states=None, relative_pos=None, rel_embeddings=None, )
Call the module Args: hidden_states (:obj:`torch.FloatTensor`): Input states to the module usually the output from previous layer, it will be the Q,K and V in `Attention(Q,K,V)` attention_mask (:obj:`torch.ByteTensor`): An attent...
Call the module
def forward( self, hidden_states, attention_mask, return_att=False, query_states=None, relative_pos=None, rel_embeddings=None, ): """ Call the module Args: hidden_states (:obj:`torch.FloatTensor`): Input sta...
[ "def", "forward", "(", "self", ",", "hidden_states", ",", "attention_mask", ",", "return_att", "=", "False", ",", "query_states", "=", "None", ",", "relative_pos", "=", "None", ",", "rel_embeddings", "=", "None", ",", ")", ":", "if", "query_states", "is", ...
[ 602, 4 ]
[ 686, 32 ]
python
en
['en', 'error', 'th']
False
DebertaV2PreTrainedModel._init_weights
(self, module)
Initialize the weights.
Initialize the weights.
def _init_weights(self, module): """Initialize the weights.""" if isinstance(module, nn.Linear): # Slightly different from the TF version which uses truncated_normal for initialization # cf https://github.com/pytorch/pytorch/pull/5617 module.weight.data.normal_(mean=0...
[ "def", "_init_weights", "(", "self", ",", "module", ")", ":", "if", "isinstance", "(", "module", ",", "nn", ".", "Linear", ")", ":", "# Slightly different from the TF version which uses truncated_normal for initialization", "# cf https://github.com/pytorch/pytorch/pull/5617", ...
[ 887, 4 ]
[ 898, 62 ]
python
en
['en', 'en', 'en']
True
DebertaV2PreTrainedModel._pre_load_hook
(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs)
Removes the classifier if it doesn't have the correct number of labels.
Removes the classifier if it doesn't have the correct number of labels.
def _pre_load_hook(self, state_dict, prefix, local_metadata, strict, missing_keys, unexpected_keys, error_msgs): """ Removes the classifier if it doesn't have the correct number of labels. """ self_state = self.state_dict() if ( ("classifier.weight" in self_state) ...
[ "def", "_pre_load_hook", "(", "self", ",", "state_dict", ",", "prefix", ",", "local_metadata", ",", "strict", ",", "missing_keys", ",", "unexpected_keys", ",", "error_msgs", ")", ":", "self_state", "=", "self", ".", "state_dict", "(", ")", "if", "(", "(", ...
[ 900, 4 ]
[ 917, 49 ]
python
en
['en', 'error', 'th']
False
netdisco_mock
()
Mock netdisco.
Mock netdisco.
def netdisco_mock(): """Mock netdisco.""" with patch.dict("sys.modules", {"netdisco.discovery": MagicMock()}): yield
[ "def", "netdisco_mock", "(", ")", ":", "with", "patch", ".", "dict", "(", "\"sys.modules\"", ",", "{", "\"netdisco.discovery\"", ":", "MagicMock", "(", ")", "}", ")", ":", "yield" ]
[ 31, 0 ]
[ 34, 13 ]
python
en
['en', 'xh', 'en']
False
mock_discovery
(hass, discoveries, config=BASE_CONFIG)
Mock discoveries.
Mock discoveries.
async def mock_discovery(hass, discoveries, config=BASE_CONFIG): """Mock discoveries.""" with patch("homeassistant.components.zeroconf.async_get_instance"), patch( "homeassistant.components.zeroconf.async_setup", return_value=True ): assert await async_setup_component(hass, "discovery", conf...
[ "async", "def", "mock_discovery", "(", "hass", ",", "discoveries", ",", "config", "=", "BASE_CONFIG", ")", ":", "with", "patch", "(", "\"homeassistant.components.zeroconf.async_get_instance\"", ")", ",", "patch", "(", "\"homeassistant.components.zeroconf.async_setup\"", "...
[ 37, 0 ]
[ 59, 39 ]
python
en
['en', 'en', 'en']
False
test_unknown_service
(hass)
Test that unknown service is ignored.
Test that unknown service is ignored.
async def test_unknown_service(hass): """Test that unknown service is ignored.""" def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [("this_service_will_never_be_supported", {"info": "some"})] mock_discover, mock_platform = await mock_discovery(hass, discover) as...
[ "async", "def", "test_unknown_service", "(", "hass", ")", ":", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "\"this_service_will_never_be_supported\"", ",", "{", "\"info\"", ":", "\"some\"",...
[ 62, 0 ]
[ 72, 35 ]
python
en
['en', 'en', 'en']
True
test_load_platform
(hass)
Test load a platform.
Test load a platform.
async def test_load_platform(hass): """Test load a platform.""" def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE, SERVICE_INFO)] mock_discover, mock_platform = await mock_discovery(hass, discover) assert not mock_discover.called assert mock_platfor...
[ "async", "def", "test_load_platform", "(", "hass", ")", ":", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "SERVICE", ",", "SERVICE_INFO", ")", "]", "mock_discover", ",", "mock_platform",...
[ 75, 0 ]
[ 88, 5 ]
python
en
['en', 'da', 'en']
True
test_load_component
(hass)
Test load a component.
Test load a component.
async def test_load_component(hass): """Test load a component.""" def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE_NO_PLATFORM, SERVICE_INFO)] mock_discover, mock_platform = await mock_discovery(hass, discover) assert mock_discover.called assert no...
[ "async", "def", "test_load_component", "(", "hass", ")", ":", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "SERVICE_NO_PLATFORM", ",", "SERVICE_INFO", ")", "]", "mock_discover", ",", "mo...
[ 91, 0 ]
[ 108, 5 ]
python
en
['en', 'en', 'en']
True
test_ignore_service
(hass)
Test ignore service.
Test ignore service.
async def test_ignore_service(hass): """Test ignore service.""" def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [(SERVICE_NO_PLATFORM, SERVICE_INFO)] mock_discover, mock_platform = await mock_discovery(hass, discover, IGNORE_CONFIG) assert not mock_discover.cal...
[ "async", "def", "test_ignore_service", "(", "hass", ")", ":", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "SERVICE_NO_PLATFORM", ",", "SERVICE_INFO", ")", "]", "mock_discover", ",", "mo...
[ 111, 0 ]
[ 121, 35 ]
python
en
['en', 'it', 'en']
True
test_discover_duplicates
(hass)
Test load a component.
Test load a component.
async def test_discover_duplicates(hass): """Test load a component.""" def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [ (SERVICE_NO_PLATFORM, SERVICE_INFO), (SERVICE_NO_PLATFORM, SERVICE_INFO), ] mock_discover, mock_platform = await ...
[ "async", "def", "test_discover_duplicates", "(", "hass", ")", ":", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "SERVICE_NO_PLATFORM", ",", "SERVICE_INFO", ")", ",", "(", "SERVICE_NO_PLATF...
[ 124, 0 ]
[ 145, 5 ]
python
en
['en', 'en', 'en']
True
test_discover_config_flow
(hass)
Test discovery triggering a config flow.
Test discovery triggering a config flow.
async def test_discover_config_flow(hass): """Test discovery triggering a config flow.""" discovery_info = {"hello": "world"} def discover(netdisco, zeroconf_instance): """Fake discovery.""" return [("mock-service", discovery_info)] with patch.dict( discovery.CONFIG_ENTRY_HANDL...
[ "async", "def", "test_discover_config_flow", "(", "hass", ")", ":", "discovery_info", "=", "{", "\"hello\"", ":", "\"world\"", "}", "def", "discover", "(", "netdisco", ",", "zeroconf_instance", ")", ":", "\"\"\"Fake discovery.\"\"\"", "return", "[", "(", "\"mock-s...
[ 148, 0 ]
[ 165, 43 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up the Rachio switches.
Set up the Rachio switches.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up the Rachio switches.""" zone_entities = [] has_flex_sched = False entities = await hass.async_add_executor_job(_create_entities, hass, config_entry) for entity in entities: if isinstance(entity, RachioZone): ...
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "zone_entities", "=", "[", "]", "has_flex_sched", "=", "False", "entities", "=", "await", "hass", ".", "async_add_executor_job", "(", "_create_entities", ",...
[ 90, 0 ]
[ 147, 9 ]
python
en
['en', 'en', 'en']
True
RachioSwitch.__init__
(self, controller)
Initialize a new Rachio switch.
Initialize a new Rachio switch.
def __init__(self, controller): """Initialize a new Rachio switch.""" super().__init__(controller) self._state = None
[ "def", "__init__", "(", "self", ",", "controller", ")", ":", "super", "(", ")", ".", "__init__", "(", "controller", ")", "self", ".", "_state", "=", "None" ]
[ 173, 4 ]
[ 176, 26 ]
python
en
['en', 'pl', 'en']
True
RachioSwitch.name
(self)
Get a name for this switch.
Get a name for this switch.
def name(self) -> str: """Get a name for this switch.""" return f"Switch on {self._controller.name}"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"Switch on {self._controller.name}\"" ]
[ 179, 4 ]
[ 181, 51 ]
python
en
['en', 'en', 'en']
True
RachioSwitch.is_on
(self)
Return whether the switch is currently on.
Return whether the switch is currently on.
def is_on(self) -> bool: """Return whether the switch is currently on.""" return self._state
[ "def", "is_on", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "_state" ]
[ 184, 4 ]
[ 186, 26 ]
python
en
['en', 'en', 'en']
True
RachioSwitch._async_handle_any_update
(self, *args, **kwargs)
Determine whether an update event applies to this device.
Determine whether an update event applies to this device.
def _async_handle_any_update(self, *args, **kwargs) -> None: """Determine whether an update event applies to this device.""" if args[0][KEY_DEVICE_ID] != self._controller.controller_id: # For another device return # For this device self._async_handle_update(args,...
[ "def", "_async_handle_any_update", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "args", "[", "0", "]", "[", "KEY_DEVICE_ID", "]", "!=", "self", ".", "_controller", ".", "controller_id", ":", "# For another device", ...
[ 189, 4 ]
[ 196, 47 ]
python
en
['en', 'en', 'en']
True
RachioSwitch._async_handle_update
(self, *args, **kwargs)
Handle incoming webhook data.
Handle incoming webhook data.
def _async_handle_update(self, *args, **kwargs) -> None: """Handle incoming webhook data."""
[ "def", "_async_handle_update", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":" ]
[ 199, 4 ]
[ 200, 43 ]
python
en
['en', 'xh', 'en']
True
RachioStandbySwitch.name
(self)
Return the name of the standby switch.
Return the name of the standby switch.
def name(self) -> str: """Return the name of the standby switch.""" return f"{self._controller.name} in standby mode"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"{self._controller.name} in standby mode\"" ]
[ 207, 4 ]
[ 209, 57 ]
python
en
['en', 'en', 'en']
True
RachioStandbySwitch.unique_id
(self)
Return a unique id by combining controller id and purpose.
Return a unique id by combining controller id and purpose.
def unique_id(self) -> str: """Return a unique id by combining controller id and purpose.""" return f"{self._controller.controller_id}-standby"
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "return", "f\"{self._controller.controller_id}-standby\"" ]
[ 212, 4 ]
[ 214, 58 ]
python
en
['en', 'en', 'en']
True
RachioStandbySwitch.icon
(self)
Return an icon for the standby switch.
Return an icon for the standby switch.
def icon(self) -> str: """Return an icon for the standby switch.""" return "mdi:power"
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "\"mdi:power\"" ]
[ 217, 4 ]
[ 219, 26 ]
python
en
['en', 'en', 'en']
True
RachioStandbySwitch._async_handle_update
(self, *args, **kwargs)
Update the state using webhook data.
Update the state using webhook data.
def _async_handle_update(self, *args, **kwargs) -> None: """Update the state using webhook data.""" if args[0][0][KEY_SUBTYPE] == SUBTYPE_SLEEP_MODE_ON: self._state = True elif args[0][0][KEY_SUBTYPE] == SUBTYPE_SLEEP_MODE_OFF: self._state = False self.async_writ...
[ "def", "_async_handle_update", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "args", "[", "0", "]", "[", "0", "]", "[", "KEY_SUBTYPE", "]", "==", "SUBTYPE_SLEEP_MODE_ON", ":", "self", ".", "_state", "=", "True"...
[ 222, 4 ]
[ 229, 35 ]
python
en
['en', 'en', 'en']
True
RachioStandbySwitch.turn_on
(self, **kwargs)
Put the controller in standby mode.
Put the controller in standby mode.
def turn_on(self, **kwargs) -> None: """Put the controller in standby mode.""" self._controller.rachio.device.turn_off(self._controller.controller_id)
[ "def", "turn_on", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "self", ".", "_controller", ".", "rachio", ".", "device", ".", "turn_off", "(", "self", ".", "_controller", ".", "controller_id", ")" ]
[ 231, 4 ]
[ 233, 79 ]
python
en
['en', 'en', 'en']
True
RachioStandbySwitch.turn_off
(self, **kwargs)
Resume controller functionality.
Resume controller functionality.
def turn_off(self, **kwargs) -> None: """Resume controller functionality.""" self._controller.rachio.device.turn_on(self._controller.controller_id)
[ "def", "turn_off", "(", "self", ",", "*", "*", "kwargs", ")", "->", "None", ":", "self", ".", "_controller", ".", "rachio", ".", "device", ".", "turn_on", "(", "self", ".", "_controller", ".", "controller_id", ")" ]
[ 235, 4 ]
[ 237, 78 ]
python
en
['da', 'en', 'en']
True
RachioStandbySwitch.async_added_to_hass
(self)
Subscribe to updates.
Subscribe to updates.
async def async_added_to_hass(self): """Subscribe to updates.""" if KEY_ON in self._controller.init_data: self._state = not self._controller.init_data[KEY_ON] self.async_on_remove( async_dispatcher_connect( self.hass, SIGNAL_RACHIO_CONTROL...
[ "async", "def", "async_added_to_hass", "(", "self", ")", ":", "if", "KEY_ON", "in", "self", ".", "_controller", ".", "init_data", ":", "self", ".", "_state", "=", "not", "self", ".", "_controller", ".", "init_data", "[", "KEY_ON", "]", "self", ".", "asyn...
[ 239, 4 ]
[ 250, 9 ]
python
en
['en', 'en', 'en']
True
RachioRainDelay.__init__
(self, controller)
Set up a Rachio rain delay switch.
Set up a Rachio rain delay switch.
def __init__(self, controller): """Set up a Rachio rain delay switch.""" self._cancel_update = None super().__init__(controller)
[ "def", "__init__", "(", "self", ",", "controller", ")", ":", "self", ".", "_cancel_update", "=", "None", "super", "(", ")", ".", "__init__", "(", "controller", ")" ]
[ 256, 4 ]
[ 259, 36 ]
python
en
['en', 'fr', 'en']
True
RachioRainDelay.name
(self)
Return the name of the switch.
Return the name of the switch.
def name(self) -> str: """Return the name of the switch.""" return f"{self._controller.name} rain delay"
[ "def", "name", "(", "self", ")", "->", "str", ":", "return", "f\"{self._controller.name} rain delay\"" ]
[ 262, 4 ]
[ 264, 52 ]
python
en
['en', 'en', 'en']
True
RachioRainDelay.unique_id
(self)
Return a unique id by combining controller id and purpose.
Return a unique id by combining controller id and purpose.
def unique_id(self) -> str: """Return a unique id by combining controller id and purpose.""" return f"{self._controller.controller_id}-delay"
[ "def", "unique_id", "(", "self", ")", "->", "str", ":", "return", "f\"{self._controller.controller_id}-delay\"" ]
[ 267, 4 ]
[ 269, 56 ]
python
en
['en', 'en', 'en']
True
RachioRainDelay.icon
(self)
Return an icon for rain delay.
Return an icon for rain delay.
def icon(self) -> str: """Return an icon for rain delay.""" return "mdi:camera-timer"
[ "def", "icon", "(", "self", ")", "->", "str", ":", "return", "\"mdi:camera-timer\"" ]
[ 272, 4 ]
[ 274, 33 ]
python
en
['en', 'gd', 'en']
True
RachioRainDelay._async_handle_update
(self, *args, **kwargs)
Update the state using webhook data.
Update the state using webhook data.
def _async_handle_update(self, *args, **kwargs) -> None: """Update the state using webhook data.""" if self._cancel_update: self._cancel_update() self._cancel_update = None if args[0][0][KEY_SUBTYPE] == SUBTYPE_RAIN_DELAY_ON: endtime = parse_datetime(args[0][...
[ "def", "_async_handle_update", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", "->", "None", ":", "if", "self", ".", "_cancel_update", ":", "self", ".", "_cancel_update", "(", ")", "self", ".", "_cancel_update", "=", "None", "if", "args", ...
[ 277, 4 ]
[ 293, 35 ]
python
en
['en', 'en', 'en']
True
RachioRainDelay._delay_expiration
(self, *args)
Trigger when a rain delay expires.
Trigger when a rain delay expires.
def _delay_expiration(self, *args) -> None: """Trigger when a rain delay expires.""" self._state = False self._cancel_update = None self.async_write_ha_state()
[ "def", "_delay_expiration", "(", "self", ",", "*", "args", ")", "->", "None", ":", "self", ".", "_state", "=", "False", "self", ".", "_cancel_update", "=", "None", "self", ".", "async_write_ha_state", "(", ")" ]
[ 296, 4 ]
[ 300, 35 ]
python
en
['en', 'gl', 'en']
True