Skip to content
Merged
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
47 changes: 34 additions & 13 deletions src/panels/developer-tools/service/developer-tools-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ import "../../../components/ha-code-editor";
import "../../../components/ha-service-picker";
import "../../../resources/ha-style";
import "../../../util/app-localstorage-document";
import LocalizeMixin from "../../../mixins/localize-mixin";

const ERROR_SENTINEL = {};
class HaPanelDevService extends PolymerElement {
/*
* @appliesMixin LocalizeMixin
*/
class HaPanelDevService extends LocalizeMixin(PolymerElement) {
static get template() {
return html`
<style include="ha-style">
Expand Down Expand Up @@ -94,8 +98,7 @@ class HaPanelDevService extends PolymerElement {

<div class="content">
<p>
The service dev tool allows you to call any available service in Home
Assistant.
[[localize('ui.panel.developer-tools.tabs.services.description')]]
</p>

<div class="ha-form">
Expand All @@ -113,38 +116,50 @@ class HaPanelDevService extends PolymerElement {
allow-custom-entity
></ha-entity-picker>
</template>
<p>Service Data (YAML, optional)</p>
<p>[[localize('ui.panel.developer-tools.tabs.services.data')]]</p>
<ha-code-editor
mode="yaml"
value="[[serviceData]]"
error="[[!validJSON]]"
on-value-changed="_yamlChanged"
></ha-code-editor>
<mwc-button on-click="_callService" raised disabled="[[!validJSON]]">
Call Service
[[localize('ui.panel.developer-tools.tabs.services.call_service')]]
</mwc-button>
</div>

<template is="dom-if" if="[[!domainService]]">
<h1>Select a service to see the description</h1>
<h1>
[[localize('ui.panel.developer-tools.tabs.services.select_service')]]
</h1>
</template>

<template is="dom-if" if="[[domainService]]">
<template is="dom-if" if="[[!_description]]">
<h1>No description is available</h1>
<h1>
[[localize('ui.panel.developer-tools.tabs.services.no_description')]]
</h1>
</template>
<template is="dom-if" if="[[_description]]">
<h3>[[_description]]</h3>

<table class="attributes">
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Example</th>
<th>
[[localize('ui.panel.developer-tools.tabs.services.column_parameter')]]
</th>
<th>
[[localize('ui.panel.developer-tools.tabs.services.column_description')]]
</th>
<th>
[[localize('ui.panel.developer-tools.tabs.services.column_example')]]
</th>
</tr>
<template is="dom-if" if="[[!_attributes.length]]">
<tr>
<td colspan="3">This service takes no parameters.</td>
<td colspan="3">
[[localize('ui.panel.developer-tools.tabs.services.no_parameters')]]
</td>
</tr>
</template>
<template is="dom-repeat" items="[[_attributes]]" as="attribute">
Expand All @@ -158,7 +173,7 @@ class HaPanelDevService extends PolymerElement {

<template is="dom-if" if="[[_attributes.length]]">
<mwc-button on-click="_fillExampleData">
Fill Example Data
[[localize('ui.panel.developer-tools.tabs.services.fill_example_data')]]
</mwc-button>
</template>
</template>
Expand Down Expand Up @@ -276,7 +291,13 @@ class HaPanelDevService extends PolymerElement {
_callService() {
if (this.parsedJSON === ERROR_SENTINEL) {
// eslint-disable-next-line
alert(`Error parsing YAML: ${this.serviceData}`);
alert(
this.hass.localize(
"ui.panel.developer-tools.tabs.services.alert_parsing_yaml",
"data",
this.serviceData
)
);
return;
}

Expand Down
13 changes: 12 additions & 1 deletion src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1807,7 +1807,18 @@
"title": "MQTT"
},
"services": {
"title": "Services"
"title": "Services",
"description": "The service dev tool allows you to call any available service in Home Assistant.",
"data": "Service Data (YAML, optional)",
"call_service": "Call Service",
"select_service": "Select a service to see the description",
"no_description": "No description is available",
"no_parameters": "This service takes no parameters.",
"column_parameter": "Parameter",
"column_description": "Description",
"column_example": "Example",
"fill_example_data": "Fill Example Data",
"alert_parsing_yaml": "Error parsing YAML: {data}"
},
"states": {
"title": "States"
Expand Down