UNPKG

iobroker.hmip

Version:

ioBroker Adapter to use the Homematic Cloud IP AccessPoint via Hommeatic Cloud Rest API

2 lines (1 loc) 4.22 kB
import{j as t}from"./jsx-runtime-DG8Pl9r2.js";import{C as r}from"./ConfigCustomHmipSet__loadShare___mf_0_mui_mf_1_material__loadShare__-DJj6ffs_.js";import{C as n}from"./ConfigCustomHmipSet__loadShare___mf_0_iobroker_mf_1_adapter_mf_2_react_mf_2_v5__loadShare__-D7_PrUO1.js";import{C as a,i as h}from"./ConfigCustomHmipSet__mf_v__runtimeInit__mf_v__-Bt-QxDJH.js";const{loadShare:c}=h,{initPromise:l}=a,p=l.then(o=>c("@iobroker/json-config",{customShareInfo:{shareConfig:{singleton:!0,strictVersion:!1,requiredVersion:"*"}}})),u=await p.then(o=>o());var i=u;class g extends i.ConfigGeneric{alive;askTimeout=null;constructor(e){super(e),this.alive=!1,this.state={...this.state,response:"",running:!1,initialized:!1,error:!1}}componentWillUnmount(){super.componentWillUnmount(),this.askTimeout&&(clearTimeout(this.askTimeout),this.askTimeout=null)}async askState(){const e=await this.props.oContext.socket.sendTo(`hmip.${this.props.oContext.instance}`,"requestTokenState",null);this.handleResponse(e)&&(this.askTimeout||=setTimeout(()=>{this.askTimeout=null,this.askState()},300))}handleResponse(e){switch(e.state){case"startedTokenCreation":return this.setState({response:"started token creation",running:!0}),!0;case"waitForBlueButton":return this.setState({response:"press blue button on accesspoint",running:!0}),!0;case"confirmToken":return this.setState({response:"confirming token",running:!0}),!0;case"errorOccurred":this.setState({response:"error occurred during token generation, look at the logs",running:!1,error:!0});break;case"idle":this.setState({response:'press "request token"',running:!1});break;case"tokenCreated":{this.setState({response:"token created, save settings to use your accesspoint",running:!1}),i.ConfigGeneric.setValue(this.props.data,"authToken",e.authToken),i.ConfigGeneric.setValue(this.props.data,"clientAuthToken",e.clientAuthToken),i.ConfigGeneric.setValue(this.props.data,"clientId",e.clientId),this.props.onChange(this.props.data,void 0,()=>this.props.oContext.forceUpdate(["authToken","clientAuthToken","clientId"],this.props.data));break}}return!1}requestToken(){this.setState({response:"started token creation",running:!0,error:!1},async()=>{const e={accessPointSgtin:i.ConfigGeneric.getValue(this.props.data,"accessPointSgtin"),clientId:i.ConfigGeneric.getValue(this.props.data,"clientId"),pin:i.ConfigGeneric.getValue(this.props.data,"pin")||"",deviceName:i.ConfigGeneric.getValue(this.props.data,"deviceName")},s=await this.props.oContext.socket.sendTo(`hmip.${this.props.oContext.instance}`,"requestToken",e);this.handleResponse(s)&&(this.askTimeout||=setTimeout(()=>{this.askTimeout=null,this.askState()},300))})}renderItem(){if(this.alive!==this.props.alive&&(this.alive=this.props.alive,this.alive&&!this.state.initialized&&setTimeout(()=>this.setState({initialized:!0},()=>this.askState()),100)),!this.props.oContext.theme)return t.jsx("div",{children:"..."});if(!this.props.alive&&!this.state.initialized)return t.jsx("div",{className:"hmip-admin-component",children:n.I18n.t("custom_hmip_not_alive")});if(!this.state.initialized)return t.jsx(r.LinearProgress,{});const e=i.ConfigGeneric.getValue(this.props.data,"accessPointSgtin");let s=null;return this.state.response==='press "request token"'&&(s=n.I18n.t("custom_hmip_press_hcu_button").split('"Home Control Unit"'),s.length===2?s=t.jsxs("div",{style:{width:"100%"},children:[t.jsx("span",{children:s[0]}),t.jsx("span",{style:{marginLeft:1,marginRight:1,fontWeight:600,color:this.props.oContext.themeType==="dark"?"#0091c5":"#004b61"},children:'"Home Control Unit"'}),t.jsx("span",{children:s[1]})]}):s=t.jsx("div",{style:{width:"100%"},children:n.I18n.t("custom_hmip_press_hcu_button")})),t.jsxs("div",{style:{width:"100%"},className:"hmip-admin-component",children:[s,t.jsx("div",{style:{color:this.state.error?this.props.oContext.themeType==="dark"?"#c20000":"#800000":void 0,marginBottom:8},children:n.I18n.t(`custom_hmip_${this.state.response}`).replace("custom_hmip_","")}),t.jsx(r.Button,{variant:"contained",color:"primary",disabled:this.state.running||!e,onClick:()=>this.requestToken(),children:this.state.running?t.jsx(r.CircularProgress,{size:24}):n.I18n.t("custom_hmip_request_token")})]})}}export{g as H};