Improvements for customize config panel (#415)

* Don't save empty json values. Allow per-domain attributes.

* Fix typo
This commit is contained in:
Andrey 2017-08-29 19:44:05 +03:00 committed by Paulus Schoutsen
parent 206f624fb6
commit 5bdbc49dc2
4 changed files with 35 additions and 34 deletions

View File

@ -32,7 +32,7 @@
<span slot='header'>Customization</span> <span slot='header'>Customization</span>
<span slot='introduction'> <span slot='introduction'>
Tweak per-entity attributes.<br> Tweak per-entity attributes.<br>
Added/edited customizations will take effect immidiately. Removed customizations will take effect when the entity is updated. Added/edited customizations will take effect immediately. Removed customizations will take effect when the entity is updated.
</span> </span>
<ha-entity-config <ha-entity-config
hass='[[hass]]' hass='[[hass]]'

View File

@ -160,7 +160,9 @@ class HaFormCustomize extends Polymer.Element {
this.globalAttributes, this.existingAttributes, this.newAttributes); this.globalAttributes, this.existingAttributes, this.newAttributes);
attrs.forEach((attr) => { attrs.forEach((attr) => {
if (attr.closed || attr.secondary || !attr.attribute || !attr.value) return; if (attr.closed || attr.secondary || !attr.attribute || !attr.value) return;
data[attr.attribute] = (attr.type === 'json' ? JSON.parse(attr.value) : attr.value); const value = attr.type === 'json' ? JSON.parse(attr.value) : attr.value;
if (!value) return;
data[attr.attribute] = value;
}); });
const objectId = this.entity.entity_id; const objectId = this.entity.entity_id;
@ -213,7 +215,11 @@ class HaFormCustomize extends Polymer.Element {
getNewAttributesOptions(localAttributes, globalAttributes, existingAttributes, newAttributes) { getNewAttributesOptions(localAttributes, globalAttributes, existingAttributes, newAttributes) {
const knownKeys = const knownKeys =
Object.keys(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES) Object.keys(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES)
.filter(key => window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key]) .filter((key) => {
const conf = window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key];
return conf && (!conf.domains || !this.entity ||
conf.domains.includes(window.hassUtil.computeDomain(this.entity)));
})
.filter(this.filterFromAttributes(localAttributes)) .filter(this.filterFromAttributes(localAttributes))
.filter(this.filterFromAttributes(globalAttributes)) .filter(this.filterFromAttributes(globalAttributes))
.filter(this.filterFromAttributes(existingAttributes)) .filter(this.filterFromAttributes(existingAttributes))

View File

@ -44,13 +44,8 @@ class HaCustomizeArray extends window.hassMixins.EventsMixin(Polymer.Element) {
} }
getOptions(item) { getOptions(item) {
const domain = item.domain; const domain = item.domain || '*';
if (!domain) { const options = item.options[domain] || item.options['*'];
this.item.type = 'string';
this.fire('item-changed');
return [];
}
const options = item.options[domain];
if (!options) { if (!options) {
this.item.type = 'string'; this.item.type = 'string';
this.fire('item-changed'); this.fire('item-changed');

View File

@ -24,27 +24,27 @@ window.hassAttributeUtil.TYPE_TO_TAG = {
// 1) Any key of this object won't be shown in more-info window. // 1) Any key of this object won't be shown in more-info window.
// 2) Any key which has value other than undefined will appear in customization // 2) Any key which has value other than undefined will appear in customization
// config according to its value. // config according to its value.
// TODO: Allow per-domain config, as some attributes are only relevant for some window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES =
// domains. window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES || {
window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES = { entity_picture: undefined,
entity_picture: undefined, friendly_name: { type: 'string', description: 'Name' },
friendly_name: { type: 'string', description: 'Name' }, icon: { type: 'icon' },
icon: { type: 'icon' }, emulated_hue: { type: 'boolean' },
emulated_hue: { type: 'boolean' }, emulated_hue_name: { type: 'string' },
emulated_hue_name: { type: 'string' }, haaska_hidden: undefined,
haaska_hidden: undefined, haaska_name: undefined,
haaska_name: undefined, homebridge_hidden: { type: 'boolean' },
homebridge_hidden: { type: 'boolean' }, homebridge_name: { type: 'string' },
homebridge_name: { type: 'string' }, supported_features: undefined,
supported_features: undefined, attribution: undefined,
attribution: undefined, custom_ui_state_card: { type: 'string' },
custom_ui_state_card: { type: 'string' }, device_class: {
device_class: { type: 'array',
type: 'array', options: window.hassAttributeUtil.DOMAIN_DEVICE_CLASS,
options: window.hassAttributeUtil.DOMAIN_DEVICE_CLASS, description: 'Device class',
description: 'Device class' }, domains: ['binary_sensor', 'cover'] },
hidden: { type: 'boolean', description: 'Hide from UI' }, hidden: { type: 'boolean', description: 'Hide from UI' },
assumed_state: { type: 'boolean' }, assumed_state: { type: 'boolean' },
initial_state: { type: 'string' }, initial_state: { type: 'string' },
unit_of_measurement: { type: 'string' }, unit_of_measurement: { type: 'string' },
}; };