Skip to content

Instantly share code, notes, and snippets.

@izonder
Created January 19, 2021 12:06
Show Gist options
  • Save izonder/fcbeb42badef6f58a9c1a1f57dff970d to your computer and use it in GitHub Desktop.
Save izonder/fcbeb42badef6f58a9c1a1f57dff970d to your computer and use it in GitHub Desktop.
const sparseMap = {
'O2': {
'ExposureAlarm': {
read: () => _.random(9, 19),
isExposureAlarm: () => true
},
'ExposureWarning': {
read: () => _.random(24, 27),
isExposureWarning: () => true
}
},
'COMB': {
'ExposureAlarm': {
read: () => _.random(21, 24),
isExposureAlarm: () => true
},
'ExposureWarning': {
read: () => _.random(14, 18),
isExposureWarning: () => true
}
},
'H2S': {
'ExposureAlarm': {
read: () => _.random(15, 20),
isExposureAlarm: () => true
},
'ExposureWarning': {
read: () => _.random(12, 15),
isExposureWarning: () => true
}
}
},
sparseMapProbe = (gasName, alarmType) => (sparseMap[gasName] || {})[alarmType] || {read: () => 0},
findByName = (statusConfig, gasName) => statusConfig.sensStatus.find((x) => x.name === gasName);
function Handler(statusConfig, gasName, alarmType) {
const probe = sparseMapProbe(gasName, alarmType),
ref = findByName(statusConfig, gasName) || {}; //TODO: make sure the object exists;
Object.keys(probe).forEach((key) => ref[key] = probe[key]());
return statusConfig;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment