├── docs ├── _static │ ├── favicon.ico │ ├── favicon.ico.license │ └── custom.css ├── api.rst.license ├── index.rst.license ├── examples.rst.license ├── requirements.txt ├── api.rst ├── examples.rst ├── index.rst └── conf.py ├── optional_requirements.txt ├── README.rst.license ├── .gitattributes ├── .github ├── workflows │ ├── build.yml │ ├── release_pypi.yml │ ├── release_gh.yml │ └── failure-help-text.yml └── PULL_REQUEST_TEMPLATE │ └── adafruit_circuitpython_pr.md ├── requirements.txt ├── .readthedocs.yaml ├── .pre-commit-config.yaml ├── LICENSES ├── MIT.txt ├── Unlicense.txt └── CC-BY-4.0.txt ├── LICENSE ├── pyproject.toml ├── examples ├── funhouse_temperature_logger.py ├── funhouse_adafruit_io_mqtt.py └── funhouse_simpletest.py ├── .gitignore ├── adafruit_funhouse ├── graphics.py ├── __init__.py ├── peripherals.py └── network.py ├── ruff.toml ├── CODE_OF_CONDUCT.md └── README.rst /docs/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_FunHouse/HEAD/docs/_static/favicon.ico -------------------------------------------------------------------------------- /optional_requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | -------------------------------------------------------------------------------- /docs/_static/favicon.ico.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries 2 | 3 | SPDX-License-Identifier: CC-BY-4.0 4 | -------------------------------------------------------------------------------- /README.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | SPDX-License-Identifier: MIT 4 | -------------------------------------------------------------------------------- /docs/api.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /docs/index.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /docs/examples.rst.license: -------------------------------------------------------------------------------- 1 | SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | 4 | SPDX-License-Identifier: MIT 5 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | .py text eol=lf 6 | .rst text eol=lf 7 | .txt text eol=lf 8 | .yaml text eol=lf 9 | .toml text eol=lf 10 | .license text eol=lf 11 | .md text eol=lf 12 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | 6 | sphinx 7 | sphinxcontrib-jquery 8 | sphinx-rtd-theme 9 | -------------------------------------------------------------------------------- /docs/_static/custom.css: -------------------------------------------------------------------------------- 1 | /* SPDX-FileCopyrightText: 2025 Sam Blenny 2 | * SPDX-License-Identifier: MIT 3 | */ 4 | 5 | /* Monkey patch the rtd theme to prevent horizontal stacking of short items 6 | * see https://github.com/readthedocs/sphinx_rtd_theme/issues/1301 7 | */ 8 | .py.property{display: block !important;} 9 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Build CI 6 | 7 | on: [pull_request, push] 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Run Build CI workflow 14 | uses: adafruit/workflows-circuitpython-libs/build@main 15 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | Adafruit-Blinka-displayio 6 | Adafruit-Blinka 7 | adafruit-circuitpython-ahtx0 8 | adafruit-circuitpython-minimqtt 9 | adafruit-circuitpython-dotstar 10 | adafruit-circuitpython-requests 11 | adafruit-circuitpython-simpleio 12 | adafruit-circuitpython-portalbase 13 | adafruit-circuitpython-dps310 14 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | # Read the Docs configuration file 6 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 7 | 8 | # Required 9 | version: 2 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | build: 15 | os: ubuntu-lts-latest 16 | tools: 17 | python: "3" 18 | 19 | python: 20 | install: 21 | - requirements: docs/requirements.txt 22 | - requirements: requirements.txt 23 | -------------------------------------------------------------------------------- /docs/api.rst: -------------------------------------------------------------------------------- 1 | 2 | .. If you created a package, create one automodule per module in the package. 3 | 4 | .. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) 5 | .. use this format as the module name: "adafruit_foo.foo" 6 | 7 | API Reference 8 | ############# 9 | 10 | .. automodule:: adafruit_funhouse 11 | :members: 12 | 13 | .. automodule:: adafruit_funhouse.graphics 14 | :members: 15 | 16 | .. automodule:: adafruit_funhouse.network 17 | :members: 18 | 19 | .. automodule:: adafruit_funhouse.peripherals 20 | :members: 21 | -------------------------------------------------------------------------------- /.github/workflows/release_pypi.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: PyPI Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run PyPI Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-pypi@main 17 | with: 18 | pypi-username: ${{ secrets.pypi_username }} 19 | pypi-password: ${{ secrets.pypi_password }} 20 | -------------------------------------------------------------------------------- /.github/workflows/release_gh.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: GitHub Release Actions 6 | 7 | on: 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | upload-release-assets: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Run GitHub Release CI workflow 16 | uses: adafruit/workflows-circuitpython-libs/release-gh@main 17 | with: 18 | github-token: ${{ secrets.GITHUB_TOKEN }} 19 | upload-url: ${{ github.event.release.upload_url }} 20 | -------------------------------------------------------------------------------- /.github/workflows/failure-help-text.yml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | name: Failure help text 6 | 7 | on: 8 | workflow_run: 9 | workflows: ["Build CI"] 10 | types: 11 | - completed 12 | 13 | jobs: 14 | post-help: 15 | runs-on: ubuntu-latest 16 | if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} 17 | steps: 18 | - name: Post comment to help 19 | uses: adafruit/circuitpython-action-library-ci-failed@v1 20 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: Unlicense 4 | 5 | repos: 6 | - repo: https://github.com/pre-commit/pre-commit-hooks 7 | rev: v4.5.0 8 | hooks: 9 | - id: check-yaml 10 | - id: end-of-file-fixer 11 | - id: trailing-whitespace 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.3.4 14 | hooks: 15 | - id: ruff-format 16 | - id: ruff 17 | args: ["--fix"] 18 | - repo: https://github.com/fsfe/reuse-tool 19 | rev: v3.0.1 20 | hooks: 21 | - id: reuse 22 | -------------------------------------------------------------------------------- /docs/examples.rst: -------------------------------------------------------------------------------- 1 | Simple test 2 | ------------ 3 | 4 | Ensure your device works with this simple test. 5 | 6 | .. literalinclude:: ../examples/funhouse_simpletest.py 7 | :caption: examples/funhouse_simpletest.py 8 | :linenos: 9 | 10 | MQTT Example 11 | ------------ 12 | 13 | .. literalinclude:: ../examples/funhouse_adafruit_io_mqtt.py 14 | :caption: examples/funhouse_adafruit_io_mqtt.py 15 | :linenos: 16 | 17 | Temperature Logger Example 18 | --------------------------- 19 | 20 | .. literalinclude:: ../examples/funhouse_temperature_logger.py 21 | :caption: examples/funhouse_temperature_logger.py 22 | :linenos: 23 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2021 Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | Thank you for contributing! Before you submit a pull request, please read the following. 6 | 7 | Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html 8 | 9 | If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs 10 | 11 | Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code 12 | 13 | Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. 14 | -------------------------------------------------------------------------------- /LICENSES/MIT.txt: -------------------------------------------------------------------------------- 1 | MIT License Copyright (c) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice (including the next 11 | paragraph) shall be included in all copies or substantial portions of the 12 | Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 18 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 19 | OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /LICENSES/Unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute 4 | this software, either in source code form or as a compiled binary, for any 5 | purpose, commercial or non-commercial, and by any means. 6 | 7 | In jurisdictions that recognize copyright laws, the author or authors of this 8 | software dedicate any and all copyright interest in the software to the public 9 | domain. We make this dedication for the benefit of the public at large and 10 | to the detriment of our heirs and successors. We intend this dedication to 11 | be an overt act of relinquishment in perpetuity of all present and future 12 | rights to this software under copyright law. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 17 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 18 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH 19 | THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, 20 | please refer to 21 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | [build-system] 6 | requires = [ 7 | "setuptools", 8 | "wheel", 9 | "setuptools-scm", 10 | ] 11 | 12 | [project] 13 | name = "adafruit-circuitpython-funhouse" 14 | description = "Helper library for the FunHouse board" 15 | version = "0.0.0+auto.0" 16 | readme = "README.rst" 17 | authors = [ 18 | {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} 19 | ] 20 | urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse"} 21 | keywords = [ 22 | "adafruit", 23 | "funhouse", 24 | "microcontroller", 25 | "sensors", 26 | "hardware", 27 | "micropythoncircuitpython", 28 | ] 29 | license = {text = "MIT"} 30 | classifiers = [ 31 | "Intended Audience :: Developers", 32 | "Topic :: Software Development :: Libraries", 33 | "Topic :: Software Development :: Embedded Systems", 34 | "Topic :: System :: Hardware", 35 | "License :: OSI Approved :: MIT License", 36 | "Programming Language :: Python :: 3", 37 | ] 38 | dynamic = ["dependencies", "optional-dependencies"] 39 | 40 | [tool.setuptools] 41 | packages = ["adafruit_funhouse"] 42 | 43 | [tool.setuptools.dynamic] 44 | dependencies = {file = ["requirements.txt"]} 45 | optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} 46 | -------------------------------------------------------------------------------- /examples/funhouse_temperature_logger.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | This example demonstrates how to log temperature on the FunHouse. Due to the sensors being near the 7 | power supply, usage of peripherals generates extra heat. By turning off unused peripherals and back 8 | on only during usage, it can lower the heat. Using light sleep in between readings will also help. 9 | By using an offset, we can improve the accuracy even more. Improving airflow near the FunHouse will 10 | also help. 11 | """ 12 | 13 | from adafruit_funhouse import FunHouse 14 | 15 | funhouse = FunHouse(default_bg=None) 16 | 17 | DELAY = 180 18 | FEED = "temperature" 19 | TEMPERATURE_OFFSET = 3 # Degrees C to adjust the temperature to compensate for board produced heat 20 | 21 | # Turn things off 22 | funhouse.peripherals.dotstars.fill(0) 23 | funhouse.display.brightness = 0 24 | funhouse.network.enabled = False 25 | 26 | 27 | def log_data(): 28 | print("Logging Temperature") 29 | print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET)) 30 | # Turn on WiFi 31 | funhouse.network.enabled = True 32 | # Connect to WiFi 33 | funhouse.network.connect() 34 | # Push to IO using REST 35 | funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET) 36 | # Turn off WiFi 37 | funhouse.network.enabled = False 38 | 39 | 40 | while True: 41 | log_data() 42 | print(f"Sleeping for {DELAY} seconds...") 43 | funhouse.enter_light_sleep(DELAY) 44 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | # Do not include files and directories created by your personal work environment, such as the IDE 6 | # you use, except for those already listed here. Pull requests including changes to this file will 7 | # not be accepted. 8 | 9 | # This .gitignore file contains rules for files generated by working with CircuitPython libraries, 10 | # including building Sphinx, testing with pip, and creating a virual environment, as well as the 11 | # MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. 12 | 13 | # If you find that there are files being generated on your machine that should not be included in 14 | # your git commit, you should create a .gitignore_global file on your computer to include the 15 | # files created by your personal setup. To do so, follow the two steps below. 16 | 17 | # First, create a file called .gitignore_global somewhere convenient for you, and add rules for 18 | # the files you want to exclude from git commits. 19 | 20 | # Second, configure Git to use the exclude file for all Git repositories by running the 21 | # following via commandline, replacing "path/to/your/" with the actual path to your newly created 22 | # .gitignore_global file: 23 | # git config --global core.excludesfile path/to/your/.gitignore_global 24 | 25 | # CircuitPython-specific files 26 | *.mpy 27 | 28 | # Python-specific files 29 | __pycache__ 30 | *.pyc 31 | 32 | # Sphinx build-specific files 33 | _build 34 | 35 | # This file results from running `pip -e install .` in a local repository 36 | *.egg-info 37 | 38 | # Virtual environment-specific files 39 | .env 40 | .venv 41 | 42 | # MacOS-specific files 43 | *.DS_Store 44 | 45 | # IDE-specific files 46 | .idea 47 | .vscode 48 | *~ 49 | -------------------------------------------------------------------------------- /adafruit_funhouse/graphics.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | `adafruit_funhouse.graphics` 7 | ================================================================================ 8 | 9 | Helper library for the Adafruit FunHouse board. 10 | 11 | 12 | * Author(s): Melissa LeBlanc-Williams 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Hardware:** 18 | 19 | * `Adafruit FunHouse `_ 20 | 21 | **Software and Dependencies:** 22 | 23 | * Adafruit CircuitPython firmware for the supported boards: 24 | https://github.com/adafruit/circuitpython/releases 25 | 26 | * Adafruit's PortalBase library: https://github.com/adafruit/Adafruit_CircuitPython_PortalBase 27 | 28 | """ 29 | 30 | import board 31 | from adafruit_portalbase.graphics import GraphicsBase 32 | 33 | __version__ = "0.0.0+auto.0" 34 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" 35 | 36 | 37 | class Graphics(GraphicsBase): 38 | """Graphics Helper Class for the FunHouse Library 39 | 40 | :param default_bg: The path to your default background image file or a hex color. 41 | Defaults to 0x000000. 42 | :param rotation: Default rotation is landscape (270) but can be 0, 90, 180 for portrait/rotated 43 | :param debug: Turn on debug print outs. Defaults to False. 44 | 45 | """ 46 | 47 | def __init__( 48 | self, *, default_bg: int = 0, rotation: int = 270, scale: int = 1, debug: bool = False 49 | ) -> None: 50 | self._debug = debug 51 | self.display = board.DISPLAY 52 | self.display.rotation = rotation 53 | 54 | super().__init__(board.DISPLAY, default_bg=default_bg, scale=scale, debug=debug) 55 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | 2 | .. include:: ../README.rst 3 | 4 | Table of Contents 5 | ================= 6 | 7 | .. toctree:: 8 | :maxdepth: 4 9 | :hidden: 10 | 11 | self 12 | 13 | .. toctree:: 14 | :caption: Examples 15 | 16 | examples 17 | 18 | .. toctree:: 19 | :caption: API Reference 20 | :maxdepth: 3 21 | 22 | api 23 | 24 | .. toctree:: 25 | :caption: Tutorials 26 | 27 | Adafruit FunHouse 28 | 29 | Pet Bowl Water Level Sensing 30 | 31 | FunHouse Parking Assistant 32 | 33 | FunHouse Mail Slot Detector 34 | 35 | Adafruit IO IOT Hub with the Adafruit FunHouse 36 | 37 | FunHouse Motion Detecting Lights with LIFX Bulbs 38 | 39 | Motion Activated Outlet with the Adafruit FunHouse 40 | 41 | Funhouse Door Alert with Email Notification 42 | 43 | Creating FunHouse Projects with CircuitPython 44 | 45 | Using the Adafruit FunHouse with Home Assistant 46 | 47 | .. toctree:: 48 | :caption: Related Products 49 | 50 | Adafruit FunHouse - WiFi Home Automation Development Board 51 | 52 | .. toctree:: 53 | :caption: Other Links 54 | 55 | Download from GitHub 56 | Download Library Bundle 57 | CircuitPython Reference Documentation 58 | CircuitPython Support Forum 59 | Discord Chat 60 | Adafruit Learning System 61 | Adafruit Blog 62 | Adafruit Store 63 | 64 | Indices and tables 65 | ================== 66 | 67 | * :ref:`genindex` 68 | * :ref:`modindex` 69 | * :ref:`search` 70 | -------------------------------------------------------------------------------- /examples/funhouse_adafruit_io_mqtt.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | import time 6 | 7 | from adafruit_funhouse import FunHouse 8 | 9 | funhouse = FunHouse(default_bg=None) 10 | funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080) 11 | 12 | 13 | def connected(client): 14 | print("Connected to Adafruit IO! Subscribing...") 15 | client.subscribe("buzzer") 16 | client.subscribe("neopixels") 17 | 18 | 19 | def subscribe(client, userdata, topic, granted_qos): 20 | print(f"Subscribed to {topic} with QOS level {granted_qos}") 21 | 22 | 23 | def disconnected(client): 24 | print("Disconnected from Adafruit IO!") 25 | 26 | 27 | def message(client, feed_id, payload): 28 | print(f"Feed {feed_id} received new value: {payload}") 29 | if feed_id == "buzzer": 30 | if int(payload) == 1: 31 | funhouse.peripherals.play_tone(2000, 0.25) 32 | if feed_id == "neopixels": 33 | print(payload) 34 | color = int(payload[1:], 16) 35 | funhouse.peripherals.dotstars.fill(color) 36 | 37 | 38 | # Initialize a new MQTT Client object 39 | funhouse.network.init_io_mqtt() 40 | funhouse.network.on_mqtt_connect = connected 41 | funhouse.network.on_mqtt_disconnect = disconnected 42 | funhouse.network.on_mqtt_subscribe = subscribe 43 | funhouse.network.on_mqtt_message = message 44 | 45 | print("Connecting to Adafruit IO...") 46 | funhouse.network.mqtt_connect() 47 | sensorwrite_timestamp = time.monotonic() 48 | last_pir = None 49 | 50 | while True: 51 | funhouse.network.mqtt_loop() 52 | 53 | print("Temp %0.1F" % funhouse.peripherals.temperature) 54 | print("Pres %d" % funhouse.peripherals.pressure) 55 | 56 | # every 10 seconds, write temp/hum/press 57 | if (time.monotonic() - sensorwrite_timestamp) > 10: 58 | funhouse.peripherals.led = True 59 | print("Sending data to adafruit IO!") 60 | funhouse.network.mqtt_publish("temperature", funhouse.peripherals.temperature) 61 | funhouse.network.mqtt_publish("humidity", int(funhouse.peripherals.relative_humidity)) 62 | funhouse.network.mqtt_publish("pressure", int(funhouse.peripherals.pressure)) 63 | sensorwrite_timestamp = time.monotonic() 64 | # Send PIR only if changed! 65 | if last_pir is None or last_pir != funhouse.peripherals.pir_sensor: 66 | last_pir = funhouse.peripherals.pir_sensor 67 | funhouse.network.mqtt_publish("pir", "%d" % last_pir) 68 | funhouse.peripherals.led = False 69 | -------------------------------------------------------------------------------- /examples/funhouse_simpletest.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: Unlicense 5 | import board 6 | from digitalio import DigitalInOut, Direction, Pull 7 | 8 | from adafruit_funhouse import FunHouse 9 | 10 | funhouse = FunHouse( 11 | default_bg=0x0F0F00, 12 | scale=2, 13 | ) 14 | 15 | funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080) 16 | 17 | # sensor setup 18 | sensors = [] 19 | for p in (board.A0, board.A1, board.A2): 20 | sensor = DigitalInOut(p) 21 | sensor.direction = Direction.INPUT 22 | sensor.pull = Pull.DOWN 23 | sensors.append(sensor) 24 | 25 | 26 | def set_label_color(conditional, index, on_color): 27 | if conditional: 28 | funhouse.set_text_color(on_color, index) 29 | else: 30 | funhouse.set_text_color(0x606060, index) 31 | 32 | 33 | # Create the labels 34 | funhouse.display.root_group = None 35 | slider_label = funhouse.add_text(text="Slider:", text_position=(50, 30), text_color=0x606060) 36 | capright_label = funhouse.add_text(text="Touch", text_position=(85, 10), text_color=0x606060) 37 | pir_label = funhouse.add_text(text="PIR", text_position=(60, 10), text_color=0x606060) 38 | capleft_label = funhouse.add_text(text="Touch", text_position=(25, 10), text_color=0x606060) 39 | onoff_label = funhouse.add_text(text="OFF", text_position=(10, 25), text_color=0x606060) 40 | up_label = funhouse.add_text(text="UP", text_position=(10, 10), text_color=0x606060) 41 | sel_label = funhouse.add_text(text="SEL", text_position=(10, 60), text_color=0x606060) 42 | down_label = funhouse.add_text(text="DOWN", text_position=(10, 100), text_color=0x606060) 43 | jst1_label = funhouse.add_text(text="SENSOR 1", text_position=(40, 80), text_color=0x606060) 44 | jst2_label = funhouse.add_text(text="SENSOR 2", text_position=(40, 95), text_color=0x606060) 45 | jst3_label = funhouse.add_text(text="SENSOR 3", text_position=(40, 110), text_color=0x606060) 46 | temp_label = funhouse.add_text(text="Temp:", text_position=(50, 45), text_color=0xFF00FF) 47 | pres_label = funhouse.add_text(text="Pres:", text_position=(50, 60), text_color=0xFF00FF) 48 | funhouse.display.root_group = funhouse.root_group 49 | 50 | while True: 51 | funhouse.set_text("Temp %0.1F" % funhouse.peripherals.temperature, temp_label) 52 | funhouse.set_text("Pres %d" % funhouse.peripherals.pressure, pres_label) 53 | 54 | print(funhouse.peripherals.temperature, funhouse.peripherals.relative_humidity) 55 | set_label_color(funhouse.peripherals.captouch6, onoff_label, 0x00FF00) 56 | set_label_color(funhouse.peripherals.captouch7, capleft_label, 0x00FF00) 57 | set_label_color(funhouse.peripherals.captouch8, capright_label, 0x00FF00) 58 | 59 | slider = funhouse.peripherals.slider 60 | if slider is not None: 61 | funhouse.peripherals.dotstars.brightness = slider 62 | funhouse.set_text("Slider: %1.1f" % slider, slider_label) 63 | set_label_color(slider is not None, slider_label, 0xFFFF00) 64 | 65 | set_label_color(funhouse.peripherals.button_up, up_label, 0xFF0000) 66 | set_label_color(funhouse.peripherals.button_sel, sel_label, 0xFFFF00) 67 | set_label_color(funhouse.peripherals.button_down, down_label, 0x00FF00) 68 | 69 | set_label_color(funhouse.peripherals.pir_sensor, pir_label, 0xFF0000) 70 | set_label_color(sensors[0].value, jst1_label, 0xFFFFFF) 71 | set_label_color(sensors[1].value, jst2_label, 0xFFFFFF) 72 | set_label_color(sensors[2].value, jst3_label, 0xFFFFFF) 73 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | target-version = "py38" 6 | line-length = 100 7 | 8 | [lint] 9 | preview = true 10 | select = ["I", "PL", "UP"] 11 | 12 | extend-select = [ 13 | "D419", # empty-docstring 14 | "E501", # line-too-long 15 | "W291", # trailing-whitespace 16 | "PLC0414", # useless-import-alias 17 | "PLC2401", # non-ascii-name 18 | "PLC2801", # unnecessary-dunder-call 19 | "PLC3002", # unnecessary-direct-lambda-call 20 | "PLE0101", # return-in-init 21 | "F706", # return-outside-function 22 | "F704", # yield-outside-function 23 | "PLE0116", # continue-in-finally 24 | "PLE0117", # nonlocal-without-binding 25 | "PLE0241", # duplicate-bases 26 | "PLE0302", # unexpected-special-method-signature 27 | "PLE0604", # invalid-all-object 28 | "PLE0605", # invalid-all-format 29 | "PLE0643", # potential-index-error 30 | "PLE0704", # misplaced-bare-raise 31 | "PLE1141", # dict-iter-missing-items 32 | "PLE1142", # await-outside-async 33 | "PLE1205", # logging-too-many-args 34 | "PLE1206", # logging-too-few-args 35 | "PLE1307", # bad-string-format-type 36 | "PLE1310", # bad-str-strip-call 37 | "PLE1507", # invalid-envvar-value 38 | "PLE2502", # bidirectional-unicode 39 | "PLE2510", # invalid-character-backspace 40 | "PLE2512", # invalid-character-sub 41 | "PLE2513", # invalid-character-esc 42 | "PLE2514", # invalid-character-nul 43 | "PLE2515", # invalid-character-zero-width-space 44 | "PLR0124", # comparison-with-itself 45 | "PLR0202", # no-classmethod-decorator 46 | "PLR0203", # no-staticmethod-decorator 47 | "UP004", # useless-object-inheritance 48 | "PLR0206", # property-with-parameters 49 | "PLR0904", # too-many-public-methods 50 | "PLR0911", # too-many-return-statements 51 | "PLR0912", # too-many-branches 52 | "PLR0913", # too-many-arguments 53 | "PLR0914", # too-many-locals 54 | "PLR0915", # too-many-statements 55 | "PLR0916", # too-many-boolean-expressions 56 | "PLR1702", # too-many-nested-blocks 57 | "PLR1704", # redefined-argument-from-local 58 | "PLR1711", # useless-return 59 | "C416", # unnecessary-comprehension 60 | "PLR1733", # unnecessary-dict-index-lookup 61 | "PLR1736", # unnecessary-list-index-lookup 62 | 63 | # ruff reports this rule is unstable 64 | #"PLR6301", # no-self-use 65 | 66 | "PLW0108", # unnecessary-lambda 67 | "PLW0120", # useless-else-on-loop 68 | "PLW0127", # self-assigning-variable 69 | "PLW0129", # assert-on-string-literal 70 | "B033", # duplicate-value 71 | "PLW0131", # named-expr-without-context 72 | "PLW0245", # super-without-brackets 73 | "PLW0406", # import-self 74 | "PLW0602", # global-variable-not-assigned 75 | "PLW0603", # global-statement 76 | "PLW0604", # global-at-module-level 77 | 78 | # fails on the try: import typing used by libraries 79 | #"F401", # unused-import 80 | 81 | "F841", # unused-variable 82 | "E722", # bare-except 83 | "PLW0711", # binary-op-exception 84 | "PLW1501", # bad-open-mode 85 | "PLW1508", # invalid-envvar-default 86 | "PLW1509", # subprocess-popen-preexec-fn 87 | "PLW2101", # useless-with-lock 88 | "PLW3301", # nested-min-max 89 | ] 90 | 91 | ignore = [ 92 | "PLR2004", # magic-value-comparison 93 | "UP030", # format literals 94 | "PLW1514", # unspecified-encoding 95 | "PLR0913", # too-many-arguments 96 | "PLR0915", # too-many-statements 97 | "PLR0917", # too-many-positional-arguments 98 | "PLR0904", # too-many-public-methods 99 | "PLR0912", # too-many-branches 100 | "PLR0916", # too-many-boolean-expressions 101 | "PLR6301", # could-be-static no-self-use 102 | "PLC0415", # import outside toplevel 103 | "PLC2701", # private import 104 | ] 105 | 106 | [format] 107 | line-ending = "lf" 108 | -------------------------------------------------------------------------------- /adafruit_funhouse/__init__.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | `adafruit_funhouse` 7 | ================================================================================ 8 | 9 | Helper library for the Adafruit FunHouse board. 10 | 11 | 12 | * Author(s): Melissa LeBlanc-Williams 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Hardware:** 18 | 19 | * `Adafruit FunHouse `_ 20 | 21 | **Software and Dependencies:** 22 | 23 | * Adafruit CircuitPython firmware for the supported boards: 24 | https://github.com/adafruit/circuitpython/releases 25 | 26 | * Adafruit's PortalBase library: https://github.com/adafruit/Adafruit_CircuitPython_PortalBase 27 | 28 | """ 29 | 30 | import gc 31 | import time 32 | 33 | from adafruit_portalbase import PortalBase 34 | 35 | from adafruit_funhouse.graphics import Graphics 36 | from adafruit_funhouse.network import Network 37 | from adafruit_funhouse.peripherals import Peripherals 38 | 39 | try: 40 | from typing import Callable, Dict, List, Optional, Sequence, Union 41 | 42 | from adafruit_dotstar import DotStar 43 | except ImportError: 44 | pass 45 | 46 | __version__ = "0.0.0+auto.0" 47 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" 48 | 49 | 50 | class FunHouse(PortalBase): 51 | """Class representing the Adafruit FunHouse. 52 | 53 | :param url: The URL of your data source. Defaults to ``None``. 54 | :param headers: The headers for authentication, typically used by Azure API's. 55 | :param json_path: The list of json traversal to get data out of. Can be list of lists for 56 | multiple data points. Defaults to ``None`` to not use json. 57 | :param regexp_path: The list of regexp strings to get data out (use a single regexp group). Can 58 | be list of regexps for multiple data points. Defaults to ``None`` to not 59 | use regexp. 60 | :param default_bg: The path to your default background image file or a hex color. 61 | Defaults to 0x000000. 62 | :param status_dotstar: The initialized object for status DotStar. Defaults to ``None``, 63 | to not use the status LED 64 | :param json_transform: A function or a list of functions to call with the parsed JSON. 65 | Changes and additions are permitted for the ``dict`` object. 66 | :param rotation: Default rotation is landscape (270) but can be 0, 90, or 180 for 67 | portrait/rotated 68 | :param scale: Default scale is 1, but can be an integer of 1 or greater 69 | :param debug: Turn on debug print outs. Defaults to False. 70 | 71 | """ 72 | 73 | def __init__( 74 | self, 75 | *, 76 | url: Optional[str] = None, 77 | headers: Dict[str, str] = None, 78 | json_path: Optional[Union[List[str], List[List[str]]]] = None, 79 | regexp_path: Optional[Sequence[str]] = None, 80 | default_bg: int = 0, 81 | status_dotstar: Optional[DotStar] = None, 82 | json_transform: Optional[Union[Callable, List[Callable]]] = None, 83 | rotation: int = 270, 84 | scale: int = 1, 85 | debug: bool = False, 86 | ) -> None: 87 | network = Network( 88 | status_dotstar=status_dotstar, 89 | extract_values=False, 90 | debug=debug, 91 | ) 92 | 93 | graphics = Graphics( 94 | default_bg=default_bg, 95 | rotation=rotation, 96 | scale=scale, 97 | debug=debug, 98 | ) 99 | 100 | super().__init__( 101 | network, 102 | graphics, 103 | url=url, 104 | headers=headers, 105 | json_path=json_path, 106 | regexp_path=regexp_path, 107 | json_transform=json_transform, 108 | debug=debug, 109 | ) 110 | 111 | self.peripherals = Peripherals() 112 | 113 | gc.collect() 114 | 115 | def enter_light_sleep(self, sleep_time: float) -> None: 116 | """ 117 | Enter light sleep and resume the program after a certain period of time. 118 | 119 | See https://circuitpython.readthedocs.io/en/latest/shared-bindings/alarm/index.html for more 120 | details. 121 | 122 | :param float sleep_time: The amount of time to sleep in seconds 123 | 124 | """ 125 | if self._alarm: 126 | dotstar_values = self.peripherals.dotstars 127 | super().enter_light_sleep(sleep_time) 128 | for i, _ in enumerate(self.peripherals.dotstars): 129 | self.peripherals.dotstars[i] = dotstar_values[i] 130 | gc.collect() 131 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # 3 | # SPDX-License-Identifier: MIT 4 | 5 | import datetime 6 | import os 7 | import sys 8 | 9 | sys.path.insert(0, os.path.abspath("..")) 10 | 11 | # -- General configuration ------------------------------------------------ 12 | 13 | # Add any Sphinx extension module names here, as strings. They can be 14 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 15 | # ones. 16 | extensions = [ 17 | "sphinx.ext.autodoc", 18 | "sphinxcontrib.jquery", 19 | "sphinx.ext.intersphinx", 20 | "sphinx.ext.napoleon", 21 | "sphinx.ext.todo", 22 | ] 23 | 24 | # TODO: Please Read! 25 | # Uncomment the below if you use native CircuitPython modules such as 26 | # digitalio, micropython and busio. List the modules you use. Without it, the 27 | # autodoc module docs will fail to generate with a warning. 28 | autodoc_mock_imports = [ 29 | "supervisor", 30 | "rtc", 31 | "ssl", 32 | "wifi", 33 | "socketpool", 34 | "analogio", 35 | "touchio", 36 | "bitmaptools", 37 | ] 38 | 39 | intersphinx_mapping = { 40 | "python": ("https://docs.python.org/3.8", None), 41 | "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), 42 | } 43 | 44 | # Show the docstring from both the class and its __init__() method. 45 | autoclass_content = "both" 46 | 47 | # Add any paths that contain templates here, relative to this directory. 48 | templates_path = ["_templates"] 49 | 50 | source_suffix = ".rst" 51 | 52 | # The master toctree document. 53 | master_doc = "index" 54 | 55 | # General information about the project. 56 | project = "Adafruit CircuitPython FunHouse Library" 57 | creation_year = "2021" 58 | current_year = str(datetime.datetime.now().year) 59 | year_duration = ( 60 | current_year if current_year == creation_year else creation_year + " - " + current_year 61 | ) 62 | copyright = year_duration + " Melissa LeBlanc-Williams" 63 | author = "Melissa LeBlanc-Williams" 64 | 65 | # The version info for the project you're documenting, acts as replacement for 66 | # |version| and |release|, also used in various other places throughout the 67 | # built documents. 68 | # 69 | # The short X.Y version. 70 | version = "1.0" 71 | # The full version, including alpha/beta/rc tags. 72 | release = "1.0" 73 | 74 | # The language for content autogenerated by Sphinx. Refer to documentation 75 | # for a list of supported languages. 76 | # 77 | # This is also used if you do content translation via gettext catalogs. 78 | # Usually you set "language" from the command line for these cases. 79 | language = "en" 80 | 81 | # List of patterns, relative to source directory, that match files and 82 | # directories to ignore when looking for source files. 83 | # This patterns also effect to html_static_path and html_extra_path 84 | exclude_patterns = [ 85 | "_build", 86 | "Thumbs.db", 87 | ".DS_Store", 88 | ".env", 89 | "CODE_OF_CONDUCT.md", 90 | ] 91 | 92 | # The reST default role (used for this markup: `text`) to use for all 93 | # documents. 94 | # 95 | default_role = "any" 96 | 97 | # If true, '()' will be appended to :func: etc. cross-reference text. 98 | # 99 | add_function_parentheses = True 100 | 101 | # The name of the Pygments (syntax highlighting) style to use. 102 | pygments_style = "sphinx" 103 | 104 | # If true, `todo` and `todoList` produce output, else they produce nothing. 105 | todo_include_todos = False 106 | 107 | # If this is True, todo emits a warning for each TODO entries. The default is False. 108 | todo_emit_warnings = True 109 | 110 | napoleon_numpy_docstring = False 111 | 112 | # -- Options for HTML output ---------------------------------------------- 113 | 114 | # The theme to use for HTML and HTML Help pages. See the documentation for 115 | # a list of builtin themes. 116 | # 117 | import sphinx_rtd_theme 118 | 119 | html_theme = "sphinx_rtd_theme" 120 | 121 | # Add any paths that contain custom static files (such as style sheets) here, 122 | # relative to this directory. They are copied after the builtin static files, 123 | # so a file named "default.css" will overwrite the builtin "default.css". 124 | html_static_path = ["_static"] 125 | 126 | # Include extra css to work around rtd theme glitches 127 | html_css_files = ["custom.css"] 128 | 129 | # The name of an image file (relative to this directory) to use as a favicon of 130 | # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 131 | # pixels large. 132 | # 133 | html_favicon = "_static/favicon.ico" 134 | 135 | # Output file base name for HTML help builder. 136 | htmlhelp_basename = "Adafruit_CircuitPython_FunhouseLibrarydoc" 137 | 138 | # -- Options for LaTeX output --------------------------------------------- 139 | 140 | latex_elements = { 141 | # The paper size ('letterpaper' or 'a4paper'). 142 | # 'papersize': 'letterpaper', 143 | # The font size ('10pt', '11pt' or '12pt'). 144 | # 'pointsize': '10pt', 145 | # Additional stuff for the LaTeX preamble. 146 | # 'preamble': '', 147 | # Latex figure (float) alignment 148 | # 'figure_align': 'htbp', 149 | } 150 | 151 | # Grouping the document tree into LaTeX files. List of tuples 152 | # (source start file, target name, title, 153 | # author, documentclass [howto, manual, or own class]). 154 | latex_documents = [ 155 | ( 156 | master_doc, 157 | "Adafruit_CircuitPython_FunHouseLibrary.tex", 158 | "Adafruit CircuitPython FunHouse Library Documentation", 159 | author, 160 | "manual", 161 | ), 162 | ] 163 | 164 | # -- Options for manual page output --------------------------------------- 165 | 166 | # One entry per manual page. List of tuples 167 | # (source start file, name, description, authors, manual section). 168 | man_pages = [ 169 | ( 170 | master_doc, 171 | "Adafruit_CircuitPython_FunHouseLibrary", 172 | "Adafruit CircuitPython FunHouse Library Documentation", 173 | [author], 174 | 1, 175 | ), 176 | ] 177 | 178 | # -- Options for Texinfo output ------------------------------------------- 179 | 180 | # Grouping the document tree into Texinfo files. List of tuples 181 | # (source start file, target name, title, author, 182 | # dir menu entry, description, category) 183 | texinfo_documents = [ 184 | ( 185 | master_doc, 186 | "Adafruit_CircuitPython_FunHouseLibrary", 187 | "Adafruit CircuitPython FunHouse Library Documentation", 188 | author, 189 | "Adafruit_CircuitPython_FunHouseLibrary", 190 | "One line description of project.", 191 | "Miscellaneous", 192 | ), 193 | ] 194 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 7 | # Adafruit Community Code of Conduct 8 | 9 | ## Our Pledge 10 | 11 | In the interest of fostering an open and welcoming environment, we as 12 | contributors and leaders pledge to making participation in our project and 13 | our community a harassment-free experience for everyone, regardless of age, body 14 | size, disability, ethnicity, gender identity and expression, level or type of 15 | experience, education, socio-economic status, nationality, personal appearance, 16 | race, religion, or sexual identity and orientation. 17 | 18 | ## Our Standards 19 | 20 | We are committed to providing a friendly, safe and welcoming environment for 21 | all. 22 | 23 | Examples of behavior that contributes to creating a positive environment 24 | include: 25 | 26 | * Be kind and courteous to others 27 | * Using welcoming and inclusive language 28 | * Being respectful of differing viewpoints and experiences 29 | * Collaborating with other community members 30 | * Gracefully accepting constructive criticism 31 | * Focusing on what is best for the community 32 | * Showing empathy towards other community members 33 | 34 | Examples of unacceptable behavior by participants include: 35 | 36 | * The use of sexualized language or imagery and sexual attention or advances 37 | * The use of inappropriate images, including in a community member's avatar 38 | * The use of inappropriate language, including in a community member's nickname 39 | * Any spamming, flaming, baiting or other attention-stealing behavior 40 | * Excessive or unwelcome helping; answering outside the scope of the question 41 | asked 42 | * Trolling, insulting/derogatory comments, and personal or political attacks 43 | * Promoting or spreading disinformation, lies, or conspiracy theories against 44 | a person, group, organisation, project, or community 45 | * Public or private harassment 46 | * Publishing others' private information, such as a physical or electronic 47 | address, without explicit permission 48 | * Other conduct which could reasonably be considered inappropriate 49 | 50 | The goal of the standards and moderation guidelines outlined here is to build 51 | and maintain a respectful community. We ask that you don’t just aim to be 52 | "technically unimpeachable", but rather try to be your best self. 53 | 54 | We value many things beyond technical expertise, including collaboration and 55 | supporting others within our community. Providing a positive experience for 56 | other community members can have a much more significant impact than simply 57 | providing the correct answer. 58 | 59 | ## Our Responsibilities 60 | 61 | Project leaders are responsible for clarifying the standards of acceptable 62 | behavior and are expected to take appropriate and fair corrective action in 63 | response to any instances of unacceptable behavior. 64 | 65 | Project leaders have the right and responsibility to remove, edit, or 66 | reject messages, comments, commits, code, issues, and other contributions 67 | that are not aligned to this Code of Conduct, or to ban temporarily or 68 | permanently any community member for other behaviors that they deem 69 | inappropriate, threatening, offensive, or harmful. 70 | 71 | ## Moderation 72 | 73 | Instances of behaviors that violate the Adafruit Community Code of Conduct 74 | may be reported by any member of the community. Community members are 75 | encouraged to report these situations, including situations they witness 76 | involving other community members. 77 | 78 | You may report in the following ways: 79 | 80 | In any situation, you may send an email to . 81 | 82 | On the Adafruit Discord, you may send an open message from any channel 83 | to all Community Moderators by tagging @community moderators. You may 84 | also send an open message from any channel, or a direct message to 85 | @kattni#1507, @tannewt#4653, @danh#1614, @cater#2442, 86 | @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. 87 | 88 | Email and direct message reports will be kept confidential. 89 | 90 | In situations on Discord where the issue is particularly egregious, possibly 91 | illegal, requires immediate action, or violates the Discord terms of service, 92 | you should also report the message directly to Discord. 93 | 94 | These are the steps for upholding our community’s standards of conduct. 95 | 96 | 1. Any member of the community may report any situation that violates the 97 | Adafruit Community Code of Conduct. All reports will be reviewed and 98 | investigated. 99 | 2. If the behavior is an egregious violation, the community member who 100 | committed the violation may be banned immediately, without warning. 101 | 3. Otherwise, moderators will first respond to such behavior with a warning. 102 | 4. Moderators follow a soft "three strikes" policy - the community member may 103 | be given another chance, if they are receptive to the warning and change their 104 | behavior. 105 | 5. If the community member is unreceptive or unreasonable when warned by a 106 | moderator, or the warning goes unheeded, they may be banned for a first or 107 | second offense. Repeated offenses will result in the community member being 108 | banned. 109 | 110 | ## Scope 111 | 112 | This Code of Conduct and the enforcement policies listed above apply to all 113 | Adafruit Community venues. This includes but is not limited to any community 114 | spaces (both public and private), the entire Adafruit Discord server, and 115 | Adafruit GitHub repositories. Examples of Adafruit Community spaces include 116 | but are not limited to meet-ups, audio chats on the Adafruit Discord, or 117 | interaction at a conference. 118 | 119 | This Code of Conduct applies both within project spaces and in public spaces 120 | when an individual is representing the project or its community. As a community 121 | member, you are representing our community, and are expected to behave 122 | accordingly. 123 | 124 | ## Attribution 125 | 126 | This Code of Conduct is adapted from the [Contributor Covenant], 127 | version 1.4, available at 128 | , 129 | and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). 130 | 131 | For other projects adopting the Adafruit Community Code of 132 | Conduct, please contact the maintainers of those projects for enforcement. 133 | If you wish to use this code of conduct for your own project, consider 134 | explicitly mentioning your moderation policy or making a copy with your 135 | own moderation policy so as to avoid confusion. 136 | 137 | [Contributor Covenant]: https://www.contributor-covenant.org 138 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | 5 | .. image:: https://readthedocs.org/projects/adafruit-circuitpython-funhouse/badge/?version=latest 6 | :target: https://docs.circuitpython.org/projects/funhouse/en/latest/ 7 | :alt: Documentation Status 8 | 9 | 10 | .. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg 11 | :target: https://adafru.it/discord 12 | :alt: Discord 13 | 14 | 15 | .. image:: https://github.com/adafruit/Adafruit_CircuitPython_FunHouse/workflows/Build%20CI/badge.svg 16 | :target: https://github.com/adafruit/Adafruit_CircuitPython_FunHouse/actions 17 | :alt: Build Status 18 | 19 | 20 | .. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json 21 | :target: https://github.com/astral-sh/ruff 22 | :alt: Code Style: Ruff 23 | 24 | Helper library for the Adafruit FunHouse board 25 | 26 | 27 | Dependencies 28 | ============= 29 | This driver depends on: 30 | 31 | * `Adafruit CircuitPython `_ 32 | * `Adafruit CircuitPython AHTx0 `_ 33 | * `Adafruit CircuitPython Connection Manager `_ 34 | * `Adafruit CircuitPython DotStar `_ 35 | * `Adafruit CircuitPython DPS310 `_ 36 | * `Adafruit CircuitPython MiniMQTT `_ 37 | * `Adafruit CircuitPython PortalBase `_ 38 | * `Adafruit CircuitPython Requests `_ 39 | * `Adafruit CircuitPython SimpleIO `_ 40 | 41 | Please ensure all dependencies are available on the CircuitPython filesystem. 42 | This is easily achieved by downloading 43 | `the Adafruit library and driver bundle `_ 44 | or individual libraries can be installed using 45 | `circup `_. 46 | 47 | Adafruit FunHouse Home Automation board 48 | 49 | `Purchase one from the Adafruit shop `_ 50 | 51 | 52 | Usage Example 53 | ============= 54 | 55 | .. code:: python 56 | 57 | import board 58 | from digitalio import DigitalInOut, Direction, Pull 59 | import adafruit_dps310 60 | import adafruit_ahtx0 61 | from adafruit_funhouse import FunHouse 62 | 63 | funhouse = FunHouse( 64 | default_bg=0x0F0F00, 65 | scale=2, 66 | ) 67 | 68 | i2c = board.I2C() 69 | dps310 = adafruit_dps310.DPS310(i2c) 70 | aht20 = adafruit_ahtx0.AHTx0(i2c) 71 | 72 | funhouse.peripherals.set_dotstars(0x800000, 0x808000, 0x008000, 0x000080, 0x800080) 73 | 74 | # sensor setup 75 | sensors = [] 76 | for p in (board.A0, board.A1, board.A2): 77 | sensor = DigitalInOut(p) 78 | sensor.direction = Direction.INPUT 79 | sensor.pull = Pull.DOWN 80 | sensors.append(sensor) 81 | 82 | 83 | def set_label_color(conditional, index, on_color): 84 | if conditional: 85 | funhouse.set_text_color(on_color, index) 86 | else: 87 | funhouse.set_text_color(0x606060, index) 88 | 89 | 90 | # Create the labels 91 | funhouse.display.root_group = None 92 | slider_label = funhouse.add_text( 93 | text="Slider:", text_position=(50, 30), text_color=0x606060 94 | ) 95 | capright_label = funhouse.add_text( 96 | text="Touch", text_position=(85, 10), text_color=0x606060 97 | ) 98 | pir_label = funhouse.add_text(text="PIR", text_position=(60, 10), text_color=0x606060) 99 | capleft_label = funhouse.add_text( 100 | text="Touch", text_position=(25, 10), text_color=0x606060 101 | ) 102 | onoff_label = funhouse.add_text(text="OFF", text_position=(10, 25), text_color=0x606060) 103 | up_label = funhouse.add_text(text="UP", text_position=(10, 10), text_color=0x606060) 104 | sel_label = funhouse.add_text(text="SEL", text_position=(10, 60), text_color=0x606060) 105 | down_label = funhouse.add_text( 106 | text="DOWN", text_position=(10, 100), text_color=0x606060 107 | ) 108 | jst1_label = funhouse.add_text( 109 | text="SENSOR 1", text_position=(40, 80), text_color=0x606060 110 | ) 111 | jst2_label = funhouse.add_text( 112 | text="SENSOR 2", text_position=(40, 95), text_color=0x606060 113 | ) 114 | jst3_label = funhouse.add_text( 115 | text="SENSOR 3", text_position=(40, 110), text_color=0x606060 116 | ) 117 | temp_label = funhouse.add_text( 118 | text="Temp:", text_position=(50, 45), text_color=0xFF00FF 119 | ) 120 | pres_label = funhouse.add_text( 121 | text="Pres:", text_position=(50, 60), text_color=0xFF00FF 122 | ) 123 | funhouse.display.root_group = funhouse.root_group 124 | 125 | while True: 126 | funhouse.set_text("Temp %0.1F" % dps310.temperature, temp_label) 127 | funhouse.set_text("Pres %d" % dps310.pressure, pres_label) 128 | 129 | print(aht20.temperature, aht20.relative_humidity) 130 | set_label_color(funhouse.peripherals.captouch6, onoff_label, 0x00FF00) 131 | set_label_color(funhouse.peripherals.captouch7, capleft_label, 0x00FF00) 132 | set_label_color(funhouse.peripherals.captouch8, capright_label, 0x00FF00) 133 | 134 | slider = funhouse.peripherals.slider 135 | if slider is not None: 136 | funhouse.peripherals.dotstars.brightness = slider 137 | funhouse.set_text("Slider: %1.1f" % slider, slider_label) 138 | set_label_color(slider is not None, slider_label, 0xFFFF00) 139 | 140 | set_label_color(funhouse.peripherals.button_up, up_label, 0xFF0000) 141 | set_label_color(funhouse.peripherals.button_sel, sel_label, 0xFFFF00) 142 | set_label_color(funhouse.peripherals.button_down, down_label, 0x00FF00) 143 | 144 | set_label_color(funhouse.peripherals.pir_sensor, pir_label, 0xFF0000) 145 | set_label_color(sensors[0].value, jst1_label, 0xFFFFFF) 146 | set_label_color(sensors[1].value, jst2_label, 0xFFFFFF) 147 | set_label_color(sensors[2].value, jst3_label, 0xFFFFFF) 148 | 149 | 150 | Documentation 151 | ============= 152 | 153 | API documentation for this library can be found on `Read the Docs `_. 154 | 155 | For information on building library documentation, please check out `this guide `_. 156 | 157 | Contributing 158 | ============ 159 | 160 | Contributions are welcome! Please read our `Code of Conduct 161 | `_ 162 | before contributing to help this project stay welcoming. 163 | -------------------------------------------------------------------------------- /adafruit_funhouse/peripherals.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | `adafruit_funhouse.peripherals` 7 | ================================================================================ 8 | 9 | Helper library for the Adafruit FunHouse board. 10 | 11 | 12 | * Author(s): Melissa LeBlanc-Williams 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Hardware:** 18 | 19 | * `Adafruit FunHouse `_ 20 | 21 | **Software and Dependencies:** 22 | 23 | * Adafruit CircuitPython firmware for the supported boards: 24 | https://github.com/adafruit/circuitpython/releases 25 | 26 | * Adafruit's PortalBase library: https://github.com/adafruit/Adafruit_CircuitPython_PortalBase 27 | 28 | """ 29 | 30 | import adafruit_ahtx0 31 | import adafruit_dotstar 32 | import adafruit_dps310 33 | import board 34 | import simpleio 35 | import touchio 36 | from analogio import AnalogIn 37 | from digitalio import DigitalInOut, Direction, Pull 38 | 39 | try: 40 | from typing import Optional 41 | except ImportError: 42 | pass 43 | 44 | __version__ = "0.0.0+auto.0" 45 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" 46 | 47 | 48 | class Peripherals: 49 | """Peripherals Helper Class for the FunHouse Library 50 | 51 | 52 | Attributes: 53 | dotstars (DotStar): The DotStars on the FunHouse board. 54 | See https://circuitpython.readthedocs.io/projects/dotstar/en/latest/api.html 55 | """ 56 | 57 | def __init__(self) -> None: 58 | # Dotstars 59 | self.dotstars = adafruit_dotstar.DotStar( 60 | board.DOTSTAR_CLOCK, board.DOTSTAR_DATA, 5, brightness=0.3 61 | ) 62 | 63 | # Light Sensor 64 | self._light = AnalogIn(board.LIGHT) 65 | 66 | # Buttons 67 | self._buttons = [] 68 | for pin in (board.BUTTON_DOWN, board.BUTTON_SELECT, board.BUTTON_UP): 69 | switch = DigitalInOut(pin) 70 | switch.direction = Direction.INPUT 71 | switch.pull = Pull.DOWN 72 | self._buttons.append(switch) 73 | 74 | # Cap Tocuh Pads 75 | self._ctp = [] 76 | for pin in ( 77 | board.CAP6, 78 | board.CAP7, 79 | board.CAP8, 80 | board.CAP13, 81 | board.CAP12, 82 | board.CAP11, 83 | board.CAP10, 84 | board.CAP9, 85 | ): 86 | cap = touchio.TouchIn(pin) 87 | cap.threshold = 20000 88 | self._ctp.append(cap) 89 | 90 | self.i2c = board.I2C() 91 | self._dps310 = adafruit_dps310.DPS310(self.i2c) 92 | self._aht20 = adafruit_ahtx0.AHTx0(self.i2c) 93 | 94 | # LED 95 | self._led = DigitalInOut(board.LED) 96 | self._led.direction = Direction.OUTPUT 97 | 98 | # PIR Sensor 99 | self._pir = DigitalInOut(board.PIR_SENSE) 100 | self._pir.direction = Direction.INPUT 101 | 102 | @staticmethod 103 | def play_tone(frequency: float, duration: float) -> None: 104 | """Automatically Enable/Disable the speaker and play 105 | a tone at the specified frequency for the specified duration 106 | It will attempt to play the sound up to 3 times in the case of 107 | an error. 108 | """ 109 | if frequency < 0: 110 | raise ValueError("Negative frequencies are not allowed.") 111 | attempt = 0 112 | # Try up to 3 times to play the sound 113 | while attempt < 3: 114 | try: 115 | simpleio.tone(board.SPEAKER, frequency, duration) 116 | break 117 | except NameError: 118 | pass 119 | attempt += 1 120 | 121 | def set_dotstars(self, *values: int) -> None: 122 | """Set the dotstar values to the provided values""" 123 | for i, value in enumerate(values[: len(self.dotstars)]): 124 | self.dotstars[i] = value 125 | 126 | def deinit(self) -> None: 127 | """Call deinit on all resources to free them""" 128 | self.dotstars.deinit() 129 | for button in self._buttons: 130 | button.deinit() 131 | for ctp in self._ctp: 132 | ctp.deinit() 133 | self._light.deinit() 134 | self._led.deinit() 135 | self._pir.deinit() 136 | 137 | @property 138 | def button_down(self) -> bool: 139 | """ 140 | Return whether Down Button is pressed 141 | """ 142 | return self._buttons[0].value 143 | 144 | @property 145 | def button_sel(self) -> bool: 146 | """ 147 | Return whether Sel Button is pressed 148 | """ 149 | return self._buttons[1].value 150 | 151 | @property 152 | def button_up(self) -> bool: 153 | """ 154 | Return whether Up Button is pressed 155 | """ 156 | return self._buttons[2].value 157 | 158 | @property 159 | def any_button_pressed(self) -> bool: 160 | """ 161 | Return whether any button is pressed 162 | """ 163 | return True in [button.value for (i, button) in enumerate(self._buttons)] 164 | 165 | @property 166 | def captouch6(self) -> bool: 167 | """ 168 | Return whether CT6 Touch Pad is touched 169 | """ 170 | return self._ctp[0].value 171 | 172 | @property 173 | def captouch7(self) -> bool: 174 | """ 175 | Return whether CT7 Touch Pad is touched 176 | """ 177 | return self._ctp[1].value 178 | 179 | @property 180 | def captouch8(self) -> bool: 181 | """ 182 | Return whether CT8 Touch Pad is touched 183 | """ 184 | return self._ctp[2].value 185 | 186 | @property 187 | def slider(self) -> Optional[float]: 188 | """ 189 | Return the slider position value in the range of 0.0-1.0 or None if not touched 190 | """ 191 | val = 0 192 | cap_map = (0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x18, 0x10) 193 | for cap in range(5): 194 | if self._ctp[cap + 3].value: 195 | val += 1 << (cap) 196 | return cap_map.index(val) / 8 if val in cap_map else None 197 | 198 | @property 199 | def light(self) -> int: 200 | """ 201 | Return the value of the light sensor. The neopixel_disable property 202 | must be false to get a value. 203 | 204 | .. code-block:: python 205 | 206 | import time 207 | from adafruit_funhouse import FunHouse 208 | 209 | funhouse = FunHouse() 210 | 211 | while True: 212 | print(funhouse.peripherals.light) 213 | time.sleep(0.01) 214 | 215 | """ 216 | return self._light.value 217 | 218 | @property 219 | def temperature(self) -> float: 220 | """ 221 | Return the temperature in degrees Celsius 222 | """ 223 | return self._aht20.temperature 224 | 225 | @property 226 | def relative_humidity(self) -> float: 227 | """ 228 | Return the relative humidity as a percentage (0 - 100) 229 | """ 230 | return self._aht20.relative_humidity 231 | 232 | @property 233 | def pressure(self) -> float: 234 | """ 235 | Return the barometric pressure in hPa, or equivalently in mBar 236 | """ 237 | return self._dps310.pressure 238 | 239 | @property 240 | def led(self) -> bool: 241 | """ 242 | Return or set the value of the LED 243 | """ 244 | return self._led.value 245 | 246 | @led.setter 247 | def led(self, value: bool) -> None: 248 | self._led.value = bool(value) 249 | 250 | @property 251 | def pir_sensor(self) -> bool: 252 | """ 253 | Return the value of the PIR Sensor 254 | """ 255 | return self._pir.value 256 | -------------------------------------------------------------------------------- /adafruit_funhouse/network.py: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries 2 | # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries 3 | # 4 | # SPDX-License-Identifier: MIT 5 | """ 6 | `adafruit_funhouse.network` 7 | ================================================================================ 8 | 9 | Helper library for the Adafruit FunHouse board. 10 | 11 | 12 | * Author(s): Melissa LeBlanc-Williams 13 | 14 | Implementation Notes 15 | -------------------- 16 | 17 | **Hardware:** 18 | 19 | * `Adafruit FunHouse `_ 20 | 21 | **Software and Dependencies:** 22 | 23 | * Adafruit CircuitPython firmware for the supported boards: 24 | https://github.com/adafruit/circuitpython/releases 25 | 26 | * Adafruit's PortalBase library: https://github.com/adafruit/Adafruit_CircuitPython_PortalBase 27 | 28 | """ 29 | 30 | import ssl 31 | 32 | import adafruit_minimqtt.adafruit_minimqtt as MQTT 33 | from adafruit_io.adafruit_io import IO_MQTT 34 | from adafruit_portalbase.network import NetworkBase 35 | from adafruit_portalbase.wifi_esp32s2 import WiFi 36 | 37 | try: 38 | from typing import Callable, Optional, Union 39 | 40 | from adafruit_dotstar import DotStar 41 | except ImportError: 42 | pass 43 | 44 | __version__ = "0.0.0+auto.0" 45 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_FunHouse.git" 46 | 47 | IO_MQTT_BROKER = "io.adafruit.com" 48 | 49 | 50 | class Network(NetworkBase): 51 | """Class representing the Adafruit FunHouse. 52 | 53 | :param status_dotstar: The initialized object for status DotStar. Defaults to ``None``, 54 | to not use the status LED 55 | :param bool extract_values: If true, single-length fetched values are automatically extracted 56 | from lists and tuples. Defaults to ``True``. 57 | :param debug: Turn on debug print outs. Defaults to False. 58 | 59 | """ 60 | 61 | def __init__( 62 | self, 63 | *, 64 | status_dotstar: Optional[DotStar] = None, 65 | extract_values: bool = True, 66 | debug: bool = False, 67 | ) -> None: 68 | super().__init__( 69 | WiFi(status_led=status_dotstar), 70 | extract_values=extract_values, 71 | debug=debug, 72 | ) 73 | self._mqtt_client = None 74 | 75 | def init_io_mqtt(self) -> IO_MQTT: 76 | """Initialize MQTT for Adafruit IO""" 77 | aio_username = self._get_setting["ADAFRUIT_AIO_USERNAME"] 78 | aio_key = self._get_setting["ADAFRUIT_AIO_KEY"] 79 | if None in {aio_username, aio_key}: 80 | raise AttributeError( 81 | "Adafruit IO keys are kept in settings.toml, please add them there." 82 | ) 83 | 84 | return self.init_mqtt(IO_MQTT_BROKER, 8883, aio_username, aio_key, True) 85 | 86 | def init_mqtt( 87 | self, 88 | broker: str, 89 | port: int = 8883, 90 | username: str = None, 91 | password: str = None, 92 | use_io: bool = False, 93 | ) -> Union[MQTT.MQTT, IO_MQTT]: 94 | """Initialize MQTT""" 95 | self.connect() 96 | self._mqtt_client = MQTT.MQTT( 97 | broker=broker, 98 | port=port, 99 | username=username, 100 | password=password, 101 | socket_pool=self._wifi.pool, 102 | ssl_context=ssl.create_default_context(), 103 | ) 104 | if use_io: 105 | self._mqtt_client = IO_MQTT(self._mqtt_client) 106 | 107 | return self._mqtt_client 108 | 109 | # pylint: enable=too-many-arguments 110 | 111 | def _get_mqtt_client(self) -> Union[MQTT.MQTT, IO_MQTT]: 112 | if self._mqtt_client is not None: 113 | return self._mqtt_client 114 | raise RuntimeError("Please initialize MQTT before using") 115 | 116 | def mqtt_loop(self, *args: int, suppress_mqtt_errors: bool = True, **kwargs: int) -> None: 117 | """Run the MQTT Loop""" 118 | self._get_mqtt_client() 119 | if suppress_mqtt_errors: 120 | try: 121 | if self._mqtt_client is not None: 122 | self._mqtt_client.loop(*args, **kwargs) 123 | except MQTT.MMQTTException as err: 124 | print(f"MMQTTException: {err}") 125 | except OSError as err: 126 | print(f"OSError: {err}") 127 | elif self._mqtt_client is not None: 128 | self._mqtt_client.loop(*args, **kwargs) 129 | 130 | def mqtt_publish( 131 | self, 132 | *args: Union[str, int, float], 133 | suppress_mqtt_errors: bool = True, 134 | **kwargs: Union[str, int, float], 135 | ) -> None: 136 | """Publish to MQTT""" 137 | self._get_mqtt_client() 138 | if suppress_mqtt_errors: 139 | try: 140 | if self._mqtt_client is not None: 141 | self._mqtt_client.publish(*args, **kwargs) 142 | except OSError as err: 143 | print(f"OSError: {err}") 144 | elif self._mqtt_client is not None: 145 | self._mqtt_client.publish(*args, **kwargs) 146 | 147 | def mqtt_connect(self, *args: Union[bool, str, int], **kwargs: Union[bool, str, int]) -> None: 148 | """Connect to MQTT""" 149 | self._get_mqtt_client() 150 | if self._mqtt_client is not None: 151 | self._mqtt_client.connect(*args, **kwargs) 152 | 153 | @property 154 | def on_mqtt_connect(self) -> Optional[Callable]: 155 | """ 156 | Get or Set the MQTT Connect Handler 157 | 158 | """ 159 | if self._mqtt_client: 160 | return self._mqtt_client.on_connect 161 | return None 162 | 163 | @on_mqtt_connect.setter 164 | def on_mqtt_connect(self, value: Callable) -> None: 165 | self._get_mqtt_client() 166 | self._mqtt_client.on_connect = value 167 | 168 | @property 169 | def on_mqtt_disconnect(self) -> Optional[Callable]: 170 | """ 171 | Get or Set the MQTT Disconnect Handler 172 | 173 | """ 174 | if self._mqtt_client: 175 | return self._mqtt_client.on_disconnect 176 | return None 177 | 178 | @on_mqtt_disconnect.setter 179 | def on_mqtt_disconnect(self, value: Callable) -> None: 180 | self._get_mqtt_client().on_disconnect = value 181 | 182 | @property 183 | def on_mqtt_subscribe(self) -> Optional[Callable]: 184 | """ 185 | Get or Set the MQTT Subscribe Handler 186 | 187 | """ 188 | if self._mqtt_client: 189 | return self._mqtt_client.on_subscribe 190 | return None 191 | 192 | @on_mqtt_subscribe.setter 193 | def on_mqtt_subscribe(self, value: Callable) -> None: 194 | self._get_mqtt_client().on_subscribe = value 195 | 196 | @property 197 | def on_mqtt_unsubscribe(self) -> Optional[Callable]: 198 | """ 199 | Get or Set the MQTT Unsubscribe Handler 200 | 201 | """ 202 | if self._mqtt_client: 203 | return self._mqtt_client.on_unsubscribe 204 | return None 205 | 206 | @on_mqtt_unsubscribe.setter 207 | def on_mqtt_unsubscribe(self, value: Callable) -> None: 208 | self._get_mqtt_client().on_unsubscribe = value 209 | 210 | @property 211 | def on_mqtt_message(self) -> Optional[Callable]: 212 | """ 213 | Get or Set the MQTT Message Handler 214 | 215 | """ 216 | if self._mqtt_client: 217 | return self._mqtt_client.on_message 218 | return None 219 | 220 | @on_mqtt_message.setter 221 | def on_mqtt_message(self, value: Callable) -> None: 222 | self._get_mqtt_client().on_message = value 223 | 224 | @property 225 | def enabled(self) -> bool: 226 | """ 227 | Get or Set whether the WiFi is enabled 228 | 229 | """ 230 | return self._wifi.enabled 231 | 232 | @enabled.setter 233 | def enabled(self, value: bool) -> None: 234 | self._wifi.enabled = bool(value) 235 | -------------------------------------------------------------------------------- /LICENSES/CC-BY-4.0.txt: -------------------------------------------------------------------------------- 1 | Creative Commons Attribution 4.0 International Creative Commons Corporation 2 | ("Creative Commons") is not a law firm and does not provide legal services 3 | or legal advice. Distribution of Creative Commons public licenses does not 4 | create a lawyer-client or other relationship. Creative Commons makes its licenses 5 | and related information available on an "as-is" basis. Creative Commons gives 6 | no warranties regarding its licenses, any material licensed under their terms 7 | and conditions, or any related information. Creative Commons disclaims all 8 | liability for damages resulting from their use to the fullest extent possible. 9 | 10 | Using Creative Commons Public Licenses 11 | 12 | Creative Commons public licenses provide a standard set of terms and conditions 13 | that creators and other rights holders may use to share original works of 14 | authorship and other material subject to copyright and certain other rights 15 | specified in the public license below. The following considerations are for 16 | informational purposes only, are not exhaustive, and do not form part of our 17 | licenses. 18 | 19 | Considerations for licensors: Our public licenses are intended for use by 20 | those authorized to give the public permission to use material in ways otherwise 21 | restricted by copyright and certain other rights. Our licenses are irrevocable. 22 | Licensors should read and understand the terms and conditions of the license 23 | they choose before applying it. Licensors should also secure all rights necessary 24 | before applying our licenses so that the public can reuse the material as 25 | expected. Licensors should clearly mark any material not subject to the license. 26 | This includes other CC-licensed material, or material used under an exception 27 | or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors 28 | 29 | Considerations for the public: By using one of our public licenses, a licensor 30 | grants the public permission to use the licensed material under specified 31 | terms and conditions. If the licensor's permission is not necessary for any 32 | reason–for example, because of any applicable exception or limitation to copyright–then 33 | that use is not regulated by the license. Our licenses grant only permissions 34 | under copyright and certain other rights that a licensor has authority to 35 | grant. Use of the licensed material may still be restricted for other reasons, 36 | including because others have copyright or other rights in the material. A 37 | licensor may make special requests, such as asking that all changes be marked 38 | or described. Although not required by our licenses, you are encouraged to 39 | respect those requests where reasonable. More considerations for the public 40 | : wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution 41 | 4.0 International Public License 42 | 43 | By exercising the Licensed Rights (defined below), You accept and agree to 44 | be bound by the terms and conditions of this Creative Commons Attribution 45 | 4.0 International Public License ("Public License"). To the extent this Public 46 | License may be interpreted as a contract, You are granted the Licensed Rights 47 | in consideration of Your acceptance of these terms and conditions, and the 48 | Licensor grants You such rights in consideration of benefits the Licensor 49 | receives from making the Licensed Material available under these terms and 50 | conditions. 51 | 52 | Section 1 – Definitions. 53 | 54 | a. Adapted Material means material subject to Copyright and Similar Rights 55 | that is derived from or based upon the Licensed Material and in which the 56 | Licensed Material is translated, altered, arranged, transformed, or otherwise 57 | modified in a manner requiring permission under the Copyright and Similar 58 | Rights held by the Licensor. For purposes of this Public License, where the 59 | Licensed Material is a musical work, performance, or sound recording, Adapted 60 | Material is always produced where the Licensed Material is synched in timed 61 | relation with a moving image. 62 | 63 | b. Adapter's License means the license You apply to Your Copyright and Similar 64 | Rights in Your contributions to Adapted Material in accordance with the terms 65 | and conditions of this Public License. 66 | 67 | c. Copyright and Similar Rights means copyright and/or similar rights closely 68 | related to copyright including, without limitation, performance, broadcast, 69 | sound recording, and Sui Generis Database Rights, without regard to how the 70 | rights are labeled or categorized. For purposes of this Public License, the 71 | rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 72 | 73 | d. Effective Technological Measures means those measures that, in the absence 74 | of proper authority, may not be circumvented under laws fulfilling obligations 75 | under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, 76 | and/or similar international agreements. 77 | 78 | e. Exceptions and Limitations means fair use, fair dealing, and/or any other 79 | exception or limitation to Copyright and Similar Rights that applies to Your 80 | use of the Licensed Material. 81 | 82 | f. Licensed Material means the artistic or literary work, database, or other 83 | material to which the Licensor applied this Public License. 84 | 85 | g. Licensed Rights means the rights granted to You subject to the terms and 86 | conditions of this Public License, which are limited to all Copyright and 87 | Similar Rights that apply to Your use of the Licensed Material and that the 88 | Licensor has authority to license. 89 | 90 | h. Licensor means the individual(s) or entity(ies) granting rights under this 91 | Public License. 92 | 93 | i. Share means to provide material to the public by any means or process that 94 | requires permission under the Licensed Rights, such as reproduction, public 95 | display, public performance, distribution, dissemination, communication, or 96 | importation, and to make material available to the public including in ways 97 | that members of the public may access the material from a place and at a time 98 | individually chosen by them. 99 | 100 | j. Sui Generis Database Rights means rights other than copyright resulting 101 | from Directive 96/9/EC of the European Parliament and of the Council of 11 102 | March 1996 on the legal protection of databases, as amended and/or succeeded, 103 | as well as other essentially equivalent rights anywhere in the world. 104 | 105 | k. You means the individual or entity exercising the Licensed Rights under 106 | this Public License. Your has a corresponding meaning. 107 | 108 | Section 2 – Scope. 109 | 110 | a. License grant. 111 | 112 | 1. Subject to the terms and conditions of this Public License, the Licensor 113 | hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, 114 | irrevocable license to exercise the Licensed Rights in the Licensed Material 115 | to: 116 | 117 | A. reproduce and Share the Licensed Material, in whole or in part; and 118 | 119 | B. produce, reproduce, and Share Adapted Material. 120 | 121 | 2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions 122 | and Limitations apply to Your use, this Public License does not apply, and 123 | You do not need to comply with its terms and conditions. 124 | 125 | 3. Term. The term of this Public License is specified in Section 6(a). 126 | 127 | 4. Media and formats; technical modifications allowed. The Licensor authorizes 128 | You to exercise the Licensed Rights in all media and formats whether now known 129 | or hereafter created, and to make technical modifications necessary to do 130 | so. The Licensor waives and/or agrees not to assert any right or authority 131 | to forbid You from making technical modifications necessary to exercise the 132 | Licensed Rights, including technical modifications necessary to circumvent 133 | Effective Technological Measures. For purposes of this Public License, simply 134 | making modifications authorized by this Section 2(a)(4) never produces Adapted 135 | Material. 136 | 137 | 5. Downstream recipients. 138 | 139 | A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed 140 | Material automatically receives an offer from the Licensor to exercise the 141 | Licensed Rights under the terms and conditions of this Public License. 142 | 143 | B. No downstream restrictions. You may not offer or impose any additional 144 | or different terms or conditions on, or apply any Effective Technological 145 | Measures to, the Licensed Material if doing so restricts exercise of the Licensed 146 | Rights by any recipient of the Licensed Material. 147 | 148 | 6. No endorsement. Nothing in this Public License constitutes or may be construed 149 | as permission to assert or imply that You are, or that Your use of the Licensed 150 | Material is, connected with, or sponsored, endorsed, or granted official status 151 | by, the Licensor or others designated to receive attribution as provided in 152 | Section 3(a)(1)(A)(i). 153 | 154 | b. Other rights. 155 | 156 | 1. Moral rights, such as the right of integrity, are not licensed under this 157 | Public License, nor are publicity, privacy, and/or other similar personality 158 | rights; however, to the extent possible, the Licensor waives and/or agrees 159 | not to assert any such rights held by the Licensor to the limited extent necessary 160 | to allow You to exercise the Licensed Rights, but not otherwise. 161 | 162 | 2. Patent and trademark rights are not licensed under this Public License. 163 | 164 | 3. To the extent possible, the Licensor waives any right to collect royalties 165 | from You for the exercise of the Licensed Rights, whether directly or through 166 | a collecting society under any voluntary or waivable statutory or compulsory 167 | licensing scheme. In all other cases the Licensor expressly reserves any right 168 | to collect such royalties. 169 | 170 | Section 3 – License Conditions. 171 | 172 | Your exercise of the Licensed Rights is expressly made subject to the following 173 | conditions. 174 | 175 | a. Attribution. 176 | 177 | 1. If You Share the Licensed Material (including in modified form), You must: 178 | 179 | A. retain the following if it is supplied by the Licensor with the Licensed 180 | Material: 181 | 182 | i. identification of the creator(s) of the Licensed Material and any others 183 | designated to receive attribution, in any reasonable manner requested by the 184 | Licensor (including by pseudonym if designated); 185 | 186 | ii. a copyright notice; 187 | 188 | iii. a notice that refers to this Public License; 189 | 190 | iv. a notice that refers to the disclaimer of warranties; 191 | 192 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 193 | 194 | B. indicate if You modified the Licensed Material and retain an indication 195 | of any previous modifications; and 196 | 197 | C. indicate the Licensed Material is licensed under this Public License, and 198 | include the text of, or the URI or hyperlink to, this Public License. 199 | 200 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner 201 | based on the medium, means, and context in which You Share the Licensed Material. 202 | For example, it may be reasonable to satisfy the conditions by providing a 203 | URI or hyperlink to a resource that includes the required information. 204 | 205 | 3. If requested by the Licensor, You must remove any of the information required 206 | by Section 3(a)(1)(A) to the extent reasonably practicable. 207 | 208 | 4. If You Share Adapted Material You produce, the Adapter's License You apply 209 | must not prevent recipients of the Adapted Material from complying with this 210 | Public License. 211 | 212 | Section 4 – Sui Generis Database Rights. 213 | 214 | Where the Licensed Rights include Sui Generis Database Rights that apply to 215 | Your use of the Licensed Material: 216 | 217 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, 218 | reuse, reproduce, and Share all or a substantial portion of the contents of 219 | the database; 220 | 221 | b. if You include all or a substantial portion of the database contents in 222 | a database in which You have Sui Generis Database Rights, then the database 223 | in which You have Sui Generis Database Rights (but not its individual contents) 224 | is Adapted Material; and 225 | 226 | c. You must comply with the conditions in Section 3(a) if You Share all or 227 | a substantial portion of the contents of the database. 228 | 229 | For the avoidance of doubt, this Section 4 supplements and does not replace 230 | Your obligations under this Public License where the Licensed Rights include 231 | other Copyright and Similar Rights. 232 | 233 | Section 5 – Disclaimer of Warranties and Limitation of Liability. 234 | 235 | a. Unless otherwise separately undertaken by the Licensor, to the extent possible, 236 | the Licensor offers the Licensed Material as-is and as-available, and makes 237 | no representations or warranties of any kind concerning the Licensed Material, 238 | whether express, implied, statutory, or other. This includes, without limitation, 239 | warranties of title, merchantability, fitness for a particular purpose, non-infringement, 240 | absence of latent or other defects, accuracy, or the presence or absence of 241 | errors, whether or not known or discoverable. Where disclaimers of warranties 242 | are not allowed in full or in part, this disclaimer may not apply to You. 243 | 244 | b. To the extent possible, in no event will the Licensor be liable to You 245 | on any legal theory (including, without limitation, negligence) or otherwise 246 | for any direct, special, indirect, incidental, consequential, punitive, exemplary, 247 | or other losses, costs, expenses, or damages arising out of this Public License 248 | or use of the Licensed Material, even if the Licensor has been advised of 249 | the possibility of such losses, costs, expenses, or damages. Where a limitation 250 | of liability is not allowed in full or in part, this limitation may not apply 251 | to You. 252 | 253 | c. The disclaimer of warranties and limitation of liability provided above 254 | shall be interpreted in a manner that, to the extent possible, most closely 255 | approximates an absolute disclaimer and waiver of all liability. 256 | 257 | Section 6 – Term and Termination. 258 | 259 | a. This Public License applies for the term of the Copyright and Similar Rights 260 | licensed here. However, if You fail to comply with this Public License, then 261 | Your rights under this Public License terminate automatically. 262 | 263 | b. Where Your right to use the Licensed Material has terminated under Section 264 | 6(a), it reinstates: 265 | 266 | 1. automatically as of the date the violation is cured, provided it is cured 267 | within 30 days of Your discovery of the violation; or 268 | 269 | 2. upon express reinstatement by the Licensor. 270 | 271 | c. For the avoidance of doubt, this Section 6(b) does not affect any right 272 | the Licensor may have to seek remedies for Your violations of this Public 273 | License. 274 | 275 | d. For the avoidance of doubt, the Licensor may also offer the Licensed Material 276 | under separate terms or conditions or stop distributing the Licensed Material 277 | at any time; however, doing so will not terminate this Public License. 278 | 279 | e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 280 | 281 | Section 7 – Other Terms and Conditions. 282 | 283 | a. The Licensor shall not be bound by any additional or different terms or 284 | conditions communicated by You unless expressly agreed. 285 | 286 | b. Any arrangements, understandings, or agreements regarding the Licensed 287 | Material not stated herein are separate from and independent of the terms 288 | and conditions of this Public License. 289 | 290 | Section 8 – Interpretation. 291 | 292 | a. For the avoidance of doubt, this Public License does not, and shall not 293 | be interpreted to, reduce, limit, restrict, or impose conditions on any use 294 | of the Licensed Material that could lawfully be made without permission under 295 | this Public License. 296 | 297 | b. To the extent possible, if any provision of this Public License is deemed 298 | unenforceable, it shall be automatically reformed to the minimum extent necessary 299 | to make it enforceable. If the provision cannot be reformed, it shall be severed 300 | from this Public License without affecting the enforceability of the remaining 301 | terms and conditions. 302 | 303 | c. No term or condition of this Public License will be waived and no failure 304 | to comply consented to unless expressly agreed to by the Licensor. 305 | 306 | d. Nothing in this Public License constitutes or may be interpreted as a limitation 307 | upon, or waiver of, any privileges and immunities that apply to the Licensor 308 | or You, including from the legal processes of any jurisdiction or authority. 309 | 310 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative 311 | Commons may elect to apply one of its public licenses to material it publishes 312 | and in those instances will be considered the "Licensor." The text of the 313 | Creative Commons public licenses is dedicated to the public domain under the 314 | CC0 Public Domain Dedication. Except for the limited purpose of indicating 315 | that material is shared under a Creative Commons public license or as otherwise 316 | permitted by the Creative Commons policies published at creativecommons.org/policies, 317 | Creative Commons does not authorize the use of the trademark "Creative Commons" 318 | or any other trademark or logo of Creative Commons without its prior written 319 | consent including, without limitation, in connection with any unauthorized 320 | modifications to any of its public licenses or any other arrangements, understandings, 321 | or agreements concerning use of licensed material. For the avoidance of doubt, 322 | this paragraph does not form part of the public licenses. 323 | 324 | Creative Commons may be contacted at creativecommons.org. 325 | --------------------------------------------------------------------------------