From c956a7a31ea97e9c3e21df7e03fdc5f565c2d4aa Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:18:11 -0400 Subject: [PATCH 01/26] bytesToLargestString to return largest metric of disk space --- src/util/calculate.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index b6a1add005dc..a66d2ad27058 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -21,3 +21,12 @@ export const getValueInPercentage = ( export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; + +export const bytesToLargestString = (value: number, decimals = 3): number => { + if (bytes === 0) return '0 Bytes'; + const k = 1024; + decimals = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(bytes) / Math.log(k)); + return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]; +} From 2d041acbb1fd45144a097458f82fdfdf76e43b9c Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:24:16 -0400 Subject: [PATCH 02/26] Add more info to title of disk space bar --- hassio/src/system/hassio-system-metrics.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 042935fba3eb..46df4d2a4229 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -24,6 +24,7 @@ import { HomeAssistant } from "../../../src/types"; import { getValueInPercentage, roundWithOneDecimal, + bytesToString, } from "../../../src/util/calculate"; import { hassioStyle } from "../resources/hassio-style"; @@ -88,6 +89,11 @@ class HassioSystemMetrics extends LitElement { ${roundedValue}% 50, "target-critical": roundedValue > 85, From d63bd1a9ee0ef433e13b4fa5a754d5b9f3062244 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:24:40 -0400 Subject: [PATCH 03/26] Rename funciton --- src/util/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index a66d2ad27058..d3676a11d3fa 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -22,7 +22,7 @@ export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; -export const bytesToLargestString = (value: number, decimals = 3): number => { +export const bytesToString = (value: number, decimals = 3): number => { if (bytes === 0) return '0 Bytes'; const k = 1024; decimals = decimals < 0 ? 0 : decimals; From dfed22e7949286dc9dd8e9aacafbb43718897ab4 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:44:45 -0400 Subject: [PATCH 04/26] Use the exponentiation operator --- src/util/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index d3676a11d3fa..1d328eb27635 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -28,5 +28,5 @@ export const bytesToString = (value: number, decimals = 3): number => { decimals = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / Math.pow(k, i)).toFixed(decimals)) + ' ' + sizes[i]; + return parseFloat((bytes / k ** i).toFixed(decimals)) + ' ' + sizes[i]; } From 82dba901d7c64e9191d3a33777f11d6666daf3a4 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:45:25 -0400 Subject: [PATCH 05/26] === --- hassio/src/system/hassio-system-metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 46df4d2a4229..491d5fea95fa 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -89,7 +89,7 @@ class HassioSystemMetrics extends LitElement { ${roundedValue}% Date: Tue, 6 Oct 2020 13:49:07 -0400 Subject: [PATCH 06/26] Add padding for Ludeeus --- hassio/src/system/hassio-system-metrics.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 491d5fea95fa..937edc2f729c 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -161,6 +161,7 @@ class HassioSystemMetrics extends LitElement { } .value { width: 42px; + padding-right: 4px; } `, ]; From 4371c9771f61e2fd691e57e3510984a3da5732be Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 13:54:10 -0400 Subject: [PATCH 07/26] Correct var and return value --- src/util/calculate.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index 1d328eb27635..afaf44413982 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -22,11 +22,11 @@ export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; -export const bytesToString = (value: number, decimals = 3): number => { - if (bytes === 0) return '0 Bytes'; +export const bytesToString = (value: number, decimals = 3): string => { + if (value === 0) return '0 Bytes'; const k = 1024; decimals = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - const i = Math.floor(Math.log(bytes) / Math.log(k)); - return parseFloat((bytes / k ** i).toFixed(decimals)) + ' ' + sizes[i]; + const i = Math.floor(Math.log(value) / Math.log(k)); + return parseFloat((value / k ** i).toFixed(decimals)) + ' ' + sizes[i]; } From def93777171489afe7c120233663784d457b41da Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:22:53 -0400 Subject: [PATCH 08/26] Add title to metrics --- hassio/src/system/hassio-system-metrics.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 937edc2f729c..a81421b2e568 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -39,27 +39,37 @@ class HassioSystemMetrics extends LitElement { @internalProperty() private _coreMetrics?: HassioStats; protected render(): TemplateResult | void { - const usedSpace = this._getUsedSpace(this.hostInfo); + const host = this.hostInfo + const usedSpace = this._getUsedSpace(host); + const usedSpaceTitle = + bytesToString(host.disk_used * 1e6) + + "/" + + bytesToString(host.disk_total * 1e6); const metrics = [ { description: "Core CPU Usage", value: this._coreMetrics?.cpu_percent, + title: "", }, { description: "Core RAM Usage", value: this._coreMetrics?.memory_percent, + title: "", }, { description: "Supervisor CPU Usage", value: this._supervisorMetrics?.cpu_percent, + title: "", }, { description: "Supervisor RAM Usage", value: this._supervisorMetrics?.memory_percent, + title: "", }, { description: "Used Space", value: usedSpace, + title: usedSpaceTitle, }, ]; @@ -89,11 +99,7 @@ class HassioSystemMetrics extends LitElement { ${roundedValue}% 50, "target-critical": roundedValue > 85, From b59268770ae28386f2d45aebb0719acd14a20b59 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:41:22 -0400 Subject: [PATCH 09/26] Add title to _renderMetric --- hassio/src/system/hassio-system-metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index a81421b2e568..6c381723f510 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -88,7 +88,7 @@ class HassioSystemMetrics extends LitElement { this._loadData(); } - private _renderMetric(description: string, value: number): TemplateResult { + private _renderMetric(description: string, value: number, title: string): TemplateResult { const roundedValue = roundWithOneDecimal(value); return html` From f5e758a738cabec571a5e4a85ece640cc55f22f0 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:45:24 -0400 Subject: [PATCH 10/26] lint --- hassio/src/system/hassio-system-metrics.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 6c381723f510..215d34441e35 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -88,7 +88,11 @@ class HassioSystemMetrics extends LitElement { this._loadData(); } - private _renderMetric(description: string, value: number, title: string): TemplateResult { + private _renderMetric( + description: string, + value: number, + title: string + ): TemplateResult { const roundedValue = roundWithOneDecimal(value); return html` From a5d45e321f3653e55e3b0010b09a87718560930e Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Tue, 6 Oct 2020 19:50:13 -0400 Subject: [PATCH 11/26] lint more --- hassio/src/system/hassio-system-metrics.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 215d34441e35..8ceb8516dd22 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -77,7 +77,11 @@ class HassioSystemMetrics extends LitElement {
${metrics.map((metric) => - this._renderMetric(metric.description, metric.value ?? 0) + this._renderMetric( + metric.description, + metric.value ?? 0, + metric.title + ) )}
From 4a32303edaa1cb4269a2b17c3ad348ba561195d2 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 07:25:07 -0400 Subject: [PATCH 12/26] Use template string, rename title to tooltip and make optional. --- hassio/src/system/hassio-system-metrics.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 8ceb8516dd22..a4c35935662c 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -39,37 +39,31 @@ class HassioSystemMetrics extends LitElement { @internalProperty() private _coreMetrics?: HassioStats; protected render(): TemplateResult | void { - const host = this.hostInfo + const host = this.hostInfo; const usedSpace = this._getUsedSpace(host); - const usedSpaceTitle = - bytesToString(host.disk_used * 1e6) + - "/" + - bytesToString(host.disk_total * 1e6); + const usedSpaceTitle = `${bytesToString(host.disk_used * 1e6)}/ + ${bytesToString(host.disk_total * 1e6)}`; const metrics = [ { description: "Core CPU Usage", value: this._coreMetrics?.cpu_percent, - title: "", }, { description: "Core RAM Usage", value: this._coreMetrics?.memory_percent, - title: "", }, { description: "Supervisor CPU Usage", value: this._supervisorMetrics?.cpu_percent, - title: "", }, { description: "Supervisor RAM Usage", value: this._supervisorMetrics?.memory_percent, - title: "", }, { description: "Used Space", value: usedSpace, - title: usedSpaceTitle, + tooltip: usedSpaceTitle, }, ]; @@ -80,7 +74,7 @@ class HassioSystemMetrics extends LitElement { this._renderMetric( metric.description, metric.value ?? 0, - metric.title + metric.tooltip ?? undefined ) )} @@ -95,7 +89,7 @@ class HassioSystemMetrics extends LitElement { private _renderMetric( description: string, value: number, - title: string + tooltip?: string ): TemplateResult { const roundedValue = roundWithOneDecimal(value); return html` @@ -107,7 +101,7 @@ class HassioSystemMetrics extends LitElement { ${roundedValue}%
50, "target-critical": roundedValue > 85, From f4233881a7797dc372b5c92c590088d11f1e7ec7 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 07:33:24 -0400 Subject: [PATCH 13/26] Fix usedSpaceTip string and change name from usedSpaceText --- hassio/src/system/hassio-system-metrics.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index a4c35935662c..db61dc712912 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -41,8 +41,9 @@ class HassioSystemMetrics extends LitElement { protected render(): TemplateResult | void { const host = this.hostInfo; const usedSpace = this._getUsedSpace(host); - const usedSpaceTitle = `${bytesToString(host.disk_used * 1e6)}/ - ${bytesToString(host.disk_total * 1e6)}`; + const usedSpaceTip = `${bytesToString( + host.disk_used * 1e6 + )}/${bytesToString(host.disk_total * 1e6)}`; const metrics = [ { description: "Core CPU Usage", From 7eb4d928c6a748c4e0e221f7949928065200cab6 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 07:34:08 -0400 Subject: [PATCH 14/26] Update usedSpaceTip var name --- hassio/src/system/hassio-system-metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index db61dc712912..72dfff8a2976 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -64,7 +64,7 @@ class HassioSystemMetrics extends LitElement { { description: "Used Space", value: usedSpace, - tooltip: usedSpaceTitle, + tooltip: usedSpaceTip, }, ]; From 1daa26d8195ef434829acae1a143c5a00604df6f Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 08:24:34 -0400 Subject: [PATCH 15/26] Template string in bytesToString calc util --- src/util/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index afaf44413982..1a9bb25be661 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -28,5 +28,5 @@ export const bytesToString = (value: number, decimals = 3): string => { decimals = decimals < 0 ? 0 : decimals; const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; const i = Math.floor(Math.log(value) / Math.log(k)); - return parseFloat((value / k ** i).toFixed(decimals)) + ' ' + sizes[i]; + return `${parseFloat((value / k ** i).toFixed(decimals))} ${sizes[i]}`; } From b45b6a034b75857a0e02a4371bff822b4055053f Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 09:33:47 -0400 Subject: [PATCH 16/26] Move tooltip to description div --- hassio/src/system/hassio-system-metrics.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 72dfff8a2976..6c5db74f982d 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -97,12 +97,11 @@ class HassioSystemMetrics extends LitElement { ${description} -
+
${roundedValue}% 50, "target-critical": roundedValue > 85, From 3012370228f3caa4abbc7d1a8fd1c3e5f4d93245 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:27:49 -0400 Subject: [PATCH 17/26] Add ram usage tooltip --- hassio/src/system/hassio-system-metrics.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 6c5db74f982d..80455500140f 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -44,6 +44,9 @@ class HassioSystemMetrics extends LitElement { const usedSpaceTip = `${bytesToString( host.disk_used * 1e6 )}/${bytesToString(host.disk_total * 1e6)}`; + const coreRamTip = `${bytesToString( + this._coreMetrics?.memory_usage + )}/${bytesToString(this._coreMetrics?.memory_limit)}`; const metrics = [ { description: "Core CPU Usage", @@ -52,6 +55,7 @@ class HassioSystemMetrics extends LitElement { { description: "Core RAM Usage", value: this._coreMetrics?.memory_percent, + tooltip: coreRamTip, }, { description: "Supervisor CPU Usage", From c0c81157e2f485f2e407521d74aa3615df182dbc Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:33:10 -0400 Subject: [PATCH 18/26] Default to 0 in bytesToString --- src/util/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index 1a9bb25be661..2a97ee68e29f 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -22,7 +22,7 @@ export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; -export const bytesToString = (value: number, decimals = 3): string => { +export const bytesToString = (value = 0, decimals = 3): string => { if (value === 0) return '0 Bytes'; const k = 1024; decimals = decimals < 0 ? 0 : decimals; From 822afcea0668ad84b0069aa86c16f069b6f5b657 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Wed, 7 Oct 2020 10:48:38 -0400 Subject: [PATCH 19/26] Update decimal default of bytesToString --- src/util/calculate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index 2a97ee68e29f..cb34362a3182 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -22,7 +22,7 @@ export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; -export const bytesToString = (value = 0, decimals = 3): string => { +export const bytesToString = (value = 0, decimals = 2): string => { if (value === 0) return '0 Bytes'; const k = 1024; decimals = decimals < 0 ? 0 : decimals; From 8def5c7ce26c19bf4c0e82de9f4e40f7661deac7 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:09:43 -0400 Subject: [PATCH 20/26] Remove some consts --- hassio/src/system/hassio-system-metrics.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 80455500140f..471809e8612a 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -39,14 +39,6 @@ class HassioSystemMetrics extends LitElement { @internalProperty() private _coreMetrics?: HassioStats; protected render(): TemplateResult | void { - const host = this.hostInfo; - const usedSpace = this._getUsedSpace(host); - const usedSpaceTip = `${bytesToString( - host.disk_used * 1e6 - )}/${bytesToString(host.disk_total * 1e6)}`; - const coreRamTip = `${bytesToString( - this._coreMetrics?.memory_usage - )}/${bytesToString(this._coreMetrics?.memory_limit)}`; const metrics = [ { description: "Core CPU Usage", @@ -55,7 +47,9 @@ class HassioSystemMetrics extends LitElement { { description: "Core RAM Usage", value: this._coreMetrics?.memory_percent, - tooltip: coreRamTip, + tooltip: `${bytesToString( + this._coreMetrics?.memory_usage + )}/${bytesToString(this._coreMetrics?.memory_limit)}`, }, { description: "Supervisor CPU Usage", @@ -67,8 +61,10 @@ class HassioSystemMetrics extends LitElement { }, { description: "Used Space", - value: usedSpace, - tooltip: usedSpaceTip, + value: this._getUsedSpace(this.hostInfo), + tooltip: `${ + this.hostInfo.disk_used + } GB/${this.hostInfo.disk_total} GB`, }, ]; From 3a16f5af6e070eb5640622be8e26255fcc3c1dd4 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:26:51 -0400 Subject: [PATCH 21/26] Add supervisor ram usage tip --- hassio/src/system/hassio-system-metrics.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 471809e8612a..29b7140397e0 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -58,6 +58,9 @@ class HassioSystemMetrics extends LitElement { { description: "Supervisor RAM Usage", value: this._supervisorMetrics?.memory_percent, + tooltip: `${bytesToString( + this._supervisorMetrics?.memory_usage + )}/${bytesToString(this._supervisorMetrics?.memory_limit)}`, }, { description: "Used Space", From 7ab5640856699f14657bbb1f64d220ec5661d4c4 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 10:29:30 -0400 Subject: [PATCH 22/26] Remove unneeded undefined fallback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joakim Sørensen --- hassio/src/system/hassio-system-metrics.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 29b7140397e0..f341a869ed75 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -78,7 +78,7 @@ class HassioSystemMetrics extends LitElement { this._renderMetric( metric.description, metric.value ?? 0, - metric.tooltip ?? undefined + metric.tooltip ) )}
From 80efdac692b5390f0c3a6abe2097793979d510e2 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 12:09:37 -0400 Subject: [PATCH 23/26] Create bytes-to-string.ts --- src/util/bytes-to-string.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/util/bytes-to-string.ts diff --git a/src/util/bytes-to-string.ts b/src/util/bytes-to-string.ts new file mode 100644 index 000000000000..72829b15daa3 --- /dev/null +++ b/src/util/bytes-to-string.ts @@ -0,0 +1,10 @@ +export const bytesToString = (value = 0, decimals = 2): string => { + if (value === 0) { + return '0 Bytes'; + } + const k = 1024; + decimals = decimals < 0 ? 0 : decimals; + const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(value) / Math.log(k)); + return `${parseFloat((value / k ** i).toFixed(decimals))} ${sizes[i]}`; +} From 0107ed401655f6eda18792e978bb5b3b211600a5 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 12:12:53 -0400 Subject: [PATCH 24/26] Import bytesToString from new file --- hassio/src/system/hassio-system-metrics.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index f341a869ed75..362bd6c2e60f 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -26,6 +26,7 @@ import { roundWithOneDecimal, bytesToString, } from "../../../src/util/calculate"; +import { bytesToString } from "../../../src/util/bytes-to-string"; import { hassioStyle } from "../resources/hassio-style"; @customElement("hassio-system-metrics") From fe8d0c62b6744a9ad8a5886733689ccc9d4ae3e6 Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 12:13:18 -0400 Subject: [PATCH 25/26] Remove bytesToString --- src/util/calculate.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/util/calculate.ts b/src/util/calculate.ts index cb34362a3182..b6a1add005dc 100644 --- a/src/util/calculate.ts +++ b/src/util/calculate.ts @@ -21,12 +21,3 @@ export const getValueInPercentage = ( export const roundWithOneDecimal = (value: number): number => { return Math.round(value * 10) / 10; }; - -export const bytesToString = (value = 0, decimals = 2): string => { - if (value === 0) return '0 Bytes'; - const k = 1024; - decimals = decimals < 0 ? 0 : decimals; - const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; - const i = Math.floor(Math.log(value) / Math.log(k)); - return `${parseFloat((value / k ** i).toFixed(decimals))} ${sizes[i]}`; -} From a24877b9d34c677429f2764384bac171f6798d5a Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Thu, 8 Oct 2020 12:17:57 -0400 Subject: [PATCH 26/26] Remove old import --- hassio/src/system/hassio-system-metrics.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/hassio/src/system/hassio-system-metrics.ts b/hassio/src/system/hassio-system-metrics.ts index 362bd6c2e60f..b3cafdbd27ad 100644 --- a/hassio/src/system/hassio-system-metrics.ts +++ b/hassio/src/system/hassio-system-metrics.ts @@ -24,7 +24,6 @@ import { HomeAssistant } from "../../../src/types"; import { getValueInPercentage, roundWithOneDecimal, - bytesToString, } from "../../../src/util/calculate"; import { bytesToString } from "../../../src/util/bytes-to-string"; import { hassioStyle } from "../resources/hassio-style";