Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor icon indicating copy to clipboard operation
Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor copied to clipboard

Fonts not working: TypeError: expected string or bytes-like object

Open jscherry opened this issue 4 years ago • 8 comments

Worked perfectly through all other updates and betas. Beta 2021.2 is the only version that's had problems with roborock camera. Python 3.7 was removed? Not sure if that has an effect. Here's the log:

Logger: homeassistant.helpers.entity
Source: custom_components/xiaomi_cloud_map_extractor/image_handler.py:236
First occurred: 10:35:20 PM (9 occurrences)
Last logged: 10:36:32 PM
Update for camera.roborock_camera fails
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 474, in async_device_update
    raise exc
  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 200, in update
    map_data = self._connector.get_map(self._country, map_name, self._colors, self._drawables, self._texts,
  File "/config/custom_components/xiaomi_cloud_map_extractor/xiaomi_cloud_connector.py", line 134, 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 81, in parse
    ImageHandler.draw_texts(map_data.image, texts)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 193, 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 245, in __draw_text__
    ImageHandler.__draw_on_new_layer__(image, draw_func)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 259, in __draw_on_new_layer__
    draw_function(draw)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 236, in draw_func
    font = ImageFont.truetype(font_file, font_size)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 852, in truetype
    return freetype(font)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 849, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 173, in __init__
    freetype_version = parse_version(features.version_module("freetype2"))
  File "/usr/local/lib/python3.8/site-packages/packaging/version.py", line 57, in parse
    return Version(version)
  File "/usr/local/lib/python3.8/site-packages/packaging/version.py", line 296, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object

jscherry avatar Jan 28 '21 04:01 jscherry

This is not a correct repo for this bug - transferring.

PiotrMachowski avatar Jan 28 '21 08:01 PiotrMachowski

Can you share your config?

PiotrMachowski avatar Jan 28 '21 08:01 PiotrMachowski

Can you please close this. I had been using a full config and changed to suggested config after seeing your reply and it fixed it. Thanks

jscherry avatar Jan 28 '21 18:01 jscherry

I will leave it open as there might be some issues with drawing texts on a map

PiotrMachowski avatar Jan 28 '21 18:01 PiotrMachowski

Im too seeing xiaomi_cloud_map_extractor camera took longer than the scheduled update interval and the map does not show...

What changes did you do/recomend?

Minglarn avatar Feb 07 '21 17:02 Minglarn

@Minglarn please check these issues: #41 #79

PiotrMachowski avatar Feb 07 '21 21:02 PiotrMachowski

I still exception caused by ImageFont.truetype


2021-04-22 18:58:19 ERROR (MainThread) [homeassistant.helpers.entity] Update for camera.vacuum_map fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 292, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 490, in async_device_update
    raise exc
  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 225, in update
    map_data, map_stored = self._connector.get_map(self._country, map_name, self._colors, self._drawables,
  File "/config/custom_components/xiaomi_cloud_map_extractor/xiaomi_cloud_connector.py", line 139, 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 99, in parse
    ImageHandler.draw_texts(map_data.image, texts)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 228, 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 280, in __draw_text__
    ImageHandler.__draw_on_new_layer__(image, draw_func)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 298, in __draw_on_new_layer__
    draw_function(draw)
  File "/config/custom_components/xiaomi_cloud_map_extractor/image_handler.py", line 271, in draw_func
    font = ImageFont.truetype(font_file, font_size)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 852, in truetype
    return freetype(font)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 849, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/usr/local/lib/python3.8/site-packages/PIL/ImageFont.py", line 173, in __init__
    freetype_version = parse_version(features.version_module("freetype2"))
  File "/usr/local/lib/python3.8/site-packages/packaging/version.py", line 57, in parse
    return Version(version)
  File "/usr/local/lib/python3.8/site-packages/packaging/version.py", line 296, in __init__
    match = self._regex.search(version)
TypeError: expected string or bytes-like object
2021-04-22 18:58:29 ERROR (MainThread) [homeassistant.helpers.entity] Update for camera.vacuum_map fails

The WA is to remove rooms annotations aka:

texts:
   - text: "Room 1"
     x: 25
     y: 25
     color: [125, 20, 213]
   - text: "Room 2"
     x: 25
     y: 75
     color: [125, 20, 213, 127]
     font: "FreeSans.ttf"
     font_size: 25

radinsky avatar Apr 22 '21 16:04 radinsky

Why if I add font: "NotoSans-BoldItalic.ttf" in config, addon crash? But if I change def __draw_text__(image: ImageData, text, x, y, color, font_file=None, font_size=None): font_file = "NotoSans-BoldItalic.ttf" font_size = 50 in /config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py, addon ok.

vashilov avatar Jul 28 '21 12:07 vashilov