Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix units and number formats for additionial sensors #2042

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:key="keyName"
:printer-object="printerObject"
:object-name="objectName"
:sensor-type="sensorType"
:key-name="keyName" />
</div>
</template>
Expand All @@ -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]
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -23,20 +24,35 @@ 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

if (this.keyName === 'gas') {
switch (this.sensorType) {
case 'sgp40':
unitPrefix = 'VOC'
break

case 'bme680':
unitPrefix = 'IAQ'
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
}

Expand All @@ -47,11 +63,16 @@ 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'
}
}
if (this.keyName.startsWith('gas') || this.keyName === 'voc') value = this.value?.toFixed(0)

if (unitPrefix) output.push(`${unitPrefix}:`)
output.push(value)
if (unitSuffix) output.push(unitSuffix)

return unit ? `${value} ${unit}` : value
return output.join(' ')
}

get guiSetting() {
Expand Down
Loading