# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


import sys
import serial
import binascii
import logger
from time import localtime
from config import config
log = logger.logging.getLogger(__name__)
log.setLevel(logger.logging.INFO)
log.addHandler(logger.alarmfile)


class Alarms:
  # Initialise and compile alarms
  def __init__(self,batdata,summary):
    self.summary=summary
    self.alarmtriggered={}
    for i in config['alarms']:
      self.alarmtriggered[i]=False
      exec(config['alarms'][i][0])
      log.info('alarm {} initialised'.format(i))
#     config['alarms'][i][1] = compile(config['alarms'][i][1], '<string>', 'exec')
#      config['alarms'][i][2] = compile(config['alarms'][i][2], '<string>', 'exec')
#      config['alarms'][i][3] = compile(config['alarms'][i][3], '<string>', 'exec')
#      config['alarms'][i][4] = compile(config['alarms'][i][4], '<string>', 'exec')

  def scanalarms(self,batdata):
#    self.timedate = localtime()
#    print (self.timedate.tm_hour)
    for i in config['alarms']:
      if not self.alarmtriggered[i]:
        exec(config['alarms'][i][1])
  #      log.debug('{}{}{}'.format(self.test,batdata.maxcellv,batdata.lastmaxcellv))
        if self.test:
    #            sys.stderr.write('Alarm 1 triggered')
          log.info('alarm {} triggered'.format(i))
          self.alarmtriggered[i]=True

# Path: config.py
# def editbatconfig(section,item,itemvalue):
# def loadconfig():


# Path: alarms.py
import sys
import serial
import binascii
import logger
from time import localtime
from config import config

log = logger.logging.getLogger(__name__)
log.setLevel(logger.logging.INFO)
log.addHandler(logger.alarmfile)


class Alarms:
  # Initialise and compile alarms
  def __init__(self,batdata,summary):
    self.summary=summary
    self.alarmtriggered={}
    for i in config['alarms']:
      self.alarmtriggered[i]=False
      exec(config['alarms'][i][0])
      log.info('alarm {} initialised'.format(i))
#     config['alarms'][i][1] = compile(config['alarms'][i][1], '<string>', 'exec')
#      config['alarms'][i][2] = compile(config['alarms'][i][2], '<string>', 'exec')
#      config['alarms'][i][3] = compile(config['alarms'][i][3], '<string>', 'exec')
#      config['alarms'][i][4] = compile(config['alarms'][i][4], '<string>', 'exec')

  def scanalarms(self,batdata):
#    self.timedate = localtime()
#    print (self.timedate.tm_hour)
    for i in config['alarms']:
      if not self.alarmtriggered[i]:
        exec(config['alarms'][i][1])
  #      log.debug('{}{}{}'.format(self.test,batdata.maxcellv,batdata.lastmaxcellv))
        if self.test:
    #            sys.stderr.write('Alarm 1 triggered')
          log.info('alarm {} triggered'.format(i))
          self.alarmtriggered[i]=True

          exec(config['alarms'][i][2])