-
diff --git a/src/components/ha-cards.js b/src/components/ha-cards.js
index 917f8433fe..61f40c857b 100644
--- a/src/components/ha-cards.js
+++ b/src/components/ha-cards.js
@@ -1,12 +1,9 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
require('.//ha-demo-badge');
require('../cards/ha-badges-card');
require('../cards/ha-card-chooser');
-const { util } = hass;
-
// mapping domain to size of the card.
const DOMAINS_WITH_CARD = {
camera: 4,
@@ -38,6 +35,10 @@ export default new Polymer({
is: 'ha-cards',
properties: {
+ hass: {
+ type: Object,
+ },
+
showIntroduction: {
type: Boolean,
value: false,
@@ -70,6 +71,7 @@ export default new Polymer({
},
computeCards(columns, states, showIntroduction) {
+ const hass = this.hass;
const byDomain = states.groupBy(entity => entity.domain);
const hasGroup = {};
@@ -137,6 +139,7 @@ export default new Polymer({
if (other.length > 0) {
cards.columns[curIndex].push({
+ hass,
cardType: 'entities',
states: other,
groupEntity,
@@ -145,12 +148,15 @@ export default new Polymer({
owncard.forEach(entity => {
cards.columns[curIndex].push({
+ hass,
cardType: entity.domain,
stateObj: entity,
});
});
}
+ const expandGroup = this.hass.util.expandGroup;
+
byDomain.keySeq().sortBy(domain => getPriority(domain))
.forEach(domain => {
if (domain === 'a') {
@@ -167,7 +173,7 @@ export default new Polymer({
} else if (domain === 'group') {
byDomain.get(domain).sortBy(entitySortBy)
.forEach(groupState => {
- const entities = util.expandGroup(groupState, states);
+ const entities = expandGroup(groupState, states);
entities.forEach(entity => { hasGroup[entity.entityId] = true; });
addEntitiesCard(groupState.entityId, entities.toArray(), groupState);
}
diff --git a/src/components/ha-sidebar.html b/src/components/ha-sidebar.html
index f7b9ddffcb..281d521e75 100644
--- a/src/components/ha-sidebar.html
+++ b/src/components/ha-sidebar.html
@@ -140,7 +140,7 @@
Streaming updates
-
+
diff --git a/src/components/ha-sidebar.js b/src/components/ha-sidebar.js
index 793d4e9eda..5480baa13f 100644
--- a/src/components/ha-sidebar.js
+++ b/src/components/ha-sidebar.js
@@ -1,23 +1,17 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./stream-status');
-const {
- configGetters,
- navigationGetters,
- authActions,
- navigationActions,
-} = hass;
-
export default new Polymer({
is: 'ha-sidebar',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
menuShown: {
type: Boolean,
},
@@ -32,17 +26,17 @@ export default new Polymer({
selected: {
type: String,
- bindNuclear: navigationGetters.activePane,
+ bindNuclear: hass => hass.navigationGetters.activePane,
},
hasHistoryComponent: {
type: Boolean,
- bindNuclear: configGetters.isComponentLoaded('history'),
+ bindNuclear: hass => hass.configGetters.isComponentLoaded('history'),
},
hasLogbookComponent: {
type: Boolean,
- bindNuclear: configGetters.isComponentLoaded('logbook'),
+ bindNuclear: hass => hass.configGetters.isComponentLoaded('logbook'),
},
},
@@ -76,11 +70,11 @@ export default new Polymer({
this.handleLogOut();
return;
}
- navigationActions.navigate.apply(null, newChoice.split('/'));
+ this.hass.navigationActions.navigate.apply(null, newChoice.split('/'));
this.debounce('updateStyles', () => this.updateStyles(), 1);
},
handleLogOut() {
- authActions.logOut();
+ this.hass.authActions.logOut();
},
});
diff --git a/src/components/ha-view-tabs.js b/src/components/ha-view-tabs.js
index 25a5939be3..3b36af8632 100644
--- a/src/components/ha-view-tabs.js
+++ b/src/components/ha-view-tabs.js
@@ -1,37 +1,32 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
-
-const {
- configGetters,
- viewActions,
- viewGetters,
-} = hass;
export default new Polymer({
is: 'ha-view-tabs',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
locationName: {
type: String,
- bindNuclear: configGetters.locationName,
+ bindNuclear: hass => hass.configGetters.locationName,
},
currentView: {
type: String,
- bindNuclear: [
- viewGetters.currentView,
+ bindNuclear: hass => [
+ hass.viewGetters.currentView,
view => view || '',
],
},
views: {
type: Array,
- bindNuclear: [
- viewGetters.views,
+ bindNuclear: hass => [
+ hass.viewGetters.views,
views => views.valueSeq()
.sortBy(view => view.attributes.order)
.toArray(),
@@ -48,7 +43,7 @@ export default new Polymer({
const current = this.currentView || null;
this.expectChange = true;
if (view !== current) {
- this.async(() => viewActions.selectView(view), 0);
+ this.async(() => this.hass.viewActions.selectView(view), 0);
}
},
});
diff --git a/src/components/logbook-entry.js b/src/components/logbook-entry.js
index f681ffdbfe..c1bd5c21b6 100644
--- a/src/components/logbook-entry.js
+++ b/src/components/logbook-entry.js
@@ -1,18 +1,20 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
require('./domain-icon');
require('./display-time');
require('./relative-ha-datetime');
-const { moreInfoActions } = hass;
-
export default new Polymer({
is: 'logbook-entry',
+ properties: {
+ hass: {
+ type: Object,
+ },
+ },
+
entityClicked(ev) {
ev.preventDefault();
- moreInfoActions.selectEntity(this.entryObj.entityId);
+ this.hass.moreInfoActions.selectEntity(this.entryObj.entityId);
},
});
diff --git a/src/components/relative-ha-datetime.js b/src/components/relative-ha-datetime.js
index 7799513e3c..ff40b96a70 100644
--- a/src/components/relative-ha-datetime.js
+++ b/src/components/relative-ha-datetime.js
@@ -1,11 +1,7 @@
-import moment from 'moment';
-import hass from '../util/home-assistant-js-instance';
import Polymer from '../polymer';
const UPDATE_INTERVAL = 60000; // 60 seconds
-const { util: { parseDateTime } } = hass;
-
export default new Polymer({
is: 'relative-ha-datetime',
@@ -43,7 +39,7 @@ export default new Polymer({
},
datetimeChanged(newVal) {
- this.parsedDateTime = newVal ? parseDateTime(newVal) : null;
+ this.parsedDateTime = newVal ? new Date(newVal) : null;
this.updateRelative();
},
@@ -56,6 +52,6 @@ export default new Polymer({
updateRelative() {
this.relativeTime = this.parsedDateTime ?
- moment(this.parsedDateTime).fromNow() : '';
+ window.moment(this.parsedDateTime).fromNow() : '';
},
});
diff --git a/src/components/services-list.js b/src/components/services-list.js
index 171b15afd1..2b6c303722 100644
--- a/src/components/services-list.js
+++ b/src/components/services-list.js
@@ -1,21 +1,20 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./domain-icon');
-const { serviceGetters } = hass;
-
export default new Polymer({
is: 'services-list',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
serviceDomains: {
type: Array,
- bindNuclear: serviceGetters.entityMap,
+ bindNuclear: hass => hass.serviceGetters.entityMap,
},
},
diff --git a/src/components/state-history-chart-line.js b/src/components/state-history-chart-line.js
index b677d346ee..cadc6cdba2 100644
--- a/src/components/state-history-chart-line.js
+++ b/src/components/state-history-chart-line.js
@@ -1,7 +1,15 @@
-import range from 'lodash/range';
-
import Polymer from '../polymer';
+function range(start, end) {
+ const result = [];
+
+ for (let i = start; i < end; i++) {
+ result.push(i);
+ }
+
+ return result;
+}
+
function saveParseFloat(value) {
const parsed = parseFloat(value);
return !isNaN(parsed) && isFinite(parsed) ? parsed : null;
diff --git a/src/components/stream-status.js b/src/components/stream-status.js
index d8d76827e6..03ef56a8a6 100644
--- a/src/components/stream-status.js
+++ b/src/components/stream-status.js
@@ -1,32 +1,31 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
-
-const { streamGetters, streamActions } = hass;
export default new Polymer({
is: 'stream-status',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
isStreaming: {
type: Boolean,
- bindNuclear: streamGetters.isStreamingEvents,
+ bindNuclear: hass => hass.streamGetters.isStreamingEvents,
},
hasError: {
type: Boolean,
- bindNuclear: streamGetters.hasStreamingEventsError,
+ bindNuclear: hass => hass.streamGetters.hasStreamingEventsError,
},
},
toggleChanged() {
if (this.isStreaming) {
- streamActions.stop();
+ this.hass.streamActions.stop();
} else {
- streamActions.start();
+ this.hass.streamActions.start();
}
},
});
diff --git a/src/dialogs/ha-voice-command-dialog.js b/src/dialogs/ha-voice-command-dialog.js
index 10c15d9bdc..5b6fa73ba0 100644
--- a/src/dialogs/ha-voice-command-dialog.js
+++ b/src/dialogs/ha-voice-command-dialog.js
@@ -1,19 +1,15 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
-
-const {
- voiceActions,
- voiceGetters,
-} = hass;
export default new Polymer({
is: 'ha-voice-command-dialog',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
dialogOpen: {
type: Boolean,
value: false,
@@ -22,22 +18,22 @@ export default new Polymer({
finalTranscript: {
type: String,
- bindNuclear: voiceGetters.finalTranscript,
+ bindNuclear: hass => hass.voiceGetters.finalTranscript,
},
interimTranscript: {
type: String,
- bindNuclear: voiceGetters.extraInterimTranscript,
+ bindNuclear: hass => hass.voiceGetters.extraInterimTranscript,
},
isTransmitting: {
type: Boolean,
- bindNuclear: voiceGetters.isTransmitting,
+ bindNuclear: hass => hass.voiceGetters.isTransmitting,
},
isListening: {
type: Boolean,
- bindNuclear: voiceGetters.isListening,
+ bindNuclear: hass => hass.voiceGetters.isListening,
},
showListenInterface: {
@@ -53,7 +49,7 @@ export default new Polymer({
dialogOpenChanged(newVal) {
if (!newVal && this.isListening) {
- voiceActions.stop();
+ this.hass.voiceActions.stop();
}
},
diff --git a/src/dialogs/more-info-dialog.html b/src/dialogs/more-info-dialog.html
index a327275eef..08aa8c4de9 100644
--- a/src/dialogs/more-info-dialog.html
+++ b/src/dialogs/more-info-dialog.html
@@ -37,13 +37,18 @@
-
+
+
+
-
-
-
-
+
+
+
+
diff --git a/src/dialogs/more-info-dialog.js b/src/dialogs/more-info-dialog.js
index fff975f387..9a7917752d 100644
--- a/src/dialogs/more-info-dialog.js
+++ b/src/dialogs/more-info-dialog.js
@@ -1,38 +1,27 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('../state-summary/state-card-content');
require('../components/state-history-charts');
require('../more-infos/more-info-content');
-const {
- configGetters,
- entityHistoryGetters,
- entityHistoryActions,
- moreInfoGetters,
- moreInfoActions,
-} = hass;
-
const DOMAINS_WITH_NO_HISTORY = ['camera', 'configurator', 'scene'];
export default new Polymer({
is: 'more-info-dialog',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
stateObj: {
type: Object,
- bindNuclear: moreInfoGetters.currentEntity,
+ bindNuclear: hass => hass.moreInfoGetters.currentEntity,
observer: 'stateObjChanged',
},
stateHistory: {
type: Object,
- bindNuclear: [
- moreInfoGetters.currentEntityHistory,
+ bindNuclear: hass => [
+ hass.moreInfoGetters.currentEntityHistory,
(history) => (history ? [history] : false),
],
},
@@ -44,18 +33,18 @@ export default new Polymer({
isLoadingEntityHistoryData: {
type: Boolean,
- bindNuclear: entityHistoryGetters.isLoadingEntityHistory,
+ bindNuclear: hass => hass.entityHistoryGetters.isLoadingEntityHistory,
},
hasHistoryComponent: {
type: Boolean,
- bindNuclear: configGetters.isComponentLoaded('history'),
+ bindNuclear: hass => hass.configGetters.isComponentLoaded('history'),
observer: 'fetchHistoryData',
},
shouldFetchHistory: {
type: Boolean,
- bindNuclear: moreInfoGetters.isCurrentEntityHistoryStale,
+ bindNuclear: hass => hass.moreInfoGetters.isCurrentEntityHistoryStale,
observer: 'fetchHistoryData',
},
@@ -95,7 +84,7 @@ export default new Polymer({
fetchHistoryData() {
if (this.stateObj && this.hasHistoryComponent &&
this.shouldFetchHistory) {
- entityHistoryActions.fetchRecent(this.stateObj.entityId);
+ this.hass.entityHistoryActions.fetchRecent(this.stateObj.entityId);
}
},
@@ -118,7 +107,7 @@ export default new Polymer({
if (newVal) {
this.async(() => { this.delayedDialogOpen = true; }, 10);
} else if (!newVal && this.stateObj) {
- this.async(() => moreInfoActions.deselectEntity(), 10);
+ this.async(() => this.hass.moreInfoActions.deselectEntity(), 10);
this.delayedDialogOpen = false;
}
},
diff --git a/src/home-assistant.html b/src/home-assistant.html
index 77d6cf631d..423aaa5941 100644
--- a/src/home-assistant.html
+++ b/src/home-assistant.html
@@ -22,12 +22,14 @@
-
+
-
+
diff --git a/src/home-assistant.js b/src/home-assistant.js
index 47a8ea0baa..89804c1251 100644
--- a/src/home-assistant.js
+++ b/src/home-assistant.js
@@ -1,20 +1,18 @@
+import moment from 'moment';
import Polymer from './polymer';
-import hass from './util/home-assistant-js-instance';
-
-import nuclearObserver from './util/bound-nuclear-behavior';
+import HomeAssistant from 'home-assistant-js';
import validateAuth from './util/validate-auth';
+import hassBehavior from './util/hass-behavior';
+
+window.hassBehavior = hassBehavior;
+window.moment = moment;
require('./layouts/login-form');
require('./layouts/home-assistant-main');
-const {
- localStoragePreferences,
- navigationActions,
- reactor,
- startLocalStoragePreferencesSync,
- syncGetters,
-} = hass;
+// While we figure out how ha-entity-marker can keep it's references
+window.hass = new HomeAssistant();
export default new Polymer({
is: 'home-assistant',
@@ -24,9 +22,13 @@ export default new Polymer({
icons: null,
},
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ value: window.hass,
+ },
auth: {
type: String,
},
@@ -35,7 +37,7 @@ export default new Polymer({
},
dataLoaded: {
type: Boolean,
- bindNuclear: syncGetters.isDataLoaded,
+ bindNuclear: hass => hass.syncGetters.isDataLoaded,
},
iconsLoaded: {
type: Boolean,
@@ -65,26 +67,6 @@ export default new Polymer({
},
created() {
- this.registerServiceWorker();
- },
-
- ready() {
- reactor.batch(() => {
- // if auth was given, tell the backend
- if (this.auth) {
- validateAuth(this.auth, false);
- } else if (localStoragePreferences.authToken) {
- validateAuth(localStoragePreferences.authToken, true);
- }
- navigationActions.showSidebar(localStoragePreferences.showSidebar);
- });
-
- startLocalStoragePreferencesSync();
-
- this.loadIcons();
- },
-
- registerServiceWorker() {
if (!('serviceWorker' in navigator)) {
return;
}
@@ -97,4 +79,21 @@ export default new Polymer({
}
});
},
+
+ ready() {
+ const hass = this.hass;
+ hass.reactor.batch(() => {
+ // if auth was given, tell the backend
+ if (this.auth) {
+ validateAuth(this.hass, this.auth, false);
+ } else if (hass.localStoragePreferences.authToken) {
+ validateAuth(this.hass, hass.localStoragePreferences.authToken, true);
+ }
+ hass.navigationActions.showSidebar(hass.localStoragePreferences.showSidebar);
+ });
+
+ hass.startLocalStoragePreferencesSync();
+
+ this.loadIcons();
+ },
});
diff --git a/src/layouts/home-assistant-main.html b/src/layouts/home-assistant-main.html
index e8e0a4dc1e..905fbecc11 100644
--- a/src/layouts/home-assistant-main.html
+++ b/src/layouts/home-assistant-main.html
@@ -18,9 +18,9 @@
-
-
-
+
+
+
@@ -28,34 +28,34 @@
force-narrow='[[computeForceNarrow(narrow, showSidebar)]]'
responsive-width='0' disable-swipe='[[isSelectedMap]]'
disable-edge-swipe='[[isSelectedMap]]'>
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/src/layouts/home-assistant-main.js b/src/layouts/home-assistant-main.js
index 1e5f32c794..8d9a87057c 100644
--- a/src/layouts/home-assistant-main.js
+++ b/src/layouts/home-assistant-main.js
@@ -1,7 +1,5 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
-import nuclearObserver from '../util/bound-nuclear-behavior';
import removeInitMsg from '../util/remove-init-message';
require('../components/ha-sidebar');
@@ -18,19 +16,23 @@ require('../managers/notification-manager');
require('../dialogs/more-info-dialog');
require('../dialogs/ha-voice-command-dialog');
-const {
- navigationActions,
- navigationGetters,
- startUrlSync,
- stopUrlSync,
-} = hass;
+// const {
+// navigationActions,
+// navigationGetters,
+// startUrlSync,
+// stopUrlSync,
+// } = hass;
export default new Polymer({
is: 'home-assistant-main',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -38,58 +40,58 @@ export default new Polymer({
activePane: {
type: String,
- bindNuclear: navigationGetters.activePane,
+ bindNuclear: hass => hass.navigationGetters.activePane,
observer: 'activePaneChanged',
},
isSelectedStates: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('states'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('states'),
},
isSelectedHistory: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('history'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('history'),
},
isSelectedMap: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('map'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('map'),
},
isSelectedLogbook: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('logbook'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('logbook'),
},
isSelectedDevEvent: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('devEvent'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('devEvent'),
},
isSelectedDevState: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('devState'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('devState'),
},
isSelectedDevTemplate: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('devTemplate'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('devTemplate'),
},
isSelectedDevService: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('devService'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('devService'),
},
isSelectedDevInfo: {
type: Boolean,
- bindNuclear: navigationGetters.isActivePane('devInfo'),
+ bindNuclear: hass => hass.navigationGetters.isActivePane('devInfo'),
},
showSidebar: {
type: Boolean,
- bindNuclear: navigationGetters.showSidebar,
+ bindNuclear: hass => hass.navigationGetters.showSidebar,
},
},
@@ -102,14 +104,14 @@ export default new Polymer({
if (this.narrow) {
this.$.drawer.openDrawer();
} else {
- navigationActions.showSidebar(true);
+ this.hass.navigationActions.showSidebar(true);
}
},
closeMenu() {
this.$.drawer.closeDrawer();
if (this.showSidebar) {
- navigationActions.showSidebar(false);
+ this.hass.navigationActions.showSidebar(false);
}
},
@@ -121,7 +123,7 @@ export default new Polymer({
attached() {
removeInitMsg();
- startUrlSync();
+ this.hass.startUrlSync();
},
computeForceNarrow(narrow, showSidebar) {
@@ -129,6 +131,6 @@ export default new Polymer({
},
detached() {
- stopUrlSync();
+ this.hass.stopUrlSync();
},
});
diff --git a/src/layouts/login-form.js b/src/layouts/login-form.js
index 25031c562e..f81d053588 100644
--- a/src/layouts/login-form.js
+++ b/src/layouts/login-form.js
@@ -1,33 +1,32 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
-
-import nuclearObserver from '../util/bound-nuclear-behavior';
import validateAuth from '../util/validate-auth';
import removeInitMsg from '../util/remove-init-message';
-const { authGetters } = hass;
-
export default new Polymer({
is: 'login-form',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
errorMessage: {
type: String,
- bindNuclear: authGetters.attemptErrorMessage,
+ bindNuclear: hass => hass.authGetters.attemptErrorMessage,
},
isInvalid: {
type: Boolean,
- bindNuclear: authGetters.isInvalidAttempt,
+ bindNuclear: hass => hass.authGetters.isInvalidAttempt,
},
isValidating: {
type: Boolean,
observer: 'isValidatingChanged',
- bindNuclear: authGetters.isValidating,
+ bindNuclear: hass => hass.authGetters.isValidating,
},
loadingResources: {
@@ -89,6 +88,6 @@ export default new Polymer({
validatePassword() {
this.$.hideKeyboardOnFocus.focus();
- validateAuth(this.$.passwordInput.value, this.$.rememberLogin.checked);
+ validateAuth(this.hass, this.$.passwordInput.value, this.$.rememberLogin.checked);
},
});
diff --git a/src/layouts/partial-cards.html b/src/layouts/partial-cards.html
index 8e951fc013..de1424c82e 100644
--- a/src/layouts/partial-cards.html
+++ b/src/layouts/partial-cards.html
@@ -65,14 +65,14 @@
-
+
+ states='[[states]]' columns='[[columns]]' hass='[[hass]]'>
diff --git a/src/layouts/partial-cards.js b/src/layouts/partial-cards.js
index 11b025dd33..b587c6282f 100644
--- a/src/layouts/partial-cards.js
+++ b/src/layouts/partial-cards.js
@@ -1,28 +1,19 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base');
require('../components/ha-cards');
require('../components/ha-view-tabs');
-const {
- configGetters,
- viewGetters,
- voiceGetters,
- streamGetters,
- syncGetters,
- syncActions,
- voiceActions,
-} = hass;
-
export default new Polymer({
is: 'partial-cards',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -30,31 +21,31 @@ export default new Polymer({
isFetching: {
type: Boolean,
- bindNuclear: syncGetters.isFetching,
+ bindNuclear: hass => hass.syncGetters.isFetching,
},
isStreaming: {
type: Boolean,
- bindNuclear: streamGetters.isStreamingEvents,
+ bindNuclear: hass => hass.streamGetters.isStreamingEvents,
},
canListen: {
type: Boolean,
- bindNuclear: [
- voiceGetters.isVoiceSupported,
- configGetters.isComponentLoaded('conversation'),
+ bindNuclear: hass => [
+ hass.voiceGetters.isVoiceSupported,
+ hass.configGetters.isComponentLoaded('conversation'),
(isVoiceSupported, componentLoaded) => isVoiceSupported && componentLoaded,
],
},
introductionLoaded: {
type: Boolean,
- bindNuclear: configGetters.isComponentLoaded('introduction'),
+ bindNuclear: hass => hass.configGetters.isComponentLoaded('introduction'),
},
locationName: {
type: String,
- bindNuclear: configGetters.locationName,
+ bindNuclear: hass => hass.configGetters.locationName,
},
showMenu: {
@@ -65,23 +56,23 @@ export default new Polymer({
currentView: {
type: String,
- bindNuclear: [
- viewGetters.currentView,
+ bindNuclear: hass => [
+ hass.viewGetters.currentView,
view => view || '',
],
},
hasViews: {
type: Boolean,
- bindNuclear: [
- viewGetters.views,
+ bindNuclear: hass => [
+ hass.viewGetters.views,
views => views.size > 0,
],
},
states: {
type: Object,
- bindNuclear: viewGetters.currentViewEntities,
+ bindNuclear: hass => hass.viewGetters.currentViewEntities,
},
columns: {
@@ -136,11 +127,11 @@ export default new Polymer({
},
handleRefresh() {
- syncActions.fetchAll();
+ this.hass.syncActions.fetchAll();
},
handleListenClick() {
- voiceActions.listen();
+ this.hass.voiceActions.listen();
},
headerScrollAdjust(ev) {
diff --git a/src/layouts/partial-dev-call-service.js b/src/layouts/partial-dev-call-service.js
index 0c0c3c2cdc..b376391d92 100644
--- a/src/layouts/partial-dev-call-service.js
+++ b/src/layouts/partial-dev-call-service.js
@@ -1,20 +1,16 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
require('./partial-base');
require('../components/services-list');
-const {
- reactor,
- serviceActions,
- serviceGetters,
-} = hass;
-
export default new Polymer({
is: 'partial-dev-call-service',
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -42,13 +38,13 @@ export default new Polymer({
description: {
type: String,
- computed: 'computeDescription(domain, service)',
+ computed: 'computeDescription(hass, domain, service)',
},
},
- computeDescription(domain, service) {
- return reactor.evaluate([
- serviceGetters.entityMap,
+ computeDescription(hass, domain, service) {
+ return hass.reactor.evaluate([
+ hass.serviceGetters.entityMap,
map => (map.has(domain) && map.get(domain).get('services').has(service) ?
JSON.stringify(map.get(domain).get('services').get(service).toJS(), null, 2) :
'No description available'),
@@ -71,7 +67,7 @@ export default new Polymer({
return;
}
- serviceActions.callService(this.domain, this.service, serviceData);
+ this.hass.serviceActions.callService(this.domain, this.service, serviceData);
},
computeFormClasses(narrow) {
diff --git a/src/layouts/partial-dev-fire-event.js b/src/layouts/partial-dev-fire-event.js
index d9898088fd..c089ef6ce6 100644
--- a/src/layouts/partial-dev-fire-event.js
+++ b/src/layouts/partial-dev-fire-event.js
@@ -1,16 +1,16 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
require('./partial-base');
require('../components/events-list');
-const { eventActions } = hass;
-
export default new Polymer({
is: 'partial-dev-fire-event',
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -48,7 +48,7 @@ export default new Polymer({
return;
}
- eventActions.fireEvent(this.eventType, eventData);
+ this.hass.eventActions.fireEvent(this.eventType, eventData);
},
computeFormClasses(narrow) {
diff --git a/src/layouts/partial-dev-info.js b/src/layouts/partial-dev-info.js
index de9489b445..68f873da69 100644
--- a/src/layouts/partial-dev-info.js
+++ b/src/layouts/partial-dev-info.js
@@ -1,21 +1,17 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base');
-const {
- configGetters,
- errorLogActions,
-} = hass;
-
export default new Polymer({
is: 'partial-dev-info',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -28,7 +24,7 @@ export default new Polymer({
hassVersion: {
type: String,
- bindNuclear: configGetters.serverVersion,
+ bindNuclear: hass => hass.configGetters.serverVersion,
},
polymerVersion: {
@@ -56,7 +52,7 @@ export default new Polymer({
this.errorLog = 'Loading error log…';
- errorLogActions.fetchErrorLog().then(
+ this.hass.errorLogActions.fetchErrorLog().then(
log => { this.errorLog = log || 'No errors have been reported.'; });
},
});
diff --git a/src/layouts/partial-dev-set-state.js b/src/layouts/partial-dev-set-state.js
index 8c65331c39..bf14f514c2 100644
--- a/src/layouts/partial-dev-set-state.js
+++ b/src/layouts/partial-dev-set-state.js
@@ -1,16 +1,16 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
require('./partial-base');
require('../components/entity-list');
-const { reactor, entityGetters, entityActions } = hass;
-
export default new Polymer({
is: 'partial-dev-set-state',
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -47,7 +47,7 @@ export default new Polymer({
},
entitySelected(ev) {
- const state = reactor.evaluate(entityGetters.byId(ev.detail.entityId));
+ const state = this.hass.reactor.evaluate(this.hass.entityGetters.byId(ev.detail.entityId));
this.entityId = state.entityId;
this.state = state.state;
@@ -65,7 +65,7 @@ export default new Polymer({
return;
}
- entityActions.save({
+ this.hass.entityActions.save({
entityId: this.entityId,
state: this.state,
attributes: attr,
diff --git a/src/layouts/partial-dev-template.js b/src/layouts/partial-dev-template.js
index 6010a835e6..5a0e905a54 100644
--- a/src/layouts/partial-dev-template.js
+++ b/src/layouts/partial-dev-template.js
@@ -1,20 +1,17 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base');
-const {
- templateActions,
-} = hass;
-
export default new Polymer({
is: 'partial-dev-template',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -84,7 +81,7 @@ export default new Polymer({
renderTemplate() {
this.rendering = true;
- templateActions.render(this.template).then(processed => {
+ this.hass.templateActions.render(this.template).then(processed => {
this.processed = processed;
this.rendering = false;
}, error => {
diff --git a/src/layouts/partial-history.js b/src/layouts/partial-history.js
index dafd21b86d..e4bd0b1e15 100644
--- a/src/layouts/partial-history.js
+++ b/src/layouts/partial-history.js
@@ -1,22 +1,18 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base');
require('../components/state-history-charts');
-const {
- entityHistoryGetters,
- entityHistoryActions,
-} = hass;
-
export default new Polymer({
is: 'partial-history',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
},
@@ -28,35 +24,35 @@ export default new Polymer({
isDataLoaded: {
type: Boolean,
- bindNuclear: entityHistoryGetters.hasDataForCurrentDate,
+ bindNuclear: hass => hass.entityHistoryGetters.hasDataForCurrentDate,
observer: 'isDataLoadedChanged',
},
stateHistory: {
type: Object,
- bindNuclear: entityHistoryGetters.entityHistoryForCurrentDate,
+ bindNuclear: hass => hass.entityHistoryGetters.entityHistoryForCurrentDate,
},
isLoadingData: {
type: Boolean,
- bindNuclear: entityHistoryGetters.isLoadingEntityHistory,
+ bindNuclear: hass => hass.entityHistoryGetters.isLoadingEntityHistory,
},
selectedDate: {
type: String,
value: null,
- bindNuclear: entityHistoryGetters.currentDate,
+ bindNuclear: hass => hass.entityHistoryGetters.currentDate,
},
},
isDataLoadedChanged(newVal) {
if (!newVal) {
- this.async(() => entityHistoryActions.fetchSelectedDate(), 1);
+ this.async(() => this.hass.entityHistoryActions.fetchSelectedDate(), 1);
}
},
handleRefreshClick() {
- entityHistoryActions.fetchSelectedDate();
+ this.hass.entityHistoryActions.fetchSelectedDate();
},
datepickerFocus() {
@@ -66,7 +62,7 @@ export default new Polymer({
attached() {
this.datePicker = new window.Pikaday({
field: this.$.datePicker.inputElement,
- onSelect: entityHistoryActions.changeCurrentDate,
+ onSelect: this.hass.entityHistoryActions.changeCurrentDate,
});
},
diff --git a/src/layouts/partial-logbook.js b/src/layouts/partial-logbook.js
index 27b0e340a2..1b500668fc 100644
--- a/src/layouts/partial-logbook.js
+++ b/src/layouts/partial-logbook.js
@@ -1,20 +1,19 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('./partial-base');
require('../components/ha-logbook');
require('../components/loading-box');
-const { logbookGetters, logbookActions } = hass;
-
export default new Polymer({
is: 'partial-logbook',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
narrow: {
type: Boolean,
value: false,
@@ -27,24 +26,24 @@ export default new Polymer({
selectedDate: {
type: String,
- bindNuclear: logbookGetters.currentDate,
+ bindNuclear: hass => hass.logbookGetters.currentDate,
},
isLoading: {
type: Boolean,
- bindNuclear: logbookGetters.isLoadingEntries,
+ bindNuclear: hass => hass.logbookGetters.isLoadingEntries,
},
isStale: {
type: Boolean,
- bindNuclear: logbookGetters.isCurrentStale,
+ bindNuclear: hass => hass.logbookGetters.isCurrentStale,
observer: 'isStaleChanged',
},
entries: {
type: Array,
- bindNuclear: [
- logbookGetters.currentEntries,
+ bindNuclear: hass => [
+ hass.logbookGetters.currentEntries,
(entries) => entries.reverse().toArray(),
],
},
@@ -56,12 +55,12 @@ export default new Polymer({
isStaleChanged(newVal) {
if (newVal) {
- this.async(() => logbookActions.fetchDate(this.selectedDate), 1);
+ this.async(() => this.hass.logbookActions.fetchDate(this.selectedDate), 1);
}
},
handleRefresh() {
- logbookActions.fetchDate(this.selectedDate);
+ this.hass.logbookActions.fetchDate(this.selectedDate);
},
datepickerFocus() {
@@ -71,7 +70,7 @@ export default new Polymer({
attached() {
this.datePicker = new window.Pikaday({
field: this.$.datePicker.inputElement,
- onSelect: logbookActions.changeCurrentDate,
+ onSelect: this.hass.logbookActions.changeCurrentDate,
});
},
diff --git a/src/layouts/partial-map.html b/src/layouts/partial-map.html
index f27f7733c1..93e85ce1ef 100644
--- a/src/layouts/partial-map.html
+++ b/src/layouts/partial-map.html
@@ -62,7 +62,8 @@
-
+
hass.configGetters.locationGPS,
},
locationName: {
type: String,
- bindNuclear: configGetters.locationName,
+ bindNuclear: hass => hass.configGetters.locationName,
},
locationEntities: {
type: Array,
- bindNuclear: [
- entityGetters.visibleEntityMap,
+ bindNuclear: hass => [
+ hass.entityGetters.visibleEntityMap,
entities => entities.valueSeq().filter(
entity => entity.attributes.latitude && entity.state !== 'home'
).toArray(),
@@ -40,8 +36,8 @@ export default new Polymer({
zoneEntities: {
type: Array,
- bindNuclear: [
- entityGetters.entityMap,
+ bindNuclear: hass => [
+ hass.entityGetters.entityMap,
entities => entities.valueSeq()
.filter(entity => entity.domain === 'zone' &&
!entity.attributes.passive)
diff --git a/src/managers/notification-manager.js b/src/managers/notification-manager.js
index 4ed54dfd16..eeaa0cb266 100644
--- a/src/managers/notification-manager.js
+++ b/src/managers/notification-manager.js
@@ -1,16 +1,15 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
-
-const { notificationGetters } = hass;
export default new Polymer({
is: 'notification-manager',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
// Otherwise we cannot close a modal when a notification is being shown.
neg: {
type: Boolean,
@@ -19,7 +18,7 @@ export default new Polymer({
text: {
type: String,
- bindNuclear: notificationGetters.lastNotificationMessage,
+ bindNuclear: hass => hass.notificationGetters.lastNotificationMessage,
observer: 'showNotification',
},
},
diff --git a/src/more-infos/more-info-alarm_control_panel.js b/src/more-infos/more-info-alarm_control_panel.js
index 668f5f4cee..47954f758a 100644
--- a/src/more-infos/more-info-alarm_control_panel.js
+++ b/src/more-infos/more-info-alarm_control_panel.js
@@ -1,9 +1,5 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'more-info-alarm_control_panel',
handleDisarmTap() {
@@ -16,6 +12,10 @@ export default new Polymer({
this.callService('alarm_arm_away', { code: this.enteredCode });
},
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -83,6 +83,6 @@ export default new Polymer({
callService(service, data) {
const serviceData = data || {};
serviceData.entity_id = this.stateObj.entityId;
- serviceActions.callService('alarm_control_panel', service, serviceData);
+ this.hass.serviceActions.callService('alarm_control_panel', service, serviceData);
},
});
diff --git a/src/more-infos/more-info-configurator.js b/src/more-infos/more-info-configurator.js
index 3ae61594b1..224fd915ae 100644
--- a/src/more-infos/more-info-configurator.js
+++ b/src/more-infos/more-info-configurator.js
@@ -1,20 +1,11 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
require('../components/loading-box');
-const {
- streamGetters,
- syncActions,
- serviceActions,
-} = hass;
-
export default new Polymer({
is: 'more-info-configurator',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
stateObj: {
@@ -28,7 +19,7 @@ export default new Polymer({
isStreaming: {
type: Boolean,
- bindNuclear: streamGetters.isStreamingEvents,
+ bindNuclear: hass => hass.streamGetters.isStreamingEvents,
},
isConfigurable: {
@@ -72,12 +63,12 @@ export default new Polymer({
fields: this.fieldInput,
};
- serviceActions.callService('configurator', 'configure', data).then(
+ this.hass.serviceActions.callService('configurator', 'configure', data).then(
() => {
this.isConfiguring = false;
if (!this.isStreaming) {
- syncActions.fetchAll();
+ this.hass.syncActions.fetchAll();
}
},
() => {
diff --git a/src/more-infos/more-info-content.js b/src/more-infos/more-info-content.js
index db561f738b..3c4436d0ab 100644
--- a/src/more-infos/more-info-content.js
+++ b/src/more-infos/more-info-content.js
@@ -21,6 +21,10 @@ export default new Polymer({
is: 'more-info-content',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -31,6 +35,7 @@ export default new Polymer({
if (!stateObj) return;
dynamicContentUpdater(
- this, `MORE-INFO-${stateMoreInfoType(stateObj).toUpperCase()}`, { stateObj });
+ this, `MORE-INFO-${stateMoreInfoType(stateObj).toUpperCase()}`,
+ { hass: this.hass, stateObj });
},
});
diff --git a/src/more-infos/more-info-group.html b/src/more-infos/more-info-group.html
index a31320b68f..202dd5908c 100644
--- a/src/more-infos/more-info-group.html
+++ b/src/more-infos/more-info-group.html
@@ -17,7 +17,7 @@
-
+
diff --git a/src/more-infos/more-info-group.js b/src/more-infos/more-info-group.js
index 1c4023871a..1cc37e0b7e 100644
--- a/src/more-infos/more-info-group.js
+++ b/src/more-infos/more-info-group.js
@@ -1,32 +1,28 @@
-import hass from '../util/home-assistant-js-instance';
import Polymer from '../polymer';
-import nuclearObserver from '../util/bound-nuclear-behavior';
import dynamicContentUpdater from '../util/dynamic-content-updater';
import stateMoreInfoType from '../util/state-more-info-type';
require('../state-summary/state-card-content');
-
-const {
- entityGetters,
- moreInfoGetters,
-} = hass;
-
export default new Polymer({
is: 'more-info-group',
- behaviors: [nuclearObserver],
+ behaviors: [window.hassBehavior],
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
},
states: {
type: Array,
- bindNuclear: [
- moreInfoGetters.currentEntity,
- entityGetters.entityMap,
+ bindNuclear: hass => [
+ hass.moreInfoGetters.currentEntity,
+ hass.entityGetters.entityMap,
(currentEntity, entities) => {
// weird bug??
if (!currentEntity) {
diff --git a/src/more-infos/more-info-hvac.js b/src/more-infos/more-info-hvac.js
index f52b0154fd..1418691e08 100644
--- a/src/more-infos/more-info-hvac.js
+++ b/src/more-infos/more-info-hvac.js
@@ -1,9 +1,6 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
import attributeClassNames from '../util/attribute-class-names';
-const { serviceActions } = hass;
const ATTRIBUTE_CLASSES = [
'away_mode',
'aux_heat',
@@ -18,6 +15,10 @@ export default new Polymer({
is: 'more-info-hvac',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -154,7 +155,7 @@ export default new Polymer({
/* eslint-disable no-param-reassign */
data.entity_id = this.stateObj.entityId;
/* eslint-enable no-param-reassign */
- serviceActions.callService('hvac', service, data)
+ this.hass.serviceActions.callService('hvac', service, data)
.then(() => this.stateObjChanged(this.stateObj));
},
});
diff --git a/src/more-infos/more-info-light.js b/src/more-infos/more-info-light.js
index 0801234a1e..1f12929e93 100644
--- a/src/more-infos/more-info-light.js
+++ b/src/more-infos/more-info-light.js
@@ -1,15 +1,12 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
import attributeClassNames from '../util/attribute-class-names';
require('../components/ha-color-picker');
-const { serviceActions } = hass;
const ATTRIBUTE_CLASSES = ['brightness', 'rgb_color', 'color_temp'];
-function pickColor(entityId, color) {
- serviceActions.callService('light', 'turn_on', {
+function pickColor(hass, entityId, color) {
+ hass.serviceActions.callService('light', 'turn_on', {
entity_id: entityId,
rgb_color: [color.r, color.g, color.b],
});
@@ -19,6 +16,10 @@ export default new Polymer({
is: 'more-info-light',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -54,9 +55,9 @@ export default new Polymer({
if (isNaN(bri)) return;
if (bri === 0) {
- serviceActions.callTurnOff(this.stateObj.entityId);
+ this.hass.serviceActions.callTurnOff(this.stateObj.entityId);
} else {
- serviceActions.callService('light', 'turn_on', {
+ this.hass.serviceActions.callService('light', 'turn_on', {
entity_id: this.stateObj.entityId,
brightness: bri,
});
@@ -68,7 +69,7 @@ export default new Polymer({
if (isNaN(ct)) return;
- serviceActions.callService('light', 'turn_on', {
+ this.hass.serviceActions.callService('light', 'turn_on', {
entity_id: this.stateObj.entityId,
color_temp: ct,
});
@@ -86,14 +87,14 @@ export default new Polymer({
this.color = ev.detail.rgb;
- pickColor(this.stateObj.entityId, this.color);
+ pickColor(this.hass, this.stateObj.entityId, this.color);
this.colorChanged = false;
this.skipColorPicked = true;
this.colorDebounce = setTimeout(() => {
if (this.colorChanged) {
- pickColor(this.stateObj.entityId, this.color);
+ pickColor(this.hass, this.stateObj.entityId, this.color);
}
this.skipColorPicked = false;
}, 500);
diff --git a/src/more-infos/more-info-lock.js b/src/more-infos/more-info-lock.js
index c47e6025c2..e85a27a9d1 100644
--- a/src/more-infos/more-info-lock.js
+++ b/src/more-infos/more-info-lock.js
@@ -1,12 +1,12 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'more-info-lock',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -35,6 +35,6 @@ export default new Polymer({
callService(service, data) {
const serviceData = data || {};
serviceData.entity_id = this.stateObj.entityId;
- serviceActions.callService('lock', service, serviceData);
+ this.hass.serviceActions.callService('lock', service, serviceData);
},
});
diff --git a/src/more-infos/more-info-media_player.js b/src/more-infos/more-info-media_player.js
index 8234bce024..dc51e74935 100644
--- a/src/more-infos/more-info-media_player.js
+++ b/src/more-infos/more-info-media_player.js
@@ -1,15 +1,16 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
import attributeClassNames from '../util/attribute-class-names';
-const { serviceActions } = hass;
const ATTRIBUTE_CLASSES = ['volume_level'];
export default new Polymer({
is: 'more-info-media_player',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -232,6 +233,6 @@ export default new Polymer({
callService(service, data) {
const serviceData = data || {};
serviceData.entity_id = this.stateObj.entityId;
- serviceActions.callService('media_player', service, serviceData);
+ this.hass.serviceActions.callService('media_player', service, serviceData);
},
});
diff --git a/src/more-infos/more-info-sun.js b/src/more-infos/more-info-sun.js
index 1fa165ae0c..8dbe209758 100644
--- a/src/more-infos/more-info-sun.js
+++ b/src/more-infos/more-info-sun.js
@@ -1,10 +1,7 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
import formatTime from '../util/format-time';
-const { util: { parseDateTime } } = hass;
-
export default new Polymer({
is: 'more-info-sun',
@@ -25,11 +22,11 @@ export default new Polymer({
},
computeRising(stateObj) {
- return parseDateTime(stateObj.attributes.next_rising);
+ return new Date(stateObj.attributes.next_rising);
},
computeSetting(stateObj) {
- return parseDateTime(stateObj.attributes.next_setting);
+ return new Date(stateObj.attributes.next_setting);
},
computeOrder(risingDate, settingDate) {
diff --git a/src/more-infos/more-info-thermostat.js b/src/more-infos/more-info-thermostat.js
index 8adf907333..d8628aa72f 100644
--- a/src/more-infos/more-info-thermostat.js
+++ b/src/more-infos/more-info-thermostat.js
@@ -1,15 +1,16 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
import attributeClassNames from '../util/attribute-class-names';
-const { serviceActions } = hass;
const ATTRIBUTE_CLASSES = ['away_mode'];
export default new Polymer({
is: 'more-info-thermostat',
properties: {
+ hass: {
+ type: Object,
+ },
+
stateObj: {
type: Object,
observer: 'stateObjChanged',
@@ -45,7 +46,7 @@ export default new Polymer({
},
targetTemperatureSliderChanged(ev) {
- serviceActions.callService('thermostat', 'set_temperature', {
+ this.hass.serviceActions.callService('thermostat', 'set_temperature', {
entity_id: this.stateObj.entityId,
temperature: ev.target.value,
});
@@ -66,7 +67,7 @@ export default new Polymer({
// with the state. It will be out of sync if our service call did not
// result in the entity to be turned on. Since the state is not changing,
// the resync is not called automatic.
- serviceActions.callService(
+ this.hass.serviceActions.callService(
'thermostat', 'set_away_mode',
{ away_mode: awayMode, entity_id: this.stateObj.entityId })
diff --git a/src/state-summary/state-card-content.js b/src/state-summary/state-card-content.js
index 56048ff2ac..6458ace430 100644
--- a/src/state-summary/state-card-content.js
+++ b/src/state-summary/state-card-content.js
@@ -20,6 +20,10 @@ export default new Polymer({
is: 'state-card-content',
properties: {
+ hass: {
+ type: Object,
+ },
+
inDialog: {
type: Boolean,
value: false,
@@ -31,13 +35,14 @@ export default new Polymer({
},
observers: [
- 'inputChanged(inDialog, stateObj)',
+ 'inputChanged(hass, inDialog, stateObj)',
],
- inputChanged(inDialog, stateObj) {
+ inputChanged(hass, inDialog, stateObj) {
if (!stateObj) return;
dynamicContentUpdater(
- this, `STATE-CARD-${stateCardType(stateObj).toUpperCase()}`, { stateObj, inDialog });
+ this, `STATE-CARD-${stateCardType(this.hass, stateObj).toUpperCase()}`,
+ { hass, stateObj, inDialog });
},
});
diff --git a/src/state-summary/state-card-input_select.js b/src/state-summary/state-card-input_select.js
index f53cb52c50..38538da11b 100644
--- a/src/state-summary/state-card-input_select.js
+++ b/src/state-summary/state-card-input_select.js
@@ -1,14 +1,15 @@
-import hass from '../util/home-assistant-js-instance';
import Polymer from '../polymer';
require('../components/state-info');
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'state-card-input_select',
properties: {
+ hass: {
+ type: Object,
+ },
+
inDialog: {
type: Boolean,
value: false,
@@ -33,7 +34,7 @@ export default new Polymer({
if (option === '' || option === this.stateObj.state) {
return;
}
- serviceActions.callService('input_select', 'select_option', {
+ this.hass.serviceActions.callService('input_select', 'select_option', {
option,
entity_id: this.stateObj.entityId,
});
diff --git a/src/state-summary/state-card-input_slider.js b/src/state-summary/state-card-input_slider.js
index b5cf8b15da..7c1419a06a 100644
--- a/src/state-summary/state-card-input_slider.js
+++ b/src/state-summary/state-card-input_slider.js
@@ -1,14 +1,15 @@
-import hass from '../util/home-assistant-js-instance';
import Polymer from '../polymer';
require('../components/state-info');
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'state-card-input_slider',
properties: {
+ hass: {
+ type: Object,
+ },
+
inDialog: {
type: Boolean,
value: false,
@@ -41,7 +42,7 @@ export default new Polymer({
if (this.value === Number(this.stateObj.state)) {
return;
}
- serviceActions.callService('input_slider', 'select_value', {
+ this.hass.serviceActions.callService('input_slider', 'select_value', {
value: this.value,
entity_id: this.stateObj.entityId,
});
diff --git a/src/state-summary/state-card-rollershutter.js b/src/state-summary/state-card-rollershutter.js
index fa2d5ecd89..a2aa0a81d1 100644
--- a/src/state-summary/state-card-rollershutter.js
+++ b/src/state-summary/state-card-rollershutter.js
@@ -1,15 +1,15 @@
-import hass from '../util/home-assistant-js-instance';
-
import Polymer from '../polymer';
require('../components/state-info');
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'state-card-rollershutter',
properties: {
+ hass: {
+ type: Object,
+ },
+
inDialog: {
type: Boolean,
value: false,
@@ -29,17 +29,17 @@ export default new Polymer({
},
onMoveUpTap() {
- serviceActions.callService('rollershutter', 'move_up',
- { entity_id: this.stateObj.entityId });
+ this.hass.serviceActions.callService('rollershutter', 'move_up',
+ { entity_id: this.stateObj.entityId });
},
onMoveDownTap() {
- serviceActions.callService('rollershutter', 'move_down',
- { entity_id: this.stateObj.entityId });
+ this.hass.serviceActions.callService('rollershutter', 'move_down',
+ { entity_id: this.stateObj.entityId });
},
onStopTap() {
- serviceActions.callService('rollershutter', 'stop',
- { entity_id: this.stateObj.entityId });
+ this.hass.serviceActions.callService('rollershutter', 'stop',
+ { entity_id: this.stateObj.entityId });
},
});
diff --git a/src/state-summary/state-card-scene.js b/src/state-summary/state-card-scene.js
index a8b4b9ef4c..f84e58075a 100644
--- a/src/state-summary/state-card-scene.js
+++ b/src/state-summary/state-card-scene.js
@@ -1,14 +1,15 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
require('../components/state-info.js');
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'state-card-scene',
properties: {
+ hass: {
+ type: Object,
+ },
+
inDialog: {
type: Boolean,
value: false,
@@ -21,6 +22,6 @@ export default new Polymer({
activateScene(ev) {
ev.stopPropagation();
- serviceActions.callTurnOn(this.stateObj.entityId);
+ this.hass.serviceActions.callTurnOn(this.stateObj.entityId);
},
});
diff --git a/src/state-summary/state-card-script.html b/src/state-summary/state-card-script.html
index 9f78394b89..1258123b61 100644
--- a/src/state-summary/state-card-script.html
+++ b/src/state-summary/state-card-script.html
@@ -19,7 +19,7 @@
-
+
ACTIVATE
diff --git a/src/state-summary/state-card-script.js b/src/state-summary/state-card-script.js
index 4512a8ab21..c95114b83c 100644
--- a/src/state-summary/state-card-script.js
+++ b/src/state-summary/state-card-script.js
@@ -1,11 +1,8 @@
import Polymer from '../polymer';
-import hass from '../util/home-assistant-js-instance';
require('../components/state-info');
require('../components/entity/ha-entity-toggle');
-const { serviceActions } = hass;
-
export default new Polymer({
is: 'state-card-script',
@@ -22,6 +19,6 @@ export default new Polymer({
fireScript(ev) {
ev.stopPropagation();
- serviceActions.callTurnOn(this.stateObj.entityId);
+ this.hass.serviceActions.callTurnOn(this.stateObj.entityId);
},
});
diff --git a/src/state-summary/state-card-toggle.html b/src/state-summary/state-card-toggle.html
index 364c8f79d8..775ad5608f 100755
--- a/src/state-summary/state-card-toggle.html
+++ b/src/state-summary/state-card-toggle.html
@@ -13,7 +13,7 @@
-
+
diff --git a/src/util/bound-nuclear-behavior.js b/src/util/bound-nuclear-behavior.js
deleted file mode 100644
index 18944ca667..0000000000
--- a/src/util/bound-nuclear-behavior.js
+++ /dev/null
@@ -1,5 +0,0 @@
-import hass from './home-assistant-js-instance';
-
-import nuclearObserver from './nuclear-behavior';
-
-export default nuclearObserver(hass.reactor);
diff --git a/src/util/can-toggle.js b/src/util/can-toggle.js
index 0346568b74..a74ca672d3 100644
--- a/src/util/can-toggle.js
+++ b/src/util/can-toggle.js
@@ -1,11 +1,4 @@
-import hass from './home-assistant-js-instance';
-
-const {
- reactor,
- serviceGetters,
-} = hass;
-
// Return boolean if entity can be toggled.
-export default function canToggle(entityId) {
- return reactor.evaluate(serviceGetters.canToggleEntity(entityId));
+export default function canToggle(hass, entityId) {
+ return hass.reactor.evaluate(hass.serviceGetters.canToggleEntity(entityId));
}
diff --git a/src/util/domain-icon.js b/src/util/domain-icon.js
index 2820c9c907..8c904f6666 100644
--- a/src/util/domain-icon.js
+++ b/src/util/domain-icon.js
@@ -91,9 +91,11 @@ export default function domainIcon(domain, state) {
return 'mdi:open-in-new';
default:
- /* eslint-disable no-console */
- console.warn(`Unable to find icon for domain ${domain} (${state})`);
- /* eslint-enable no-console */
+ if (__DEV__) {
+ /* eslint-disable no-console */
+ console.warn(`Unable to find icon for domain ${domain} (${state})`);
+ /* eslint-enable no-console */
+ }
return defaultIcon;
}
}
diff --git a/src/util/format-date-time.js b/src/util/format-date-time.js
index 67c759954e..21aa8ca20e 100644
--- a/src/util/format-date-time.js
+++ b/src/util/format-date-time.js
@@ -1,5 +1,3 @@
-import moment from 'moment';
-
export default function formatDateTime(dateObj) {
- return moment(dateObj).format('lll');
+ return window.moment(dateObj).format('lll');
}
diff --git a/src/util/format-date.js b/src/util/format-date.js
index 6ddc191dbe..b2164856fc 100644
--- a/src/util/format-date.js
+++ b/src/util/format-date.js
@@ -1,5 +1,3 @@
-import moment from 'moment';
-
export default function formatDate(dateObj) {
- return moment(dateObj).format('ll');
+ return window.moment(dateObj).format('ll');
}
diff --git a/src/util/format-time.js b/src/util/format-time.js
index 0742eee642..339c6f06d9 100644
--- a/src/util/format-time.js
+++ b/src/util/format-time.js
@@ -1,5 +1,3 @@
-import moment from 'moment';
-
export default function formatTime(dateObj) {
- return moment(dateObj).format('LT');
+ return window.moment(dateObj).format('LT');
}
diff --git a/src/util/hass-behavior.js b/src/util/hass-behavior.js
new file mode 100644
index 0000000000..e8d340ecad
--- /dev/null
+++ b/src/util/hass-behavior.js
@@ -0,0 +1,44 @@
+export default {
+
+ attached() {
+ const hass = this.hass;
+
+ if (!hass) {
+ throw new Error(`No hass property found on ${this.nodeName}`);
+ }
+
+ this.nuclearUnwatchFns = Object.keys(this.properties).reduce(
+ (unwatchFns, key) => {
+ if (!('bindNuclear' in this.properties[key])) {
+ return unwatchFns;
+ }
+
+ let getter = this.properties[key].bindNuclear;
+
+ if (typeof getter !== 'function') {
+ /* eslint-disable no-console */
+ console.warn(`Component ${this.nodeName} uses old style bindNuclear`);
+ /* eslint-enable no-console */
+ } else {
+ getter = getter(hass);
+ }
+
+ if (!getter) {
+ throw new Error(`Undefined getter specified for key ${key}`);
+ }
+
+ this[key] = hass.reactor.evaluate(getter);
+
+ return unwatchFns.concat(hass.reactor.observe(getter, (val) => {
+ this[key] = val;
+ }));
+ }, []);
+ },
+
+ detached() {
+ while (this.nuclearUnwatchFns.length) {
+ this.nuclearUnwatchFns.shift()();
+ }
+ },
+
+};
diff --git a/src/util/home-assistant-js-instance.js b/src/util/home-assistant-js-instance.js
deleted file mode 100644
index 3d2bc0f18f..0000000000
--- a/src/util/home-assistant-js-instance.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import HomeAssistant from 'home-assistant-js';
-
-export default new HomeAssistant();
diff --git a/src/util/nuclear-behavior.js b/src/util/nuclear-behavior.js
deleted file mode 100644
index 5bbb5242a0..0000000000
--- a/src/util/nuclear-behavior.js
+++ /dev/null
@@ -1,29 +0,0 @@
-export default function NuclearObserver(reactor) {
- return {
-
- attached() {
- this.nuclearUnwatchFns = Object.keys(this.properties).reduce(
- (unwatchFns, key) => {
- if (!('bindNuclear' in this.properties[key])) {
- return unwatchFns;
- }
- const getter = this.properties[key].bindNuclear;
- if (!getter) {
- throw new Error(`Undefined getter specified for key ${key}`);
- }
- this[key] = reactor.evaluate(getter);
-
- return unwatchFns.concat(reactor.observe(getter, (val) => {
- this[key] = val;
- }));
- }, []);
- },
-
- detached() {
- while (this.nuclearUnwatchFns.length) {
- this.nuclearUnwatchFns.shift()();
- }
- },
-
- };
-}
diff --git a/src/util/state-card-type.js b/src/util/state-card-type.js
index 961b01abc0..1e50a442d5 100644
--- a/src/util/state-card-type.js
+++ b/src/util/state-card-type.js
@@ -13,12 +13,12 @@ const DOMAINS_WITH_CARD = [
'weblink',
];
-export default function stateCardType(state) {
+export default function stateCardType(hass, state) {
if (state.state === 'unavailable') {
return 'display';
} else if (DOMAINS_WITH_CARD.indexOf(state.domain) !== -1) {
return state.domain;
- } else if (canToggle(state.entityId)) {
+ } else if (canToggle(hass, state.entityId)) {
return 'toggle';
}
return 'display';
diff --git a/src/util/state-icon.js b/src/util/state-icon.js
index 875f270fcb..c597694b95 100644
--- a/src/util/state-icon.js
+++ b/src/util/state-icon.js
@@ -1,8 +1,5 @@
import defaultIcon from './default-icon';
import domainIcon from './domain-icon.js';
-import hass from './home-assistant-js-instance';
-
-const { util: { temperatureUnits } } = hass;
function binarySensorIcon(state) {
const activated = state.state && state.state === 'off';
@@ -42,8 +39,7 @@ export default function stateIcon(state) {
const unit = state.attributes.unit_of_measurement;
if (unit && state.domain === 'sensor') {
- if (unit === temperatureUnits.UNIT_TEMP_C ||
- unit === temperatureUnits.UNIT_TEMP_F) {
+ if (unit === '°C' || unit === '°F') {
return 'mdi:thermometer';
} else if (unit === 'Mice') {
return 'mdi:mouse-variant';
diff --git a/src/util/validate-auth.js b/src/util/validate-auth.js
index 36be6867b4..9e3dc27961 100644
--- a/src/util/validate-auth.js
+++ b/src/util/validate-auth.js
@@ -1,10 +1,6 @@
-import hass from '../util/home-assistant-js-instance';
-
-const { authActions, localStoragePreferences } = hass;
-
-export default function (authToken, rememberAuth) {
- authActions.validate(authToken, {
+export default function (hass, authToken, rememberAuth) {
+ hass.authActions.validate(authToken, {
rememberAuth,
- useStreaming: localStoragePreferences.useStreaming,
+ useStreaming: hass.localStoragePreferences.useStreaming,
});
}