Closed Chacsam closed 1 year ago
Hi! Thanks for the detailed notes, that helps a lot.
You're not doing anything wrong - it looks like there has been an update to the underlying PyPDF2 library that changes the extractText
method to extract_text
instead.
The documentation for this method is here: https://pypdf2.readthedocs.io/en/stable/user/extract-text.html
The only occurrence of this method in this repo is here: https://github.com/emcniece/ha_pdf/blob/master/sensor.py#L117
Does it work if you modify line 117 of sensor.py to use page.extract_text()
? I don't have an installation running right now for easy testing, but I might be able to investigate more in the next few days.
Give this a shot and let's see what happens 😄
Hi, Thanks for quick response.
So I did change line 117 in sensor.py in the /config/custom_components/ha_pdf folder to:
except IndexError:
_LOGGER.error("PDF Page %s does not exist in file: %s", self._pdf_page, self._file_path)
text = page.extract_Text()
restarted Home Assistant, but no pdf sensor to be seen.
Updated log states something different:
Logger: homeassistant.components.sensor
Source: custom_components/ha_pdf/sensor.py:117
Integration: Capteur (documentation, issues)
First occurred: 21:03:11 (1 occurrences)
Last logged: 21:03:11
pdf: Error on device update!
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 521, in _async_add_entity
await entity.async_device_update(warning=False)
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 784, in async_device_update
await coro
File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/ha_pdf/sensor.py", line 117, in update
text = page.extract_Text()
AttributeError: 'PageObject' object has no attribute 'extract_Text'
Sorry, my mistake, I just realized I left the capital 'T' in the page.extract_Text()
line.
With a small 't' page.extract_text()
does work.
That seems to be the fix
Merged a PR and tagged https://github.com/emcniece/ha_pdf/releases/tag/v1.1.2 - feel free to keep your changes locally or check out the repo at master
or v1.1.2
👍
Thank you for your help testing this fix!
Thanks for the quick fix, now I can start the complex task of finding the right RegEx to parse my electricty provider's monthly rate card :)
Hello,
I have just tried to install ha_pdf as per documentation.
Git duplicated, files in the correct folder:
Configured my Home Assistant:
Where the pdf file is a plain text, ipsum.pdf
No "Test PDF Sensor" to be found anywhere
Feedback in log:
Anything I am doing wrong?