Skip to content

Commit

Permalink
Add override_headline option
Browse files Browse the repository at this point in the history
  • Loading branch information
MrBartusek committed May 23, 2021
1 parent f3ea693 commit 09cd6d6
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build & Lint
on: [push, pull_request]
jobs:
build:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Validate JSON
- name: Validate JSONs
uses: docker://orrosenblatt/validate-json-action:latest
env:
INPUT_SCHEMA: src/schema.json
INPUT_SCHEMA: src/translations/schema.json
INPUT_JSONS: "src/translations/en.json,\
src/translations/de.json,\
src/translations/es.json,\
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ If you plan to contribute back to this repo, please fork & open a PR.

## How to add translation

We are currently looking to implement languages of all countries supported by meteoalarm. If you are able to add or improve translations in language you speak don't hastate to make a PR.
We are currently looking to implement languages of all countries supported by meteoalarm. If you are able to add or improve translations in language you speak don't hastate to make a PR. Some of the keys are replaced with `null` that means specified key is not yet translated.

1. Clone the repository - [How to run locally](#How-to-run-locally). Follow steps 1 and 2.
2. Copy `src/translations/en.json` file and name it with appropriate language code.
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ After completing installation you can add this card like any other to your dashb

Here is what configuration options mean:

| Name | Type | Default | Description |
| -------------- | --------- | ------------ | ----------------------------------------------------------------------- |
| `type` | `string` | **Required** | `custom:meteoalarm-card` |
| `entity` | `string` | **Required** | An entity_id with weather alerts |
| `integration` | `string` | **Required** | Name of the integration. `automatic`, `meteoalarm`, `meteofrance` or `meteoalarmeu`. It's recommended to keep this option at automatic |
| Name | Type | Default | Description |
| ------------------- | --------- | ------------ | -------------------------------------------------------------------------------- |
| `type` | `string` | **Required** | `custom:meteoalarm-card` |
| `entity` | `string` | **Required** | An entity_id with weather alerts |
| `integration` | `string` | **Required** | Name of the integration. `automatic`, `meteoalarm`, `meteofrance` or `meteoalarmeu`. It's recommended to keep this option at automatic |
| `override_headline` | `boolean` | `false` | Core Meteoalarm provides `event` and `headline` attributes which are used for text displayed on the card. This option forces card to always generate own headline.


## Supported languages

Expand Down
26 changes: 26 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,25 @@ export class MeteoalarmCardEditor extends LitElement
return '';
}

// eslint-disable-next-line
get _override_headline()
{
if (this._config)
{
return this._config.override_headline || false;
}

return '';
}


render()
{
if (!this.hass) return html``;

return html`
<div class="card-config">
<!-- Enity Selector -->
<ha-entity-picker
label=${`${localize('editor.entity')} (${localize('editor.required')})`}
.hass=${this.hass}
Expand All @@ -64,6 +76,7 @@ export class MeteoalarmCardEditor extends LitElement
allow-custom-entity
></ha-entity-picker>
<!-- Integration Selector -->
<paper-dropdown-menu
label=${`${localize('editor.integration')} (${localize('editor.required')})`}
@value-changed=${this._valueChanged}
Expand All @@ -79,6 +92,19 @@ export class MeteoalarmCardEditor extends LitElement
})}
</paper-listbox>
</paper-dropdown-menu>
<!-- Override headline -->
${this._integration == 'automatic' || this._integration == 'meteoalarm' ? html`
<p class="option">
<ha-switch
.checked=${this._override_headline !== false}
.configValue=${'override_headline'}
@change=${this._valueChanged}
>
</ha-switch>
${localize('editor.override_headline')}
</p>
`: ''}
</div>
`;
}
Expand Down
7 changes: 6 additions & 1 deletion src/meteoalarm-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class MeteoalarmCard extends LitElement
return this.hass.states[this.config.entity];
}

get overrideHeadline()
{
return this.config.override_headline === true;
}

get integration()
{
return this.keyToIntegration(this.config.integration)
Expand Down Expand Up @@ -143,7 +148,7 @@ class MeteoalarmCard extends LitElement
...this.integration.getResult(entity)
}

if(result.headline == undefined)
if(result.headline === undefined || this.overrideHeadline)
{
result.headline = this.generateHeadline(result.awarenessType, result.awarenessLevel)
}
Expand Down
5 changes: 3 additions & 2 deletions src/translations/de.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Meteoalarm-Karte",
"description": "Die Meteoalarm-Karte warnt dich vor bevorstehenden Wetterereignissen.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Keine Warnungen",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Meteoalarm Card",
"description": "Meteoalarm card warns you about current weather events.",
Expand All @@ -15,7 +15,8 @@
"integration": "Integration",
"required": "Required",
"automatic": "Automatic",
"recommended": "Recommended"
"recommended": "Recommended",
"override_headline": "Override headline"
},
"events": {
"no_warnings": "No warnings",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/es.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Tarjeta Meteoalarm",
"description": "La tarjeta Meteoalarm le advierte sobre eventos meteorológicos actuales.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Sin avisos",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/et.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Ohtlike ilmanähtuste kaart",
"description": "Ohtlike ilmanähtuste kaart hoiatab ilmaohtude eest.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Hoiatusi hetkel pole",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/fr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Carte Meteoalarm",
"description": "Carte Meteoalarm vous alerte des conditions météorologique courante.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Aucune alerte",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/it.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Scheda Meteoalarm",
"description": "La scheda Meteoalarm ti informa degli eventi meteorologici in corso.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Nessun allarme",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/nl.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Meteoalarm Kaart",
"description": "Meteoalarm kaart waarschuwt u voor actuele weersomstandigheden.",
Expand All @@ -15,7 +15,8 @@
"integration": null,
"required": null,
"automatic": null,
"recommended": null
"recommended": null,
"override_headline": null
},
"events": {
"no_warnings": "Geen waarschuwingen",
Expand Down
5 changes: 3 additions & 2 deletions src/translations/pl.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "../schema.json",
"$schema": "./schema.json",
"common": {
"name": "Karta Meteoalarm",
"description": "Meteoalarm ostrzega cię przed aktualnymi zdarzeniami pogodowymi.",
Expand All @@ -15,7 +15,8 @@
"integration": "Integracja",
"required": "Wymagane",
"automatic": "Automatyczne",
"recommended": "Zalecane"
"recommended": "Zalecane",
"override_headline": "Nadpisz nagłówek"
},
"events": {
"no_warnings": "Brak ostrzeżeń",
Expand Down
7 changes: 6 additions & 1 deletion src/schema.json → src/translations/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"integration",
"required",
"automatic",
"recommended"
"recommended",
"override_headline"
],
"properties": {
"entity": {
Expand All @@ -92,6 +93,10 @@
"recommended": {
"$id": "#/properties/editor/properties/recommended",
"type": ["string", "null"]
},
"override_headline": {
"$id": "#/properties/editor/properties/override_headline",
"type": ["string", "null"]
}
},
"additionalProperties": false
Expand Down

0 comments on commit 09cd6d6

Please sign in to comment.