Skip to content

Commit 3e5ba26

Browse files
committed
fix camera feed for yuka to just one camera for now
1 parent dee1a94 commit 3e5ba26

File tree

4 files changed

+15
-37
lines changed

4 files changed

+15
-37
lines changed

pymammotion/agora/agora_api.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import logging
1515
from random import randint
1616
import time
17+
from types import TracebackType
18+
from typing import Any
1719

1820
import aiohttp
19-
from types import TracebackType
20-
from typing import Optional, Type
2121

2222
# Service IDs for API requests (what you send in the request)
2323
SERVICE_IDS = {
@@ -112,7 +112,7 @@ class AgoraResponse:
112112
detail: dict
113113
flag: int
114114
opid: int
115-
responses: dict = None # Multi-flag responses: {flag: response_dict}
115+
responses: dict | None = None # Multi-flag responses: {flag: response_dict}
116116

117117
@classmethod
118118
def from_api_response(cls, response_data: dict) -> "AgoraResponse":
@@ -507,7 +507,9 @@ async def __aenter__(self):
507507
"""Context manager entry."""
508508
return self
509509

510-
async def __aexit__(self, exc_type: Optional[Type[BaseException]], exc_val: Optional[BaseException], exc_tb: Optional[TracebackType]) -> None:
510+
async def __aexit__(
511+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
512+
) -> None:
511513
"""Context manager exit - close session if we created it."""
512514
if self._own_session and self.session:
513515
await self.session.close()
@@ -795,7 +797,7 @@ async def _call_endpoint(
795797
domain: str,
796798
request_payload: dict,
797799
proxy_server: str | None = None,
798-
) -> dict:
800+
) -> Any:
799801
"""Call a single Agora endpoint.
800802
801803
Args:
@@ -826,5 +828,4 @@ async def _call_endpoint(
826828
if resp.status != 200:
827829
raise Exception(f"HTTP {resp.status}: {await resp.text()}")
828830

829-
response_data = await resp.json()
830-
return response_data
831+
return await resp.json()

pymammotion/http/http.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -290,40 +290,17 @@ async def net_rtk_enable(self, device_id: str) -> Response:
290290
return Response.from_dict(data)
291291

292292
@refresh_token_decorator
293-
async def get_stream_subscription(self, iot_id: str) -> Response[StreamSubscriptionResponse]:
294-
"""Fetches stream subscription data from agora.io for a given IoT device."""
295-
resp = await self._session.post(
296-
f"{MAMMOTION_API_DOMAIN}/device-server/v1/stream/subscription",
297-
json={"deviceId": iot_id},
298-
headers={
299-
**self._headers,
300-
"Authorization": f"Bearer {self.login_info.access_token}",
301-
"Content-Type": "application/json",
302-
"User-Agent": "okhttp/4.9.3",
303-
},
304-
)
305-
data = await resp.json()
306-
# TODO catch errors from mismatch like token expire etc
307-
# Assuming the data format matches the expected structure
308-
response = Response[StreamSubscriptionResponse].from_dict(data)
309-
await self.handle_expiry(response)
310-
if response.code != 0:
311-
return response
312-
response.data = StreamSubscriptionResponse.from_dict(data.get("data", {}))
313-
return response
314-
315-
@refresh_token_decorator
316-
async def get_stream_subscription_mini_or_x_series(
317-
self, iot_id: str, is_yuka: bool
318-
) -> Response[StreamSubscriptionResponse]:
293+
async def get_stream_subscription(self, iot_id: str, is_yuka: bool) -> Response[StreamSubscriptionResponse]:
319294
# Prepare the payload with cameraStates based on is_yuka flag
320295
"""Fetches stream subscription data for a given IoT device."""
321296

322297
payload = {"deviceId": iot_id, "mode": 0, "cameraStates": []}
323298

324299
# Add appropriate cameraStates based on the is_yuka flag
300+
# yukas have two cameras you could view [{"cameraState": 1}, {"cameraState": 0}, {"cameraState": 1}]
301+
# but its not useful so ignore this and only subscribe to the front one.
325302
if is_yuka:
326-
payload["cameraStates"] = [{"cameraState": 1}, {"cameraState": 0}, {"cameraState": 1}]
303+
payload["cameraStates"] = [{"cameraState": 1}, {"cameraState": 0}, {"cameraState": 0}]
327304
else:
328305
payload["cameraStates"] = [{"cameraState": 1}, {"cameraState": 0}, {"cameraState": 0}]
329306

pymammotion/mammotion/devices/mammotion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ async def start_schedule_sync(self, name: str) -> None:
542542
async def get_stream_subscription(self, name: str, iot_id: str) -> Response[StreamSubscriptionResponse] | Any:
543543
"""Get stream subscription."""
544544
device = self.get_device_by_name(name)
545-
_stream_response = await device.mammotion_http.get_stream_subscription_mini_or_x_series(
545+
_stream_response = await device.mammotion_http.get_stream_subscription(
546546
iot_id, DeviceType.is_yuka(name) and not DeviceType.is_yuka_mini(name)
547547
)
548548
_LOGGER.debug(_stream_response)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "pymammotion"
7-
version = "0.5.72"
7+
version = "0.5.73"
88
description = ""
99
authors = [
1010
{ name = "Michael Arthur", email = "michael@jumblesoft.co.nz" },
@@ -68,7 +68,7 @@ include = ["pymammotion"]
6868
include = ["pymammotion"]
6969

7070
[tool.bumpver]
71-
current_version = "0.5.72"
71+
current_version = "0.5.73"
7272
version_pattern = "MAJOR.MINOR.PATCH"
7373
commit_message = "Bump version {old_version} -> {new_version}"
7474
commit = true

0 commit comments

Comments
 (0)