Allow changing entity id (#1508)

* Allow changing entity id

* _entityId

* Use set properties
This commit is contained in:
Paulus Schoutsen 2018-07-24 14:07:40 +02:00 committed by GitHub
parent 201959841c
commit f7d9aecf47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 5 deletions

View File

@ -48,7 +48,14 @@ class MoreInfoSettings extends LocalizeMixin(EventsMixin(PolymerElement)) {
</app-toolbar> </app-toolbar>
<div class="form"> <div class="form">
<paper-input value="{{_name}}" label="[[localize('ui.dialogs.more_info_settings.name')]]"></paper-input> <paper-input
value="{{_name}}"
label="[[localize('ui.dialogs.more_info_settings.name')]]"
></paper-input>
<paper-input
value="{{_entityId}}"
label="[[localize('ui.dialogs.more_info_settings.entity_id')]]"
></paper-input>
</div> </div>
`; `;
} }
@ -70,6 +77,7 @@ class MoreInfoSettings extends LocalizeMixin(EventsMixin(PolymerElement)) {
}, },
_name: String, _name: String,
_entityId: String,
}; };
} }
@ -84,9 +92,15 @@ class MoreInfoSettings extends LocalizeMixin(EventsMixin(PolymerElement)) {
_registryInfoChanged(newVal) { _registryInfoChanged(newVal) {
if (newVal) { if (newVal) {
this._name = newVal.name; this.setProperties({
_name: newVal.name,
_entityId: newVal.entity_id,
});
} else { } else {
this._name = ''; this.setProperties({
_name: '',
_entityId: '',
});
} }
} }
@ -100,10 +114,17 @@ class MoreInfoSettings extends LocalizeMixin(EventsMixin(PolymerElement)) {
type: 'config/entity_registry/update', type: 'config/entity_registry/update',
entity_id: this.stateObj.entity_id, entity_id: this.stateObj.entity_id,
name: this._name, name: this._name,
new_entity_id: this._entityId,
}); });
this.registryInfo = info; this.registryInfo = info;
// Keep the more info dialog open at the new entity.
if (this.stateObj.entity_id !== this._entityId) {
this.fire('hass-more-info', { entityId: this._entityId });
}
} catch (err) { } catch (err) {
alert('save failed!'); alert(`save failed: ${err.message}`);
} }
} }
} }

View File

@ -437,7 +437,8 @@
"dialogs": { "dialogs": {
"more_info_settings": { "more_info_settings": {
"save": "Save", "save": "Save",
"name": "Name" "name": "Name",
"entity_id": "Entity ID"
} }
}, },
"duration": { "duration": {