/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/iobroker.ebus@4.0.3/build/main.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(t,e,i,s){void 0===s&&(s=i);var a=Object.getOwnPropertyDescriptor(e,i);a&&!("get"in a?!e.__esModule:a.writable||a.configurable)||(a={enumerable:!0,get:function(){return e[i]}}),Object.defineProperty(t,s,a)}:function(t,e,i,s){void 0===s&&(s=i),t[s]=e[i]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),__importStar=this&&this.__importStar||function(){var t=function(e){return t=Object.getOwnPropertyNames||function(t){var e=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[e.length]=i);return e},t(e)};return function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var s=t(e),a=0;a<s.length;a++)"default"!==s[a]&&__createBinding(i,e,s[a]);return __setModuleDefault(i,e),i}}(),__importDefault=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ebus=void 0;const utils=__importStar(require("@iobroker/adapter-core")),axios_1=__importDefault(require("axios")),TelnetClient_1=__importDefault(require("./lib/TelnetClient"));class ebus extends utils.Adapter{intervalID=null;updateTimerID=null;requestRunning=!1;oPolledVars=[];oHistoryVars=[];oHTTPParamsVars=[];ebusdMinVersion=[26,1];ebusdVersion=[0,0];ebusdUpdateVersion=[0,0];constructor(t={}){super({...t,name:"ebus"}),this.on("ready",this.onReady.bind(this)),this.on("stateChange",this.onStateChange.bind(this)),this.on("objectChange",this.onObjectChange.bind(this)),this.on("message",this.onMessage.bind(this)),this.on("unload",this.onUnload.bind(this))}async onReady(){this.log.debug(JSON.stringify(this.config));try{await this.main()}catch(t){this.log.error("Exception in onReady ["+t+"]")}}async onUnload(t){await Promise.resolve();try{null!=this.intervalID&&clearInterval(this.intervalID),null!=this.updateTimerID&&clearTimeout(this.updateTimerID),this.log.info("cleaned everything up..."),t()}catch(e){this.log.error("Exception in onUnload "+e),t()}}onObjectChange(t,e){e?this.log.info(`Objekt ${t} geändert: ${JSON.stringify(e)}`):this.log.info(`Objekt ${t} gelöscht`)}async onStateChange(t,e){if(null!=e&&!0!==e.ack){this.log.debug(`handle state change ${t}`);const e=t.split(".");"cmd"===e[2]?(await this.ebusd_Command(),this.StartDataRequest()):"find"===e[2]?await this.ebusd_find():this.log.warn(`unhandled state change ${t}`)}}async onMessage(t){if(this.log.info("on message "+JSON.stringify(t)),await Promise.resolve(),"object"==typeof t&&t.command)switch(t.command){case"findParams":this.log.debug("message FindParams called"),await this.FindParams(t);break;case"Install":this.log.debug("message install called");break;case"Update":this.log.debug("message update called");break;case"checkInstallableversion":await this.CheckVersion("installable",t);break;case"checkCurrentVersion":await this.CheckVersion("current",t);break;case"checkSupportedVersion":await this.CheckVersion("supported",t);break;default:this.log.error(`unknown message ${t.command}`)}}async main(){this.log.debug("start with interface ebusd "),this.FillPolledVars(),this.FillHistoryVars(),this.FillHTTPParamsVars(),await this.checkVariables(),await this.subscribeVars();let t=5;this.config.readInterval>0&&(t=this.config.readInterval),this.log.debug(`read every  ${t} minutes`),this.intervalID=setInterval(this.Do.bind(this),60*t*1e3),await this.Do()}async DoRequest(){this.log.debug("DoRequest "),this.requestRunning?this.log.debug("DoRequest: do nothing already running "):(this.requestRunning=!0,await this.ebusd_ReadValues(),await this.ebusd_ReceiveData()),this.requestRunning=!1}async Do(){this.log.debug("starting ... "),await this.ebusd_Command(),await this.DoRequest()}StartDataRequest(){null!=this.updateTimerID&&(clearTimeout(this.updateTimerID),this.updateTimerID=null),this.updateTimerID=setTimeout(this.DataRequest.bind(this),500),this.log.debug("StartDataRequest")}async DataRequest(){this.log.debug("get data after command and timeout"),null!=this.updateTimerID&&(clearTimeout(this.updateTimerID),this.updateTimerID=null),await this.DoRequest()}FillPolledVars(){try{if(void 0!==this.config.PolledDPs&&null!=this.config.PolledDPs&&this.config.PolledDPs.length>0){this.log.debug("use new object list for polled vars");for(let t=0;t<this.config.PolledDPs.length;t++)this.config.PolledDPs[t].active&&this.oPolledVars.push(this.config.PolledDPs[t])}}catch(t){this.log.error(`exception in FillPolledVars [${t}]`)}this.log.debug(`list of polled vars ${JSON.stringify(this.oPolledVars)}`)}FillHistoryVars(){try{void 0!==this.config.HistoryDPs&&null!=this.config.HistoryDPs&&this.config.HistoryDPs.length>0&&(this.log.debug("use new object list for history vars"),this.oHistoryVars=this.config.HistoryDPs)}catch(t){this.log.error(`exception in function FillHistoryVars [${t}]`)}this.log.debug(`list of history vars ${JSON.stringify(this.oHistoryVars)}`),this.oHistoryVars.forEach(((t,e)=>{const i=t.name.includes("."),s=t.name.includes("ebus."),a=t.name.includes("value");this.log.debug("checking "+t.name+" index "+e+" hasDot: "+i+" hasInstance: "+s+" hasValue: "+a),i||this.log.warn("please check history variable: "+t.name+" -> should contain the complete DP"),a||this.log.warn("please check history variable "+t.name+" -> should contain 'value'"),s&&this.log.warn("please check history variable "+t.name+" -> should not contain instance name and instance number e.g. 'ebus.0' ")}))}FillHTTPParamsVars(){void 0!==this.config.HTTPparameter&&null!=this.config.HTTPparameter&&this.config.HTTPparameter.length>0&&(this.oHTTPParamsVars=this.config.HTTPparameter,this.log.debug(`use optionally HTTP parameter ${JSON.stringify(this.oHTTPParamsVars)}`))}async ebusd_Command(){const t=await this.getStateAsync("cmd");if(void 0!==t&&null!=t){const e=t.val?.toString();if(null!=e&&""!==e){this.log.debug(`got command(s): ${e}`),this.log.debug(`connect telnet to IP ${this.config.targetIP} port ${this.config.targetTelnetPort}`);try{const t=new TelnetClient_1.default;await t.connect(this.config.targetIP,this.config.targetTelnetPort);const i=e.split(",");if(i.length>0){let e="";for(let s=0;s<i.length;s++){this.log.debug(`send ${i[s]}`),await t.write(`${i[s]}\n`);const a=await t.read();a.includes("ERR")?this.log.warn(`sent ${i[s]}, received ${a} please check ebusd logs for details!`):this.log.debug(`received ${a}`),e+=a.toString(),e+=", "}e=e.replace(/\r?\n|\r/g,""),e=e.slice(0,-2),await this.setState("cmdResult",{ack:!0,val:e})}else this.log.warn(`no commands in list ${e} ${JSON.stringify(i)}`);await this.setState("cmd",{ack:!0,val:""}),await t.disconnect()}catch(t){this.log.error(`exception from tcp socket[${t}]`)}}}else this.log.debug(`object cmd not found ${JSON.stringify(t)}`)}async ebusd_find(){try{const t=new TelnetClient_1.default;await t.connect(this.config.targetIP,this.config.targetTelnetPort),await t.write("find -F circuit,name,comment\n");const e=await t.read();let i;e.includes("ERR")?this.log.warn(`received error! sent find, received ${e} please check ebusd logs for details!`):this.log.debug(`received ${typeof e} ${e}`),i="string"==typeof e?e:e instanceof Uint8Array?(new TextDecoder).decode(e):e instanceof ArrayBuffer?(new TextDecoder).decode(new Uint8Array(e)):String(e);const s=i.split(/[\r?\n,]+/);this.log.info("found entries: "+s.length);for(let e=0;e<s.length;e++){const i=s[e].split(",");await this.UpdateDP(i[0],i[1],i[2]);let a=`read -f -c ${i[0]} ${i[1]}`;this.log.debug(`send cmd ${a}`),a+="\n",await t.write(a);const n=await t.read();this.log.debug(`received ${typeof n} ${n}`)}await t.disconnect()}catch(t){this.log.error(`exception from tcp socket in ebusd_find[${t}]`)}}async subscribeVars(){this.subscribeStates("cmd"),this.subscribeStates("find"),await this.setState("cmdResult",{ack:!0,val:""})}async checkVariables(){let t,e;if(this.log.debug("init variables "),t="cmd",e={type:"state",common:{name:"ebusd command",type:"string",role:"text",read:!0,write:!0}},await this.CreateObject(t,e),t="cmdResult",e={type:"state",common:{name:"ebusd command result",type:"string",role:"text",read:!0,write:!1}},await this.CreateObject(t,e),t="find",e={type:"state",common:{name:"find existing data points",type:"boolean",role:"button",read:!1,write:!0}},await this.CreateObject(t,e),this.log.debug(`init common variables and ${this.oHistoryVars.length} history DP's`),this.oHistoryVars.length>0){this.oHistoryVars.length>4&&this.log.warn(`too many history values ${this.oHistoryVars.length} -> maximum is  4`);for(let i=1;i<=this.oHistoryVars.length;i++)if(this.oHistoryVars[i-1].name.length>0){t=`history.value${i}`,e={type:"state",common:{name:`history value ${i} as JSON ${this.oHistoryVars[i-1].name}`,type:"string",role:"value",unit:"",read:!0,write:!1},native:{location:t}},await this.CreateObject(t,e)}else this.log.warn(`ignoring history value ${i} (invalid name)`);t="history.date",e={type:"state",common:{name:"ebus history date / time as JSON",type:"string",role:"value",unit:"",read:!0,write:!1},native:{location:t}},await this.CreateObject(t,e)}t="history.error",e={type:"state",common:{name:"ebus error",type:"string",role:"value",unit:"",read:!0,write:!1},native:{location:t}},await this.CreateObject(t,e)}VersionCheck(){this.ebusdVersion[0]>0&&((this.ebusdVersion[0]<this.ebusdMinVersion[0]||this.ebusdVersion[0]==this.ebusdMinVersion[0]&&this.ebusdVersion[1]<this.ebusdMinVersion[1])&&this.log.info(`please update ebusd, old version found: ${this.ebusdVersion[0]}.${this.ebusdVersion[1]} supported version is ${this.ebusdMinVersion[0]}.${this.ebusdMinVersion[1]}`),(this.ebusdVersion[0]>this.ebusdMinVersion[0]||this.ebusdVersion[0]>=this.ebusdMinVersion[0]&&this.ebusdVersion[1]>this.ebusdMinVersion[1])&&this.log.info(`unsupported ebusd version found (too new): ${this.ebusdVersion[0]}.${this.ebusdVersion[1]} supported version is ${this.ebusdMinVersion[0]}.${this.ebusdMinVersion[1]}`)),this.ebusdUpdateVersion[0]>0&&this.ebusdVersion[0]>0&&(this.ebusdUpdateVersion[0]>this.ebusdVersion[0]||this.ebusdUpdateVersion[0]==this.ebusdVersion[0]&&this.ebusdUpdateVersion[1]>this.ebusdVersion[1])&&this.log.info(`new ebusd version found: ${this.ebusdUpdateVersion[0]}.${this.ebusdUpdateVersion[1]} supported version is ${this.ebusdMinVersion[0]}.${this.ebusdMinVersion[1]}`)}async ebusd_ReceiveData(){try{let t=`http://${this.config.targetIP}:${this.config.targetHTTPPort}/data`,e=0;if(void 0!==this.oHTTPParamsVars&&null!=this.oHTTPParamsVars&&this.oHTTPParamsVars.length>0)for(let i=0;i<this.oHTTPParamsVars.length;i++)this.oHTTPParamsVars[i].active&&(t+=0==e?"?":"&",t+=`${this.oHTTPParamsVars[i].name}=${this.oHTTPParamsVars[i].value}`,e++);this.log.debug(`request data from ${t}`);const i=await axios_1.default.get(t);this.log.debug(`got data ${typeof i.data} ${JSON.stringify(i.data)}`);const s=(t,e=".",i="")=>Object.keys(t).reduce(((a,n)=>{const o=i.length?`${i}${e}`:"";return"object"==typeof t[n]&&null!==t[n]&&Object.keys(t[n]).length>0?Object.assign(a,s(t[n],e,o+n)):a[o+n]=t[n],a}),{}),a=s(i.data,"."),n=[],o=[],r=new Date,l=r.getMonth()+1;o.push({date:`${r.getDate()}.${l}.${r.getFullYear()}`,time:`${r.getHours()}:${r.getMinutes()}:${r.getSeconds()}`});let h="none";for(let t in a){const e=t.split(".");let i=a[t];if(t.includes("[")||t.includes("]")){this.log.debug(`found unsupported chars in ${t}`);const e=t.indexOf("["),i=t.lastIndexOf("]");if(e>0&&i>0){const s=t.slice(e,i+1);t=t.replace(s,"")}}if(t.includes("global.version")){const t=i.split(".");t.length>1&&(this.log.debug(`installed ebusd version is ${t[0]}.${t[1]}`),this.ebusdVersion[0]=t[0],this.ebusdVersion[1]=t[1],this.VersionCheck())}if(t.includes("global.updatecheck")){i=i.replace("revision v",""),i=i.replace(" available","");const t=i.split(".");t.length>1&&(this.log.info(`found ebusd update version ${t[0]}.${t[1]}`),this.ebusdUpdateVersion[0]=t[0],this.ebusdUpdateVersion[1]=t[1],this.VersionCheck())}let s=this.mapJsTypeToIoBrokerType(i);if(this.config.useBoolean4Onoff&&("string"!=s||"on"!=i&&"off"!=i||(this.log.debug(`Key ${t} change to boolean ${i}`),s="boolean",i="on"==i)),(t.includes(".hcmode2.value")||t.includes(".hcmode.value"))&&(0===parseInt(i)?(this.log.info(`${t}in hcmode2 with value 0: off`),i="off"):5===parseInt(i)?(this.log.info(`${t} with value 5: EVU Sperrzeit`),i="EVU Sperrzeit"):this.log.debug(`in hcmode2, value ${i}`),s=this.mapJsTypeToIoBrokerType(i)),t.includes(".lastup")&&parseInt(i)>0){const a=new Date(1e3*i),n=a.toLocaleString();i=n,s=this.mapJsTypeToIoBrokerType(i);const o=new Date;let r=!1;if((e[0].includes("scan")||e[0].includes("Scan")||e[0].includes("ehp")||e.length>2&&e[2].includes("currenterror")||this.config.DisableTimeUpdateCheck)&&(r=!0),e.length>2&&e[2].includes("Timer")&&(r=!0),!r&&Math.abs(a.getTime()-o.getTime())>36e5){const e=`no update since ${n} ${t} `;h.includes("none")?h=`ebus: ${e}`:h+=e,this.log.warn(e)}}await this.AddObject(t,s),await this.UpdateObject(t,i);for(let e=0;e<this.oHistoryVars.length;e++)if(t===this.oHistoryVars[e].name){const s='{"'+t+'": "'+i+'"}';this.log.debug("push history "+s),n[e]=[],n[e].push(JSON.parse(s))}}await this.setState("history.error",{ack:!0,val:h}),this.log.debug("all http done"),n.length>0&&o.length>0&&(this.config.History4Vis2?await this.UpdateHistory_Vis2(n,o):await this.UpdateHistory(n,o))}catch(t){this.log.error(`exception in ebusd_ReceiveData [${t}]`),await this.setState("history.error",{ack:!0,val:"exception in receive"})}}mapJsTypeToIoBrokerType(t){if(Array.isArray(t))return"array";switch(typeof t){case"string":return"string";case"number":return"number";case"boolean":return"boolean";case"object":return null===t?"mixed":"object";default:return"mixed"}}async UpdateHistory_Vis2(t,e){this.log.debug(`start history 4 VIS-2 ${JSON.stringify(t)} ${JSON.stringify(e)}`),await this.setState("history.date",{ack:!0,val:""});for(let i=0;i<t.length;i++){const s=t[i];let a=[];const n=i+1,o=await this.getStateAsync(`history.value${n}`);null==o?(this.log.warn(`history.value${n} not found, creating DP ${JSON.stringify(o)}`),await this.setState(`history.value${n}`,{ack:!0,val:"[]"})):null!=o.val&&""!=o.val&&"string"==typeof o.val&&(a=JSON.parse(o.val),this.log.debug(`history.value${n} got ${JSON.stringify(a)}`));for(let t=0;t<s.length;t++){const i=s[t];let n=0;for(const t in i){const s=i[t],o=e[n].time,r=e[n].date;n++;const l=o.split(":"),h=r.split("."),c=parseInt(h[0]),d=parseInt(h[1])-1,u=parseInt(h[2]),g=parseInt(l[0]),m=parseInt(l[1]),b=new Date(u,d,c,g,m,0,0);if(this.log.debug(`${t} ${s} ${b.toLocaleString()}`),a.push([b,s]),a.length>200)for(let t=a.length;t>200;t--)a.shift()}}await this.setState(`history.value${n}`,{ack:!0,val:JSON.stringify(a)})}}async UpdateHistory(t,e){if(this.oHistoryVars.length>0){let i=-1;const s=await this.getStateAsync("history.date");if(void 0!==s&&null!=s)try{let t=[];if(null!=s.val&&""!=s.val&&"string"==typeof s.val&&(t=JSON.parse(s.val)),t.push(e),t.length>200)for(let e=t.length;e>200;e--)t.shift();i=t.length,await this.setState("history.date",{ack:!0,val:JSON.stringify(t)})}catch(t){this.log.error(`exception in UpdateHistory part1 [${t}]`),await this.setState("history.date",{ack:!0,val:"[]"}),i=0}else this.log.warn("history.date not found, creating DP "),await this.setState("history.date",{ack:!0,val:"[]"}),i=0;if(this.oHistoryVars.length>0){for(let e=1;e<=this.oHistoryVars.length;e++)if(this.oHistoryVars[e-1].name.length>0){await this.UpdateHistoryValues(t,e,i)||(await this.setState("history.date",{ack:!0,val:"[]"}),i=0,this.log.warn("reset history date too"))}else this.log.debug(`ignoring history value ${e}`);this.log.info("all history done")}}else this.log.debug("nothing to do for history")}async UpdateHistoryValues(t,e,i){let s=!0;const a=await this.getStateAsync(`history.value${e}`);if(void 0!==a&&null!=a)try{let n=[];if(null!==a&&null!=a.val&&""!=a.val&&"string"==typeof a.val&&(n=JSON.parse(a.val)),n.push(t[e-1]),n.length>200)for(let t=n.length;t>200;t--)n.shift();const o=`history.value${e}`;this.log.debug(`update history ${o}`),i!=n.length?(s=!1,await this.setState(`history.value${e}`,{ack:!0,val:"[]"}),this.log.warn(`reset history ${o} because number of values different to date values`)):await this.setState(o,{ack:!0,val:JSON.stringify(n)})}catch(t){this.log.error(`exception in UpdateHistory part2 [${t}]`),await this.setState(`history.value${e}`,{ack:!0,val:"[]"}),i>0&&(s=!1)}else this.log.warn(`history.value${e} not found, creating DP ${JSON.stringify(a)}`),await this.setState(`history.value${e}`,{ack:!0,val:"[]"}),i>0&&(s=!1);return s}async ebusd_ReadValues(){if(this.oPolledVars.length>0){this.log.debug(`to poll ctr ${this.oPolledVars.length} vals:  ${JSON.stringify(this.oPolledVars)}`);try{const t=new TelnetClient_1.default;await t.connect(this.config.targetIP,this.config.targetTelnetPort);let e=0;for(let i=0;i<this.oPolledVars.length;i++){let s="",a="";null!=this.oPolledVars[i].circuit&&this.oPolledVars[i].circuit.length>0&&(s=`-c ${this.oPolledVars[i].circuit} `),null!=this.oPolledVars[i].parameter&&this.oPolledVars[i].parameter.length>0&&(a=` ${this.oPolledVars[i].parameter}`);let n=`read -f ${s}${this.oPolledVars[i].name}${a}`;this.log.debug(`send cmd ${n}`),n+="\n";let o=null;try{await t.write(n),o=await t.read()}catch(t){this.log.warn(`exception from tcp socket write/read in ebusd_ReadValues for cmd ${n}[${t}] -> retry`),e++,e>this.config.maxretries?this.log.error(`max retries, skip cmd ${n}`):(i--,this.log.debug("retry to send data "))}null!==o&&this.log.debug(`received ${o} for ${JSON.stringify(this.oPolledVars[i])}`)}await t.disconnect(),this.log.debug("telnet disonnected")}catch(t){this.log.error(`exception from tcp socket in ebusd_ReadValues [${t}]`)}}else this.log.debug("nothing to poll; skip telnet")}async FindParams(t){this.log.debug(`FindParams ${JSON.stringify(t)}`);const e=[];try{if(null!==t.message&&null!==t.message.circuit){const i=t.message.circuit,s=new TelnetClient_1.default;await s.connect(this.config.targetIP,this.config.targetTelnetPort);const a=`find -c ${i} -F circuit,name\n`;this.log.debug(`send cmd ${a}`),await s.write(a),this.log.debug("sent, wait for data...");const n=await s.read();let o;this.log.info("data received: "+n),n.includes("ERR")?this.log.warn(`received error! sent find, received ${n} please check ebusd logs for details! ${a}`):this.log.info(`received ${typeof n} ${n} ${+a}`),o="string"==typeof n?n:n instanceof Uint8Array?(new TextDecoder).decode(n):n instanceof ArrayBuffer?(new TextDecoder).decode(new Uint8Array(n)):String(n);const r=o.split(/[\r?\n,]+/);this.log.info("found entries: "+r.length);for(let t=0;t<r.length;t++){const i=r[t].split(",");let s=!0;if(""==i[0]||""==i[1])s=!1;else for(let t=0;t<e.length;t++)e[t].circuit==i[0]&&e[t].name==i[1]&&(s=!1);if(s){const t={active:!1,circuit:i[0],name:i[1]};e.push(t)}}await s.disconnect()}else this.log.error("no circuit defined where to look for parameter, check values!")}catch(t){this.log.error(`exception in FindParams [${t}]`)}this.log.info(`parameters ${JSON.stringify(e)}`),this.sendTo(t.from,t.command,e,t.callback)}async CheckVersion(t,e){if("installable"==t){let t="unknown";t=this.ebusdUpdateVersion[0]>0&&this.ebusdVersion[0]>0?`${this.ebusdUpdateVersion[0]}.${this.ebusdUpdateVersion[1]}`:await this.GetLatestVersionGithub(),this.sendTo(e.from,e.command,t,e.callback)}else"current"==t?this.sendTo(e.from,e.command,`${this.ebusdVersion[0]}.${this.ebusdVersion[1]}`,e.callback):"supported"==t&&this.sendTo(e.from,e.command,`${this.ebusdMinVersion[0]}.${this.ebusdMinVersion[1]}`,e.callback)}async GetLatestVersionGithub(){let t="unknown";try{const e="https://api.github.com/repos/john30/ebusd/releases/latest";this.log.debug(`call ${e}`);const i=await axios_1.default.get(e,{timeout:5e3});null!=i&&200==i.status&&null!=i.data?(this.log.info(`installable version on github ${JSON.stringify(i.data.tag_name)} (${JSON.stringify(i.data.name)})`),t="on github "+JSON.stringify(i.data.tag_name)+"("+JSON.stringify(i.data.name)+")"):t="unknown / no result"}catch(e){this.log.error(`exception in GetLatestVersionGithub [${e}]`),t="unknown / error"}return t}async CreateObject(t,e){const i=await this.getObjectAsync(t);null!=i?(i.common.role!=e.common.role||i.common.type!=e.common.type||i.common.unit!=e.common.unit&&null!=e.common.unit||i.common.read!=e.common.read||i.common.write!=e.common.write||i.common.name!=e.common.name)&&"state"===e.type&&(this.log.warn(`change object ${JSON.stringify(e)} ${JSON.stringify(i)}`),await this.extendObject(t,{common:{name:e.common.name,role:e.common.role,type:e.common.type,unit:e.common.unit,read:e.common.read,write:e.common.write}})):await this.setObjectNotExistsAsync(t,e)}async UpdateDP(t,e,i){const s=`${t}.messages.${e}`;this.log.debug(`update check for ${s}`);const a=await this.getObjectAsync(s);this.log.debug(`update check got ${JSON.stringify(a)}`),null!=a?a.common.name!=i&&(this.log.debug(`update  ${s} ${i}`),await this.extendObject(s,{common:{name:i,read:!0,write:!1}})):await this.setObjectNotExistsAsync(s,{type:"channel",common:{name:i},native:{}})}async AddObject(t,e){try{const i=await this.getObjectAsync(t);null!=i?"value"==i.common.role&&i.common.type==e||(this.log.debug(` !!! need to extend for ${t}`),await this.extendObject(t,{common:{type:e,role:"value"}})):(this.log.warn(` !!! does not exist, creating now ${t}`),await this.setObjectNotExistsAsync(t,{type:"state",common:{name:"data",type:e,role:"value",unit:"",read:!0,write:!1},native:{location:t}}))}catch(t){this.log.error(`exception in AddObject [${t}]`)}}async UpdateObject(t,e){try{void 0===e?this.log.warn(`updateObject: not updated ${t} value: ${e} ${typeof e}`):null==e?(this.log.debug(`updateObject: update to null ${t} value: ${e}`),await this.setState(t,{ack:!0,val:null})):await this.setState(t,{ack:!0,val:e})}catch(t){this.log.error(`exception in UpdateObject [${t}]`)}}}exports.ebus=ebus,require.main!==module?module.exports=t=>new ebus(t):new ebus;
//# sourceMappingURL=/sm/a40c728d683fc1bafebda7ca1ab6bf8392d59d0ac327ab4004a9bd622f14585c.map