From c44978c246acc6aac30dd8ff6082cc3886a2d604 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 11 Nov 2024 20:44:56 +0100 Subject: [PATCH 1/2] fix: fix units and number formats for addition sensors Signed-off-by: Stefan Dej --- ...turePanelListItemAdditionalSensorValue.vue | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue index aadc033b1..313c2e835 100644 --- a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue +++ b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue @@ -23,20 +23,32 @@ export default class TemperaturePanelListItemAdditionalSensorValue extends Mixin } get formatValue() { + const output = [] let value = this.value?.toFixed(1) if (this.value === null) value = '--' // get unit - let unit: string | null = null + let unitPrefix: string | null = null + let unitSuffix: string | null = null + + switch (this.keyName) { + case 'gas': + unitPrefix = 'IAQ' + break + case 'voc': + unitPrefix = 'VOC' + break + } + switch (this.keyName) { case 'pressure': - unit = 'hPa' + unitSuffix = 'hPa' break case 'humidity': - unit = '%' + unitSuffix = '%' break case 'current_z_adjust': - unit = 'mm' + unitSuffix = 'mm' break } @@ -47,11 +59,19 @@ export default class TemperaturePanelListItemAdditionalSensorValue extends Mixin // convert z_adjust value if it is smaller than 0.1 to μm if (Math.abs(this.value) < 0.1) { value = Math.round(this.value * 1000).toString() - unit = 'μm' + unitSuffix = 'μm' } } - return unit ? `${value} ${unit}` : value + if (['gas', 'voc'].includes(this.keyName) && this.value) { + value = this.value.toFixed(0) + } + + if (unitPrefix) output.push(`${unitPrefix}:`) + output.push(value) + if (unitSuffix) output.push(unitSuffix) + + return output.join(' ') } get guiSetting() { From 820d4129ed626c046058170a8e2cdc758c6ba0d8 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Thu, 14 Nov 2024 12:30:48 +0100 Subject: [PATCH 2/2] fix: fix units and number formats for additional sensors Signed-off-by: Stefan Dej --- ...mperaturePanelListItemAdditionalSensor.vue | 5 ++++ ...turePanelListItemAdditionalSensorValue.vue | 23 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensor.vue b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensor.vue index 40f1afd7e..fdceb7fd2 100644 --- a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensor.vue +++ b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensor.vue @@ -5,6 +5,7 @@ :key="keyName" :printer-object="printerObject" :object-name="objectName" + :sensor-type="sensorType" :key-name="keyName" /> @@ -30,5 +31,9 @@ export default class TemperaturePanelListItemAdditionalSensor extends Mixins(Bas return Object.keys(this.printerObject).filter((key) => key !== 'temperature') } + + get sensorType() { + return this.additionalObjectName.split(' ')[0] + } } diff --git a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue index 313c2e835..1cf063c98 100644 --- a/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue +++ b/src/components/panels/Temperature/TemperaturePanelListItemAdditionalSensorValue.vue @@ -13,6 +13,7 @@ import BaseMixin from '@/components/mixins/base' export default class TemperaturePanelListItemAdditionalSensorValue extends Mixins(BaseMixin) { @Prop({ type: Object, required: true }) readonly printerObject!: { [key: string]: number } @Prop({ type: String, required: true }) readonly objectName!: string + @Prop({ type: String, required: true }) readonly sensorType!: string @Prop({ type: String, required: true }) readonly keyName!: string get value() { @@ -31,13 +32,16 @@ export default class TemperaturePanelListItemAdditionalSensorValue extends Mixin let unitPrefix: string | null = null let unitSuffix: string | null = null - switch (this.keyName) { - case 'gas': - unitPrefix = 'IAQ' - break - case 'voc': - unitPrefix = 'VOC' - break + if (this.keyName === 'gas') { + switch (this.sensorType) { + case 'sgp40': + unitPrefix = 'VOC' + break + + case 'bme680': + unitPrefix = 'IAQ' + break + } } switch (this.keyName) { @@ -62,10 +66,7 @@ export default class TemperaturePanelListItemAdditionalSensorValue extends Mixin unitSuffix = 'μm' } } - - if (['gas', 'voc'].includes(this.keyName) && this.value) { - value = this.value.toFixed(0) - } + if (this.keyName.startsWith('gas') || this.keyName === 'voc') value = this.value?.toFixed(0) if (unitPrefix) output.push(`${unitPrefix}:`) output.push(value)