Fix climate rows. Add localize function
This commit is contained in:
parent
2940ee2bcb
commit
57fc14bbab
12
README.md
12
README.md
@ -87,6 +87,7 @@ The following functions are defined:
|
||||
| `cardTools.hasTemplate(text)` | 0.2 | Check if `text` contains a simple state template |
|
||||
| `cardTools.parseTemplate(text, [error])` | 0.2 | Parse a simple state template and return results |
|
||||
| `cardTools.args()` | 0.3 | Returns URL parameters of the script from `resources:` |
|
||||
| `cardTools.localize(key)` | 0.3 | Returns translations of certains strings to the users language |
|
||||
|
||||
> Another way to use the `card-tools` is to just copy the function you want, and paste it into your card. It requires a bit of more work, but may be more user friendly.
|
||||
|
||||
@ -225,6 +226,17 @@ resources:
|
||||
|
||||
If called from `my-plugin.js` `cardTools.args()` will return the javascript object `{height: 5, flag: undefined, width: 10}`.
|
||||
|
||||
### localize
|
||||
Returns the translation of certain strings (defined by string keys) to the users language.
|
||||
|
||||
Examples of keys:
|
||||
- `"state.light.on"`
|
||||
- `"state.binary_sensor.garage_door.off"`
|
||||
- `"domain.fan"`
|
||||
- `"attribute.weather.humidity"`
|
||||
|
||||
More can be found by exploring `cardTools.hass().resources`.
|
||||
|
||||
## Changelog
|
||||
|
||||
*0.2*
|
||||
|
@ -116,7 +116,7 @@ class {
|
||||
const DEFAULT_ROWS = {
|
||||
alert: "toggle",
|
||||
automation: "toggle",
|
||||
climate: "toggle",
|
||||
climate: "climate",
|
||||
cover: "cover",
|
||||
fan: "toggle",
|
||||
group: "group",
|
||||
@ -133,6 +133,7 @@ class {
|
||||
timer: "timer",
|
||||
switch: "toggle",
|
||||
vacuum: "toggle",
|
||||
water_heater: "climate",
|
||||
};
|
||||
|
||||
if(!config || typeof config !== "object" || (!config.entity && !config.type)) {
|
||||
@ -212,6 +213,13 @@ class {
|
||||
return args;
|
||||
}
|
||||
|
||||
static localize(key, def="") {
|
||||
const language = this.hass().language;
|
||||
if(this.hass().resources[language] && this.hass().resources[language][key])
|
||||
return this.hass().resources[language][key];
|
||||
return def;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Global definition of cardTools
|
||||
|
Loading…
x
Reference in New Issue
Block a user