Skip to content

Commit

Permalink
Merge pull request OpenEPaperLink#114 from rohankapoorcom/use-relativ…
Browse files Browse the repository at this point in the history
…e-paths

Remove hardcoded paths to config and use relative paths
  • Loading branch information
jonasniesner authored Feb 9, 2024
2 parents 47969bf + b98b9fe commit f716992
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
7 changes: 4 additions & 3 deletions custom_components/open_epaper_link/camera.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations
from .const import DOMAIN
from .util import get_image_path
import logging
import datetime
import mimetypes
Expand All @@ -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)

Expand All @@ -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:
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions custom_components/open_epaper_link/imagegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 12 additions & 4 deletions custom_components/open_epaper_link/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions custom_components/open_epaper_link/util.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit f716992

Please sign in to comment.