From 4b39d5b438a24e7b11f99cb5acff09659b939fc6 Mon Sep 17 00:00:00 2001 From: ticaki Date: Tue, 21 Jan 2025 11:07:16 +0100 Subject: [PATCH] rename channel to DeviceName --- ioBroker/DEV/NSPanelTs.ts | 67 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/ioBroker/DEV/NSPanelTs.ts b/ioBroker/DEV/NSPanelTs.ts index 525fad80..0ecb8338 100644 --- a/ioBroker/DEV/NSPanelTs.ts +++ b/ioBroker/DEV/NSPanelTs.ts @@ -3397,6 +3397,7 @@ get_locales_servicemenu(); // get_panel_update_data(); // check_updates(); +renameChannel(); // Updates currently compare and every 12 hours let scheduleCheckUpdates = adapterSchedule(undefined, 60 * 60 * 12, () => { get_tasmota_status0(); @@ -3877,10 +3878,7 @@ function get_current_berry_driver_version() { log('Requesting current berry driver version', 'info'); } - let urlString = `http://${get_current_tasmota_ip_address()}/cm?cmnd=GetDriverVersion`; - if (tasmota_web_admin_password != '') { - urlString = `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=GetDriverVersion`; - } + let urlString = get_tasmot_url('GetDriverVersion') axios .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) @@ -4046,6 +4044,46 @@ function get_tasmota_status0() { } } +function renameChannel() { + const urlString = get_tasmot_url('DeviceName'); + axios + .get(urlString, { headers: { 'User-Agent': 'ioBroker' } }) + .then(async function (response) { + if (response.status === 200) { + if (Debug) { + log(JSON.stringify(response.data), 'info'); + } + if (isSetOptionActive) { + try { + if (response.data && response.data.DeviceName && response.data.DeviceName !== '') { + await extendObjectAsync(NSPanel_Path.slice(0,-1), {common:{name:response.data.DeviceName}}) + await extendObjectAsync(AliasPath.slice(0,-1), {common:{name:response.data.DeviceName}}) + } + } catch (e) { + //nothing + } + } + } + }) + .catch(function (error) { + if (error.code === 'EHOSTUNREACH') { + log(`Can't connect to display!`, 'warn'); + } else log(error, 'error'); + }); +} + +/** + * Get url to tasmota api + * @param cmd tasmota command + * @returns url + */ +function get_tasmot_url(cmd: string): string { + if (tasmota_web_admin_password != '') { + return `http://${get_current_tasmota_ip_address()}/cm?user=${tasmota_web_admin_user}&password=${tasmota_web_admin_password}&cmnd=${cmd}`; + } + return `http://${get_current_tasmota_ip_address()}/cm?cmnd=${cmd}`; +} + /** * Updates the Tasmota firmware. * @@ -12599,12 +12637,33 @@ namespace NSPanel { export type PageBaseItem = { uniqueName?: string; role?: string; + /** + * The data point with the data to be used. + */ id?: string | null; + /** + * The icon that is used in the standard case or if ID is true + */ icon?: string; + /** + * The icon that is used when id is false + */ icon2?: string; + /** + * The color that is used in the standard case or if ID is true + */ onColor?: RGB; + /** + * The color that is used when id is false + */ offColor?: RGB; + /** + * + */ useColor?: boolean; + /** + * Interpolate the icon colour by ID + */ interpolateColor?: boolean; minValueBrightness?: number; maxValueBrightness?: number;