mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-24 22:25:16 +02:00
🔀 Merge pull request #1157 from luispabon/sensors
Tweak GlCpuTemp widget to support other sensor units
This commit is contained in:
commit
c8653e525e
@ -2,7 +2,7 @@
|
|||||||
<div class="glances-temp-wrapper" v-if="tempData">
|
<div class="glances-temp-wrapper" v-if="tempData">
|
||||||
<div class="temp-row" v-for="sensor in tempData" :key="sensor.label">
|
<div class="temp-row" v-for="sensor in tempData" :key="sensor.label">
|
||||||
<p class="label">{{ sensor.label | formatLbl }}</p>
|
<p class="label">{{ sensor.label | formatLbl }}</p>
|
||||||
<p :class="`temp range-${sensor.color}`">{{ sensor.value | formatVal }}</p>
|
<p :class="`temp range-${sensor.color}`">{{ sensor.value | formatVal(sensor.sensorType) }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -29,8 +29,15 @@ export default {
|
|||||||
formatLbl(lbl) {
|
formatLbl(lbl) {
|
||||||
return capitalize(lbl);
|
return capitalize(lbl);
|
||||||
},
|
},
|
||||||
formatVal(val) {
|
formatVal(val, sensorType) {
|
||||||
|
switch (sensorType) {
|
||||||
|
case 'rpm':
|
||||||
|
return `${Math.round(val)} rpm`;
|
||||||
|
case 'percentage':
|
||||||
|
return `${Math.round(val)}%`;
|
||||||
|
default:
|
||||||
return `${Math.round(val)}°C`;
|
return `${Math.round(val)}°C`;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@ -40,14 +47,49 @@ export default {
|
|||||||
if (temp >= 75) return 'red';
|
if (temp >= 75) return 'red';
|
||||||
return 'grey';
|
return 'grey';
|
||||||
},
|
},
|
||||||
|
getPercentageColor(percentage) {
|
||||||
|
if (percentage < 20) return 'red';
|
||||||
|
if (percentage < 50) return 'orange';
|
||||||
|
if (percentage < 75) return 'yellow';
|
||||||
|
return 'green';
|
||||||
|
},
|
||||||
processData(sensorData) {
|
processData(sensorData) {
|
||||||
const results = [];
|
const results = [];
|
||||||
sensorData.forEach((sensor) => {
|
sensorData.forEach((sensor) => {
|
||||||
const tempC = sensor.unit === 'F' ? fahrenheitToCelsius(sensor.value) : sensor.value;
|
// Start by assuming the sensor's unit is degrees Celsius
|
||||||
|
let sensorValue = sensor.value;
|
||||||
|
let color = this.getTempColor(sensorValue);
|
||||||
|
let sensorType = 'temperature';
|
||||||
|
|
||||||
|
// Now, override above if sensor unit is actually of a different type
|
||||||
|
switch (sensor.unit) {
|
||||||
|
case 'F':
|
||||||
|
sensorValue = fahrenheitToCelsius(sensorValue);
|
||||||
|
color = fahrenheitToCelsius(sensorValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// R is for RPM and is typically for fans
|
||||||
|
case 'R':
|
||||||
|
color = 'grey';
|
||||||
|
sensorType = 'rpm';
|
||||||
|
break;
|
||||||
|
|
||||||
|
// For instance, battery levels
|
||||||
|
case '%':
|
||||||
|
sensorType = 'percentage';
|
||||||
|
color = this.getPercentageColor(sensorValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Nothing to do here, already covered by default values
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
results.push({
|
results.push({
|
||||||
label: sensor.label,
|
label: sensor.label,
|
||||||
value: tempC,
|
value: sensorValue,
|
||||||
color: this.getTempColor(tempC),
|
color,
|
||||||
|
sensorType,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.tempData = results;
|
this.tempData = results;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user