core icon indicating copy to clipboard operation
core copied to clipboard

Xiaomi_miio doesn't use "device_class: duration" where appropriate

Open dewi-ny-je opened this issue 3 years ago • 8 comments

The problem

xiaomi_miio vacuum (and maybe others) (see https://github.com/home-assistant/core/blob/bfd84ba89c25d432b1b8be946118214c6681e01e/homeassistant/components/xiaomi_miio/sensor.py and see https://community.home-assistant.io/t/how-to-format-a-card-to-show-hours-instead-of-seconds/425473/7 ) does not declare the sensors related to duration (time it took for last cleaning, total running time) as "device_class: duration", resulting in a poor display on the UI, which shows seconds instead of splitting in hours and minutes where appropriate.

What version of Home Assistant Core has the issue?

2022.8.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

xiaomi_miio

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

dewi-ny-je avatar Aug 12 '22 07:08 dewi-ny-je

@rytilahti do you know if it can be updated?

dewi-ny-je avatar Sep 18 '22 18:09 dewi-ny-je

@dewi-ny-je thanks for pinging me, this somehow slipped through the cracks! Yes, this should be fixed so I'll reopen it, feel free to create a PR, if you wish!

edit: I realized this was not assigned to me as you didn't follow the instructions when reporting and didn't use the URL for the integration so it didn't get assigned a label automatically by the bot, just a friendly reminder :-)

rytilahti avatar Sep 18 '22 19:09 rytilahti

Hey there @syssi, @starkillerog, @bieniu, mind taking a look at this issue as it has been labeled with an integration (xiaomi_miio) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)

@rytilahti thanks for the reminder, my bad.

I'll see what I can do but projects in my free time gets measured in weeks even for small tasks, if they require me to turn on my main PC, so I can't guarantee any deadline

dewi-ny-je avatar Sep 18 '22 20:09 dewi-ny-je

Sure thing, we are all volunteers here :-) given that I now know about the issue, maybe I'll have some downtime to look into it when I have a device to test it.

rytilahti avatar Sep 18 '22 20:09 rytilahti

Someone posted the same issue: https://github.com/home-assistant/core/issues/72602

I use a docker image, so I cannot modify it to test it. Should I copy the integration to the custom_components and modify that one, to have HA use the modified one instead of the built-in one?

By the way, by looking at (sensor about duration, but no device_class) https://github.com/home-assistant/core/blob/bfd84ba89c25d432b1b8be946118214c6681e01e/homeassistant/components/xiaomi_miio/sensor.py#L529 and by comparing with (sensor with device_class, not duration) https://github.com/home-assistant/core/blob/bfd84ba89c25d432b1b8be946118214c6681e01e/homeassistant/components/xiaomi_miio/sensor.py#L155 and by looking at (sensor from another integration with device_class=SensorDeviceClass.DURATION) https://github.com/home-assistant/core/blob/9a6b22a156192ec056ac2f73db4de079506705a1/homeassistant/components/overkiz/sensor.py#L357

it seems to me that I should simply add the line

device_class=SensorDeviceClass.DURATION,

to the sensors:

current_clean_duration total_clean_duration filter_left main_brush_left sensor_dirty_left side_brush_left

It's a pure copy/paste with basically NO risk of mistakes, provided someone reviews it after I make the change. I'm not even sure it needs testing...

dewi-ny-je avatar Sep 20 '22 11:09 dewi-ny-je

Yes, I think that should do the trick. Though it's still worth testing that the change works as expected :-)

rytilahti avatar Sep 20 '22 18:09 rytilahti

@dewi-ny-je @rytilahti I made a PR to include the duration device class and have tested it on my dev enviroment: https://github.com/home-assistant/core/pull/78974

@dewi-ny-je thanks for figuring this out!

starkillerOG avatar Sep 22 '22 21:09 starkillerOG

Fixed with #78974 – thanks @starkillerOG & @dewi-ny-je!

rytilahti avatar Sep 23 '22 16:09 rytilahti