Possible to split state_map for value vs display
pgiblock opened this issue · 3 comments
Is your feature request related to a problem? Please describe.
Use case: a battery level reported as a binary sensor. The ones I've seen report: "normal", "low", "unavailable". In this card, "normal" seems to map to "off", and "low" maps to "on". Thus, what happens is all these switches is they show as a battery with question mark icon, and the values are "off" or "on". I can use a state_map
to map "off" and "on" to, say, "90" and "20". This fixes the icons, but now I have these arbitrary values printed on the right. I can map "off" and "on" back to to "Normal" and "Low", which fixes the text legends, but the batteries revert back to question marks - and the sorting is wrong.
Describe the solution you'd like
One way to fix this is to provide two state_maps. One for values, which will be used for sorting as well as icon levels. The other state_map will be used for labels. Thus, my solution would look something like:
state_map:
- from: 'off'
to: 100
- from: 'on'
to: 20
label_state_map:
- from: 'off'
to: Normal
- from: 'on'
to: Low
If label_state_map
is not defined, the extension would use state_map
for labels as well. This is the current behavior, so it shouldn't cause and regressions to users' configurations.
Additional context
Note: this is a partial screenshot. "Unavailable" sorts before "Normal", then there would be "Low", then numericals. Ideally, they would be sorted: "Unavailable", "Low", numericals, "Normal".
Thanks for the suggestion. I was thinking about this already and I was planning to add a property to Convert object so it would be something like
state_map:
- from: off
to: 100
display: "Normal"
So, in that case, to
is being used for the battery icon and sorting, and display
is used for the label? I'm pretty sure that would work for me.
Only thing I'm trying to figure out how I could get Unavailable devices to sort before devices with a value when sorted ascending. Use case is: a card that lists batteries in order of maintenance priority. Anything unavailable is urgent, then we see items in order of battery level; lowest first. I suppose I could do:
- from: Unavailable
to: -1
display: "Unavailable"
but, I'm not sure what that would do to the icon. I'm definately interested in testing when ready.
Thanks!