Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link functionality to shortcuts #323

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,15 @@ You can defined service invocations to override default actions behavior. Availa

### `shortcuts` object

You can defined [custom scripts][ha-scripts] for custom actions i.e cleaning specific room and add them to this card with `shortcuts` option.
You can define [custom scripts][ha-scripts] for custom actions i.e cleaning specific room and add them to this card with `shortcuts` option by using the `service` and `service_data` options or create a clickable link with the `link` 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. |
| `service_data` | `object` | `service_data` for `service` call |
| `service` | `string` | Optional | A service to call, i.e. `script.clean_bedroom`. |
| `service_data` | `object` | `service_data` for `service` call | |
| `link` | `string` | Optional | Creates a web link, i.e. `https://vacuum.webui` |

## Animations

Expand Down
20 changes: 13 additions & 7 deletions src/vacuum-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,13 +455,19 @@ class VacuumCard extends LitElement {
const { shortcuts = [] } = this.config;

const buttons = shortcuts.map(
({ name, service, icon, service_data }) => {
const execute = () => {
this.callAction({ service, service_data });
};
return html`<ha-icon-button title="${name}" @click="${execute}"
><ha-icon icon="${icon}"></ha-icon
></ha-icon-button>`;
({ name, service, icon, service_data, link }) => {
if (link) {
return html`<ha-icon-button title="${name}"
><a rel="noreferrer" href="${link}" target="_blank"><ha-icon icon="${icon}"></ha-icon
></ha-icon-button>`;
} else {
const execute = () => {
this.callAction({ service, service_data });
};
return html`<ha-icon-button title="${name}" @click="${execute}"
><ha-icon icon="${icon}"></ha-icon
></ha-icon-button>`;
}
}
);

Expand Down