def __init__(self, config, car): self.log = logging.getLogger("EVNotiPi/EVNotify") self.log.info("Initializing EVNotify") self.abortNotificationSent = False self.car = car self.chargingStartSOC = 0 self.config = config self.last_charging = time() self.last_charging_soc = 0 self.last_evn_settings_poll = 0 self.notificationSent = False self.poll_interval = config['interval'] self.running = False self.thread = None self.evnotify = evnotifyapi.EVNotify(config['akey'], config['token']) self.data = [] self.gps_data = [] self.data_lock = Condition() self.settings = None self.socThreshold = 100
import json import os import re import string import sys import signal LOOP_DELAY = 11 ABORT_NOTIFICATION_DELAY = 60 # load config with open('config.json', encoding='utf-8') as config_file: config = json.loads(config_file.read()) # load api lib EVNotify = evnotifyapi.EVNotify(config['akey'], config['token']) settings = None if 'cartype' in config: cartype = config['cartype'] else: # get settings from backend while settings == None: try: settings = EVNotify.getSettings() except EVNotify.CommunicationError as e: print("Waiting for network connectivity") sleep(3) cartype = settings['car']