mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-22 17:36:15 +00:00
code clean
This commit is contained in:
+1
-3
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import traceback
|
||||
from urllib import request
|
||||
@@ -105,14 +104,13 @@ def firstLaunchConfig(package_name, client_email, client_password, country_code,
|
||||
msg += res2.text
|
||||
except:
|
||||
pass
|
||||
logging.error(msg)
|
||||
logger.error(msg)
|
||||
Exception(msg)
|
||||
|
||||
# Psacc
|
||||
psacc = MyPSACC(None, client_id, client_secret, REMOTE_REFRESH_TOKEN, customer_id, BRAND[package_name]["realm"],
|
||||
country_code)
|
||||
psacc.connect(client_email, client_password)
|
||||
|
||||
psacc.save_config(name=config_prefix + "config.json")
|
||||
res = psacc.get_vehicles()
|
||||
print(f"\nYour vehicles: {res}")
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
echo "Containerised psa_car_controller loading..."
|
||||
cd $PSACC_CONFIG_DIR
|
||||
python3 /psa_car_controller/server.py -p $PSACC_PORT -l 0.0.0.0 -b $PSACC_BASE_PATH $PSACC_OPTIONS
|
||||
cd "$PSACC_CONFIG_DIR"
|
||||
python3 /psa_car_controller/server.py -p "$PSACC_PORT" -l 0.0.0.0 -b "$PSACC_BASE_PATH" "$PSACC_OPTIONS"
|
||||
|
||||
+3
-6
@@ -37,7 +37,7 @@ def openTab(driver, n):
|
||||
|
||||
def getDriver():
|
||||
chrome_options = Options()
|
||||
if not os.environ.get("NO_HEADLESS", "0") == "1":
|
||||
if os.environ.get("NO_HEADLESS", "0") != "1":
|
||||
chrome_options.add_argument("--headless")
|
||||
driver = webdriver.Chrome(options=chrome_options)
|
||||
driver.implicitly_wait(10)
|
||||
@@ -79,9 +79,6 @@ class ServerThread(threading.Thread):
|
||||
|
||||
|
||||
class FrontTest(unittest.TestCase):
|
||||
def __init__(self, methodName='runTest'):
|
||||
super().__init__(methodName)
|
||||
|
||||
def test_trips_only(self):
|
||||
get_new_test_db()
|
||||
driver = getDriver()
|
||||
@@ -103,8 +100,8 @@ class FrontTest(unittest.TestCase):
|
||||
record_charging()
|
||||
flask_app.start()
|
||||
wait_for_start(driver, URL)
|
||||
assert "-" != driver.find_element_by_id("avg_emission_kw")
|
||||
assert "18.6" == driver.find_element_by_id("avg_chg_speed").text
|
||||
assert driver.find_element_by_id("avg_emission_kw") != "-"
|
||||
assert driver.find_element_by_id("avg_chg_speed").text == "18.6"
|
||||
openTab(driver, 2)
|
||||
assert "18.86 kWh" in driver.find_element_by_id("battery-table").text
|
||||
flask_app.stop()
|
||||
|
||||
+7
-3
@@ -21,26 +21,30 @@ date4 = date3 + timedelta(minutes=1)
|
||||
vehicule_list = Cars()
|
||||
vehicule_list.extend(
|
||||
[Car("VR3UHZKX", "vid", "Peugeot"), Car("VXXXXX", "XXXX", "Peugeot", label="SUV 3008")])
|
||||
car=vehicule_list[0]
|
||||
car = vehicule_list[0]
|
||||
DB_DIR = DATA_DIR + "tmp.db"
|
||||
|
||||
|
||||
def get_new_test_db():
|
||||
try:
|
||||
os.remove(DATA_DIR + "tmp.db")
|
||||
except:
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
Database.DEFAULT_DB_FILE = DB_DIR
|
||||
Database.db_initialized = False
|
||||
conn = Database.get_db()
|
||||
return conn
|
||||
|
||||
|
||||
def record_position():
|
||||
Database.record_position(None, car.vin, 11, latitude, longitude - 0.05, None, date0, 40, None, False)
|
||||
Database.record_position(None, car.vin, 20, latitude, longitude, 32, date1, 35, None, False)
|
||||
Database.record_position(None, car.vin, 30, latitude, longitude, 42, date2, 30, None, False)
|
||||
|
||||
|
||||
def record_charging():
|
||||
Charging.record_charging(car, "InProgress", date0, 50, latitude, longitude, "FR", "slow", 20, 60)
|
||||
Charging.record_charging(car, "InProgress", date1, 75, latitude, longitude, "FR", "slow", 20, 60)
|
||||
Charging.record_charging(car, "InProgress", date2, 85, latitude, longitude, "FR", "slow", 20, 60)
|
||||
Charging.record_charging(car, "InProgress", date3, 90, latitude, longitude, "FR", "slow", 20, 60)
|
||||
Charging.record_charging(car, "Stopped", date4, 91, latitude, longitude, "FR", "slow", 20, 60)
|
||||
Charging.record_charging(car, "Stopped", date4, 91, latitude, longitude, "FR", "slow", 20, 60)
|
||||
|
||||
Reference in New Issue
Block a user