code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def _html_sub(m: re.Match[str]) -> str: """ Substitute raw html with plain text. """ try: raw = md.htmlStash.rawHtmlBlocks[int(m.group(1))] except (IndexError, TypeError): # pragma: no cover return m.group(0) # Strip out tags and/or entities - leaving text ...
Substitute raw html with plain text.
_html_sub
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def strip_tags(text: str) -> str: """ Strip HTML tags and return plain text. Note: HTML entities are unaffected. """ # A comment could contain a tag, so strip comments first while (start := text.find('<!--')) != -1 and (end := text.find('-->', start)) != -1: text = f'{text[:start]}{text[end + 3:]}' ...
Strip HTML tags and return plain text. Note: HTML entities are unaffected.
strip_tags
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def run_postprocessors(text: str, md: Markdown) -> str: """ Run postprocessors from Markdown instance on text. """ for pp in md.postprocessors: text = pp.run(text) return text.strip()
Run postprocessors from Markdown instance on text.
run_postprocessors
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def render_inner_html(el: etree.Element, md: Markdown) -> str: """ Fully render inner html of an `etree` element as a string. """ # The `UnescapeTreeprocessor` runs after `toc` extension so run here. text = unescape(md.serializer(el)) # strip parent tag start = text.index('>') + 1 end = text.ri...
Fully render inner html of an `etree` element as a string.
render_inner_html
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def remove_fnrefs(root: etree.Element) -> etree.Element: """ Remove footnote references from a copy of the element, if any are present. """ # Remove footnote references, which look like this: `<sup id="fnref:1">...</sup>`. # If there are no `sup` elements, then nothing to do. if next(root.iter('sup'), N...
Remove footnote references from a copy of the element, if any are present.
remove_fnrefs
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def nest_toc_tokens(toc_list): """Given an unsorted list with errors and skips, return a nested one. [{'level': 1}, {'level': 2}] => [{'level': 1, 'children': [{'level': 2, 'children': []}]}] A wrong list is also converted: [{'level': 2}, {'level': 1}] => [{'le...
Given an unsorted list with errors and skips, return a nested one. [{'level': 1}, {'level': 2}] => [{'level': 1, 'children': [{'level': 2, 'children': []}]}] A wrong list is also converted: [{'level': 2}, {'level': 1}] => [{'level': 2, 'children': []}, {'level': 1,...
nest_toc_tokens
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def iterparent(self, node: etree.Element) -> Iterator[tuple[etree.Element, etree.Element]]: """ Iterator wrapper to get allowed parent and child all at once. """ # We do not allow the marker inside a header as that # would causes an endless loop of placing a new TOC # inside previously ...
Iterator wrapper to get allowed parent and child all at once.
iterparent
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def set_level(self, elem: etree.Element) -> None: """ Adjust header level according to base level. """ level = int(elem.tag[-1]) + self.base_level if level > 6: level = 6 elem.tag = 'h%d' % level
Adjust header level according to base level.
set_level
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def build_toc_div(self, toc_list: list) -> etree.Element: """ Return a string div given a toc list. """ div = etree.Element("div") div.attrib["class"] = self.toc_class # Add title to the div if self.title: header = etree.SubElement(div, "span") if self.ti...
Return a string div given a toc list.
build_toc_div
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def extendMarkdown(self, md): """ Add TOC tree processor to Markdown. """ md.registerExtension(self) self.md = md self.reset() tocext = self.TreeProcessorClass(md, self.getConfigs()) md.treeprocessors.register(tocext, 'toc', 5)
Add TOC tree processor to Markdown.
extendMarkdown
python
Python-Markdown/markdown
markdown/extensions/toc.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/toc.py
BSD-3-Clause
def build_url(label: str, base: str, end: str) -> str: """ Build a URL from the label, a base, and an end. """ clean_label = re.sub(r'([ ]+_)|(_[ ]+)|([ ]+)', '_', label) return '{}{}{}'.format(base, clean_label, end)
Build a URL from the label, a base, and an end.
build_url
python
Python-Markdown/markdown
markdown/extensions/wikilinks.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/wikilinks.py
BSD-3-Clause
def _getMeta(self) -> tuple[str, str, str]: """ Return meta data or `config` data. """ base_url = self.config['base_url'] end_url = self.config['end_url'] html_class = self.config['html_class'] if hasattr(self.md, 'Meta'): if 'wiki_base_url' in self.md.Meta: ...
Return meta data or `config` data.
_getMeta
python
Python-Markdown/markdown
markdown/extensions/wikilinks.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/wikilinks.py
BSD-3-Clause
def getConfig(self, key: str, default: Any = '') -> Any: """ Return a single configuration option value. Arguments: key: The configuration option name. default: Default value to return if key is not set. Returns: Value of stored configuration option....
Return a single configuration option value. Arguments: key: The configuration option name. default: Default value to return if key is not set. Returns: Value of stored configuration option.
getConfig
python
Python-Markdown/markdown
markdown/extensions/__init__.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/__init__.py
BSD-3-Clause
def setConfig(self, key: str, value: Any) -> None: """ Set a configuration option. If the corresponding default value set in [`config`][markdown.extensions.Extension.config] is a `bool` value or `None`, then `value` is passed through [`parseBoolValue`][markdown.util.parseBoolVal...
Set a configuration option. If the corresponding default value set in [`config`][markdown.extensions.Extension.config] is a `bool` value or `None`, then `value` is passed through [`parseBoolValue`][markdown.util.parseBoolValue] before being stored. Arguments: key: ...
setConfig
python
Python-Markdown/markdown
markdown/extensions/__init__.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/__init__.py
BSD-3-Clause
def setConfigs(self, items: Mapping[str, Any] | Iterable[tuple[str, Any]]) -> None: """ Loop through a collection of configuration options, passing each to [`setConfig`][markdown.extensions.Extension.setConfig]. Arguments: items: Collection of configuration options. ...
Loop through a collection of configuration options, passing each to [`setConfig`][markdown.extensions.Extension.setConfig]. Arguments: items: Collection of configuration options. Raises: KeyError: for any unknown key.
setConfigs
python
Python-Markdown/markdown
markdown/extensions/__init__.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/__init__.py
BSD-3-Clause
def extendMarkdown(self, md: Markdown) -> None: """ Add the various processors and patterns to the Markdown Instance. This method must be overridden by every extension. Arguments: md: The Markdown instance. """ raise NotImplementedError( 'Extens...
Add the various processors and patterns to the Markdown Instance. This method must be overridden by every extension. Arguments: md: The Markdown instance.
extendMarkdown
python
Python-Markdown/markdown
markdown/extensions/__init__.py
https://github.com/Python-Markdown/markdown/blob/master/markdown/extensions/__init__.py
BSD-3-Clause
def on_class_instance(self, node: ast.AST | ObjectNode, cls: Class, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002 """Add section to docstrings of deprecated classes.""" if message := _deprecated(cls): self._insert_message(cls, message) cls.labels.add("deprec...
Add section to docstrings of deprecated classes.
on_class_instance
python
Python-Markdown/markdown
scripts/griffe_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/scripts/griffe_extensions.py
BSD-3-Clause
def on_function_instance(self, node: ast.AST | ObjectNode, func: Function, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002 """Add section to docstrings of deprecated functions.""" if message := _deprecated(func): self._insert_message(func, message) func.labels...
Add section to docstrings of deprecated functions.
on_function_instance
python
Python-Markdown/markdown
scripts/griffe_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/scripts/griffe_extensions.py
BSD-3-Clause
def on_function_instance(self, node: ast.AST | ObjectNode, func: Function, agent: Visitor | Inspector, **kwargs: Any) -> None: # noqa: ARG002 """Add table to specified function docstrings.""" if self.paths and func.path not in self.paths: return # skip objects that were not selected ...
Add table to specified function docstrings.
on_function_instance
python
Python-Markdown/markdown
scripts/griffe_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/scripts/griffe_extensions.py
BSD-3-Clause
def getTempFiles(self, src): """ Return the file names for two temp files. """ infd, infile = tempfile.mkstemp(suffix='.txt') with os.fdopen(infd, 'w') as fp: fp.write(src) outfd, outfile = tempfile.mkstemp(suffix='.html') return infile, outfile, outfd
Return the file names for two temp files.
getTempFiles
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testStoreMore(self): """ Test `HtmlStash.store` with additional blocks. """ placeholder = self.stash.store('bar') self.assertEqual(placeholder, self.stash.get_placeholder(1)) self.assertEqual(self.stash.html_counter, 2) self.assertEqual( self.stash.rawHtmlBlocks, ...
Test `HtmlStash.store` with additional blocks.
testStoreMore
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testLoadExtensionFailure(self): """ Test failure of an extension to load. """ self.assertRaises( ImportError, markdown.Markdown, extensions=['non_existant_ext'] )
Test failure of an extension to load.
testLoadExtensionFailure
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testDotNotationExtensionWithBadClass(self): """ Test Extension loading with non-existent class name (`path.to.module:Class`). """ self.assertRaises( AttributeError, markdown.Markdown, extensions=['markdown.extensions.footnotes:MissingExtension'] )
Test Extension loading with non-existent class name (`path.to.module:Class`).
testDotNotationExtensionWithBadClass
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testBaseExtention(self): """ Test that the base Extension class will raise `NotImplemented`. """ self.assertRaises( NotImplementedError, markdown.Markdown, extensions=[markdown.extensions.Extension()] )
Test that the base Extension class will raise `NotImplemented`.
testBaseExtention
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testCommentSerialization(self): """ Test that an `ElementTree` `Comment` serializes properly. """ self.assertEqual( markdown.serializers.to_html_string(self.comment), '<!--foo-->' )
Test that an `ElementTree` `Comment` serializes properly.
testCommentSerialization
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testCommentPrettify(self): """ Test that an `ElementTree` `Comment` is prettified properly. """ pretty = markdown.treeprocessors.PrettifyTreeprocessor(markdown.Markdown()) pretty.run(self.comment) self.assertEqual( markdown.serializers.to_html_string(self.comment), ...
Test that an `ElementTree` `Comment` is prettified properly.
testCommentPrettify
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testBrTailNoNewline(self): """ Test that last `<br>` in tree has a new line tail """ root = etree.Element('root') br = etree.SubElement(root, 'br') self.assertEqual(br.tail, None) self.pretty.run(root) self.assertEqual(br.tail, "\n")
Test that last `<br>` in tree has a new line tail
testBrTailNoNewline
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testBadQNameTag(self): """ Test serialization of `QName` with no tag. """ qname = etree.QName('http://www.w3.org/1998/Math/MathML') el = etree.Element(qname) self.assertRaises(ValueError, markdown.serializers.to_xhtml_string, el)
Test serialization of `QName` with no tag.
testBadQNameTag
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testQNamePreEscaping(self): """ Test `QName` that is already partially escaped. """ qname = etree.QName('&lt;&amp;"test&#10;escaping"&gt;', 'div') el = etree.Element(qname) self.assertEqual( markdown.serializers.to_xhtml_string(el), '<div xmlns="&lt;&amp;&quot...
Test `QName` that is already partially escaped.
testQNamePreEscaping
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def buildExtension(self): """ Build an extension which registers `fakeSerializer`. """ def fakeSerializer(elem): # Ignore input and return hard-coded output return '<div><p>foo</p></div>' class registerFakeSerializer(markdown.extensions.Extension): def extend...
Build an extension which registers `fakeSerializer`.
buildExtension
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testString(self): """ Test that a regular string is parsed. """ tree = etree.Element('div') p = etree.SubElement(tree, 'p') p.text = 'some *text*' new = self.inlineprocessor.run(tree) self.assertEqual( markdown.serializers.to_html_string(new), ...
Test that a regular string is parsed.
testString
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testSimpleAtomicString(self): """ Test that a simple `AtomicString` is not parsed. """ tree = etree.Element('div') p = etree.SubElement(tree, 'p') p.text = markdown.util.AtomicString('some *text*') new = self.inlineprocessor.run(tree) self.assertEqual( mar...
Test that a simple `AtomicString` is not parsed.
testSimpleAtomicString
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testNestedAtomicString(self): """ Test that a nested `AtomicString` is not parsed. """ tree = etree.Element('div') p = etree.SubElement(tree, 'p') p.text = markdown.util.AtomicString('*some* ') span1 = etree.SubElement(p, 'span') span1.text = markdown.util.AtomicStrin...
Test that a nested `AtomicString` is not parsed.
testNestedAtomicString
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testInlineProcessorDoesntCrashWithWrongAtomicString(self): """ Test that an `AtomicString` returned from a Pattern doesn't cause a crash. """ tree = etree.Element('div') p = etree.SubElement(tree, 'p') p.text = 'a marker c' self.md.inlinePatterns.register( _Inline...
Test that an `AtomicString` returned from a Pattern doesn't cause a crash.
testInlineProcessorDoesntCrashWithWrongAtomicString
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def create_config_file(self, config): """ Helper to create temporary configuration files. """ if not isinstance(config, str): # convert to string config = yaml.dump(config) fd, self.tempfile = tempfile.mkstemp('.yml') with os.fdopen(fd, 'w') as fp: fp....
Helper to create temporary configuration files.
create_config_file
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testAppend(self): """ Test that appended escapes are only in the current instance. """ md = markdown.Markdown() md.ESCAPED_CHARS.append('|') self.assertEqual('|' in md.ESCAPED_CHARS, True) md2 = markdown.Markdown() self.assertEqual('|' not in md2.ESCAPED_CHARS, True)
Test that appended escapes are only in the current instance.
testAppend
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def test_ancestors(self): """ Test that an extension can exclude parent tags. """ test = """ Some +test+ and a [+link+](http://test.com) """ result = """<p>Some <strong>test</strong> and a <a href="http://test.com">+link+</a></p>""" self.md.reset() self.assertEqual(self.md.conve...
Test that an extension can exclude parent tags.
test_ancestors
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def test_ancestors_tail(self): """ Test that an extension can exclude parent tags when dealing with a tail. """ test = """ [***+em+*+strong+**](http://test.com) """ result = """<p><a href="http://test.com"><strong><em>+em+</em>+strong+</strong></a></p>""" self.md.reset() self.as...
Test that an extension can exclude parent tags when dealing with a tail.
test_ancestors_tail
python
Python-Markdown/markdown
tests/test_apis.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_apis.py
BSD-3-Clause
def testYamlMetaData(self): """ Test metadata specified as simple YAML. """ text = '''--- Title: A Test Doc. Author: [Waylan Limberg, John Doe] Blank_Data: --- The body. This is paragraph one.''' self.assertEqual( self.md.convert(text), '<p>The body. This is paragraph o...
Test metadata specified as simple YAML.
testYamlMetaData
python
Python-Markdown/markdown
tests/test_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_extensions.py
BSD-3-Clause
def testMetaDataWithoutNewline(self): """ Test document with only metadata and no newline at end.""" text = 'title: No newline' self.assertEqual(self.md.convert(text), '') self.assertEqual(self.md.Meta, {'title': ['No newline']})
Test document with only metadata and no newline at end.
testMetaDataWithoutNewline
python
Python-Markdown/markdown
tests/test_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_extensions.py
BSD-3-Clause
def testMetaDataReset(self): """ Test that reset call remove Meta entirely """ text = '''Title: A Test Doc. Author: Waylan Limberg John Doe Blank_Data: The body. This is paragraph one.''' self.md.convert(text) self.md.reset() self.assertEqual(self.md.Meta, {})
Test that reset call remove Meta entirely
testMetaDataReset
python
Python-Markdown/markdown
tests/test_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_extensions.py
BSD-3-Clause
def testURLCallback(self): """ Test used of a custom URL builder. """ from markdown.extensions.wikilinks import WikiLinkExtension def my_url_builder(label, base, end): return '/bar/' md = markdown.Markdown(extensions=[WikiLinkExtension(build_url=my_url_builder)]) s...
Test used of a custom URL builder.
testURLCallback
python
Python-Markdown/markdown
tests/test_extensions.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_extensions.py
BSD-3-Clause
def test_get_version(self): """Test that _get_version formats __version_info__ as required by PEP 440.""" self.assertEqual(_get_version((1, 1, 2, 'dev', 0)), "1.1.2.dev0") self.assertEqual(_get_version((1, 1, 2, 'alpha', 1)), "1.1.2a1") self.assertEqual(_get_version((1, 2, 0, 'beta', 2)...
Test that _get_version formats __version_info__ as required by PEP 440.
test_get_version
python
Python-Markdown/markdown
tests/test_meta.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_meta.py
BSD-3-Clause
def test__version__IsValid(self): """Test that __version__ is valid and normalized.""" try: import packaging.version except ImportError: self.skipTest('packaging does not appear to be installed') self.assertEqual(__version__, str(packaging.version.Version(__vers...
Test that __version__ is valid and normalized.
test__version__IsValid
python
Python-Markdown/markdown
tests/test_meta.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_meta.py
BSD-3-Clause
def test_backlink_title(self): """Test back-link title configuration without placeholder.""" self.assertMarkdownRenders( 'paragraph[^1]\n\n[^1]: A Footnote', '<p>paragraph<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup></p>\n' '<div class="footnote"...
Test back-link title configuration without placeholder.
test_backlink_title
python
Python-Markdown/markdown
tests/test_syntax/extensions/test_footnotes.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_syntax/extensions/test_footnotes.py
BSD-3-Clause
def load_tests(loader, tests, pattern): """ Ensure `TestHTMLBlocks` doesn't get run twice by excluding it here. """ suite = TestSuite() for test_class in [TestDefaultwMdInHTML, TestMdInHTML, TestMarkdownInHTMLPostProcessor]: tests = loader.loadTestsFromTestCase(test_class) suite.addTests(tes...
Ensure `TestHTMLBlocks` doesn't get run twice by excluding it here.
load_tests
python
Python-Markdown/markdown
tests/test_syntax/extensions/test_md_in_html.py
https://github.com/Python-Markdown/markdown/blob/master/tests/test_syntax/extensions/test_md_in_html.py
BSD-3-Clause
def resize_image(data, sz=(256, 256)): """ Resize image. Please use this resize logic for best results instead of the caffe, since it was used to generate training dataset :param str data: The image data :param sz tuple: The resized image dimensions :returns bytearray: ...
Resize image. Please use this resize logic for best results instead of the caffe, since it was used to generate training dataset :param str data: The image data :param sz tuple: The resized image dimensions :returns bytearray: A byte array with the resized image
resize_image
python
yahoo/open_nsfw
classify_nsfw.py
https://github.com/yahoo/open_nsfw/blob/master/classify_nsfw.py
BSD-2-Clause
def caffe_preprocess_and_compute(pimg, caffe_transformer=None, caffe_net=None, output_layers=None): """ Run a Caffe network on an input image after preprocessing it to prepare it for Caffe. :param PIL.Image pimg: PIL image to be input into Caffe. :param caffe.Net caffe_net: A Caf...
Run a Caffe network on an input image after preprocessing it to prepare it for Caffe. :param PIL.Image pimg: PIL image to be input into Caffe. :param caffe.Net caffe_net: A Caffe network with which to process pimg afrer preprocessing. :param list output_layers: A list of the...
caffe_preprocess_and_compute
python
yahoo/open_nsfw
classify_nsfw.py
https://github.com/yahoo/open_nsfw/blob/master/classify_nsfw.py
BSD-2-Clause
async def async_setup(hass, config): """Track states and offer events for alarm_control_panel.""" return True
Track states and offer events for alarm_control_panel.
async_setup
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the platform from config.""" return True
Set up the platform from config.
async_setup_platform
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_add_alarm_entity(config: dict): """Add each entity as Alarm Control Panel.""" entity_id = "{}.{}".format(PLATFORM, slugify(config["name"])) alarm_entity = AlarmoAreaEntity( hass=hass, entity_id=entity_id, name=config["name"], area_id=con...
Add each entity as Alarm Control Panel.
async_add_alarm_entity
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def code_format(self): """Return whether code consists of digits or characters.""" if ( self._state == AlarmControlPanelState.DISARMED and self.code_arm_required ): return self._config[ATTR_CODE_FORMAT] elif ( self._state != AlarmControlP...
Return whether code consists of digits or characters.
code_format
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def code_arm_required(self): """Whether the code is required for arm actions.""" if not self._config or ATTR_CODE_ARM_REQUIRED not in self._config: return True # assume code is needed (conservative approach) elif self._state != AlarmControlPanelState.DISARMED: return sel...
Whether the code is required for arm actions.
code_arm_required
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def extra_state_attributes(self): """Return the data of the entity.""" return { "arm_mode": self.arm_mode, "next_state": self.next_state, "open_sensors": self.open_sensors, "bypassed_sensors": self.bypassed_sensors, "delay": self.delay, ...
Return the data of the entity.
extra_state_attributes
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_service_disarm_handler(self, code, context_id=None): """handle external disarm request from alarmo.disarm service""" _LOGGER.debug("Service alarmo.disarm was called") self.alarm_disarm( code=code, context_id=context_id )
handle external disarm request from alarmo.disarm service
async_service_disarm_handler
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_service_arm_handler(self, code, mode, skip_delay, force, context_id=None): """handle external arm request from alarmo.arm service""" _LOGGER.debug("Service alarmo.arm was called") if mode in const.ARM_MODE_TO_STATE: mode = const.ARM_MODE_TO_STATE[mode] self.async_...
handle external arm request from alarmo.arm service
async_service_arm_handler
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_handle_arm_request(self, arm_mode, **kwargs): """check if conditions are met for starting arm procedure""" code = kwargs.get(const.CONF_CODE, "") skip_code = kwargs.get("skip_code", False) skip_delay = kwargs.get(const.ATTR_SKIP_DELAY, False) bypass_open_sensors = kwarg...
check if conditions are met for starting arm procedure
async_handle_arm_request
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def next_state(self): """Return the state after transition (countdown) state.""" next_state = self.state if self._state == AlarmControlPanelState.ARMING: next_state = self.arm_mode elif self._state == AlarmControlPanelState.PENDING: next_state = AlarmControlPanelS...
Return the state after transition (countdown) state.
next_state
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_update_state(self, state: str = None): """update the state or refresh state attributes""" if state == self._state: return old_state = self._state self._state = state _LOGGER.debug("entity {} was updated from {} to {}".format(self.entity_id, old_state, sta...
update the state or refresh state attributes
async_update_state
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_arm(self, arm_mode, **kwargs): """Arm the alarm or switch between arm modes.""" skip_delay = kwargs.get("skip_delay", False) skip_validation = kwargs.get("skip_validation", False) self._bypass_open_sensors = kwargs.get("bypass_open_sensors", self._bypass_open_sensors) c...
Arm the alarm or switch between arm modes.
async_arm
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_leave_timer_finished(now): """Update state at a scheduled point in time.""" _LOGGER.debug("async_leave_timer_finished") self.async_clear_timer() self.async_arm( self.arm_mode, skip_d...
Update state at a scheduled point in time.
async_leave_timer_finished
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def async_trigger(self, skip_delay: bool = False, open_sensors: dict = None): """Trigger request. Will only be called the first time a sensor trips.""" if self._state == AlarmControlPanelState.PENDING or skip_delay or not self._arm_mode: entry_delay = 0 else: entry_delay...
Trigger request. Will only be called the first time a sensor trips.
async_trigger
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
def update_ready_to_arm_modes(self, value): """Set arm modes which are ready for arming (no blocking sensors).""" if value == self._ready_to_arm_modes: return _LOGGER.debug("ready_to_arm_modes for {} updated to {}".format(self.name, ", ".join(value).replace("armed_",""))) sel...
Set arm modes which are ready for arming (no blocking sensors).
update_ready_to_arm_modes
python
nielsfaber/alarmo
custom_components/alarmo/alarm_control_panel.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/alarm_control_panel.py
Apache-2.0
async def replace_wildcards_in_string(self, input: str, alarm_entity: AlarmoBaseEntity): """look for wildcards in string and replace them with content.""" # process wildcard '{{open_sensors}}' res = re.search(r'{{open_sensors(\|lang=([^}]+))?(\|format=short)?}}', input) if res: ...
look for wildcards in string and replace them with content.
replace_wildcards_in_string
python
nielsfaber/alarmo
custom_components/alarmo/automations.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/automations.py
Apache-2.0
async def async_get_arm_mode_string(self, arm_mode: str, language: str): """get translation for alarm arm mode""" if ( self._alarmTranslationCache and self._alarmTranslationLang == language ): translations = self._alarmTranslationCache else: ...
get translation for alarm arm mode
async_get_arm_mode_string
python
nielsfaber/alarmo
custom_components/alarmo/automations.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/automations.py
Apache-2.0
async def async_register_card(hass): """publish event to lovelace when alarm changes""" async_register_command( hass, handle_subscribe_updates )
publish event to lovelace when alarm changes
async_register_card
python
nielsfaber/alarmo
custom_components/alarmo/card.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/card.py
Apache-2.0
def friendly_name_for_entity_id(entity_id: str, hass: HomeAssistant): """helper to get friendly name for entity""" state = hass.states.get(entity_id) if state and state.attributes.get("friendly_name"): return state.attributes["friendly_name"] return entity_id
helper to get friendly name for entity
friendly_name_for_entity_id
python
nielsfaber/alarmo
custom_components/alarmo/helpers.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/helpers.py
Apache-2.0
def async_update_config(_args=None): """mqtt config updated, reload the configuration.""" old_config = self._config new_config = self.hass.data[const.DOMAIN]["coordinator"].store.async_get_config() if old_config and old_config[ATTR_MQTT] == new_config[ATTR_MQTT]: ...
mqtt config updated, reload the configuration.
async_update_config
python
nielsfaber/alarmo
custom_components/alarmo/mqtt.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/mqtt.py
Apache-2.0
async def _async_subscribe_topics(self): """install a listener for the command topic.""" if len(self._subscribed_topics): while len(self._subscribed_topics): self._subscribed_topics.pop()() _LOGGER.debug("Removed subscribed topics") if not self._config[A...
install a listener for the command topic.
_async_subscribe_topics
python
nielsfaber/alarmo
custom_components/alarmo/mqtt.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/mqtt.py
Apache-2.0
def async_update_sensor_config(): """sensor config updated, reload the configuration.""" self._config = self.hass.data[const.DOMAIN]["coordinator"].store.async_get_sensors() self._groups = self.hass.data[const.DOMAIN]["coordinator"].store.async_get_sensor_groups() self._g...
sensor config updated, reload the configuration.
async_update_sensor_config
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def async_watch_sensor_states(self, area_id: str = None, old_state: str = None, state: str = None): """watch sensors based on the state of the alarm entities.""" sensors_list = [] for area in self.hass.data[const.DOMAIN]["areas"].keys(): sensors_list.extend(self.active_sensors_for_a...
watch sensors based on the state of the alarm entities.
async_watch_sensor_states
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def active_sensors_for_alarm_state(self, area_id: str, to_state: str = None): """Compose a list of sensors that are active for the state""" alarm_entity = self.hass.data[const.DOMAIN]["areas"][area_id] if to_state: state = to_state else: state = alarm_entity.arm_...
Compose a list of sensors that are active for the state
active_sensors_for_alarm_state
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def validate_arming_event(self, area_id: str, target_state: str = None, **kwargs): """check whether all sensors have the correct state prior to arming.""" use_delay = kwargs.get("use_delay", False) bypass_open_sensors = kwargs.get("bypass_open_sensors", False) sensors_list = self.activ...
check whether all sensors have the correct state prior to arming.
validate_arming_event
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def async_sensor_state_changed(self, event): """Callback fired when a sensor state has changed.""" entity = event.data["entity_id"] old_state = parse_sensor_state(event.data["old_state"]) new_state = parse_sensor_state(event.data["new_state"]) sensor_config = self._config[entity...
Callback fired when a sensor state has changed.
async_sensor_state_changed
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def process_group_event(self, entity: str, state: str) -> dict: """check if sensor entity is member of a group and compare with previous events to evaluate trigger""" group_id = None for group in self._groups.values(): if entity in group[ATTR_ENTITIES]: group_id = gro...
check if sensor entity is member of a group and compare with previous events to evaluate trigger
process_group_event
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
def update_ready_to_arm_status(self, area_id): """calculate whether the system is ready for arming (based on the sensor states).""" alarm_entity = self.hass.data[const.DOMAIN]["areas"][area_id] arm_modes = [ mode for (mode, config) in alarm_entity._config[const.ATTR_MODE...
calculate whether the system is ready for arming (based on the sensor states).
update_ready_to_arm_status
python
nielsfaber/alarmo
custom_components/alarmo/sensors.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/sensors.py
Apache-2.0
async def async_load(self) -> None: """Load the registry of schedule entries.""" data = await self._store.async_load() config: Config = Config() areas: "OrderedDict[str, AreaEntry]" = OrderedDict() sensors: "OrderedDict[str, SensorEntry]" = OrderedDict() users: "OrderedDi...
Load the registry of schedule entries.
async_load
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def _data_to_save(self) -> dict: """Return data for the registry for alarmo to store in a file.""" store_data = { "config": attr.asdict(self.config), } store_data["areas"] = [ attr.asdict(entry) for entry in self.areas.values() ] store_data["senso...
Return data for the registry for alarmo to store in a file.
_data_to_save
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def async_get_area(self, area_id) -> AreaEntry: """Get an existing AreaEntry by id.""" res = self.areas.get(area_id) return attr.asdict(res) if res else None
Get an existing AreaEntry by id.
async_get_area
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def async_get_sensor(self, entity_id) -> SensorEntry: """Get an existing SensorEntry by id.""" res = self.sensors.get(entity_id) return attr.asdict(res) if res else None
Get an existing SensorEntry by id.
async_get_sensor
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def async_get_user(self, user_id) -> UserEntry: """Get an existing UserEntry by id.""" res = self.users.get(user_id) return attr.asdict(res) if res else None
Get an existing UserEntry by id.
async_get_user
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def async_get_automations(self): """Get an existing AutomationEntry by id.""" res = {} for (key, val) in self.automations.items(): res[key] = attr.asdict(val) return res
Get an existing AutomationEntry by id.
async_get_automations
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def async_get_sensor_group(self, group_id) -> SensorGroupEntry: """Get an existing SensorGroupEntry by id.""" res = self.sensor_groups.get(group_id) return attr.asdict(res) if res else None
Get an existing SensorGroupEntry by id.
async_get_sensor_group
python
nielsfaber/alarmo
custom_components/alarmo/store.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/store.py
Apache-2.0
def websocket_get_countdown(hass, connection, msg): """Publish countdown time for alarm entity.""" entity_id = msg["entity_id"] item = next((entity for entity in hass.data[const.DOMAIN]["areas"].values() if entity.entity_id == entity_id), None) if hass.data[const.DOMAIN]["master"] and not item and hass....
Publish countdown time for alarm entity.
websocket_get_countdown
python
nielsfaber/alarmo
custom_components/alarmo/websockets.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/websockets.py
Apache-2.0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Alarmo integration from a config entry.""" session = async_get_clientsession(hass) store = await async_get_registry(hass) coordinator = AlarmoCoordinator(hass, session, entry, store) device_registry = dr.async_get(hass...
Set up Alarmo integration from a config entry.
async_setup_entry
python
nielsfaber/alarmo
custom_components/alarmo/__init__.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/__init__.py
Apache-2.0
def register_services(hass): """Register services used by alarmo component.""" coordinator = hass.data[const.DOMAIN]["coordinator"] async def async_srv_toggle_user(call): """Enable a user by service call""" name = call.data.get(ATTR_NAME) enable = True if call.service == const.SERV...
Register services used by alarmo component.
register_services
python
nielsfaber/alarmo
custom_components/alarmo/__init__.py
https://github.com/nielsfaber/alarmo/blob/master/custom_components/alarmo/__init__.py
Apache-2.0
def load_json_object_fixture(filename: str) -> dict[str, object]: """Load a JSON object from a fixture in the local test/fixtures directory.""" fixture_path = Path(__file__).parent / "fixtures" / filename with open(fixture_path, encoding="utf-8") as f: return json.load(f)
Load a JSON object from a fixture in the local test/fixtures directory.
load_json_object_fixture
python
nielsfaber/alarmo
tests/common.py
https://github.com/nielsfaber/alarmo/blob/master/tests/common.py
Apache-2.0
def create_area( area_id: str = "area_1", name: str = "Test Area 1", modes: Optional[list[str]] = None, **kwargs: Any, ) -> dict[str, Any]: """Create an area with optional defaults. Args: area_id: The ID of the area. name: The name of the area...
Create an area with optional defaults. Args: area_id: The ID of the area. name: The name of the area. modes: The alarm modes of the area.
create_area
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_master_config( enabled: bool = True, name: str = "Master", code_format: str = "number", code_arm_required: bool = True, code_disarm_required: bool = True, code_mode_change_required: bool = True, ) -> Dict[str, Any]: """Create a master config with op...
Create a master config with optional defaults.
create_master_config
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_arm_only_user(user_id: str = "arm_only_user") -> Dict[str, Any]: """Create a user that can arm but not disarm.""" return UserFactory.create_user( user_id=user_id, name="Arm Only User", can_arm=True, can_disarm=False )
Create a user that can arm but not disarm.
create_arm_only_user
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_disarm_only_user(user_id: str = "disarm_only_user") -> Dict[str, Any]: """Create a user that can disarm only""" return UserFactory.create_user( user_id=user_id, name="Disarm Only User", can_arm=False, can_disarm=True )
Create a user that can disarm only
create_disarm_only_user
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_door_sensor( entity_id: str = "binary_sensor.generic_area_1_door_sensor", name: str = "Generic Area 1 Door", enabled: bool = True, area: str = "area_1", modes: Optional[List[str]] = None, use_exit_delay: bool = True, use_entry_delay: bool = True, ...
Create a door sensor with optional defaults.
create_door_sensor
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_window_sensor( entity_id: str = "binary_sensor.generic_area_1_window_sensor", name: str = "Generic Area 1 Window", area: str = "area_1", modes: Optional[List[str]] = None, use_exit_delay: bool = True, use_entry_delay: bool = True, arm_on_close: bool = F...
Create a window sensor with optional defaults.
create_window_sensor
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_motion_sensor( entity_id: str = "binary_sensor.generic_area_1_motion_sensor", name: str = "Generic Area 1 Motion", area: str = "area_1", modes: Optional[List[str]] = None, use_exit_delay: bool = True, use_entry_delay: bool = True, arm_on_close: bool = F...
Create a motion sensor with optional defaults.
create_motion_sensor
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_bypass_sensor( entity_id: str = "binary_sensor.generic_area_1_door_sensor", name: str = "Door with Auto-Bypass", area: str = "area_1", auto_bypass_modes: Optional[List[str]] = None, ) -> Dict[str, Any]: """Create a bypass sensor with optional defaults.""" i...
Create a bypass sensor with optional defaults.
create_bypass_sensor
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_all_sensors() -> Dict[str, Dict[str, Any]]: """Create all sensors with optional defaults.""" return { "binary_sensor.generic_area_1_door_sensor": SensorFactory.create_door_sensor(), "binary_sensor.generic_area_1_window_sensor": SensorFactory.create_window_sensor(), ...
Create all sensors with optional defaults.
create_all_sensors
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def _ensure_area_defaults(self): """Ensure all areas have the required keys.""" required_keys = { "code_format": "number", "code_arm_required": True, "code_disarm_required": True, "code_mode_change_required": True, } for area in self.areas:...
Ensure all areas have the required keys.
_ensure_area_defaults
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def async_update_area( self, area_id: str, changes: dict[str, Any] ) -> dict[str, Any]: """Update an area with optional changes.""" for area in self.areas: if area["area_id"] == area_id: if "modes" in changes: for mode, mode_changes in changes[...
Update an area with optional changes.
async_update_area
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def create_storage( areas: Optional[list[dict[str, Any]]] = None, sensors: Optional[list[dict[str, Any]]] = None, sensor_groups: Optional[list[dict[str, Any]]] = None, master_enabled: bool = False, ) -> MockStorage: """Create a mock storage with optional defaults.""" ...
Create a mock storage with optional defaults.
create_storage
python
nielsfaber/alarmo
tests/factories.py
https://github.com/nielsfaber/alarmo/blob/master/tests/factories.py
Apache-2.0
def update_sensor_config_in_entry( config_entry: ConfigEntry, sensor_entity_id: str, updates: Dict[str, Any] ): """Update a sensor's configuration in config_entry.data. Assumes config_entry.data is a mutable dictionary. """ if not isinstance(config_entry.data, dict): # This check is more for...
Update a sensor's configuration in config_entry.data. Assumes config_entry.data is a mutable dictionary.
update_sensor_config_in_entry
python
nielsfaber/alarmo
tests/helpers.py
https://github.com/nielsfaber/alarmo/blob/master/tests/helpers.py
Apache-2.0