Skip to content

Commit

Permalink
feat: add target for service calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdovhan committed Jun 16, 2024
1 parent 125cb58 commit 5631cdf
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 86 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ You can defined service invocations to override default actions behavior. Availa

You can defined [custom scripts][ha-scripts] for custom actions i.e cleaning specific room and add them to this card with `shortcuts` option.

| Name | Type | Default | Description |
| -------------- | :------: | --------------------------------- | -------------------------------------------------- |
| `name` | `string` | Optional | Friendly name of the action, i.e. `Clean bedroom`. |
| `service` | `string` | Optional | A service to call, i.e. `script.clean_bedroom`. |
| `icon` | `string` | Optional | Any icon for action button. |
| Name | Type | Default | Description |
| -------------- | :------: | --------------------------------- | ----------------------------------------------------------------------- |
| `name` | `string` | Optional | Friendly name of the action, i.e. `Clean bedroom`. |
| `service` | `string` | Optional | A service to call, i.e. `script.clean_bedroom`. |
| `target` | `object` | Optional | A `HassServiceTarget`, to define a target for the current service call. |
| `icon` | `string` | Optional | Any icon for action button. |
| `service_data` | `object` | `service_data` for `service` call |

## Theming
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import localize from './localize';
import { VacuumCardConfig } from './types';

export default function buildConfig(
config?: Partial<VacuumCardConfig>
config?: Partial<VacuumCardConfig>,
): VacuumCardConfig {
if (!config) {
throw new Error(localize('error.invalid_config'));
Expand Down
22 changes: 12 additions & 10 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
validationMessage=${localize('error.missing_entity')}
>
${vacuumEntities.map(
(entity) => html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`
(entity) =>
html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`,
)}
</ha-select>
</div>
Expand All @@ -86,9 +87,10 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
naturalMenuWidth
>
${cameraEntities.map(
(entity) => html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`
(entity) =>
html` <mwc-list-item .value=${entity}
>${entity}</mwc-list-item
>`,
)}
</ha-select>
</div>
Expand All @@ -107,7 +109,7 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
aria-label=${localize(
this.compact_view
? 'editor.compact_view_aria_label_off'
: 'editor.compact_view_aria_label_on'
: 'editor.compact_view_aria_label_on',
)}
.checked=${Boolean(this.compact_view)}
.configValue=${'compact_view'}
Expand All @@ -122,7 +124,7 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
aria-label=${localize(
this.show_name
? 'editor.show_name_aria_label_off'
: 'editor.show_name_aria_label_on'
: 'editor.show_name_aria_label_on',
)}
.checked=${Boolean(this.show_name)}
.configValue=${'show_name'}
Expand All @@ -137,7 +139,7 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
aria-label=${localize(
this.show_status
? 'editor.show_status_aria_label_off'
: 'editor.show_status_aria_label_on'
: 'editor.show_status_aria_label_on',
)}
.checked=${Boolean(this.show_status)}
.configValue=${'show_status'}
Expand All @@ -152,7 +154,7 @@ export class VacuumCardEditor extends LitElement implements LovelaceCardEditor {
aria-label=${localize(
this.show_toolbar
? 'editor.show_toolbar_aria_label_off'
: 'editor.show_toolbar_aria_label_on'
: 'editor.show_toolbar_aria_label_on',
)}
.checked=${Boolean(this.show_toolbar)}
.configValue=${'show_toolbar'}
Expand Down
2 changes: 1 addition & 1 deletion src/localize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DEFAULT_LANG = 'en';
export default function localize(
str: string,
search?: string,
replace?: string
replace?: string,
): string | undefined {
const [section, key] = str.toLowerCase().split('.');

Expand Down
2 changes: 1 addition & 1 deletion src/translations/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@
"show_toolbar_aria_label_off": "Eszköztár megjelenítésének kikapcsolása",
"code_only_note": "Megjegyzés: A műveletek és statisztika beállítások kizárólag a kód szerkesztő használatával érhetők el."
}
}
}
2 changes: 1 addition & 1 deletion src/translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"show_name_aria_label_off": "Disattiva nome",
"show_status": "Mostra Stato",
"show_status_aria_label_on": "Attiva stato",
"show_status_aria_label_off": "Disattiva stato",
"show_status_aria_label_off": "Disattiva stato",
"show_toolbar": "Mostra barra degli strumenti",
"show_toolbar_aria_label_on": "Attiva barra degli strumenti",
"show_toolbar_aria_label_off": "Disattiva barra degli strumenti",
Expand Down
126 changes: 63 additions & 63 deletions src/translations/pt-BR.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"status": {
"cleaning": "Limpando",
"auto": "Limpeza automatica",
"spot": "Limpando local",
"edge": "Limpando borda",
"single_room": "Limpando um quarto",
"paused": "Em pausa",
"idle": "Ocioso",
"stop": "Parado",
"charging": "Carregando",
"returning home": "Voltando à base",
"returning": "Voltando",
"docked": "Na base",
"unknown": "Desconhecido",
"offline": "Offline",
"error": "Erro"
},
"source": {
"gentle": "Delicado",
"silent": "Silencioso",
"standard": "Padrão",
"medium": "Médio",
"turbo": "Turbo",
"normal": "Normal",
"high": "Alto",
"strong": "Forte"
},
"common": {
"name": "Vacuum Card",
"description": "Vacuum card para controlar seu robô aspirador.",
"start": "Limpar",
"continue": "Continuar",
"pause": "Pausa",
"stop": "Parar",
"return_to_base": "Retornar à base",
"locate": "Localizar aspirador",
"not_available": "Aspirador indisponível"
},
"error": {
"missing_entity": "Entidade obrigatória"
},
"warning": {
"actions_array": "AVISO: 'actions' são reservadas para substituir as ações padrões para botões existentes. Se sua intenção era adicionar ações adicionais, use a opção 'shortcuts'."
},
"editor": {
"entity": "Entidade (Obrigatória)",
"map": "Mapa (Opcional)",
"image": "Imagem (Opcional)",
"compact_view": "Vista Compacta",
"compact_view_aria_label_on": "Ativar visualização compacta",
"compact_view_aria_label_off": "Desativar visualização compacta",
"show_name": "Mostrar nome",
"show_name_aria_label_on": "Mostrar nome",
"show_name_aria_label_off": "Ocultar nome",
"show_status": "Mostrar estado",
"show_status_aria_label_on": "Mostrar estado",
"show_status_aria_label_off": "Ocultar estado",
"show_toolbar": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_on": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_off": "Ocultar barra de ferramentas",
"code_only_note": "Nota: Ações e estatísticas estão disponiveis exclusivamente usando o editor de código."
}
}
"status": {
"cleaning": "Limpando",
"auto": "Limpeza automatica",
"spot": "Limpando local",
"edge": "Limpando borda",
"single_room": "Limpando um quarto",
"paused": "Em pausa",
"idle": "Ocioso",
"stop": "Parado",
"charging": "Carregando",
"returning home": "Voltando à base",
"returning": "Voltando",
"docked": "Na base",
"unknown": "Desconhecido",
"offline": "Offline",
"error": "Erro"
},
"source": {
"gentle": "Delicado",
"silent": "Silencioso",
"standard": "Padrão",
"medium": "Médio",
"turbo": "Turbo",
"normal": "Normal",
"high": "Alto",
"strong": "Forte"
},
"common": {
"name": "Vacuum Card",
"description": "Vacuum card para controlar seu robô aspirador.",
"start": "Limpar",
"continue": "Continuar",
"pause": "Pausa",
"stop": "Parar",
"return_to_base": "Retornar à base",
"locate": "Localizar aspirador",
"not_available": "Aspirador indisponível"
},
"error": {
"missing_entity": "Entidade obrigatória"
},
"warning": {
"actions_array": "AVISO: 'actions' são reservadas para substituir as ações padrões para botões existentes. Se sua intenção era adicionar ações adicionais, use a opção 'shortcuts'."
},
"editor": {
"entity": "Entidade (Obrigatória)",
"map": "Mapa (Opcional)",
"image": "Imagem (Opcional)",
"compact_view": "Vista Compacta",
"compact_view_aria_label_on": "Ativar visualização compacta",
"compact_view_aria_label_off": "Desativar visualização compacta",
"show_name": "Mostrar nome",
"show_name_aria_label_on": "Mostrar nome",
"show_name_aria_label_off": "Ocultar nome",
"show_status": "Mostrar estado",
"show_status_aria_label_on": "Mostrar estado",
"show_status_aria_label_off": "Ocultar estado",
"show_toolbar": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_on": "Mostrar barra de ferramentas",
"show_toolbar_aria_label_off": "Ocultar barra de ferramentas",
"code_only_note": "Nota: Ações e estatísticas estão disponiveis exclusivamente usando o editor de código."
}
}
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
HassEntityAttributeBase,
HassEntityBase,
HassServiceTarget,
} from 'home-assistant-js-websocket';
import { TemplateResult, nothing } from 'lit';

Expand Down Expand Up @@ -44,13 +45,15 @@ export interface VacuumCardStat {
export interface VacuumCardAction {
service: string;
service_data?: Record<string, unknown>;
target?: HassServiceTarget;
}

export interface VacuumCardShortcut {
name?: string;
icon?: string;
service?: string;
service_data?: Record<string, unknown>;
target?: HassServiceTarget;
}

export interface VacuumCardConfig {
Expand Down
8 changes: 4 additions & 4 deletions src/vacuum-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export class VacuumCard extends LitElement {
}

private callService(action: VacuumCardAction) {
const { service, service_data } = action;
const { service, service_data, target } = action;
const [domain, name] = service.split('.');
this.hass.callService(domain, name, service_data);
this.hass.callService(domain, name, service_data, target);
}

private callVacuumService(
Expand Down Expand Up @@ -409,10 +409,10 @@ export class VacuumCard extends LitElement {
case 'idle':
default: {
const buttons = this.config.shortcuts.map(
({ name, service, icon, service_data }) => {
({ name, service, icon, service_data, target }) => {
const execute = () => {
if (service) {
return this.callService({ service, service_data });
return this.callService({ service, service_data, target });
}
};
return html`
Expand Down

0 comments on commit 5631cdf

Please sign in to comment.