PiotrMachowski / Home-Assistant-custom-components-Xiaomi-Cloud-Map-Extractor

This custom integration provides a way to present a live view of a map for Xiaomi (Roborock/Viomi/Roidmi/Dreame) vacuums without a need for rooting.
MIT License
1.15k stars 122 forks source link

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

Open jscherry opened 3 years ago

jscherry commented 3 years ago

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
PiotrMachowski commented 3 years ago

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

PiotrMachowski commented 3 years ago

Can you share your config?

jscherry commented 3 years ago

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

PiotrMachowski commented 3 years ago

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

Minglarn commented 3 years ago

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?

PiotrMachowski commented 3 years ago

@Minglarn please check these issues: #41 #79

radinsky commented 3 years ago

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
vashilov commented 3 years ago

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.