Sort unit lists sent to frontend (#88898)
This commit is contained in:
parent
a2a23564a4
commit
390daf1723
6 changed files with 41 additions and 35 deletions
|
@ -29,7 +29,10 @@ def ws_device_class_units(
|
|||
) -> None:
|
||||
"""Return supported units for a device class."""
|
||||
device_class = msg["device_class"]
|
||||
convertible_units = set()
|
||||
convertible_units = []
|
||||
if device_class in UNIT_CONVERTERS and device_class in DEVICE_CLASS_UNITS:
|
||||
convertible_units = DEVICE_CLASS_UNITS[device_class]
|
||||
convertible_units = sorted(
|
||||
DEVICE_CLASS_UNITS[device_class],
|
||||
key=lambda s: str.casefold(str(s)),
|
||||
)
|
||||
connection.send_result(msg["id"], {"units": convertible_units})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue