Skip to content

Commit

Permalink
Merge pull request #29 from tomvanswam/dev
Browse files Browse the repository at this point in the history
v0.3.1
  • Loading branch information
tomvanswam committed Aug 19, 2020
2 parents ac9902e + 3662b6c commit 67e081f
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 65 deletions.
42 changes: 33 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,45 @@ compass:

### Compass Object

| Name | Type | Requirement | Default | Supported | Visual Config | Description |
| ---------- | --------- | ------------ | --------------- | --------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| indicator | list item | **Optional** | `arrow_outward` | v0.1.0 | &#10003; | Type of indicator to display in compass following indicators are possible:<br />`arrow_outward`<br />`arrow_inward`<br />`circle` |
| show_north | boolean | **Optional** | `false` | v0.2.0 | &#10003; | Show an indicator at the northern side of the compass |
| language | list item | **Optional** | | v0.3.0 | &#10003; | Show the abbreviation in the language configured in Home Assistant (default/empty), or configured language |
| Name | Type | Requirement | Default | Supported | Visual Config | Description |
| ---------- | --------------------- | ------------ | --------------- | --------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| indicator | list item | **Optional** | `arrow_outward` | v0.1.0 | &#10003; | Type of indicator to display in compass following indicators are possible:<br />`arrow_outward`<br />`arrow_inward`<br />`circle` |
| show_north | boolean | **Optional** | `false` | v0.2.0 | &#10003; | Show an indicator at the northern side of the compass |
| language | [language](#language) | **Optional** | | v0.3.0 | &#10003; | Show the abbreviation in the language configured in Home Assistant (default/empty), or configured language |

### Language

The following languages are supported:

| Language | Yaml value | Supported | Translated by |
| --------- | ---------- | --------- | ------------------------------------------------------------ |
| Dutch | `nl` | v0.3.0 | [@tomvanswam](https://github.com/tomvanswam) |
| English | `en` | v0.3.0 | [@tomvanswam](https://github.com/tomvanswam) |
| French | `fr` | v0.3.1 | [@andilge](https://github.com/andilge) |
| German | `de` | v0.3.0 | [@rainer-geiger](https://github.com/rainer-geiger) |
| Italian | `it` | v0.3.0 | [@matteofranceschini](https://github.com/matteofranceschini) |
| Norwegian | `no` | v0.3.1 | [@hwikene](https://github.com/hwikene) |
| Portugese | `pt` | v0.3.1 | [@andilge](https://github.com/andilge) |
| Spanish | `es` | v0.3.1 | [@andilge](https://github.com/andilge) |

Pick the language in the visual editor, or add it to yaml config.

Example for Portugese abbreviations (regardless of Home Assistant language setting):

```yaml
type: custom:compass-card
entity: sensor.friends_direction
secondary_entity: sensor.friends_distance
compass:
language: pt
```

## Wish/Todo list

- Additional entities to show on circle
- Custom styled indicator (per entity)
- Background image
- Hide indicator in certain directions (to use the card to display the sun or moon's movement)
- Css options to change look & feel
- Localisation of direction abbreviation
- Cleanup unused boilerplate code

## Contact
Expand All @@ -145,8 +170,7 @@ And occasionally on the [HACS](https://discord.gg/apgchf8) and [Home Assistant](
- [@rsnodgrass](https://github.com/rsnodgrass) for [wind-compass-card](https://github.com/rsnodgrass/wind-compass-card), which gave me the idea to make this
- [@iantrich](https://www.github.com/iantrich) for the [boiler-plate card](https://github.com/custom-cards/boilerplate-card), which got me started
- [@xixao](https://codepen.io/xixao/) for [wind speed/direction css](https://codepen.io/xixao/pen/OPovyN)
- [@matteofranceschini](https://github.com/matteofranceschini) for the Italian translation
- [@rainer-geiger](https://github.com/rainer-geiger) for the German translation
- [All the translators](#language)

## Support

Expand Down
84 changes: 42 additions & 42 deletions dist/compass-card.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "compass-card",
"version": "0.3.0",
"version": "0.3.1",
"description": "Lovelace compass-card",
"keywords": [
"home-assistant",
Expand Down
4 changes: 2 additions & 2 deletions src/compass-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CompassCardConfig, CCProperties } from './types';
import './editor';
import style from './style';

import { CARD_VERSION, ICONS, COMPASS_ABBREVIATIONS, COMPASS_POINTS, UNAVAILABLE, INDICATORS } from './const';
import { CARD_VERSION, ICONS, COMPASS_ABBREVIATIONS, COMPASS_POINTS, UNAVAILABLE, INDICATORS, DEFAULT_INDICATOR } from './const';

import { localize } from './localize/localize';

Expand Down Expand Up @@ -202,7 +202,7 @@ export class CompassCard extends LitElement {
if (config.compass && config.compass.indicator && INDICATORS.indexOf(config.compass.indicator) >= 0) {
return config.compass.indicator;
}
return INDICATORS[0];
return INDICATORS[DEFAULT_INDICATOR];
}

static getDegrees(abbrevation: string): number {
Expand Down
5 changes: 3 additions & 2 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { localize } from './localize/localize';

export const CARD_VERSION = '0.3.0';
export const CARD_VERSION = '0.3.1';
export const ICONS = {
compass: 'mdi:compass',
};
Expand Down Expand Up @@ -42,7 +42,8 @@ export const COMPASS_ABBREVIATIONS = [
];
export const UNAVAILABLE = localize('common.invalid');

export const INDICATORS = ['arrow_outward', 'arrow_inward', 'circle'].sort();
export const INDICATORS = ['arrow_inward', 'arrow_outward', 'circle'].sort();
export const DEFAULT_INDICATOR = 1; // Arrow outward

export const CONFIG_ENTITY = 'entity';
export const CONFIG_SECONDARY_ENTITY = 'secondary_entity';
Expand Down
17 changes: 8 additions & 9 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LitElement, html, customElement, property, TemplateResult, CSSResult, c
import { HomeAssistant, fireEvent, LovelaceCardEditor } from 'custom-card-helpers';

import { CompassCardConfig } from './types';
import { INDICATORS, CONFIG_COMPASS, CONFIG_INDICATOR, CONFIG_ENTITY, CONFIG_SECONDARY_ENTITY, CONFIG_DIRECTION_OFFSET, CONFIG_NAME, CONFIG_SHOW_NORTH, CONFIG_DOMAINS, CONFIG_LANGUAGE } from './const';
import { INDICATORS, DEFAULT_INDICATOR, CONFIG_COMPASS, CONFIG_INDICATOR, CONFIG_ENTITY, CONFIG_SECONDARY_ENTITY, CONFIG_DIRECTION_OFFSET, CONFIG_NAME, CONFIG_SHOW_NORTH, CONFIG_DOMAINS, CONFIG_LANGUAGE } from './const';

import { localize, COMPASS_LANGUAGES } from './localize/localize';

Expand Down Expand Up @@ -47,10 +47,11 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
}

get _compass_indicator(): string {
console.log(this._config?.compass?.indicator, INDICATORS[DEFAULT_INDICATOR]);
if (this._config) {
return this._config?.compass?.indicator || INDICATORS[1];
return this._config?.compass?.indicator || INDICATORS[DEFAULT_INDICATOR];
}
return INDICATORS[1];
return INDICATORS[DEFAULT_INDICATOR];
}

get _compass_show_north(): boolean {
Expand All @@ -76,8 +77,6 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
const entities = Object.keys(this.hass.states)
.filter((eid) => CONFIG_DOMAINS.includes(eid.substr(0, eid.indexOf('.'))))
.sort();
const indicatorsSorted = INDICATORS;
const languages = COMPASS_LANGUAGES;

return html`
<div class="card-config">
Expand All @@ -97,8 +96,8 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
</paper-listbox>
</paper-dropdown-menu>
<paper-dropdown-menu class="editor-entity-select" label="${localize('editor.indicator')} (${localize('editor.optional')})" @value-changed=${this._valueChanged} .configValue=${CONFIG_COMPASS + '.' + CONFIG_INDICATOR}>
<paper-listbox slot="dropdown-content" .selected=${indicatorsSorted.indexOf(this._compass_indicator)}>
${indicatorsSorted.map((indicator) => {
<paper-listbox slot="dropdown-content" .selected=${INDICATORS.indexOf(this._compass_indicator)}>
${INDICATORS.map((indicator) => {
return html` <paper-item>${indicator}</paper-item>`;
})}
</paper-listbox>
Expand All @@ -109,8 +108,8 @@ export class CompassCardEditor extends LitElement implements LovelaceCardEditor
@value-changed=${this._valueChanged}
.configValue=${CONFIG_COMPASS + '.' + CONFIG_LANGUAGE}
>
<paper-listbox slot="dropdown-content" .selected=${languages.indexOf(this._compass_language)}>
${languages.map((language) => {
<paper-listbox slot="dropdown-content" .selected=${COMPASS_LANGUAGES.indexOf(this._compass_language)}>
${COMPASS_LANGUAGES.map((language) => {
return html` <paper-item>${language}</paper-item>`;
})}
</paper-listbox>
Expand Down
49 changes: 49 additions & 0 deletions src/localize/languages/es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"common": {
"version": "Versión",
"description": "Mostrar una brújula con un indicador en la dirección del valor de la entidad",
"invalid_configuration": "Configuración inválida",
"no_entity": "Entidad no configurada",
"offset_not_a_number": "El desplazamiento de dirección no es un número",
"invalid": "inválido",
"on": "Encendido",
"off": "Apagado"
},
"editor": {
"name": "Nombre",
"optional": "Opcional",
"entity": "Entidad",
"required": "Requerido",
"primary": "Primario",
"secondary": "Secundario",
"indicator": "Indicador",
"direction": "Dirección",
"offset": "Desplazamiento",
"show": "Mostrar",
"abbreviations": "Abreviaturas",
"toggle": "Conmutar",
"language": "Idioma"
},
"directions": {
"north": "Norte",
"east": "Este",
"south": "Sur",
"west": "Oeste",
"N": "N",
"NNE": "NNE",
"NE": "NE",
"ENE": "ENE",
"E": "E",
"ESE": "ESE",
"SE": "SE",
"SSE": "SSE",
"S": "S",
"SSW": "SSO",
"SW": "SO",
"WSW": "OSO",
"W": "O",
"WNW": "ONO",
"NW": "NO",
"NNW": "NNO"
}
}
49 changes: 49 additions & 0 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"common": {
"version": "version",
"description": "Montre une boussole avec un indicateur dans la direction de la valeur de l'entité",
"invalid_configuration": "configuration non valable",
"no_entity": "entité non configurée",
"offset_not_a_number": "Le décalage de direction n'est pas un nombre",
"invalid": "invalide",
"on": "allumé",
"off": "éteint"
},
"editor": {
"name": "Nom",
"optional": "Facultatif",
"entity": "entité",
"required": "obligatoire",
"primary": "primaire",
"secondary": "secondaire",
"indicator": "indicateur",
"direction": "direction",
"offset": "décalage",
"show": "montrer",
"abbreviations": "abréviations",
"toggle": "basculer",
"language": "langue"
},
"directions": {
"north": "Nord",
"east": "Est",
"south": "Sud",
"west": "Ouest",
"N": "N",
"NNE": "NNE",
"NE": "NE",
"ENE": "ENE",
"E": "E",
"ESE": "ESE",
"SE": "SE",
"SSE": "SSE",
"S": "S",
"SSW": "SSO",
"SW": "SO",
"WSW": "OSO",
"W": "O",
"WNW": "ONO",
"NW": "NO",
"NNW": "NNO"
}
}
49 changes: 49 additions & 0 deletions src/localize/languages/no.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"common": {
"version": "Versjon",
"description": "Vis et kompass med en indikator i retning av enhetens verdi",
"invalid_configuration": "Ugyldig konfigurasjon",
"no_entity": "Enheten er ikke konfigurert",
"offset_not_a_number": "Retningsforskyvning er ikke et tall",
"invalid": "Ugyldig",
"on": "",
"off": "Av"
},
"editor": {
"name": "Navn",
"optional": "Valgfri",
"entity": "Enhet",
"required": "Obligatorisk",
"primary": "Primær",
"secondary": "Sekundær",
"indicator": "Indikator",
"direction": "Retning",
"offset": "Offset",
"show": "Vis",
"abbreviations": "Forkortelser",
"toggle": "Veksle",
"language": "Språk"
},
"directions": {
"north": "Nord",
"east": "Øst",
"south": "Sør",
"west": "Vest",
"N": "N",
"NNE": "NNØ",
"NE": "",
"ENE": "ØNØ",
"E": "E",
"ESE": "ESE",
"SE": "",
"SSE": "SSE",
"S": "S",
"SSW": "SSV",
"SW": "SV",
"WSW": "VSV",
"W": "V",
"WNW": "VNV",
"NW": "NV",
"NNW": "NNV"
}
}
49 changes: 49 additions & 0 deletions src/localize/languages/pt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"common": {
"version": "versão",
"description": "Exibe uma bússola com um indicador na direção do valor da entidade",
"invalid_configuration": "configuração inválida",
"no_entity": "entidade não configurada",
"offset_not_a_number": "o offset direcional não é um número",
"invalid": "inválido",
"on": "ligado",
"off": "desligado"
},
"editor": {
"name": "nome",
"optional": "opcional",
"entity": "entidade",
"required": "necessário",
"primary": "primário",
"secondary": "secundário",
"indicator": "indicador",
"direction": "direção",
"offset": "offset",
"show": "mostra",
"abbreviations": "abreviações",
"toggle": "alternar",
"language": "idioma"
},
"directions": {
"north": "norte",
"east": "leste",
"south": "sul",
"west": "oeste",
"N": "N",
"NNE": "NNE",
"NE": "NE",
"ENE": "ENE",
"E": "L",
"ESE": "ESE",
"SE": "SE",
"SSE": "SSE",
"S": "S",
"SSW": "SSO",
"SW": "SO",
"WSW": "OSO",
"W": "O",
"WNW": "ONO",
"NW": "NO",
"NNW": "NNO"
}
}
8 changes: 8 additions & 0 deletions src/localize/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import * as en from './languages/en.json';
import * as nl from './languages/nl.json';
import * as it from './languages/it.json';
import * as de from './languages/de.json';
import * as fr from './languages/fr.json';
import * as es from './languages/es.json';
import * as pt from './languages/pt.json';
import * as no from './languages/no.json';

export const languages: any = {
en: en,
nl: nl,
it: it,
de: de,
es: es,
pt: pt,
no: no,
fr: fr,
};
export const COMPASS_LANGUAGES = [...Object.keys(languages), ''].sort();

Expand Down

0 comments on commit 67e081f

Please sign in to comment.