urban-arrow-api 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- urban_arrow_api/__init__.py +48 -0
- urban_arrow_api/__main__.py +125 -0
- urban_arrow_api/auth.py +219 -0
- urban_arrow_api/client.py +182 -0
- urban_arrow_api/const.py +36 -0
- urban_arrow_api/exceptions.py +25 -0
- urban_arrow_api/login.py +152 -0
- urban_arrow_api/models.py +251 -0
- urban_arrow_api/py.typed +0 -0
- urban_arrow_api-0.1.0.dist-info/METADATA +175 -0
- urban_arrow_api-0.1.0.dist-info/RECORD +14 -0
- urban_arrow_api-0.1.0.dist-info/WHEEL +4 -0
- urban_arrow_api-0.1.0.dist-info/entry_points.txt +2 -0
- urban_arrow_api-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from .auth import (
|
|
2
|
+
AbstractAuth,
|
|
3
|
+
LoginRequest,
|
|
4
|
+
Token,
|
|
5
|
+
TokenAuth,
|
|
6
|
+
create_login_request,
|
|
7
|
+
exchange_code,
|
|
8
|
+
extract_code,
|
|
9
|
+
)
|
|
10
|
+
from .client import UrbanArrowClient
|
|
11
|
+
from .const import ActivityPeriod, BikeSetting
|
|
12
|
+
from .exceptions import (
|
|
13
|
+
UrbanArrowApiError,
|
|
14
|
+
UrbanArrowAuthError,
|
|
15
|
+
UrbanArrowCaptchaRequired,
|
|
16
|
+
UrbanArrowConnectionError,
|
|
17
|
+
UrbanArrowError,
|
|
18
|
+
UrbanArrowMfaRequired,
|
|
19
|
+
)
|
|
20
|
+
from .login import login_with_credentials
|
|
21
|
+
from .models import Activity, Bike, BikeSummary, Location, Notification, Telemetry, TimedValue
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"AbstractAuth",
|
|
25
|
+
"Activity",
|
|
26
|
+
"ActivityPeriod",
|
|
27
|
+
"Bike",
|
|
28
|
+
"BikeSetting",
|
|
29
|
+
"BikeSummary",
|
|
30
|
+
"Location",
|
|
31
|
+
"LoginRequest",
|
|
32
|
+
"Notification",
|
|
33
|
+
"Telemetry",
|
|
34
|
+
"TimedValue",
|
|
35
|
+
"Token",
|
|
36
|
+
"TokenAuth",
|
|
37
|
+
"UrbanArrowApiError",
|
|
38
|
+
"UrbanArrowAuthError",
|
|
39
|
+
"UrbanArrowCaptchaRequired",
|
|
40
|
+
"UrbanArrowClient",
|
|
41
|
+
"UrbanArrowConnectionError",
|
|
42
|
+
"UrbanArrowError",
|
|
43
|
+
"UrbanArrowMfaRequired",
|
|
44
|
+
"create_login_request",
|
|
45
|
+
"exchange_code",
|
|
46
|
+
"extract_code",
|
|
47
|
+
"login_with_credentials",
|
|
48
|
+
]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"""Small CLI for exploring the API: ``urban-arrow login`` then ``urban-arrow status``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import getpass
|
|
8
|
+
import json
|
|
9
|
+
import os
|
|
10
|
+
from datetime import date
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
import aiohttp
|
|
15
|
+
|
|
16
|
+
from . import ActivityPeriod, BikeSetting, Token, TokenAuth, UrbanArrowClient
|
|
17
|
+
from .auth import create_login_request, exchange_code, extract_code
|
|
18
|
+
from .login import login_with_credentials
|
|
19
|
+
|
|
20
|
+
TOKEN_FILE = Path(
|
|
21
|
+
os.environ.get("URBAN_ARROW_TOKEN_FILE", "~/.config/urban-arrow/token.json")
|
|
22
|
+
).expanduser()
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _save(token: Token) -> None:
|
|
26
|
+
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
TOKEN_FILE.write_text(json.dumps(token.as_dict()))
|
|
28
|
+
TOKEN_FILE.chmod(0o600)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _dump(data: Any) -> None:
|
|
32
|
+
print(json.dumps(data, indent=2, default=str))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def _password_login(username: str) -> None:
|
|
36
|
+
password = os.environ.get("URBAN_ARROW_PASSWORD") or await asyncio.to_thread(
|
|
37
|
+
getpass.getpass, "Password: "
|
|
38
|
+
)
|
|
39
|
+
_save(await login_with_credentials(username, password))
|
|
40
|
+
print(f"Saved token to {TOKEN_FILE}")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def _browser_login() -> None:
|
|
44
|
+
req = create_login_request()
|
|
45
|
+
print("1. Open this URL in a browser and log in with your Urban Arrow account:\n")
|
|
46
|
+
print(req.url)
|
|
47
|
+
print(
|
|
48
|
+
"\n2. After login the browser tries to open an 'urbanarrow://...' URL and fails."
|
|
49
|
+
"\n Copy that URL (DevTools > Network, or the address bar / error page)"
|
|
50
|
+
" and paste it here."
|
|
51
|
+
)
|
|
52
|
+
redirect = await asyncio.to_thread(input, "\nRedirect URL or code: ")
|
|
53
|
+
async with aiohttp.ClientSession() as session:
|
|
54
|
+
token = await exchange_code(session, extract_code(redirect, req.state), req.code_verifier)
|
|
55
|
+
_save(token)
|
|
56
|
+
print(f"Saved token to {TOKEN_FILE}")
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
async def _run(args: argparse.Namespace) -> None:
|
|
60
|
+
token = Token.from_dict(json.loads(TOKEN_FILE.read_text()))
|
|
61
|
+
async with aiohttp.ClientSession() as session:
|
|
62
|
+
client = UrbanArrowClient(TokenAuth(session, token, _save))
|
|
63
|
+
match args.command:
|
|
64
|
+
case "bikes":
|
|
65
|
+
_dump([b.raw for b in await client.get_bikes()])
|
|
66
|
+
case "status":
|
|
67
|
+
for summary in await client.get_bikes():
|
|
68
|
+
bike = await client.get_bike(summary.id)
|
|
69
|
+
print(f"== {bike.name} ({bike.id})")
|
|
70
|
+
_dump(bike.raw)
|
|
71
|
+
_dump((await client.get_telemetry(bike.id)).raw)
|
|
72
|
+
case "activity":
|
|
73
|
+
bike = await client.get_bike(args.bike_id)
|
|
74
|
+
start = (
|
|
75
|
+
date.fromisoformat(args.start) if args.start else date.today().replace(day=1)
|
|
76
|
+
)
|
|
77
|
+
_dump((await client.get_activity(bike, ActivityPeriod(args.period), start)).raw)
|
|
78
|
+
case "notifications":
|
|
79
|
+
_dump([n.raw for n in await client.get_notifications()])
|
|
80
|
+
case "flash":
|
|
81
|
+
await client.flash_lights(args.bike_id)
|
|
82
|
+
print("ok")
|
|
83
|
+
case "setting":
|
|
84
|
+
await client.set_setting(
|
|
85
|
+
args.bike_id, BikeSetting(args.setting), args.state == "on"
|
|
86
|
+
)
|
|
87
|
+
print("ok")
|
|
88
|
+
case "raw":
|
|
89
|
+
_dump(await client._request(args.method.upper(), args.path))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def main() -> None:
|
|
93
|
+
parser = argparse.ArgumentParser(prog="urban-arrow")
|
|
94
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
95
|
+
p = sub.add_parser("login", help="Log in with email + password")
|
|
96
|
+
p.add_argument("username")
|
|
97
|
+
sub.add_parser("browser-login", help="Fallback: log in via browser and paste the redirect URL")
|
|
98
|
+
sub.add_parser("bikes")
|
|
99
|
+
sub.add_parser("status")
|
|
100
|
+
sub.add_parser("notifications")
|
|
101
|
+
p = sub.add_parser("activity")
|
|
102
|
+
p.add_argument("bike_id")
|
|
103
|
+
p.add_argument("--period", default="MONTH", choices=[p.value for p in ActivityPeriod])
|
|
104
|
+
p.add_argument("--start", help="YYYY-MM-DD, defaults to first day of this month")
|
|
105
|
+
p = sub.add_parser("flash")
|
|
106
|
+
p.add_argument("bike_id")
|
|
107
|
+
p = sub.add_parser("setting")
|
|
108
|
+
p.add_argument("bike_id")
|
|
109
|
+
p.add_argument("setting", choices=[s.value for s in BikeSetting])
|
|
110
|
+
p.add_argument("state", choices=["on", "off"])
|
|
111
|
+
p = sub.add_parser("raw", help="Call any endpoint path relative to /api/")
|
|
112
|
+
p.add_argument("method")
|
|
113
|
+
p.add_argument("path")
|
|
114
|
+
args = parser.parse_args()
|
|
115
|
+
match args.command:
|
|
116
|
+
case "login":
|
|
117
|
+
asyncio.run(_password_login(args.username))
|
|
118
|
+
case "browser-login":
|
|
119
|
+
asyncio.run(_browser_login())
|
|
120
|
+
case _:
|
|
121
|
+
asyncio.run(_run(args))
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
if __name__ == "__main__":
|
|
125
|
+
main()
|
urban_arrow_api/auth.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"""Auth0 login for the Pon Connected backend.
|
|
2
|
+
|
|
3
|
+
The tenant has the password grant disabled for the app's client, so login is the
|
|
4
|
+
same Authorization Code + PKCE flow the app uses. The redirect goes to the app's
|
|
5
|
+
custom ``urbanarrow://`` scheme, which a desktop browser cannot open: the user
|
|
6
|
+
copies that final URL (or just its ``code``) back to us. After that the refresh
|
|
7
|
+
token keeps the session alive without user interaction.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import asyncio
|
|
13
|
+
import base64
|
|
14
|
+
import hashlib
|
|
15
|
+
import inspect
|
|
16
|
+
import secrets
|
|
17
|
+
import time
|
|
18
|
+
from abc import ABC, abstractmethod
|
|
19
|
+
from collections.abc import Awaitable, Callable
|
|
20
|
+
from dataclasses import asdict, dataclass
|
|
21
|
+
from typing import Any
|
|
22
|
+
from urllib.parse import parse_qs, urlencode, urlparse
|
|
23
|
+
|
|
24
|
+
import aiohttp
|
|
25
|
+
|
|
26
|
+
from .const import (
|
|
27
|
+
AUTH0_AUDIENCE,
|
|
28
|
+
AUTH0_CLIENT_ID,
|
|
29
|
+
AUTH0_DOMAIN,
|
|
30
|
+
AUTH0_REDIRECT_URI,
|
|
31
|
+
AUTH0_SCOPE,
|
|
32
|
+
)
|
|
33
|
+
from .exceptions import UrbanArrowAuthError, UrbanArrowConnectionError
|
|
34
|
+
|
|
35
|
+
TOKEN_URL = f"https://{AUTH0_DOMAIN}/oauth/token"
|
|
36
|
+
AUTHORIZE_URL = f"https://{AUTH0_DOMAIN}/authorize"
|
|
37
|
+
# Refresh a little before expiry so a request never races the deadline.
|
|
38
|
+
EXPIRY_MARGIN_SECONDS = 60
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@dataclass(slots=True)
|
|
42
|
+
class Token:
|
|
43
|
+
access_token: str
|
|
44
|
+
refresh_token: str
|
|
45
|
+
expires_at: float
|
|
46
|
+
id_token: str | None = None
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def expired(self) -> bool:
|
|
50
|
+
return time.time() >= self.expires_at - EXPIRY_MARGIN_SECONDS
|
|
51
|
+
|
|
52
|
+
def as_dict(self) -> dict[str, Any]:
|
|
53
|
+
return asdict(self)
|
|
54
|
+
|
|
55
|
+
@classmethod
|
|
56
|
+
def from_dict(cls, data: dict[str, Any]) -> Token:
|
|
57
|
+
return cls(
|
|
58
|
+
access_token=data["access_token"],
|
|
59
|
+
refresh_token=data["refresh_token"],
|
|
60
|
+
expires_at=float(data["expires_at"]),
|
|
61
|
+
id_token=data.get("id_token"),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass(slots=True)
|
|
66
|
+
class LoginRequest:
|
|
67
|
+
url: str
|
|
68
|
+
code_verifier: str
|
|
69
|
+
state: str
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def create_login_request(*, signup: bool = False, locale: str | None = None) -> LoginRequest:
|
|
73
|
+
code_verifier = secrets.token_urlsafe(64)
|
|
74
|
+
challenge = (
|
|
75
|
+
base64.urlsafe_b64encode(hashlib.sha256(code_verifier.encode()).digest())
|
|
76
|
+
.rstrip(b"=")
|
|
77
|
+
.decode()
|
|
78
|
+
)
|
|
79
|
+
state = secrets.token_urlsafe(16)
|
|
80
|
+
params = {
|
|
81
|
+
"response_type": "code",
|
|
82
|
+
"client_id": AUTH0_CLIENT_ID,
|
|
83
|
+
"redirect_uri": AUTH0_REDIRECT_URI,
|
|
84
|
+
"audience": AUTH0_AUDIENCE,
|
|
85
|
+
"scope": AUTH0_SCOPE,
|
|
86
|
+
"code_challenge": challenge,
|
|
87
|
+
"code_challenge_method": "S256",
|
|
88
|
+
"state": state,
|
|
89
|
+
"prompt": "login",
|
|
90
|
+
}
|
|
91
|
+
if signup:
|
|
92
|
+
params["screen_hint"] = "signup"
|
|
93
|
+
if locale:
|
|
94
|
+
params["ui_locales"] = locale
|
|
95
|
+
return LoginRequest(f"{AUTHORIZE_URL}?{urlencode(params)}", code_verifier, state)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def extract_code(redirect: str, expected_state: str | None = None) -> str:
|
|
99
|
+
"""Accept either the full ``urbanarrow://...callback?code=...`` URL or a bare code."""
|
|
100
|
+
redirect = redirect.strip()
|
|
101
|
+
if "://" not in redirect and "?" not in redirect:
|
|
102
|
+
return redirect
|
|
103
|
+
query = parse_qs(urlparse(redirect).query)
|
|
104
|
+
if "error" in query:
|
|
105
|
+
raise UrbanArrowAuthError(query.get("error_description", query["error"])[0])
|
|
106
|
+
if expected_state is not None and query.get("state", [None])[0] != expected_state:
|
|
107
|
+
raise UrbanArrowAuthError("State mismatch in redirect URL")
|
|
108
|
+
try:
|
|
109
|
+
return query["code"][0]
|
|
110
|
+
except KeyError as err:
|
|
111
|
+
raise UrbanArrowAuthError("No authorization code in redirect URL") from err
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
async def _token_request(session: aiohttp.ClientSession, payload: dict[str, str]) -> dict[str, Any]:
|
|
115
|
+
try:
|
|
116
|
+
async with session.post(TOKEN_URL, json=payload) as resp:
|
|
117
|
+
data = await resp.json(content_type=None)
|
|
118
|
+
if resp.status in (400, 401, 403):
|
|
119
|
+
raise UrbanArrowAuthError(
|
|
120
|
+
data.get("error_description") or data.get("error") or str(resp.status)
|
|
121
|
+
)
|
|
122
|
+
resp.raise_for_status()
|
|
123
|
+
return data
|
|
124
|
+
except aiohttp.ClientError as err:
|
|
125
|
+
raise UrbanArrowConnectionError(str(err)) from err
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def _token_from_response(data: dict[str, Any], previous_refresh: str | None = None) -> Token:
|
|
129
|
+
refresh = data.get("refresh_token") or previous_refresh
|
|
130
|
+
if not refresh:
|
|
131
|
+
raise UrbanArrowAuthError("Auth0 did not return a refresh token")
|
|
132
|
+
return Token(
|
|
133
|
+
access_token=data["access_token"],
|
|
134
|
+
# Auth0 only returns a new refresh token when rotation is enabled.
|
|
135
|
+
refresh_token=refresh,
|
|
136
|
+
expires_at=time.time() + int(data.get("expires_in", 3600)),
|
|
137
|
+
id_token=data.get("id_token"),
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
async def exchange_code(session: aiohttp.ClientSession, code: str, code_verifier: str) -> Token:
|
|
142
|
+
data = await _token_request(
|
|
143
|
+
session,
|
|
144
|
+
{
|
|
145
|
+
"grant_type": "authorization_code",
|
|
146
|
+
"client_id": AUTH0_CLIENT_ID,
|
|
147
|
+
"code": code,
|
|
148
|
+
"code_verifier": code_verifier,
|
|
149
|
+
"redirect_uri": AUTH0_REDIRECT_URI,
|
|
150
|
+
},
|
|
151
|
+
)
|
|
152
|
+
return _token_from_response(data)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
async def refresh_token(session: aiohttp.ClientSession, token: Token) -> Token:
|
|
156
|
+
data = await _token_request(
|
|
157
|
+
session,
|
|
158
|
+
{
|
|
159
|
+
"grant_type": "refresh_token",
|
|
160
|
+
"client_id": AUTH0_CLIENT_ID,
|
|
161
|
+
"refresh_token": token.refresh_token,
|
|
162
|
+
},
|
|
163
|
+
)
|
|
164
|
+
return _token_from_response(data, token.refresh_token)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
TokenUpdateCallback = Callable[[Token], Awaitable[None] | None]
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
class AbstractAuth(ABC):
|
|
171
|
+
"""Supplies access tokens to the client.
|
|
172
|
+
|
|
173
|
+
The client never stores or refreshes tokens itself; subclass this to control
|
|
174
|
+
where tokens live and how they are renewed (e.g. persisted in a config entry).
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
def __init__(self, session: aiohttp.ClientSession) -> None:
|
|
178
|
+
self.session = session
|
|
179
|
+
|
|
180
|
+
@abstractmethod
|
|
181
|
+
async def async_get_access_token(self, *, force_refresh: bool = False) -> str:
|
|
182
|
+
"""Return a valid access token; ``force_refresh`` is set after a 401."""
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
class TokenAuth(AbstractAuth):
|
|
186
|
+
"""Holds a ``Token`` and refreshes it through Auth0 when it expires.
|
|
187
|
+
|
|
188
|
+
``on_token_update`` fires after every refresh; persist the token there,
|
|
189
|
+
because Auth0 may rotate the refresh token and invalidate the old one.
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
def __init__(
|
|
193
|
+
self,
|
|
194
|
+
session: aiohttp.ClientSession,
|
|
195
|
+
token: Token,
|
|
196
|
+
on_token_update: TokenUpdateCallback | None = None,
|
|
197
|
+
) -> None:
|
|
198
|
+
super().__init__(session)
|
|
199
|
+
self._token = token
|
|
200
|
+
self._on_token_update = on_token_update
|
|
201
|
+
self._lock = asyncio.Lock()
|
|
202
|
+
|
|
203
|
+
@property
|
|
204
|
+
def token(self) -> Token:
|
|
205
|
+
return self._token
|
|
206
|
+
|
|
207
|
+
async def async_refresh_token(self, token: Token) -> Token:
|
|
208
|
+
"""Override to add a fallback, e.g. a fresh login when the refresh token is revoked."""
|
|
209
|
+
return await refresh_token(self.session, token)
|
|
210
|
+
|
|
211
|
+
async def async_get_access_token(self, *, force_refresh: bool = False) -> str:
|
|
212
|
+
async with self._lock:
|
|
213
|
+
if force_refresh or self._token.expired:
|
|
214
|
+
self._token = await self.async_refresh_token(self._token)
|
|
215
|
+
if self._on_token_update:
|
|
216
|
+
result = self._on_token_update(self._token)
|
|
217
|
+
if inspect.isawaitable(result):
|
|
218
|
+
await result
|
|
219
|
+
return self._token.access_token
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from datetime import UTC, date, datetime
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import aiohttp
|
|
7
|
+
|
|
8
|
+
from .auth import AbstractAuth
|
|
9
|
+
from .const import (
|
|
10
|
+
API_BASE_URL,
|
|
11
|
+
CLIENT_TYPE,
|
|
12
|
+
MANUFACTURER_ID,
|
|
13
|
+
PRODUCTION_PROFILE_IMAGE_URL,
|
|
14
|
+
ActivityPeriod,
|
|
15
|
+
BikeSetting,
|
|
16
|
+
)
|
|
17
|
+
from .exceptions import (
|
|
18
|
+
UrbanArrowApiError,
|
|
19
|
+
UrbanArrowAuthError,
|
|
20
|
+
UrbanArrowConnectionError,
|
|
21
|
+
)
|
|
22
|
+
from .models import Activity, Bike, BikeSummary, Notification, Telemetry
|
|
23
|
+
|
|
24
|
+
DEFAULT_TIMEOUT = aiohttp.ClientTimeout(total=15)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class UrbanArrowClient:
|
|
28
|
+
"""Async client for the Pon Connected API as used by the Urban Arrow app."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, auth: AbstractAuth, *, language: str = "en") -> None:
|
|
31
|
+
self._auth = auth
|
|
32
|
+
self._session = auth.session
|
|
33
|
+
self._language = language
|
|
34
|
+
|
|
35
|
+
async def _request(
|
|
36
|
+
self,
|
|
37
|
+
method: str,
|
|
38
|
+
path: str,
|
|
39
|
+
*,
|
|
40
|
+
params: dict[str, Any] | None = None,
|
|
41
|
+
json: Any = None,
|
|
42
|
+
_retry: bool = True,
|
|
43
|
+
) -> Any:
|
|
44
|
+
access_token = await self._auth.async_get_access_token()
|
|
45
|
+
headers = {
|
|
46
|
+
"Authorization": f"Bearer {access_token}",
|
|
47
|
+
"Manufacturer-Id": MANUFACTURER_ID,
|
|
48
|
+
"Client-Type": CLIENT_TYPE,
|
|
49
|
+
"Accept-Language": self._language,
|
|
50
|
+
"Accept": "application/json",
|
|
51
|
+
}
|
|
52
|
+
try:
|
|
53
|
+
async with self._session.request(
|
|
54
|
+
method,
|
|
55
|
+
API_BASE_URL + path,
|
|
56
|
+
params=params,
|
|
57
|
+
json=json,
|
|
58
|
+
headers=headers,
|
|
59
|
+
timeout=DEFAULT_TIMEOUT,
|
|
60
|
+
) as resp:
|
|
61
|
+
if resp.status == 401 and _retry:
|
|
62
|
+
await self._auth.async_get_access_token(force_refresh=True)
|
|
63
|
+
return await self._request(method, path, params=params, json=json, _retry=False)
|
|
64
|
+
if resp.status == 401:
|
|
65
|
+
raise UrbanArrowAuthError("Access token rejected")
|
|
66
|
+
if resp.status >= 400:
|
|
67
|
+
raise UrbanArrowApiError(resp.status, await resp.text())
|
|
68
|
+
if resp.status == 204 or resp.content_length == 0:
|
|
69
|
+
return None
|
|
70
|
+
text = await resp.text()
|
|
71
|
+
if not text:
|
|
72
|
+
return None
|
|
73
|
+
try:
|
|
74
|
+
return await resp.json(content_type=None)
|
|
75
|
+
except ValueError:
|
|
76
|
+
return text
|
|
77
|
+
except (aiohttp.ClientError, TimeoutError) as err:
|
|
78
|
+
raise UrbanArrowConnectionError(str(err)) from err
|
|
79
|
+
|
|
80
|
+
# Bikes
|
|
81
|
+
|
|
82
|
+
async def get_bikes(self) -> list[BikeSummary]:
|
|
83
|
+
return [BikeSummary.parse(b) for b in await self._request("GET", "v9/bikes")]
|
|
84
|
+
|
|
85
|
+
async def get_bike(self, bike_id: str) -> Bike:
|
|
86
|
+
return Bike.parse(await self._request("GET", f"v11/bikes/{bike_id}"))
|
|
87
|
+
|
|
88
|
+
async def get_telemetry(self, bike_id: str) -> Telemetry:
|
|
89
|
+
return Telemetry.parse(await self._request("GET", f"v11/bikes/{bike_id}/telemetry"))
|
|
90
|
+
|
|
91
|
+
async def get_bike_by_module(self, module_id: str) -> BikeSummary:
|
|
92
|
+
return BikeSummary.parse(await self._request("GET", f"v9/bikes/module/{module_id}"))
|
|
93
|
+
|
|
94
|
+
async def check_frame_number(self, frame_number: str) -> dict[str, Any]:
|
|
95
|
+
"""Returns ``{"isSmart": bool, "productionProfileId": str}``."""
|
|
96
|
+
return await self._request("GET", f"v10/bikes/frame-number/{frame_number}")
|
|
97
|
+
|
|
98
|
+
async def set_nickname(self, bike_id: str, nickname: str) -> None:
|
|
99
|
+
await self._request("PUT", f"v1/bikes/{bike_id}/nickname", json={"nickname": nickname})
|
|
100
|
+
|
|
101
|
+
async def flash_lights(self, bike_id: str) -> None:
|
|
102
|
+
await self._request("POST", f"v1/bikes/{bike_id}/flash-lights")
|
|
103
|
+
|
|
104
|
+
async def set_setting(self, bike_id: str, setting: BikeSetting, enabled: bool) -> None:
|
|
105
|
+
action = "enable" if enabled else "disable"
|
|
106
|
+
await self._request("PUT", f"v2/bikes/{bike_id}/settings/{setting.value}/{action}")
|
|
107
|
+
|
|
108
|
+
async def set_theft_protection(self, bike_id: str, enabled: bool) -> None:
|
|
109
|
+
await self._request(
|
|
110
|
+
"PUT", f"v1/bikes/{bike_id}/theft/detection/mode", json={"enabled": enabled}
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
async def get_activity(
|
|
114
|
+
self,
|
|
115
|
+
bike: Bike,
|
|
116
|
+
period: ActivityPeriod,
|
|
117
|
+
start_date: date,
|
|
118
|
+
cutoff_date: date | None = None,
|
|
119
|
+
) -> Activity:
|
|
120
|
+
"""Distance per sub-period (e.g. per day for WEEK) starting at ``start_date``.
|
|
121
|
+
|
|
122
|
+
The app passes the pairing date as ``cutoffDate`` so nothing before the
|
|
123
|
+
current owner is returned; we default to the same.
|
|
124
|
+
"""
|
|
125
|
+
if cutoff_date is None:
|
|
126
|
+
cutoff_date = bike.paired_on.date() if bike.paired_on else date(1970, 1, 1)
|
|
127
|
+
cutoff_ms = int(
|
|
128
|
+
datetime(cutoff_date.year, cutoff_date.month, cutoff_date.day, tzinfo=UTC).timestamp()
|
|
129
|
+
* 1000
|
|
130
|
+
)
|
|
131
|
+
data = await self._request(
|
|
132
|
+
"GET",
|
|
133
|
+
f"v6/bikes/{bike.id}/activity/history",
|
|
134
|
+
params={
|
|
135
|
+
"timeUnit": period.value,
|
|
136
|
+
"startDate": start_date.isoformat(),
|
|
137
|
+
"cutoffDate": cutoff_ms,
|
|
138
|
+
},
|
|
139
|
+
)
|
|
140
|
+
return Activity.parse(data)
|
|
141
|
+
|
|
142
|
+
# Theft
|
|
143
|
+
|
|
144
|
+
async def report_theft(
|
|
145
|
+
self, bike_id: str, police_report_number: str | None, phone_number: str | None
|
|
146
|
+
) -> None:
|
|
147
|
+
await self._request(
|
|
148
|
+
"POST",
|
|
149
|
+
f"v4/bikes/{bike_id}/theft/report",
|
|
150
|
+
json={"policeReportNumber": police_report_number, "customerPhoneNumber": phone_number},
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
async def cancel_theft_report(self, bike_id: str) -> None:
|
|
154
|
+
await self._request("POST", f"v1/bikes/{bike_id}/theft/cancel")
|
|
155
|
+
|
|
156
|
+
# Notifications (the in-app inbox, not push)
|
|
157
|
+
|
|
158
|
+
async def get_notifications(self, version: str = "6") -> list[Notification]:
|
|
159
|
+
data = await self._request("GET", "v4/notifications", params={"version": version})
|
|
160
|
+
return [Notification.parse(n) for n in data or []]
|
|
161
|
+
|
|
162
|
+
async def mark_notifications_read(self, ids: list[str], read: bool = True) -> None:
|
|
163
|
+
path = "v7/notifications/mark-as-read" if read else "v7/notifications/mark-as-unread"
|
|
164
|
+
await self._request("PUT", path, json={"content": ids})
|
|
165
|
+
|
|
166
|
+
async def delete_notifications(self, ids: list[str]) -> None:
|
|
167
|
+
await self._request("DELETE", "v7/notifications", json={"content": ids})
|
|
168
|
+
|
|
169
|
+
# Account / misc
|
|
170
|
+
|
|
171
|
+
async def get_user_preferences(self) -> dict[str, Any]:
|
|
172
|
+
return await self._request("GET", "v9/user-preferences")
|
|
173
|
+
|
|
174
|
+
async def get_health(self) -> dict[str, Any] | None:
|
|
175
|
+
return await self._request("GET", "health-watcher/v1/health")
|
|
176
|
+
|
|
177
|
+
async def get_points_of_interest(self) -> list[dict[str, Any]]:
|
|
178
|
+
return await self._request("GET", "v3/pois")
|
|
179
|
+
|
|
180
|
+
@staticmethod
|
|
181
|
+
def image_url(production_profile_id: str) -> str:
|
|
182
|
+
return PRODUCTION_PROFILE_IMAGE_URL.format(profile_id=production_profile_id)
|
urban_arrow_api/const.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
from enum import StrEnum
|
|
2
|
+
|
|
3
|
+
# Extracted from com.urbanarrow.connected 5.2.1 (ConnectApp / LibraryConfig).
|
|
4
|
+
API_BASE_URL = "https://app.connected.pon.bike/api/"
|
|
5
|
+
AUTH0_DOMAIN = "consumer.login.pon.bike"
|
|
6
|
+
AUTH0_CLIENT_ID = "i2ype1HhtU4rg4LKRdBKgldnfVbVwrG6"
|
|
7
|
+
AUTH0_AUDIENCE = "https://app.connected.pon.bike/"
|
|
8
|
+
AUTH0_SCOPE = "openid profile offline_access email"
|
|
9
|
+
# Auth0 Android SDK builds the callback as {scheme}://{domain}/android/{package}/callback.
|
|
10
|
+
# The tenant only accepts registered callbacks, so we must reuse the app's one.
|
|
11
|
+
AUTH0_REDIRECT_URI = (
|
|
12
|
+
"urbanarrow://consumer.login.pon.bike/android/com.urbanarrow.connected/callback"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
# The same backend serves several Pon brands; "UA" selects Urban Arrow.
|
|
16
|
+
MANUFACTURER_ID = "UA"
|
|
17
|
+
CLIENT_TYPE = "ANDROID"
|
|
18
|
+
PRODUCTION_PROFILE_IMAGE_URL = (
|
|
19
|
+
"https://app.connected.pon.bike/api/v1/productionprofiles/{profile_id}/image"
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class BikeSetting(StrEnum):
|
|
24
|
+
AUTO_PROTECTION = "AUTO_PROTECTION"
|
|
25
|
+
NOTIFICATION_PROTECTION_ACTIVATED = "NOTIFICATION_PROTECTION_ACTIVATED"
|
|
26
|
+
MODULE_BATTERY_MANAGEMENT = "MODULE_BATTERY_MANAGEMENT"
|
|
27
|
+
NOTIFICATION_BATTERY_FULL = "NOTIFICATION_BATTERY_FULL"
|
|
28
|
+
NOTIFICATION_BATTERY_LOW = "NOTIFICATION_BATTERY_LOW"
|
|
29
|
+
NOTIFICATION_MODULE_BATTERY_LOW = "NOTIFICATION_MODULE_BATTERY_LOW"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ActivityPeriod(StrEnum):
|
|
33
|
+
WEEK = "WEEK"
|
|
34
|
+
MONTH = "MONTH"
|
|
35
|
+
QUARTER = "QUARTER"
|
|
36
|
+
YEAR = "YEAR"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class UrbanArrowError(Exception):
|
|
2
|
+
pass
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class UrbanArrowAuthError(UrbanArrowError):
|
|
6
|
+
"""Credentials are invalid or the refresh token was revoked; the user must log in again."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class UrbanArrowConnectionError(UrbanArrowError):
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class UrbanArrowApiError(UrbanArrowError):
|
|
14
|
+
def __init__(self, status: int, message: str) -> None:
|
|
15
|
+
super().__init__(f"HTTP {status}: {message}")
|
|
16
|
+
self.status = status
|
|
17
|
+
self.message = message
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class UrbanArrowCaptchaRequired(UrbanArrowAuthError):
|
|
21
|
+
pass
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class UrbanArrowMfaRequired(UrbanArrowAuthError):
|
|
25
|
+
pass
|
urban_arrow_api/login.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Headless username/password login through Auth0 Universal Login.
|
|
2
|
+
|
|
3
|
+
The password grant is disabled for the app's client, so we drive the hosted login
|
|
4
|
+
pages the way a browser without JavaScript would: identifier form, password form,
|
|
5
|
+
then follow redirects until Auth0 sends us to the app's ``urbanarrow://`` callback
|
|
6
|
+
carrying the authorization code. This depends on Auth0's page markup and breaks if
|
|
7
|
+
the tenant turns on bot detection (captcha) or MFA; those cases raise distinct
|
|
8
|
+
errors so callers can fall back to the manual browser flow.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import html
|
|
14
|
+
import re
|
|
15
|
+
from urllib.parse import urljoin
|
|
16
|
+
|
|
17
|
+
import aiohttp
|
|
18
|
+
|
|
19
|
+
from .auth import Token, create_login_request, exchange_code, extract_code
|
|
20
|
+
from .const import AUTH0_DOMAIN, AUTH0_REDIRECT_URI
|
|
21
|
+
from .exceptions import (
|
|
22
|
+
UrbanArrowAuthError,
|
|
23
|
+
UrbanArrowCaptchaRequired,
|
|
24
|
+
UrbanArrowConnectionError,
|
|
25
|
+
UrbanArrowMfaRequired,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
LOGIN_BASE = f"https://{AUTH0_DOMAIN}"
|
|
29
|
+
MAX_REDIRECTS = 10
|
|
30
|
+
# Auth0 adapts the page to these hints; claiming JS keeps us on the standard form.
|
|
31
|
+
BROWSER_HINTS = {
|
|
32
|
+
"js-available": "true",
|
|
33
|
+
"webauthn-available": "false",
|
|
34
|
+
"webauthn-platform-available": "false",
|
|
35
|
+
"is-brave": "false",
|
|
36
|
+
}
|
|
37
|
+
USER_AGENT = (
|
|
38
|
+
"Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 "
|
|
39
|
+
"(KHTML, like Gecko) Chrome/130.0 Mobile Safari/537.36"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
_STATE_RE = re.compile(r'<input[^>]*name="state"[^>]*value="([^"]+)"')
|
|
43
|
+
_ERROR_RE = re.compile(r'id="error-element-[\w-]+"[^>]*>(.*?)</', re.S)
|
|
44
|
+
# Match a real widget element, not the selector strings in Auth0's inline JS.
|
|
45
|
+
_CAPTCHA_RE = re.compile(r'<[a-z]+\b[^>]*\bdata-captcha-sitekey="[^"]+"')
|
|
46
|
+
_PROMPT_ALERT_RE = re.compile(r'id="prompt-alert"[^>]*>.*?<p[^>]*>(.*?)</p>', re.S)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _form_state(page: str) -> str:
|
|
50
|
+
match = _STATE_RE.search(page)
|
|
51
|
+
if not match:
|
|
52
|
+
raise UrbanArrowAuthError("Unexpected login page: no state field")
|
|
53
|
+
return html.unescape(match.group(1))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _page_error(page: str) -> str | None:
|
|
57
|
+
match = _ERROR_RE.search(page) or _PROMPT_ALERT_RE.search(page)
|
|
58
|
+
if not match:
|
|
59
|
+
return None
|
|
60
|
+
return html.unescape(re.sub(r"<[^>]+>", "", match.group(1))).strip() or None
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _check_blockers(url: str, page: str) -> None:
|
|
64
|
+
if _CAPTCHA_RE.search(page):
|
|
65
|
+
raise UrbanArrowCaptchaRequired("Auth0 requires a captcha; use the browser login")
|
|
66
|
+
if "/u/mfa" in url:
|
|
67
|
+
raise UrbanArrowMfaRequired("Account has MFA enabled; use the browser login")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
async def _follow(
|
|
71
|
+
session: aiohttp.ClientSession, resp: aiohttp.ClientResponse
|
|
72
|
+
) -> tuple[str | None, str, str]:
|
|
73
|
+
"""Follow redirects by hand so we can stop at the custom-scheme callback.
|
|
74
|
+
|
|
75
|
+
Returns ``(callback_url, last_page_url, last_page_body)``.
|
|
76
|
+
"""
|
|
77
|
+
for _ in range(MAX_REDIRECTS):
|
|
78
|
+
location = resp.headers.get("Location")
|
|
79
|
+
if resp.status not in (301, 302, 303, 307) or not location:
|
|
80
|
+
return None, str(resp.url), await resp.text()
|
|
81
|
+
if location.startswith(AUTH0_REDIRECT_URI.split("://")[0] + "://"):
|
|
82
|
+
return location, str(resp.url), ""
|
|
83
|
+
next_url = urljoin(str(resp.url), location)
|
|
84
|
+
if "/u/mfa" in next_url:
|
|
85
|
+
raise UrbanArrowMfaRequired("Account has MFA enabled; use the browser login")
|
|
86
|
+
resp = await session.get(next_url, allow_redirects=False)
|
|
87
|
+
raise UrbanArrowAuthError("Too many redirects during login")
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
async def login_with_credentials(
|
|
91
|
+
username: str,
|
|
92
|
+
password: str,
|
|
93
|
+
*,
|
|
94
|
+
session: aiohttp.ClientSession | None = None,
|
|
95
|
+
) -> Token:
|
|
96
|
+
"""Log in with email + password and return a token with a refresh token.
|
|
97
|
+
|
|
98
|
+
``session`` is used only for the final token exchange. The form steps always
|
|
99
|
+
run in a private session because they need their own cookie jar, which must
|
|
100
|
+
not leak into a shared Home Assistant session.
|
|
101
|
+
"""
|
|
102
|
+
req = create_login_request()
|
|
103
|
+
try:
|
|
104
|
+
async with aiohttp.ClientSession(
|
|
105
|
+
cookie_jar=aiohttp.CookieJar(),
|
|
106
|
+
headers={"User-Agent": USER_AGENT},
|
|
107
|
+
timeout=aiohttp.ClientTimeout(total=30),
|
|
108
|
+
) as form_session:
|
|
109
|
+
resp = await form_session.get(req.url, allow_redirects=False)
|
|
110
|
+
callback, url, page = await _follow(form_session, resp)
|
|
111
|
+
if callback is None:
|
|
112
|
+
_check_blockers(url, page)
|
|
113
|
+
state = _form_state(page)
|
|
114
|
+
resp = await form_session.post(
|
|
115
|
+
url,
|
|
116
|
+
data={
|
|
117
|
+
"state": state,
|
|
118
|
+
"username": username,
|
|
119
|
+
"action": "default",
|
|
120
|
+
**BROWSER_HINTS,
|
|
121
|
+
},
|
|
122
|
+
allow_redirects=False,
|
|
123
|
+
)
|
|
124
|
+
callback, url, page = await _follow(form_session, resp)
|
|
125
|
+
|
|
126
|
+
if callback is None:
|
|
127
|
+
_check_blockers(url, page)
|
|
128
|
+
if "/u/login/password" not in url:
|
|
129
|
+
raise UrbanArrowAuthError(_page_error(page) or "Unknown email address")
|
|
130
|
+
state = _form_state(page)
|
|
131
|
+
resp = await form_session.post(
|
|
132
|
+
url,
|
|
133
|
+
data={
|
|
134
|
+
"state": state,
|
|
135
|
+
"username": username,
|
|
136
|
+
"password": password,
|
|
137
|
+
"action": "default",
|
|
138
|
+
},
|
|
139
|
+
allow_redirects=False,
|
|
140
|
+
)
|
|
141
|
+
callback, url, page = await _follow(form_session, resp)
|
|
142
|
+
|
|
143
|
+
if callback is None:
|
|
144
|
+
_check_blockers(url, page)
|
|
145
|
+
raise UrbanArrowAuthError(_page_error(page) or "Invalid email or password")
|
|
146
|
+
|
|
147
|
+
code = extract_code(callback, req.state)
|
|
148
|
+
if session is not None:
|
|
149
|
+
return await exchange_code(session, code, req.code_verifier)
|
|
150
|
+
return await exchange_code(form_session, code, req.code_verifier)
|
|
151
|
+
except aiohttp.ClientError as err:
|
|
152
|
+
raise UrbanArrowConnectionError(str(err)) from err
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""Typed views over the API's JSON. Every model keeps the original payload in ``raw``
|
|
2
|
+
because field nullability was inferred from the decompiled app, not from a spec."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from datetime import UTC, date, datetime
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _ts(value: Any) -> datetime | None:
|
|
12
|
+
"""The backend sends timestamps as epoch milliseconds."""
|
|
13
|
+
if value is None:
|
|
14
|
+
return None
|
|
15
|
+
return datetime.fromtimestamp(int(value) / 1000, tz=UTC)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(slots=True)
|
|
19
|
+
class TimedValue[T]:
|
|
20
|
+
value: T | None
|
|
21
|
+
last_updated: datetime | None
|
|
22
|
+
|
|
23
|
+
@classmethod
|
|
24
|
+
def parse(cls, data: dict[str, Any] | None) -> TimedValue[T] | None:
|
|
25
|
+
if not data:
|
|
26
|
+
return None
|
|
27
|
+
return cls(data.get("value"), _ts(data.get("lastUpdatedOn")))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
@dataclass(slots=True)
|
|
31
|
+
class Location:
|
|
32
|
+
latitude: float
|
|
33
|
+
longitude: float
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(slots=True)
|
|
37
|
+
class Telemetry:
|
|
38
|
+
assist_level: TimedValue[int] | None
|
|
39
|
+
battery_charge: TimedValue[float] | None
|
|
40
|
+
battery_charging: TimedValue[bool] | None
|
|
41
|
+
location: TimedValue[Location] | None
|
|
42
|
+
module_charge: TimedValue[float] | None
|
|
43
|
+
odometer: TimedValue[float] | None
|
|
44
|
+
range: TimedValue[float] | None
|
|
45
|
+
raw: dict[str, Any] = field(repr=False)
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def parse(cls, data: dict[str, Any]) -> Telemetry:
|
|
49
|
+
battery = data.get("battery") or {}
|
|
50
|
+
coordinate = data.get("coordinate")
|
|
51
|
+
location = None
|
|
52
|
+
if coordinate and coordinate.get("value"):
|
|
53
|
+
loc = coordinate["value"]
|
|
54
|
+
location = TimedValue(
|
|
55
|
+
Location(loc["latitude"], loc["longitude"]),
|
|
56
|
+
_ts(coordinate.get("lastUpdatedOn")),
|
|
57
|
+
)
|
|
58
|
+
return cls(
|
|
59
|
+
assist_level=TimedValue.parse(data.get("assistLevel")),
|
|
60
|
+
battery_charge=TimedValue.parse(battery.get("charge")),
|
|
61
|
+
battery_charging=TimedValue.parse(battery.get("isCharging")),
|
|
62
|
+
location=location,
|
|
63
|
+
module_charge=TimedValue.parse(data.get("moduleCharge")),
|
|
64
|
+
odometer=TimedValue.parse(data.get("odometer")),
|
|
65
|
+
range=TimedValue.parse(data.get("range")),
|
|
66
|
+
raw=data,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(slots=True)
|
|
71
|
+
class BikeSummary:
|
|
72
|
+
id: str
|
|
73
|
+
frame_number: str | None
|
|
74
|
+
is_stolen: bool
|
|
75
|
+
model: str | None
|
|
76
|
+
nickname: str | None
|
|
77
|
+
production_profile_id: str | None
|
|
78
|
+
system: str | None
|
|
79
|
+
raw: dict[str, Any] = field(repr=False)
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def parse(cls, data: dict[str, Any]) -> BikeSummary:
|
|
83
|
+
return cls(
|
|
84
|
+
id=data["id"],
|
|
85
|
+
frame_number=data.get("frameNumber"),
|
|
86
|
+
is_stolen=bool(data.get("isStolen")),
|
|
87
|
+
model=data.get("model"),
|
|
88
|
+
nickname=data.get("nickname"),
|
|
89
|
+
production_profile_id=data.get("productionProfileId"),
|
|
90
|
+
system=data.get("system"),
|
|
91
|
+
raw=data,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(slots=True)
|
|
96
|
+
class Firmware:
|
|
97
|
+
branch: str | None
|
|
98
|
+
version: str | None
|
|
99
|
+
upgraded_on: datetime | None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(slots=True)
|
|
103
|
+
class Module:
|
|
104
|
+
id: str | None
|
|
105
|
+
auto_charge_enabled: bool
|
|
106
|
+
auto_protection_enabled: bool
|
|
107
|
+
protection_enabled: bool
|
|
108
|
+
can_data_supported: bool
|
|
109
|
+
supports_telemetry_over_ble: bool
|
|
110
|
+
last_online: datetime | None
|
|
111
|
+
firmware: Firmware | None
|
|
112
|
+
|
|
113
|
+
@classmethod
|
|
114
|
+
def parse(cls, data: dict[str, Any] | None) -> Module | None:
|
|
115
|
+
if not data:
|
|
116
|
+
return None
|
|
117
|
+
fw = data.get("firmware")
|
|
118
|
+
return cls(
|
|
119
|
+
id=data.get("id"),
|
|
120
|
+
auto_charge_enabled=bool(data.get("autoChargeEnabled")),
|
|
121
|
+
auto_protection_enabled=bool(data.get("autoProtectionEnabled")),
|
|
122
|
+
protection_enabled=bool(data.get("protectionEnabled")),
|
|
123
|
+
can_data_supported=bool(data.get("canDataSupported")),
|
|
124
|
+
supports_telemetry_over_ble=bool(data.get("supportsTelemetryOverBle")),
|
|
125
|
+
last_online=_ts(data.get("lastOnline")),
|
|
126
|
+
firmware=Firmware(fw.get("branch"), fw.get("version"), _ts(fw.get("upgradedOn")))
|
|
127
|
+
if fw
|
|
128
|
+
else None,
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@dataclass(slots=True)
|
|
133
|
+
class NotificationSettings:
|
|
134
|
+
battery_full: bool
|
|
135
|
+
battery_low: bool
|
|
136
|
+
module_battery_low: bool
|
|
137
|
+
protection_activated: bool
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@dataclass(slots=True)
|
|
141
|
+
class DataSubscription:
|
|
142
|
+
state: str | None
|
|
143
|
+
start_date: datetime | None
|
|
144
|
+
end_date: datetime | None
|
|
145
|
+
can_withdraw_until: datetime | None
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
@dataclass(slots=True)
|
|
149
|
+
class Bike:
|
|
150
|
+
id: str
|
|
151
|
+
frame_number: str | None
|
|
152
|
+
model: str | None
|
|
153
|
+
category: str | None
|
|
154
|
+
is_smart: bool
|
|
155
|
+
nickname: str | None
|
|
156
|
+
production_profile_id: str | None
|
|
157
|
+
system: str | None
|
|
158
|
+
protection_level: str | None
|
|
159
|
+
paired_on: datetime | None
|
|
160
|
+
module: Module | None
|
|
161
|
+
notifications: NotificationSettings | None
|
|
162
|
+
data_subscription: DataSubscription | None
|
|
163
|
+
raw: dict[str, Any] = field(repr=False)
|
|
164
|
+
|
|
165
|
+
@property
|
|
166
|
+
def name(self) -> str:
|
|
167
|
+
return self.nickname or self.model or self.id
|
|
168
|
+
|
|
169
|
+
@classmethod
|
|
170
|
+
def parse(cls, data: dict[str, Any]) -> Bike:
|
|
171
|
+
details = data.get("details") or {}
|
|
172
|
+
notif = data.get("notifications")
|
|
173
|
+
sub = data.get("dataSubscription")
|
|
174
|
+
return cls(
|
|
175
|
+
id=data["id"],
|
|
176
|
+
frame_number=details.get("frameNumber"),
|
|
177
|
+
model=details.get("model"),
|
|
178
|
+
category=details.get("category"),
|
|
179
|
+
is_smart=bool(details.get("isSmart")),
|
|
180
|
+
nickname=details.get("nickname"),
|
|
181
|
+
production_profile_id=details.get("productionProfileId"),
|
|
182
|
+
system=details.get("system"),
|
|
183
|
+
protection_level=details.get("protectionLevel"),
|
|
184
|
+
paired_on=_ts(details.get("pairedOn")),
|
|
185
|
+
module=Module.parse(data.get("module")),
|
|
186
|
+
notifications=NotificationSettings(
|
|
187
|
+
bool(notif.get("batteryFull")),
|
|
188
|
+
bool(notif.get("batteryLow")),
|
|
189
|
+
bool(notif.get("moduleBatteryLow")),
|
|
190
|
+
bool(notif.get("protectionActivated")),
|
|
191
|
+
)
|
|
192
|
+
if notif
|
|
193
|
+
else None,
|
|
194
|
+
data_subscription=DataSubscription(
|
|
195
|
+
sub.get("state"),
|
|
196
|
+
_ts(sub.get("startDate")),
|
|
197
|
+
_ts(sub.get("endDate")),
|
|
198
|
+
_ts(sub.get("canWithdrawUntil")),
|
|
199
|
+
)
|
|
200
|
+
if sub
|
|
201
|
+
else None,
|
|
202
|
+
raw=data,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
@dataclass(slots=True)
|
|
207
|
+
class Activity:
|
|
208
|
+
bicycle_id: str | None
|
|
209
|
+
period: str | None
|
|
210
|
+
start_date: date | None
|
|
211
|
+
values: list[float]
|
|
212
|
+
raw: dict[str, Any] = field(repr=False)
|
|
213
|
+
|
|
214
|
+
@classmethod
|
|
215
|
+
def parse(cls, data: dict[str, Any]) -> Activity:
|
|
216
|
+
start = data.get("startDate")
|
|
217
|
+
return cls(
|
|
218
|
+
bicycle_id=data.get("bicycleId"),
|
|
219
|
+
period=data.get("period"),
|
|
220
|
+
start_date=date.fromisoformat(start[:10]) if isinstance(start, str) else None,
|
|
221
|
+
values=[float(v) for v in data.get("values") or []],
|
|
222
|
+
raw=data,
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
@dataclass(slots=True)
|
|
227
|
+
class Notification:
|
|
228
|
+
id: str
|
|
229
|
+
bicycle_id: str | None
|
|
230
|
+
title: str | None
|
|
231
|
+
body: str | None
|
|
232
|
+
channel: str | None
|
|
233
|
+
type: str | None
|
|
234
|
+
unread: bool
|
|
235
|
+
created_on: datetime | None
|
|
236
|
+
raw: dict[str, Any] = field(repr=False)
|
|
237
|
+
|
|
238
|
+
@classmethod
|
|
239
|
+
def parse(cls, data: dict[str, Any]) -> Notification:
|
|
240
|
+
created = data.get("createdOn")
|
|
241
|
+
return cls(
|
|
242
|
+
id=data["id"],
|
|
243
|
+
bicycle_id=data.get("bicycleId"),
|
|
244
|
+
title=data.get("title"),
|
|
245
|
+
body=data.get("body"),
|
|
246
|
+
channel=data.get("channel"),
|
|
247
|
+
type=data.get("type"),
|
|
248
|
+
unread=bool(data.get("unread")),
|
|
249
|
+
created_on=_ts(created) if isinstance(created, int | float) else None,
|
|
250
|
+
raw=data,
|
|
251
|
+
)
|
urban_arrow_api/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: urban-arrow-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Async Python client for the Urban Arrow (Pon Connected) bike cloud API
|
|
5
|
+
Project-URL: Homepage, https://github.com/koenhendriks/urban-arrow-api
|
|
6
|
+
Project-URL: Issues, https://github.com/koenhendriks/urban-arrow-api/issues
|
|
7
|
+
Project-URL: Changelog, https://github.com/koenhendriks/urban-arrow-api/releases
|
|
8
|
+
Author: Koen Hendriks
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: cargo bike,e-bike,home assistant,pon,urban arrow
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Framework :: AsyncIO
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Home Automation
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Python: >=3.12
|
|
20
|
+
Requires-Dist: aiohttp>=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# urban-arrow-api
|
|
24
|
+
|
|
25
|
+
Async Python client for the cloud API behind the Urban Arrow app
|
|
26
|
+
(`com.urbanarrow.connected` 5.2.1). Intended as the library for a Home Assistant
|
|
27
|
+
integration.
|
|
28
|
+
|
|
29
|
+
The API is the shared **Pon Connected** backend (also used by Gazelle and other
|
|
30
|
+
Pon brands); the `Manufacturer-Id: UA` header selects Urban Arrow.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install urban-arrow-api
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv sync
|
|
42
|
+
uv run urban-arrow login you@example.com # prompts for password, stores ~/.config/urban-arrow/token.json
|
|
43
|
+
uv run urban-arrow browser-login # fallback: manual browser login
|
|
44
|
+
uv run urban-arrow status # bike details + telemetry as JSON
|
|
45
|
+
uv run urban-arrow raw GET v9/bikes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from urban_arrow_api import TokenAuth, UrbanArrowClient, login_with_credentials
|
|
50
|
+
|
|
51
|
+
async with aiohttp.ClientSession() as session:
|
|
52
|
+
token = await login_with_credentials("you@example.com", "password", session=session)
|
|
53
|
+
client = UrbanArrowClient(TokenAuth(session, token, on_token_update=save_token))
|
|
54
|
+
for summary in await client.get_bikes():
|
|
55
|
+
telemetry = await client.get_telemetry(summary.id)
|
|
56
|
+
print(telemetry.battery_charge, telemetry.location)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Authentication
|
|
60
|
+
|
|
61
|
+
| | |
|
|
62
|
+
|---|---|
|
|
63
|
+
| Auth0 tenant | `consumer.login.pon.bike` |
|
|
64
|
+
| Client ID | `i2ype1HhtU4rg4LKRdBKgldnfVbVwrG6` |
|
|
65
|
+
| Audience | `https://app.connected.pon.bike/` |
|
|
66
|
+
| Scope | `openid profile offline_access email` |
|
|
67
|
+
| Redirect URI | `urbanarrow://consumer.login.pon.bike/android/com.urbanarrow.connected/callback` |
|
|
68
|
+
|
|
69
|
+
The password grant is **disabled** for this client (`unauthorized_client`), so
|
|
70
|
+
there is no direct username/password token call. Instead,
|
|
71
|
+
`login_with_credentials(username, password)` (`login.py`) drives Auth0's hosted
|
|
72
|
+
login pages over plain HTTP, the way a browser without JavaScript would:
|
|
73
|
+
|
|
74
|
+
1. `GET /authorize` (PKCE) redirects to `/u/login/identifier?state=...`
|
|
75
|
+
2. `POST` `state` + `username` redirects to `/u/login/password?state=...`
|
|
76
|
+
3. `POST` `state` + `username` + `password` redirects to `/authorize/resume`,
|
|
77
|
+
which redirects to `urbanarrow://...callback?code=...`
|
|
78
|
+
4. The code is exchanged at `/oauth/token`, same as the app.
|
|
79
|
+
|
|
80
|
+
This works because the tenant currently has no captcha or MFA on the login
|
|
81
|
+
pages. If Auth0 starts showing a captcha or asks for MFA, it raises
|
|
82
|
+
`UrbanArrowCaptchaRequired` or `UrbanArrowMfaRequired`. The manual flow
|
|
83
|
+
(`create_login_request` + `extract_code` + `exchange_code`, CLI
|
|
84
|
+
`browser-login`) stays available as a fallback: log in in a browser and paste
|
|
85
|
+
the `urbanarrow://...?code=...` URL back.
|
|
86
|
+
|
|
87
|
+
After login the refresh token (`offline_access`) keeps the session alive.
|
|
88
|
+
`UrbanArrowClient` never handles tokens itself: it asks an `AbstractAuth` for
|
|
89
|
+
one via `async_get_access_token()`. `TokenAuth` is the ready-made
|
|
90
|
+
implementation; it refreshes through Auth0 and calls `on_token_update` so the
|
|
91
|
+
new token can be persisted (Auth0 may rotate refresh tokens). Override
|
|
92
|
+
`TokenAuth.async_refresh_token` to add a fallback such as a fresh login.
|
|
93
|
+
`Token.as_dict()` / `Token.from_dict()` give a JSON-serialisable form for
|
|
94
|
+
storage.
|
|
95
|
+
|
|
96
|
+
For Home Assistant: the config flow asks for email + password, and the
|
|
97
|
+
integration stores the token. It also stores the credentials, so if the refresh
|
|
98
|
+
token is ever revoked it can log in again silently, and only start a reauth
|
|
99
|
+
flow when that fails.
|
|
100
|
+
|
|
101
|
+
## Request headers
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
Authorization: Bearer <access_token>
|
|
105
|
+
Manufacturer-Id: UA
|
|
106
|
+
Client-Type: ANDROID
|
|
107
|
+
Accept-Language: <lang>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Endpoints
|
|
111
|
+
|
|
112
|
+
Base URL: `https://app.connected.pon.bike/api/`. Timestamps are epoch milliseconds.
|
|
113
|
+
|
|
114
|
+
| Method | Path | Notes | Client method |
|
|
115
|
+
|---|---|---|---|
|
|
116
|
+
| GET | `v9/bikes` | List of paired bikes | `get_bikes` |
|
|
117
|
+
| GET | `v11/bikes/{id}` | Details, module, firmware, subscription, notification settings | `get_bike` |
|
|
118
|
+
| GET | `v11/bikes/{id}/telemetry` | Battery %, charging, GPS, odometer, range, assist level, module charge | `get_telemetry` |
|
|
119
|
+
| GET | `v6/bikes/{id}/activity/history?timeUnit=&startDate=&cutoffDate=` | `timeUnit` WEEK/MONTH/QUARTER/YEAR, `startDate` yyyy-MM-dd, `cutoffDate` epoch ms (app uses pairing date). Returns `values: [double]` | `get_activity` |
|
|
120
|
+
| POST | `v1/bikes/{id}/flash-lights` | Blink lights (find my bike) | `flash_lights` |
|
|
121
|
+
| PUT | `v2/bikes/{id}/settings/{SETTING}/enable` / `disable` | `AUTO_PROTECTION`, `MODULE_BATTERY_MANAGEMENT`, `NOTIFICATION_*` | `set_setting` |
|
|
122
|
+
| PUT | `v1/bikes/{id}/theft/detection/mode` | `{"enabled": bool}` | `set_theft_protection` |
|
|
123
|
+
| PUT | `v1/bikes/{id}/nickname` | `{"nickname": str}` | `set_nickname` |
|
|
124
|
+
| GET | `v9/bikes/module/{moduleId}` | Bike by module id | `get_bike_by_module` |
|
|
125
|
+
| GET | `v10/bikes/frame-number/{frameNumber}` | `{isSmart, productionProfileId}` | `check_frame_number` |
|
|
126
|
+
| POST | `v4/bikes/{id}/theft/report` | `{policeReportNumber, customerPhoneNumber}` (PUT updates) | `report_theft` |
|
|
127
|
+
| POST | `v1/bikes/{id}/theft/cancel` | | `cancel_theft_report` |
|
|
128
|
+
| GET | `v4/notifications?version=6` | In-app inbox | `get_notifications` |
|
|
129
|
+
| PUT | `v7/notifications/mark-as-read` / `mark-as-unread` | `{"content": [ids]}` | `mark_notifications_read` |
|
|
130
|
+
| DELETE | `v7/notifications` | `{"content": [ids]}` | `delete_notifications` |
|
|
131
|
+
| GET | `v9/user-preferences` | `{preferredDealerId, theftNotificationSound}` | `get_user_preferences` |
|
|
132
|
+
| GET | `v3/pois` | Dealers / points of interest | `get_points_of_interest` |
|
|
133
|
+
| GET | `health-watcher/v1/health` | Backend status message (no auth needed) | `get_health` |
|
|
134
|
+
| GET | `v1/productionprofiles/{productionProfileId}/image` | Bike image | `image_url` |
|
|
135
|
+
|
|
136
|
+
Not wrapped (account/commerce, not useful for HA): pairing
|
|
137
|
+
(`v10/bikes/pairing/smart|non-smart`, `DELETE v10/bikes/{id}/pairing`),
|
|
138
|
+
insurance (`v9/bikes/{id}/insurance*`), subscription payments
|
|
139
|
+
(`v10/bikes/{id}/subscription/extension/payment/{variantId}`,
|
|
140
|
+
`v7/payments/sessions/*`, `v7/bikes/{id}/subscription/withdraw`), FCM push
|
|
141
|
+
registration (`v4/notifications/fcm/register`, `v1/notifications/fcm/unregister`),
|
|
142
|
+
dealers (`v3/dealers/...`), FAQ (`v4/faq`, `v3/faq/{id}`), route planning
|
|
143
|
+
(`v11/navigation/route`) and version checks (`v3/minimum-version/android`,
|
|
144
|
+
`v3/latest-release-version/ANDROID`). All reachable through `client._request`.
|
|
145
|
+
|
|
146
|
+
## Observed values (real Family Active Line Plus, BES2 system)
|
|
147
|
+
|
|
148
|
+
- `battery.charge` and `moduleCharge`: percent (72, 22). `moduleCharge` is the
|
|
149
|
+
connectivity module's own backup battery, not the e-bike battery.
|
|
150
|
+
- `odometer`: km with 2 decimals (1705.04). `range`: km (26.0).
|
|
151
|
+
- `assistLevel`: integer (4).
|
|
152
|
+
- Each telemetry value has its own `lastUpdatedOn`; battery and location can be
|
|
153
|
+
hours older than assist level / range, so they come from separate reports.
|
|
154
|
+
- Bike details also include `category` ("Bakfiets") and `isSmart`.
|
|
155
|
+
|
|
156
|
+
## Open questions
|
|
157
|
+
|
|
158
|
+
- Whether the refresh token rotates, and how long it lives.
|
|
159
|
+
- How often telemetry updates while the bike is parked or asleep.
|
|
160
|
+
|
|
161
|
+
## Development and releases
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
uv sync
|
|
165
|
+
uv run ruff check . && uv run ruff format --check . && uv run pytest
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Releases are published to PyPI by `.github/workflows/release.yaml` when a
|
|
169
|
+
GitHub release is published. The tag (`v0.1.0` or `0.1.0`) must match
|
|
170
|
+
`version` in `pyproject.toml`. PyPI trusted publishing has to be configured once
|
|
171
|
+
for the `pypi` environment of this repository.
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
urban_arrow_api/__init__.py,sha256=HuPKNcLr1Jb-t4zZ40G2KRLC-NnsjjFTl4LO6JLOp_4,1093
|
|
2
|
+
urban_arrow_api/__main__.py,sha256=6ujuW0qqZFUpVPgR1kO9LxepA5vZzKgAmJzG5jTYRXE,4666
|
|
3
|
+
urban_arrow_api/auth.py,sha256=BgXF358eiDatedv8Ss-EOY-qvAPbdnYfraH22ItsP_E,7312
|
|
4
|
+
urban_arrow_api/client.py,sha256=SXFo1f3M89aJ4O8HVXW526jFwrqpnyIBnMNpgjj7EQM,6868
|
|
5
|
+
urban_arrow_api/const.py,sha256=rlETy0gaq4INjXP-R1Ji6gfklYU3ufZc12SlfFAMpos,1381
|
|
6
|
+
urban_arrow_api/exceptions.py,sha256=NmNg0UI_1jfSIs9ZcVSqWIl-yZdZpvbM6qIpOqs3_E0,590
|
|
7
|
+
urban_arrow_api/login.py,sha256=JGif7Ber5-Yu_sk2A0Aftrl-1klFH8jfgJMJxH3DijM,5951
|
|
8
|
+
urban_arrow_api/models.py,sha256=XAYX-YiX4qQzppi8BDDksmB5jIezysYMaC_Oo7wUAj0,7708
|
|
9
|
+
urban_arrow_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
urban_arrow_api-0.1.0.dist-info/METADATA,sha256=_vgodY3BZYNMz_Hv6mmSQtMaFsOce9tZx3MEAQ195Dg,8143
|
|
11
|
+
urban_arrow_api-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
12
|
+
urban_arrow_api-0.1.0.dist-info/entry_points.txt,sha256=zDGZsteXxCw-kuwhDRK5Y6iH_lb5B1fcuiMykqDFVtw,62
|
|
13
|
+
urban_arrow_api-0.1.0.dist-info/licenses/LICENSE,sha256=_WG4kAsXw5-Lgq7V0k2GqYLSHE2bM4UeQWRJkXJROLg,1070
|
|
14
|
+
urban_arrow_api-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Koen Hendriks
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|