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 some device classes #71

Merged
merged 1 commit into from
Mar 21, 2023
Merged

Add some device classes #71

merged 1 commit into from
Mar 21, 2023

Conversation

jd1
Copy link
Contributor

@jd1 jd1 commented Mar 2, 2023

I added device_class to the sensor where I could test them.

If it is fine for you, I can also add more device classes to other sensors, but I will not able to test them because my car doesn't have this sensors.

@jd1
Copy link
Contributor Author

jd1 commented Mar 8, 2023

I noticed that "Charging time left" is now only shown as full hours in Home Assistant. The minutes are gone. I'm going to invest if this is related to my changes.

@dvx76
Copy link
Member

dvx76 commented Mar 19, 2023

I noticed that "Charging time left" is now only shown as full hours in Home Assistant. The minutes are gone. I'm going to invest if this is related to my changes.

Never paid attention to this but I also only see hours (without added device_classes). Next time I'm charging at home I'll take a look at the API responses.

@dvx76
Copy link
Member

dvx76 commented Mar 20, 2023

API:

XXXXVIN      Charging time left - (charging_time_left)
        str_state: 07:20 h - state: 07:20
        attributes: {}

In HA the state value of the sensor correctly shows the minutes too. However when looking at the history graph, or using any graph card with that entity, it only shows the whole hour (e.g. 7h for the example above).

I wonder if the problem is the unit_of_measurement: h. Perhaps that expects a float with the number of hours (e.g. 7:30 would be 7.5)...

@dvx76
Copy link
Member

dvx76 commented Mar 20, 2023

@jd1
Copy link
Contributor Author

jd1 commented Mar 20, 2023

Yeah, I think the problem is that the value is not numeric. I encountered the problem, when I tried to do some calculations with the remaining charging time. I couldn't format it into anything usable, especially not into a timedelta which would require a format like 0:07:30 instead of 7:30 for 7 h.

My first attempt was to add the device class, but that didn't solve the issue. I think the correct solution is to convert it into a float value. If I find the time, I will have a look into it, but if someone else wants to fix it, I'm also fine with it 😃

@dvx76
Copy link
Member

dvx76 commented Mar 20, 2023

I got this working with device_class: duration, unit_of_measurement: h and charging_time_left() returning the number of hours remaining as a float.

I have two concerns with this though:

  • The formatting in the front-end doesn't seem quite consistent yet. E.g. the default Entities card will correctly format the value as hh:mm:ss but Entities just prints the float value with unit h. Same with templating (e.g. {{ states("sensor.<vin>_charging_time_left") }}
  • "Fixing" this would change the value of the existing entity, which could end up breaking peoples existing dashboard and automatons.

I'm not convinced the device_class stuff in HA is mature yet.

@Farfar
Copy link
Collaborator

Farfar commented Mar 21, 2023

Yes the logical next step is to set the state to a full 'hh:mm:ss' for easier parsing. The time/date handling in Home Assistant hasn't been consistent.
But for now this will be enough if it works for you.

@Farfar Farfar merged commit af5ee0e into skodaconnect:main Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants