refactor: prepare machine statuses code for new statuses
This commit is contained in:
parent
f7c42992d8
commit
ff3c51623f
1 changed files with 20 additions and 11 deletions
|
|
@ -104,26 +104,35 @@ function getConfig(defaultConfig) {
|
||||||
return defaultConfig ? Promise.resolve(defaultConfig) : loadLatestConfig()
|
return defaultConfig ? Promise.resolve(defaultConfig) : loadLatestConfig()
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStatus = (ping, stuck) => {
|
const getMachineStatuses = (pings, events, machine) => {
|
||||||
if (ping && ping.age) return unresponsiveStatus
|
const lastPing = pings[machine.deviceId][0]
|
||||||
|
if (lastPing?.age) return [unresponsiveStatus]
|
||||||
|
|
||||||
if (stuck && stuck.age) return stuckStatus
|
const machineEvents = events
|
||||||
|
.filter(
|
||||||
|
ev =>
|
||||||
|
ev.device_id === machine.deviceId && ev.event_type === 'stateChange',
|
||||||
|
)
|
||||||
|
.map(ev =>
|
||||||
|
Object.assign({}, ev, {
|
||||||
|
age: Math.floor(ev.age),
|
||||||
|
note: JSON.parse(ev.note),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.sort((e1, e2) => e2.age - e1.age)
|
||||||
|
|
||||||
return fullyFunctionalStatus
|
const stuckScreen = checkStuckScreen(machineEvents, machine)[0]
|
||||||
|
if (stuckScreen?.age) return [stuckStatus]
|
||||||
|
|
||||||
|
return [fullyFunctionalStatus]
|
||||||
}
|
}
|
||||||
|
|
||||||
function addName(pings, events, config) {
|
function addName(pings, events, config) {
|
||||||
return machine => {
|
return machine => {
|
||||||
const cashOutConfig = configManager.getCashOut(machine.deviceId, config)
|
const cashOutConfig = configManager.getCashOut(machine.deviceId, config)
|
||||||
|
|
||||||
const cashOut = !!cashOutConfig.active
|
const cashOut = !!cashOutConfig.active
|
||||||
|
|
||||||
const statuses = [
|
const statuses = getMachineStatuses(pings, events, machine)
|
||||||
getStatus(
|
|
||||||
_.first(pings[machine.deviceId]),
|
|
||||||
_.first(checkStuckScreen(events, machine)),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
||||||
return _.assign(machine, { cashOut, statuses })
|
return _.assign(machine, { cashOut, statuses })
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue