diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d4f131..cfaf592 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - No unreleased changes so far +## [0.12.0] - 2021-07-05 +### Added +- Possibility to retrieve images and save attributes to files on disk + ## [0.11.1] - 2021-07-03 ### Fixed - Addressing of statuses @@ -130,7 +134,8 @@ Minor fix in observer interface ## [0.1.0] - 2021-05-26 Initial release -[unreleased]: https://github.com/tillsteinbach/WeConnect-python/compare/v0.11.1...HEAD +[unreleased]: https://github.com/tillsteinbach/WeConnect-python/compare/v0.12.0...HEAD +[0.12.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.12.0 [0.11.1]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.11.1 [0.11.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.11.0 [0.10.0]: https://github.com/tillsteinbach/WeConnect-python/releases/tag/v0.10.0 diff --git a/requirements.txt b/requirements.txt index b7ec5aa..accc948 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -requests>=2.23.0 \ No newline at end of file +requests>=2.23.0 +pillow>=8.3.0 +ascii_magic>=1.5.5 \ No newline at end of file diff --git a/weconnect/addressable.py b/weconnect/addressable.py index 0fc5335..1b253a9 100644 --- a/weconnect/addressable.py +++ b/weconnect/addressable.py @@ -3,7 +3,10 @@ from enum import Enum, IntEnum, Flag, auto from typing import Dict, List -from .util import toBool +from PIL import Image +import ascii_magic + +from .util import toBool, imgToASCIIArt LOG = logging.getLogger("weconnect") @@ -181,11 +184,47 @@ def isLeaf(self): # pylint: disable=R0201 def getLeafChildren(self): return [self] + def saveToFile(self, filename): + if filename.endswith(('.txt', '.TXT', '.text')): + with open(filename, mode='w') as file: + if self.valueType == Image.Image: + file.write(imgToASCIIArt(self.value, columns=120, mode=ascii_magic.Modes.ASCII)) + else: + file.write(str(self)) + elif filename.endswith(('.htm', '.HTM', '.html', '.HTML')): + with open(filename, mode='w') as file: + if self.valueType == Image.Image: + html = """
""" + file.write(html) + file.write(imgToASCIIArt(self.value, columns=240, mode=ascii_magic.Modes.HTML)) + file.write('