Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update frontend #5685

Merged
merged 1 commit into from Feb 1, 2017
Merged

Update frontend #5685

merged 1 commit into from Feb 1, 2017

Conversation

balloob
Copy link
Member

@balloob balloob commented Feb 1, 2017

Description:
Update frontend

  • Fix last changed label (@balloob, thanks to @lwis for reporting)
  • Refactored Home Assistant JS Websocket (@balloob)
  • Try to reconnect for 10 seconds on first launch when can't find server right away (@balloob)
  • Show that it is connecting in frontend (@balloob)
  • Allow multiple forecasts getting rendered (@Tommatheussen)
  • Fix input_slider (@andrey-git)
  • Support for custom cards (@andrey-git)
homeassistant:
  customize:
    light.ceiling_lights:
      custom_ui_state_card: custom_light

@@ -1 +1 @@
!(function(){"use strict";function e(e){return{type:"auth",api_password:e}}function n(){return{type:"get_states"}}function t(){return{type:"get_config"}}function r(){return{type:"get_services"}}function i(){return{type:"get_panels"}}function s(e,n,t){var r={type:"call_service",domain:e,service:n};return t&&(r.service_data=t),r}function o(e){var n={type:"subscribe_events"};return e&&(n.event_type=e),n}function c(e){return{type:"unsubscribe_events",subscription:e}}function u(){return{type:"ping"}}function a(e,n){return{type:"result",success:!1,error:{code:e,message:n}}}function f(e){return e.result}function d(e,n){var t=new j(e,n);return t.connect()}function v(e,n){return e._subscribeConfig?e._subscribeConfig(n):new Promise(function(t,r){function i(e){a=Object.assign({},a,e);for(var n=0;n<d.length;n++)d[n](a)}function s(e){if(null!==a){var n=Object.assign({},a.core,{components:a.core.components.concat(e.data.component)});i({core:n})}}function o(e){if(null!==a){var n,t=e.data,r=t.domain,s=t.service,o=Object.assign({},a.services[r]||{},(n={},n[s]={description:"",fields:{}},n));i({services:Object.assign({},a.services,(c={},c[r]=o,c))});var c}}function c(){return Promise.all([e.getConfig(),e.getPanels(),e.getServices()]).then((function(e){var n=e[0],t=e[1],r=e[2];i({core:n,panels:t,services:r})}))}function u(e){e&&d.splice(d.indexOf(e),1),0===d.length&&f()}var a=null,f=null,d=[],v=null;n&&d.push(n),e._subscribeConfig=function(e){return e&&(d.push(e),null!==a&&e(a)),v.then((function(){return function(){return u(e)}}))},v=Promise.all([e.subscribeEvents(s,"component_loaded"),e.subscribeEvents(o,"service_registered"),c()]),v.then((function(r){var i=r[0],s=r[1];f=function(){removeEventListener("ready",c),i(),s()},e.addEventListener("ready",c),t((function(){return u(n)}))}),(function(){return r()}))})}function l(e){for(var n={},t=0;t<e.length;t++){var r=e[t];n[r.entity_id]=r}return n}function p(e,n){var t=Object.assign({},e);return t[n.entity_id]=n,t}function h(e,n){var t=Object.assign({},e);return delete t[n],t}function b(e,n){return e._subscribeEntities?e._subscribeEntities(n):new Promise(function(t,r){function i(e){if(null!==c){var n=e.data,t=n.entity_id,r=n.new_state;c=r?p(c,r):h(c,t);for(var i=0;i<a.length;i++)a[i](c)}}function s(){return e.getStates().then((function(e){c=l(e);for(var n=0;n<a.length;n++)a[n](c)}))}function o(n){n&&a.splice(a.indexOf(n),1),0===a.length&&(u(),e.removeEventListener("ready",s),e._subscribeEntities=null)}var c=null,u=null,a=[],f=null;n&&a.push(n),e._subscribeEntities=function(e){return e&&(a.push(e),null!==c&&e(c)),f.then((function(){return function(){return o(e)}}))},f=Promise.all([e.subscribeEvents(i,"state_changed"),s()]),f.then((function(r){var i=r[0];u=i,e.addEventListener("ready",s),t((function(){return o(n)}))}),(function(){return r()}))})}function g(e){return e.substr(0,e.indexOf("."))}function m(e){return e.substr(e.indexOf(".")+1)}function y(e,n){var t={};return n.attributes.entity_id.forEach((function(n){var r=e[n];r&&(t[r.entity_id]=r)})),t}function _(e){var n=[],t={};return Object.keys(e).forEach((function(r){var i=e[r];"group"===g(r)?n.push(i):t[r]=i})),n.sort((function(e,n){return e.attributes.order-n.attributes.order})),n.forEach((function(e){return e.attributes.entity_id.forEach((function(e){delete t[e]}))})),{groups:n,ungrouped:t}}function w(e,n){var t={};return n.attributes.entity_id.forEach((function(n){var r=e[n];r&&!r.attributes.hidden&&(t[r.entity_id]=r,"group"===g(r.entity_id)&&Object.assign(t,y(e,r)))})),t}function E(e){var n=[];return Object.keys(e).forEach((function(t){var r=e[t];r.attributes.view&&n.push(r)})),n.sort((function(e,n){return e.entity_id===P?-1:n.entity_id===P?1:e.attributes.order-n.attributes.order})),n}var k=1,O=2,C=3,j=function(e,n){this.url=e,this.options=n||{},this.commandId=1,this.commands={},this.connectionTries=0,this.eventListeners={},this.closeRequested=!1,this.firstConnection=!0};j.prototype.addEventListener=function(e,n){var t=this.eventListeners[e];t||(t=this.eventListeners[e]=[]),t.push(n)},j.prototype.removeEventListener=function(e,n){var t=this.eventListeners[e];if(t){var r=t.indexOf(n);r!==-1&&t.splice(r,1)}},j.prototype.fireEvent=function(e){var n=this;(this.eventListeners[e]||[]).forEach((function(e){return e(n)}))},j.prototype.connect=function(){var n=this;return new Promise(function(t,r){var i=n.commands;Object.keys(i).forEach((function(e){var n=i[e];n.reject&&n.reject(a(C,"Connection lost"))}));var s=!1;n.connectionTries+=1,n.socket=new WebSocket(n.url),n.socket.addEventListener("open",(function(){n.firstConnection=!1,n.connectionTries=0})),n.socket.addEventListener("message",(function(o){var c=JSON.parse(o.data);switch(c.type){case"event":n.commands[c.id].eventCallback(c.event);break;case"result":c.success?n.commands[c.id].resolve(c):n.commands[c.id].reject(c.error),delete n.commands[c.id];break;case"pong":break;case"auth_required":n.sendMessage(e(n.options.authToken));break;case"auth_invalid":r(O),s=!0;break;case"auth_ok":t(n),n.commandId=1,n.commands={},Object.keys(i).forEach((function(e){var t=i[e];t.eventType&&n.subscribeEvents(t.eventCallback,t.eventType).then((function(e){t.unsubscribe=e}))})),n.fireEvent("ready")}})),n.socket.addEventListener("close",(function(){if(!s&&!n.closeRequested){if(n.firstConnection)return void r(k);0===n.connectionTries&&n.fireEvent("disconnected");var e=1e3*Math.min(n.connectionTries,5);setTimeout((function(){return n.connect()}),e)}}))})},j.prototype.close=function(){this.closeRequested=!0,this.socket.close()},j.prototype.getStates=function(){return this.sendMessagePromise(n()).then(f)},j.prototype.getServices=function(){return this.sendMessagePromise(r()).then(f)},j.prototype.getPanels=function(){return this.sendMessagePromise(i()).then(f)},j.prototype.getConfig=function(){return this.sendMessagePromise(t()).then(f)},j.prototype.callService=function(e,n,t){return this.sendMessagePromise(s(e,n,t))},j.prototype.subscribeEvents=function(e,n){var t=this;return this.sendMessagePromise(o(n)).then((function(r){var i={eventCallback:e,eventType:n,unsubscribe:function(){return t.sendMessagePromise(c(r.id)).then((function(){delete t.commands[r.id]}))}};return t.commands[r.id]=i,function(){return i.unsubscribe()}}))},j.prototype.ping=function(){return this.sendMessagePromise(u())},j.prototype.sendMessage=function(e){this.socket.send(JSON.stringify(e))},j.prototype.sendMessagePromise=function(e){var n=this;return new Promise(function(t,r){n.commandId+=1;var i=n.commandId;e.id=i,n.commands[i]={resolve:t,reject:r},n.sendMessage(e)})};var P="group.default_view",L=Object.freeze({ERR_CANNOT_CONNECT:k,ERR_INVALID_AUTH:O,createConnection:d,subscribeConfig:v,subscribeEntities:b,getGroupEntities:y,splitByGroups:_,getViewEntities:w,extractViews:E,extractDomain:g,extractObjectId:m});window.HAWS=L,window.HASS_DEMO=!1;var T=window.createHassConnection=function(e){var n="https:"===window.location.protocol?"wss":"ws",t=n+"://"+window.location.host+"/api/websocket",r={};return void 0!==e&&(r.authToken=e),d(t,r).then((function(e){return b(e),v(e),e}))};window.noAuth?window.hassConnection=T():window.localStorage.authToken?window.hassConnection=T(window.localStorage.authToken):window.hassConnection=null,"serviceWorker"in navigator&&window.addEventListener("load",(function(){navigator.serviceWorker.register("/service_worker.js")}))})();
!(function(){"use strict";function e(e){return{type:"auth",api_password:e}}function t(){return{type:"get_states"}}function n(){return{type:"get_config"}}function i(){return{type:"get_services"}}function r(){return{type:"get_panels"}}function s(e,t,n){var i={type:"call_service",domain:e,service:t};return n&&(i.service_data=n),i}function o(e){var t={type:"subscribe_events"};return e&&(t.event_type=e),t}function u(e){return{type:"unsubscribe_events",subscription:e}}function c(){return{type:"ping"}}function a(e,t){return{type:"result",success:!1,error:{code:e,message:t}}}function d(t,n){function i(r,s,o){var u=new WebSocket(t),c=!1,a=function(){if(c)return void o(C);if(0===r)return void o(O);var e=r===-1?-1:r-1;setTimeout((function(){return i(e,s,o)}),1e3)},d=function(t){var i=JSON.parse(t.data);switch(i.type){case"auth_required":"authToken"in n?u.send(JSON.stringify(e(n.authToken))):(c=!0,u.close());break;case"auth_invalid":c=!0,u.close();break;case"auth_ok":u.removeEventListener("message",d),u.removeEventListener("close",a),s(u)}};u.addEventListener("message",d),u.addEventListener("close",a)}return new Promise(function(e,t){return i(n.setupRetry||0,e,t)})}function f(e){return e.result}function v(e,t){return void 0===t&&(t={}),d(e,t).then((function(n){var i=new j(e,t);return i.setSocket(n),i}))}function h(e,t){return e._subscribeConfig?e._subscribeConfig(t):new Promise(function(n,i){function r(e){a=Object.assign({},a,e);for(var t=0;t<f.length;t++)f[t](a)}function s(e){if(null!==a){var t=Object.assign({},a.core,{components:a.core.components.concat(e.data.component)});r({core:t})}}function o(e){if(null!==a){var t,n=e.data,i=n.domain,s=n.service,o=Object.assign({},a.services[i]||{},(t={},t[s]={description:"",fields:{}},t));r({services:Object.assign({},a.services,(u={},u[i]=o,u))});var u}}function u(){return Promise.all([e.getConfig(),e.getPanels(),e.getServices()]).then((function(e){var t=e[0],n=e[1],i=e[2];r({core:t,panels:n,services:i})}))}function c(e){e&&f.splice(f.indexOf(e),1),0===f.length&&d()}var a=null,d=null,f=[],v=null;t&&f.push(t),e._subscribeConfig=function(e){return e&&(f.push(e),null!==a&&e(a)),v.then((function(){return function(){return c(e)}}))},v=Promise.all([e.subscribeEvents(s,"component_loaded"),e.subscribeEvents(o,"service_registered"),u()]),v.then((function(i){var r=i[0],s=i[1];d=function(){removeEventListener("ready",u),r(),s()},e.addEventListener("ready",u),n((function(){return c(t)}))}),(function(){return i()}))})}function l(e){for(var t={},n=0;n<e.length;n++){var i=e[n];t[i.entity_id]=i}return t}function p(e,t){var n=Object.assign({},e);return n[t.entity_id]=t,n}function b(e,t){var n=Object.assign({},e);return delete n[t],n}function g(e,t){return e._subscribeEntities?e._subscribeEntities(t):new Promise(function(n,i){function r(e){if(null!==u){var t=e.data,n=t.entity_id,i=t.new_state;u=i?p(u,i):b(u,n);for(var r=0;r<a.length;r++)a[r](u)}}function s(){return e.getStates().then((function(e){u=l(e);for(var t=0;t<a.length;t++)a[t](u)}))}function o(t){t&&a.splice(a.indexOf(t),1),0===a.length&&(c(),e.removeEventListener("ready",s),e._subscribeEntities=null)}var u=null,c=null,a=[],d=null;t&&a.push(t),e._subscribeEntities=function(e){return e&&(a.push(e),null!==u&&e(u)),d.then((function(){return function(){return o(e)}}))},d=Promise.all([e.subscribeEvents(r,"state_changed"),s()]),d.then((function(i){var r=i[0];c=r,e.addEventListener("ready",s),n((function(){return o(t)}))}),(function(){return i()}))})}function m(e){return e.substr(0,e.indexOf("."))}function y(e){return e.substr(e.indexOf(".")+1)}function _(e,t){var n={};return t.attributes.entity_id.forEach((function(t){var i=e[t];i&&(n[i.entity_id]=i)})),n}function w(e){var t=[],n={};return Object.keys(e).forEach((function(i){var r=e[i];"group"===m(i)?t.push(r):n[i]=r})),t.sort((function(e,t){return e.attributes.order-t.attributes.order})),t.forEach((function(e){return e.attributes.entity_id.forEach((function(e){delete n[e]}))})),{groups:t,ungrouped:n}}function E(e,t){var n={};return t.attributes.entity_id.forEach((function(t){var i=e[t];i&&!i.attributes.hidden&&(n[i.entity_id]=i,"group"===m(i.entity_id)&&Object.assign(n,_(e,i)))})),n}function k(e){var t=[];return Object.keys(e).forEach((function(n){var i=e[n];i.attributes.view&&t.push(i)})),t.sort((function(e,t){return e.entity_id===P?-1:t.entity_id===P?1:e.attributes.order-t.attributes.order})),t}var O=1,C=2,L=3,j=function(e,t){this.url=e,this.options=t||{},this.commandId=1,this.commands={},this.eventListeners={},this.closeRequested=!1,this._handleMessage=this._handleMessage.bind(this),this._handleClose=this._handleClose.bind(this)};j.prototype.setSocket=function(e){var t=this,n=this.socket;if(this.socket=e,e.addEventListener("message",this._handleMessage),e.addEventListener("close",this._handleClose),n){var i=this.commands;this.commandId=1,this.commands={},Object.keys(i).forEach((function(e){var n=i[e];n.eventType&&t.subscribeEvents(n.eventCallback,n.eventType).then((function(e){n.unsubscribe=e}))})),this.fireEvent("ready")}},j.prototype.addEventListener=function(e,t){var n=this.eventListeners[e];n||(n=this.eventListeners[e]=[]),n.push(t)},j.prototype.removeEventListener=function(e,t){var n=this.eventListeners[e];if(n){var i=n.indexOf(t);i!==-1&&n.splice(i,1)}},j.prototype.fireEvent=function(e){var t=this;(this.eventListeners[e]||[]).forEach((function(e){return e(t)}))},j.prototype.close=function(){this.closeRequested=!0,this.socket.close()},j.prototype.getStates=function(){return this.sendMessagePromise(t()).then(f)},j.prototype.getServices=function(){return this.sendMessagePromise(i()).then(f)},j.prototype.getPanels=function(){return this.sendMessagePromise(r()).then(f)},j.prototype.getConfig=function(){return this.sendMessagePromise(n()).then(f)},j.prototype.callService=function(e,t,n){return this.sendMessagePromise(s(e,t,n))},j.prototype.subscribeEvents=function(e,t){var n=this;return this.sendMessagePromise(o(t)).then((function(i){var r={eventCallback:e,eventType:t,unsubscribe:function(){return n.sendMessagePromise(u(i.id)).then((function(){delete n.commands[i.id]}))}};return n.commands[i.id]=r,function(){return r.unsubscribe()}}))},j.prototype.ping=function(){return this.sendMessagePromise(c())},j.prototype.sendMessage=function(e){this.socket.send(JSON.stringify(e))},j.prototype.sendMessagePromise=function(e){var t=this;return new Promise(function(n,i){t.commandId+=1;var r=t.commandId;e.id=r,t.commands[r]={resolve:n,reject:i},t.sendMessage(e)})},j.prototype._handleMessage=function(e){var t=JSON.parse(e.data);switch(t.type){case"event":this.commands[t.id].eventCallback(t.event);break;case"result":t.success?this.commands[t.id].resolve(t):this.commands[t.id].reject(t.error),delete this.commands[t.id];break;case"pong":}},j.prototype._handleClose=function(){var e=this;if(Object.keys(this.commands).forEach((function(t){var n=e.commands[t],i=n.reject;i&&i(a(L,"Connection lost"))})),!this.closeRequested){this.fireEvent("disconnected");var t=Object.assign({},this.options,{setupRetry:0}),n=function(i){setTimeout((function(){d(e.url,t).then((function(t){return e.setSocket(t)}),(function(){return n(i+1)}))}),1e3*Math.min(i,5))};n(0)}};var P="group.default_view",S=Object.freeze({ERR_CANNOT_CONNECT:O,ERR_INVALID_AUTH:C,createConnection:v,subscribeConfig:h,subscribeEntities:g,getGroupEntities:_,splitByGroups:w,getViewEntities:E,extractViews:k,extractDomain:m,extractObjectId:y});window.HAWS=S,window.HASS_DEMO=!1;var M=window.createHassConnection=function(e){var t="https:"===window.location.protocol?"wss":"ws",n=t+"://"+window.location.host+"/api/websocket",i={setupRetry:10};return void 0!==e&&(i.authToken=e),v(n,i).then((function(e){return g(e),h(e),e}))};window.noAuth?window.hassConnection=M():window.localStorage.authToken?window.hassConnection=M(window.localStorage.authToken):window.hassConnection=null,"serviceWorker"in navigator&&window.addEventListener("load",(function(){navigator.serviceWorker.register("/service_worker.js")}))})();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semicolon.
Expected an assignment or function call and instead saw an expression.
Too many errors. (50% scanned).

@balloob balloob merged commit 987f59e into dev Feb 1, 2017
@balloob balloob deleted the update-frontend branch February 1, 2017 08:47
Ordep pushed a commit to Ordep/home-assistant that referenced this pull request Feb 9, 2017
@home-assistant home-assistant locked and limited conversation to collaborators May 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants