Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#378 #380

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions inkycal/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 0 additions & 16 deletions inkycal/modules/inky_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tests/test_inkycal_agenda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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()
3 changes: 1 addition & 2 deletions tests/test_inkycal_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
3 changes: 1 addition & 2 deletions tests/test_inkycal_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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()

3 changes: 1 addition & 2 deletions tests/test_inkycal_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
3 changes: 1 addition & 2 deletions tests/test_inkycal_jokes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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()
9 changes: 4 additions & 5 deletions tests/test_inkycal_slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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')
3 changes: 1 addition & 2 deletions tests/test_inkycal_textfile_to_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_inkycal_tindie.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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()
4 changes: 2 additions & 2 deletions tests/test_inkycal_todoist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
1 change: 0 additions & 1 deletion tests/test_inkycal_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/test_inkycal_webshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

preview = Inkyimage.preview
merge = Inkyimage.merge

tests = [
Expand Down Expand Up @@ -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')