computeStateDomain instead of computeDmoain

This commit is contained in:
Paulus Schoutsen 2018-05-16 09:20:21 -04:00
parent 7b3b717f43
commit 3fa9896543
16 changed files with 39 additions and 40 deletions

View File

@ -5,7 +5,7 @@ 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'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
class HaConfigAutomation extends PolymerElement { class HaConfigAutomation extends PolymerElement {
static get template() { static get template() {
@ -76,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 (computeDomain(entity) === 'automation' && if (computeStateDomain(entity) === 'automation' &&
'id' in entity.attributes) { 'id' in entity.attributes) {
automations.push(entity); automations.push(entity);
} }

View File

@ -12,7 +12,7 @@ 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 computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
import sortByName from '../../../js/common/entity/states_sort_by_name.js'; import sortByName from '../../../js/common/entity/states_sort_by_name.js';
/* /*
@ -62,7 +62,7 @@ class HaConfigCustomize extends window.hassMixins.LocalizeMixin(PolymerElement)
value: { value: {
component: 'ha-form-customize', component: 'ha-form-customize',
computeSelectCaption: stateObj => computeSelectCaption: stateObj =>
computeStateName(stateObj) + ' (' + computeDomain(stateObj) + ')' computeStateName(stateObj) + ' (' + computeStateDomain(stateObj) + ')'
} }
}, },
}; };

View File

@ -6,7 +6,7 @@ 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 computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
class HaConfigScript extends PolymerElement { class HaConfigScript extends PolymerElement {
static get template() { static get template() {
@ -77,7 +77,7 @@ 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 (computeDomain(entity) === 'script') { if (computeStateDomain(entity) === 'script') {
scripts.push(entity); scripts.push(entity);
} }
}); });

View File

@ -27,7 +27,7 @@ import './zwave-values.js';
import sortByName from '../../../js/common/entity/states_sort_by_name.js'; import sortByName from '../../../js/common/entity/states_sort_by_name.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js'; import computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
/* /*
* @appliesMixin window.hassMixins.LocalizeMixin * @appliesMixin window.hassMixins.LocalizeMixin
*/ */
@ -397,7 +397,7 @@ class HaConfigZwave extends window.hassMixins.LocalizeMixin(PolymerElement) {
} }
computeSelectCaptionEnt(stateObj) { computeSelectCaptionEnt(stateObj) {
return (computeDomain(stateObj) + '.' return (computeStateDomain(stateObj) + '.'
+ computeStateName(stateObj)); + computeStateName(stateObj));
} }

View File

@ -8,7 +8,7 @@ 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 computeStateDomain from '../../js/common/entity/compute_state_domain.js';
import computeStateName from '../../js/common/entity/compute_state_name.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';
@ -109,7 +109,7 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
var title = computeStateName(entity); var title = computeStateName(entity);
if ((entity.attributes.hidden && if ((entity.attributes.hidden &&
computeDomain(entity) !== 'zone') || computeStateDomain(entity) !== 'zone') ||
entity.state === 'home' || entity.state === 'home' ||
!('latitude' in entity.attributes) || !('latitude' in entity.attributes) ||
!('longitude' in entity.attributes)) { !('longitude' in entity.attributes)) {
@ -118,7 +118,7 @@ class HaPanelMap extends window.hassMixins.LocalizeMixin(PolymerElement) {
var icon; var icon;
if (computeDomain(entity) === 'zone') { if (computeStateDomain(entity) === 'zone') {
// DRAW ZONE // DRAW ZONE
if (entity.attributes.passive) return; if (entity.attributes.passive) return;

View File

@ -53,7 +53,7 @@ import computeStateName from '../../js/common/entity/compute_state_name.js';
<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]]">
([[localize('ui.card.camera.not_available')]]) ([[localize('ui.card.camera.not_available')]])
</template> </template>

View File

@ -7,7 +7,7 @@ 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 computeStateDomain from '../../js/common/entity/compute_state_domain.js';
import computeStateName from '../../js/common/entity/compute_state_name.js'; import computeStateName from '../../js/common/entity/compute_state_name.js';
import stateMoreInfoType from '../../js/common/entity/state_more_info_type.js'; import stateMoreInfoType from '../../js/common/entity/state_more_info_type.js';
import canToggleState from '../../js/common/entity/can_toggle_state.js'; import canToggleState from '../../js/common/entity/can_toggle_state.js';
@ -86,7 +86,7 @@ class HaEntitiesCard extends
if (groupEntity) { if (groupEntity) {
return computeStateName(groupEntity).trim(); return computeStateName(groupEntity).trim();
} }
const domain = computeDomain(states[0]); const domain = computeStateDomain(states[0]);
return (localize && localize(`domain.${domain}`)) || domain.replace(/_/g, ' '); return (localize && localize(`domain.${domain}`)) || domain.replace(/_/g, ' ');
} }

View File

@ -4,7 +4,7 @@ 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 { STATES_OFF } from '../../../js/common/const.js';
import computeDomain from '../../../js/common/entity/compute_domain'; import computeStateDomain from '../../../js/common/entity/compute_state_domain';
class HaEntityToggle extends PolymerElement { class HaEntityToggle extends PolymerElement {
static get template() { static get template() {
@ -116,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 = computeDomain(this.stateObj); const stateDomain = computeStateDomain(this.stateObj);
let serviceDomain; let serviceDomain;
let service; let service;

View File

@ -4,7 +4,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js';
import '../../util/hass-mixins.js'; import '../../util/hass-mixins.js';
import '../ha-label-badge.js'; import '../ha-label-badge.js';
import computeDomain from '../../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
import computeStateName from '../../../js/common/entity/compute_state_name.js'; import computeStateName from '../../../js/common/entity/compute_state_name.js';
import domainIcon from '../../../js/common/entity/domain_icon.js'; import domainIcon from '../../../js/common/entity/domain_icon.js';
import stateIcon from '../../../js/common/entity/state_icon.js'; import stateIcon from '../../../js/common/entity/state_icon.js';
@ -97,13 +97,13 @@ class HaStateLabelBadge extends
} }
computeClassNames(state) { computeClassNames(state) {
const classes = [computeDomain(state)]; const classes = [computeStateDomain(state)];
classes.push(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 = computeDomain(state); const domain = computeStateDomain(state);
switch (domain) { switch (domain) {
case 'binary_sensor': case 'binary_sensor':
case 'device_tracker': case 'device_tracker':
@ -125,7 +125,7 @@ class HaStateLabelBadge extends
if (state.state === 'unavailable') { if (state.state === 'unavailable') {
return null; return null;
} }
const domain = computeDomain(state); const domain = computeStateDomain(state);
switch (domain) { switch (domain) {
case 'alarm_control_panel': case 'alarm_control_panel':
if (state.state === 'pending') { if (state.state === 'pending') {
@ -162,7 +162,7 @@ class HaStateLabelBadge extends
} }
computeLabel(localize, state, _timerTimeRemaining) { computeLabel(localize, state, _timerTimeRemaining) {
const domain = computeDomain(state); const domain = computeStateDomain(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
@ -194,7 +194,7 @@ class HaStateLabelBadge extends
startInterval(stateObj) { startInterval(stateObj) {
this.clearInterval(); this.clearInterval();
if (computeDomain(stateObj) === 'timer') { if (computeStateDomain(stateObj) === 'timer') {
this.calculateTimerRemaining(stateObj); this.calculateTimerRemaining(stateObj);
if (stateObj.state === 'active') { if (stateObj.state === 'active') {

View File

@ -8,7 +8,7 @@ import '../cards/ha-badges-card.js';
import '../cards/ha-card-chooser.js'; import '../cards/ha-card-chooser.js';
import './ha-demo-badge.js'; import './ha-demo-badge.js';
import computeDomain from '../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../js/common/entity/compute_state_domain.js';
{ {
// mapping domain to size of the card. // mapping domain to size of the card.
@ -247,7 +247,7 @@ import computeDomain from '../../js/common/entity/compute_domain.js';
let size = 0; let size = 0;
entities.forEach((entity) => { entities.forEach((entity) => {
const domain = computeDomain(entity); const domain = computeStateDomain(entity);
if (domain in DOMAINS_WITH_CARD) { if (domain in DOMAINS_WITH_CARD) {
owncard.push(entity); owncard.push(entity);
@ -275,7 +275,7 @@ import computeDomain from '../../js/common/entity/compute_domain.js';
owncard.forEach((entity) => { owncard.forEach((entity) => {
cards.columns[curIndex].push({ cards.columns[curIndex].push({
hass: hass, hass: hass,
cardType: computeDomain(entity), cardType: computeStateDomain(entity),
stateObj: entity, stateObj: entity,
}); });
}); });
@ -295,7 +295,7 @@ import computeDomain from '../../js/common/entity/compute_domain.js';
Object.keys(splitted.ungrouped).forEach((key) => { Object.keys(splitted.ungrouped).forEach((key) => {
const state = splitted.ungrouped[key]; const state = splitted.ungrouped[key];
const domain = computeDomain(state); const domain = computeStateDomain(state);
if (domain === 'a') { if (domain === 'a') {
cards.demo = true; cards.demo = true;

View File

@ -5,7 +5,7 @@ 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 computeStateName from '../../js/common/entity/compute_state_name.js';
import computeDomain from '../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../js/common/entity/compute_state_domain.js';
import computeStateDisplay from '../../js/common/entity/compute_state_display.js'; import computeStateDisplay from '../../js/common/entity/compute_state_display.js';
{ {
@ -59,7 +59,7 @@ import computeStateDisplay from '../../js/common/entity/compute_state_display.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 = computeDomain(last); const domain = computeStateDomain(last);
return { return {
domain: domain, domain: domain,
name: computeStateName(last), name: computeStateName(last),

View File

@ -8,7 +8,7 @@ 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 computeStateDomain from '../../js/common/entity/compute_state_domain';
import isComponentLoaded from '../../js/common/config/is_component_loaded.js'; import isComponentLoaded from '../../js/common/config/is_component_loaded.js';
class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) { class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) {
@ -116,7 +116,7 @@ class HaMoreInfoDialog extends window.hassMixins.DialogMixin(PolymerElement) {
} }
_computeDomain(stateObj) { _computeDomain(stateObj) {
return stateObj ? computeDomain(stateObj) : ''; return stateObj ? computeStateDomain(stateObj) : '';
} }
_computeStateObj(hass) { _computeStateObj(hass) {

View File

@ -4,7 +4,7 @@ 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 computeStateDomain from '../../../../js/common/entity/compute_state_domain';
import dynamicContentUpdater from '../../../../js/common/dom/dynamic_content_updater.js'; import dynamicContentUpdater from '../../../../js/common/dom/dynamic_content_updater.js';
import stateMoreInfoType from '../../../../js/common/entity/state_more_info_type.js'; import stateMoreInfoType from '../../../../js/common/entity/state_more_info_type.js';
@ -73,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 = computeDomain(baseStateObj); const groupDomain = computeStateDomain(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
@ -84,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 !== computeDomain(states[i])) { if (groupDomain !== computeStateDomain(states[i])) {
groupDomainStateObj = false; groupDomainStateObj = false;
break; break;
} }

View File

@ -12,7 +12,7 @@ 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 computeStateName from '../../../js/common/entity/compute_state_name.js';
import computeDomain from '../../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../../js/common/entity/compute_state_domain.js';
import isComponentLoaded from '../../../js/common/config/is_component_loaded.js'; import isComponentLoaded from '../../../js/common/config/is_component_loaded.js';
import { DOMAINS_MORE_INFO_NO_HISTORY } from '../../../js/common/const.js'; import { DOMAINS_MORE_INFO_NO_HISTORY } from '../../../js/common/const.js';
@ -121,17 +121,17 @@ import { DOMAINS_MORE_INFO_NO_HISTORY } from '../../../js/common/const.js';
} }
_computeShowStateInfo(stateObj) { _computeShowStateInfo(stateObj) {
return !stateObj || !DOMAINS_NO_INFO.includes(computeDomain(stateObj)); return !stateObj || !DOMAINS_NO_INFO.includes(computeStateDomain(stateObj));
} }
_computeShowHistoryComponent(hass, stateObj) { _computeShowHistoryComponent(hass, stateObj) {
return hass && stateObj && return hass && stateObj &&
isComponentLoaded(hass, 'history') && isComponentLoaded(hass, 'history') &&
!DOMAINS_MORE_INFO_NO_HISTORY.includes(computeDomain(stateObj)); !DOMAINS_MORE_INFO_NO_HISTORY.includes(computeStateDomain(stateObj));
} }
_computeDomain(stateObj) { _computeDomain(stateObj) {
return stateObj ? computeDomain(stateObj) : ''; return stateObj ? computeStateDomain(stateObj) : '';
} }
_computeStateName(stateObj) { _computeStateName(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/ha-sidebar.js'; import '../components/ha-sidebar.js';
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';

View File

@ -17,7 +17,7 @@ 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 computeStateName from '../../js/common/entity/compute_state_name.js';
import computeDomain from '../../js/common/entity/compute_domain.js'; import computeStateDomain from '../../js/common/entity/compute_state_domain.js';
import computeLocationName from '../../js/common/config/location_name.js'; import computeLocationName from '../../js/common/config/location_name.js';
{ {
@ -315,7 +315,7 @@ import computeLocationName from '../../js/common/config/location_name.js';
entityIds.forEach((entityId) => { entityIds.forEach((entityId) => {
const state = hass.states[entityId]; const state = hass.states[entityId];
if (ALWAYS_SHOW_DOMAIN.includes(computeDomain(state))) { if (ALWAYS_SHOW_DOMAIN.includes(computeStateDomain(state))) {
states[entityId] = state; states[entityId] = state;
} }
}); });