diff --git a/src/components/ha-attributes.js b/src/components/ha-attributes.js index 9e86391b0e..b62986cdf6 100644 --- a/src/components/ha-attributes.js +++ b/src/components/ha-attributes.js @@ -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) { diff --git a/src/panels/config/customize/ha-customize-attribute.js b/src/panels/config/customize/ha-customize-attribute.js index 3fdd516473..0726e2eb54 100644 --- a/src/panels/config/customize/ha-customize-attribute.js +++ b/src/panels/config/customize/ha-customize-attribute.js @@ -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; diff --git a/src/panels/config/customize/ha-form-customize.js b/src/panels/config/customize/ha-form-customize.js index 0869ec5fa0..5f6ed7c3d4 100644 --- a/src/panels/config/customize/ha-form-customize.js +++ b/src/panels/config/customize/ha-form-customize.js @@ -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; diff --git a/src/util/hass-attributes-util.js b/src/util/hass-attributes-util.js index de3ffcd016..75945a37b9 100644 --- a/src/util/hass-attributes-util.js +++ b/src/util/hass-attributes-util.js @@ -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;