P3: Replace hassUtil with imports (#1181)

* P3: Remove get is()

* P3: Replace hassUtil with imports

* Remove hass-util imports

* Fix errors
This commit is contained in:
c727 2018-05-16 14:03:04 +02:00 committed by GitHub
parent 23a2a479a5
commit 0c6f8c34fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 296 additions and 158 deletions

View File

@ -3,11 +3,12 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../src/layouts/hass-loading-screen.js'; import '../src/layouts/hass-loading-screen.js';
import '../src/util/hass-util.js';
import './addon-view/hassio-addon-view.js'; import './addon-view/hassio-addon-view.js';
import './hassio-data.js'; import './hassio-data.js';
import './hassio-pages-with-tabs.js'; import './hassio-pages-with-tabs.js';
import applyThemesOnElement from '../js/common/dom/apply_themes_on_element.js';
class HassioMain extends window.hassMixins.EventsMixin(PolymerElement) { class HassioMain extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -57,7 +58,7 @@ class HassioMain extends window.hassMixins.EventsMixin(PolymerElement) {
ready() { ready() {
super.ready(); super.ready();
window.hassUtil.applyThemesOnElement(this, this.hass.themes, this.hass.selectedTheme, true); applyThemesOnElement(this, this.hass.themes, this.hass.selectedTheme, true);
this.addEventListener('hass-api-called', ev => this.apiCalled(ev)); this.addEventListener('hass-api-called', ev => this.apiCalled(ev));
} }

View File

@ -24,8 +24,10 @@ import '../../../src/components/ha-service-picker.js';
import '../../../src/layouts/ha-app-layout.js'; import '../../../src/layouts/ha-app-layout.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import Automation from '../../../js/panel-config/automation.js'; import Automation from '../../../js/panel-config/automation.js';
import unmountPreact from '../../../js/common/preact/unmount.js'; import unmountPreact from '../../../js/common/preact/unmount.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
function AutomationEditor(mountEl, props, mergeEl) { function AutomationEditor(mountEl, props, mergeEl) {
return render(h(Automation, props), mountEl, mergeEl); return render(h(Automation, props), mountEl, mergeEl);
@ -282,7 +284,7 @@ class HaAutomationEditor extends
computeName(automation, localize) { computeName(automation, localize) {
return automation return automation
? window.hassUtil.computeStateName(automation) ? computeStateName(automation)
: localize('ui.panel.config.automation.editor.default_name'); : localize('ui.panel.config.automation.editor.default_name');
} }
} }

View File

@ -13,6 +13,7 @@ import '../../../src/layouts/ha-app-layout.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
@ -122,7 +123,7 @@ class HaAutomationPicker extends
} }
computeName(automation) { computeName(automation) {
return window.hassUtil.computeStateName(automation); return computeStateName(automation);
} }
// Still thinking of something to add here. // Still thinking of something to add here.

View File

@ -5,6 +5,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import './ha-automation-editor.js'; import './ha-automation-editor.js';
import './ha-automation-picker.js'; import './ha-automation-picker.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
class HaConfigAutomation extends PolymerElement { class HaConfigAutomation extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -74,7 +76,7 @@ class HaConfigAutomation extends PolymerElement {
Object.keys(hass.states).forEach(function (key) { Object.keys(hass.states).forEach(function (key) {
var entity = hass.states[key]; var entity = hass.states[key];
if (window.hassUtil.computeDomain(entity) === 'automation' && if (computeDomain(entity) === 'automation' &&
'id' in entity.attributes) { 'id' in entity.attributes) {
automations.push(entity); automations.push(entity);
} }

View File

@ -10,6 +10,8 @@ import '../../../src/resources/ha-style.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import formatDateTime from '../../../js/common/datetime/format_date_time.js';
class HaConfigCloudAccount extends window.hassMixins.EventsMixin(PolymerElement) { class HaConfigCloudAccount extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -148,7 +150,7 @@ class HaConfigCloudAccount extends window.hassMixins.EventsMixin(PolymerElement)
} }
_formatExpiration(date) { _formatExpiration(date) {
return window.hassUtil.formatDateTime(new Date(date)); return formatDateTime(new Date(date));
} }
_accountChanged(newAccount) { _accountChanged(newAccount) {

View File

@ -12,6 +12,8 @@ import './ha-config-section-push-notifications.js';
import './ha-config-section-themes.js'; import './ha-config-section-themes.js';
import './ha-config-section-translation.js'; import './ha-config-section-translation.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -80,7 +82,7 @@ class HaConfigCore extends window.hassMixins.LocalizeMixin(PolymerElement) {
} }
computeIsZwaveLoaded(hass) { computeIsZwaveLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'config.zwave'); return isComponentLoaded(hass, 'config.zwave');
} }
computeIsTranslationLoaded(hass) { computeIsTranslationLoaded(hass) {

View File

@ -9,6 +9,8 @@ import '../../../src/resources/ha-style.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -144,15 +146,15 @@ class HaConfigSectionCore extends window.hassMixins.LocalizeMixin(PolymerElement
} }
groupLoaded(hass) { groupLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'group'); return isComponentLoaded(hass, 'group');
} }
automationLoaded(hass) { automationLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'automation'); return isComponentLoaded(hass, 'automation');
} }
scriptLoaded(hass) { scriptLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'script'); return isComponentLoaded(hass, 'script');
} }
validateConfig() { validateConfig() {

View File

@ -7,11 +7,14 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../src/resources/ha-style.js'; import '../../../src/resources/ha-style.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../../../src/util/hass-util.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import '../ha-entity-config.js'; import '../ha-entity-config.js';
import './ha-form-customize.js'; import './ha-form-customize.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
import sortByName from '../../../js/common/entity/states_sort_by_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -59,7 +62,7 @@ class HaConfigCustomize extends window.hassMixins.LocalizeMixin(PolymerElement)
value: { value: {
component: 'ha-form-customize', component: 'ha-form-customize',
computeSelectCaption: stateObj => computeSelectCaption: stateObj =>
window.hassUtil.computeStateName(stateObj) + ' (' + window.hassUtil.computeDomain(stateObj) + ')' computeStateName(stateObj) + ' (' + computeDomain(stateObj) + ')'
} }
}, },
}; };
@ -76,7 +79,7 @@ class HaConfigCustomize extends window.hassMixins.LocalizeMixin(PolymerElement)
computeEntities(hass) { computeEntities(hass) {
return Object.keys(hass.states) return Object.keys(hass.states)
.map(key => hass.states[key]) .map(key => hass.states[key])
.sort(window.hassUtil.sortByName); .sort(sortByName);
} }
} }
customElements.define('ha-config-customize', HaConfigCustomize); customElements.define('ha-config-customize', HaConfigCustomize);

View File

@ -5,9 +5,10 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../src/util/hass-attributes-util.js'; import '../../../src/util/hass-attributes-util.js';
import '../../../src/util/hass-util.js';
import './ha-form-customize-attributes.js'; import './ha-form-customize-attributes.js';
import computeDomain from '../../../js/common/entity/compute_domain';
class HaFormCustomize extends PolymerElement { class HaFormCustomize extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -119,7 +120,7 @@ class HaFormCustomize extends PolymerElement {
attribute: key, attribute: key,
value: value, value: value,
closed: false, closed: false,
domain: window.hassUtil.computeDomain(this.entity), domain: computeDomain(this.entity),
secondary: secondary, secondary: secondary,
description: key, description: key,
}, config); }, config);
@ -199,7 +200,7 @@ class HaFormCustomize extends PolymerElement {
.filter((key) => { .filter((key) => {
const conf = window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key]; const conf = window.hassAttributeUtil.LOGIC_STATE_ATTRIBUTES[key];
return conf && (!conf.domains || !this.entity || return conf && (!conf.domains || !this.entity ||
conf.domains.includes(window.hassUtil.computeDomain(this.entity))); conf.domains.includes(computeDomain(this.entity)));
}) })
.filter(this.filterFromAttributes(localAttributes)) .filter(this.filterFromAttributes(localAttributes))
.filter(this.filterFromAttributes(globalAttributes)) .filter(this.filterFromAttributes(globalAttributes))

View File

@ -11,6 +11,8 @@ import './ha-config-cloud-menu.js';
import './ha-config-entries-menu.js'; import './ha-config-entries-menu.js';
import './ha-config-navigation.js'; import './ha-config-navigation.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -62,7 +64,7 @@ class HaConfigDashboard extends window.hassMixins.LocalizeMixin(PolymerElement)
} }
computeIsLoaded(hass, component) { computeIsLoaded(hass, component) {
return window.hassUtil.isComponentLoaded(hass, component); return isComponentLoaded(hass, component);
} }
} }

View File

@ -7,6 +7,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
{ {
const CORE_PAGES = [ const CORE_PAGES = [
'core', 'core',
@ -64,7 +66,7 @@ import '../../../src/util/hass-mixins.js';
} }
_computeLoaded(hass, page) { _computeLoaded(hass, page) {
return CORE_PAGES.includes(page) || window.hassUtil.isComponentLoaded(hass, page); return CORE_PAGES.includes(page) || isComponentLoaded(hass, page);
} }
_computeCaption(page, localize) { _computeCaption(page, localize) {

View File

@ -7,6 +7,8 @@ import '@polymer/paper-spinner/paper-spinner.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
class HaEntityConfig extends PolymerElement { class HaEntityConfig extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -125,7 +127,7 @@ class HaEntityConfig extends PolymerElement {
computeSelectCaption(stateObj) { computeSelectCaption(stateObj) {
return this.config.computeSelectCaption ? return this.config.computeSelectCaption ?
this.config.computeSelectCaption(stateObj) : this.config.computeSelectCaption(stateObj) :
window.hassUtil.computeStateName(stateObj); computeStateName(stateObj);
} }
computeShowNoDevices(formState) { computeShowNoDevices(formState) {

View File

@ -14,6 +14,7 @@ import './dashboard/ha-config-dashboard.js';
import './script/ha-config-script.js'; import './script/ha-config-script.js';
import './zwave/ha-config-zwave.js'; import './zwave/ha-config-zwave.js';
import isComponentLoaded from '../../js/common/config/is_component_loaded.js';
class HaPanelConfig extends window.hassMixins.NavigateMixin(PolymerElement) { class HaPanelConfig extends window.hassMixins.NavigateMixin(PolymerElement) {
static get template() { static get template() {
@ -128,7 +129,7 @@ class HaPanelConfig extends window.hassMixins.NavigateMixin(PolymerElement) {
ready() { ready() {
super.ready(); super.ready();
if (window.hassUtil.isComponentLoaded(this.hass, 'cloud')) { if (isComponentLoaded(this.hass, 'cloud')) {
this.hass.callApi('get', 'cloud/account').then((account) => { this.account = account; }); this.hass.callApi('get', 'cloud/account').then((account) => { this.account = account; });
} }
this.addEventListener('ha-account-refreshed', (ev) => { this.addEventListener('ha-account-refreshed', (ev) => {

View File

@ -5,6 +5,9 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import './ha-script-editor.js'; import './ha-script-editor.js';
import './ha-script-picker.js'; import './ha-script-picker.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
class HaConfigScript extends PolymerElement { class HaConfigScript extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -74,14 +77,14 @@ class HaConfigScript extends PolymerElement {
Object.keys(hass.states).forEach(function (key) { Object.keys(hass.states).forEach(function (key) {
var entity = hass.states[key]; var entity = hass.states[key];
if (window.hassUtil.computeDomain(entity) === 'script') { if (computeDomain(entity) === 'script') {
scripts.push(entity); scripts.push(entity);
} }
}); });
return scripts.sort(function entitySortBy(entityA, entityB) { return scripts.sort(function entitySortBy(entityA, entityB) {
var nameA = window.hassUtil.computeStateName(entityA); var nameA = computeStateName(entityA);
var nameB = window.hassUtil.computeStateName(entityB); var nameB = computeStateName(entityB);
if (nameA < nameB) { if (nameA < nameB) {
return -1; return -1;

View File

@ -25,6 +25,9 @@ import '../ha-config-section.js';
import Script from '../../../js/panel-config/script.js'; import Script from '../../../js/panel-config/script.js';
import unmountPreact from '../../../js/common/preact/unmount.js'; import unmountPreact from '../../../js/common/preact/unmount.js';
import computeObjectId from '../../../js/common/entity/compute_object_id.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
function ScriptEditor(mountEl, props, mergeEl) { function ScriptEditor(mountEl, props, mergeEl) {
return render(h(Script, props), mountEl, mergeEl); return render(h(Script, props), mountEl, mergeEl);
} }
@ -202,7 +205,7 @@ class HaScriptEditor extends
if (oldVal && oldVal.entity_id === newVal.entity_id) { if (oldVal && oldVal.entity_id === newVal.entity_id) {
return; return;
} }
this.hass.callApi('get', 'config/script/config/' + window.hassUtil.computeObjectId(newVal.entity_id)) this.hass.callApi('get', 'config/script/config/' + computeObjectId(newVal.entity_id))
.then((config) => { .then((config) => {
// Normalize data: ensure sequence is a list // Normalize data: ensure sequence is a list
// Happens when people copy paste their scripts into the config // Happens when people copy paste their scripts into the config
@ -260,7 +263,7 @@ class HaScriptEditor extends
saveScript() { saveScript() {
var id = this.creatingNew ? var id = this.creatingNew ?
'' + Date.now() : window.hassUtil.computeObjectId(this.script.entity_id); '' + Date.now() : computeObjectId(this.script.entity_id);
this.hass.callApi('post', 'config/script/config/' + id, this.config).then(() => { this.hass.callApi('post', 'config/script/config/' + id, this.config).then(() => {
this.dirty = false; this.dirty = false;
@ -274,7 +277,7 @@ class HaScriptEditor extends
} }
computeName(script) { computeName(script) {
return script && window.hassUtil.computeStateName(script); return script && computeStateName(script);
} }
} }

View File

@ -12,6 +12,8 @@ import '../../../src/layouts/ha-app-layout.js';
import '../../../src/util/hass-mixins.js'; import '../../../src/util/hass-mixins.js';
import '../ha-config-section.js'; import '../ha-config-section.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
@ -118,7 +120,7 @@ class HaScriptPicker extends
} }
computeName(script) { computeName(script) {
return window.hassUtil.computeStateName(script); return computeStateName(script);
} }
// Still thinking of something to add here. // Still thinking of something to add here.

View File

@ -25,6 +25,9 @@ import './zwave-node-information.js';
import './zwave-usercodes.js'; import './zwave-usercodes.js';
import './zwave-values.js'; import './zwave-values.js';
import sortByName from '../../../js/common/entity/states_sort_by_name.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -310,7 +313,7 @@ class HaConfigZwave extends window.hassMixins.LocalizeMixin(PolymerElement) {
.filter(function (ent) { .filter(function (ent) {
return ((ent.entity_id).match('zwave[.]')); return ((ent.entity_id).match('zwave[.]'));
}) })
.sort(window.hassUtil.sortByName); .sort(sortByName);
} }
computeEntities(selectedNode) { computeEntities(selectedNode) {
@ -328,7 +331,7 @@ class HaConfigZwave extends window.hassMixins.LocalizeMixin(PolymerElement) {
ent.attributes.node_id === nodeid && ent.attributes.node_id === nodeid &&
(!(ent.entity_id).match('zwave[.]'))); (!(ent.entity_id).match('zwave[.]')));
}) })
.sort(window.hassUtil.sortByName); .sort(sortByName);
} }
selectedNodeChanged(selectedNode) { selectedNodeChanged(selectedNode) {
@ -388,14 +391,14 @@ class HaConfigZwave extends window.hassMixins.LocalizeMixin(PolymerElement) {
} }
computeSelectCaption(stateObj) { computeSelectCaption(stateObj) {
return window.hassUtil.computeStateName(stateObj) + ' (Node:' + return computeStateName(stateObj) + ' (Node:' +
stateObj.attributes.node_id + ' ' + stateObj.attributes.node_id + ' ' +
stateObj.attributes.query_stage + ')'; stateObj.attributes.query_stage + ')';
} }
computeSelectCaptionEnt(stateObj) { computeSelectCaptionEnt(stateObj) {
return (window.hassUtil.computeDomain(stateObj) + '.' return (computeDomain(stateObj) + '.'
+ window.hassUtil.computeStateName(stateObj)); + computeStateName(stateObj));
} }
computeIsNodeSelected() { computeIsNodeSelected() {

View File

@ -7,6 +7,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../src/components/buttons/ha-call-service-button.js'; import '../../../src/components/buttons/ha-call-service-button.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
class ZwaveGroups extends PolymerElement { class ZwaveGroups extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -188,7 +190,7 @@ class ZwaveGroups extends PolymerElement {
} }
computeSelectCaption(stateObj) { computeSelectCaption(stateObj) {
return window.hassUtil.computeStateName(stateObj) + ' (Node:' + return computeStateName(stateObj) + ' (Node:' +
stateObj.attributes.node_id + ' ' + stateObj.attributes.node_id + ' ' +
stateObj.attributes.query_stage + ')'; stateObj.attributes.query_stage + ')';
} }

View File

@ -14,6 +14,9 @@ import '../../src/components/buttons/ha-call-service-button.js';
import '../../src/components/ha-menu-button.js'; import '../../src/components/ha-menu-button.js';
import '../../src/resources/ha-style.js'; import '../../src/resources/ha-style.js';
import formatDateTime from '../../js/common/datetime/format_date_time.js';
import formatTime from '../../js/common/datetime/format_time.js';
class HaPanelDevInfo extends PolymerElement { class HaPanelDevInfo extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -311,7 +314,7 @@ class HaPanelDevInfo extends PolymerElement {
const dateTimeDay = new Date(date * 1000).setHours(0, 0, 0, 0); const dateTimeDay = new Date(date * 1000).setHours(0, 0, 0, 0);
return dateTimeDay < today ? return dateTimeDay < today ?
window.hassUtil.formatDateTime(dateTime) : window.hassUtil.formatTime(dateTime); formatDateTime(dateTime) : formatTime(dateTime);
} }
openLog(event) { openLog(event) {

View File

@ -17,6 +17,8 @@ import '../../src/resources/ha-date-picker-style.js';
import '../../src/resources/ha-style.js'; import '../../src/resources/ha-style.js';
import '../../src/util/hass-mixins.js'; import '../../src/util/hass-mixins.js';
import formatDate from '../../js/common/datetime/format_date.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -156,7 +158,7 @@ class HaPanelHistory extends window.hassMixins.LocalizeMixin(PolymerElement) {
// We are unable to parse date because we use intl api to render date // We are unable to parse date because we use intl api to render date
this.$.picker.set('i18n.parseDate', null); this.$.picker.set('i18n.parseDate', null);
this.$.picker.set('i18n.formatDate', function (date) { this.$.picker.set('i18n.formatDate', function (date) {
return window.hassUtil.formatDate(new Date(date.year, date.month, date.day)); return formatDate(new Date(date.year, date.month, date.day));
}); });
} }

View File

@ -5,6 +5,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../src/components/domain-icon.js'; import '../../src/components/domain-icon.js';
import '../../src/util/hass-mixins.js'; import '../../src/util/hass-mixins.js';
import formatTime from '../../js/common/datetime/format_time.js';
class HaLogbook extends window.hassMixins.EventsMixin(PolymerElement) { class HaLogbook extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -45,7 +47,7 @@ class HaLogbook extends window.hassMixins.EventsMixin(PolymerElement) {
<template is="dom-repeat" items="[[entries]]"> <template is="dom-repeat" items="[[entries]]">
<div class="horizontal layout entry"> <div class="horizontal layout entry">
<div class="time">[[formatTime(item.when)]]</div> <div class="time">[[_formatTime(item.when)]]</div>
<domain-icon domain="[[item.domain]]" class="icon"></domain-icon> <domain-icon domain="[[item.domain]]" class="icon"></domain-icon>
<div class="message" flex=""> <div class="message" flex="">
<template is="dom-if" if="[[!item.entity_id]]"> <template is="dom-if" if="[[!item.entity_id]]">
@ -75,8 +77,8 @@ class HaLogbook extends window.hassMixins.EventsMixin(PolymerElement) {
}; };
} }
formatTime(date) { _formatTime(date) {
return window.hassUtil.formatTime(new Date(date)); return formatTime(new Date(date));
} }
entityClicked(ev) { entityClicked(ev) {

View File

@ -15,6 +15,8 @@ import '../../src/util/hass-mixins.js';
import './ha-logbook-data.js'; import './ha-logbook-data.js';
import './ha-logbook.js'; import './ha-logbook.js';
import formatDate from '../../js/common/datetime/format_date.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -132,7 +134,7 @@ class HaPanelLogbook extends window.hassMixins.LocalizeMixin(PolymerElement) {
// We are unable to parse date because we use intl api to render date // We are unable to parse date because we use intl api to render date
this.$.picker.set('i18n.parseDate', null); this.$.picker.set('i18n.parseDate', null);
this.$.picker.set('i18n.formatDate', function (date) { this.$.picker.set('i18n.formatDate', function (date) {
return window.hassUtil.formatDate(new Date(date.year, date.month, date.day)); return formatDate(new Date(date.year, date.month, date.day));
}); });
} }

View File

@ -14,6 +14,8 @@ import '../../src/components/ha-menu-button.js';
import '../../src/resources/ha-style.js'; import '../../src/resources/ha-style.js';
import '../../src/util/hass-mixins.js'; import '../../src/util/hass-mixins.js';
import formatDateTime from '../../js/common/datetime/format_date_time.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -234,7 +236,7 @@ class HaPanelMailbox extends window.hassMixins.LocalizeMixin(PolymerElement) {
var platformItems = []; var platformItems = [];
var arrayLength = values.length; var arrayLength = values.length;
for (var i = 0; i < arrayLength; i++) { for (var i = 0; i < arrayLength; i++) {
var datetime = window.hassUtil.formatDateTime(new Date(values[i].info.origtime * 1000)); var datetime = formatDateTime(new Date(values[i].info.origtime * 1000));
platformItems.push({ platformItems.push({
timestamp: datetime, timestamp: datetime,
caller: values[i].info.callerid, caller: values[i].info.callerid,

View File

@ -8,6 +8,9 @@ import '../../src/components/ha-menu-button.js';
import '../../src/util/hass-mixins.js'; import '../../src/util/hass-mixins.js';
import './ha-entity-marker.js'; import './ha-entity-marker.js';
import computeDomain from '../../js/common/entity/compute_domain.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
Leaflet.Icon.Default.imagePath = '/static/images/leaflet'; Leaflet.Icon.Default.imagePath = '/static/images/leaflet';
/* /*
@ -103,10 +106,10 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
Object.keys(hass.states).forEach(function (entityId) { Object.keys(hass.states).forEach(function (entityId) {
var entity = hass.states[entityId]; var entity = hass.states[entityId];
var title = window.hassUtil.computeStateName(entity); var title = computeStateName(entity);
if ((entity.attributes.hidden && if ((entity.attributes.hidden &&
window.hassUtil.computeDomain(entity) !== 'zone') || computeDomain(entity) !== 'zone') ||
entity.state === 'home' || entity.state === 'home' ||
!('latitude' in entity.attributes) || !('latitude' in entity.attributes) ||
!('longitude' in entity.attributes)) { !('longitude' in entity.attributes)) {
@ -115,7 +118,7 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
var icon; var icon;
if (window.hassUtil.computeDomain(entity) === 'zone') { if (computeDomain(entity) === 'zone') {
// DRAW ZONE // DRAW ZONE
if (entity.attributes.passive) return; if (entity.attributes.passive) return;
@ -174,7 +177,7 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
[entity.attributes.latitude, entity.attributes.longitude], [entity.attributes.latitude, entity.attributes.longitude],
{ {
icon: icon, icon: icon,
title: window.hassUtil.computeStateName(entity), title: computeStateName(entity),
} }
).addTo(map)); ).addTo(map));

View File

@ -4,6 +4,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
{ {
const UPDATE_INTERVAL = 10000; // ms const UPDATE_INTERVAL = 10000; // ms
/* /*
@ -49,7 +51,7 @@ import '../util/hass-mixins.js';
} }
</style> </style>
<img src="[[cameraFeedSrc]]" class="camera-feed" hidden\$="[[!imageLoaded]]" alt="[[computeStateName(stateObj)]]"> <img src="[[cameraFeedSrc]]" class="camera-feed" hidden\$="[[!imageLoaded]]" alt="[[_computeStateName(stateObj)]]">
<div class="caption"> <div class="caption">
[[computeStateName(stateObj)]] [[computeStateName(stateObj)]]
<template is="dom-if" if="[[!imageLoaded]]"> <template is="dom-if" if="[[!imageLoaded]]">
@ -109,8 +111,8 @@ import '../util/hass-mixins.js';
}); });
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
} }
customElements.define('ha-camera-card', HaCameraCard); customElements.define('ha-camera-card', HaCameraCard);

View File

@ -8,6 +8,8 @@ import './ha-persistent_notification-card.js';
import './ha-plant-card.js'; import './ha-plant-card.js';
import './ha-weather-card.js'; import './ha-weather-card.js';
import dynamicContentUpdater from '../../js/common/dom/dynamic_content_updater.js';
class HaCardChooser extends PolymerElement { class HaCardChooser extends PolymerElement {
static get properties() { static get properties() {
return { return {
@ -19,7 +21,7 @@ class HaCardChooser extends PolymerElement {
} }
_updateCard(newData) { _updateCard(newData) {
window.hassUtil.dynamicContentUpdater( dynamicContentUpdater(
this, 'HA-' + newData.cardType.toUpperCase() + '-CARD', this, 'HA-' + newData.cardType.toUpperCase() + '-CARD',
newData newData
); );

View File

@ -7,6 +7,11 @@ import '../components/ha-card.js';
import '../state-summary/state-card-content.js'; import '../state-summary/state-card-content.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeDomain from '../../js/common/entity/compute_domain.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
import stateMoreInfoType from '../../js/common/entity/state_more_info_type.js';
import canToggleState from '../../js/common/entity/can_toggle_state.js';
class HaEntitiesCard extends class HaEntitiesCard extends
window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(PolymerElement)) { window.hassMixins.LocalizeMixin(window.hassMixins.EventsMixin(PolymerElement)) {
static get template() { static get template() {
@ -79,9 +84,9 @@ class HaEntitiesCard extends
computeTitle(states, groupEntity, localize) { computeTitle(states, groupEntity, localize) {
if (groupEntity) { if (groupEntity) {
return window.hassUtil.computeStateName(groupEntity).trim(); return computeStateName(groupEntity).trim();
} }
const domain = window.hassUtil.computeDomain(states[0]); const domain = computeDomain(states[0]);
return (localize && localize(`domain.${domain}`)) || domain.replace(/_/g, ' '); return (localize && localize(`domain.${domain}`)) || domain.replace(/_/g, ' ');
} }
@ -94,7 +99,7 @@ class HaEntitiesCard extends
} }
computeStateClass(stateObj) { computeStateClass(stateObj) {
return window.hassUtil.stateMoreInfoType(stateObj) !== 'hidden' ? 'state more-info' : 'state'; return stateMoreInfoType(stateObj) !== 'hidden' ? 'state more-info' : 'state';
} }
addTapEvents() { addTapEvents() {
@ -133,7 +138,7 @@ class HaEntitiesCard extends
// Only show if we can toggle 2+ entities in group // Only show if we can toggle 2+ entities in group
let canToggleCount = 0; let canToggleCount = 0;
for (let i = 0; i < states.length; i++) { for (let i = 0; i < states.length; i++) {
if (!window.hassUtil.canToggleState(this.hass, states[i])) { if (!canToggleState(this.hass, states[i])) {
continue; continue;
} }

View File

@ -6,6 +6,8 @@ import '../components/state-history-charts.js';
import '../data/ha-state-history-data.js'; import '../data/ha-state-history-data.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
class HaHistoryGraphCard extends window.hassMixins.EventsMixin(PolymerElement) { class HaHistoryGraphCard extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -82,7 +84,7 @@ class HaHistoryGraphCard extends window.hassMixins.EventsMixin(PolymerElement) {
} }
computeTitle(stateObj) { computeTitle(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
computeContentClass(inDialog) { computeContentClass(inDialog) {

View File

@ -8,6 +8,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-media-player-model.js'; import '../util/hass-media-player-model.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
@ -158,7 +160,7 @@ class HaMediaPlayerCard extends
<div class="cover" id="cover"></div> <div class="cover" id="cover"></div>
<div class="caption"> <div class="caption">
[[computeStateName(stateObj)]] [[_computeStateName(stateObj)]]
<div class="title">[[computePrimaryText(localize, playerObj)]]</div> <div class="title">[[computePrimaryText(localize, playerObj)]]</div>
[[playerObj.secondaryTitle]]<br> [[playerObj.secondaryTitle]]<br>
</div> </div>
@ -277,8 +279,8 @@ class HaMediaPlayerCard extends
return ''; return '';
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
handleNext(ev) { handleNext(ev) {

View File

@ -6,6 +6,8 @@ import '../components/ha-card.js';
import '../components/ha-markdown.js'; import '../components/ha-markdown.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -57,7 +59,7 @@ class HaPersistentNotificationCard extends window.hassMixins.LocalizeMixin(Polym
computeTitle(stateObj) { computeTitle(stateObj) {
return (stateObj.attributes.title || return (stateObj.attributes.title ||
window.hassUtil.computeStateName(stateObj)); computeStateName(stateObj));
} }
dismissTap(ev) { dismissTap(ev) {

View File

@ -5,6 +5,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/ha-card.js'; import '../components/ha-card.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
class HaPlantCard extends window.hassMixins.EventsMixin(PolymerElement) { class HaPlantCard extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -68,7 +70,7 @@ class HaPlantCard extends window.hassMixins.EventsMixin(PolymerElement) {
} }
computeTitle(stateObj) { computeTitle(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
computeAttributes(data) { computeAttributes(data) {

View File

@ -5,6 +5,8 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js'; import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
import { timeOut } from '@polymer/polymer/lib/utils/async.js'; import { timeOut } from '@polymer/polymer/lib/utils/async.js';
import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js'; import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
import formatTime from '../../../js/common/datetime/format_time.js';
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
/* global Chart moment Color */ /* global Chart moment Color */
@ -314,7 +316,7 @@ class HaChartBase extends mixinBehaviors([
return value; return value;
} }
const date = new Date(values[index].value); const date = new Date(values[index].value);
return window.hassUtil.formatTime(date); return formatTime(date);
} }
drawChart() { drawChart() {
const data = this.data.data; const data = this.data.data;

View File

@ -9,6 +9,8 @@ import '@vaadin/vaadin-combo-box/vaadin-combo-box-light.js';
import '../../util/hass-mixins.js'; import '../../util/hass-mixins.js';
import './state-badge.js'; import './state-badge.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -40,7 +42,7 @@ class HaEntityPicker extends window.hassMixins.LocalizeMixin(PolymerElement) {
<paper-icon-item> <paper-icon-item>
<state-badge state-obj="[[item]]" slot="item-icon"></state-badge> <state-badge state-obj="[[item]]" slot="item-icon"></state-badge>
<paper-item-body two-line=""> <paper-item-body two-line="">
<div>[[computeStateName(item)]]</div> <div>[[_computeStateName(item)]]</div>
<div secondary="">[[item.entity_id]]</div> <div secondary="">[[item.entity_id]]</div>
</paper-item-body> </paper-item-body>
</paper-icon-item> </paper-icon-item>
@ -113,8 +115,8 @@ class HaEntityPicker extends window.hassMixins.LocalizeMixin(PolymerElement) {
return entities; return entities;
} }
computeStateName(state) { _computeStateName(state) {
return window.hassUtil.computeStateName(state); return computeStateName(state);
} }
_openedChanged(newVal) { _openedChanged(newVal) {

View File

@ -3,6 +3,9 @@ import '@polymer/paper-toggle-button/paper-toggle-button.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import STATES_OFF from '../../../js/common/const.js';
import computeDomain from '../../../js/common/entity/compute_domain';
class HaEntityToggle extends PolymerElement { class HaEntityToggle extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -97,7 +100,7 @@ class HaEntityToggle extends PolymerElement {
} }
computeIsOn(stateObj) { computeIsOn(stateObj) {
return stateObj && !window.hassUtil.OFF_STATES.includes(stateObj.state); return stateObj && !STATES_OFF.includes(stateObj.state);
} }
stateObjObserver(newVal, oldVal) { stateObjObserver(newVal, oldVal) {
@ -113,7 +116,7 @@ class HaEntityToggle extends PolymerElement {
// result in the entity to be turned on. Since the state is not changing, // result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic. // the resync is not called automatic.
callService(turnOn) { callService(turnOn) {
const stateDomain = window.hassUtil.computeDomain(this.stateObj); const stateDomain = computeDomain(this.stateObj);
let serviceDomain; let serviceDomain;
let service; let service;

View File

@ -2,9 +2,16 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../util/hass-mixins.js'; import '../../util/hass-mixins.js';
import '../../util/hass-util.js';
import '../ha-label-badge.js'; import '../ha-label-badge.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import domainIcon from '../../../js/common/entity/domain_icon.js';
import stateIcon from '../../../js/common/entity/state_icon.js';
import timerTimeRemaining from '../../../js/common/entity/timer_time_remaining.js';
import attributeClassNames from '../../../js/common/entity/attribute_class_names.js';
import secondsToDuration from '../../../js/common/datetime/seconds_to_duration.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
* @appliesMixin window.hassMixins.EventsMixin * @appliesMixin window.hassMixins.EventsMixin
@ -51,7 +58,7 @@ class HaStateLabelBadge extends
} }
</style> </style>
<ha-label-badge class\$="[[computeClassNames(state)]]" value="[[computeValue(localize, state)]]" icon="[[computeIcon(state)]]" image="[[computeImage(state)]]" label="[[computeLabel(localize, state, timerTimeRemaining)]]" description="[[computeDescription(state)]]"></ha-label-badge> <ha-label-badge class\$="[[computeClassNames(state)]]" value="[[computeValue(localize, state)]]" icon="[[computeIcon(state)]]" image="[[computeImage(state)]]" label="[[computeLabel(localize, state, _timerTimeRemaining)]]" description="[[computeDescription(state)]]"></ha-label-badge>
`; `;
} }
@ -62,7 +69,7 @@ class HaStateLabelBadge extends
type: Object, type: Object,
observer: 'stateChanged', observer: 'stateChanged',
}, },
timerTimeRemaining: { _timerTimeRemaining: {
type: Number, type: Number,
value: 0, value: 0,
} }
@ -90,13 +97,13 @@ class HaStateLabelBadge extends
} }
computeClassNames(state) { computeClassNames(state) {
const classes = [window.hassUtil.computeDomain(state)]; const classes = [computeDomain(state)];
classes.push(window.hassUtil.attributeClassNames(state, ['unit_of_measurement'])); classes.push(attributeClassNames(state, ['unit_of_measurement']));
return classes.join(' '); return classes.join(' ');
} }
computeValue(localize, state) { computeValue(localize, state) {
const domain = window.hassUtil.computeDomain(state); const domain = computeDomain(state);
switch (domain) { switch (domain) {
case 'binary_sensor': case 'binary_sensor':
case 'device_tracker': case 'device_tracker':
@ -118,7 +125,7 @@ class HaStateLabelBadge extends
if (state.state === 'unavailable') { if (state.state === 'unavailable') {
return null; return null;
} }
const domain = window.hassUtil.computeDomain(state); const domain = computeDomain(state);
switch (domain) { switch (domain) {
case 'alarm_control_panel': case 'alarm_control_panel':
if (state.state === 'pending') { if (state.state === 'pending') {
@ -135,14 +142,14 @@ class HaStateLabelBadge extends
return 'mdi:alert-circle'; return 'mdi:alert-circle';
} }
// state == 'disarmed' // state == 'disarmed'
return window.hassUtil.domainIcon(domain, state.state); return domainIcon(domain, state.state);
case 'binary_sensor': case 'binary_sensor':
case 'device_tracker': case 'device_tracker':
case 'updater': case 'updater':
return window.hassUtil.stateIcon(state); return stateIcon(state);
case 'sun': case 'sun':
return state.state === 'above_horizon' ? return state.state === 'above_horizon' ?
window.hassUtil.domainIcon(domain) : 'mdi:brightness-3'; domainIcon(domain) : 'mdi:brightness-3';
case 'timer': case 'timer':
return state.state === 'active' ? 'mdi:timer' : 'mdi:timer-off'; return state.state === 'active' ? 'mdi:timer' : 'mdi:timer-off';
default: default:
@ -154,8 +161,8 @@ class HaStateLabelBadge extends
return state.attributes.entity_picture || null; return state.attributes.entity_picture || null;
} }
computeLabel(localize, state, timerTimeRemaining) { computeLabel(localize, state, _timerTimeRemaining) {
const domain = window.hassUtil.computeDomain(state); const domain = computeDomain(state);
if (state.state === 'unavailable' || if (state.state === 'unavailable' ||
['device_tracker', 'alarm_control_panel'].includes(domain)) { ['device_tracker', 'alarm_control_panel'].includes(domain)) {
// Localize the state with a special state_badge namespace, which has variations of // Localize the state with a special state_badge namespace, which has variations of
@ -164,13 +171,13 @@ class HaStateLabelBadge extends
return localize(`state_badge.${domain}.${state.state}`) || localize(`state_badge.default.${state.state}`) || state.state; return localize(`state_badge.${domain}.${state.state}`) || localize(`state_badge.default.${state.state}`) || state.state;
} }
if (domain === 'timer') { if (domain === 'timer') {
return window.hassUtil.secondsToDuration(timerTimeRemaining); return secondsToDuration(_timerTimeRemaining);
} }
return state.attributes.unit_of_measurement || null; return state.attributes.unit_of_measurement || null;
} }
computeDescription(state) { computeDescription(state) {
return window.hassUtil.computeStateName(state); return computeStateName(state);
} }
stateChanged(stateObj) { stateChanged(stateObj) {
@ -187,7 +194,7 @@ class HaStateLabelBadge extends
startInterval(stateObj) { startInterval(stateObj) {
this.clearInterval(); this.clearInterval();
if (window.hassUtil.computeDomain(stateObj) === 'timer') { if (computeDomain(stateObj) === 'timer') {
this.calculateTimerRemaining(stateObj); this.calculateTimerRemaining(stateObj);
if (stateObj.state === 'active') { if (stateObj.state === 'active') {
@ -197,7 +204,7 @@ class HaStateLabelBadge extends
} }
calculateTimerRemaining(stateObj) { calculateTimerRemaining(stateObj) {
this.timerTimeRemaining = window.hassUtil.timerTimeRemaining(stateObj); this._timerTimeRemaining = timerTimeRemaining(stateObj);
} }
} }

View File

@ -6,9 +6,10 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../cards/ha-badges-card.js'; import '../cards/ha-badges-card.js';
import '../cards/ha-card-chooser.js'; import '../cards/ha-card-chooser.js';
import '../util/hass-util.js';
import './ha-demo-badge.js'; import './ha-demo-badge.js';
import computeDomain from '../../js/common/entity/compute_domain.js';
{ {
// mapping domain to size of the card. // mapping domain to size of the card.
const DOMAINS_WITH_CARD = { const DOMAINS_WITH_CARD = {
@ -73,8 +74,6 @@ import './ha-demo-badge.js';
}); });
}; };
const computeDomain = window.hassUtil.computeDomain;
class HaCards extends PolymerElement { class HaCards extends PolymerElement {
static get template() { static get template() {
return html` return html`

View File

@ -4,6 +4,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import isComponentLoaded from '../../js/common/config/is_component_loaded.js';
class HaStartVoiceButton extends window.hassMixins.EventsMixin(PolymerElement) { class HaStartVoiceButton extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -28,7 +30,7 @@ class HaStartVoiceButton extends window.hassMixins.EventsMixin(PolymerElement) {
computeCanListen(hass) { computeCanListen(hass) {
return ('webkitSpeechRecognition' in window && return ('webkitSpeechRecognition' in window &&
window.hassUtil.isComponentLoaded(hass, 'conversation')); isComponentLoaded(hass, 'conversation'));
} }
handleListenClick() { handleListenClick() {

View File

@ -2,7 +2,6 @@ import '@polymer/iron-icon/iron-icon.js';
import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-util.js';
import './ha-relative-time.js'; import './ha-relative-time.js';
class HassioCardContent extends PolymerElement { class HassioCardContent extends PolymerElement {

View File

@ -4,6 +4,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import './entity/ha-chart-base.js'; import './entity/ha-chart-base.js';
import formatDateTime from '../../js/common/datetime/format_date_time.js';
class StateHistoryChartLine extends PolymerElement { class StateHistoryChartLine extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -233,7 +235,7 @@ class StateHistoryChartLine extends PolymerElement {
const item = items[0]; const item = items[0];
const date = data.datasets[item.datasetIndex].data[item.index].x; const date = data.datasets[item.datasetIndex].data[item.index].x;
return window.hassUtil.formatDateTime(date); return formatDateTime(date);
}; };
const chartOptions = { const chartOptions = {

View File

@ -4,6 +4,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import './entity/ha-chart-base.js'; import './entity/ha-chart-base.js';
import formatDateTime from '../../js/common/datetime/format_date_time';
class StateHistoryChartTimeline extends PolymerElement { class StateHistoryChartTimeline extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -148,8 +150,8 @@ class StateHistoryChartTimeline extends PolymerElement {
const formatTooltipLabel = function (item, data) { const formatTooltipLabel = function (item, data) {
const values = data.datasets[item.datasetIndex].data[item.index]; const values = data.datasets[item.datasetIndex].data[item.index];
const start = window.hassUtil.formatDateTime(values[0]); const start = formatDateTime(values[0]);
const end = window.hassUtil.formatDateTime(values[1]); const end = formatDateTime(values[1]);
const state = values[2]; const state = values[2];
return [state, start, end]; return [state, start, end];

View File

@ -3,7 +3,10 @@ import { Debouncer } from '@polymer/polymer/lib/utils/debounce.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import '../util/hass-util.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
import computeDomain from '../../js/common/entity/compute_domain.js';
import computeStateDisplay from '../../js/common/entity/compute_state_display.js';
{ {
const RECENT_THRESHOLD = 60000; // 1 minute const RECENT_THRESHOLD = 60000; // 1 minute
@ -31,11 +34,11 @@ import '../util/hass-util.js';
if (!unit) { if (!unit) {
timelineDevices.push({ timelineDevices.push({
name: window.hassUtil.computeStateName(stateInfo[0]), name: computeStateName(stateInfo[0]),
entity_id: stateInfo[0].entity_id, entity_id: stateInfo[0].entity_id,
data: stateInfo data: stateInfo
.map(state => ({ .map(state => ({
state_localize: window.hassUtil.computeStateDisplay(localize, state, language), state_localize: computeStateDisplay(localize, state, language),
state: state.state, state: state.state,
last_changed: state.last_changed, last_changed: state.last_changed,
})) }))
@ -56,10 +59,10 @@ import '../util/hass-util.js';
identifier: lineChartDevices[unit].map(states => states[0].entity_id).join(''), identifier: lineChartDevices[unit].map(states => states[0].entity_id).join(''),
data: lineChartDevices[unit].map((states) => { data: lineChartDevices[unit].map((states) => {
const last = states[states.length - 1]; const last = states[states.length - 1];
const domain = window.hassUtil.computeDomain(last); const domain = computeDomain(last);
return { return {
domain: domain, domain: domain,
name: window.hassUtil.computeStateName(last), name: computeStateName(last),
entity_id: last.entity_id, entity_id: last.entity_id,
states: states.map((state) => { states: states.map((state) => {
const result = { const result = {

View File

@ -8,6 +8,9 @@ import '../util/hass-mixins.js';
import './more-info/more-info-controls.js'; import './more-info/more-info-controls.js';
import './more-info/more-info-settings.js'; import './more-info/more-info-settings.js';
import computeDomain from '../../js/common/entity/compute_domain';
import isComponentLoaded from '../../js/common/config/is_component_loaded.js';
class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) { class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -113,7 +116,7 @@ class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) {
} }
_computeDomain(stateObj) { _computeDomain(stateObj) {
return stateObj ? window.hassUtil.computeDomain(stateObj) : ''; return stateObj ? computeDomain(stateObj) : '';
} }
_computeStateObj(hass) { _computeStateObj(hass) {
@ -131,7 +134,7 @@ class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) {
return; return;
} }
if (window.hassUtil.isComponentLoaded(this.hass, 'config.entity_registry') && if (isComponentLoaded(this.hass, 'config.entity_registry') &&
(!oldVal || oldVal.entity_id !== newVal.entity_id)) { (!oldVal || oldVal.entity_id !== newVal.entity_id)) {
this.hass.callApi('get', `config/entity_registry/${newVal.entity_id}`) this.hass.callApi('get', `config/entity_registry/${newVal.entity_id}`)
.then( .then(

View File

@ -3,6 +3,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../util/hass-mixins.js'; import '../../../util/hass-mixins.js';
import computeStateName from '../../../../js/common/entity/compute_state_name.js';
class MoreInfoCamera extends window.hassMixins.EventsMixin(PolymerElement) { class MoreInfoCamera extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -16,7 +18,7 @@ class MoreInfoCamera extends window.hassMixins.EventsMixin(PolymerElement) {
} }
</style> </style>
<img class="camera-image" src="[[computeCameraImageUrl(hass, stateObj, isVisible)]]" on-load="imageLoaded" alt="[[computeStateName(stateObj)]]"> <img class="camera-image" src="[[computeCameraImageUrl(hass, stateObj, isVisible)]]" on-load="imageLoaded" alt="[[_computeStateName(stateObj)]]">
`; `;
} }
@ -51,8 +53,8 @@ class MoreInfoCamera extends window.hassMixins.EventsMixin(PolymerElement) {
this.fire('iron-resize'); this.fire('iron-resize');
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
computeCameraImageUrl(hass, stateObj, isVisible) { computeCameraImageUrl(hass, stateObj, isVisible) {

View File

@ -12,6 +12,9 @@ import '../../../components/ha-climate-control.js';
import '../../../components/ha-paper-slider.js'; import '../../../components/ha-paper-slider.js';
import '../../../util/hass-mixins.js'; import '../../../util/hass-mixins.js';
import attributeClassNames from '../../../../js/common/entity/attribute_class_names.js';
import featureClassNames from '../../../../js/common/entity/feature_class_names';
class MoreInfoClimate extends window.hassMixins.EventsMixin(PolymerElement) { class MoreInfoClimate extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -338,7 +341,7 @@ class MoreInfoClimate extends window.hassMixins.EventsMixin(PolymerElement) {
} }
computeClassNames(stateObj) { computeClassNames(stateObj) {
const featureClassNames = { const _featureClassNames = {
1: 'has-target_temperature', 1: 'has-target_temperature',
2: 'has-target_temperature_high', 2: 'has-target_temperature_high',
4: 'has-target_temperature_low', 4: 'has-target_temperature_low',
@ -356,8 +359,8 @@ class MoreInfoClimate extends window.hassMixins.EventsMixin(PolymerElement) {
var classes = [ var classes = [
window.hassUtil.attributeClassNames(stateObj, ['current_temperature', 'current_humidity']), attributeClassNames(stateObj, ['current_temperature', 'current_humidity']),
window.hassUtil.featureClassNames(stateObj, featureClassNames), featureClassNames(stateObj, _featureClassNames),
]; ];
classes.push('more-info-climate'); classes.push('more-info-climate');

View File

@ -20,6 +20,9 @@ import './more-info-updater.js';
import './more-info-vacuum.js'; import './more-info-vacuum.js';
import './more-info-weather.js'; import './more-info-weather.js';
import stateMoreInfoType from '../../../../js/common/entity/state_more_info_type.js';
import dynamicContentUpdater from '../../../../js/common/dom/dynamic_content_updater.js';
class MoreInfoContent extends PolymerElement { class MoreInfoContent extends PolymerElement {
static get properties() { static get properties() {
return { return {
@ -56,9 +59,9 @@ class MoreInfoContent extends PolymerElement {
if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) { if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) {
moreInfoType = stateObj.attributes.custom_ui_more_info; moreInfoType = stateObj.attributes.custom_ui_more_info;
} else { } else {
moreInfoType = 'more-info-' + window.hassUtil.stateMoreInfoType(stateObj); moreInfoType = 'more-info-' + stateMoreInfoType(stateObj);
} }
window.hassUtil.dynamicContentUpdater( dynamicContentUpdater(
this, moreInfoType.toUpperCase(), this, moreInfoType.toUpperCase(),
{ hass: hass, stateObj: stateObj } { hass: hass, stateObj: stateObj }
); );

View File

@ -7,6 +7,9 @@ import '../../../components/ha-cover-tilt-controls.js';
import '../../../components/ha-paper-slider.js'; import '../../../components/ha-paper-slider.js';
import '../../../util/cover-model.js'; import '../../../util/cover-model.js';
import attributeClassNames from '../../../../js/common/entity/attribute_class_names';
import featureClassNames from '../../../../js/common/entity/feature_class_names';
{ {
const FEATURE_CLASS_NAMES = { const FEATURE_CLASS_NAMES = {
128: 'has-set_tilt_position', 128: 'has-set_tilt_position',
@ -93,8 +96,8 @@ import '../../../util/cover-model.js';
computeClassNames(stateObj) { computeClassNames(stateObj) {
var classes = [ var classes = [
window.hassUtil.attributeClassNames(stateObj, ['current_position', 'current_tilt_position']), attributeClassNames(stateObj, ['current_position', 'current_tilt_position']),
window.hassUtil.featureClassNames(stateObj, FEATURE_CLASS_NAMES), featureClassNames(stateObj, FEATURE_CLASS_NAMES),
]; ];
return classes.join(' '); return classes.join(' ');
} }

View File

@ -10,6 +10,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../components/ha-attributes.js'; import '../../../components/ha-attributes.js';
import '../../../util/hass-mixins.js'; import '../../../util/hass-mixins.js';
import attributeClassNames from '../../../../js/common/entity/attribute_class_names';
class MoreInfoFan extends window.hassMixins.EventsMixin(PolymerElement) { class MoreInfoFan extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -109,7 +111,7 @@ class MoreInfoFan extends window.hassMixins.EventsMixin(PolymerElement) {
} }
computeClassNames(stateObj) { computeClassNames(stateObj) {
return 'more-info-fan ' + window.hassUtil.attributeClassNames(stateObj, ['oscillating', 'speed_list', 'direction']); return 'more-info-fan ' + attributeClassNames(stateObj, ['oscillating', 'speed_list', 'direction']);
} }
speedChanged(speedIndex) { speedChanged(speedIndex) {

View File

@ -4,6 +4,10 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../state-summary/state-card-content.js'; import '../../../state-summary/state-card-content.js';
import computeDomain from '../../../../js/common/entity/compute_domain';
import dynamicContentUpdater from '../../../../js/common/dom/dynamic_content_updater.js';
import stateMoreInfoType from '../../../../js/common/entity/state_more_info_type.js';
class MoreInfoGroup extends PolymerElement { class MoreInfoGroup extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -69,7 +73,7 @@ class MoreInfoGroup extends PolymerElement {
if (states && states.length > 0) { if (states && states.length > 0) {
const baseStateObj = states.find(s => s.state === 'on') || states[0]; const baseStateObj = states.find(s => s.state === 'on') || states[0];
const groupDomain = window.hassUtil.computeDomain(baseStateObj); const groupDomain = computeDomain(baseStateObj);
// Groups need to be filtered out or we'll show content of // Groups need to be filtered out or we'll show content of
// first child above the children of the current group // first child above the children of the current group
@ -80,7 +84,7 @@ class MoreInfoGroup extends PolymerElement {
}); });
for (let i = 0; i < states.length; i++) { for (let i = 0; i < states.length; i++) {
if (groupDomain !== window.hassUtil.computeDomain(states[i])) { if (groupDomain !== computeDomain(states[i])) {
groupDomainStateObj = false; groupDomainStateObj = false;
break; break;
} }
@ -94,9 +98,9 @@ class MoreInfoGroup extends PolymerElement {
el.removeChild(el.lastChild); el.removeChild(el.lastChild);
} }
} else { } else {
window.hassUtil.dynamicContentUpdater( dynamicContentUpdater(
this.$.groupedControlDetails, this.$.groupedControlDetails,
'MORE-INFO-' + window.hassUtil.stateMoreInfoType(groupDomainStateObj).toUpperCase(), 'MORE-INFO-' + stateMoreInfoType(groupDomainStateObj).toUpperCase(),
{ stateObj: groupDomainStateObj, hass: this.hass } { stateObj: groupDomainStateObj, hass: this.hass }
); );
} }

View File

@ -7,6 +7,8 @@ import '@vaadin/vaadin-date-picker/vaadin-date-picker.js';
import '../../../components/ha-relative-time.js'; import '../../../components/ha-relative-time.js';
import attributeClassNames from '../../../../js/common/entity/attribute_class_names.js';
class DatetimeInput extends PolymerElement { class DatetimeInput extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -150,7 +152,7 @@ class DatetimeInput extends PolymerElement {
} }
computeClassNames(stateObj) { computeClassNames(stateObj) {
return 'more-info-input_datetime ' + window.hassUtil.attributeClassNames(stateObj, ['has_time', 'has_date']); return 'more-info-input_datetime ' + attributeClassNames(stateObj, ['has_time', 'has_date']);
} }
} }

View File

@ -10,6 +10,8 @@ import '../../../components/ha-color-picker.js';
import '../../../components/ha-labeled-slider.js'; import '../../../components/ha-labeled-slider.js';
import '../../../util/hass-mixins.js'; import '../../../util/hass-mixins.js';
import featureClassNames from '../../../../js/common/entity/feature_class_names';
{ {
const FEATURE_CLASS_NAMES = { const FEATURE_CLASS_NAMES = {
1: 'has-brightness', 1: 'has-brightness',
@ -176,7 +178,7 @@ import '../../../util/hass-mixins.js';
} }
computeClassNames(stateObj) { computeClassNames(stateObj) {
const classes = [window.hassUtil.featureClassNames(stateObj, FEATURE_CLASS_NAMES)]; const classes = [featureClassNames(stateObj, FEATURE_CLASS_NAMES)];
if (stateObj && stateObj.state === 'on') { if (stateObj && stateObj.state === 'on') {
classes.push('is-on'); classes.push('is-on');
} }

View File

@ -11,6 +11,9 @@ import '../../../components/ha-paper-slider.js';
import '../../../util/hass-media-player-model.js'; import '../../../util/hass-media-player-model.js';
import '../../../util/hass-mixins.js'; import '../../../util/hass-mixins.js';
import attributeClassNames from '../../../../js/common/entity/attribute_class_names';
import isComponentLoaded from '../../../../js/common/config/is_component_loaded.js';
{ {
class MoreInfoMediaPlayer extends window.hassMixins.EventsMixin(PolymerElement) { class MoreInfoMediaPlayer extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
@ -145,7 +148,7 @@ import '../../../util/hass-mixins.js';
} }
computeClassNames(stateObj) { computeClassNames(stateObj) {
return window.hassUtil.attributeClassNames(stateObj, ['volume_level']); return attributeClassNames(stateObj, ['volume_level']);
} }
computeMuteVolumeIcon(playerObj) { computeMuteVolumeIcon(playerObj) {
@ -180,7 +183,7 @@ import '../../../util/hass-mixins.js';
} }
computeTTSLoaded(hass) { computeTTSLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'tts'); return isComponentLoaded(hass, 'tts');
} }
handleTogglePower() { handleTogglePower() {

View File

@ -4,6 +4,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../../components/ha-relative-time.js'; import '../../../components/ha-relative-time.js';
import formatTime from '../../../../js/common/datetime/format_time.js';
class MoreInfoSun extends PolymerElement { class MoreInfoSun extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -64,7 +66,7 @@ class MoreInfoSun extends PolymerElement {
} }
itemValue(type) { itemValue(type) {
return window.hassUtil.formatTime(this.itemDate(type)); return formatTime(this.itemDate(type));
} }
} }

View File

@ -11,6 +11,11 @@ import '../../state-summary/state-card-content.js';
import '../../util/hass-mixins.js'; import '../../util/hass-mixins.js';
import './controls/more-info-content.js'; import './controls/more-info-content.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
import DOMAINS_MORE_INFO_NO_HISTORY from '../../../js/common/const.js';
{ {
const DOMAINS_NO_INFO = [ const DOMAINS_NO_INFO = [
'camera', 'camera',
@ -116,21 +121,21 @@ import './controls/more-info-content.js';
} }
_computeShowStateInfo(stateObj) { _computeShowStateInfo(stateObj) {
return !stateObj || !DOMAINS_NO_INFO.includes(window.hassUtil.computeDomain(stateObj)); return !stateObj || !DOMAINS_NO_INFO.includes(computeDomain(stateObj));
} }
_computeShowHistoryComponent(hass, stateObj) { _computeShowHistoryComponent(hass, stateObj) {
return hass && stateObj && return hass && stateObj &&
window.hassUtil.isComponentLoaded(hass, 'history') && isComponentLoaded(hass, 'history') &&
!window.hassUtil.DOMAINS_WITH_NO_HISTORY.includes(window.hassUtil.computeDomain(stateObj)); !DOMAINS_MORE_INFO_NO_HISTORY.includes(computeDomain(stateObj));
} }
_computeDomain(stateObj) { _computeDomain(stateObj) {
return stateObj ? window.hassUtil.computeDomain(stateObj) : ''; return stateObj ? computeDomain(stateObj) : '';
} }
_computeStateName(stateObj) { _computeStateName(stateObj) {
return stateObj ? window.hassUtil.computeStateName(stateObj) : ''; return stateObj ? computeStateName(stateObj) : '';
} }
_stateObjChanged(newVal) { _stateObjChanged(newVal) {

View File

@ -7,6 +7,9 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../util/hass-mixins.js'; import '../../util/hass-mixins.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
class MoreInfoSettings extends window.hassMixins.EventsMixin(PolymerElement) { class MoreInfoSettings extends window.hassMixins.EventsMixin(PolymerElement) {
static get template() { static get template() {
return html` return html`
@ -67,11 +70,11 @@ class MoreInfoSettings extends window.hassMixins.EventsMixin(PolymerElement) {
_computeStateName(stateObj) { _computeStateName(stateObj) {
if (!stateObj) return ''; if (!stateObj) return '';
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
_computeComponentLoaded(hass) { _computeComponentLoaded(hass) {
return window.hassUtil.isComponentLoaded(hass, 'config.entity_registry'); return isComponentLoaded(hass, 'config.entity_registry');
} }
_registryInfoChanged(newVal) { _registryInfoChanged(newVal) {

View File

@ -18,12 +18,14 @@ import './resources/panel-imports.js';
import './util/ha-pref-storage.js'; import './util/ha-pref-storage.js';
import './util/hass-call-api.js'; import './util/hass-call-api.js';
import './util/hass-translation.js'; import './util/hass-translation.js';
import './util/hass-util.js';
import './util/legacy-support'; import './util/legacy-support';
import './util/roboto.js'; import './util/roboto.js';
// For mdi icons. // For mdi icons.
import './components/ha-iconset-svg.js'; import './components/ha-iconset-svg.js';
import computeStateName from '../js/common/entity/compute_state_name.js';
import applyThemesOnElement from '../js/common/dom/apply_themes_on_element.js';
setPassiveTouchGestures(true); setPassiveTouchGestures(true);
/* LastPass createElement workaround. See #428 */ /* LastPass createElement workaround. See #428 */
document.createElement = Document.prototype.createElement; document.createElement = Document.prototype.createElement;
@ -180,7 +182,7 @@ class HomeAssistant extends PolymerElement {
var name; var name;
if (serviceData.entity_id && this.hass.states && if (serviceData.entity_id && this.hass.states &&
this.hass.states[serviceData.entity_id]) { this.hass.states[serviceData.entity_id]) {
name = window.hassUtil.computeStateName(this.hass.states[serviceData.entity_id]); name = computeStateName(this.hass.states[serviceData.entity_id]);
} }
if (service === 'turn_on' && serviceData.entity_id) { if (service === 'turn_on' && serviceData.entity_id) {
message = 'Turned on ' + (name || serviceData.entity_id) + '.'; message = 'Turned on ' + (name || serviceData.entity_id) + '.';
@ -253,7 +255,7 @@ class HomeAssistant extends PolymerElement {
this.hass.callApi('get', 'themes').then((themes) => { this.hass.callApi('get', 'themes').then((themes) => {
this._updateHass({ themes: themes }); this._updateHass({ themes: themes });
window.hassUtil.applyThemesOnElement( applyThemesOnElement(
document.documentElement, document.documentElement,
themes, themes,
this.hass.selectedTheme, this.hass.selectedTheme,
@ -262,7 +264,7 @@ class HomeAssistant extends PolymerElement {
}); });
conn.subscribeEvents((event) => { conn.subscribeEvents((event) => {
this._updateHass({ themes: event.data }); this._updateHass({ themes: event.data });
window.hassUtil.applyThemesOnElement( applyThemesOnElement(
document.documentElement, document.documentElement,
event.data, event.data,
this.hass.selectedTheme, this.hass.selectedTheme,
@ -326,7 +328,7 @@ class HomeAssistant extends PolymerElement {
setTheme(event) { setTheme(event) {
this._updateHass({ selectedTheme: event.detail }); this._updateHass({ selectedTheme: event.detail });
window.hassUtil.applyThemesOnElement( applyThemesOnElement(
document.documentElement, document.documentElement,
this.hass.themes, this.hass.themes,
this.hass.selectedTheme, this.hass.selectedTheme,

View File

@ -11,7 +11,6 @@ import '../dialogs/ha-more-info-dialog.js';
import '../dialogs/ha-voice-command-dialog.js'; import '../dialogs/ha-voice-command-dialog.js';
import '../util/ha-url-sync.js'; import '../util/ha-url-sync.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import '../util/hass-util.js';
import './partial-cards.js'; import './partial-cards.js';
import './partial-panel-resolver.js'; import './partial-panel-resolver.js';

View File

@ -16,6 +16,10 @@ import '../components/ha-start-voice-button.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import './ha-app-layout.js'; import './ha-app-layout.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
import computeDomain from '../../js/common/entity/compute_domain.js';
import computeLocationName from '../../js/common/config/location_name.js';
{ {
const DEFAULT_VIEW_ENTITY_ID = 'group.default_view'; const DEFAULT_VIEW_ENTITY_ID = 'group.default_view';
const ALWAYS_SHOW_DOMAIN = ['persistent_notification', 'configurator']; const ALWAYS_SHOW_DOMAIN = ['persistent_notification', 'configurator'];
@ -58,20 +62,20 @@ import './ha-app-layout.js';
</template> </template>
<template is="dom-if" if="[[defaultView]]"> <template is="dom-if" if="[[defaultView]]">
<template is="dom-if" if="[[defaultView.attributes.icon]]"> <template is="dom-if" if="[[defaultView.attributes.icon]]">
<iron-icon title\$="[[computeStateName(defaultView)]]" icon="[[defaultView.attributes.icon]]"></iron-icon> <iron-icon title\$="[[_computeStateName(defaultView)]]" icon="[[defaultView.attributes.icon]]"></iron-icon>
</template> </template>
<template is="dom-if" if="[[!defaultView.attributes.icon]]"> <template is="dom-if" if="[[!defaultView.attributes.icon]]">
[[computeStateName(defaultView)]] [[_computeStateName(defaultView)]]
</template> </template>
</template> </template>
</paper-tab> </paper-tab>
<template is="dom-repeat" items="[[views]]"> <template is="dom-repeat" items="[[views]]">
<paper-tab data-entity\$="[[item.entity_id]]" on-click="scrollToTop"> <paper-tab data-entity\$="[[item.entity_id]]" on-click="scrollToTop">
<template is="dom-if" if="[[item.attributes.icon]]"> <template is="dom-if" if="[[item.attributes.icon]]">
<iron-icon title\$="[[computeStateName(item)]]" icon="[[item.attributes.icon]]"></iron-icon> <iron-icon title\$="[[_computeStateName(item)]]" icon="[[item.attributes.icon]]"></iron-icon>
</template> </template>
<template is="dom-if" if="[[!item.attributes.icon]]"> <template is="dom-if" if="[[!item.attributes.icon]]">
[[computeStateName(item)]] [[_computeStateName(item)]]
</template> </template>
</paper-tab> </paper-tab>
</template> </template>
@ -127,7 +131,7 @@ import './ha-app-layout.js';
locationName: { locationName: {
type: String, type: String,
value: '', value: '',
computed: 'computeLocationName(hass)', computed: '_computeLocationName(hass)',
}, },
currentView: { currentView: {
@ -249,12 +253,12 @@ import './ha-app-layout.js';
return (views && views.length > 0 && !defaultView && locationName === 'Home') || !locationName ? 'Home Assistant' : locationName; return (views && views.length > 0 && !defaultView && locationName === 'Home') || !locationName ? 'Home Assistant' : locationName;
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
computeLocationName(hass) { _computeLocationName(hass) {
return window.hassUtil.computeLocationName(hass); return computeLocationName(hass);
} }
hassChanged(hass) { hassChanged(hass) {
@ -311,7 +315,7 @@ import './ha-app-layout.js';
entityIds.forEach((entityId) => { entityIds.forEach((entityId) => {
const state = hass.states[entityId]; const state = hass.states[entityId];
if (ALWAYS_SHOW_DOMAIN.includes(window.hassUtil.computeDomain(state))) { if (ALWAYS_SHOW_DOMAIN.includes(computeDomain(state))) {
states[entityId] = state; states[entityId] = state;
} }
}); });

View File

@ -6,6 +6,8 @@ import '../util/hass-mixins.js';
import './hass-loading-screen.js'; import './hass-loading-screen.js';
import { importHref } from '../resources/html-import/import-href'; import { importHref } from '../resources/html-import/import-href';
import dynamicContentUpdater from '../../js/common/dom/dynamic_content_updater.js';
const loaded = {}; const loaded = {};
function ensureLoaded(panel) { function ensureLoaded(panel) {
@ -163,7 +165,7 @@ class PartialPanelResolver extends window.hassMixins.NavigateMixin(PolymerElemen
loadingProm.then( loadingProm.then(
() => { () => {
window.hassUtil.dynamicContentUpdater(this.$.panel, 'ha-panel-' + panel.component_name, { dynamicContentUpdater(this.$.panel, 'ha-panel-' + panel.component_name, {
hass: this.hass, hass: this.hass,
narrow: this.narrow, narrow: this.narrow,
showMenu: this.showMenu, showMenu: this.showMenu,

View File

@ -1,6 +1,5 @@
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../util/hass-util.js';
import './state-card-climate.js'; import './state-card-climate.js';
import './state-card-configurator.js'; import './state-card-configurator.js';
import './state-card-cover.js'; import './state-card-cover.js';
@ -15,6 +14,9 @@ import './state-card-timer.js';
import './state-card-toggle.js'; import './state-card-toggle.js';
import './state-card-weblink.js'; import './state-card-weblink.js';
import stateCardType from '../../js/common/entity/state_card_type.js';
import dynamicContentUpdater from '../../js/common/dom/dynamic_content_updater.js';
class StateCardContent extends PolymerElement { class StateCardContent extends PolymerElement {
static get properties() { static get properties() {
return { return {
@ -34,16 +36,16 @@ class StateCardContent extends PolymerElement {
} }
inputChanged(hass, inDialog, stateObj) { inputChanged(hass, inDialog, stateObj) {
let stateCardType; let stateCard;
if (!stateObj || !hass) return; if (!stateObj || !hass) return;
if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) {
stateCardType = stateObj.attributes.custom_ui_state_card; stateCard = stateObj.attributes.custom_ui_state_card;
} else { } else {
stateCardType = 'state-card-' + window.hassUtil.stateCardType(hass, stateObj); stateCard = 'state-card-' + stateCardType(hass, stateObj);
} }
window.hassUtil.dynamicContentUpdater( dynamicContentUpdater(
this, this,
stateCardType.toUpperCase(), stateCard.toUpperCase(),
{ {
hass: hass, hass: hass,
stateObj: stateObj, stateObj: stateObj,

View File

@ -7,7 +7,6 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/entity/state-info.js'; import '../components/entity/state-info.js';
import '../util/hass-util.js';
class StateCardInputNumber extends mixinBehaviors([ class StateCardInputNumber extends mixinBehaviors([
IronResizableBehavior IronResizableBehavior

View File

@ -6,6 +6,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/entity/state-badge.js'; import '../components/entity/state-badge.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
class StateCardInputSelect extends PolymerElement { class StateCardInputSelect extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -30,7 +32,7 @@ class StateCardInputSelect extends PolymerElement {
</style> </style>
<state-badge state-obj="[[stateObj]]"></state-badge> <state-badge state-obj="[[stateObj]]"></state-badge>
<paper-dropdown-menu on-click="stopPropagation" selected-item-label="{{selectedOption}}" label="[[computeStateName(stateObj)]]"> <paper-dropdown-menu on-click="stopPropagation" selected-item-label="{{selectedOption}}" label="[[_computeStateName(stateObj)]]">
<paper-listbox slot="dropdown-content" selected="[[computeSelected(stateObj)]]"> <paper-listbox slot="dropdown-content" selected="[[computeSelected(stateObj)]]">
<template is="dom-repeat" items="[[stateObj.attributes.options]]"> <template is="dom-repeat" items="[[stateObj.attributes.options]]">
<paper-item>[[item]]</paper-item> <paper-item>[[item]]</paper-item>
@ -55,8 +57,8 @@ class StateCardInputSelect extends PolymerElement {
}; };
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
computeSelected(stateObj) { computeSelected(stateObj) {

View File

@ -4,7 +4,6 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js';
import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/entity/state-info.js'; import '../components/entity/state-info.js';
import '../util/hass-util.js';
class StateCardInputText extends PolymerElement { class StateCardInputText extends PolymerElement {
static get template() { static get template() {

View File

@ -4,7 +4,9 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/entity/state-info.js'; import '../components/entity/state-info.js';
import '../util/hass-mixins.js'; import '../util/hass-mixins.js';
import '../util/hass-util.js';
import timerTimeRemaining from '../../js/common/entity/timer_time_remaining.js';
import secondsToDuration from '../../js/common/datetime/seconds_to_duration.js';
class StateCardTimer extends window.hassMixins.LocalizeMixin(PolymerElement) { class StateCardTimer extends window.hassMixins.LocalizeMixin(PolymerElement) {
static get template() { static get template() {
@ -23,7 +25,7 @@ class StateCardTimer extends window.hassMixins.LocalizeMixin(PolymerElement) {
<div class="horizontal justified layout"> <div class="horizontal justified layout">
<state-info state-obj="[[stateObj]]" in-dialog="[[inDialog]]"></state-info> <state-info state-obj="[[stateObj]]" in-dialog="[[inDialog]]"></state-info>
<div class="state">[[secondsToDuration(timeRemaining)]]</div> <div class="state">[[_secondsToDuration(timeRemaining)]]</div>
</div> </div>
`; `;
} }
@ -74,11 +76,11 @@ class StateCardTimer extends window.hassMixins.LocalizeMixin(PolymerElement) {
} }
calculateRemaining(stateObj) { calculateRemaining(stateObj) {
this.timeRemaining = window.hassUtil.timerTimeRemaining(stateObj); this.timeRemaining = timerTimeRemaining(stateObj);
} }
secondsToDuration(time) { _secondsToDuration(time) {
return window.hassUtil.secondsToDuration(time); return secondsToDuration(time);
} }
} }
customElements.define('state-card-timer', StateCardTimer); customElements.define('state-card-timer', StateCardTimer);

View File

@ -3,6 +3,8 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../components/entity/state-badge.js'; import '../components/entity/state-badge.js';
import computeStateName from '../../js/common/entity/compute_state_name.js';
class StateCardWeblink extends PolymerElement { class StateCardWeblink extends PolymerElement {
static get template() { static get template() {
return html` return html`
@ -22,7 +24,7 @@ class StateCardWeblink extends PolymerElement {
</style> </style>
<state-badge state-obj="[[stateObj]]"></state-badge> <state-badge state-obj="[[stateObj]]"></state-badge>
<a href\$="[[stateObj.state]]" target="_blank" class="name" id="link">[[computeStateName(stateObj)]]</a> <a href\$="[[stateObj.state]]" target="_blank" class="name" id="link">[[_computeStateName(stateObj)]]</a>
`; `;
} }
@ -41,8 +43,8 @@ class StateCardWeblink extends PolymerElement {
this.addEventListener('click', ev => this.onTap(ev)); this.addEventListener('click', ev => this.onTap(ev));
} }
computeStateName(stateObj) { _computeStateName(stateObj) {
return window.hassUtil.computeStateName(stateObj); return computeStateName(stateObj);
} }
onTap(ev) { onTap(ev) {