Skip to content

Commit

Permalink
Use the same User-Agent as the app
Browse files Browse the repository at this point in the history
  • Loading branch information
JohNan committed Feb 12, 2024
1 parent fb83b58 commit dfc50dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 11 additions & 12 deletions custom_components/wellbeing/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import asyncio
import logging
import socket
import json
from datetime import datetime, timedelta
from enum import Enum

Expand All @@ -17,12 +16,12 @@
CONCENTRATION_PARTS_PER_BILLION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER
from homeassistant.helpers.aiohttp_client import async_get_clientsession


TIMEOUT = 10
RETRIES = 3
CLIENT_ID = "ElxOneApp"
CLIENT_SECRET = "8UKrsKD7jH9zvTV7rz5HeCLkit67Mmj68FvRVTlYygwJYy4dW6KF2cVLPKeWzUQUd6KJMtTifFf4NkDnjI7ZLdfnwcPtTSNtYvbP7OzEkmQD9IjhMOf5e1zeAQYtt2yN"
X_API_KEY = "2AMqwEV5MqVhTKrRCyYfVF8gmKrd2rAmp7cUsfky"
USER_AGENT = "Electrolux/2.9 android/9"

BASE_URL = "https://api.ocp.electrolux.one"
TOKEN_URL = f"{BASE_URL}/one-account-authorization/api/v1/token"
Expand All @@ -45,12 +44,6 @@

_LOGGER: logging.Logger = logging.getLogger(__package__)

HEADERS = {"Content-type": "application/json; charset=UTF-8"}

class CustomComponent:
def get_translation(self, key):
return translations.get(key, key)

class Mode(str, Enum):
OFF = "PowerOff"
AUTO = "Auto"
Expand Down Expand Up @@ -300,7 +293,8 @@ async def _get_token(self) -> dict:
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json"
"Accept": "application/json",
"User-Agent": USER_AGENT
}
return await self.api_wrapper("post", TOKEN_URL, json, headers)

Expand All @@ -313,20 +307,22 @@ async def _login(self, access_token: str) -> dict:
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
"x-api-key": X_API_KEY
}
return await self.api_wrapper("post", AUTHENTICATION_URL, credentials, headers)

async def _get_token2(self, idToken: str, countryCode: str) -> dict:
async def _get_token2(self, id_token: str, country_code: str) -> dict:
credentials = {
"clientId": CLIENT_ID,
"idToken": idToken,
"idToken": id_token,
"grantType": "urn:ietf:params:oauth:grant-type:token-exchange"
}
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"Origin-Country-Code": countryCode
"User-Agent": USER_AGENT,
"Origin-Country-Code": country_code
}
return await self.api_wrapper("post", TOKEN_URL, credentials, headers)

Expand All @@ -335,6 +331,7 @@ async def _get_appliances(self, access_token: str) -> dict:
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
"x-api-key": X_API_KEY
}
return await self.api_wrapper("get", APPLIANCES_URL, headers=headers)
Expand All @@ -344,6 +341,7 @@ async def _get_appliance_info(self, access_token: str, pnc_id: str) -> dict:
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
"x-api-key": X_API_KEY
}
url = f"{APPLIANCES_URL}/{pnc_id}/info"
Expand Down Expand Up @@ -452,6 +450,7 @@ async def _send_command(self, access_token: str, pnc_id: str, command: dict) ->
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json",
"Accept": "application/json",
"User-Agent": USER_AGENT,
"x-api-key": X_API_KEY
}

Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
homeassistant==2023.6.3
aiohttp==3.8.4
homeassistant==2024.1.6
aiohttp==3.9.3

0 comments on commit dfc50dd

Please sign in to comment.