Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to retrieve map. Python error is thrown #455

Closed
2 tasks done
HummerDK opened this issue Aug 3, 2023 · 17 comments
Closed
2 tasks done

Unable to retrieve map. Python error is thrown #455

HummerDK opened this issue Aug 3, 2023 · 17 comments
Assignees
Labels
bug Something isn't working

Comments

@HummerDK
Copy link

HummerDK commented Aug 3, 2023

Checklist

  • I have updated the integration to the latest version available
  • I have checked if the problem is already reported

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 HummerDK added the bug Something isn't working label Aug 3, 2023
@HummerDK
Copy link
Author

HummerDK commented Aug 3, 2023

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

@HummerDK HummerDK closed this as completed Aug 3, 2023
@HummerDK
Copy link
Author

HummerDK commented Aug 3, 2023

Error appears again

@HummerDK HummerDK reopened this Aug 3, 2023
@PiotrMachowski
Copy link
Owner

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
Copy link

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
Copy link
Owner

@spider7611 #422

@churtbeullar
Copy link

Yea, same for me. Stopped working after update.

@redblue-pkt
Copy link

redblue-pkt commented Aug 4, 2023

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
Copy link

theone11 commented Aug 4, 2023

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
Copy link

DirkFust commented Aug 4, 2023

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
Copy link

matmos30 commented Aug 5, 2023

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
Copy link
Owner

Fixed in v2.2.1

@peterjuras
Copy link

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
Copy link
Owner

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

@peterjuras
Copy link

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
Copy link
Owner

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
Copy link

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
Copy link

matmos30 commented Aug 8, 2023

Fixed in v2.2.1

Works perfect now, piece of awesome work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants