Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 28 additions & 17 deletions deebot_t8/auth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,34 @@

LOGGER = logging.getLogger(__name__)

CLIENT_KEY = "1520391301804"
CLIENT_SECRET = "6c319b2a5cd3e66e39159c2e28f2fce9"
AUTH_CLIENT_KEY = "1520391491841"
AUTH_CLIENT_SECRET = "77ef58ce3afbe337da74aa8c5ab963a9"


class DeebotAuthClient:
def __init__(self, portal_client: PortalClient, device_id: str, country: str):
def __init__(self, portal_client: PortalClient, device_id: str, country: str, vendor: str):
self._portal_client = portal_client
self._device_id = device_id
self._country = country
self._vendor = vendor
self._meta = {
"country": country,
"lang": "EN",
"deviceId": device_id,
"appCode": "global_e",
"appVersion": "1.6.3",
"channel": "google_play",
"deviceType": "1",
}
if self._vendor == 'ecovacs':
self._CLIENT_KEY = "1520391301804"
self._CLIENT_SECRET = "6c319b2a5cd3e66e39159c2e28f2fce9"
self._AUTH_CLIENT_KEY = "1520391491841"
self._AUTH_CLIENT_SECRET = "77ef58ce3afbe337da74aa8c5ab963a9"
self._meta["appCode"] = "global_e"
self._meta["appVersion"] = "1.6.3"
elif self._vendor == 'yeedi':
self._CLIENT_KEY = "1581917520081"
self._CLIENT_SECRET = "ed5b3dd9a0253de7d90305d077eb5fee"
self._AUTH_CLIENT_KEY = "1581923437995"
self._AUTH_CLIENT_SECRET = "304a71592690995b2bb304e66b5ddee6"
self._meta["appCode"] = "yd_global_e"
self._meta["appVersion"] = "1.3.0"

def _sign_params(
self,
Expand All @@ -53,15 +61,15 @@ def _get_login_url(self):
tld = "cn" if self._country == "cn" else "com"
login_path = "user/loginCheckMobile" if self._country == "cn" else "user/login"
return (
"https://gl-{country}-api.ecovacs.{tld}/v1/private/{country}/"
"https://gl-{country}-api.{vendor}.{tld}/v1/private/{country}/"
"{lang}/{deviceId}/{appCode}/{appVersion}/{channel}/"
"{deviceType}/{login_path}"
).format(login_path=login_path, tld=tld, **self._meta)
).format(login_path=login_path, tld=tld, vendor=self._vendor, **self._meta)

def _get_authcode_url(self):
tld = "cn" if self._country == "cn" else "com"
return (
f"https://gl-{self._country}-openapi.ecovacs.{tld}/"
f"https://gl-{self._country}-openapi.{self._vendor}.{tld}/"
f"v1/global/auth/getAuthCode"
)

Expand All @@ -78,10 +86,10 @@ def do_account_password_exchange(

# Sign params
params_sig = self._sign_params(
{**self._meta, **params}, CLIENT_KEY, CLIENT_SECRET
{**self._meta, **params}, self._CLIENT_KEY, self._CLIENT_SECRET
)
params["authSign"] = params_sig
params["authAppkey"] = CLIENT_KEY
params["authAppkey"] = self._CLIENT_KEY

url = self._get_login_url()

Expand Down Expand Up @@ -120,11 +128,11 @@ def do_get_authcode(self, uid: str, access_token: str):
"openId": "global",
**params,
},
AUTH_CLIENT_KEY,
AUTH_CLIENT_SECRET,
self._AUTH_CLIENT_KEY,
self._AUTH_CLIENT_SECRET,
)
params["authSign"] = params_sig
params["authAppkey"] = AUTH_CLIENT_KEY
params["authAppkey"] = self._AUTH_CLIENT_KEY

# Do request
resp = requests.get(self._get_authcode_url(), params=params)
Expand All @@ -144,7 +152,10 @@ def do_get_authcode(self, uid: str, access_token: str):
)

def do_login_by_iot_token(self, user_id: str, auth_code: str):
org = "ECOCN" if self._country == "cn" else "ECOWW"
if self._vendor == 'ecovacs':
org = "ECOCN" if self._country == "cn" else "ECOWW"
elif self._vendor == 'yeedi':
org = "ECOYDCN" if self._country == "cn" else "ECOYDWW"
country = "Chinese" if self._country == "cn" else self._country.upper()

resp = self._portal_client.do_post(
Expand Down
6 changes: 5 additions & 1 deletion deebot_t8/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def on_credentials_changed(credentials: Credentials):
portal_client=portal_client,
device_id=config.device_id,
country=config.country,
vendor=config.vendor,
)
authenticator = Authenticator(
auth_client=auth_client,
Expand Down Expand Up @@ -100,9 +101,10 @@ def renew_access_tokens_impl(auth: DeebotAuthClient, config: Config):
@click.option("--username", type=str, required=True)
@click.option("--password", type=str, required=True)
@click.option("--country", type=str, required=True)
@click.option("--vendor", type=str, required=True)
@click.option("--continent", type=str, required=True)
@click.option("--regen-device", type=bool)
def login(obj: TypedObj, username, password, country, continent, regen_device):
def login(obj: TypedObj, username, password, country, vendor, continent, regen_device):
# TODO(NW): Infer continent from country

if not regen_device and obj.config is not None and obj.config.device_id is not None:
Expand All @@ -116,6 +118,7 @@ def login(obj: TypedObj, username, password, country, continent, regen_device):
password_hash=md5_hex(password),
device_id=device_id,
country=country,
vendor=vendor,
continent=continent,
)
# Recreate clients for this special use case to apply new configuration
Expand All @@ -129,6 +132,7 @@ def login(obj: TypedObj, username, password, country, continent, regen_device):
portal_client=portal_client,
device_id=obj.config.device_id,
country=obj.config.country,
vendor=obj.config.vendor
)

write_config(obj.config_path, obj.config)
Expand Down
3 changes: 3 additions & 0 deletions deebot_t8/cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Config:
username: str
password_hash: str
country: str
vendor: str
continent: str
device_id: str

Expand All @@ -33,6 +34,7 @@ def serialize(self):
"username": self.username,
"passwordHash": self.password_hash,
"country": self.country,
"vendor": self.vendor,
"continent": self.continent,
"deviceId": self.device_id,
"credentials": creds,
Expand All @@ -52,6 +54,7 @@ def deserialize(cls, o):
username=o["username"],
password_hash=o["passwordHash"],
country=o["country"],
vendor=o["vendor"],
continent=o["continent"],
device_id=o["deviceId"],
credentials=creds,
Expand Down
24 changes: 21 additions & 3 deletions deebot_t8/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,31 @@ def stop(self):
)

def pause(self):
self.exc_command("clean_V2", {"act": "pause"})
self.exc_command(
"clean_V2",
{
"act": "pause",
"content": {"count": "", "donotClean": "", "type": "", "value": ""},
}
)

def resume(self):
self.exc_command("clean_V2", {"act": "resume"})
self.exc_command(
"clean_V2",
{
"act": "resume",
"content": {"count": "", "donotClean": "", "type": "", "value": ""},
}
)

def return_to_charge(self):
self.exc_command("charge", {"act": "go"})
self.exc_command(
"charge",
{
"act": "go",
"content": {"count": "", "donotClean": "", "type": "", "value": ""},
}
)

def relocate(self):
self.exc_command("setRelocationState", {"mode": "manu"})
Expand Down