diff --git a/src/cards/ValveCard.ts b/src/cards/ValveCard.ts new file mode 100644 index 0000000..e9a5e38 --- /dev/null +++ b/src/cards/ValveCard.ts @@ -0,0 +1,57 @@ +// noinspection JSUnusedGlobalSymbols Class is dynamically imported. + +import { EntityRegistryEntry } from '../types/homeassistant/data/entity_registry'; +import { TemplateCardConfig } from '../types/lovelace-mushroom/cards/template-card-config'; +import { localize } from '../utilities/localize'; +import AbstractCard from './AbstractCard'; + +/** + * Valve Card Class + * + * Used to create a card configuration to control an entity of the valve domain. + */ +class ValveCard extends AbstractCard { + /** Returns the default configuration object for the card. */ + static getDefaultConfig(): TemplateCardConfig { + return { + type: 'custom:mushroom-template-card', + icon: 'mdi:valve', + icon_color: 'blue', + double_tap_action: { + action: 'toggle', + }, + }; + } + + /** + * Class constructor. + * + * @param {EntityRegistryEntry} entity The HASS entity to create a card configuration for. + * @param {VacuumCardConfig} [customConfiguration] Custom card configuration. + */ + constructor(entity: EntityRegistryEntry, customConfiguration?: TemplateCardConfig) { + super(entity); + + // Initialize the default configuration. + const configuration = ValveCard.getDefaultConfig(); + + configuration.entity = entity.entity_id; + configuration.icon = entity.icon ?? configuration.icon; + configuration.primary = entity.name ?? entity.original_name ?? '?'; + configuration.secondary = `{% + set mapping = { + 'open': '${localize('valve.open')}', + 'opening': '${localize('valve.opening')}', + 'closed': '${localize('valve.closed')}', + 'closing': '${localize('valve.closing')}', + 'stopped': '${localize('valve.stopped')}', + 'unavailable': '${localize('generic.unavailable')}' + } + %} + {{ mapping.get(states('${entity.entity_id}'), '${localize('generic.unknown')}') }}`; + + this.configuration = { ...this.configuration, ...configuration, ...customConfiguration }; + } +} + +export default ValveCard; diff --git a/src/translations/de.json b/src/translations/de.json index a3c4320..731220d 100644 --- a/src/translations/de.json +++ b/src/translations/de.json @@ -29,8 +29,10 @@ "off": "Aus", "on": "Ein", "open": "Offen", + "unavailable": "Nicht verfügbar", "unclosed": "Nicht Geschlossen", - "undisclosed": "Sonstiges" + "undisclosed": "Sonstiges", + "unknown": "Unbekannt" }, "input_select": { "input_selects": "Auswahl-Eingaben" @@ -65,5 +67,14 @@ "vacuum": { "all_vacuums": "Alle Staubsauger", "vacuums": "Staubsauger" + }, + "valve": { + "all_valves": "Alle Ventile", + "valves": "Ventile", + "open": "Offen", + "opening": "Öffnet", + "closed": "Geschlossen", + "closing": "Schließt", + "stopped": "Gestoppt" } } diff --git a/src/translations/en.json b/src/translations/en.json index 80b9b63..1ec9369 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -29,8 +29,10 @@ "off": "Off", "on": "On", "open": "Open", + "unavailable": "Unavailable", "unclosed": "Unclosed", - "undisclosed": "Other" + "undisclosed": "Other", + "unknown": "Unknown" }, "input_select": { "input_selects": "Input Selects" @@ -65,5 +67,14 @@ "vacuum": { "all_vacuums": "All Vacuums", "vacuums": "Vacuums" + }, + "valve": { + "all_valves": "All Valves", + "valves": "Valves", + "open": "Open", + "opening": "Opening", + "closed": "Closed", + "closing": "Closing", + "stopped": "Stopped" } } diff --git a/src/translations/es.json b/src/translations/es.json index 333024c..a991c95 100644 --- a/src/translations/es.json +++ b/src/translations/es.json @@ -29,8 +29,10 @@ "off": "Apagado", "on": "Encendido", "open": "Abierto", + "unavailable": "No Disponible", "unclosed": "Sin Cerrar", - "undisclosed": "Varios" + "undisclosed": "Varios", + "unknown": "Desconocido" }, "input_select": { "input_selects": "Selecciones de Entrada" @@ -65,5 +67,14 @@ "vacuum": { "all_vacuums": "Todas las Aspiradoras", "vacuums": "Aspiradoras" + }, + "valve": { + "all_valves": "Todas las válvulas", + "valves": "Válvulas", + "open": "Abierta", + "opening": "Abriendo", + "closed": "Cerrada", + "closing": "Cerrando", + "stopped": "Detenida" } } diff --git a/src/translations/nl.json b/src/translations/nl.json index dc53e97..30cbfa5 100644 --- a/src/translations/nl.json +++ b/src/translations/nl.json @@ -29,8 +29,10 @@ "off": "Uit", "on": "Aan", "open": "Open", + "unavailable": "Onbeschikbaar", "unclosed": "Ongesloten", - "undisclosed": "Overige" + "undisclosed": "Overige", + "unknown": "Onbekend" }, "input_select": { "input_selects": "Lijsten" @@ -65,5 +67,14 @@ "vacuum": { "all_vacuums": "Alle Afzuiging", "vacuums": "Afzuiging" + }, + "valve": { + "all_valves": "Alle kleppen", + "valves": "Kleppen", + "open": "Open", + "opening": "Openen", + "closed": "Gesloten", + "closing": "Sluiten", + "stopped": "Gestopt" } }