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.13k stars 122 forks source link

Unable to retrieve map. Python error is thrown #455

Closed HummerDK closed 1 year ago

HummerDK commented 1 year ago

Checklist

The problem

It is currently unable to retrieve a new map. Might be due to an update of python? See stacktrace below.

What version of an integration has described problem?

v2.2.0

What was the last working version of an integration?

v2.2.0

What vacuum model do you have problems with?

roborock s6

What version of Home Assistant do you use?

2023.8.0

What type of installation are you running?

Home Assistant OS

Camera's configuration

camera:
  - platform: xiaomi_cloud_map_extractor
    host: !secret xiaomi_vacuum_host
    token: !secret xiaomi_vacuum_token
    username: !secret xiaomi_cloud_username
    password: !secret xiaomi_cloud_password
    map_transformation:
      scale: 2 
      trim:
        top: 25
        bottom: 25
        left: 15
        right: 15
    draw: ['charger', 'cleaned_area', 'goto_path', 'vacuum_position', 'path', 'predicted_path', 'room_names']
    attributes:
      - calibration_points
      - rooms
      - vacuum_room_name
      - vacuum_position
      - cleaned_rooms
    scan_interval:
     seconds: 15
    auto_update: false
    colors:
     color_map_inside: [28,28,28]
     color_map_outside: [28,28,28]
     color_map_wall: [100, 196, 254]
     color_map_wall_v2: [93, 109, 126]
     color_grey_wall: [28,28,28]
     color_path: [0, 0, 0]
     color_goto_path: [0, 255, 0]
     color_predicted_path: [255, 255, 0, 0]
     color_zones: [0xAD, 0xD8, 0xFF, 0x8F]
     color_zones_outline: [0xAD, 0xD8, 0xFF]
     color_virtual_walls: [255, 0, 0]
     color_no_go_zones: [255, 33, 55, 127]
     color_no_go_zones_outline: [255, 0, 0]
     color_no_mop_zones: [163, 130, 211, 127]
     color_no_mop_zones_outline: [163, 130, 211]
     color_charger: [0x66, 0xfe, 0xda, 0x7f]
     color_robo: [75, 235, 149]
     color_unknown: [0, 0, 0]
     color_scan: [0xDF, 0xDF, 0xDF]

Errors shown in the HA logs (if applicable)

Update for camera.xiaomi_cloud_map_extractor fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 699, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 940, in async_device_update
    await hass.async_add_executor_job(self.update)
  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/xiaomi_cloud_map_extractor/camera.py", line 282, in update
    self._set_map_data(MapDataParser.create_empty(self._colors, str(self._status)))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_cloud_map_extractor/common/map_data_parser.py", line 16, in create_empty
    empty_map = ImageHandler.create_empty_map_image(colors, text)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 76, in create_empty_map_image
    w, h = draw.textsize(text)
           ^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'

Additional information

No response

HummerDK commented 1 year ago

Hmm, for some reason it suddently started working again. Ill close this issue for now

HummerDK commented 1 year ago

Error appears again

PiotrMachowski commented 1 year ago

The problem appears when Map Extractor tries to display a text on the image (e.g. when the map can't be retrieved from the cloud/vacuum). It should work properly when the map is downloaded correctly.

spider7611 commented 1 year ago

After latest HA 2023.8.0 update for me not working too. If I login xiaomi mihome app, map is disappered too. Don't know what happend. Yesterday was good...

PiotrMachowski commented 1 year ago

@spider7611 #422

churtbeullar commented 1 year ago

Yea, same for me. Stopped working after update.

redblue-pkt commented 1 year ago

Possible solution:

w, h = draw.textsize(text)

    left, top, right, bottom = draw.textbbox((0, 0), text)
    w, h = right - left, bottom - top

Same as in:

https://github.com/blockdiag/blockdiag/pull/171/files

theone11 commented 1 year ago

I also keep getting this error (log is full of them) since HA 2023.08

2023-08-04 12:38:59.896 ERROR (MainThread) [homeassistant.helpers.entity] Update for camera.vacuum_top fails
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 699, in async_update_ha_state
    await self.async_device_update()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 940, in async_device_update
    await hass.async_add_executor_job(self.update)
  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/xiaomi_cloud_map_extractor/camera.py", line 282, in update
    self._set_map_data(MapDataParser.create_empty(self._colors, str(self._status)))
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_cloud_map_extractor/common/map_data_parser.py", line 16, in create_empty
    empty_map = ImageHandler.create_empty_map_image(colors, text)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 76, in create_empty_map_image
    w, h = draw.textsize(text)
           ^^^^^^^^^^^^^
AttributeError: 'ImageDraw' object has no attribute 'textsize'
DirkFust commented 1 year ago

Same for me. I've got exactly the same error in the log. I can confirm that the fix @redblue-pkt suggests does indeed seems to work.

Possible solution: #w, h = draw.textsize(text) left, top, right, bottom = draw.textbbox((0, 0), text) w, h = right - left, bottom - top

Same as in:

https://github.com/blockdiag/blockdiag/pull/171/files

matmos30 commented 1 year ago

Similar situation here, but in different line (306). Does @redblue-pkt solution would work in my case aswell? My coding skills are 0 so I would be grateful if You guys could explain a bit more how to properly implement those changes.

My log:

File "/config/custom_components/xiaomi_cloud_map_extractor/camera.py", line 278, in update self._handle_map_data(map_name) File "/config/custom_components/xiaomi_cloud_map_extractor/camera.py", line 335, in _handle_map_data map_data, map_stored = self._device.get_map(map_name, self._colors, self._drawables, self._texts, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/xiaomi_cloud_map_extractor/common/vacuum.py", line 36, in get_map map_data = self.decode_map(response, colors, drawables, texts, sizes, image_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/xiaomi_cloud_map_extractor/roidmi/vacuum.py", line 23, in decode_map return MapDataParserRoidmi.parse(unzipped, colors, drawables, texts, sizes, image_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/xiaomi_cloud_map_extractor/roidmi/map_data_parser.py", line 41, in parse MapDataParserRoidmi.draw_elements(colors, drawables, sizes, map_data, image_config) File "/config/custom_components/xiaomi_cloud_map_extractor/common/map_data_parser.py", line 59, in draw_elements ImageHandler.draw_room_names(map_data.image, map_data.rooms, colors) File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 168, in draw_room_names ImageHandler.draw_text__(image, room.name, point.x, point.y, color) File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 309, in draw_text ImageHandler.draw_on_new_layer(image, draw_func, 1, ImageHandler.__use_transparency(color)) File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 323, in __draw_on_new_layer__ draw_function(draw) File "/config/custom_components/xiaomi_cloud_map_extractor/common/image_handler.py", line 306, in draw_func w, h = draw.textsize(text, font) ^^^^^^^^^^^^^ AttributeError: 'ImageDraw' object has no attribute 'textsize'

PiotrMachowski commented 1 year ago

Fixed in v2.2.1

peterjuras commented 1 year ago

Hi @PiotrMachowski , I'm not sure that the fix works properly. I'm running HA 2023.8.1 with your integration on v2.2.1 and it still can't initialize.

PiotrMachowski commented 1 year ago

@peterjuras do you have anything in logs? Does the image show anything? Which model do you have?

peterjuras commented 1 year ago

Hi @PiotrMachowski , I have the Roborock S7 (a15). Note: It's called Roomba, because that's how my wife likes to call it via Google Assistant. This is what my card shows: image My logs don't mention anything specific: image

PiotrMachowski commented 1 year ago

It is a different issue: #422

The fact that the camera displays the text on the image instead of crashing means that current issue is fixed.

peterjuras commented 1 year ago

I see. For me the addon still stopped working after the update though, it has not recovered since and I can't see entity statuses or the map 😔

matmos30 commented 1 year ago

Fixed in v2.2.1

Works perfect now, piece of awesome work!