OpenEPaperLink / Home_Assistant_Integration

Home assistant Integration for the OpenEPaperLink project
Apache License 2.0
137 stars 32 forks source link

Payload type multiline is not working #55

Closed ArmenGhazaryan closed 9 months ago

ArmenGhazaryan commented 9 months ago

Describe the bug Payload type multiline is not working in my HA setup.

To Reproduce Steps to reproduce the behavior:

  1. Copy multiline sample from here: https://github.com/jonasniesner/open_epaper_link_homeassistant/blob/main/docs/drawcustom/supported_types.md#multiline
  2. Use that in my HA /developer-tools/service page (Other payload types are working both with dry-run enabled and disabled)
  3. In my case it see this error message "Failed to call service open_epaper_link.drawcustom. Unknown error"
  4. I see 2 error lines in my HA log (attaching in additional context)

Expected behavior The expected behaviour is to have no errors and generate the image for the tag.

Screenshots

Screenshot 2023-11-13 at 1 58 11 PM

Additional context

Logger: homeassistant.helpers.script.websocket_api_script Source: helpers/script.py:468 First occurred: 2:12:58 PM (1 occurrences) Last logged: 2:12:58 PM

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 'y_padding'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/open_epaper_link/__init__.py", line 44, in drawcustomservice
    imgbuff = await hass.async_add_executor_job(customimage,entity_id, service, hass)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/open_epaper_link/imagegen.py", line 165, in customimage
    pos = pos_y + + element['y_padding']
                    ~~~~~~~^^^^^^^^^^^^^
KeyError: 'y_padding'
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/open_epaper_link/imagegen.py:165
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 2:12:58 PM (1 occurrences)
Last logged: 2:12:58 PM

[546696530880] Error handling message: Unknown error (unknown_error) **MY_USERNAME** from **MY_DEVICE_IP** (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 731, in handle_execute_script
    script_result = await script_obj.async_run(msg.get("variables"), context=context)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1578, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 420, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 470, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 493, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 704, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 666, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/open_epaper_link/__init__.py", line 44, in drawcustomservice
    imgbuff = await hass.async_add_executor_job(customimage,entity_id, service, hass)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/open_epaper_link/imagegen.py", line 165, in customimage
    pos = pos_y + + element['y_padding']
                    ~~~~~~~^^^^^^^^^^^^^
KeyError: 'y_padding'
zarqeon commented 9 months ago

I am not the original author, but I managed to get it to work. This is more like a documentation issue, and the fact that the error messages that the service reports are no help:

you are missing a mandatory attribute called "offset_y", which expects an INT value. This tells the thing the line height: how much space to start the next line down the y axis.

unfortunately the example does not has this attribute, but i think it is mentioned in the documentation somewhere.

ArmenGhazaryan commented 9 months ago

@zarqeon, you are right. Thanks for the hint. Actually just offset_y didn't do the trick for me. I had to submit all these fields

- type: multiline
    value: "adb|asd"
    delimiter: "|"
    font: "ppb.ttf"
    offset_y: 50
    x: 0
    size: 40
    color: black
    y_padding: 10

I will try to purpose the documentation change

jonasniesner commented 9 months ago

closed thanks to @ArmenGhazaryan PR