Skip to content
Merged
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
133 changes: 71 additions & 62 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -788,55 +788,65 @@ export const getters = {
* Return available temperature probes / sensors.
*/
getSensors: (state, getters): Sensor[] => {
const nonCriticalDisconnectedMcusSet: Set<string> = getters.getNonCriticalDisconnectedMcusSet

const sensors = Object.keys(state.printer)
.filter(key => (
const keyGroups = [
(key: string) => (
key.startsWith('temperature_sensor ') ||
key.startsWith('temperature_probe ') ||
key.startsWith('tmc2240 ') ||
key === 'z_thermal_adjust'
))
.reduce<Record<string, Sensor>>((groups, key) => {
const [type, ...restSplit] = key.trim().split(/\s+/)
const nameFromSplit = restSplit.pop()
const name = nameFromSplit || key
key.startsWith('temperature_probe ')
),
Comment thread
pedrolamas marked this conversation as resolved.
(key: string) => key.startsWith('tmc2240 '),
(key: string) => key === 'z_thermal_adjust'
]
const nonCriticalDisconnectedMcusSet: Set<string> = getters.getNonCriticalDisconnectedMcusSet

if (!name.startsWith('_')) {
const prettyName = type === 'tmc2240'
? i18n.t('app.general.label.stepper_driver',
{
name:
name.startsWith('stepper_')
? name.substring(8).toUpperCase()
: Vue.$filters.prettyCase(name)
}).toString()
: Vue.$filters.prettyCase(name)
const color = Vue.$colorset.next(getKlipperType(key), key)
const config = state.printer.configfile.settings[key.toLowerCase()]

const disconnected = configHasDisconnectedMcu(config, nonCriticalDisconnectedMcusSet)

groups[name] = {
...state.printer[key],
...getters.getExtraSensorData(config && 'sensor_type' in config && config.sensor_type?.toLowerCase(), name),
config: { ...config },
minTemp: config && 'min_temp' in config ? config.min_temp ?? null : null,
maxTemp: config && 'max_temp' in config ? config.max_temp ?? null : null,
name,
key,
prettyName,
color,
type,
disconnected
}
}
const printerKeys = Object.keys(state.printer)

return groups
}, {})
const sensors = keyGroups
.flatMap(keyCheck => {
const sensors = printerKeys
.filter(keyCheck)
Comment thread
pedrolamas marked this conversation as resolved.
.reduce<Record<string, Sensor>>((groups, key) => {
const [type, ...restSplit] = key.trim().split(/\s+/)
const nameFromSplit = restSplit.pop()
const name = nameFromSplit || key

if (!name.startsWith('_')) {
const prettyName = type === 'tmc2240'
? i18n.t('app.general.label.stepper_driver',
{
name:
name.startsWith('stepper_')
? name.substring(8).toUpperCase()
: Vue.$filters.prettyCase(name)
}).toString()
: Vue.$filters.prettyCase(name)
const color = Vue.$colorset.next(getKlipperType(key), key)
const config = state.printer.configfile.settings[key.toLowerCase()]

const disconnected = configHasDisconnectedMcu(config, nonCriticalDisconnectedMcusSet)

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

return groups
}, {})

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

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

getExtraSensorData: (state) => (sensorType: string, name: string) => {
Expand Down Expand Up @@ -876,29 +886,28 @@ export const getters = {
*/
getChartableSensors: (state) => {
const keyGroups = [
[
'temperature_fan'
],
[
'temperature_probe',
'z_thermal_adjust',
'temperature_sensor'
],
[
'tmc2240'
]
(key: string) => key.startsWith('temperature_fan '),
(key: string) => (
key.startsWith('temperature_sensor ') ||
key.startsWith('temperature_probe ')
),
(key: string) => key.startsWith('tmc2240 '),
(key: string) => key === 'z_thermal_adjust'
]

const printerKeys = Object.keys(state.printer)

const sensors = keyGroups
.flatMap(keyGroup => {
const keyGroupRegExpArray = keyGroup
.map(x => new RegExp(`^${x}(?! _)`))

.flatMap(keyCheck => {
return printerKeys
.filter(key => keyGroupRegExpArray.some(x => x.test(key)))
.sort((a, b) => a.localeCompare(b))
.filter(keyCheck)
.map(key => ({
key,
name: key.trim().split(/\s+/).pop() || ''
}))
.filter(entry => !entry.name.startsWith('_'))
.sort((a, b) => a.name.localeCompare(b.name))
.map(entry => entry.key)
})

const heaters = [...state.printer.heaters?.available_heaters ?? []]
Expand Down