From b91d5ff62a8932fcaa431b69e2477873f8884c6a Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 21 Sep 2024 00:21:00 +0200 Subject: [PATCH 1/2] Show battery level of PiSugar when PiSugar support is enabled --- inkycal/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/inkycal/main.py b/inkycal/main.py index 62380828..52e738f8 100644 --- a/inkycal/main.py +++ b/inkycal/main.py @@ -345,8 +345,12 @@ async def run(self, run_once=False): logger.info("All images generated successfully!") del errors - if self.battery_capacity < 20: - self.info += "Low battery! " + if self.use_pi_sugar: + self.battery_capacity = self.pisugar.get_battery() or 0 + if self.battery_capacity < 20: + self.info += f"Low battery! ({self.battery_capacity})% " + else: + self.info += f"Battery: {self.battery_capacity}% " # Assemble image from each module - add info section if specified self._assemble() From a3f4a186545657f133ca1614b48ff46013308493 Mon Sep 17 00:00:00 2001 From: Ace Date: Sat, 21 Sep 2024 00:21:55 +0200 Subject: [PATCH 2/2] Use .show instead of extra preview function --- inkycal/modules/inky_image.py | 16 ---------------- tests/test_inkycal_agenda.py | 3 +-- tests/test_inkycal_calendar.py | 3 +-- tests/test_inkycal_feeds.py | 3 +-- tests/test_inkycal_image.py | 3 +-- tests/test_inkycal_jokes.py | 3 +-- tests/test_inkycal_slideshow.py | 9 ++++----- tests/test_inkycal_textfile_to_display.py | 3 +-- tests/test_inkycal_tindie.py | 3 +-- tests/test_inkycal_todoist.py | 4 ++-- tests/test_inkycal_weather.py | 1 - tests/test_inkycal_webshot.py | 3 +-- 12 files changed, 14 insertions(+), 40 deletions(-) diff --git a/inkycal/modules/inky_image.py b/inkycal/modules/inky_image.py index 5795f0e4..7d0bd572 100755 --- a/inkycal/modules/inky_image.py +++ b/inkycal/modules/inky_image.py @@ -71,22 +71,6 @@ def clear(self): self.image = None logger.info("cleared previous image") - def _preview(self): - """Preview the image on gpicview (only works on Rapsbian with Desktop)""" - if self._image_loaded(): - path = "/home/pi/Desktop/" - self.image.save(path + "temp.png") - os.system("gpicview " + path + "temp.png") - os.system("rm " + path + "temp.png") - - @staticmethod - def preview(image): - """Previews an image on gpicview (only works on Rapsbian with Desktop).""" - path = "~/temp" - image.save(path + "/temp.png") - os.system("gpicview " + path + "/temp.png") - os.system("rm " + path + "/temp.png") - def _image_loaded(self): """returns True if image was loaded""" if self.image: diff --git a/tests/test_inkycal_agenda.py b/tests/test_inkycal_agenda.py index 685bb860..8758fd20 100755 --- a/tests/test_inkycal_agenda.py +++ b/tests/test_inkycal_agenda.py @@ -8,7 +8,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge logger = logging.getLogger(__name__) @@ -72,4 +71,4 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_calendar.py b/tests/test_inkycal_calendar.py index 434d5d83..7d62beba 100755 --- a/tests/test_inkycal_calendar.py +++ b/tests/test_inkycal_calendar.py @@ -8,7 +8,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge sample_url = Config.SAMPLE_ICAL_URL @@ -77,4 +76,4 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() print('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_feeds.py b/tests/test_inkycal_feeds.py index ccf44810..f88435e4 100755 --- a/tests/test_inkycal_feeds.py +++ b/tests/test_inkycal_feeds.py @@ -7,7 +7,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge logger = logging.getLogger(__name__) @@ -53,5 +52,5 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_image.py b/tests/test_inkycal_image.py index 9e72b098..1c6c80bf 100755 --- a/tests/test_inkycal_image.py +++ b/tests/test_inkycal_image.py @@ -11,7 +11,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge url ="https://raw.githubusercontent.com/aceinnolab/Inkycal/assets/tests/Inkycal_cover.png" @@ -113,4 +112,4 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_jokes.py b/tests/test_inkycal_jokes.py index a4455eff..790e107d 100755 --- a/tests/test_inkycal_jokes.py +++ b/tests/test_inkycal_jokes.py @@ -8,7 +8,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge logger = logging.getLogger(__name__) @@ -57,4 +56,4 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_slideshow.py b/tests/test_inkycal_slideshow.py index 9c811b96..ee6a7b9b 100755 --- a/tests/test_inkycal_slideshow.py +++ b/tests/test_inkycal_slideshow.py @@ -12,7 +12,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge if not os.path.exists("tmp"): @@ -144,21 +143,21 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() def test_switch_to_next_image(self): logger.info(f'testing switching to next images..') module = Slideshow(tests[0]) im_black, im_colour = module.generate_image() if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() im_black, im_colour = module.generate_image() if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() im_black, im_colour = module.generate_image() if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() logger.info('OK') diff --git a/tests/test_inkycal_textfile_to_display.py b/tests/test_inkycal_textfile_to_display.py index 7c99f8e9..05458090 100644 --- a/tests/test_inkycal_textfile_to_display.py +++ b/tests/test_inkycal_textfile_to_display.py @@ -10,7 +10,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge logger = logging.getLogger(__name__) @@ -100,7 +99,7 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() def tearDown(self): if os.path.exists(self.temp_path): diff --git a/tests/test_inkycal_tindie.py b/tests/test_inkycal_tindie.py index ff9389c0..f2e3eaf7 100755 --- a/tests/test_inkycal_tindie.py +++ b/tests/test_inkycal_tindie.py @@ -8,7 +8,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge logger = logging.getLogger(__name__) @@ -69,4 +68,4 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() logger.info('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() diff --git a/tests/test_inkycal_todoist.py b/tests/test_inkycal_todoist.py index 44c3041d..ac208cee 100644 --- a/tests/test_inkycal_todoist.py +++ b/tests/test_inkycal_todoist.py @@ -8,7 +8,7 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview + merge = Inkyimage.merge api_key = Config.TODOIST_API_KEY @@ -42,6 +42,6 @@ def test_generate_image(self): im_black, im_colour = module.generate_image() print('OK') if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() else: print('No api key given, omitting test') diff --git a/tests/test_inkycal_weather.py b/tests/test_inkycal_weather.py index dce32977..d512d88e 100755 --- a/tests/test_inkycal_weather.py +++ b/tests/test_inkycal_weather.py @@ -8,7 +8,6 @@ from inkycal.modules.inky_image import Inkyimage from tests import Config -preview = Inkyimage.preview merge = Inkyimage.merge owm_api_key = Config.OPENWEATHERMAP_API_KEY diff --git a/tests/test_inkycal_webshot.py b/tests/test_inkycal_webshot.py index 073a437a..a75c603f 100755 --- a/tests/test_inkycal_webshot.py +++ b/tests/test_inkycal_webshot.py @@ -12,7 +12,6 @@ logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG) -preview = Inkyimage.preview merge = Inkyimage.merge tests = [ @@ -70,5 +69,5 @@ def test_generate_image(self): module = Webshot(test) im_black, im_colour = module.generate_image() if Config.USE_PREVIEW: - preview(merge(im_black, im_colour)) + merge(im_black, im_colour).show() logger.info('OK')