diff --git a/src/pbHelpers/DeviceState.tsx b/src/pbHelpers/DeviceState.tsx index e57b803..5fe498a 100644 --- a/src/pbHelpers/DeviceState.tsx +++ b/src/pbHelpers/DeviceState.tsx @@ -44,18 +44,29 @@ const DEVICE_STATE_MAP = new Map([ [pond.DeviceState.DEVICE_STATE_MISSING, Missing] ]); -export function compareEnum(value: string | number, enumMember: T): boolean { - // Get the enum object from the enum member - const enumObj = Object.freeze(enumMember as any).constructor; - - // Check if the value matches either the key or the value of the enum member - return Object.keys(enumObj).some( - key => enumObj[key] === value || key === value - ); +export function compareEnum(value: T[keyof T], e: T, enumMember: T[keyof T]): boolean { + // let has = false + // if (typeof value === 'string') { + // Object.values(e).forEach((val: keyof T) => { + if (e[value as keyof T] === enumMember) { + // has = true + return true + } + return false + // }) + // } else if (typeof value === 'number') { + // Object.keys(e as any).forEach(val => { + // if (val === enumMember) { + // has = true + // return + // } + // }) + // } + // return has } export function getDeviceStateHelper(state: pond.DeviceState): DeviceStateHelper { - if (compareEnum(state, pond.DeviceState.DEVICE_STATE_OK)) { + if (compareEnum(state, pond.DeviceState, pond.DeviceState.DEVICE_STATE_OK)) { return OK; } const deviceStates = Array.from(DEVICE_STATE_MAP.keys());