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
async_setup
(hass, config)
Set up the history hooks.
Set up the history hooks.
async def async_setup(hass, config): """Set up the history hooks.""" conf = config.get(DOMAIN, {}) filters = sqlalchemy_filter_from_include_exclude_conf(conf) hass.data[HISTORY_BAKERY] = baked.bakery() use_include_order = conf.get(CONF_ORDER) hass.http.register_view(HistoryPeriodView(filters...
[ "async", "def", "async_setup", "(", "hass", ",", "config", ")", ":", "conf", "=", "config", ".", "get", "(", "DOMAIN", ",", "{", "}", ")", "filters", "=", "sqlalchemy_filter_from_include_exclude_conf", "(", "conf", ")", "hass", ".", "data", "[", "HISTORY_B...
[ 432, 0 ]
[ 447, 15 ]
python
en
['en', 'zu', 'en']
True
sqlalchemy_filter_from_include_exclude_conf
(conf)
Build a sql filter from config.
Build a sql filter from config.
def sqlalchemy_filter_from_include_exclude_conf(conf): """Build a sql filter from config.""" filters = Filters() exclude = conf.get(CONF_EXCLUDE) if exclude: filters.excluded_entities = exclude.get(CONF_ENTITIES, []) filters.excluded_domains = exclude.get(CONF_DOMAINS, []) filter...
[ "def", "sqlalchemy_filter_from_include_exclude_conf", "(", "conf", ")", ":", "filters", "=", "Filters", "(", ")", "exclude", "=", "conf", ".", "get", "(", "CONF_EXCLUDE", ")", "if", "exclude", ":", "filters", ".", "excluded_entities", "=", "exclude", ".", "get...
[ 574, 0 ]
[ 588, 50 ]
python
en
['en', 'en', 'en']
True
_glob_to_like
(glob_str)
Translate glob to sql.
Translate glob to sql.
def _glob_to_like(glob_str): """Translate glob to sql.""" return States.entity_id.like(glob_str.translate(GLOB_TO_SQL_CHARS))
[ "def", "_glob_to_like", "(", "glob_str", ")", ":", "return", "States", ".", "entity_id", ".", "like", "(", "glob_str", ".", "translate", "(", "GLOB_TO_SQL_CHARS", ")", ")" ]
[ 666, 0 ]
[ 668, 71 ]
python
en
['en', 'hr', 'en']
True
_entities_may_have_state_changes_after
( hass: HomeAssistantType, entity_ids: Iterable, start_time: dt )
Check the state machine to see if entities have changed since start time.
Check the state machine to see if entities have changed since start time.
def _entities_may_have_state_changes_after( hass: HomeAssistantType, entity_ids: Iterable, start_time: dt ) -> bool: """Check the state machine to see if entities have changed since start time.""" for entity_id in entity_ids: state = hass.states.get(entity_id) if state is None or state.last...
[ "def", "_entities_may_have_state_changes_after", "(", "hass", ":", "HomeAssistantType", ",", "entity_ids", ":", "Iterable", ",", "start_time", ":", "dt", ")", "->", "bool", ":", "for", "entity_id", "in", "entity_ids", ":", "state", "=", "hass", ".", "states", ...
[ 671, 0 ]
[ 681, 16 ]
python
en
['en', 'en', 'en']
True
HistoryPeriodView.__init__
(self, filters, use_include_order)
Initialize the history period view.
Initialize the history period view.
def __init__(self, filters, use_include_order): """Initialize the history period view.""" self.filters = filters self.use_include_order = use_include_order
[ "def", "__init__", "(", "self", ",", "filters", ",", "use_include_order", ")", ":", "self", ".", "filters", "=", "filters", "self", ".", "use_include_order", "=", "use_include_order" ]
[ 457, 4 ]
[ 460, 50 ]
python
en
['en', 'en', 'en']
True
HistoryPeriodView.get
( self, request: web.Request, datetime: Optional[str] = None )
Return history over a period of time.
Return history over a period of time.
async def get( self, request: web.Request, datetime: Optional[str] = None ) -> web.Response: """Return history over a period of time.""" datetime_ = None if datetime: datetime_ = dt_util.parse_datetime(datetime) if datetime_ is None: return se...
[ "async", "def", "get", "(", "self", ",", "request", ":", "web", ".", "Request", ",", "datetime", ":", "Optional", "[", "str", "]", "=", "None", ")", "->", "web", ".", "Response", ":", "datetime_", "=", "None", "if", "datetime", ":", "datetime_", "=",...
[ 462, 4 ]
[ 525, 9 ]
python
en
['en', 'en', 'en']
True
HistoryPeriodView._sorted_significant_states_json
( self, hass, start_time, end_time, entity_ids, include_start_time_state, significant_changes_only, minimal_response, )
Fetch significant stats from the database as json.
Fetch significant stats from the database as json.
def _sorted_significant_states_json( self, hass, start_time, end_time, entity_ids, include_start_time_state, significant_changes_only, minimal_response, ): """Fetch significant stats from the database as json.""" timer_start = time.perf...
[ "def", "_sorted_significant_states_json", "(", "self", ",", "hass", ",", "start_time", ",", "end_time", ",", "entity_ids", ",", "include_start_time_state", ",", "significant_changes_only", ",", "minimal_response", ",", ")", ":", "timer_start", "=", "time", ".", "per...
[ 527, 4 ]
[ 571, 32 ]
python
en
['en', 'en', 'en']
True
Filters.__init__
(self)
Initialise the include and exclude filters.
Initialise the include and exclude filters.
def __init__(self): """Initialise the include and exclude filters.""" self.excluded_entities = [] self.excluded_domains = [] self.excluded_entity_globs = [] self.included_entities = [] self.included_domains = [] self.included_entity_globs = []
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "excluded_entities", "=", "[", "]", "self", ".", "excluded_domains", "=", "[", "]", "self", ".", "excluded_entity_globs", "=", "[", "]", "self", ".", "included_entities", "=", "[", "]", "self", ".", ...
[ 594, 4 ]
[ 602, 39 ]
python
en
['en', 'en', 'en']
True
Filters.apply
(self, query)
Apply the entity filter.
Apply the entity filter.
def apply(self, query): """Apply the entity filter.""" if not self.has_config: return query return query.filter(self.entity_filter())
[ "def", "apply", "(", "self", ",", "query", ")", ":", "if", "not", "self", ".", "has_config", ":", "return", "query", "return", "query", ".", "filter", "(", "self", ".", "entity_filter", "(", ")", ")" ]
[ 604, 4 ]
[ 609, 49 ]
python
en
['en', 'en', 'en']
True
Filters.has_config
(self)
Determine if there is any filter configuration.
Determine if there is any filter configuration.
def has_config(self): """Determine if there is any filter configuration.""" if ( self.excluded_entities or self.excluded_domains or self.excluded_entity_globs or self.included_entities or self.included_domains or self.included_entit...
[ "def", "has_config", "(", "self", ")", ":", "if", "(", "self", ".", "excluded_entities", "or", "self", ".", "excluded_domains", "or", "self", ".", "excluded_entity_globs", "or", "self", ".", "included_entities", "or", "self", ".", "included_domains", "or", "se...
[ 612, 4 ]
[ 624, 20 ]
python
en
['en', 'en', 'en']
True
Filters.bake
(self, baked_query)
Update a baked query. Works the same as apply on a baked_query.
Update a baked query.
def bake(self, baked_query): """Update a baked query. Works the same as apply on a baked_query. """ if not self.has_config: return baked_query += lambda q: q.filter(self.entity_filter())
[ "def", "bake", "(", "self", ",", "baked_query", ")", ":", "if", "not", "self", ".", "has_config", ":", "return", "baked_query", "+=", "lambda", "q", ":", "q", ".", "filter", "(", "self", ".", "entity_filter", "(", ")", ")" ]
[ 626, 4 ]
[ 634, 63 ]
python
en
['es', 'en', 'en']
True
Filters.entity_filter
(self)
Generate the entity filter query.
Generate the entity filter query.
def entity_filter(self): """Generate the entity filter query.""" includes = [] if self.included_domains: includes.append(States.domain.in_(self.included_domains)) if self.included_entities: includes.append(States.entity_id.in_(self.included_entities)) for ...
[ "def", "entity_filter", "(", "self", ")", ":", "includes", "=", "[", "]", "if", "self", ".", "included_domains", ":", "includes", ".", "append", "(", "States", ".", "domain", ".", "in_", "(", "self", ".", "included_domains", ")", ")", "if", "self", "."...
[ 636, 4 ]
[ 663, 52 ]
python
en
['en', 'en', 'en']
True
LazyState.__init__
(self, row)
Init the lazy state.
Init the lazy state.
def __init__(self, row): # pylint: disable=super-init-not-called """Init the lazy state.""" self._row = row self.entity_id = self._row.entity_id self.state = self._row.state self._attributes = None self._last_changed = None self._last_updated = None self....
[ "def", "__init__", "(", "self", ",", "row", ")", ":", "# pylint: disable=super-init-not-called", "self", ".", "_row", "=", "row", "self", ".", "entity_id", "=", "self", ".", "_row", ".", "entity_id", "self", ".", "state", "=", "self", ".", "_row", ".", "...
[ 697, 4 ]
[ 705, 28 ]
python
en
['en', 'en', 'en']
True
LazyState.attributes
(self)
State attributes.
State attributes.
def attributes(self): """State attributes.""" if not self._attributes: try: self._attributes = json.loads(self._row.attributes) except ValueError: # When json.loads fails _LOGGER.exception("Error converting row to state: %s", self) ...
[ "def", "attributes", "(", "self", ")", ":", "if", "not", "self", ".", "_attributes", ":", "try", ":", "self", ".", "_attributes", "=", "json", ".", "loads", "(", "self", ".", "_row", ".", "attributes", ")", "except", "ValueError", ":", "# When json.loads...
[ 708, 4 ]
[ 717, 31 ]
python
en
['en', 'en', 'en']
False
LazyState.attributes
(self, value)
Set attributes.
Set attributes.
def attributes(self, value): """Set attributes.""" self._attributes = value
[ "def", "attributes", "(", "self", ",", "value", ")", ":", "self", ".", "_attributes", "=", "value" ]
[ 720, 4 ]
[ 722, 32 ]
python
en
['en', 'la', 'en']
False
LazyState.context
(self)
State context.
State context.
def context(self): """State context.""" if not self._context: self._context = Context(id=None) return self._context
[ "def", "context", "(", "self", ")", ":", "if", "not", "self", ".", "_context", ":", "self", ".", "_context", "=", "Context", "(", "id", "=", "None", ")", "return", "self", ".", "_context" ]
[ 725, 4 ]
[ 729, 28 ]
python
en
['en', 'en', 'en']
False
LazyState.context
(self, value)
Set context.
Set context.
def context(self, value): """Set context.""" self._context = value
[ "def", "context", "(", "self", ",", "value", ")", ":", "self", ".", "_context", "=", "value" ]
[ 732, 4 ]
[ 734, 29 ]
python
en
['en', 'ca', 'en']
False
LazyState.last_changed
(self)
Last changed datetime.
Last changed datetime.
def last_changed(self): """Last changed datetime.""" if not self._last_changed: self._last_changed = process_timestamp(self._row.last_changed) return self._last_changed
[ "def", "last_changed", "(", "self", ")", ":", "if", "not", "self", ".", "_last_changed", ":", "self", ".", "_last_changed", "=", "process_timestamp", "(", "self", ".", "_row", ".", "last_changed", ")", "return", "self", ".", "_last_changed" ]
[ 737, 4 ]
[ 741, 33 ]
python
en
['en', 'en', 'en']
True
LazyState.last_changed
(self, value)
Set last changed datetime.
Set last changed datetime.
def last_changed(self, value): """Set last changed datetime.""" self._last_changed = value
[ "def", "last_changed", "(", "self", ",", "value", ")", ":", "self", ".", "_last_changed", "=", "value" ]
[ 744, 4 ]
[ 746, 34 ]
python
en
['en', 'fr', 'en']
True
LazyState.last_updated
(self)
Last updated datetime.
Last updated datetime.
def last_updated(self): """Last updated datetime.""" if not self._last_updated: self._last_updated = process_timestamp(self._row.last_updated) return self._last_updated
[ "def", "last_updated", "(", "self", ")", ":", "if", "not", "self", ".", "_last_updated", ":", "self", ".", "_last_updated", "=", "process_timestamp", "(", "self", ".", "_row", ".", "last_updated", ")", "return", "self", ".", "_last_updated" ]
[ 749, 4 ]
[ 753, 33 ]
python
en
['en', 'en', 'en']
True
LazyState.last_updated
(self, value)
Set last updated datetime.
Set last updated datetime.
def last_updated(self, value): """Set last updated datetime.""" self._last_updated = value
[ "def", "last_updated", "(", "self", ",", "value", ")", ":", "self", ".", "_last_updated", "=", "value" ]
[ 756, 4 ]
[ 758, 34 ]
python
en
['en', 'et', 'en']
True
LazyState.as_dict
(self)
Return a dict representation of the LazyState. Async friendly. To be used for JSON serialization.
Return a dict representation of the LazyState.
def as_dict(self): """Return a dict representation of the LazyState. Async friendly. To be used for JSON serialization. """ if self._last_changed: last_changed_isoformat = self._last_changed.isoformat() else: last_changed_isoformat = process_time...
[ "def", "as_dict", "(", "self", ")", ":", "if", "self", ".", "_last_changed", ":", "last_changed_isoformat", "=", "self", ".", "_last_changed", ".", "isoformat", "(", ")", "else", ":", "last_changed_isoformat", "=", "process_timestamp_to_utc_isoformat", "(", "self"...
[ 760, 4 ]
[ 785, 9 ]
python
en
['en', 'en', 'en']
True
LazyState.__eq__
(self, other)
Return the comparison.
Return the comparison.
def __eq__(self, other): """Return the comparison.""" return ( other.__class__ in [self.__class__, State] and self.entity_id == other.entity_id and self.state == other.state and self.attributes == other.attributes )
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "return", "(", "other", ".", "__class__", "in", "[", "self", ".", "__class__", ",", "State", "]", "and", "self", ".", "entity_id", "==", "other", ".", "entity_id", "and", "self", ".", "state", "==...
[ 787, 4 ]
[ 794, 9 ]
python
en
['en', 'it', 'en']
True
_get_indent
(t)
Returns the indentation in the first line of t
Returns the indentation in the first line of t
def _get_indent(t): """Returns the indentation in the first line of t""" search = re.search(r"^(\s*)\S", t) return "" if search is None else search.groups()[0]
[ "def", "_get_indent", "(", "t", ")", ":", "search", "=", "re", ".", "search", "(", "r\"^(\\s*)\\S\"", ",", "t", ")", "return", "\"\"", "if", "search", "is", "None", "else", "search", ".", "groups", "(", ")", "[", "0", "]" ]
[ 626, 0 ]
[ 629, 55 ]
python
en
['en', 'en', 'en']
True
_convert_output_args_doc
(output_args_doc)
Convert output_args_doc to display properly.
Convert output_args_doc to display properly.
def _convert_output_args_doc(output_args_doc): """Convert output_args_doc to display properly.""" # Split output_arg_doc in blocks argument/description indent = _get_indent(output_args_doc) blocks = [] current_block = "" for line in output_args_doc.split("\n"): # If the indent is the sam...
[ "def", "_convert_output_args_doc", "(", "output_args_doc", ")", ":", "# Split output_arg_doc in blocks argument/description", "indent", "=", "_get_indent", "(", "output_args_doc", ")", "blocks", "=", "[", "]", "current_block", "=", "\"\"", "for", "line", "in", "output_a...
[ 632, 0 ]
[ 655, 28 ]
python
en
['en', 'en', 'en']
True
_prepare_output_docstrings
(output_type, config_class)
Prepares the return part of the docstring using `output_type`.
Prepares the return part of the docstring using `output_type`.
def _prepare_output_docstrings(output_type, config_class): """ Prepares the return part of the docstring using `output_type`. """ docstrings = output_type.__doc__ # Remove the head of the docstring to keep the list of args only lines = docstrings.split("\n") i = 0 while i < len(lines) a...
[ "def", "_prepare_output_docstrings", "(", "output_type", ",", "config_class", ")", ":", "docstrings", "=", "output_type", ".", "__doc__", "# Remove the head of the docstring to keep the list of args only", "lines", "=", "docstrings", ".", "split", "(", "\"\\n\"", ")", "i"...
[ 658, 0 ]
[ 677, 29 ]
python
en
['en', 'error', 'th']
False
hf_bucket_url
( model_id: str, filename: str, subfolder: Optional[str] = None, revision: Optional[str] = None, mirror=None )
Resolve a model identifier, a file name, and an optional revision id, to a huggingface.co-hosted url, redirecting to Cloudfront (a Content Delivery Network, or CDN) for large files. Cloudfront is replicated over the globe so downloads are way faster for the end user (and it also lowers our bandwidth c...
Resolve a model identifier, a file name, and an optional revision id, to a huggingface.co-hosted url, redirecting to Cloudfront (a Content Delivery Network, or CDN) for large files.
def hf_bucket_url( model_id: str, filename: str, subfolder: Optional[str] = None, revision: Optional[str] = None, mirror=None ) -> str: """ Resolve a model identifier, a file name, and an optional revision id, to a huggingface.co-hosted url, redirecting to Cloudfront (a Content Delivery Network, or CDN)...
[ "def", "hf_bucket_url", "(", "model_id", ":", "str", ",", "filename", ":", "str", ",", "subfolder", ":", "Optional", "[", "str", "]", "=", "None", ",", "revision", ":", "Optional", "[", "str", "]", "=", "None", ",", "mirror", "=", "None", ")", "->", ...
[ 983, 0 ]
[ 1015, 96 ]
python
en
['en', 'error', 'th']
False
url_to_filename
(url: str, etag: Optional[str] = None)
Convert `url` into a hashed filename in a repeatable way. If `etag` is specified, append its hash to the url's, delimited by a period. If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name so that TF 2.0 can identify it as a HDF5 file (see https://github.com/tensorflow/tensorflow/blob/00...
Convert `url` into a hashed filename in a repeatable way. If `etag` is specified, append its hash to the url's, delimited by a period. If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name so that TF 2.0 can identify it as a HDF5 file (see https://github.com/tensorflow/tensorflow/blob/00...
def url_to_filename(url: str, etag: Optional[str] = None) -> str: """ Convert `url` into a hashed filename in a repeatable way. If `etag` is specified, append its hash to the url's, delimited by a period. If the url ends with .h5 (Keras HDF5 weights) adds '.h5' to the name so that TF 2.0 can identify it...
[ "def", "url_to_filename", "(", "url", ":", "str", ",", "etag", ":", "Optional", "[", "str", "]", "=", "None", ")", "->", "str", ":", "url_bytes", "=", "url", ".", "encode", "(", "\"utf-8\"", ")", "filename", "=", "sha256", "(", "url_bytes", ")", ".",...
[ 1018, 0 ]
[ 1035, 19 ]
python
en
['en', 'error', 'th']
False
filename_to_url
(filename, cache_dir=None)
Return the url and etag (which may be ``None``) stored for `filename`. Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist.
Return the url and etag (which may be ``None``) stored for `filename`. Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist.
def filename_to_url(filename, cache_dir=None): """ Return the url and etag (which may be ``None``) stored for `filename`. Raise ``EnvironmentError`` if `filename` or its stored metadata do not exist. """ if cache_dir is None: cache_dir = TRANSFORMERS_CACHE if isinstance(cache_dir, Path):...
[ "def", "filename_to_url", "(", "filename", ",", "cache_dir", "=", "None", ")", ":", "if", "cache_dir", "is", "None", ":", "cache_dir", "=", "TRANSFORMERS_CACHE", "if", "isinstance", "(", "cache_dir", ",", "Path", ")", ":", "cache_dir", "=", "str", "(", "ca...
[ 1038, 0 ]
[ 1061, 20 ]
python
en
['en', 'error', 'th']
False
get_cached_models
(cache_dir: Union[str, Path] = None)
Returns a list of tuples representing model binaries that are cached locally. Each tuple has shape :obj:`(model_url, etag, size_MB)`. Filenames in :obj:`cache_dir` are use to get the metadata for each model, only urls ending with `.bin` are added. Args: cache_dir (:obj:`Union[str, Path]`, `opt...
Returns a list of tuples representing model binaries that are cached locally. Each tuple has shape :obj:`(model_url, etag, size_MB)`. Filenames in :obj:`cache_dir` are use to get the metadata for each model, only urls ending with `.bin` are added.
def get_cached_models(cache_dir: Union[str, Path] = None) -> List[Tuple]: """ Returns a list of tuples representing model binaries that are cached locally. Each tuple has shape :obj:`(model_url, etag, size_MB)`. Filenames in :obj:`cache_dir` are use to get the metadata for each model, only urls ending w...
[ "def", "get_cached_models", "(", "cache_dir", ":", "Union", "[", "str", ",", "Path", "]", "=", "None", ")", "->", "List", "[", "Tuple", "]", ":", "if", "cache_dir", "is", "None", ":", "cache_dir", "=", "TRANSFORMERS_CACHE", "elif", "isinstance", "(", "ca...
[ 1064, 0 ]
[ 1094, 24 ]
python
en
['en', 'error', 'th']
False
cached_path
( url_or_filename, cache_dir=None, force_download=False, proxies=None, resume_download=False, user_agent: Union[Dict, str, None] = None, extract_compressed_file=False, force_extract=False, use_auth_token: Union[bool, str, None] = None, local_files_only=False, )
Given something that might be a URL (or might be a local path), determine which. If it's a URL, download the file and cache it, and return the path to the cached file. If it's already a local path, make sure the file exists and then return the path Args: cache_dir: specify a cache directory to...
Given something that might be a URL (or might be a local path), determine which. If it's a URL, download the file and cache it, and return the path to the cached file. If it's already a local path, make sure the file exists and then return the path
def cached_path( url_or_filename, cache_dir=None, force_download=False, proxies=None, resume_download=False, user_agent: Union[Dict, str, None] = None, extract_compressed_file=False, force_extract=False, use_auth_token: Union[bool, str, None] = None, local_files_only=False, ) -> ...
[ "def", "cached_path", "(", "url_or_filename", ",", "cache_dir", "=", "None", ",", "force_download", "=", "False", ",", "proxies", "=", "None", ",", "resume_download", "=", "False", ",", "user_agent", ":", "Union", "[", "Dict", ",", "str", ",", "None", "]",...
[ 1097, 0 ]
[ 1196, 22 ]
python
en
['en', 'error', 'th']
False
http_user_agent
(user_agent: Union[Dict, str, None] = None)
Formats a user-agent string with basic info about a request.
Formats a user-agent string with basic info about a request.
def http_user_agent(user_agent: Union[Dict, str, None] = None) -> str: """ Formats a user-agent string with basic info about a request. """ ua = f"transformers/{__version__}; python/{sys.version.split()[0]}; session_id/{SESSION_ID}" if is_torch_available(): ua += f"; torch/{_torch_version}" ...
[ "def", "http_user_agent", "(", "user_agent", ":", "Union", "[", "Dict", ",", "str", ",", "None", "]", "=", "None", ")", "->", "str", ":", "ua", "=", "f\"transformers/{__version__}; python/{sys.version.split()[0]}; session_id/{SESSION_ID}\"", "if", "is_torch_available", ...
[ 1225, 0 ]
[ 1240, 13 ]
python
en
['en', 'error', 'th']
False
http_get
(url: str, temp_file: BinaryIO, proxies=None, resume_size=0, headers: Optional[Dict[str, str]] = None)
Donwload remote file. Do not gobble up errors.
Donwload remote file. Do not gobble up errors.
def http_get(url: str, temp_file: BinaryIO, proxies=None, resume_size=0, headers: Optional[Dict[str, str]] = None): """ Donwload remote file. Do not gobble up errors. """ headers = copy.deepcopy(headers) if resume_size > 0: headers["Range"] = "bytes=%d-" % (resume_size,) r = requests.get...
[ "def", "http_get", "(", "url", ":", "str", ",", "temp_file", ":", "BinaryIO", ",", "proxies", "=", "None", ",", "resume_size", "=", "0", ",", "headers", ":", "Optional", "[", "Dict", "[", "str", ",", "str", "]", "]", "=", "None", ")", ":", "headers...
[ 1243, 0 ]
[ 1266, 20 ]
python
en
['en', 'error', 'th']
False
get_from_cache
( url: str, cache_dir=None, force_download=False, proxies=None, etag_timeout=10, resume_download=False, user_agent: Union[Dict, str, None] = None, use_auth_token: Union[bool, str, None] = None, local_files_only=False, )
Given a URL, look for the corresponding file in the local cache. If it's not there, download it. Then return the path to the cached file. Return: Local path (string) of file or if networking is off, last version of file cached on disk. Raises: In case of non-recoverable file (non-exis...
Given a URL, look for the corresponding file in the local cache. If it's not there, download it. Then return the path to the cached file.
def get_from_cache( url: str, cache_dir=None, force_download=False, proxies=None, etag_timeout=10, resume_download=False, user_agent: Union[Dict, str, None] = None, use_auth_token: Union[bool, str, None] = None, local_files_only=False, ) -> Optional[str]: """ Given a URL, loo...
[ "def", "get_from_cache", "(", "url", ":", "str", ",", "cache_dir", "=", "None", ",", "force_download", "=", "False", ",", "proxies", "=", "None", ",", "etag_timeout", "=", "10", ",", "resume_download", "=", "False", ",", "user_agent", ":", "Union", "[", ...
[ 1269, 0 ]
[ 1414, 21 ]
python
en
['en', 'error', 'th']
False
is_tensor
(x)
Tests if ``x`` is a :obj:`torch.Tensor`, :obj:`tf.Tensor` or :obj:`np.ndarray`.
Tests if ``x`` is a :obj:`torch.Tensor`, :obj:`tf.Tensor` or :obj:`np.ndarray`.
def is_tensor(x): """ Tests if ``x`` is a :obj:`torch.Tensor`, :obj:`tf.Tensor` or :obj:`np.ndarray`. """ if is_torch_available(): import torch if isinstance(x, torch.Tensor): return True if is_tf_available(): import tensorflow as tf if isinstance(x, tf.Tensor):...
[ "def", "is_tensor", "(", "x", ")", ":", "if", "is_torch_available", "(", ")", ":", "import", "torch", "if", "isinstance", "(", "x", ",", "torch", ".", "Tensor", ")", ":", "return", "True", "if", "is_tf_available", "(", ")", ":", "import", "tensorflow", ...
[ 1464, 0 ]
[ 1476, 36 ]
python
en
['en', 'mt', 'hi']
False
to_py_obj
(obj)
Convert a TensorFlow tensor, PyTorch tensor, Numpy array or python list to a python list.
Convert a TensorFlow tensor, PyTorch tensor, Numpy array or python list to a python list.
def to_py_obj(obj): """ Convert a TensorFlow tensor, PyTorch tensor, Numpy array or python list to a python list. """ if isinstance(obj, (dict, UserDict)): return {k: to_py_obj(v) for k, v in obj.items()} elif isinstance(obj, (list, tuple)): return [to_py_obj(o) for o in obj] eli...
[ "def", "to_py_obj", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "(", "dict", ",", "UserDict", ")", ")", ":", "return", "{", "k", ":", "to_py_obj", "(", "v", ")", "for", "k", ",", "v", "in", "obj", ".", "items", "(", ")", "}", "...
[ 1507, 0 ]
[ 1522, 18 ]
python
en
['en', 'error', 'th']
False
ModelOutput.to_tuple
(self)
Convert self to a tuple containing all the attributes/keys that are not ``None``.
Convert self to a tuple containing all the attributes/keys that are not ``None``.
def to_tuple(self) -> Tuple[Any]: """ Convert self to a tuple containing all the attributes/keys that are not ``None``. """ return tuple(self[k] for k in self.keys())
[ "def", "to_tuple", "(", "self", ")", "->", "Tuple", "[", "Any", "]", ":", "return", "tuple", "(", "self", "[", "k", "]", "for", "k", "in", "self", ".", "keys", "(", ")", ")" ]
[ 1607, 4 ]
[ 1611, 50 ]
python
en
['en', 'error', 'th']
False
DataUpdateCoordinator.__init__
( self, hass: HomeAssistant, logger: logging.Logger, *, name: str, update_interval: Optional[timedelta] = None, update_method: Optional[Callable[[], Awaitable[T]]] = None, request_refresh_debouncer: Optional[Debouncer] = None, )
Initialize global data updater.
Initialize global data updater.
def __init__( self, hass: HomeAssistant, logger: logging.Logger, *, name: str, update_interval: Optional[timedelta] = None, update_method: Optional[Callable[[], Awaitable[T]]] = None, request_refresh_debouncer: Optional[Debouncer] = None, ): ""...
[ "def", "__init__", "(", "self", ",", "hass", ":", "HomeAssistant", ",", "logger", ":", "logging", ".", "Logger", ",", "*", ",", "name", ":", "str", ",", "update_interval", ":", "Optional", "[", "timedelta", "]", "=", "None", ",", "update_method", ":", ...
[ 30, 4 ]
[ 66, 59 ]
python
en
['es', 'en', 'it']
False
DataUpdateCoordinator.async_add_listener
(self, update_callback: CALLBACK_TYPE)
Listen for data updates.
Listen for data updates.
def async_add_listener(self, update_callback: CALLBACK_TYPE) -> Callable[[], None]: """Listen for data updates.""" schedule_refresh = not self._listeners self._listeners.append(update_callback) # This is the first listener, set up interval. if schedule_refresh: self...
[ "def", "async_add_listener", "(", "self", ",", "update_callback", ":", "CALLBACK_TYPE", ")", "->", "Callable", "[", "[", "]", ",", "None", "]", ":", "schedule_refresh", "=", "not", "self", ".", "_listeners", "self", ".", "_listeners", ".", "append", "(", "...
[ 69, 4 ]
[ 84, 30 ]
python
da
['da', 'no', 'en']
False
DataUpdateCoordinator.async_remove_listener
(self, update_callback: CALLBACK_TYPE)
Remove data update.
Remove data update.
def async_remove_listener(self, update_callback: CALLBACK_TYPE) -> None: """Remove data update.""" self._listeners.remove(update_callback) if not self._listeners and self._unsub_refresh: self._unsub_refresh() self._unsub_refresh = None
[ "def", "async_remove_listener", "(", "self", ",", "update_callback", ":", "CALLBACK_TYPE", ")", "->", "None", ":", "self", ".", "_listeners", ".", "remove", "(", "update_callback", ")", "if", "not", "self", ".", "_listeners", "and", "self", ".", "_unsub_refres...
[ 87, 4 ]
[ 93, 38 ]
python
en
['fr', 'it', 'en']
False
DataUpdateCoordinator._schedule_refresh
(self)
Schedule a refresh.
Schedule a refresh.
def _schedule_refresh(self) -> None: """Schedule a refresh.""" if self.update_interval is None: return if self._unsub_refresh: self._unsub_refresh() self._unsub_refresh = None # We _floor_ utcnow to create a schedule on a rounded second, # mi...
[ "def", "_schedule_refresh", "(", "self", ")", "->", "None", ":", "if", "self", ".", "update_interval", "is", "None", ":", "return", "if", "self", ".", "_unsub_refresh", ":", "self", ".", "_unsub_refresh", "(", ")", "self", ".", "_unsub_refresh", "=", "None...
[ 96, 4 ]
[ 113, 9 ]
python
en
['en', 'de', 'en']
True
DataUpdateCoordinator._handle_refresh_interval
(self, _now: datetime)
Handle a refresh interval occurrence.
Handle a refresh interval occurrence.
async def _handle_refresh_interval(self, _now: datetime) -> None: """Handle a refresh interval occurrence.""" self._unsub_refresh = None await self.async_refresh()
[ "async", "def", "_handle_refresh_interval", "(", "self", ",", "_now", ":", "datetime", ")", "->", "None", ":", "self", ".", "_unsub_refresh", "=", "None", "await", "self", ".", "async_refresh", "(", ")" ]
[ 115, 4 ]
[ 118, 34 ]
python
en
['en', 'en', 'en']
True
DataUpdateCoordinator.async_request_refresh
(self)
Request a refresh. Refresh will wait a bit to see if it can batch them.
Request a refresh.
async def async_request_refresh(self) -> None: """Request a refresh. Refresh will wait a bit to see if it can batch them. """ await self._debounced_refresh.async_call()
[ "async", "def", "async_request_refresh", "(", "self", ")", "->", "None", ":", "await", "self", ".", "_debounced_refresh", ".", "async_call", "(", ")" ]
[ 120, 4 ]
[ 125, 50 ]
python
en
['en', 'en', 'en']
True
DataUpdateCoordinator._async_update_data
(self)
Fetch the latest data from the source.
Fetch the latest data from the source.
async def _async_update_data(self) -> Optional[T]: """Fetch the latest data from the source.""" if self.update_method is None: raise NotImplementedError("Update method not implemented") return await self.update_method()
[ "async", "def", "_async_update_data", "(", "self", ")", "->", "Optional", "[", "T", "]", ":", "if", "self", ".", "update_method", "is", "None", ":", "raise", "NotImplementedError", "(", "\"Update method not implemented\"", ")", "return", "await", "self", ".", ...
[ 127, 4 ]
[ 131, 41 ]
python
en
['en', 'en', 'en']
True
DataUpdateCoordinator.async_refresh
(self)
Refresh data.
Refresh data.
async def async_refresh(self) -> None: """Refresh data.""" if self._unsub_refresh: self._unsub_refresh() self._unsub_refresh = None self._debounced_refresh.async_cancel() start = monotonic() try: self.data = await self._async_update_data() ...
[ "async", "def", "async_refresh", "(", "self", ")", "->", "None", ":", "if", "self", ".", "_unsub_refresh", ":", "self", ".", "_unsub_refresh", "(", ")", "self", ".", "_unsub_refresh", "=", "None", "self", ".", "_debounced_refresh", ".", "async_cancel", "(", ...
[ 133, 4 ]
[ 192, 29 ]
python
de
['de', 'sn', 'en']
False
DataUpdateCoordinator.async_set_updated_data
(self, data: T)
Manually update data, notify listeners and reset refresh interval.
Manually update data, notify listeners and reset refresh interval.
def async_set_updated_data(self, data: T) -> None: """Manually update data, notify listeners and reset refresh interval.""" if self._unsub_refresh: self._unsub_refresh() self._unsub_refresh = None self._debounced_refresh.async_cancel() self.data = data s...
[ "def", "async_set_updated_data", "(", "self", ",", "data", ":", "T", ")", "->", "None", ":", "if", "self", ".", "_unsub_refresh", ":", "self", ".", "_unsub_refresh", "(", ")", "self", ".", "_unsub_refresh", "=", "None", "self", ".", "_debounced_refresh", "...
[ 195, 4 ]
[ 214, 29 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity.__init__
(self, coordinator: DataUpdateCoordinator)
Create the entity with a DataUpdateCoordinator.
Create the entity with a DataUpdateCoordinator.
def __init__(self, coordinator: DataUpdateCoordinator) -> None: """Create the entity with a DataUpdateCoordinator.""" self.coordinator = coordinator
[ "def", "__init__", "(", "self", ",", "coordinator", ":", "DataUpdateCoordinator", ")", "->", "None", ":", "self", ".", "coordinator", "=", "coordinator" ]
[ 220, 4 ]
[ 222, 38 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity.should_poll
(self)
No need to poll. Coordinator notifies entity of updates.
No need to poll. Coordinator notifies entity of updates.
def should_poll(self) -> bool: """No need to poll. Coordinator notifies entity of updates.""" return False
[ "def", "should_poll", "(", "self", ")", "->", "bool", ":", "return", "False" ]
[ 225, 4 ]
[ 227, 20 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity.available
(self)
Return if entity is available.
Return if entity is available.
def available(self) -> bool: """Return if entity is available.""" return self.coordinator.last_update_success
[ "def", "available", "(", "self", ")", "->", "bool", ":", "return", "self", ".", "coordinator", ".", "last_update_success" ]
[ 230, 4 ]
[ 232, 51 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity.async_added_to_hass
(self)
When entity is added to hass.
When entity is added to hass.
async def async_added_to_hass(self) -> None: """When entity is added to hass.""" await super().async_added_to_hass() self.async_on_remove( self.coordinator.async_add_listener(self._handle_coordinator_update) )
[ "async", "def", "async_added_to_hass", "(", "self", ")", "->", "None", ":", "await", "super", "(", ")", ".", "async_added_to_hass", "(", ")", "self", ".", "async_on_remove", "(", "self", ".", "coordinator", ".", "async_add_listener", "(", "self", ".", "_hand...
[ 234, 4 ]
[ 239, 9 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity._handle_coordinator_update
(self)
Handle updated data from the coordinator.
Handle updated data from the coordinator.
def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" self.async_write_ha_state()
[ "def", "_handle_coordinator_update", "(", "self", ")", "->", "None", ":", "self", ".", "async_write_ha_state", "(", ")" ]
[ 242, 4 ]
[ 244, 35 ]
python
en
['en', 'en', 'en']
True
CoordinatorEntity.async_update
(self)
Update the entity. Only used by the generic entity update service.
Update the entity.
async def async_update(self) -> None: """Update the entity. Only used by the generic entity update service. """ # Ignore manual update requests if the entity is disabled if not self.enabled: return await self.coordinator.async_request_refresh()
[ "async", "def", "async_update", "(", "self", ")", "->", "None", ":", "# Ignore manual update requests if the entity is disabled", "if", "not", "self", ".", "enabled", ":", "return", "await", "self", ".", "coordinator", ".", "async_request_refresh", "(", ")" ]
[ 246, 4 ]
[ 256, 54 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass, config_entry, async_add_entities)
Set up Homekit air quality sensor.
Set up Homekit air quality sensor.
async def async_setup_entry(hass, config_entry, async_add_entities): """Set up Homekit air quality sensor.""" hkid = config_entry.data["AccessoryPairingID"] conn = hass.data[KNOWN_DEVICES][hkid] @callback def async_add_service(service): if service.short_type != ServicesTypes.AIR_QUALITY_SEN...
[ "async", "def", "async_setup_entry", "(", "hass", ",", "config_entry", ",", "async_add_entities", ")", ":", "hkid", "=", "config_entry", ".", "data", "[", "\"AccessoryPairingID\"", "]", "conn", "=", "hass", ".", "data", "[", "KNOWN_DEVICES", "]", "[", "hkid", ...
[ 82, 0 ]
[ 95, 40 ]
python
en
['en', 'pt', 'en']
True
HomeAirQualitySensor.get_characteristic_types
(self)
Define the homekit characteristics the entity cares about.
Define the homekit characteristics the entity cares about.
def get_characteristic_types(self): """Define the homekit characteristics the entity cares about.""" return [ CharacteristicsTypes.AIR_QUALITY, CharacteristicsTypes.DENSITY_PM25, CharacteristicsTypes.DENSITY_PM10, CharacteristicsTypes.DENSITY_OZONE, ...
[ "def", "get_characteristic_types", "(", "self", ")", ":", "return", "[", "CharacteristicsTypes", ".", "AIR_QUALITY", ",", "CharacteristicsTypes", ".", "DENSITY_PM25", ",", "CharacteristicsTypes", ".", "DENSITY_PM10", ",", "CharacteristicsTypes", ".", "DENSITY_OZONE", ",...
[ 22, 4 ]
[ 32, 9 ]
python
en
['en', 'en', 'en']
True
HomeAirQualitySensor.particulate_matter_2_5
(self)
Return the particulate matter 2.5 level.
Return the particulate matter 2.5 level.
def particulate_matter_2_5(self): """Return the particulate matter 2.5 level.""" return self.service.value(CharacteristicsTypes.DENSITY_PM25)
[ "def", "particulate_matter_2_5", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_PM25", ")" ]
[ 35, 4 ]
[ 37, 68 ]
python
en
['en', 'en', 'en']
True
HomeAirQualitySensor.particulate_matter_10
(self)
Return the particulate matter 10 level.
Return the particulate matter 10 level.
def particulate_matter_10(self): """Return the particulate matter 10 level.""" return self.service.value(CharacteristicsTypes.DENSITY_PM10)
[ "def", "particulate_matter_10", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_PM10", ")" ]
[ 40, 4 ]
[ 42, 68 ]
python
en
['en', 'en', 'en']
True
HomeAirQualitySensor.ozone
(self)
Return the O3 (ozone) level.
Return the O3 (ozone) level.
def ozone(self): """Return the O3 (ozone) level.""" return self.service.value(CharacteristicsTypes.DENSITY_OZONE)
[ "def", "ozone", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_OZONE", ")" ]
[ 45, 4 ]
[ 47, 69 ]
python
en
['en', 'ig', 'en']
True
HomeAirQualitySensor.sulphur_dioxide
(self)
Return the SO2 (sulphur dioxide) level.
Return the SO2 (sulphur dioxide) level.
def sulphur_dioxide(self): """Return the SO2 (sulphur dioxide) level.""" return self.service.value(CharacteristicsTypes.DENSITY_SO2)
[ "def", "sulphur_dioxide", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_SO2", ")" ]
[ 50, 4 ]
[ 52, 67 ]
python
en
['en', 'no', 'en']
True
HomeAirQualitySensor.nitrogen_dioxide
(self)
Return the NO2 (nitrogen dioxide) level.
Return the NO2 (nitrogen dioxide) level.
def nitrogen_dioxide(self): """Return the NO2 (nitrogen dioxide) level.""" return self.service.value(CharacteristicsTypes.DENSITY_NO2)
[ "def", "nitrogen_dioxide", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_NO2", ")" ]
[ 55, 4 ]
[ 57, 67 ]
python
en
['en', 'da', 'en']
True
HomeAirQualitySensor.air_quality_text
(self)
Return the Air Quality Index (AQI).
Return the Air Quality Index (AQI).
def air_quality_text(self): """Return the Air Quality Index (AQI).""" air_quality = self.service.value(CharacteristicsTypes.AIR_QUALITY) return AIR_QUALITY_TEXT.get(air_quality, "unknown")
[ "def", "air_quality_text", "(", "self", ")", ":", "air_quality", "=", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "AIR_QUALITY", ")", "return", "AIR_QUALITY_TEXT", ".", "get", "(", "air_quality", ",", "\"unknown\"", ")" ]
[ 60, 4 ]
[ 63, 59 ]
python
en
['en', 'cy', 'en']
True
HomeAirQualitySensor.volatile_organic_compounds
(self)
Return the volatile organic compounds (VOC) level.
Return the volatile organic compounds (VOC) level.
def volatile_organic_compounds(self): """Return the volatile organic compounds (VOC) level.""" return self.service.value(CharacteristicsTypes.DENSITY_VOC)
[ "def", "volatile_organic_compounds", "(", "self", ")", ":", "return", "self", ".", "service", ".", "value", "(", "CharacteristicsTypes", ".", "DENSITY_VOC", ")" ]
[ 66, 4 ]
[ 68, 67 ]
python
en
['en', 'fr', 'en']
True
HomeAirQualitySensor.device_state_attributes
(self)
Return the device state attributes.
Return the device state attributes.
def device_state_attributes(self): """Return the device state attributes.""" data = {"air_quality_text": self.air_quality_text} voc = self.volatile_organic_compounds if voc: data["volatile_organic_compounds"] = voc return data
[ "def", "device_state_attributes", "(", "self", ")", ":", "data", "=", "{", "\"air_quality_text\"", ":", "self", ".", "air_quality_text", "}", "voc", "=", "self", ".", "volatile_organic_compounds", "if", "voc", ":", "data", "[", "\"volatile_organic_compounds\"", "]...
[ 71, 4 ]
[ 79, 19 ]
python
en
['en', 'en', 'en']
True
setup_platform
(hass, config, add_entities, discovery_info=None)
Set up the MPC-HC platform.
Set up the MPC-HC platform.
def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the MPC-HC platform.""" name = config.get(CONF_NAME) host = config.get(CONF_HOST) port = config.get(CONF_PORT) url = f"{host}:{port}" add_entities([MpcHcDevice(name, url)], True)
[ "def", "setup_platform", "(", "hass", ",", "config", ",", "add_entities", ",", "discovery_info", "=", "None", ")", ":", "name", "=", "config", ".", "get", "(", "CONF_NAME", ")", "host", "=", "config", ".", "get", "(", "CONF_HOST", ")", "port", "=", "co...
[ 52, 0 ]
[ 60, 48 ]
python
en
['en', 'lv', 'en']
True
MpcHcDevice.__init__
(self, name, url)
Initialize the MPC-HC device.
Initialize the MPC-HC device.
def __init__(self, name, url): """Initialize the MPC-HC device.""" self._name = name self._url = url self._player_variables = {} self._available = False
[ "def", "__init__", "(", "self", ",", "name", ",", "url", ")", ":", "self", ".", "_name", "=", "name", "self", ".", "_url", "=", "url", "self", ".", "_player_variables", "=", "{", "}", "self", ".", "_available", "=", "False" ]
[ 66, 4 ]
[ 71, 31 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.update
(self)
Get the latest details.
Get the latest details.
def update(self): """Get the latest details.""" try: response = requests.get(f"{self._url}/variables.html", data=None, timeout=3) mpchc_variables = re.findall(r'<p id="(.+?)">(.+?)</p>', response.text) for var in mpchc_variables: self._player_variabl...
[ "def", "update", "(", "self", ")", ":", "try", ":", "response", "=", "requests", ".", "get", "(", "f\"{self._url}/variables.html\"", ",", "data", "=", "None", ",", "timeout", "=", "3", ")", "mpchc_variables", "=", "re", ".", "findall", "(", "r'<p id=\"(.+?...
[ 73, 4 ]
[ 88, 35 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice._send_command
(self, command_id)
Send a command to MPC-HC via its window message ID.
Send a command to MPC-HC via its window message ID.
def _send_command(self, command_id): """Send a command to MPC-HC via its window message ID.""" try: params = {"wm_command": command_id} requests.get(f"{self._url}/command.html", params=params, timeout=3) except requests.exceptions.RequestException: _LOGGER.err...
[ "def", "_send_command", "(", "self", ",", "command_id", ")", ":", "try", ":", "params", "=", "{", "\"wm_command\"", ":", "command_id", "}", "requests", ".", "get", "(", "f\"{self._url}/command.html\"", ",", "params", "=", "params", ",", "timeout", "=", "3", ...
[ 90, 4 ]
[ 98, 13 ]
python
en
['en', 'mk', 'en']
True
MpcHcDevice.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" ]
[ 101, 4 ]
[ 103, 25 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.state
(self)
Return the state of the device.
Return the state of the device.
def state(self): """Return the state of the device.""" state = self._player_variables.get("statestring", None) if state is None: return STATE_OFF if state == "playing": return STATE_PLAYING if state == "paused": return STATE_PAUSED re...
[ "def", "state", "(", "self", ")", ":", "state", "=", "self", ".", "_player_variables", ".", "get", "(", "\"statestring\"", ",", "None", ")", "if", "state", "is", "None", ":", "return", "STATE_OFF", "if", "state", "==", "\"playing\"", ":", "return", "STAT...
[ 106, 4 ]
[ 117, 25 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.available
(self)
Return True if entity is available.
Return True if entity is available.
def available(self): """Return True if entity is available.""" return self._available
[ "def", "available", "(", "self", ")", ":", "return", "self", ".", "_available" ]
[ 120, 4 ]
[ 122, 30 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.media_title
(self)
Return the title of current playing media.
Return the title of current playing media.
def media_title(self): """Return the title of current playing media.""" return self._player_variables.get("file", None)
[ "def", "media_title", "(", "self", ")", ":", "return", "self", ".", "_player_variables", ".", "get", "(", "\"file\"", ",", "None", ")" ]
[ 125, 4 ]
[ 127, 55 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.volume_level
(self)
Return the volume level of the media player (0..1).
Return the volume level of the media player (0..1).
def volume_level(self): """Return the volume level of the media player (0..1).""" return int(self._player_variables.get("volumelevel", 0)) / 100.0
[ "def", "volume_level", "(", "self", ")", ":", "return", "int", "(", "self", ".", "_player_variables", ".", "get", "(", "\"volumelevel\"", ",", "0", ")", ")", "/", "100.0" ]
[ 130, 4 ]
[ 132, 72 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.is_volume_muted
(self)
Return boolean if volume is currently muted.
Return boolean if volume is currently muted.
def is_volume_muted(self): """Return boolean if volume is currently muted.""" return self._player_variables.get("muted", "0") == "1"
[ "def", "is_volume_muted", "(", "self", ")", ":", "return", "self", ".", "_player_variables", ".", "get", "(", "\"muted\"", ",", "\"0\"", ")", "==", "\"1\"" ]
[ 135, 4 ]
[ 137, 62 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.media_duration
(self)
Return the duration of the current playing media in seconds.
Return the duration of the current playing media in seconds.
def media_duration(self): """Return the duration of the current playing media in seconds.""" duration = self._player_variables.get("durationstring", "00:00:00").split(":") return int(duration[0]) * 3600 + int(duration[1]) * 60 + int(duration[2])
[ "def", "media_duration", "(", "self", ")", ":", "duration", "=", "self", ".", "_player_variables", ".", "get", "(", "\"durationstring\"", ",", "\"00:00:00\"", ")", ".", "split", "(", "\":\"", ")", "return", "int", "(", "duration", "[", "0", "]", ")", "*"...
[ 140, 4 ]
[ 143, 81 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.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_MPCHC
[ "def", "supported_features", "(", "self", ")", ":", "return", "SUPPORT_MPCHC" ]
[ 146, 4 ]
[ 148, 28 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.volume_up
(self)
Volume up the media player.
Volume up the media player.
def volume_up(self): """Volume up the media player.""" self._send_command(907)
[ "def", "volume_up", "(", "self", ")", ":", "self", ".", "_send_command", "(", "907", ")" ]
[ 150, 4 ]
[ 152, 31 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.volume_down
(self)
Volume down media player.
Volume down media player.
def volume_down(self): """Volume down media player.""" self._send_command(908)
[ "def", "volume_down", "(", "self", ")", ":", "self", ".", "_send_command", "(", "908", ")" ]
[ 154, 4 ]
[ 156, 31 ]
python
en
['en', 'sl', 'en']
True
MpcHcDevice.mute_volume
(self, mute)
Mute the volume.
Mute the volume.
def mute_volume(self, mute): """Mute the volume.""" self._send_command(909)
[ "def", "mute_volume", "(", "self", ",", "mute", ")", ":", "self", ".", "_send_command", "(", "909", ")" ]
[ 158, 4 ]
[ 160, 31 ]
python
en
['en', 'sn', 'en']
True
MpcHcDevice.media_play
(self)
Send play command.
Send play command.
def media_play(self): """Send play command.""" self._send_command(887)
[ "def", "media_play", "(", "self", ")", ":", "self", ".", "_send_command", "(", "887", ")" ]
[ 162, 4 ]
[ 164, 31 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.media_pause
(self)
Send pause command.
Send pause command.
def media_pause(self): """Send pause command.""" self._send_command(888)
[ "def", "media_pause", "(", "self", ")", ":", "self", ".", "_send_command", "(", "888", ")" ]
[ 166, 4 ]
[ 168, 31 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.media_stop
(self)
Send stop command.
Send stop command.
def media_stop(self): """Send stop command.""" self._send_command(890)
[ "def", "media_stop", "(", "self", ")", ":", "self", ".", "_send_command", "(", "890", ")" ]
[ 170, 4 ]
[ 172, 31 ]
python
en
['en', 'en', 'en']
True
MpcHcDevice.media_next_track
(self)
Send next track command.
Send next track command.
def media_next_track(self): """Send next track command.""" self._send_command(920)
[ "def", "media_next_track", "(", "self", ")", ":", "self", ".", "_send_command", "(", "920", ")" ]
[ 174, 4 ]
[ 176, 31 ]
python
en
['en', 'pt', 'en']
True
MpcHcDevice.media_previous_track
(self)
Send previous track command.
Send previous track command.
def media_previous_track(self): """Send previous track command.""" self._send_command(919)
[ "def", "media_previous_track", "(", "self", ")", ":", "self", ".", "_send_command", "(", "919", ")" ]
[ 178, 4 ]
[ 180, 31 ]
python
en
['en', 'it', 'en']
True
async_setup
(hass: HomeAssistant, config: dict)
Set up the Garmin Connect component.
Set up the Garmin Connect component.
async def async_setup(hass: HomeAssistant, config: dict): """Set up the Garmin Connect component.""" hass.data[DOMAIN] = {} return True
[ "async", "def", "async_setup", "(", "hass", ":", "HomeAssistant", ",", "config", ":", "dict", ")", ":", "hass", ".", "data", "[", "DOMAIN", "]", "=", "{", "}", "return", "True" ]
[ 26, 0 ]
[ 29, 15 ]
python
en
['en', 'en', 'en']
True
async_setup_entry
(hass: HomeAssistant, entry: ConfigEntry)
Set up Garmin Connect from a config entry.
Set up Garmin Connect from a config entry.
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Garmin Connect from a config entry.""" username = entry.data[CONF_USERNAME] password = entry.data[CONF_PASSWORD] garmin_client = Garmin(username, password) try: await hass.async_add_executor_job(garmin_client.l...
[ "async", "def", "async_setup_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "username", "=", "entry", ".", "data", "[", "CONF_USERNAME", "]", "password", "=", "entry", ".", "data", "[", "CONF_PASSWORD", "]", "garmin_cl...
[ 32, 0 ]
[ 64, 15 ]
python
en
['en', 'en', '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 PLATFORMS ] ) ...
[ "async", "def", "async_unload_entry", "(", "hass", ":", "HomeAssistant", ",", "entry", ":", "ConfigEntry", ")", ":", "unload_ok", "=", "all", "(", "await", "asyncio", ".", "gather", "(", "*", "[", "hass", ".", "config_entries", ".", "async_forward_entry_unload...
[ 67, 0 ]
[ 80, 20 ]
python
en
['en', 'es', 'en']
True
GarminConnectData.__init__
(self, hass, client)
Initialize.
Initialize.
def __init__(self, hass, client): """Initialize.""" self.hass = hass self.client = client self.data = None
[ "def", "__init__", "(", "self", ",", "hass", ",", "client", ")", ":", "self", ".", "hass", "=", "hass", "self", ".", "client", "=", "client", "self", ".", "data", "=", "None" ]
[ 86, 4 ]
[ 90, 24 ]
python
en
['en', 'en', 'it']
False
GarminConnectData._get_combined_alarms_of_all_devices
(self)
Combine the list of active alarms from all garmin devices.
Combine the list of active alarms from all garmin devices.
async def _get_combined_alarms_of_all_devices(self): """Combine the list of active alarms from all garmin devices.""" alarms = [] devices = await self.hass.async_add_executor_job(self.client.get_devices) for device in devices: device_settings = await self.hass.async_add_execu...
[ "async", "def", "_get_combined_alarms_of_all_devices", "(", "self", ")", ":", "alarms", "=", "[", "]", "devices", "=", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "client", ".", "get_devices", ")", "for", "device", "in", "d...
[ 92, 4 ]
[ 101, 21 ]
python
en
['en', 'en', 'en']
True
GarminConnectData.async_update
(self)
Update data via library.
Update data via library.
async def async_update(self): """Update data via library.""" today = date.today() try: self.data = await self.hass.async_add_executor_job( self.client.get_stats_and_body, today.isoformat() ) self.data["nextAlarm"] = await self._get_combined_al...
[ "async", "def", "async_update", "(", "self", ")", ":", "today", "=", "date", ".", "today", "(", ")", "try", ":", "self", ".", "data", "=", "await", "self", ".", "hass", ".", "async_add_executor_job", "(", "self", ".", "client", ".", "get_stats_and_body",...
[ 104, 4 ]
[ 126, 18 ]
python
en
['fr', 'en', 'en']
True
storage_setup
(hass, hass_storage)
Storage setup.
Storage setup.
def storage_setup(hass, hass_storage): """Storage setup.""" async def _storage(items=None, config=None): if items is None: hass_storage[DOMAIN] = { "key": DOMAIN, "version": 1, "data": { "items": [ {...
[ "def", "storage_setup", "(", "hass", ",", "hass_storage", ")", ":", "async", "def", "_storage", "(", "items", "=", "None", ",", "config", "=", "None", ")", ":", "if", "items", "is", "None", ":", "hass_storage", "[", "DOMAIN", "]", "=", "{", "\"key\"", ...
[ 29, 0 ]
[ 61, 19 ]
python
en
['en', 'bs', 'en']
False
set_value
(hass, entity_id, value)
Set input_number to value. This is a legacy helper method. Do not use it for new tests.
Set input_number to value.
async def set_value(hass, entity_id, value): """Set input_number to value. This is a legacy helper method. Do not use it for new tests. """ await hass.services.async_call( DOMAIN, SERVICE_SET_VALUE, {ATTR_ENTITY_ID: entity_id, ATTR_VALUE: value}, blocking=True, )
[ "async", "def", "set_value", "(", "hass", ",", "entity_id", ",", "value", ")", ":", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_SET_VALUE", ",", "{", "ATTR_ENTITY_ID", ":", "entity_id", ",", "ATTR_VALUE", ":", "value", ...
[ 64, 0 ]
[ 74, 5 ]
python
en
['en', 'en', 'en']
True
increment
(hass, entity_id)
Increment value of entity. This is a legacy helper method. Do not use it for new tests.
Increment value of entity.
async def increment(hass, entity_id): """Increment value of entity. This is a legacy helper method. Do not use it for new tests. """ await hass.services.async_call( DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id}, blocking=True )
[ "async", "def", "increment", "(", "hass", ",", "entity_id", ")", ":", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_INCREMENT", ",", "{", "ATTR_ENTITY_ID", ":", "entity_id", "}", ",", "blocking", "=", "True", ")" ]
[ 77, 0 ]
[ 84, 5 ]
python
en
['en', 'en', 'en']
True
decrement
(hass, entity_id)
Decrement value of entity. This is a legacy helper method. Do not use it for new tests.
Decrement value of entity.
async def decrement(hass, entity_id): """Decrement value of entity. This is a legacy helper method. Do not use it for new tests. """ await hass.services.async_call( DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id}, blocking=True )
[ "async", "def", "decrement", "(", "hass", ",", "entity_id", ")", ":", "await", "hass", ".", "services", ".", "async_call", "(", "DOMAIN", ",", "SERVICE_DECREMENT", ",", "{", "ATTR_ENTITY_ID", ":", "entity_id", "}", ",", "blocking", "=", "True", ")" ]
[ 87, 0 ]
[ 94, 5 ]
python
en
['en', 'fr', 'en']
True
test_config
(hass)
Test config.
Test config.
async def test_config(hass): """Test config.""" invalid_configs = [ None, {}, {"name with space": None}, {"test_1": {"min": 50, "max": 50}}, ] for cfg in invalid_configs: assert not await async_setup_component(hass, DOMAIN, {DOMAIN: cfg})
[ "async", "def", "test_config", "(", "hass", ")", ":", "invalid_configs", "=", "[", "None", ",", "{", "}", ",", "{", "\"name with space\"", ":", "None", "}", ",", "{", "\"test_1\"", ":", "{", "\"min\"", ":", "50", ",", "\"max\"", ":", "50", "}", "}", ...
[ 97, 0 ]
[ 106, 75 ]
python
en
['en', 'en', 'en']
False
test_set_value
(hass, caplog)
Test set_value method.
Test set_value method.
async def test_set_value(hass, caplog): """Test set_value method.""" assert await async_setup_component( hass, DOMAIN, {DOMAIN: {"test_1": {"initial": 50, "min": 0, "max": 100}}} ) entity_id = "input_number.test_1" state = hass.states.get(entity_id) assert 50 == float(state.state) ...
[ "async", "def", "test_set_value", "(", "hass", ",", "caplog", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "{", "DOMAIN", ":", "{", "\"test_1\"", ":", "{", "\"initial\"", ":", "50", ",", "\"min\"", ":", "0", ",",...
[ 109, 0 ]
[ 137, 35 ]
python
en
['en', 'et', 'en']
True
test_increment
(hass)
Test increment method.
Test increment method.
async def test_increment(hass): """Test increment method.""" assert await async_setup_component( hass, DOMAIN, {DOMAIN: {"test_2": {"initial": 50, "min": 0, "max": 51}}} ) entity_id = "input_number.test_2" state = hass.states.get(entity_id) assert 50 == float(state.state) await inc...
[ "async", "def", "test_increment", "(", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "{", "DOMAIN", ":", "{", "\"test_2\"", ":", "{", "\"initial\"", ":", "50", ",", "\"min\"", ":", "0", ",", "\"max\"", ":"...
[ 140, 0 ]
[ 160, 35 ]
python
en
['en', 'la', 'en']
True
test_decrement
(hass)
Test decrement method.
Test decrement method.
async def test_decrement(hass): """Test decrement method.""" assert await async_setup_component( hass, DOMAIN, {DOMAIN: {"test_3": {"initial": 50, "min": 49, "max": 100}}} ) entity_id = "input_number.test_3" state = hass.states.get(entity_id) assert 50 == float(state.state) await d...
[ "async", "def", "test_decrement", "(", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "{", "DOMAIN", ":", "{", "\"test_3\"", ":", "{", "\"initial\"", ":", "50", ",", "\"min\"", ":", "49", ",", "\"max\"", ":...
[ 163, 0 ]
[ 183, 35 ]
python
en
['fr', 'la', 'en']
False
test_mode
(hass)
Test mode settings.
Test mode settings.
async def test_mode(hass): """Test mode settings.""" assert await async_setup_component( hass, DOMAIN, { DOMAIN: { "test_default_slider": {"min": 0, "max": 100}, "test_explicit_box": {"min": 0, "max": 100, "mode": "box"}, "test_...
[ "async", "def", "test_mode", "(", "hass", ")", ":", "assert", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "{", "DOMAIN", ":", "{", "\"test_default_slider\"", ":", "{", "\"min\"", ":", "0", ",", "\"max\"", ":", "100", "}", ",", "\"t...
[ 186, 0 ]
[ 210, 47 ]
python
en
['en', 'no', 'en']
True
test_restore_state
(hass)
Ensure states are restored on startup.
Ensure states are restored on startup.
async def test_restore_state(hass): """Ensure states are restored on startup.""" mock_restore_cache( hass, (State("input_number.b1", "70"), State("input_number.b2", "200")) ) hass.state = CoreState.starting await async_setup_component( hass, DOMAIN, {DOMAIN: {"b1": ...
[ "async", "def", "test_restore_state", "(", "hass", ")", ":", "mock_restore_cache", "(", "hass", ",", "(", "State", "(", "\"input_number.b1\"", ",", "\"70\"", ")", ",", "State", "(", "\"input_number.b2\"", ",", "\"200\"", ")", ")", ")", "hass", ".", "state", ...
[ 213, 0 ]
[ 233, 35 ]
python
en
['en', 'en', 'en']
True
test_initial_state_overrules_restore_state
(hass)
Ensure states are restored on startup.
Ensure states are restored on startup.
async def test_initial_state_overrules_restore_state(hass): """Ensure states are restored on startup.""" mock_restore_cache( hass, (State("input_number.b1", "70"), State("input_number.b2", "200")) ) hass.state = CoreState.starting await async_setup_component( hass, DOMAIN, ...
[ "async", "def", "test_initial_state_overrules_restore_state", "(", "hass", ")", ":", "mock_restore_cache", "(", "hass", ",", "(", "State", "(", "\"input_number.b1\"", ",", "\"70\"", ")", ",", "State", "(", "\"input_number.b2\"", ",", "\"200\"", ")", ")", ")", "h...
[ 236, 0 ]
[ 261, 35 ]
python
en
['en', 'en', 'en']
True
test_no_initial_state_and_no_restore_state
(hass)
Ensure that entity is create without initial and restore feature.
Ensure that entity is create without initial and restore feature.
async def test_no_initial_state_and_no_restore_state(hass): """Ensure that entity is create without initial and restore feature.""" hass.state = CoreState.starting await async_setup_component(hass, DOMAIN, {DOMAIN: {"b1": {"min": 0, "max": 100}}}) state = hass.states.get("input_number.b1") assert ...
[ "async", "def", "test_no_initial_state_and_no_restore_state", "(", "hass", ")", ":", "hass", ".", "state", "=", "CoreState", ".", "starting", "await", "async_setup_component", "(", "hass", ",", "DOMAIN", ",", "{", "DOMAIN", ":", "{", "\"b1\"", ":", "{", "\"min...
[ 264, 0 ]
[ 272, 34 ]
python
en
['en', 'en', 'en']
True