forked from flobz/psa_car_controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
64 lines (49 loc) · 2.32 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# flake8: noqa
import os
from datetime import timedelta, datetime
from unittest.mock import MagicMock
import pytz
from psa_car_controller.psa.RemoteClient import RemoteClient
from psa_car_controller.psa.connected_car_api import Vehicles
from psa_car_controller.psacc.application.charging import Charging
from psa_car_controller.psacc.model.car import Cars, Car
from psa_car_controller.psacc.repository.db import Database
DATA_DIR = os.path.dirname(os.path.realpath(__file__)) + "/data/"
latitude = 47.2183
longitude = -1.55362
date3 = datetime.utcnow().replace(2021, 3, 1, 12, 00, 00, 00, tzinfo=pytz.UTC)
date2 = date3 - timedelta(minutes=20)
date1 = date3 - timedelta(minutes=40)
date0 = date3 - timedelta(minutes=60)
date4 = date3 + timedelta(minutes=1)
vehicule_list = Cars()
vehicule_list.extend(
[Car("VR3UHZKX", "vid", "Peugeot"), Car("VXXXXX", "XXXX", "Peugeot", label="SUV 3008 Hybrid 225")])
car = vehicule_list[0]
DB_DIR = DATA_DIR + "tmp.db"
def get_new_test_db():
try:
os.remove(DATA_DIR + "tmp.db")
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)
Database.record_position(None, car.vin, None, 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)
def get_date(offset):
return date3 + timedelta(minutes=60 * offset)
def get_rc() -> RemoteClient:
account_info = MagicMock()
account_info.realm = ""
return RemoteClient(account_info, Vehicles, None, None)