Skip to content

Commit

Permalink
Support navigation action on tap actions (#66, #82)
Browse files Browse the repository at this point in the history
  • Loading branch information
benct committed Oct 7, 2020
1 parent e399469 commit e61e1a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ If `toggle` is set to `true` the default action is `toggle`, otherwise it is `mo

| Name | Type | Default | Description
| ---- | ---- | ------- | -----------
| action | string | **Required** | Action to perform (`more-info`, `toggle`, `call-service`, `url`, `none`)
| action | string | **Required** | Action to perform (`more-info`, `toggle`, `call-service`, `url`, `navigate`, `none`)
| service | string | | Service to call (e.g. `light.turn_on`) when `action` is `call-service`
| service_data | object | | Optional data to include when `action` is `call-service`
| url_path | string | | URL to open when `action` is `url`
| navigation_path | string | | Path to navigate to when `action` is `navigate`
| confirmation | bool/string | `false` | Enable/set text to present in a confirmation dialog
| entity | string | | A valid entity_id override when `action` is `more-info`

Expand Down
20 changes: 14 additions & 6 deletions multiple-entity-row.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
}
const confirmation = config.confirmation === true ? 'Are you sure?' : config.confirmation;
if (config.action === 'call-service') {
const [domain, service] = config.service.split(".");
const [domain, service] = config.service.split('.');
return () => {
if (!confirmation || confirm(confirmation)) {
this._hass.callService(domain, service, config.service_data);
Expand All @@ -311,26 +311,34 @@
}
}
}
if (config.action === 'navigate') {
return () => {
if (config.navigation_path && (!confirmation || confirm(confirmation))) {
history.pushState(null, '', config.navigation_path);
this.fireEvent(window, 'location-changed', {replace: false});
}
}
}
}
return this.moreInfoAction(config, entityId);
}

moreInfoAction(config, entityId) {
return () => this.fireEvent('hass-more-info', (config && config.entity) || entityId);
return () => this.fireEvent(this, 'hass-more-info', {entityId: (config && config.entity) || entityId});
}

fireEvent(type, entity, options = {}) {
fireEvent(node, type, detail = {}, options = {}) {
const event = new Event(type, {
bubbles: options.bubbles || true,
cancelable: options.cancelable || true,
composed: options.composed || true,
});
event.detail = {entityId: entity};
this.dispatchEvent(event);
event.detail = detail;
node.dispatchEvent(event);
}

forwardHaptic(type) {
const event = new Event("haptic", {bubbles: true, cancelable: false, composed: true});
const event = new Event('haptic', {bubbles: true, cancelable: false, composed: true});
event.detail = type;
this.dispatchEvent(event);
}
Expand Down

0 comments on commit e61e1a4

Please sign in to comment.