HA screenshots
This commit is contained in:
parent
aedab09f2a
commit
75de390973
3 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
---
|
||||
name: Screenshotter
|
||||
version: 1.0.1.4
|
||||
version: 1.0.1.5
|
||||
#image: ghcr.io/maxwinterstein/homeassistant-addon-toogoodtogo-ha-mqtt-bridge-{arch}
|
||||
slug: screenshotter
|
||||
description: Screenshot images for E-Paper pricetags
|
||||
|
@ -19,6 +19,8 @@ options:
|
|||
height: 128
|
||||
rotate: 270
|
||||
wait_seconds: 5
|
||||
ha_url: https://homeassistant.local:8123
|
||||
ha_token: 123aaa
|
||||
schema:
|
||||
image_path: str
|
||||
config_file: str
|
||||
|
@ -26,5 +28,7 @@ schema:
|
|||
height: int
|
||||
rotate: int
|
||||
wait_seconds: int
|
||||
ha_url: str
|
||||
ha_token: str
|
||||
stage: experimental
|
||||
init: false
|
||||
|
|
|
@ -16,6 +16,8 @@ width = os.environ.get("SCREEN_WIDTH", default="640")
|
|||
height = os.environ.get("SCREEN_HEIGHT", default="480")
|
||||
rotate = os.environ.get("SCREEN_ROTATE", default="0")
|
||||
wait = os.environ.get("SCREEN_WAIT", default="5")
|
||||
ha_url = os.environ.get("SCREEN_HA_URL", default="")
|
||||
ha_token = os.environ.get("SCREEN_HA_TOKEN", default="")
|
||||
|
||||
# Open another headless browser with height extracted above
|
||||
chrome_options = Options()
|
||||
|
@ -37,16 +39,24 @@ for image in config["images"]:
|
|||
tasks += [image]
|
||||
|
||||
while True:
|
||||
now = datetime.datetime.now()
|
||||
for i, task in enumerate(tasks):
|
||||
now = datetime.datetime.now()
|
||||
if task["next_execution"] > now:
|
||||
continue
|
||||
print(f"Running {task['name']}")
|
||||
driver = webdriver.Chrome(options=chrome_options, desired_capabilities=d)
|
||||
driver.implicitly_wait(10)
|
||||
driver.get(task["url"])
|
||||
# pause 3 second to let page loads
|
||||
time.sleep(int(wait))
|
||||
|
||||
if task["ha_auth"]:
|
||||
print("Doing HA Auth")
|
||||
driver.execute_script(f"window.localStorage.setItem('hassTokens', {hassUrl: '{ha_url}', access_token: '{ha_token}', token_type: 'Bearer'});")
|
||||
driver.get(task["url"])
|
||||
time.sleep(int(wait))
|
||||
|
||||
print("Making screenshot")
|
||||
|
||||
# save screenshot
|
||||
file_name = f'/tmp/{task["name"]}.png'
|
||||
driver.save_screenshot(file_name)
|
||||
|
@ -58,4 +68,5 @@ while True:
|
|||
file_name = f'{image_path}/{task["name"]}.png'
|
||||
image.save(file_name)
|
||||
tasks[i]["next_execution"] = now + datetime.timedelta(minutes=task["period_minutes"])
|
||||
print(f"Task finished, next execution: {tasks[i]['next_execution']}")
|
||||
time.sleep(1)
|
||||
|
|
|
@ -8,6 +8,9 @@ export SCREEN_WIDTH="$(bashio::config 'width')"
|
|||
export SCREEN_HEIGHT="$(bashio::config 'height')"
|
||||
export SCREEN_ROTATE="$(bashio::config 'rotate')"
|
||||
export SCREEN_WAIT="$(bashio::config 'wait_seconds')"
|
||||
export SCREEN_HA_URL="$(bashio::config 'ha_url')"
|
||||
export SCREEN_HA_TOKEN="$(bashio::config 'ha_token')"
|
||||
|
||||
|
||||
mkdir -p $SCREEN_IMAGE_PATH
|
||||
|
||||
|
|
Loading…
Reference in a new issue