Skip to content

Commit

Permalink
Automatically get continent from country (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Jan 11, 2024
1 parent 6714834 commit da2a257
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ repos:
hooks:
- id: codespell
args:
- --ignore-words-list=hass,deebot
- --ignore-words-list=deebot
- --skip="./.*,*.csv,*.json"
- --quiet-level=2
- --exclude-file=deebot_client/util/continents.py
exclude_types:
- csv
- json
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,13 @@ from deebot_client.device import Device
device_id = md5(str(time.time()))
account_id = "your email or phonenumber (cn)"
password_hash = md5("yourPassword")
continent = "eu"
country = "de"


async def main():
async with aiohttp.ClientSession() as session:
logging.basicConfig(level=logging.DEBUG)
config = Configuration(session,
device_id=device_id, country=country, continent=continent,
)
config = Configuration(session, device_id=device_id, country=country)

authenticator = Authenticator(config, account_id, password_hash)
api_client = ApiClient(authenticator)
Expand Down
2 changes: 1 addition & 1 deletion deebot_client/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ async def __call_login_api(

url = _USER_LOGIN_URL_FORMAT.format(**self._meta, tld=self._tld)

if self._config.country.lower() == "cn":
if self._config.country == "cn":
url += "CheckMobile"

return await self.__do_auth_response(
Expand Down
7 changes: 4 additions & 3 deletions deebot_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aiohttp import ClientSession

from deebot_client.const import DataType
from deebot_client.util.continents import get_continent

if TYPE_CHECKING:
from deebot_client.capabilities import Capabilities
Expand Down Expand Up @@ -182,13 +183,13 @@ def __init__(
*,
device_id: str,
country: str,
continent: str,
continent: str | None = None,
verify_ssl: bool | str = True,
) -> None:
self._session = session
self._device_id = device_id
self._country = country
self._continent = continent
self._country = country.lower()
self._continent = (continent or get_continent(country)).lower()
self._verify_ssl = _str_to_bool_or_cert(verify_ssl)

@property
Expand Down
5 changes: 1 addition & 4 deletions deebot_client/mqtt_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ def __post_init__(self, config: Configuration) -> None:

object.__setattr__(self, "device_id", config.device_id)

if (
self.hostname == MqttConfiguration.hostname
and config.country.lower() != "cn"
):
if self.hostname == MqttConfiguration.hostname and config.country != "cn":
object.__setattr__(self, "hostname", f"mq-{config.continent}.ecouser.net")


Expand Down
File renamed without changes.
262 changes: 262 additions & 0 deletions deebot_client/util/continents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
"""Continents module."""


def get_continent(country: str) -> str:
"""Return the continent for the given country or ww."""
return _COUNTRIES_TO_CONTINENTS.get(country, "WW")


# Co pied from https://github.com/mrbungle64/ecovacs-deebot.js/blob/master/countries.json on 11.01.2024
_COUNTRIES_TO_CONTINENTS = {
"AD": "EU",
"AE": "AS",
"AF": "AS",
"AG": "NA",
"AI": "NA",
"AL": "EU",
"AM": "AS",
"AO": "WW",
"AQ": "WW",
"AR": "WW",
"AS": "WW",
"AT": "EU",
"AU": "WW",
"AW": "NA",
"AX": "EU",
"AZ": "AS",
"BA": "EU",
"BB": "NA",
"BD": "AS",
"BE": "EU",
"BF": "WW",
"BG": "EU",
"BH": "AS",
"BI": "WW",
"BJ": "WW",
"BL": "NA",
"BM": "NA",
"BN": "AS",
"BO": "WW",
"BQ": "NA",
"BR": "WW",
"BS": "NA",
"BT": "AS",
"BV": "WW",
"BW": "WW",
"BY": "EU",
"BZ": "NA",
"CA": "NA",
"CC": "AS",
"CD": "WW",
"CF": "WW",
"CG": "WW",
"CH": "EU",
"CI": "WW",
"CK": "WW",
"CL": "WW",
"CM": "WW",
"CN": "WW",
"CO": "WW",
"CR": "NA",
"CU": "NA",
"CV": "WW",
"CW": "NA",
"CX": "AS",
"CY": "EU",
"CZ": "EU",
"DE": "EU",
"DJ": "WW",
"DK": "EU",
"DM": "NA",
"DO": "NA",
"DZ": "WW",
"EC": "WW",
"EE": "EU",
"EG": "WW",
"EH": "WW",
"ER": "WW",
"ES": "EU",
"ET": "WW",
"FI": "EU",
"FJ": "WW",
"FK": "WW",
"FM": "WW",
"FO": "EU",
"FR": "EU",
"GA": "WW",
"GB": "EU",
"GD": "NA",
"GE": "AS",
"GF": "WW",
"GG": "EU",
"GH": "WW",
"GI": "EU",
"GL": "NA",
"GM": "WW",
"GN": "WW",
"GP": "NA",
"GQ": "WW",
"GR": "EU",
"GS": "WW",
"GT": "NA",
"GU": "WW",
"GW": "WW",
"GY": "WW",
"HK": "AS",
"HM": "WW",
"HN": "NA",
"HR": "EU",
"HT": "NA",
"HU": "EU",
"ID": "AS",
"IE": "EU",
"IL": "AS",
"IM": "EU",
"IN": "AS",
"IO": "AS",
"IQ": "AS",
"IR": "AS",
"IS": "EU",
"IT": "EU",
"JE": "EU",
"JM": "NA",
"JO": "AS",
"JP": "AS",
"KE": "WW",
"KG": "AS",
"KH": "AS",
"KI": "WW",
"KM": "WW",
"KN": "NA",
"KP": "AS",
"KR": "AS",
"KW": "AS",
"KY": "NA",
"KZ": "AS",
"LA": "AS",
"LB": "AS",
"LC": "NA",
"LI": "EU",
"LK": "AS",
"LR": "WW",
"LS": "WW",
"LT": "EU",
"LU": "EU",
"LV": "EU",
"LY": "WW",
"MA": "WW",
"MC": "EU",
"MD": "EU",
"ME": "EU",
"MF": "NA",
"MG": "WW",
"MH": "WW",
"MK": "EU",
"ML": "WW",
"MM": "AS",
"MN": "AS",
"MO": "AS",
"MP": "WW",
"MQ": "NA",
"MR": "WW",
"MS": "NA",
"MT": "EU",
"MU": "WW",
"MV": "AS",
"MW": "WW",
"MX": "NA",
"MY": "AS",
"MZ": "WW",
"NA": "WW",
"NC": "WW",
"NE": "WW",
"NF": "WW",
"NG": "WW",
"NI": "NA",
"NL": "EU",
"NO": "EU",
"NP": "AS",
"NR": "WW",
"NU": "WW",
"NZ": "WW",
"OM": "AS",
"PA": "NA",
"PE": "WW",
"PF": "WW",
"PG": "WW",
"PH": "AS",
"PK": "AS",
"PL": "EU",
"PM": "NA",
"PN": "WW",
"PR": "NA",
"PS": "AS",
"PT": "EU",
"PW": "WW",
"PY": "WW",
"QA": "AS",
"RE": "WW",
"RO": "EU",
"RS": "EU",
"RU": "EU",
"RW": "WW",
"SA": "AS",
"SB": "WW",
"SC": "WW",
"SD": "WW",
"SE": "EU",
"SG": "AS",
"SH": "WW",
"SI": "EU",
"SJ": "EU",
"SK": "EU",
"SL": "WW",
"SM": "EU",
"SN": "WW",
"SO": "WW",
"SR": "WW",
"SS": "WW",
"ST": "WW",
"SV": "NA",
"SX": "NA",
"SY": "AS",
"SZ": "WW",
"TC": "NA",
"TD": "WW",
"TF": "WW",
"TG": "WW",
"TH": "AS",
"TJ": "AS",
"TK": "WW",
"TL": "WW",
"TM": "AS",
"TN": "WW",
"TO": "WW",
"TR": "AS",
"TT": "NA",
"TV": "WW",
"TW": "AS",
"TZ": "WW",
"UA": "EU",
"UG": "WW",
"UK": "EU",
"UM": "WW",
"US": "NA",
"UY": "WW",
"UZ": "AS",
"VA": "EU",
"VC": "NA",
"VE": "WW",
"VG": "NA",
"VI": "NA",
"VN": "AS",
"VU": "WW",
"WF": "WW",
"WS": "WW",
"XK": "EU",
"YE": "AS",
"YT": "WW",
"ZA": "WW",
"ZM": "WW",
"ZW": "WW",
}
Empty file added tests/util/__init__.py
Empty file.
18 changes: 18 additions & 0 deletions tests/util/test_continents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest

from deebot_client.util.continents import get_continent


@pytest.mark.parametrize(
("continent", "expected"),
[
("IT", "EU"),
("DE", "EU"),
("US", "NA"),
("invalid", "WW"),
("", "WW"),
("XX", "WW"),
],
)
def test_get_continent(continent: str, expected: str) -> None:
assert get_continent(continent) == expected
File renamed without changes.

0 comments on commit da2a257

Please sign in to comment.