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

Add Image entities for vehicle status #437

Merged
merged 13 commits into from
Dec 19, 2024

Conversation

WebSpider
Copy link
Contributor

This adds 2 image entities that can display the vehicle status, as is done in the MySkoda App as well.

  • One image is in 'Light' style
  • One image is in 'Dark' style

The status is related to the window state, door state, bonnet state, etc.

Images are disabled by default, since it probably mostly is interesting to developers of custom cards.
They can be enabled manually in HA when going to the list of entities, and enabling them.

image

@WebSpider WebSpider added the enhancement New feature or request label Dec 11, 2024
@WebSpider WebSpider requested review from dvx76 and prvakt December 11, 2024 15:22
@WebSpider
Copy link
Contributor Author

Fixes #342

@WebSpider WebSpider linked an issue Dec 11, 2024 that may be closed by this pull request
@prvakt
Copy link
Collaborator

prvakt commented Dec 11, 2024

question 1: do we want to have those 2 under SENSORS because I think its more suitable for DIAGNOSTICS
question 2: I have noticed state for all images (also main render) is uknown.. I dont know if we want to handle state or not, but if yes maybe we can show something like available if image is present and unavailable if not?

    if is_available:
        self._state = "available"
    else:
        self._state = "unavailable"
    self.schedule_update_ha_state()

question 3: both images are same for my case, but from code I can see its retrieving correct path, so just want to check its same for you as well. (If it same, then does it make sense to have both?)
image
image

@prvakt
Copy link
Collaborator

prvakt commented Dec 11, 2024

question 4: is it updated with the periodical vehicle update?

@WebSpider
Copy link
Contributor Author

WebSpider commented Dec 11, 2024

question 1: do we want to have those 2 under SENSORS because I think its more suitable for DIAGNOSTICS

I figured, that since it is disabled by default, if you want this bad enough to enable it, you probably want it under sensors. But i don't mind changing it if anyone has a strong opinion on this

question 2: I have noticed state for all images (also main render) is uknown.. I dont know if we want to handle state or not, but if yes maybe we can show something like available if image is present and unavailable if not?

I am in favor of handling the state, as long as we know what we want the state to be. I did not have any opinion on this yet, so i decided to leave it undefined for now.

question 3: both images are same for my case, but from code I can see its retrieving correct path, so just want to check its same for you as well. (If it same, then does it make sense to have both?

I didn't check :-) Only enabled one to see if it works. Will check and report back in a bit.

Update: They are the same for me as well. I will remove one entity.

@WebSpider
Copy link
Contributor Author

question 4: is it updated with the periodical vehicle update?

If there is an update to the state, the URL should change, triggering an update as part of the ImageEntity. Have not seen that happen yet, since my car is not close to my home at the moment.

@prvakt
Copy link
Collaborator

prvakt commented Dec 12, 2024

1 ) asked ChatGPT about the sensor vs diagnostic section and it suggest also sensors :)

Suggestion for Your Case:
Given that the image likely represents the state of doors and windows in real-time, I recommend placing it under Sensors, as it primarily visualizes the output of door/window state sensors. If, however, it includes additional diagnostic elements like system errors or advanced analytics, then Diagnostics would be a better fit.

2 ) the state of all image entities can be implemented later once we agree what to show.

4 ) I'm running this version for hour with poll interval set to 15 minutes.. Initially the state was correct, then I have opened door but state was never changed, even I see periodical update of all sensors have been triggered, Status Render image was not updated..

@WebSpider
Copy link
Contributor Author

4 ) I'm running this version for hour with poll interval set to 15 minutes.. Initially the state was correct, then I have opened door but state was never changed, even I see periodical update of all sensors have been triggered, Status Render image was not updated..

The ImageEntity has some strange defaults. This should be corrected now.

@prvakt
Copy link
Collaborator

prvakt commented Dec 12, 2024

The ImageEntity has some strange defaults. This should be corrected now.

Still doesnt work, I can see from logs that image url was changed from

https://mysmob.api.connect.skoda-auto.cz/api/v2/vehicle-status/render?carType=COMBI&vehicleState=1-1-1-1-0-0-0-0-0&lastModifiedAt=1733938917&dimension=3x&theme=LIGHT

to

https://mysmob.api.connect.skoda-auto.cz/api/v2/vehicle-status/render?carType=COMBI&vehicleState=1-1-3-1-0-0-0-0-0&lastModifiedAt=1733938917&dimension=3x&theme=LIGHT

but image was not updated and last updated timestamp was not changed either...

@WebSpider
Copy link
Contributor Author

Thanks, will continue in the mysteries of the ImageEntity tomorrow 😂

@dvx76
Copy link
Member

dvx76 commented Dec 14, 2024

From https://developers.home-assistant.io/docs/core/entity/image/

Implement async_image or image if your entity returns bytes of the image instead of providing a URL. Frontend will call async_image or image to fetch the image. If the image is fetched remotely, image data should be cached and the cache invalidated when image_last_updated is changed.

I would assume if the url is updated this would automatically invalidate the cache and force the url to be re-fetched. But maybe that's not happening?

@WebSpider
Copy link
Contributor Author

From https://developers.home-assistant.io/docs/core/entity/image/

Implement async_image or image if your entity returns bytes of the image instead of providing a URL. Frontend will call async_image or image to fetch the image. If the image is fetched remotely, image data should be cached and the cache invalidated when image_last_updated is changed.

I would assume if the url is updated this would automatically invalidate the cache and force the url to be re-fetched. But maybe that's not happening?

Rereading that piece of documentation, I think they mean we should implement a "last changed" property ourselves, so did that in last commit.

@prvakt
Copy link
Collaborator

prvakt commented Dec 16, 2024

Rereading that piece of documentation, I think they mean we should implement a "last changed" property ourselves, so did that in last commit.

We are still missing something. "Last changed" was updated correctly, but image was not changed. I can see in MySkoda app that image has changed and door is now opened, and also new binary sensors which I have created today were updated accordingly but image was not

@WebSpider
Copy link
Contributor Author

I will have a look at that parent class more thoroughly. This will not make v1.16.0.

@WebSpider WebSpider requested a review from prvakt December 19, 2024 09:58
@prvakt
Copy link
Collaborator

prvakt commented Dec 19, 2024

I will have a look at that parent class more thoroughly. This will not make v1.16.0.

Good job! Can confirm it works as expected now ;)

@WebSpider WebSpider merged commit 3140ea7 into skodaconnect:main Dec 19, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Vehicle status render
3 participants