import { selectSpecificEntityState } from './index';

export const selectSensorState = state => selectSpecificEntityState(state, 'sensor');

export const selectSensorsById = state => {
  const sensorState = selectSensorState(state);
  const { byId } = sensorState;
  return byId;
};

export const selectSensorByMac = (state, mac) => {
  const sensorsById = selectSensorsById(state);
  const foundSensor = Object.values(sensorsById).find(({ macAddress }) => macAddress === mac);
  return foundSensor;
};

export const selectNewSensor = state => {
  const sensorState = selectSensorState(state);
  const { newId, byId } = sensorState;
  return byId[newId];
};

export const selectEditingSensor = state => {
  const sensorState = selectSensorState(state);
  const { editingId, byId } = sensorState;
  return byId[editingId];
};

export const selectNewSensorId = state => {
  const sensorState = selectSensorState(state);
  const { newId } = sensorState;

  return newId;
};

export const selectSensors = state => {
  const sensorsById = selectSensorsById(state);
  return Object.values(sensorsById);
};

@@ -1,8 +1,84 @@
+import %7B VACCINE_CONSTANTS %7D from '../../utilities/modules/vaccines/index';%0A
 import %7B
@@ -1165,12 +1165,979 @@
 rsById);%0A%7D;%0A
+%0Aexport const selectIsLowBatteryByMac = (state, mac) =%3E %7B%0A  const sensor = selectSensorByMac(state, mac);%0A  const %7B batteryLevel %7D = sensor;%0A  return batteryLevel %3C= VACCINE_CONSTANTS.LOW_BATTERY_PERCENTAGE;%0A%7D;%0A%0Aexport const selectIsInHotBreachByMac = (state, mac) =%3E %7B%0A  const sensor = selectSensorByMac(state, mac);%0A  const %7B isInHotBreach %7D = sensor;%0A  return isInHotBreach;%0A%7D;%0A%0Aexport const selectIsInColdBreachByMac = (state, mac) =%3E %7B%0A  const sensor = selectSensorByMac(state, mac);%0A  const %7B isInColdBreach %7D = sensor;%0A  return isInColdBreach;%0A%7D;%0A%0Aexport const selectIsInBreachByMac = (state, mac) =%3E %7B%0A  const sensor = selectSensorByMac(state, mac);%0A  const %7B isInHotBreach, isInColdBreach %7D = sensor;%0A  return isInHotBreach %7C%7C isInColdBreach;%0A%7D;%0A%0Aexport const selectIsInDangerByMac = (state, mac) =%3E %7B%0A  const isLowBattery = selectIsLowBatteryByMac(state, mac);%0A  const isInBreach = selectIsInBreachByMac(state, mac);%0A  return isLowBattery %7C%7C isInBreach;%0A%7D;%0A

Add selectors