mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-26 10:17:18 +00:00
Feature abrp (#79)
* add ABRP connection * update doc * fix get_last_temp() * add image * update abrp * fix abrpname * fix no last postition * add type point * find model by vin * add Spacetourer * fix indent
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import re
|
||||
|
||||
from MyLogger import logger
|
||||
|
||||
DEFAULT_BATTERY_POWER = 46
|
||||
DEFAULT_FUEL_CAPACITY = 0
|
||||
DEFAULT_MAX_ELEC_CONSUMPTION = 70
|
||||
DEFAULT_MAX_FUEL_CONSUMPTION = 30
|
||||
|
||||
|
||||
class CarModel:
|
||||
def __init__(self, name, battery_power, fuel_capacity, abrp_name=None, reg=None,
|
||||
max_elec_consumption=DEFAULT_MAX_ELEC_CONSUMPTION, max_fuel_consumption=DEFAULT_MAX_FUEL_CONSUMPTION):
|
||||
self.name = name
|
||||
self.battery_power = battery_power
|
||||
self.fuel_capacity = fuel_capacity
|
||||
self.abrp_name = abrp_name
|
||||
self.reg = reg
|
||||
self.max_elec_consumption = max_elec_consumption
|
||||
self.max_fuel_consumption = max_fuel_consumption
|
||||
|
||||
def match(self, vin):
|
||||
return re.match(self.reg, vin) is not None
|
||||
|
||||
@staticmethod
|
||||
def find_model_by_vin(vin):
|
||||
for carmodel in carmodels:
|
||||
if carmodel.match(vin):
|
||||
return carmodel
|
||||
logger.warning("Can't get car model, please report an issue on github with your car model"
|
||||
" and first ten letter of your VIN")
|
||||
return CarModel("unknown", DEFAULT_BATTERY_POWER, DEFAULT_FUEL_CAPACITY)
|
||||
|
||||
@staticmethod
|
||||
def find_model_by_name(name):
|
||||
for carmodel in carmodels:
|
||||
if carmodel.name == name:
|
||||
return carmodel
|
||||
return None
|
||||
|
||||
|
||||
class ElecModel(CarModel):
|
||||
def __init__(self, name, battery_power, abrp_name=None, reg=None,
|
||||
max_elec_consumption=DEFAULT_MAX_ELEC_CONSUMPTION):
|
||||
super().__init__(name, battery_power, 0, abrp_name, reg, max_elec_consumption, 0)
|
||||
|
||||
|
||||
carmodels = [
|
||||
ElecModel("e-208", 46, "peugeot:e208:20:50", r"VR3UHZKX.*"),
|
||||
ElecModel("e-2008", 46, "peugeot:e2008:20:48", r"VR3UKZKX.*"),
|
||||
ElecModel("e-Spacetourer", 46, "peugeot:etraveler:21:50:citroen", r"VF7VZZKX.*"),
|
||||
ElecModel("corsa-e", 46, "opel:corsae:20:50", r"VXKUHZKX.*"),
|
||||
CarModel("SUV 3008", 10.8, 43),
|
||||
CarModel("C5 Aircross", 10.8, 43)
|
||||
]
|
||||
@@ -0,0 +1,37 @@
|
||||
from MyLogger import logger
|
||||
from psa_connectedcar import Position, Geometry, PositionProperties, Kinetic, Energy, EnergyCharging, Status
|
||||
|
||||
|
||||
class CarStatus(Status):
|
||||
def __init__(self, embedded=None, links=None, battery=None, doors_state=None, energy=None, environment=None,
|
||||
ignition=None, kinetic=None, last_position=None, preconditionning=None, privacy=None, safety=None,
|
||||
service=None, timed_odometer=None): # noqa: E501
|
||||
super().__init__(embedded, links, battery, doors_state, energy, environment, ignition, kinetic, last_position,
|
||||
preconditionning, privacy, safety, service, timed_odometer)
|
||||
self.correct()
|
||||
|
||||
def correct(self):
|
||||
try:
|
||||
if len(self.last_position.geometry.coordinates) < 2:
|
||||
raise AttributeError()
|
||||
if len(self.last_position.geometry.coordinates) < 3:
|
||||
# set altitude none
|
||||
self.last_position.geometry.coordinates.append(None)
|
||||
except AttributeError:
|
||||
self.last_position = Position(geometry=Geometry(coordinates=[None, None, None], type="Point"),
|
||||
properties=PositionProperties(updated_at=None))
|
||||
if self.kinetic is None:
|
||||
self.kinetic = Kinetic()
|
||||
|
||||
def is_moving(self):
|
||||
try:
|
||||
return self.kinetic.moving
|
||||
except AttributeError:
|
||||
logger.error("kinetic not available from api")
|
||||
return None
|
||||
|
||||
def get_energy(self, energy_type) -> Energy:
|
||||
for energy in self._energy:
|
||||
if energy.type == energy_type:
|
||||
return energy
|
||||
return Energy(charging=EnergyCharging())
|
||||
Reference in New Issue
Block a user