-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aiways SoC module #2066
Open
FriedrichF
wants to merge
1
commit into
openWB:master
Choose a base branch
from
FriedrichF:aiways-soc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Aiways SoC module #2066
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import Optional | ||
|
||
""" | ||
The attributes for configuration can be retrieved with this guide: | ||
https://community.home-assistant.io/t/read-aiways-u5-state-of-charge/466441/5 | ||
""" | ||
|
||
|
||
class AiwaysVehicleSocConfiguration: | ||
def __init__(self, user_id: Optional[str] = None, vin: Optional[str] = None, device_id: Optional[str] = None, | ||
register_id: Optional[str] = None, token: Optional[str] = None, | ||
condition_url: Optional[str] = "https://coiapp-api-eu.ai-ways.com:10443/app/vc/getCondition") -> None: | ||
self.user_id = user_id | ||
self.vin = vin | ||
self.device_id = device_id | ||
self.register_id = register_id | ||
self.token = token | ||
self.condition_url = condition_url | ||
|
||
|
||
class AiwaysVehicleSoc: | ||
def __init__(self, | ||
name: str = "Aiways SoC module", | ||
type: str = "aiways", | ||
configuration: AiwaysVehicleSocConfiguration = None) -> None: | ||
self.name = name | ||
self.type = type | ||
self.configuration = configuration or AiwaysVehicleSocConfiguration() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
import logging | ||
|
||
from modules.common import req | ||
from modules.common.abstract_device import DeviceDescriptor | ||
from modules.common.abstract_vehicle import VehicleUpdateData | ||
from modules.common.component_state import CarState | ||
from modules.common.configurable_vehicle import ConfigurableVehicle | ||
from modules.vehicles.aiways.config import AiwaysVehicleSoc | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
language = "de" | ||
version = "1.3.0" | ||
platform = "iOS" | ||
apptimezone = "MEZ" | ||
apptimezoneid = "Europe/Berlin" | ||
content_type = "application/json; charset=utf-8" | ||
accept_encoding = "gzip" | ||
user_agent = "okhttp/4.3.1" | ||
|
||
|
||
def fetch(vehicle_config: AiwaysVehicleSoc, vehicle_update_data: VehicleUpdateData) -> CarState: | ||
response = req.get_http_session().post(vehicle_config.configuration.condition_url, timeout=10, | ||
headers={"language": language, | ||
"registerid": vehicle_config.configuration.register_id, | ||
"deviceid": vehicle_config.configuration.device_id, | ||
"version": version, | ||
"platform": platform, | ||
"token": vehicle_config.configuration.token, | ||
"apptimezone": apptimezone, | ||
"apptimezoneid": apptimezoneid, | ||
"content-type": content_type, | ||
"accept-encoding": accept_encoding, | ||
"user-agent": user_agent}, | ||
json={"userId": vehicle_config.configuration.user_id, | ||
"vin": vehicle_config.configuration.vin}, verify=False) | ||
response.raise_for_status() | ||
json = response.json() | ||
soc = float(json['data']['vc']['soc']) | ||
range = float(json['data']['vc']['drivingRange']) | ||
soc_timestamp = float(json['data']['vc']['dataTimeTS']) | ||
return CarState(soc, range, soc_timestamp) | ||
|
||
|
||
def create_vehicle(vehicle_config: AiwaysVehicleSoc, vehicle: int): | ||
def updater(vehicle_update_data: VehicleUpdateData) -> CarState: | ||
return fetch(vehicle_config, vehicle_update_data) | ||
|
||
return ConfigurableVehicle(vehicle_config=vehicle_config, | ||
component_updater=updater, | ||
vehicle=vehicle, | ||
calc_while_charging=False) | ||
|
||
|
||
device_descriptor = DeviceDescriptor(configuration_factory=AiwaysVehicleSoc) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unser Code ist nach dem Python Style Guide formatiert, dh globale Variablen werden mit GROßBUCHSTABEN benannt. Oder Du setzt die Werte direkt im Header, es wird ja nur einmal auf die Variablen zugegriffen.