Skip to content
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

fix: Service Endpoints & Code Cleanup #422

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
820475f
Update audi_account.py
coreywillwhat May 2, 2024
a4b3d6b
Update audi_connect_account.py
coreywillwhat May 2, 2024
430841d
Update audi_services.py
coreywillwhat May 2, 2024
a20b480
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 2, 2024
80afb48
Update audi_services.py
coreywillwhat May 29, 2024
402d1e1
Merge branch 'master' into climate_control_cleanup
coreywillwhat May 29, 2024
6b769c2
Merge branch 'master' into climate_control_cleanup
coreywillwhat Jul 26, 2024
d7bca60
Update const.py
coreywillwhat Jul 26, 2024
37b5ca8
Update audi_api.py
coreywillwhat Jul 26, 2024
88f7f1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
bf3c062
Update audi_account.py
coreywillwhat Jul 26, 2024
75bf35a
Update audi_account.py
coreywillwhat Jul 26, 2024
10ad8ce
Update audi_account.py
coreywillwhat Jul 26, 2024
9f3a6f7
Update audi_services.py
coreywillwhat Jul 26, 2024
6ed572e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
377ed07
Update audi_services.py
coreywillwhat Jul 26, 2024
b14ebf1
Update audi_services.py
coreywillwhat Jul 26, 2024
639b24d
Update audi_services.py
coreywillwhat Jul 26, 2024
675f2a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
17ddf26
Update util.py
coreywillwhat Jul 26, 2024
dc3e947
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
f32ed2e
Update audi_services.py
coreywillwhat Jul 26, 2024
4f9cbba
Update audi_services.py
coreywillwhat Jul 26, 2024
a8b73c5
Update audi_services.py
coreywillwhat Jul 26, 2024
93b157a
Update audi_services.py
coreywillwhat Jul 26, 2024
d1f3843
Update const.py
coreywillwhat Jul 26, 2024
abb85f7
Update audi_services.py
coreywillwhat Jul 26, 2024
133be86
Update audi_services.py
coreywillwhat Jul 26, 2024
b26d584
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
904dfae
Update audi_services.py
coreywillwhat Jul 26, 2024
f37b80a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jul 26, 2024
355f0a9
Update audi_services.py
coreywillwhat Jul 26, 2024
6c0202c
Update audi_services.py
coreywillwhat Jul 26, 2024
6073f2d
Merge branch 'master' into climate_control_cleanup
coreywillwhat Jul 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions custom_components/audiconnect/audi_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,29 @@ async def execute_vehicle_action(self, service):
await self.connection.set_vehicle_window_heating(vin, False)

async def start_climate_control(self, service):
_LOGGER.info("Initiating Start Climate Control Service...")
_LOGGER.debug("Initiating Start Climate Control Service...")
vin = service.data.get(CONF_VIN).lower()
redacted_vin = "*" * (len(vin) - 4) + vin[-4:]
# Optional Parameters
temp_f = service.data.get(CONF_CLIMATE_TEMP_F, None)
temp_c = service.data.get(CONF_CLIMATE_TEMP_C, None)
glass_heating = service.data.get(CONF_CLIMATE_GLASS, False)
seat_fl = service.data.get(CONF_CLIMATE_SEAT_FL, False)
seat_fr = service.data.get(CONF_CLIMATE_SEAT_FR, False)
seat_rl = service.data.get(CONF_CLIMATE_SEAT_RL, False)
seat_rr = service.data.get(CONF_CLIMATE_SEAT_RR, False)
glass_heating = service.data.get(CONF_CLIMATE_GLASS, None)
seat_fl = service.data.get(CONF_CLIMATE_SEAT_FL, None)
seat_fr = service.data.get(CONF_CLIMATE_SEAT_FR, None)
seat_rl = service.data.get(CONF_CLIMATE_SEAT_RL, None)
seat_rr = service.data.get(CONF_CLIMATE_SEAT_RR, None)

_LOGGER.debug(
"Sending command to start climate control for vehicle %s with settings - Temp(F): %s, Temp(C): %s, Glass Heating: %s, Seat FL: %s, Seat FR: %s, Seat RL: %s, Seat RR: %s",
redacted_vin,
temp_f,
temp_c,
glass_heating,
seat_fl,
seat_fr,
seat_rl,
seat_rr,
)

await self.connection.start_climate_control(
vin,
Expand Down
10 changes: 4 additions & 6 deletions custom_components/audiconnect/audi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from asyncio import TimeoutError, CancelledError
from aiohttp import ClientResponseError
from aiohttp.hdrs import METH_GET, METH_POST, METH_PUT
from .const import HDR_XAPP_VERSION, HDR_USER_AGENT

from typing import Dict

Expand All @@ -16,9 +17,6 @@


class AudiAPI:
HDR_XAPP_VERSION = "4.23.1"
HDR_USER_AGENT = "Android/4.23.1 (Build 800240120.root project 'onetouch-android'.ext.buildTime) Android/11"

def __init__(self, session, proxy=None):
self.__token = None
self.__xclientid = None
Expand All @@ -38,7 +36,7 @@ async def request(
self,
method,
url,
data,
data=None,
headers: Dict[str, str] = None,
raw_reply: bool = False,
raw_contents: bool = False,
Expand Down Expand Up @@ -129,9 +127,9 @@ def __get_headers(self):
data = {
"Accept": "application/json",
"Accept-Charset": "utf-8",
"X-App-Version": self.HDR_XAPP_VERSION,
"X-App-Version": HDR_XAPP_VERSION,
"X-App-Name": "myAudi",
"User-Agent": self.HDR_USER_AGENT,
"User-Agent": HDR_USER_AGENT,
}
if self.__token is not None:
data["Authorization"] = "Bearer " + self.__token.get("access_token")
Expand Down
14 changes: 8 additions & 6 deletions custom_components/audiconnect/audi_connect_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,14 @@ async def start_climate_control(
seat_rl: bool,
seat_rr: bool,
):
redacted_vin = "*" * (len(vin) - 4) + vin[-4:]
if not self._loggedin:
await self.login()

if not self._loggedin:
return False

try:
_LOGGER.debug(
f"Sending command to start climate control for vehicle {vin} with settings - Temp(F): {temp_f}, Temp(C): {temp_c}, Glass Heating: {glass_heating}, Seat FL: {seat_fl}, Seat FR: {seat_fr}, Seat RL: {seat_rl}, Seat RR: {seat_rr}"
)

await self._audi_service.start_climate_control(
vin,
temp_f,
Expand All @@ -322,15 +319,20 @@ async def start_climate_control(
seat_rr,
)

_LOGGER.debug(f"Successfully started climate control of vehicle {vin}")
_LOGGER.debug(
"Successfully started climate control of vehicle with VIN: %s",
redacted_vin,
)

await self.notify(vin, ACTION_CLIMATISATION)

return True

except Exception as exception:
_LOGGER.error(
f"Unable to start climate control of vehicle {vin}. Error: {exception}",
"Unable to start climate control of vehicle with VIN: %s. Error: %s",
redacted_vin,
exception,
exc_info=True,
)
return False
Expand Down
Loading