AmoebeLabs / swiss-army-knife-card

The versatile custom Swiss Army Knife card for Home Assistant allows you to create your unique visualization using several graphical tools, styling options and animations.
223 stars 19 forks source link

Refactor state building (states, animations) and state display (localization, specifics) #227

Closed AmoebeLabs closed 1 year ago

AmoebeLabs commented 1 year ago

The Problem To Be Solved

The current state-building and state-display routines have some flaws in correctly handling states for animations and states for localized display. These two should be refactored to differentiate between these two functions: state handling and state display.

The state building and display of the secondary_info should serve as an example. That one already has localization and special formatting options build in for display.

Additional background:

Check the various custom cards on how they process this, especially the display building:

@2023.05.23 Update It is clear that most custom cards are NOT up to date with the latest frontend implementation of localization and state string and number building.

So, with this refactoring, the HA Frontend modules are going to be the basis. I can't reuse them 1:1, as that would mean I have to 'pull' a greater part of the HA frontend into this card.

As other custom cards did in the past: adapt these files, and then use them in your card.

Adapting these files (to .js) for use in SAK will take some time, but at least it brings SAK up-to-date with the latest and greatest locale implementation of HA.

Related Issues (if any)

(Optional): Suggested Solution

There should be two different functions:

_BuildState():

Might be subdivided into:

_BuildStateRender(): Uses the state as build by _BuildState() to

Flow from set hass():

Flow from render():

(Optional): Alternative Solutions

AmoebeLabs commented 1 year ago

@2023.05.23 Status

A quick hack with up-to-date localization tags already shows translations. So this direction looks good!

You can see that the Pollen integration does not have Dutch translations for every state! I have checked that in the Chrome console by evaluating the hass.resources.nl strings for the pollen integration.

image

image

The AQI integration also does very well: image

As does the Person card: image

@2023.05.23 Status Part 2 (Evening)

And first results for numbering (only works for states, not for attributes and secondary_info):

image

@2023.05.28 DateTime formats using the 'format: ' option for an entity

image

@2023.05.29 Status

AmoebeLabs commented 1 year ago

@2023.06.11 Status

Progress with light colors

As part of this issue, but described in issue #232, icon states are also updated.