Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor
Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor copied to clipboard
Warning: Unable to open font (...)
I cannot add label in Cyrillic, such as "Кухня":
Traceback (most recent call last):
File "E:\HassWP\python-3.7.7\lib\site-packages\homeassistant\helpers\entity.py", line 279, in async_update_ha_state
await self.async_device_update()
File "E:\HassWP\python-3.7.7\lib\site-packages\homeassistant\helpers\entity.py", line 472, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "E:\HassWP\python-3.7.7\lib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\camera.py", line 186, in update
self._image_config)
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\xiaomi_cloud_connector.py", line 105, in get_map
map_data = MapDataParser.parse(unzipped, colors, drawables, texts, sizes, image_config)
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\map_data_parser.py", line 76, in parse
MapDataParser.draw_elements(colors, drawables, texts, sizes, map_data)
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\map_data_parser.py", line 237, in draw_elements
ImageHandler.draw_texts(map_data.image, texts)
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\image_handler.py", line 171, in draw_texts
text_config[CONF_FONT], text_config[CONF_FONT_SIZE])
File "E:\HassWP\config\custom_components\xiaomi_cloud_map_extractor\image_handler.py", line 206, in __draw_text__
w, h = draw.textsize(text, font)
File "E:\HassWP\config\deps\Python37\site-packages\PIL\ImageDraw.py", line 430, in textsize
return font.getsize(text, direction, features, language, stroke_width)
File "E:\HassWP\config\deps\Python37\site-packages\PIL\ImageFont.py", line 128, in getsize
return self.font.getsize(text)
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-6: ordinal not in range(256)
It's impossible using default font, but when you use a font that supports latin characters everything works:
Thanks, just need to know all of my font available. I am using HA in docker.
Here you have a command that should retrieve all available fonts: https://github.com/PiotrMachowski/Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor#texts-configuration
On RPi I have another error:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 278, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 471, in async_device_update
await self.hass.async_add_executor_job(self.update) # type: ignore
File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/xiaomi_cloud_map_extractor/camera.py", line 185, in update
self._map_data = self._connector.get_map(map_name, self._colors, self._drawables, self._texts, self._sizes,
File "/config/custom_components/xiaomi_cloud_map_extractor/xiaomi_cloud_connector.py", line 105, in get_map
map_data = MapDataParser.parse(unzipped, colors, drawables, texts, sizes, image_config)
File "/config/custom_components/xiaomi_cloud_map_extractor/map_data_parser.py", line 76, in parse
MapDataParser.draw_elements(colors, drawables, texts, sizes, map_data)
File "/config/custom_components/xiaomi_cloud_map_extractor/map_data_parser.py", line 237, in draw_elements
ImageHandler.draw_texts(map_data.image, texts)
File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 170, in draw_texts
ImageHandler.__draw_text__(image, text_config[CONF_TEXT], x, y, text_config[CONF_COLOR],
File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 205, in __draw_text__
font = ImageFont.truetype(font_file, font_size)
File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 655, in truetype
return freetype(font)
File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 652, in freetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 169, in __init__
if core.HAVE_RAQM:
File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 43, in __getattr__
raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed
Can you check which version of pillow
/PIL
you have?
pip3 list
I am trying to figure out how deps are installed for HA in docker... Which python is used and where to run the command.
Pillow 7.2.0
I am trying to run the next:
apk add --no-cache g++ freetype-dev jpeg-dev
pip uninstall pillow
pip install --no-cache-dir pillow
to make sure pillow will be compiled with libfreetype. I am not sure if this will be a persistent solution for HA in docker.
It looks like no fonts preinstalled in homeassistant docker image
I will try to find a way to attach a font file
Solution for me was to jump inside HA container and run the next commands:
apk add --no-cache g++ freetype-dev jpeg-dev
pip uninstall pillow
pip install --no-cache-dir pillow
apk add font-noto
and use NotoSansDisplay-Light.ttf font.
BTW it will be nice to choose TTF file stored somewhere in the config folder.
Using TTF stored in a config is much better, as it doesn't require manual changes after every HA update. I will check if it is possible
But there is still an issue with Pillow installed(compiled during installation) without libfreetype. I don't know if there is any solution for that. That how homeassistant processing requirements, looks like no options to control that. So I still have to run the command after every update of HA.
I've hit the same problem, unfortunately my understanding is too limited to follow the instructions above.
I'm left with "ImportError: The _imagingft C module is not installed"
My home assistant is also installed within docker.
Thanks for the great work, really looking forward to being able to utilise this! :-)
After HA was updated to 0.116.2 I cannot fix the issue with the above commands. Every time I see The _imagingft C module is not installed error.
After HA was updated to 0.116.2 I cannot fix the issue with the above commands. Every time I see The _imagingft C module is not installed error.
I have the same error. So there is currently no solution to fix the Problem?
RPI4
Unfortunately I haven't found a solution yet
I have added handling to errors thrown during fonts loading.
I use HA on Docker with my NAS Synology. No fonts TTF on Synology...
it's Ok wihout font: "FreeSans.ttf" but i can't change the font_size...
texts:
- text: "Room 1"
x: 25
y: 25
color: [125, 20, 213]
font_size: 100
- text: "Room 2"
x: 25
y: 75
color: [125, 20, 213, 127]
font_size: 10
@Nicols07 unfortunately it's not possible to change size for a default font
Hi! I came over this issue when troubleshooting a similar issue with one of my own integrations. Not sure if it helps for this case, but I found a workaround by using bitmap fonts and then converting to PIL-fonts. Quite cumbersome solution, but it works better in my case. More info here if you're interested.