Switch Manager - ${null===(t=this.config)||void 0===t?void 0:t.name}
@@ -355,7 +361,7 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
${(null===(s=this.config)||void 0===s?void 0:s.enabled)?"Disable":"Enable"}
+ .path=${(null===(o=this.config)||void 0===o?void 0:o.enabled)?pt:ct}>
@@ -370,7 +376,7 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
+ .path=${ht}>
@@ -404,7 +410,7 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
- ${this.blueprint&&!(null===(d=this.blueprint)||void 0===d?void 0:d.has_image)?V` `:V` `}
+ ${this.blueprint&&!(null===(d=this.blueprint)||void 0===d?void 0:d.has_image)?V` `:V` `}
${(null===(c=this.config)||void 0===c?void 0:c.valid_blueprint)?V`
@@ -439,7 +445,7 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
.hass=${this.hass}
.value=${null===(m=null===(g=this.config)||void 0===g?void 0:g.buttons[this.button_index])||void 0===m?void 0:m.actions[this.action_index].mode}
label="Mode"
- .selector=${{select:{mode:"dropdown",options:vt.map((t=>({label:t.charAt(0).toUpperCase()+t.slice(1),value:t})))}}}
+ .selector=${{select:{mode:"dropdown",options:ut.map((t=>({label:t.charAt(0).toUpperCase()+t.slice(1),value:t})))}}}
@value-changed=${this._modeValueChanged}>
@@ -488,20 +494,22 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
}
h3, #identifier {
padding-left: 25px;
+ position: relative;
}
#identifier-input {
width: 300px;
}
#identifier ha-icon-button {
vertical-align: middle;
- background: var(--material-secondary-text-color);
+ background: var(--mdc-text-field-fill-color);
border-radius: 50%;
- color: var(--primary-background-color);
+ color: var(--mdc-text-field-ink-color);
margn-top: -10px;
margin-top: -14px;
margin-left: -34px;
position: relative;
--mdc-icon-button-size: 54px;
+ box-shadow: -5px 1px 8px -6px;
}
#identifier ha-icon-button[listening] {
animation: 1s infinite alternate pulse;
@@ -561,6 +569,9 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
width: 260px;
height: 260px;
}
+ #switch-image svg image {
+ filter: drop-shadow(0px 0px 8px #00000033);
+ }
#switch-image svg .button {
fill: #00000000;
stroke: #00adff3d;
@@ -576,11 +587,11 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
font-weight: bold;
color: var(--error-color);
}
- `]}connectedCallback(){super.connectedCallback(),this._loadConfig()}disconnectedCallback(){super.disconnectedCallback(),this._subscribed&&(this._subscribed(),this._subscribed=null)}_loadConfig(){"id"in this.params?(this.is_new=!1,this.hass.callWS({type:bt("configs"),config_id:this.params.id}).then((t=>{this._setConfig(t.config)}))):(this.is_new=!0,this._dirty=!0,"blueprint"in this.params&&this._loadBlueprint(this.params.blueprint).then((t=>{this._setConfig(function(t){let e={id:null,name:"New Switch",enabled:!0,identifier:"",blueprint:t,valid_blueprint:!0,buttons:[]};return t.buttons.forEach(((t,i)=>{e.buttons[i]={actions:[]},t.actions.forEach(((t,s)=>{e.buttons[i].actions[s]={mode:vt[0],sequence:[]}}))})),e}(t.blueprint)),this._showRenameDialog()})))}_loadBlueprint(t){return this.hass.callWS({type:bt("blueprints"),blueprint_id:t})}_setConfig(t){if(this.config=t,t._error)return this._errors=t._error,void(this._block_save=!0);this._setBlueprint(t.blueprint),this._updateSequence()}_setBlueprint(t){this.blueprint=t,this.requestUpdate(),this._drawSVG()}async _drawSVG(){if(this.blueprint.has_image){await this.updateComplete;var t=new Image;t.src=ft(`${this.blueprint.id}.png`),t.onload=()=>{this.svg.setAttributeNS(null,"viewBox",`0 0 ${t.width.toString()} ${t.height.toString()}`);var e=document.createElementNS("http://www.w3.org/2000/svg","image");e.setAttributeNS(null,"x","0"),e.setAttributeNS(null,"y","0"),e.setAttributeNS(null,"width",t.width.toString()),e.setAttributeNS(null,"height",t.height.toString()),e.setAttributeNS("http://www.w3.org/1999/xlink","href",t.src),e.setAttributeNS(null,"visibility","visible"),this.svg.prepend(e)},this.blueprint.buttons.length>1&&this.blueprint.buttons.forEach(((t,e)=>{let i;"circle"==t.shape?(i=document.createElementNS("http://www.w3.org/2000/svg","circle"),i.setAttributeNS(null,"cx",t.x.toString()),i.setAttributeNS(null,"cy",t.y.toString()),i.setAttributeNS(null,"r",t.width.toString())):"path"==t.shape?(i=document.createElementNS("http://www.w3.org/2000/svg","path"),i.setAttributeNS(null,"d",t.d.toString())):(i=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.setAttributeNS(null,"x",t.x.toString()),i.setAttributeNS(null,"y",t.y.toString()),i.setAttributeNS(null,"width",t.width.toString()),i.setAttributeNS(null,"height",t.height.toString())),i.setAttribute("class","button"),i.setAttribute("index",e.toString()),this.button_index==e&&i.setAttribute("selected",""),i.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),this._setButtonIndex(parseInt(t.target.getAttribute("index")))})),this.svg.append(i)}))}}_validate(){return this._errors=null,this.identifier_input.invalid=!1,!!this.config.identifier||(this._errors="Identifier must not be empty",this.identifier_input.invalid=!0,this.identifier_input.errorMessage="Identifier required",!1)}_save(){!this._block_save&&this._validate()&&(this._block_save=!0,this._dirty=!1,this.hass.callWS({type:bt("config/save"),config:Object.assign(Object.assign({},this.config),{blueprint:this.config.blueprint.id})}).then((t=>{this.is_new&&(this.is_new=!1,this.config.id=t.config_id,$t(_t(`edit/${t.config_id}`))),yt(this,{message:"Switch Saved"})})).catch((t=>{yt(this,{message:t.message}),this._errors=t.message,this._dirty=!0})).finally((()=>this._block_save=!1)))}_actionChanged(t){this._setActionIndex(t.detail.index)}_setButtonIndex(t){t!=this.button_index&&(this.svg.querySelector("[selected]").removeAttribute("selected"),this.svg.querySelector(`[index="${t}"]`).setAttribute("selected",""),this.button_index=t,this._setActionIndex(0))}_setActionIndex(t){this.action_index=t,this._updateSequence()}_configSequenceChanged(t){this._updateSequence(t.detail.value),this._errors=void 0,this._dirty=!0}async _listenForEvent(){if(this._subscribed)return this._subscribed(),void(this._subscribed=void 0);this._subscribed=await this.hass.connection.subscribeEvents((t=>{this.blueprint.identifier_key in t.data&&(this.identifier_input.value=t.data[this.blueprint.identifier_key],this._identifierChanged(),this._subscribed(),this._subscribed=void 0)}),this.blueprint.event_type)}_identifierChanged(t){this.config.identifier=function(t,e,i=!0){return i?t.renderRoot.querySelector(`#${e}`).value.toString().trim():t.querySelector(`#${e}`).value.toString().trim()}(this,"identifier-input"),this._dirty=!0}_modeValueChanged(t){var e;(null===(e=this.config)||void 0===e?void 0:e.buttons[this.button_index].actions[this.action_index].mode)!=t.detail.value&&(this.config.buttons[this.button_index].actions[this.action_index].mode=t.detail.value,this.requestUpdate("config"),this._dirty=!0)}async _showRenameDialog(){gt(this,"show-dialog",{dialogTag:"switch-manager-dialog-rename-switch",dialogImport:()=>Promise.resolve().then((function(){return ze})),dialogParams:{config:this.config,update:t=>{this.config.name=t.name,this._dirty=!0,this.requestUpdate()},onClose:()=>{}}})}_updateSequence(t){t&&(this.config.buttons[this.button_index].actions[this.action_index].sequence=t),this.sequence=this.config.buttons[this.button_index].actions[this.action_index].sequence,this.requestUpdate("config")}_toggleEnabled(){this.hass.callWS({type:bt("config/enabled"),enabled:!this.config.enabled,config_id:this.config.id}).then((t=>{this.config.enabled=t.enabled,this.requestUpdate("config"),yt(this,{message:"Switch "+(t.enabled?"Enabled":"Disabled")})})).catch((t=>yt(this,{message:t.message})))}async _deleteConfirm(){wt(this,{title:"Delete switch?",text:`${this.config.name} will be permanently deleted.`,confirmText:"Delete",dismissText:"Cancel",confirm:()=>this._delete(),confirmation:!0,destructive:!0})}async _delete(){this.hass.callWS({type:bt("config/delete"),config_id:this.config.id.toString()}).then((t=>{yt(this,{message:"Switch Deleted"}),$t(_t())}))}}t([s()],Me.prototype,"hass",void 0),t([s()],Me.prototype,"narrow",void 0),t([s()],Me.prototype,"panel",void 0),t([s()],Me.prototype,"route",void 0),t([s()],Me.prototype,"params",void 0),t([s()],Me.prototype,"blueprint",void 0),t([s()],Me.prototype,"config",void 0),t([s()],Me.prototype,"disabled",void 0),t([o()],Me.prototype,"_subscribed",void 0),t([o()],Me.prototype,"sequence",void 0),t([o()],Me.prototype,"button_index",void 0),t([o()],Me.prototype,"action_index",void 0),t([o()],Me.prototype,"is_new",void 0),t([o()],Me.prototype,"_dirty",void 0),t([o()],Me.prototype,"_block_save",void 0),t([o()],Me.prototype,"_errors",void 0),t([n("#switch-svg")],Me.prototype,"svg",void 0),t([n("#identifier-input")],Me.prototype,"identifier_input",void 0),customElements.define("switch-manager-switch-editor",Me);let Ue=class extends nt{get route(){return this._route}set route(t){this._route=t;let e=t.path.split("/");"new"==e[1]?this.params={action:"new",blueprint:e[2]}:"edit"==e[1]?this.params={action:"edit",id:e[2]}:this.params={}}constructor(){super(),this.params={},(async()=>{var t,e,i,s,o,n,r;if(customElements.get("ha-automation-action")&&customElements.get("ha-data-table"))return;await customElements.whenDefined("partial-panel-resolver");const a=document.createElement("partial-panel-resolver").getRoutes([{component_name:"config",url_path:"a"}]);await(null===(i=null===(e=null===(t=null==a?void 0:a.routes)||void 0===t?void 0:t.a)||void 0===e?void 0:e.load)||void 0===i?void 0:i.call(e)),await customElements.whenDefined("ha-panel-config");const l=document.createElement("ha-panel-config");await(null===(r=null===(n=null===(o=null===(s=null==l?void 0:l.routerOptions)||void 0===s?void 0:s.routes)||void 0===o?void 0:o.script)||void 0===n?void 0:n.load)||void 0===r?void 0:r.call(n)),await customElements.whenDefined("ha-config-dashboard")})()}render(){return"action"in this.params?V`
+ `]}connectedCallback(){super.connectedCallback(),this._loadConfig()}disconnectedCallback(){super.disconnectedCallback(),this._subscribed&&(this._subscribed(),this._subscribed=null)}_loadConfig(){"id"in this.params?(this.is_new=!1,this.hass.callWS({type:ft("configs"),config_id:this.params.id}).then((t=>{this._setConfig(t.config)}))):(this.is_new=!0,this._dirty=!0,"blueprint"in this.params&&this._loadBlueprint(this.params.blueprint).then((t=>{this._setConfig(function(t){let e={id:null,name:"New Switch",enabled:!0,identifier:"",blueprint:t,valid_blueprint:!0,buttons:[]};return t.buttons.forEach(((t,i)=>{e.buttons[i]={actions:[]},t.actions.forEach(((t,s)=>{e.buttons[i].actions[s]={mode:ut[0],sequence:[]}}))})),e}(t.blueprint)),this._showRenameDialog()})))}_loadBlueprint(t){return this.hass.callWS({type:ft("blueprints"),blueprint_id:t})}_setConfig(t){if(this.config=t,t._error)return this._errors=t._error,void(this._block_save=!0);this._setBlueprint(t.blueprint),this._updateSequence()}_setBlueprint(t){this.blueprint=t,this.requestUpdate(),this._drawSVG()}async _drawSVG(){if(this.blueprint.has_image){await this.updateComplete;var t=new Image;t.src=_t(`${this.blueprint.id}.png`),t.onload=()=>{this.svg.setAttributeNS(null,"viewBox",`0 0 ${t.width.toString()} ${t.height.toString()}`);var e=document.createElementNS("http://www.w3.org/2000/svg","image");e.setAttributeNS(null,"x","0"),e.setAttributeNS(null,"y","0"),e.setAttributeNS(null,"width",t.width.toString()),e.setAttributeNS(null,"height",t.height.toString()),e.setAttributeNS("http://www.w3.org/1999/xlink","href",t.src),e.setAttributeNS(null,"visibility","visible"),this.svg.prepend(e)},this.blueprint.buttons.length>1&&this.blueprint.buttons.forEach(((t,e)=>{let i;"circle"==t.shape?(i=document.createElementNS("http://www.w3.org/2000/svg","circle"),i.setAttributeNS(null,"cx",t.x.toString()),i.setAttributeNS(null,"cy",t.y.toString()),i.setAttributeNS(null,"r",t.width.toString())):"path"==t.shape?(i=document.createElementNS("http://www.w3.org/2000/svg","path"),i.setAttributeNS(null,"d",t.d.toString())):(i=document.createElementNS("http://www.w3.org/2000/svg","rect"),i.setAttributeNS(null,"x",t.x.toString()),i.setAttributeNS(null,"y",t.y.toString()),i.setAttributeNS(null,"width",t.width.toString()),i.setAttributeNS(null,"height",t.height.toString())),i.setAttribute("class","button"),i.setAttribute("index",e.toString()),this.button_index==e&&i.setAttribute("selected",""),i.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),this._setButtonIndex(parseInt(t.target.getAttribute("index")))})),this.svg.append(i)}))}}_validate(){return this._errors=null,this.identifier_input.invalid=!1,!!this.config.identifier||(this._errors="Identifier must not be empty",this.identifier_input.invalid=!0,this.identifier_input.errorMessage="Identifier required",!1)}_save(){!this._block_save&&this._validate()&&(this._block_save=!0,this._dirty=!1,this.hass.callWS({type:ft("config/save"),config:Object.assign(Object.assign({},this.config),{blueprint:this.config.blueprint.id})}).then((t=>{this.is_new&&(this.is_new=!1,this.config.id=t.config_id,bt(mt(`edit/${t.config_id}`))),yt(this,{message:"Switch Saved"})})).catch((t=>{yt(this,{message:t.message}),this._errors=t.message,this._dirty=!0})).finally((()=>this._block_save=!1)))}_actionChanged(t){this._setActionIndex(t.detail.index)}_setButtonIndex(t){t!=this.button_index&&(this.svg.querySelector("[selected]").removeAttribute("selected"),this.svg.querySelector(`[index="${t}"]`).setAttribute("selected",""),this.button_index=t,this._setActionIndex(0))}_setActionIndex(t){this.action_index=t,this._updateSequence()}_configSequenceChanged(t){this._updateSequence(t.detail.value),this._errors=void 0,this._dirty=!0}async _listenForEvent(){if(this._subscribed)return this._subscribed(),void(this._subscribed=void 0);this._subscribed=await this.hass.connection.subscribeEvents((t=>{this.blueprint.identifier_key in t.data&&(this.identifier_input.value=t.data[this.blueprint.identifier_key],this._identifierChanged(),this._subscribed(),this._subscribed=void 0)}),this.blueprint.event_type)}_identifierChanged(t){this.config.identifier=function(t,e,i=!0){return i?t.renderRoot.querySelector(`#${e}`).value.toString().trim():t.querySelector(`#${e}`).value.toString().trim()}(this,"identifier-input"),this._dirty=!0}_modeValueChanged(t){var e;(null===(e=this.config)||void 0===e?void 0:e.buttons[this.button_index].actions[this.action_index].mode)!=t.detail.value&&(this.config.buttons[this.button_index].actions[this.action_index].mode=t.detail.value,this.requestUpdate("config"),this._dirty=!0)}async _showRenameDialog(){vt(this,"show-dialog",{dialogTag:"switch-manager-dialog-rename-switch",dialogImport:()=>Promise.resolve().then((function(){return ze})),dialogParams:{config:this.config,update:t=>{this.config.name=t.name,this._dirty=!0,this.requestUpdate()},onClose:()=>{}}})}_updateSequence(t){t&&(this.config.buttons[this.button_index].actions[this.action_index].sequence=t),this.sequence=this.config.buttons[this.button_index].actions[this.action_index].sequence,this.requestUpdate("config")}_toggleEnabled(){this.hass.callWS({type:ft("config/enabled"),enabled:!this.config.enabled,config_id:this.config.id}).then((t=>{this.config.enabled=t.enabled,this.requestUpdate("config"),yt(this,{message:"Switch "+(t.enabled?"Enabled":"Disabled")})})).catch((t=>yt(this,{message:t.message})))}async _deleteConfirm(){wt(this,{title:"Delete switch?",text:`${this.config.name} will be permanently deleted.`,confirmText:"Delete",dismissText:"Cancel",confirm:()=>this._delete(),confirmation:!0,destructive:!0})}async _delete(){this.hass.callWS({type:ft("config/delete"),config_id:this.config.id.toString()}).then((t=>{yt(this,{message:"Switch Deleted"}),bt(mt())}))}}t([s()],Me.prototype,"hass",void 0),t([s()],Me.prototype,"narrow",void 0),t([s()],Me.prototype,"panel",void 0),t([s()],Me.prototype,"route",void 0),t([s()],Me.prototype,"params",void 0),t([s()],Me.prototype,"blueprint",void 0),t([s()],Me.prototype,"config",void 0),t([s()],Me.prototype,"disabled",void 0),t([o()],Me.prototype,"_subscribed",void 0),t([o()],Me.prototype,"sequence",void 0),t([o()],Me.prototype,"button_index",void 0),t([o()],Me.prototype,"action_index",void 0),t([o()],Me.prototype,"is_new",void 0),t([o()],Me.prototype,"_dirty",void 0),t([o()],Me.prototype,"_block_save",void 0),t([o()],Me.prototype,"_errors",void 0),t([n("#switch-svg")],Me.prototype,"svg",void 0),t([n("#identifier-input")],Me.prototype,"identifier_input",void 0),customElements.define("switch-manager-switch-editor",Me);let Ue=class extends nt{get route(){return this._route}set route(t){this._route=t;let e=t.path.split("/");"new"==e[1]?this.params={action:"new",blueprint:e[2]}:"edit"==e[1]?this.params={action:"edit",id:e[2]}:this.params={}}constructor(){super(),this.params={},this.component_name="custom",(async()=>{var t,e,i,s,o,n,r;if(customElements.get("ha-automation-action")&&customElements.get("ha-data-table"))return;await customElements.whenDefined("partial-panel-resolver");const a=document.createElement("partial-panel-resolver").getRoutes([{component_name:"config",url_path:"a"}]);await(null===(i=null===(e=null===(t=null==a?void 0:a.routes)||void 0===t?void 0:t.a)||void 0===e?void 0:e.load)||void 0===i?void 0:i.call(e)),await customElements.whenDefined("ha-panel-config");const l=document.createElement("ha-panel-config");await(null===(r=null===(n=null===(o=null===(s=null==l?void 0:l.routerOptions)||void 0===s?void 0:s.routes)||void 0===o?void 0:o.script)||void 0===n?void 0:n.load)||void 0===r?void 0:r.call(n)),await customElements.whenDefined("ha-config-dashboard")})()}render(){return"action"in this.params?V`
`:V`
- `}firstUpdated(t){super.firstUpdated(t),this.hass.loadFragmentTranslation("config")}};t([s({attribute:!1})],Ue.prototype,"hass",void 0),t([s()],Ue.prototype,"narrow",void 0),t([s()],Ue.prototype,"panel",void 0),t([o()],Ue.prototype,"params",void 0),t([s()],Ue.prototype,"route",null),Ue=t([e("switch-manager-panel")],Ue);let Oe=class extends nt{async showDialog(t){this._params=t}closeDialog(){var t,e;return!(null===(t=this._params)||void 0===t?void 0:t.confirmation)&&!(null===(e=this._params)||void 0===e?void 0:e.prompt)&&(!this._params||(this._dismiss(),!0))}render(){if(!this._params)return V``;const t=this._params.confirmation||this._params.prompt;return V`
+ `}firstUpdated(t){super.firstUpdated(t),this.hass.loadFragmentTranslation("config")}};t([s()],Ue.prototype,"hass",void 0),t([s()],Ue.prototype,"narrow",void 0),t([s()],Ue.prototype,"panel",void 0),t([o()],Ue.prototype,"params",void 0),t([o()],Ue.prototype,"component_name",void 0),t([s()],Ue.prototype,"route",null),Ue=t([e("switch-manager-panel")],Ue);let Oe=class extends nt{async showDialog(t){this._params=t}closeDialog(){var t,e;return!(null===(t=this._params)||void 0===t?void 0:t.confirmation)&&!(null===(e=this._params)||void 0===e?void 0:e.prompt)&&(!this._params||(this._dismiss(),!0))}render(){if(!this._params)return V``;const t=this._params.confirmation||this._params.prompt;return V`
- `}_dismiss(){var t;(null===(t=this._params)||void 0===t?void 0:t.cancel)&&this._params.cancel(),this._close()}_confirm(){this._params.confirm&&this._params.confirm(),this._close()}_dialogClosed(t){"ignore"!==t.detail.action&&this._dismiss()}_close(){this._params&&(this._params=void 0,gt(this,"dialog-closed",{dialog:this.localName}))}static get styles(){return p`
+ `}_dismiss(){var t;(null===(t=this._params)||void 0===t?void 0:t.cancel)&&this._params.cancel(),this._close()}_confirm(){this._params.confirm&&this._params.confirm(),this._close()}_dialogClosed(t){"ignore"!==t.detail.action&&this._dismiss()}_close(){this._params&&(this._params=void 0,vt(this,"dialog-closed",{dialog:this.localName}))}static get styles(){return p`
:host([inert]) {
pointer-events: initial !important;
cursor: initial !important;
@@ -646,95 +657,94 @@ function t(t,e,i,s){var o,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPro
ha-textfield {
width: 100%;
}
- `}};t([s({attribute:!1})],Oe.prototype,"hass",void 0),t([o()],Oe.prototype,"_params",void 0),Oe=t([e("switch-manager-dialog-confirm")],Oe);var Te=Object.freeze({__proto__:null});let Le=class extends nt{constructor(){super(...arguments),this._opened=!1}showDialog(){this._opened=!0}closeDialog(){this._opened&>(this,"dialog-closed",{dialog:this.localName}),this._opened=!1}render(){return this._opened?V`
+ `}};t([s({attribute:!1})],Oe.prototype,"hass",void 0),t([o()],Oe.prototype,"_params",void 0),Oe=t([e("switch-manager-dialog-confirm")],Oe);var Te=Object.freeze({__proto__:null});let Le=class extends nt{constructor(){super(...arguments),this._opened=!1}showDialog(){this._opened=!0}closeDialog(){this._opened&&vt(this,"dialog-closed",{dialog:this.localName}),this._opened=!1}render(){return this._opened?V`
`}>
-
+ .heading="${$t("Select Blueprint")}">
+