rand256 / valetudo

Valetudo RE - experimental vacuum software, cloud free
Apache License 2.0
669 stars 74 forks source link

Cleaning History Maps via API? #261

Closed CaCu15 closed 4 years ago

CaCu15 commented 4 years ago

First I would like to thank you for this great piece of software. This makes integration into smart home solutions like Home Assistant much easier!

I would like to offer a cleaning history incl. map snapshots similar to the one offered on the settings page of Valetudo: grafik

I would like to integrate that with Home Assistant. I've already found the api endpoints listed below that provide the majority of the required information.

The map data delivered by /api/clean_record_map do not contain the image in a grafic format (e.g. PNG, JPG), but are gzipped raw map data that need to be interpreted in order to "draw" a map image.

There is an endpoint /api/simple_map available, that draws a map from raw map data. But I can not pass the map data returned by /api/clean_record_map to this endpoint in order to return a map image for the map snapshot. Instead

Is there any other endpoint that can be used to produce a map image for the cleaning history? If not: Is there any chance to offer such an endpoint? Best option (from my point of view) would be to pass the recordID directly to the endpoint. Than the endpoint can load the map data using /api/clean_record_map and draw the map in the same way as /api/simple_map does it.

I could imlement a logic to manage the cleaning history maps outside of valetudo (just save them at the end of each cleaning event), but if I see that correctly, than Valetudo does already have all the necessary data and logic in place. IMHO this would be not a really "elegant" solution . I would prefer to use the data and features already available...

pidator commented 4 years ago

Is there any other endpoint that can be used to produce a map image for the cleaning history?

I think this is what you looking for?

CaCu15 commented 4 years ago

Hello pidator,

thanks for you advise. If I understand correctly, the valetudo re mapper gives me the map for the CURRENT cleaning activity, i.e. the currently ongoing activity or the LAST activity if there is no ongoing activity. But I'm locking for the maps of the activities in the past that happend BEFORE the current/last activity. I can get a list of the last 20 cleaning activities using /api/clean_summary and /api/clean_record_map gives me raw map data. So the data is there, it just needs to be translated into a PNG. Anyway, maybe I will try to implement that on my own if I find the time. Should be just a combination of the implementation of /api/clean_record_map and /api/simple_map. Instead of returning the data to the client as /api/clean_record_map does it curretnly the code needs to call the SimpleMapDrawer with this data just as /api/simple_map does it. But instead of using the current map data and status this would work with the data returned by /api/clean_record_map.

rand256 commented 4 years ago

I suppose it should be really easy to make /api/simple_map endpoint to optionally accept binary mapdata to draw the map from, if its capabilities are enough for you (since it's quiet ugly compared to what valetudo-mapper can do).

rand256 commented 4 years ago

I've uploaded a test build in which a new parameter called "slot" is added to /api/simple_map endpoint. This allows to draw a map currently stored in the specified slot.

So regarding cleaning history, you can call the already known /api/clean_record_map (usually 2 times) to get a response like ["map_slot_8"], and right after that you can request a /api/simple_map?slot=8 to get the simple map of that exact cleaning.

Also, there are a few other GET parameters for a simple map:

CaCu15 commented 4 years ago

Thanks a lot, rand256, for implementing this. I will try that as soon as I find the time. Currently I've a lot to work on at my job, thus only very little time.