Skip to content

Commit

Permalink
fix: include extra sensor data on temperature_fan (#1067)
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <[email protected]>
  • Loading branch information
pedrolamas authored Mar 14, 2023
1 parent 5c11f0d commit e39d835
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/components/widgets/thermals/TemperatureTargets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<td class="temp-actual">
<span v-if="item.temperature">
{{ item.temperature.toFixed(1) }}<small>°C</small>
<small v-if="item.humidity && showRelativeHumidity"><br>{{ item.humidity.toFixed(1) }}&nbsp;%</small>
<small v-if="item.pressure && showBarometricPressure"><br>{{ item.pressure.toFixed(1) }}&nbsp;hpa</small>
<small v-if="item.gas && showGasResistance"><br>{{ item.gas.toFixed(1) }}&nbsp;&ohm;</small>
</span>
</td>
<td>/</td>
Expand Down
80 changes: 45 additions & 35 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ export const getters: GetterTree<PrinterState, RootState> = {

for (const pin in state.printer) {
const split = pin.split(' ')
const type = split[0]
const name = (split.length > 1) ? split[1] : pin
const type = (split.length) ? split[0] : pin

if (
supportedTypes.includes(type) &&
Expand All @@ -543,6 +543,7 @@ export const getters: GetterTree<PrinterState, RootState> = {

let output: Fan | Led | OutputPin = {
...state.printer[pin],
...getters.getExtraSensorData(config?.sensor_type?.toLowerCase(), name),
config: { ...config },
name,
prettyName,
Expand Down Expand Up @@ -585,49 +586,58 @@ export const getters: GetterTree<PrinterState, RootState> = {
'temperature_probe',
'z_thermal_adjust'
]
const extraSupportedSensors = [

const sensors = Object.keys(state.printer)
.reduce((groups, item) => {
const split = item.split(' ')
const type = split[0]
const name = (split.length > 1) ? split[1] : item

if (supportedSensors.includes(type)) {
const prettyName = Vue.$filters.startCase(name)
const color = Vue.$colorset.next(getKlipperType(item), item)
const config = getters.getPrinterSettings(item)

groups[name] = {
...state.printer[item],
...getters.getExtraSensorData(config?.sensor_type?.toLowerCase(), name),
config: { ...config },
minTemp: config?.min_temp ?? null,
maxTemp: config?.max_temp ?? null,
name,
key: item,
prettyName,
color,
type
}
}

return groups
}, {} as Record<string, Sensor>)

return Object.values(sensors)
.sort((a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name))
},

getExtraSensorData: (state) => (sensorType: string, name: string) => {
const supportedSensors = [
'bme280',
'htu21d'
]

const sensors = Object.keys(state.printer).reduce((groups, item) => {
const split = item.split(' ')
const type = split[0]
const name = (split.length > 1) ? split[1] : item

if (supportedSensors.includes(type)) {
const prettyName = Vue.$filters.startCase(name)
const color = Vue.$colorset.next(getKlipperType(item), item)
const config = getters.getPrinterSettings(item)

groups[name] = {
...groups[name],
...state.printer[item],
...config,
minTemp: config?.min_temp ?? null,
maxTemp: config?.max_temp ?? null,
name,
key: item,
prettyName,
color,
type
}
} else if (extraSupportedSensors.includes(type)) {
const { pressure, humidity, gas } = state.printer[item]
if (supportedSensors.includes(sensorType)) {
const sensor = state.printer[`${sensorType} ${name}`]

if (sensor) {
const { pressure, humidity, gas } = sensor

groups[name] = {
return {
pressure,
humidity,
gas,
...groups[name]
gas
}
}

return groups
}, {} as Record<string, Sensor>)

return Object.values(sensors)
.sort((a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name))
}
},

/**
Expand Down

0 comments on commit e39d835

Please sign in to comment.