From d7b2a0388006f88ca531dd295cece298482c4525 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 19 May 2018 16:21:29 -0400 Subject: [PATCH] Don't use window to share CoverEntity (#1192) * Don't use window to share CoverEntity * Lint --- src/components/ha-cover-controls.js | 4 ++-- src/components/ha-cover-tilt-controls.js | 4 ++-- src/dialogs/more-info/controls/more-info-cover.js | 4 ++-- src/state-summary/state-card-cover.js | 3 ++- src/util/cover-model.js | 8 ++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/ha-cover-controls.js b/src/components/ha-cover-controls.js index 24655f0387..223c599b07 100644 --- a/src/components/ha-cover-controls.js +++ b/src/components/ha-cover-controls.js @@ -2,7 +2,7 @@ import '@polymer/paper-icon-button/paper-icon-button.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; -import '../util/cover-model.js'; +import CoverEntity from '../util/cover-model.js'; class HaCoverControls extends PolymerElement { static get template() { @@ -39,7 +39,7 @@ class HaCoverControls extends PolymerElement { }; } computeEntityObj(hass, stateObj) { - return new window.CoverEntity(hass, stateObj); + return new CoverEntity(hass, stateObj); } computeOpenDisabled(stateObj, entityObj) { var assumedState = stateObj.attributes.assumed_state === true; diff --git a/src/components/ha-cover-tilt-controls.js b/src/components/ha-cover-tilt-controls.js index 2875f910a7..baf63c22c9 100644 --- a/src/components/ha-cover-tilt-controls.js +++ b/src/components/ha-cover-tilt-controls.js @@ -3,7 +3,7 @@ import '@polymer/paper-icon-button/paper-icon-button.js'; import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; -import '../util/cover-model.js'; +import CoverEntity from '../util/cover-model.js'; class HaCoverTiltControls extends PolymerElement { static get template() { @@ -38,7 +38,7 @@ class HaCoverTiltControls extends PolymerElement { }; } computeEntityObj(hass, stateObj) { - return new window.CoverEntity(hass, stateObj); + return new CoverEntity(hass, stateObj); } computeOpenDisabled(stateObj, entityObj) { var assumedState = stateObj.attributes.assumed_state === true; diff --git a/src/dialogs/more-info/controls/more-info-cover.js b/src/dialogs/more-info/controls/more-info-cover.js index a5c81d0042..3edf437175 100644 --- a/src/dialogs/more-info/controls/more-info-cover.js +++ b/src/dialogs/more-info/controls/more-info-cover.js @@ -5,7 +5,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import '../../../components/ha-cover-tilt-controls.js'; import '../../../components/ha-paper-slider.js'; -import '../../../util/cover-model.js'; +import CoverEntity from '../../../util/cover-model.js'; import attributeClassNames from '../../../common/entity/attribute_class_names'; import featureClassNames from '../../../common/entity/feature_class_names'; @@ -82,7 +82,7 @@ import featureClassNames from '../../../common/entity/feature_class_names'; } computeEntityObj(hass, stateObj) { - return new window.CoverEntity(hass, stateObj); + return new CoverEntity(hass, stateObj); } stateObjChanged(newVal) { diff --git a/src/state-summary/state-card-cover.js b/src/state-summary/state-card-cover.js index a10ea6806c..9a89280e89 100644 --- a/src/state-summary/state-card-cover.js +++ b/src/state-summary/state-card-cover.js @@ -5,6 +5,7 @@ import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import '../components/entity/state-info.js'; import '../components/ha-cover-controls.js'; import '../components/ha-cover-tilt-controls.js'; +import CoverEntity from '../util/cover-model.js'; class StateCardCover extends PolymerElement { static get template() { @@ -42,7 +43,7 @@ class StateCardCover extends PolymerElement { } computeEntityObj(hass, stateObj) { - var entity = new window.CoverEntity(hass, stateObj); + var entity = new CoverEntity(hass, stateObj); return entity; } } diff --git a/src/util/cover-model.js b/src/util/cover-model.js index 7fede5bbe6..af1caa2d5c 100644 --- a/src/util/cover-model.js +++ b/src/util/cover-model.js @@ -1,11 +1,11 @@ -window.CoverEntity = function (hass, stateObj) { +export default function CoverEntity(hass, stateObj) { this.hass = hass; this.stateObj = stateObj; -}; +} function addGetter(name, getter) { Object.defineProperty( - window.CoverEntity.prototype, name, + CoverEntity.prototype, name, { get: getter } ); } @@ -74,7 +74,7 @@ addGetter('isTiltOnly', function () { /* eslint-enable no-bitwise */ -Object.assign(window.CoverEntity.prototype, { +Object.assign(CoverEntity.prototype, { openCover: function () { this.callService('open_cover'); },