pax_global_header00006660000000000000000000000064150060316620014511gustar00rootroot0000000000000052 comment=bb603f83142072d8ba705280f7600f7a9aec1e4f Python-package-vacuum-map-parser-base-0.1.5/000077500000000000000000000000001500603166200206415ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/.github/000077500000000000000000000000001500603166200222015ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/.github/FUNDING.yml000066400000000000000000000001531500603166200240150ustar00rootroot00000000000000ko_fi: piotrmachowski custom: ["buycoffee.to/piotrmachowski", "paypal.me/PiMachowski", "revolut.me/314ma"] Python-package-vacuum-map-parser-base-0.1.5/.github/dependabot.yml000066400000000000000000000003151500603166200250300ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: "pip" directory: "/" schedule: interval: "weekly" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "weekly" Python-package-vacuum-map-parser-base-0.1.5/.github/workflows/000077500000000000000000000000001500603166200242365ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/.github/workflows/automerge.yaml000066400000000000000000000013551500603166200271160ustar00rootroot00000000000000--- name: 'Automatically merge master -> dev' on: push: branches: - master jobs: build: name: Automatically merge master to dev runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 name: Git checkout with: fetch-depth: 0 - name: Merge master -> dev run: | git config user.name "GitHub Actions" git config user.email "PiotrMachowski@users.noreply.github.com" if (git checkout dev) then git merge --ff-only master || git merge --no-commit master git commit -m "Automatically merge master -> dev" || echo "No commit needed" git push origin dev else echo "No dev branch" fi Python-package-vacuum-map-parser-base-0.1.5/.github/workflows/code_quality.yaml000066400000000000000000000017021500603166200276040ustar00rootroot00000000000000name: Code Quality on: pull_request: branches: - master push: jobs: code_quality: name: ${{ matrix.name }} runs-on: ubuntu-latest strategy: matrix: include: - id: black name: Check code with black - id: isort name: Check code with isort - id: pylint name: Check code with pylint - id: mypy name: Check code with mypy steps: - name: Checkout the repository uses: actions/checkout@v4 - name: Set up Python 3 uses: actions/setup-python@v5 id: python with: python-version: "3.11" - name: Install workflow dependencies run: | pip install -r .github/workflows/requirements.txt - name: Install Python dependencies run: poetry install --no-interaction - name: Run ${{ matrix.id }} checks run: poetry run ${{ matrix.id }} srcPython-package-vacuum-map-parser-base-0.1.5/.github/workflows/codeql.yml000066400000000000000000000013311500603166200262260ustar00rootroot00000000000000name: "CodeQL" on: push: branches: [master] pull_request: branches: [master] schedule: - cron: "21 5 * * 0" jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: fail-fast: false matrix: language: ["python"] steps: - name: Checkout repository uses: actions/checkout@v4 - name: Initialize CodeQL uses: github/codeql-action/init@v3 with: languages: ${{ matrix.language }} - name: Autobuild uses: github/codeql-action/autobuild@v3 - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3Python-package-vacuum-map-parser-base-0.1.5/.github/workflows/release.yml000066400000000000000000000021101500603166200263730ustar00rootroot00000000000000name: Publish release on: release: types: [published] jobs: build-and-publish-pypi: name: Builds and publishes release to PyPI runs-on: ubuntu-latest outputs: version: ${{ steps.vars.outputs.tag }} steps: - uses: actions/checkout@v4 - name: Set up Python 3.11 uses: actions/setup-python@v5 with: python-version: "3.11" - name: Install workflow dependencies run: | pip install -r .github/workflows/requirements.txt - name: Install dependencies run: poetry install --no-interaction - name: Set package version run: | version="${{ github.event.release.tag_name }}" version="${version,,}" version="${version#v}" poetry version --no-interaction "${version}" - name: Build package run: poetry build --no-interaction - name: Publish to PyPi env: PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} run: | poetry config pypi-token.pypi "${PYPI_TOKEN}" poetry publish --no-interaction Python-package-vacuum-map-parser-base-0.1.5/.github/workflows/requirements.txt000066400000000000000000000000271500603166200275210ustar00rootroot00000000000000pip>=23.3 poetry==1.5.1Python-package-vacuum-map-parser-base-0.1.5/.gitignore000066400000000000000000000060051500603166200226320ustar00rootroot00000000000000# Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ cover/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder .pybuilder/ target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv # For a library or package, you might want to ignore these files since the code is # intended to run in multiple environments; otherwise, check them in: # .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # poetry # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. # This is especially recommended for binary packages to ensure reproducibility, and is more # commonly ignored for libraries. # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control #poetry.lock # pdm # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. #pdm.lock # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it # in version control. # https://pdm.fming.dev/#use-with-ide .pdm.toml # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ # pytype static type analyzer .pytype/ # Cython debug symbols cython_debug/ # PyCharm # JetBrains specific template is maintained in a separate JetBrains.gitignore that can # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/Python-package-vacuum-map-parser-base-0.1.5/LICENSE000066400000000000000000000261211500603166200216500ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2023 Piotr Machowski Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.Python-package-vacuum-map-parser-base-0.1.5/README.md000066400000000000000000000126201500603166200221210ustar00rootroot00000000000000[![GitHub Latest Release][releases_shield]][latest_release] [![PyPI][pypi_releases_shield]][pypi_latest_release] [![PyPI - Downloads][pypi_downloads_shield]][pypi_downloads] [![Ko-Fi][ko_fi_shield]][ko_fi] [![buycoffee.to][buycoffee_to_shield]][buycoffee_to] [![PayPal.Me][paypal_me_shield]][paypal_me] [![Revolut.Me][revolut_me_shield]][revolut_me] [latest_release]: https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-base/releases/latest [releases_shield]: https://img.shields.io/github/release/PiotrMachowski/Python-package-vacuum-map-parser-base.svg?style=popout [pypi_latest_release]: https://pypi.org/project/vacuum-map-parser-base/ [pypi_releases_shield]: https://img.shields.io/pypi/v/vacuum-map-parser-base [pypi_downloads]: https://pepy.tech/project/vacuum-map-parser-base [pypi_downloads_shield]: https://static.pepy.tech/badge/vacuum-map-parser-base # Vacuum map parser - base Package that contains base classes that should be extended by a vacuum-specific implementation of a map parser. Available implementations: * [`vacuum-map-parser-roborock`](https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-roborock) * [`vacuum-map-parser-viomi`](https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-viomi) * [`vacuum-map-parser-roidmi`](https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-roidmi) * [`vacuum-map-parser-dreame`](https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-dreame) ## Installation ```shell pip install vacuum-map-parser-base ``` ## Support If you want to support my work with a donation you can use one of the following platforms:
Platform Payment methods Link Comment
Ko-fi
  • PayPal
  • Credit card
  • Buy Me a Coffee at ko-fi.com
  • No fees
  • Single or monthly payment
  • buycoffee.to
  • BLIK
  • Bank transfer
  • Postaw mi kawÄ™ na buycoffee.to
    PayPal
  • PayPal
  • PayPal Logo
  • No fees
  • Revolut
  • Revolut
  • Credit Card
  • Revolut
  • No fees
  • ### Powered by [![PyCharm logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSourceSupport) [ko_fi_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Ko-Fi&color=F16061&logo=ko-fi&logoColor=white [ko_fi]: https://ko-fi.com/piotrmachowski [buycoffee_to_shield]: https://shields.io/badge/buycoffee.to-white?style=flat&labelColor=white&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABhmlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpaIVh1YQcchQnayIijhKFYtgobQVWnUweemP0KQhSXFxFFwLDv4sVh1cnHV1cBUEwR8QVxcnRRcp8b6k0CLGC4/3cd49h/fuA4R6malmxzigapaRisfEbG5FDLzChxB6MIZ+iZl6Ir2QgWd93VM31V2UZ3n3/Vm9St5kgE8knmW6YRGvE09vWjrnfeIwK0kK8TnxqEEXJH7kuuzyG+eiwwLPDBuZ1BxxmFgstrHcxqxkqMRTxBFF1ShfyLqscN7irJarrHlP/sJgXltOc53WEOJYRAJJiJBRxQbKsBClXSPFRIrOYx7+QcefJJdMrg0wcsyjAhWS4wf/g9+zNQuTE25SMAZ0vtj2xzAQ2AUaNdv+PrbtxgngfwautJa/UgdmPkmvtbTIEdC3DVxctzR5D7jcAQaedMmQHMlPSygUgPcz+qYcELoFulfduTXPcfoAZGhWSzfAwSEwUqTsNY93d7XP7d+e5vx+AIahcq//o+yoAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH5wETCy4vFNqLzwAAAVpJREFUOMvd0rFLVXEYxvHPOedKJnKJhrDLuUFREULE7YDCMYj+AydpsCWiaKu29hZxiP4Al4aWwC1EdFI4Q3hqEmkIBI8ZChWXKNLLvS0/Qcza84V3enm/7/s878t/HxGkeTaIGziP+EB918nawu7Dq1d0e1+2J2bepnk2jFEUVVF+qKV51o9neBCaugfge70keoxxUbSWjrQ+4SUyzKZ5NlnDZdzGG7w4DIh+dtZEFntDA98l8S0MYwctNGrYz9WqKJePFLq80g5Sr+EHlnATp+NA+4qLaZ7FfzMrzbMBjGEdq8GrJMZnvAvFC/8wfAwjWMQ8XmMzaW9sdevNRgd3MFhvNpbaG1u/Dk2/hOc4gadVUa7Um425qii/7Z+xH9O4jwW8Cqv24Tru4hyeVEU588cfBMgpPMI9nMFe0BkFzVOYrYqycyQgQJLwTC2cDZCPeF8V5Y7jGb8BUpRicy7OU5MAAAAASUVORK5CYII= [buycoffee_to]: https://buycoffee.to/piotrmachowski [buy_me_a_coffee_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Buy%20me%20a%20coffee&color=6f4e37&logo=buy%20me%20a%20coffee&logoColor=white [buy_me_a_coffee]: https://www.buymeacoffee.com/PiotrMachowski [paypal_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=PayPal.Me&logo=paypal [paypal_me]: https://paypal.me/PiMachowski [revolut_me_shield]: https://img.shields.io/static/v1.svg?label=%20&message=Revolut&logo=revolut [revolut_me]: https://revolut.me/314ma Python-package-vacuum-map-parser-base-0.1.5/pyproject.toml000066400000000000000000000035111500603166200235550ustar00rootroot00000000000000[tool.poetry] name = "vacuum-map-parser-base" # The version is set by GH action on release version = "0.0.0" license = "Apache-2.0" description = "Common code for vacuum map parsers" readme = "README.md" authors = ["Piotr Machowski "] classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Environment :: Console", "Programming Language :: Python :: 3.11", "Topic :: Home Automation", ] packages = [ { include = "vacuum_map_parser_base", from = "src" }, ] [tool.poetry.urls] "Homepage" = "https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-base" "Repository" = "https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-base" "Bug Tracker" = "https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-base/issues" "Changelog" = "https://github.com/PiotrMachowski/Python-package-vacuum-map-parser-base/releases" [tool.poetry.dependencies] python = "^3.11" Pillow = "*" [tool.poetry.dev-dependencies] black = "*" mypy = "*" ruff = "*" isort = "*" pylint = "*" types-Pillow = "*" [tool.black] line-length = 120 [tool.isort] profile = "black" line_length = 120 [tool.mypy] platform = "linux" check_untyped_defs = true disallow_any_generics = true disallow_incomplete_defs = true disallow_subclassing_any = true disallow_untyped_calls = true disallow_untyped_defs = true disallow_untyped_decorators = true no_implicit_optional = true no_implicit_reexport = true strict_optional = true warn_incomplete_stub = true warn_no_return = true warn_redundant_casts = true warn_return_any = true warn_unused_configs = true warn_unused_ignores = true [tool.pylint] disable = ["C0103", "C0116", "R0902", "R0903", "R0913", "R0914", "W0640"] max-line-length = 120 [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" Python-package-vacuum-map-parser-base-0.1.5/src/000077500000000000000000000000001500603166200214305ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/000077500000000000000000000000001500603166200261335ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/__init__.py000066400000000000000000000001051500603166200302400ustar00rootroot00000000000000"""Basic functionalities for map parsing, common for all vacuums.""" Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/000077500000000000000000000000001500603166200274005ustar00rootroot00000000000000Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/__init__.py000066400000000000000000000000611500603166200315060ustar00rootroot00000000000000"""Package for configuration-related classes.""" Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/color.py000066400000000000000000000160031500603166200310700ustar00rootroot00000000000000"""Configuration of map colors.""" from __future__ import annotations from enum import StrEnum from random import Random from typing import TypeVar T = TypeVar("T") Color = tuple[int, int, int] | tuple[int, int, int, int] class SupportedColor(StrEnum): """Color of a supported map element.""" CARPETS = "color_carpets" CHARGER = "color_charger" CHARGER_OUTLINE = "color_charger_outline" CLEANED_AREA = "color_cleaned_area" GOTO_PATH = "color_goto_path" GREY_WALL = "color_grey_wall" IGNORED_OBSTACLE = "color_ignored_obstacle" IGNORED_OBSTACLE_WITH_PHOTO = "color_ignored_obstacle_with_photo" MAP_INSIDE = "color_map_inside" MAP_OUTSIDE = "color_map_outside" MAP_WALL = "color_map_wall" MAP_WALL_V2 = "color_map_wall_v2" MOP_PATH = "color_mop_path" NEW_DISCOVERED_AREA = "color_new_discovered_area" NO_CARPET_ZONES = "color_no_carpet_zones" NO_CARPET_ZONES_OUTLINE = "color_no_carpet_zones_outline" NO_GO_ZONES = "color_no_go_zones" NO_GO_ZONES_OUTLINE = "color_no_go_zones_outline" NO_MOPPING_ZONES = "color_no_mop_zones" NO_MOPPING_ZONES_OUTLINE = "color_no_mop_zones_outline" OBSTACLE = "color_obstacle" OBSTACLE_WITH_PHOTO = "color_obstacle_with_photo" PATH = "color_path" PREDICTED_PATH = "color_predicted_path" ROBO = "color_robo" ROBO_OUTLINE = "color_robo_outline" ROOM_NAMES = "color_room_names" SCAN = "color_scan" UNKNOWN = "color_unknown" VIRTUAL_WALLS = "color_virtual_walls" ZONES = "color_zones" ZONES_OUTLINE = "color_zones_outline" class ColorsPalette: """Container that simplifies retrieving desired color.""" COLORS: dict[SupportedColor, Color] = { SupportedColor.MAP_INSIDE: (32, 115, 185), SupportedColor.MAP_OUTSIDE: (19, 87, 148), SupportedColor.MAP_WALL: (100, 196, 254), SupportedColor.MAP_WALL_V2: (93, 109, 126), SupportedColor.GREY_WALL: (93, 109, 126), SupportedColor.CLEANED_AREA: (127, 127, 127, 127), SupportedColor.PATH: (147, 194, 238), SupportedColor.GOTO_PATH: (0, 255, 0), SupportedColor.PREDICTED_PATH: (255, 255, 0), SupportedColor.ZONES: (0xAD, 0xD8, 0xFF, 0x8F), SupportedColor.ZONES_OUTLINE: (0xAD, 0xD8, 0xFF), SupportedColor.VIRTUAL_WALLS: (255, 0, 0), SupportedColor.NEW_DISCOVERED_AREA: (64, 64, 64), SupportedColor.CARPETS: (0xA9, 0xF7, 0xA9), SupportedColor.NO_CARPET_ZONES: (255, 33, 55, 127), SupportedColor.NO_CARPET_ZONES_OUTLINE: (255, 0, 0), SupportedColor.NO_GO_ZONES: (255, 33, 55, 127), SupportedColor.NO_GO_ZONES_OUTLINE: (255, 0, 0), SupportedColor.MOP_PATH: (255, 255, 255, 0x48), SupportedColor.NO_MOPPING_ZONES: (163, 130, 211, 127), SupportedColor.NO_MOPPING_ZONES_OUTLINE: (163, 130, 211), SupportedColor.CHARGER: (0x66, 0xFE, 0xDA, 0x7F), SupportedColor.CHARGER_OUTLINE: (0x66, 0xFE, 0xDA, 0x7F), SupportedColor.ROBO: (0xFF, 0xFF, 0xFF), SupportedColor.ROBO_OUTLINE: (0, 0, 0), SupportedColor.ROOM_NAMES: (0, 0, 0), SupportedColor.OBSTACLE: (0, 0, 0, 128), SupportedColor.IGNORED_OBSTACLE: (0, 0, 0, 128), SupportedColor.OBSTACLE_WITH_PHOTO: (0, 0, 0, 128), SupportedColor.IGNORED_OBSTACLE_WITH_PHOTO: (0, 0, 0, 128), SupportedColor.UNKNOWN: (0, 0, 0), SupportedColor.SCAN: (0xDF, 0xDF, 0xDF), } ROOM_COLORS: dict[str, Color] = { "1": (240, 178, 122), "2": (133, 193, 233), "3": (217, 136, 128), "4": (52, 152, 219), "5": (205, 97, 85), "6": (243, 156, 18), "7": (88, 214, 141), "8": (245, 176, 65), "9": (252, 212, 81), "10": (72, 201, 176), "11": (84, 153, 199), "12": (133, 193, 233), "13": (245, 176, 65), "14": (82, 190, 128), "15": (72, 201, 176), "16": (165, 105, 189), "17": (240, 178, 122), "18": (133, 193, 233), "19": (217, 136, 128), "20": (52, 152, 219), "21": (205, 97, 85), "22": (243, 156, 18), "23": (88, 214, 141), "24": (245, 176, 65), "25": (252, 212, 81), "26": (72, 201, 176), "27": (84, 153, 199), "28": (133, 193, 233), "29": (245, 176, 65), "30": (82, 190, 128), "31": (72, 201, 176), "32": (165, 105, 189), } def __init__( self, colors_dict: dict[SupportedColor, Color] | None = None, room_colors: dict[str, Color] | None = None, ) -> None: self._random = Random() if colors_dict is None: self._overridden_colors = {} else: self._overridden_colors = colors_dict if room_colors is None: self._overridden_room_colors = {} else: self._overridden_room_colors = room_colors # Create it once so that it can be accessed in get_color in the future self._cached_colors: dict[SupportedColor, Color] = {} for color in self.COLORS: self.get_color(color) # Create it once so that it can be accessed in get_room_color in the future self._cached_room_colors: dict[int | str, Color] = {} for room in self.ROOM_COLORS: self.get_room_color(room) def get_color(self, color_name: SupportedColor) -> Color: if color_name not in self._cached_colors: if color_name in self._overridden_colors: val = self._overridden_colors[color_name] elif color_name in ColorsPalette.COLORS: val = ColorsPalette.COLORS[color_name] elif SupportedColor.UNKNOWN in ColorsPalette.COLORS: val = ColorsPalette.COLORS[SupportedColor.UNKNOWN] else: val = (0, 0, 0) self._cached_colors[color_name] = val return self._cached_colors[color_name] @property def cached_colors(self) -> dict[SupportedColor, Color]: return self._cached_colors def get_room_color(self, room_id: str | int) -> Color: if room_id not in self._cached_room_colors: if isinstance(room_id, str): room_id = int(room_id) if room_id > len(ColorsPalette.ROOM_COLORS): room_id = (room_id - 1) % len(ColorsPalette.ROOM_COLORS) + 1 key = str(room_id) if key in self._overridden_room_colors: val = self._overridden_room_colors[key] elif key in ColorsPalette.ROOM_COLORS: val = ColorsPalette.ROOM_COLORS[key] else: val = ColorsPalette.ROOM_COLORS.get(str(self._random.randint(1, 16)), (0, 0, 0)) # ensure we have both str and int in the dictionary so we don't have to always convert. self._cached_room_colors[str(room_id)] = val self._cached_room_colors[int(room_id)] = val return self._cached_room_colors[room_id] @property def cached_room_colors(self) -> dict[str | int, Color]: return self._cached_room_colors Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/drawable.py000066400000000000000000000013621500603166200315350ustar00rootroot00000000000000"""Configuration of elements that can be drawn on a map.""" from enum import StrEnum class Drawable(StrEnum): """Supported element of a map image.""" CHARGER = "charger" CLEANED_AREA = "cleaned_area" GOTO_PATH = "goto_path" IGNORED_OBSTACLES = "ignored_obstacles" IGNORED_OBSTACLES_WITH_PHOTO = "ignored_obstacles_with_photo" MOP_PATH = "mop_path" NO_CARPET_AREAS = "no_carpet_zones" NO_GO_AREAS = "no_go_zones" NO_MOPPING_AREAS = "no_mopping_zones" OBSTACLES = "obstacles" OBSTACLES_WITH_PHOTO = "obstacles_with_photo" PATH = "path" PREDICTED_PATH = "predicted_path" ROOM_NAMES = "room_names" VACUUM_POSITION = "vacuum_position" VIRTUAL_WALLS = "virtual_walls" ZONES = "zones" Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/image_config.py000066400000000000000000000006341500603166200323640ustar00rootroot00000000000000"""Configuration of map dimensions.""" from dataclasses import dataclass, field @dataclass class TrimConfig: """Configuration of map trimming.""" left: float = 0 right: float = 0 top: float = 0 bottom: float = 0 @dataclass class ImageConfig: """Configuration of map dimensions.""" scale: float = 1 rotate: float = 0 trim: TrimConfig = field(default_factory=TrimConfig) Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/size.py000066400000000000000000000023131500603166200307230ustar00rootroot00000000000000"""Configuration of sizes of map elements.""" from enum import StrEnum class Size(StrEnum): """Identifier of a size of a map element.""" CHARGER_RADIUS = "charger_radius" IGNORED_OBSTACLE_RADIUS = "ignored_obstacle_radius" IGNORED_OBSTACLE_WITH_PHOTO_RADIUS = "ignored_obstacle_with_photo_radius" MOP_PATH_WIDTH = "mop_path_width" OBSTACLE_RADIUS = "obstacle_radius" OBSTACLE_WITH_PHOTO_RADIUS = "obstacle_with_photo_radius" VACUUM_RADIUS = "vacuum_radius" PATH_WIDTH = "path_width" class Sizes: """Container that simplifies retrieving size of map elements.""" SIZES = { Size.VACUUM_RADIUS: 6, Size.PATH_WIDTH: 1, Size.IGNORED_OBSTACLE_RADIUS: 3, Size.IGNORED_OBSTACLE_WITH_PHOTO_RADIUS: 3, Size.MOP_PATH_WIDTH: 16, Size.OBSTACLE_RADIUS: 3, Size.OBSTACLE_WITH_PHOTO_RADIUS: 3, Size.CHARGER_RADIUS: 6, } def __init__(self, sizes: dict[Size, float] | None = None): if sizes is None: self._overriden_sizes = {} else: self._overriden_sizes = sizes def get_size(self, size: Size) -> float: return self._overriden_sizes.get(size, Sizes.SIZES.get(size, 1)) Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/config/text.py000066400000000000000000000005031500603166200307340ustar00rootroot00000000000000"""Configuration of texts displayed on the map.""" from dataclasses import dataclass from .color import Color @dataclass class Text: """Configuration of texts displayed on the map.""" text: str x: float y: float color: Color = (0, 0, 0) font: str | None = None font_size: int | None = None Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/image_generator.py000066400000000000000000000447061500603166200316500ustar00rootroot00000000000000"""Generates a map image.""" import logging import math from typing import Callable from PIL import Image, ImageDraw, ImageFont from PIL.Image import Image as ImageType from PIL.Image import Resampling, Transpose from PIL.ImageDraw import ImageDraw as ImageDrawType from .config.color import Color, ColorsPalette, SupportedColor from .config.drawable import Drawable from .config.image_config import ImageConfig from .config.size import Size, Sizes from .config.text import Text from .map_data import Area, ImageData, MapData, Obstacle, Path, Point _LOGGER = logging.getLogger(__name__) class ImageGenerator: """Generates a map image.""" def __init__( # pylint: disable=R0917 self, palette: ColorsPalette, sizes: Sizes, drawables: list[Drawable], image_config: ImageConfig, texts: list[Text], ): self._palette = palette self._sizes = sizes self._drawables = drawables self._image_config = image_config self._texts = texts def draw_map(self, map_data: MapData) -> None: if map_data.image is None: return for drawable in self._drawables: match drawable: case Drawable.CHARGER.value: self._draw_charger(map_data) case Drawable.VACUUM_POSITION.value: self._draw_vacuum_position(map_data) case Drawable.OBSTACLES.value: self._draw_obstacles(map_data) case Drawable.IGNORED_OBSTACLES.value: self._draw_ignored_obstacles(map_data) case Drawable.OBSTACLES_WITH_PHOTO.value: self._draw_obstacles_with_photo(map_data) case Drawable.IGNORED_OBSTACLES_WITH_PHOTO.value: self._draw_ignored_obstacles_with_photo(map_data) case Drawable.MOP_PATH.value: self._draw_mop_path(map_data) case Drawable.PATH.value: self._draw_vacuum_path(map_data) case Drawable.GOTO_PATH.value: self._draw_goto_path(map_data) case Drawable.PREDICTED_PATH.value: self._draw_predicted_path(map_data) case Drawable.NO_CARPET_AREAS.value: self._draw_no_carpet_areas(map_data) case Drawable.NO_GO_AREAS.value: self._draw_no_go_areas(map_data) case Drawable.NO_MOPPING_AREAS.value: self._draw_no_mopping_areas(map_data) case Drawable.VIRTUAL_WALLS.value: self._draw_walls(map_data) case Drawable.ZONES.value: self._draw_zones(map_data) case Drawable.CLEANED_AREA.value: self._draw_layer(map_data, drawable) case Drawable.ROOM_NAMES.value: self._draw_room_names(map_data) self._rotate(map_data.image) self._draw_texts(map_data.image, self._texts) def create_empty_map_image(self, text: str = "NO MAP") -> ImageType: color = self._get_color(SupportedColor.MAP_OUTSIDE) image = Image.new("RGBA", (300, 200), color=color) if sum(color[0:3]) > 382: text_color = (0, 0, 0) else: text_color = (255, 255, 255) draw = ImageDraw.Draw(image, "RGBA") l, t, r, b = draw.textbbox((0, 0), text) w, h = r - l, b - t draw.text(((image.size[0] - w) / 2, (image.size[1] - h) / 2), text, fill=text_color) return image def _draw_vacuum_path(self, map_data: MapData) -> None: if map_data.path is not None and map_data.image is not None: self._draw_path( map_data.image, map_data.path, self._get_size(Size.PATH_WIDTH), self._get_color(SupportedColor.PATH), ) def _draw_goto_path(self, map_data: MapData) -> None: if map_data.goto_path is not None and map_data.image is not None: self._draw_path( map_data.image, map_data.goto_path, self._get_size(Size.PATH_WIDTH), self._get_color(SupportedColor.GOTO_PATH), ) def _draw_predicted_path(self, map_data: MapData) -> None: if map_data.predicted_path is not None and map_data.image is not None: self._draw_path( map_data.image, map_data.predicted_path, self._get_size(Size.PATH_WIDTH), self._get_color(SupportedColor.PREDICTED_PATH), ) def _draw_mop_path(self, map_data: MapData) -> None: if map_data.mop_path is not None and map_data.image is not None: self._draw_path( map_data.image, map_data.mop_path, self._get_size(Size.MOP_PATH_WIDTH), self._get_color(SupportedColor.MOP_PATH), ) def _draw_no_carpet_areas(self, map_data: MapData) -> None: if map_data.no_carpet_areas is not None and map_data.image is not None: ImageGenerator._draw_areas( map_data.image, map_data.no_carpet_areas, self._get_color(SupportedColor.NO_CARPET_ZONES), self._get_color(SupportedColor.NO_CARPET_ZONES_OUTLINE), ) def _draw_no_go_areas(self, map_data: MapData) -> None: if map_data.no_go_areas is not None and map_data.image is not None: ImageGenerator._draw_areas( map_data.image, map_data.no_go_areas, self._get_color(SupportedColor.NO_GO_ZONES), self._get_color(SupportedColor.NO_GO_ZONES_OUTLINE), ) def _draw_no_mopping_areas(self, map_data: MapData) -> None: if map_data.no_mopping_areas is not None and map_data.image is not None: ImageGenerator._draw_areas( map_data.image, map_data.no_mopping_areas, self._get_color(SupportedColor.NO_MOPPING_ZONES), self._get_color(SupportedColor.NO_MOPPING_ZONES_OUTLINE), ) def _draw_walls(self, map_data: MapData) -> None: if map_data.walls is None or map_data.image is None: return image = map_data.image walls = map_data.walls color = self._get_color(SupportedColor.VIRTUAL_WALLS) def draw_func(draw: ImageDrawType) -> None: for wall in walls: draw.line(wall.to_img(image.dimensions).as_list(), color, width=2) ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(color)) def _draw_zones(self, map_data: MapData) -> None: if map_data.zones is None or map_data.image is None: return ImageGenerator._draw_areas( map_data.image, [z.as_area() for z in map_data.zones], self._get_color(SupportedColor.ZONES), self._get_color(SupportedColor.ZONES_OUTLINE), ) def _draw_charger(self, map_data: MapData) -> None: if map_data.charger is None or map_data.image is None: return fill = self._get_color(SupportedColor.CHARGER) outline = self._get_color(SupportedColor.CHARGER_OUTLINE) radius = self._get_size(Size.CHARGER_RADIUS) ImageGenerator._draw_pieslice(map_data.image, map_data.charger, radius, outline, fill) def _draw_obstacles(self, map_data: MapData) -> None: if map_data.obstacles is None or map_data.image is None: return color = self._get_color(SupportedColor.OBSTACLE) radius = self._get_size(Size.OBSTACLE_RADIUS) ImageGenerator._draw_all_obstacles(map_data.image, map_data.obstacles, radius, color) def _draw_ignored_obstacles(self, map_data: MapData) -> None: if map_data.ignored_obstacles is None or map_data.image is None: return color = self._get_color(SupportedColor.IGNORED_OBSTACLE) radius = self._get_size(Size.IGNORED_OBSTACLE_RADIUS) ImageGenerator._draw_all_obstacles(map_data.image, map_data.ignored_obstacles, radius, color) def _draw_obstacles_with_photo(self, map_data: MapData) -> None: if map_data.obstacles_with_photo is None or map_data.image is None: return color = self._get_color(SupportedColor.OBSTACLE_WITH_PHOTO) radius = self._get_size(Size.OBSTACLE_WITH_PHOTO_RADIUS) ImageGenerator._draw_all_obstacles(map_data.image, map_data.obstacles_with_photo, radius, color) def _draw_ignored_obstacles_with_photo(self, map_data: MapData) -> None: if map_data.ignored_obstacles_with_photo is None or map_data.image is None: return color = self._get_color(SupportedColor.IGNORED_OBSTACLE_WITH_PHOTO) radius = self._get_size(Size.IGNORED_OBSTACLE_WITH_PHOTO_RADIUS) ImageGenerator._draw_all_obstacles(map_data.image, map_data.ignored_obstacles_with_photo, radius, color) def _draw_vacuum_position(self, map_data: MapData) -> None: if map_data.vacuum_position is None or map_data.image is None: return color = self._get_color(SupportedColor.ROBO) outline = self._get_color(SupportedColor.ROBO_OUTLINE) radius = self._get_size(Size.VACUUM_RADIUS) ImageGenerator._draw_vacuum(map_data.image, map_data.vacuum_position, radius, outline, color) def _draw_room_names(self, map_data: MapData) -> None: if map_data.rooms is None or map_data.image is None: return color = self._get_color(SupportedColor.ROOM_NAMES) for room in map_data.rooms.values(): p = room.point() if p is not None and room.name is not None: point = p.to_img(map_data.image.dimensions) self._draw_text(image=map_data.image, text=room.name, x=point.x, y=point.y, color=color) def _rotate(self, image: ImageData) -> None: if image.dimensions.rotation == 0: return if image.dimensions.rotation == 90: image.data = image.data.transpose(Transpose.ROTATE_90) elif image.dimensions.rotation == 180: image.data = image.data.transpose(Transpose.ROTATE_180) elif image.dimensions.rotation == 270: image.data = image.data.transpose(Transpose.ROTATE_270) else: image.data = image.data.rotate( image.dimensions.rotation, Resampling.BILINEAR, True, fillcolor=self._get_color(SupportedColor.MAP_OUTSIDE), ) @staticmethod def _draw_texts(image: ImageData, texts: list[Text]) -> None: for text_config in texts: x = text_config.x * image.data.size[0] / 100 y = text_config.y * image.data.size[1] / 100 ImageGenerator._draw_text( image=image, text=text_config.text, x=x, y=y, color=text_config.color, font_file=text_config.font, font_size=text_config.font_size, ) @staticmethod def _draw_layer(map_data: MapData, layer_name: str) -> None: if map_data.image is not None and layer_name in map_data.image.additional_layers: ImageGenerator._draw_layer_with_alpha(map_data.image, map_data.image.additional_layers[layer_name]) @staticmethod def _draw_all_obstacles(image: ImageData, obstacles: list[Obstacle], radius: float, color: Color) -> None: for obstacle in obstacles: ImageGenerator._draw_circle(image, obstacle, radius, color, color) def _get_color(self, name: SupportedColor) -> Color: return self._palette.get_color(name) def _get_room_color(self, index: int) -> Color: return self._palette.get_room_color(index + 1) def _get_size(self, size: Size) -> float: return self._sizes.get_size(size) @staticmethod def _use_transparency(*colors: Color) -> bool: return any(len(color) > 3 for color in colors) @staticmethod def _draw_vacuum(image: ImageData, vacuum_pos: Point, r: float, outline: Color, fill: Color) -> None: def draw_func(draw: ImageDrawType) -> None: if vacuum_pos.a is None: vacuum_pos.a = 0 point = vacuum_pos.to_img(image.dimensions) r_scaled = r / 16 # main outline coords = [point.x - r, point.y - r, point.x + r, point.y + r] draw.ellipse(coords, outline=outline, fill=fill) if r >= 8: # secondary outline r2 = r_scaled * 14 x = point.x y = point.y coords = [x - r2, y - r2, x + r2, y + r2] draw.ellipse(coords, outline=outline) # bin cover a1 = (vacuum_pos.a + 104) / 180 * math.pi a2 = (vacuum_pos.a - 104) / 180 * math.pi r2 = r_scaled * 13 x1 = point.x - r2 * math.cos(a1) y1 = point.y + r2 * math.sin(a1) x2 = point.x - r2 * math.cos(a2) y2 = point.y + r2 * math.sin(a2) draw.line([x1, y1, x2, y2], width=1, fill=outline) # lidar angle = vacuum_pos.a / 180 * math.pi r2 = r_scaled * 3 x = point.x + r2 * math.cos(angle) y = point.y - r2 * math.sin(angle) r2 = r_scaled * 4 coords = [x - r2, y - r2, x + r2, y + r2] draw.ellipse(coords, outline=outline, fill=fill) # button half_color = ( (outline[0] + fill[0]) // 2, (outline[1] + fill[1]) // 2, (outline[2] + fill[2]) // 2, ) r2 = r_scaled * 10 x = point.x + r2 * math.cos(angle) y = point.y - r2 * math.sin(angle) r2 = r_scaled * 2 coords = [x - r2, y - r2, x + r2, y + r2] draw.ellipse(coords, outline=half_color, fill=half_color) ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(outline, fill)) @staticmethod def _draw_circle(image: ImageData, center: Point, r: float, outline: Color, fill: Color) -> None: def draw_func(draw: ImageDrawType) -> None: point = center.to_img(image.dimensions) coords = [point.x - r, point.y - r, point.x + r, point.y + r] draw.ellipse(coords, outline=outline, fill=fill) ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(outline, fill)) @staticmethod def _draw_pieslice(image: ImageData, position: Point, r: float, outline: Color, fill: Color) -> None: def draw_func(draw: ImageDrawType) -> None: point = position.to_img(image.dimensions) angle = -position.a if position.a is not None else 0 coords = (point.x - r, point.y - r), (point.x + r, point.y + r) draw.pieslice(coords, angle + 90, angle - 90, outline=outline, fill=fill) ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(outline, fill)) @staticmethod def _draw_areas(image: ImageData, areas: list[Area], fill: Color, outline: Color) -> None: if len(areas) == 0: return use_transparency = ImageGenerator._use_transparency(outline, fill) for area in areas: polygon = area.to_img(image.dimensions).as_list() def draw_func(draw: ImageDrawType) -> None: draw.polygon(polygon, fill, outline) ImageGenerator._draw_on_new_layer(image, draw_func, use_transparency) def _draw_path(self, image: ImageData, path: Path, path_width: float, color: Color) -> None: if len(path.path) < 1: return def draw_func(draw: ImageDrawType) -> None: for current_path in path.path: if len(current_path) > 1: s = current_path[0].to_img(image.dimensions) coords = None for point in current_path[1:]: e = point.to_img(image.dimensions) draw.line( [s.x, s.y, e.x, e.y], width=int(path_width), fill=color, ) if path_width > 4: r = path_width / 2 if not coords: coords = (s.x - r, s.y - r), (s.x + r, s.y + r) draw.pieslice(coords, 0, 360, outline=color, fill=color) coords = (e.x - r, e.y - r), (e.x + r, e.y + r) draw.pieslice(coords, 0, 360, outline=color, fill=color) s = e ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(color)) @staticmethod def _draw_text( *, image: ImageData, text: str, x: float, y: float, color: Color, font_file: str | None = None, font_size: int | None = None, ) -> None: def draw_func(draw: ImageDrawType) -> None: font = None try: if font_file is not None and font_size is not None and font_size > 0: font = ImageFont.truetype(font_file, font_size) except OSError: _LOGGER.warning("Unable to find font file: %s", font_file) except ImportError: _LOGGER.warning("Unable to open font: %s", font_file) finally: l, t, r, b = draw.textbbox((0, 0), text, font) w, h = r - l, b - t draw.text((x - w / 2, y - h / 2), text, font=font, fill=color) ImageGenerator._draw_on_new_layer(image, draw_func, ImageGenerator._use_transparency(color)) @staticmethod def _draw_on_new_layer( image: ImageData, draw_function: Callable[[ImageDrawType], None], use_transparency: bool = False, ) -> None: if not use_transparency: draw = ImageDraw.Draw(image.data, "RGBA") draw_function(draw) else: layer = Image.new("RGBA", image.data.size, (255, 255, 255, 0)) draw = ImageDraw.Draw(layer, "RGBA") draw_function(draw) ImageGenerator._draw_layer_with_alpha(image, layer) @staticmethod def _draw_layer_with_alpha(image: ImageData, layer: ImageType) -> None: image.data = Image.alpha_composite(image.data, layer) Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/map_data.py000066400000000000000000000216431500603166200302610ustar00rootroot00000000000000"""Contains classes that are returned as a result of parsing.""" from __future__ import annotations import math from abc import ABC from dataclasses import asdict, dataclass from typing import Any, Callable from PIL.Image import Image as ImageType from .config.image_config import ImageConfig CalibrationPoints = list[dict[str, dict[str, float | int]]] @dataclass class OutputObject(ABC): """Base class for parsing outcomes.""" def as_dict(self) -> dict[str, Any]: return {k: v for k, v in asdict(self).items() if v is not None} @dataclass class Point(OutputObject): """Point on a map.""" x: float y: float a: float | None = None def to_img(self, image_dimensions: ImageDimensions) -> Point: return image_dimensions.to_img(self) def rotated(self, image_dimensions: ImageDimensions) -> Point: alpha = image_dimensions.rotation w = int(image_dimensions.width * image_dimensions.scale) h = int(image_dimensions.height * image_dimensions.scale) x = self.x y = self.y if alpha % 90 == 0: while alpha > 0: (x, y) = (y, w - x) (h, w) = (w, h) alpha = alpha - 90 return Point(x, y) xm = w / 2 ym = h / 2 a = math.radians(alpha) wr = math.fabs(w * math.cos(a)) + math.fabs(h * math.sin(a)) hr = math.fabs(w * math.sin(a)) + math.fabs(h * math.cos(a)) xr = (x - xm) * math.cos(a) + (y - ym) * math.sin(a) + wr / 2 yr = -(x - xm) * math.sin(a) + (y - ym) * math.cos(a) + hr / 2 return Point(xr, yr) def __mul__(self, other: float) -> Point: return Point(self.x * other, self.y * other, self.a) def __truediv__(self, other: float) -> Point: return Point(self.x / other, self.y / other, self.a) @dataclass class Obstacle(Point): """Obstacle on a map.""" def __init__(self, x: float, y: float, details: ObstacleDetails): super().__init__(x, y) self.details = details def as_dict(self) -> dict[str, Any]: return {**super().as_dict(), **self.details.as_dict()} @dataclass class ObstacleDetails(OutputObject): """Metadata of an obstacle.""" type: int | None = None description: str | None = None confidence_level: float | None = None photo_name: str | None = None @dataclass class ImageDimensions: """Dimensions of an image.""" top: int left: int height: int width: int scale: float rotation: float img_transformation: Callable[[Point], Point] def to_img(self, point: Point) -> Point: p = self.img_transformation(point) return Point( (p.x - self.left) * self.scale, (self.height - (p.y - self.top) - 1) * self.scale, ) class ImageData(OutputObject): """Image data.""" def __init__( # pylint: disable=R0917 self, size: int, top: int, left: int, height: int, width: int, image_config: ImageConfig, data: ImageType, img_transformation: Callable[[Point], Point], additional_layers: dict[str, ImageType | None] | None = None, ): trim_left = int(image_config.trim.left * width / 100) trim_right = int(image_config.trim.right * width / 100) trim_top = int(image_config.trim.top * height / 100) trim_bottom = int(image_config.trim.bottom * height / 100) scale = image_config.scale rotation = image_config.rotate self.size = size self.dimensions = ImageDimensions( top + trim_bottom, left + trim_left, height - trim_top - trim_bottom, width - trim_left - trim_right, scale, rotation, img_transformation, ) self.is_empty = height == 0 or width == 0 self.data = data self.additional_layers: dict[str, ImageType] = ( {} if additional_layers is None else {name: layer for name, layer in additional_layers.items() if layer is not None} ) def as_dict(self) -> dict[str, Any]: return { "size": self.size, "offset_y": self.dimensions.top, "offset_x": self.dimensions.left, "height": self.dimensions.height, "scale": self.dimensions.scale, "rotation": self.dimensions.rotation, "width": self.dimensions.width, } @staticmethod def create_empty(data: ImageType) -> ImageData: return ImageData(0, 0, 0, 0, 0, ImageConfig(), data, lambda p: p) @dataclass class Path(OutputObject): """Path on a map.""" point_length: int | None point_size: int | None angle: int | None path: list[list[Point]] def as_dict(self) -> dict[str, Any]: return { **super().as_dict(), "path": [[p.as_dict() for p in subpath] for subpath in self.path], } @dataclass class Zone(OutputObject): """Zone on a map.""" x0: float y0: float x1: float y1: float def as_area(self) -> Area: return Area(self.x0, self.y0, self.x0, self.y1, self.x1, self.y1, self.x1, self.y0) @dataclass class Room(Zone): """Room on a map.""" number: int name: str | None = None pos_x: float | None = None pos_y: float | None = None def point(self) -> Point | None: if self.pos_x is not None and self.pos_y is not None and self.name is not None: return Point(self.pos_x, self.pos_y) return None @dataclass class Wall(OutputObject): """Wall on a map.""" x0: float y0: float x1: float y1: float def to_img(self, image_dimensions: ImageDimensions) -> Wall: p0 = Point(self.x0, self.y0).to_img(image_dimensions) p1 = Point(self.x1, self.y1).to_img(image_dimensions) return Wall(p0.x, p0.y, p1.x, p1.y) def as_list(self) -> list[float]: return [self.x0, self.y0, self.x1, self.y1] @dataclass class Area(OutputObject): """Area on a map.""" x0: float y0: float x1: float y1: float x2: float y2: float x3: float y3: float def as_list(self) -> list[float]: return [self.x0, self.y0, self.x1, self.y1, self.x2, self.y2, self.x3, self.y3] def to_img(self, image_dimensions: ImageDimensions) -> Area: p0 = Point(self.x0, self.y0).to_img(image_dimensions) p1 = Point(self.x1, self.y1).to_img(image_dimensions) p2 = Point(self.x2, self.y2).to_img(image_dimensions) p3 = Point(self.x3, self.y3).to_img(image_dimensions) return Area(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y) class MapData: """Parsed map data.""" def __init__(self, calibration_center: float = 0, calibration_diff: float = 0): self._calibration_center = calibration_center self._calibration_diff = calibration_diff self.blocks: bytes | None = None self.charger: Point | None = None self.goto: Point | None = None self.goto_path: Path | None = None self.image: ImageData | None = None self.no_go_areas: list[Area] | None = None self.no_mopping_areas: list[Area] | None = None self.no_carpet_areas: list[Area] | None = None self.carpet_map: set[int] | None = set() self.obstacles: list[Obstacle] | None = None self.ignored_obstacles: list[Obstacle] | None = None self.obstacles_with_photo: list[Obstacle] | None = None self.ignored_obstacles_with_photo: list[Obstacle] | None = None self.path: Path | None = None self.predicted_path: Path | None = None self.mop_path: Path | None = None self.rooms: dict[int, Room] | None = None self.vacuum_position: Point | None = None self.vacuum_room: int | None = None self.vacuum_room_name: str | None = None self.walls: list[Wall] | None = None self.zones: list[Zone] | None = None self.cleaned_rooms: set[int] | None = None self.map_name: str | None = None self.additional_parameters: dict[str, Any] = {} def calibration(self) -> CalibrationPoints | None: if self.image is None or self.image.is_empty: return None calibration_points = [] for point in [ Point(self._calibration_center, self._calibration_center), Point( self._calibration_center + self._calibration_diff * 10, self._calibration_center, ), Point( self._calibration_center, self._calibration_center + self._calibration_diff * 10, ), ]: img_point = point.to_img(self.image.dimensions).rotated(self.image.dimensions) calibration_points.append( { "vacuum": {"x": point.x, "y": point.y}, "map": {"x": img_point.x, "y": img_point.y}, } ) return calibration_points Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/map_data_parser.py000066400000000000000000000025451500603166200316350ustar00rootroot00000000000000"""Base class for a map parser.""" import logging from abc import ABC, abstractmethod from typing import Any from .config.color import ColorsPalette from .config.drawable import Drawable from .config.image_config import ImageConfig from .config.size import Sizes from .config.text import Text from .image_generator import ImageGenerator from .map_data import ImageData, MapData _LOGGER = logging.getLogger(__name__) class MapDataParser(ABC): """Base class for a map parser.""" def __init__( # pylint: disable=R0917 self, palette: ColorsPalette, sizes: Sizes, drawables: list[Drawable], image_config: ImageConfig, texts: list[Text], ): self._palette = palette self._sizes = sizes self._image_config = image_config self._texts = texts self._image_generator = ImageGenerator(palette, sizes, drawables, image_config, texts) def create_empty(self, text: str) -> MapData: map_data = MapData() empty_map = self._image_generator.create_empty_map_image(text) map_data.image = ImageData.create_empty(empty_map) return map_data @abstractmethod def parse(self, raw: bytes, *args: Any, **kwargs: Any) -> MapData: pass @abstractmethod def unpack_map(self, raw_encoded: bytes, *args: Any, **kwargs: Any) -> bytes: pass Python-package-vacuum-map-parser-base-0.1.5/src/vacuum_map_parser_base/py.typed000066400000000000000000000000001500603166200276200ustar00rootroot00000000000000