Fill example data for services in dev tools (#3596)

* Fill example data

* Align indents

* Comments
This commit is contained in:
Bram Kragten 2019-09-05 15:57:17 +02:00 committed by Paulus Schoutsen
parent 3927eb53ac
commit 460a56aa0a

View File

@ -115,9 +115,9 @@ class HaPanelDevService extends PolymerElement {
autocomplete="off" autocomplete="off"
spellcheck="false" spellcheck="false"
></paper-textarea> ></paper-textarea>
<mwc-button on-click="_callService" raised disabled="[[!validJSON]]" <mwc-button on-click="_callService" raised disabled="[[!validJSON]]">
>Call Service</mwc-button Call Service
> </mwc-button>
<template is="dom-if" if="[[!validJSON]]"> <template is="dom-if" if="[[!validJSON]]">
<span class="error">Invalid JSON</span> <span class="error">Invalid JSON</span>
</template> </template>
@ -153,6 +153,12 @@ class HaPanelDevService extends PolymerElement {
</tr> </tr>
</template> </template>
</table> </table>
<template is="dom-if" if="[[_attributes.length]]">
<mwc-button on-click="_fillExampleData">
Fill Example Data
</mwc-button>
</template>
</template> </template>
</template> </template>
</div> </div>
@ -274,11 +280,17 @@ class HaPanelDevService extends PolymerElement {
this.hass.callService(this._domain, this._service, this.parsedJSON); this.hass.callService(this._domain, this._service, this.parsedJSON);
} }
_fillExampleData() {
const example = {};
for (const attribute of this._attributes) {
example[attribute.key] = attribute.example;
}
this.serviceData = JSON.stringify(example, null, 2);
}
_entityPicked(ev) { _entityPicked(ev) {
this.serviceData = JSON.stringify( this.serviceData = JSON.stringify(
Object.assign({}, this.parsedJSON, { { ...this.parsedJSON, entity_id: ev.target.value },
entity_id: ev.target.value,
}),
null, null,
2 2
); );