diff --git a/package.json b/package.json index 3356d15c2b..f0e33cfe41 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "license": "MIT", "dependencies": { "home-assistant-js": "git+https://github.com/home-assistant/home-assistant-js.git#ff2bd7efd23bb731d1bcc88996154c5d573395ed", - "lodash": "^4.11.2", "moment": "^2.13.0" }, "devDependencies": { diff --git a/src/cards/ha-badges-card.html b/src/cards/ha-badges-card.html index 2d55578198..7bea8c26c3 100644 --- a/src/cards/ha-badges-card.html +++ b/src/cards/ha-badges-card.html @@ -7,7 +7,7 @@ diff --git a/src/cards/ha-badges-card.js b/src/cards/ha-badges-card.js index 988d2aa5f1..be1078458f 100644 --- a/src/cards/ha-badges-card.js +++ b/src/cards/ha-badges-card.js @@ -6,6 +6,10 @@ export default new Polymer({ is: 'ha-badges-card', properties: { + hass: { + type: Object, + }, + states: { type: Array, }, diff --git a/src/cards/ha-camera-card.js b/src/cards/ha-camera-card.js index c69c1897e6..1b6307d964 100644 --- a/src/cards/ha-camera-card.js +++ b/src/cards/ha-camera-card.js @@ -1,7 +1,4 @@ import Polymer from '../polymer'; -import hass from '../util/home-assistant-js-instance'; - -const { moreInfoActions } = hass; const UPDATE_INTERVAL = 10000; // ms @@ -9,6 +6,10 @@ export default new Polymer({ is: 'ha-camera-card', properties: { + hass: { + type: Object, + }, + stateObj: { type: Object, observer: 'updateCameraFeedSrc', @@ -47,7 +48,7 @@ export default new Polymer({ }, cardTapped() { - this.async(() => moreInfoActions.selectEntity(this.stateObj.entityId), 1); + this.async(() => this.hass.moreInfoActions.selectEntity(this.stateObj.entityId), 1); }, updateCameraFeedSrc(stateObj) { diff --git a/src/cards/ha-entities-card.html b/src/cards/ha-entities-card.html index 7db7f1d806..bff8f70eda 100644 --- a/src/cards/ha-entities-card.html +++ b/src/cards/ha-entities-card.html @@ -38,13 +38,18 @@
[[computeTitle(states, groupEntity)]]
diff --git a/src/cards/ha-entities-card.js b/src/cards/ha-entities-card.js index abc53f88d5..bced27b17e 100644 --- a/src/cards/ha-entities-card.js +++ b/src/cards/ha-entities-card.js @@ -1,17 +1,18 @@ import Polymer from '../polymer'; -import hass from '../util/home-assistant-js-instance'; import canToggle from '../util/can-toggle'; require('../components/ha-card'); require('../components/entity/ha-entity-toggle'); require('../state-summary/state-card-content'); -const { moreInfoActions } = hass; - export default new Polymer({ is: 'ha-entities-card', properties: { + hass: { + type: Object, + }, + states: { type: Array, }, @@ -45,7 +46,7 @@ export default new Polymer({ } else { entityId = this.groupEntity.entityId; } - this.async(() => moreInfoActions.selectEntity(entityId), 1); + this.async(() => this.hass.moreInfoActions.selectEntity(entityId), 1); }, showGroupToggle(groupEntity, states) { @@ -54,6 +55,6 @@ export default new Polymer({ } // only show if we can toggle 2+ entities in group - return states.reduce((sum, state) => sum + canToggle(state.entityId), 0) > 1; + return states.reduce((sum, state) => sum + canToggle(this.hass, state.entityId), 0) > 1; }, }); diff --git a/src/cards/ha-media_player-card.js b/src/cards/ha-media_player-card.js index 32a23a57f4..277fe6917e 100644 --- a/src/cards/ha-media_player-card.js +++ b/src/cards/ha-media_player-card.js @@ -1,14 +1,15 @@ import classnames from 'classnames'; import Polymer from '../polymer'; -import hass from '../util/home-assistant-js-instance'; - -const { moreInfoActions } = hass; export default new Polymer({ is: 'ha-media_player-card', properties: { + hass: { + type: Object, + }, + stateObj: { type: Object, }, @@ -54,7 +55,7 @@ export default new Polymer({ }, computePlayerObj(stateObj) { - return stateObj.domainModel(hass); + return stateObj.domainModel(this.hass); }, computePlaybackControlIcon(playerObj) { @@ -77,7 +78,7 @@ export default new Polymer({ handleOpenMoreInfo(ev) { ev.stopPropagation(); - this.async(() => moreInfoActions.selectEntity(this.stateObj.entityId), 1); + this.async(() => this.hass.moreInfoActions.selectEntity(this.stateObj.entityId), 1); }, handlePlaybackControl(ev) { diff --git a/src/components/entity-list.js b/src/components/entity-list.js index 671d00620c..72b6ccc43f 100644 --- a/src/components/entity-list.js +++ b/src/components/entity-list.js @@ -1,20 +1,19 @@ -import hass from '../util/home-assistant-js-instance'; - import Polymer from '../polymer'; -import nuclearObserver from '../util/bound-nuclear-behavior'; - -const { entityGetters } = hass; export default new Polymer({ is: 'entity-list', - behaviors: [nuclearObserver], + behaviors: [window.hassBehavior], properties: { + hass: { + type: Object, + }, + entities: { type: Array, - bindNuclear: [ - entityGetters.entityMap, + bindNuclear: hass => [ + hass.entityGetters.entityMap, (map) => map.valueSeq().sortBy((entity) => entity.entityId).toArray(), ], }, diff --git a/src/components/entity/ha-entity-marker.html b/src/components/entity/ha-entity-marker.html index e9aa079e5c..ab36c656ee 100644 --- a/src/components/entity/ha-entity-marker.html +++ b/src/components/entity/ha-entity-marker.html @@ -31,7 +31,7 @@ diff --git a/src/components/entity/ha-entity-marker.js b/src/components/entity/ha-entity-marker.js index 49b9045bb8..b92c4e2161 100644 --- a/src/components/entity/ha-entity-marker.js +++ b/src/components/entity/ha-entity-marker.js @@ -1,21 +1,26 @@ import Polymer from '../../polymer'; -import hass from '../../util/home-assistant-js-instance'; require('../../components/ha-label-badge'); -const { - reactor, - entityGetters, - moreInfoActions, -} = hass; +/* +Leaflet clones this element before adding it to the map. This messes up +our Poylmer object and we lose the reference to the `hass` object. + +That's why we refer here to window.hass instead of the hass property. +*/ export default new Polymer({ is: 'ha-entity-marker', properties: { + hass: { + type: Object, + }, + entityId: { type: String, value: '', + reflectToAttribute: true, }, state: { @@ -46,12 +51,12 @@ export default new Polymer({ badgeTap(ev) { ev.stopPropagation(); if (this.entityId) { - this.async(() => moreInfoActions.selectEntity(this.entityId), 1); + this.async(() => window.hass.moreInfoActions.selectEntity(this.entityId), 1); } }, computeState(entityId) { - return entityId && reactor.evaluate(entityGetters.byId(entityId)); + return entityId && window.hass.reactor.evaluate(window.hass.entityGetters.byId(entityId)); }, computeIcon(state) { diff --git a/src/components/entity/ha-entity-toggle.js b/src/components/entity/ha-entity-toggle.js index 2ced510434..c321a41084 100644 --- a/src/components/entity/ha-entity-toggle.js +++ b/src/components/entity/ha-entity-toggle.js @@ -1,14 +1,15 @@ import Polymer from '../../polymer'; -import hass from '../../util/home-assistant-js-instance'; import OFF_STATES from '../../util/off-states'; -const { serviceActions } = hass; - export default new Polymer({ is: 'ha-entity-toggle', properties: { + hass: { + type: Object, + }, + stateObj: { type: Object, }, @@ -89,7 +90,7 @@ export default new Polymer({ service = turnOn ? 'turn_on' : 'turn_off'; } - const call = serviceActions.callService( + const call = this.hass.serviceActions.callService( domain, service, { entity_id: this.stateObj.entityId }); if (!this.stateObj.attributes.assumed_state) { diff --git a/src/components/entity/ha-state-label-badge.js b/src/components/entity/ha-state-label-badge.js index 5c7f4eedbd..dcef86685f 100644 --- a/src/components/entity/ha-state-label-badge.js +++ b/src/components/entity/ha-state-label-badge.js @@ -1,18 +1,17 @@ import Polymer from '../../polymer'; -import hass from '../../util/home-assistant-js-instance'; import domainIcon from '../../util/domain-icon'; import stateIcon from '../../util/state-icon'; require('../../components/ha-label-badge'); -const { - moreInfoActions, -} = hass; - export default new Polymer({ is: 'ha-state-label-badge', properties: { + hass: { + type: Object, + }, + state: { type: Object, observer: 'stateChanged', @@ -25,7 +24,7 @@ export default new Polymer({ badgeTap(ev) { ev.stopPropagation(); - this.async(() => moreInfoActions.selectEntity(this.state.entityId), 1); + this.async(() => this.hass.moreInfoActions.selectEntity(this.state.entityId), 1); }, computeClasses(state) { diff --git a/src/components/events-list.js b/src/components/events-list.js index 3b0e933b70..0b4579ce41 100644 --- a/src/components/events-list.js +++ b/src/components/events-list.js @@ -1,20 +1,19 @@ -import hass from '../util/home-assistant-js-instance'; - import Polymer from '../polymer'; -import nuclearObserver from '../util/bound-nuclear-behavior'; - -const { eventGetters } = hass; export default new Polymer({ is: 'events-list', - behaviors: [nuclearObserver], + behaviors: [window.hassBehavior], properties: { + hass: { + type: Object, + }, + events: { type: Array, - bindNuclear: [ - eventGetters.entityMap, + bindNuclear: hass => [ + hass.eventGetters.entityMap, (map) => map.valueSeq().sortBy((event) => event.event).toArray(), ], }, diff --git a/src/components/ha-cards.html b/src/components/ha-cards.html index 717161e063..6991a38ae9 100644 --- a/src/components/ha-cards.html +++ b/src/components/ha-cards.html @@ -58,7 +58,7 @@ - +