mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-09 18:36:35 +00:00
Inline hass-attribute-util (#1196)
This commit is contained in:
parent
1d144a101c
commit
4de7cbec30
@ -2,7 +2,7 @@ import '@polymer/iron-flex-layout/iron-flex-layout-classes.js';
|
||||
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||
|
||||
import '../util/hass-attributes-util.js';
|
||||
import hassAttributeUtil from '../util/hass-attributes-util.js';
|
||||
|
||||
class HaAttributes extends PolymerElement {
|
||||
static get template() {
|
||||
@ -47,7 +47,7 @@ class HaAttributes extends PolymerElement {
|
||||
}
|
||||
|
||||
computeFiltersArray(extraFilters) {
|
||||
return Object.keys(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES).concat(extraFilters ? extraFilters.split(',') : []);
|
||||
return Object.keys(hassAttributeUtil.LOGIC_STATE_ATTRIBUTES).concat(extraFilters ? extraFilters.split(',') : []);
|
||||
}
|
||||
|
||||
computeDisplayAttributes(stateObj, filtersArray) {
|
||||
|
@ -2,7 +2,7 @@ import '@polymer/paper-icon-button/paper-icon-button.js';
|
||||
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||
|
||||
import '../../../util/hass-attributes-util.js';
|
||||
import hassAttributeUtil from '../../../util/hass-attributes-util.js';
|
||||
import '../ha-form-style.js';
|
||||
import './types/ha-customize-array.js';
|
||||
import './types/ha-customize-boolean.js';
|
||||
@ -56,7 +56,7 @@ class HaCustomizeAttribute extends PolymerElement {
|
||||
|
||||
itemObserver(item) {
|
||||
const wrapper = this.$.wrapper;
|
||||
const tag = window.hassAttributeUtil.TYPE_TO_TAG[item.type].toUpperCase();
|
||||
const tag = hassAttributeUtil.TYPE_TO_TAG[item.type].toUpperCase();
|
||||
let child;
|
||||
if (wrapper.lastChild && wrapper.lastChild.tagName === tag) {
|
||||
child = wrapper.lastChild;
|
||||
|
@ -4,7 +4,7 @@ import '@polymer/paper-listbox/paper-listbox.js';
|
||||
import { html } from '@polymer/polymer/lib/utils/html-tag.js';
|
||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
||||
|
||||
import '../../../util/hass-attributes-util.js';
|
||||
import hassAttributeUtil from '../../../util/hass-attributes-util.js';
|
||||
import './ha-form-customize-attributes.js';
|
||||
|
||||
import computeStateDomain from '../../../common/entity/compute_state_domain';
|
||||
@ -152,8 +152,8 @@ class HaFormCustomize extends PolymerElement {
|
||||
}
|
||||
|
||||
_computeSingleAttribute(key, value, secondary) {
|
||||
const config = window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key]
|
||||
|| { type: window.hassAttributeUtil.UNKNOWN_TYPE };
|
||||
const config = hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key]
|
||||
|| { type: hassAttributeUtil.UNKNOWN_TYPE };
|
||||
return this._initOpenObject(key, config.type === 'json' ? JSON.stringify(value) : value, secondary, config);
|
||||
}
|
||||
|
||||
@ -196,9 +196,9 @@ class HaFormCustomize extends PolymerElement {
|
||||
|
||||
getNewAttributesOptions(localAttributes, globalAttributes, existingAttributes, newAttributes) {
|
||||
const knownKeys =
|
||||
Object.keys(window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES)
|
||||
Object.keys(hassAttributeUtil.LOGIC_STATE_ATTRIBUTES)
|
||||
.filter((key) => {
|
||||
const conf = window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key];
|
||||
const conf = hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key];
|
||||
return conf && (!conf.domains || !this.entity ||
|
||||
conf.domains.includes(computeStateDomain(this.entity)));
|
||||
})
|
||||
@ -214,7 +214,7 @@ class HaFormCustomize extends PolymerElement {
|
||||
const option = this.newAttributesOptions[selected];
|
||||
if (selected === this.newAttributesOptions.length - 1) {
|
||||
// The "Other" option.
|
||||
const attr = this._initOpenObject('', '', false /* secondary */, { type: window.hassAttributeUtil.ADD_TYPE });
|
||||
const attr = this._initOpenObject('', '', false /* secondary */, { type: hassAttributeUtil.ADD_TYPE });
|
||||
this.push('newAttributes', attr);
|
||||
this.selectedNewAttribute = -1;
|
||||
return;
|
||||
|
@ -1,6 +1,6 @@
|
||||
window.hassAttributeUtil = window.hassAttributeUtil || {};
|
||||
const hassAttributeUtil = {};
|
||||
|
||||
window.hassAttributeUtil.DOMAIN_DEVICE_CLASS = {
|
||||
hassAttributeUtil.DOMAIN_DEVICE_CLASS = {
|
||||
binary_sensor: [
|
||||
'battery',
|
||||
'cold',
|
||||
@ -35,10 +35,10 @@ window.hassAttributeUtil.DOMAIN_DEVICE_CLASS = {
|
||||
],
|
||||
};
|
||||
|
||||
window.hassAttributeUtil.UNKNOWN_TYPE = 'json';
|
||||
window.hassAttributeUtil.ADD_TYPE = 'key-value';
|
||||
hassAttributeUtil.UNKNOWN_TYPE = 'json';
|
||||
hassAttributeUtil.ADD_TYPE = 'key-value';
|
||||
|
||||
window.hassAttributeUtil.TYPE_TO_TAG = {
|
||||
hassAttributeUtil.TYPE_TO_TAG = {
|
||||
string: 'ha-customize-string',
|
||||
json: 'ha-customize-string',
|
||||
icon: 'ha-customize-icon',
|
||||
@ -51,8 +51,8 @@ window.hassAttributeUtil.TYPE_TO_TAG = {
|
||||
// 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
|
||||
// config according to its value.
|
||||
window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES =
|
||||
window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES || {
|
||||
hassAttributeUtil.LOGIC_STATE_ATTRIBUTES =
|
||||
hassAttributeUtil.LOGIC_STATE_ATTRIBUTES || {
|
||||
entity_picture: undefined,
|
||||
friendly_name: { type: 'string', description: 'Name' },
|
||||
icon: { type: 'icon' },
|
||||
@ -74,7 +74,7 @@ window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES =
|
||||
custom_ui_state_card: { type: 'string' },
|
||||
device_class: {
|
||||
type: 'array',
|
||||
options: window.hassAttributeUtil.DOMAIN_DEVICE_CLASS,
|
||||
options: hassAttributeUtil.DOMAIN_DEVICE_CLASS,
|
||||
description: 'Device class',
|
||||
domains: ['binary_sensor', 'cover', 'sensor']
|
||||
},
|
||||
@ -89,3 +89,5 @@ window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES =
|
||||
},
|
||||
unit_of_measurement: { type: 'string' },
|
||||
};
|
||||
|
||||
export default hassAttributeUtil;
|
||||
|
Loading…
x
Reference in New Issue
Block a user