Skip to content

Commit 95f26a3

Browse files
authored
fix(Thermals): sensor sort order anomalies (#1868)
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
1 parent 85fee0a commit 95f26a3

1 file changed

Lines changed: 71 additions & 62 deletions

File tree

src/store/printer/getters.ts

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -788,55 +788,65 @@ export const getters = {
788788
* Return available temperature probes / sensors.
789789
*/
790790
getSensors: (state, getters): Sensor[] => {
791-
const nonCriticalDisconnectedMcusSet: Set<string> = getters.getNonCriticalDisconnectedMcusSet
792-
793-
const sensors = Object.keys(state.printer)
794-
.filter(key => (
791+
const keyGroups = [
792+
(key: string) => (
795793
key.startsWith('temperature_sensor ') ||
796-
key.startsWith('temperature_probe ') ||
797-
key.startsWith('tmc2240 ') ||
798-
key === 'z_thermal_adjust'
799-
))
800-
.reduce<Record<string, Sensor>>((groups, key) => {
801-
const [type, ...restSplit] = key.trim().split(/\s+/)
802-
const nameFromSplit = restSplit.pop()
803-
const name = nameFromSplit || key
794+
key.startsWith('temperature_probe ')
795+
),
796+
(key: string) => key.startsWith('tmc2240 '),
797+
(key: string) => key === 'z_thermal_adjust'
798+
]
799+
const nonCriticalDisconnectedMcusSet: Set<string> = getters.getNonCriticalDisconnectedMcusSet
804800

805-
if (!name.startsWith('_')) {
806-
const prettyName = type === 'tmc2240'
807-
? i18n.t('app.general.label.stepper_driver',
808-
{
809-
name:
810-
name.startsWith('stepper_')
811-
? name.substring(8).toUpperCase()
812-
: Vue.$filters.prettyCase(name)
813-
}).toString()
814-
: Vue.$filters.prettyCase(name)
815-
const color = Vue.$colorset.next(getKlipperType(key), key)
816-
const config = state.printer.configfile.settings[key.toLowerCase()]
817-
818-
const disconnected = configHasDisconnectedMcu(config, nonCriticalDisconnectedMcusSet)
819-
820-
groups[name] = {
821-
...state.printer[key],
822-
...getters.getExtraSensorData(config && 'sensor_type' in config && config.sensor_type?.toLowerCase(), name),
823-
config: { ...config },
824-
minTemp: config && 'min_temp' in config ? config.min_temp ?? null : null,
825-
maxTemp: config && 'max_temp' in config ? config.max_temp ?? null : null,
826-
name,
827-
key,
828-
prettyName,
829-
color,
830-
type,
831-
disconnected
832-
}
833-
}
801+
const printerKeys = Object.keys(state.printer)
834802

835-
return groups
836-
}, {})
803+
const sensors = keyGroups
804+
.flatMap(keyCheck => {
805+
const sensors = printerKeys
806+
.filter(keyCheck)
807+
.reduce<Record<string, Sensor>>((groups, key) => {
808+
const [type, ...restSplit] = key.trim().split(/\s+/)
809+
const nameFromSplit = restSplit.pop()
810+
const name = nameFromSplit || key
811+
812+
if (!name.startsWith('_')) {
813+
const prettyName = type === 'tmc2240'
814+
? i18n.t('app.general.label.stepper_driver',
815+
{
816+
name:
817+
name.startsWith('stepper_')
818+
? name.substring(8).toUpperCase()
819+
: Vue.$filters.prettyCase(name)
820+
}).toString()
821+
: Vue.$filters.prettyCase(name)
822+
const color = Vue.$colorset.next(getKlipperType(key), key)
823+
const config = state.printer.configfile.settings[key.toLowerCase()]
824+
825+
const disconnected = configHasDisconnectedMcu(config, nonCriticalDisconnectedMcusSet)
826+
827+
groups[name] = {
828+
...state.printer[key],
829+
...getters.getExtraSensorData(config && 'sensor_type' in config && config.sensor_type?.toLowerCase(), name),
830+
config: { ...config },
831+
minTemp: config && 'min_temp' in config ? config.min_temp ?? null : null,
832+
maxTemp: config && 'max_temp' in config ? config.max_temp ?? null : null,
833+
name,
834+
key,
835+
prettyName,
836+
color,
837+
type,
838+
disconnected
839+
}
840+
}
841+
842+
return groups
843+
}, {})
844+
845+
return Object.values(sensors)
846+
.sort((a, b) => a.name.localeCompare(b.name))
847+
})
837848

838-
return Object.values(sensors)
839-
.sort((a, b) => a.type.localeCompare(b.type) || a.name.localeCompare(b.name))
849+
return sensors
840850
},
841851

842852
getExtraSensorData: (state) => (sensorType: string, name: string) => {
@@ -876,29 +886,28 @@ export const getters = {
876886
*/
877887
getChartableSensors: (state) => {
878888
const keyGroups = [
879-
[
880-
'temperature_fan'
881-
],
882-
[
883-
'temperature_probe',
884-
'z_thermal_adjust',
885-
'temperature_sensor'
886-
],
887-
[
888-
'tmc2240'
889-
]
889+
(key: string) => key.startsWith('temperature_fan '),
890+
(key: string) => (
891+
key.startsWith('temperature_sensor ') ||
892+
key.startsWith('temperature_probe ')
893+
),
894+
(key: string) => key.startsWith('tmc2240 '),
895+
(key: string) => key === 'z_thermal_adjust'
890896
]
891897

892898
const printerKeys = Object.keys(state.printer)
893899

894900
const sensors = keyGroups
895-
.flatMap(keyGroup => {
896-
const keyGroupRegExpArray = keyGroup
897-
.map(x => new RegExp(`^${x}(?! _)`))
898-
901+
.flatMap(keyCheck => {
899902
return printerKeys
900-
.filter(key => keyGroupRegExpArray.some(x => x.test(key)))
901-
.sort((a, b) => a.localeCompare(b))
903+
.filter(keyCheck)
904+
.map(key => ({
905+
key,
906+
name: key.trim().split(/\s+/).pop() || ''
907+
}))
908+
.filter(entry => !entry.name.startsWith('_'))
909+
.sort((a, b) => a.name.localeCompare(b.name))
910+
.map(entry => entry.key)
902911
})
903912

904913
const heaters = [...state.printer.heaters?.available_heaters ?? []]

0 commit comments

Comments
 (0)