diff --git a/custom_components/open_epaper_link/camera.py b/custom_components/open_epaper_link/camera.py index be82dd4..16be449 100644 --- a/custom_components/open_epaper_link/camera.py +++ b/custom_components/open_epaper_link/camera.py @@ -1,5 +1,6 @@ from __future__ import annotations from .const import DOMAIN +from .util import get_image_path import logging import datetime import mimetypes @@ -22,7 +23,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): new_devices = [] for esls in hub.esls: if hub.data[esls]["lqi"] != 100 or hub.data[esls]["rssi"] != 100: - camera = LocalFile(esls, "/config/www/open_epaper_link/open_epaper_link."+ str(esls).lower() + ".jpg", hub) + camera = LocalFile(esls, get_image_path(hass, "open_epaper_link." + str(esls).lower()), hub) new_devices.append(camera) async_add_entities(new_devices,True) @@ -49,7 +50,7 @@ def device_info(self) -> DeviceInfo: @property def name(self): return self._name - + def camera_image( self, width: int | None = None, height: int | None = None ) -> bytes | None: @@ -65,7 +66,7 @@ def camera_image( def check_file_path_access(self, file_path): """Check that filepath given is readable.""" - + def update_file_path(self, file_path): self._file_path = file_path self.schedule_update_ha_state() diff --git a/custom_components/open_epaper_link/imagegen.py b/custom_components/open_epaper_link/imagegen.py index 2d9db7a..447d457 100644 --- a/custom_components/open_epaper_link/imagegen.py +++ b/custom_components/open_epaper_link/imagegen.py @@ -11,6 +11,7 @@ import asyncio import time from .const import DOMAIN +from .util import get_image_folder, get_image_path from PIL import Image, ImageDraw, ImageFont from requests_toolbelt.multipart.encoder import MultipartEncoder from homeassistant.exceptions import HomeAssistantError @@ -447,8 +448,8 @@ def customimage(entity_id, service, hass): img = img.rotate(rotate, expand=True) rgb_image = img.convert('RGB') patha = os.path.join(os.path.dirname(__file__), entity_id + '.jpg') - pathb = os.path.join("/config/www/open_epaper_link", str(entity_id).lower() + '.jpg') - pathc = "/config/www/open_epaper_link" + pathb = get_image_path(hass, entity_id) + pathc = get_image_folder(hass) isExist = os.path.exists(pathc) if not isExist: os.makedirs(pathc) diff --git a/custom_components/open_epaper_link/manifest.json b/custom_components/open_epaper_link/manifest.json index 33cf802..0221dfe 100644 --- a/custom_components/open_epaper_link/manifest.json +++ b/custom_components/open_epaper_link/manifest.json @@ -1,13 +1,21 @@ { "domain": "open_epaper_link", "name": "OpenEPaperLink", - "codeowners": ["@jonasniesner"], + "codeowners": [ + "@jonasniesner" + ], "config_flow": true, - "dependencies": ["recorder"], + "dependencies": [ + "recorder" + ], "documentation": "https://github.com/jonasniesner/open_epaper_link_homeassistant", "integration_type": "hub", "iot_class": "local_push", "issue_tracker": "https://github.com/jonasniesner/open_epaper_link_homeassistant/issues", - "requirements": ["qrcode[pil]"], + "requirements": [ + "qrcode[pil]==7.4.2", + "requests_toolbelt==1.0.0", + "websocket-client==1.7.0" + ], "version": "0.1.4" -} +} \ No newline at end of file diff --git a/custom_components/open_epaper_link/util.py b/custom_components/open_epaper_link/util.py new file mode 100644 index 0000000..a3c8d99 --- /dev/null +++ b/custom_components/open_epaper_link/util.py @@ -0,0 +1,8 @@ + +def get_image_folder(hass): + """Return the folder where images are stored.""" + return hass.config.path("www/open_epaper_link") + +def get_image_path(hass, entity_id): + """Return the path to the image for a specific tag.""" + return hass.config.path("www/open_epaper_link/open_epaper_link."+ str(entity_id).lower() + ".jpg") \ No newline at end of file