Skip to content

Commit 2e10e66

Browse files
committed
Allow webcam_uri to not be set
1 parent 326111a commit 2e10e66

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ readme = "README.rst"
66
license-files = ["LICENSE"]
77
requires-python = ">=3.9"
88
authors = [
9-
{ name = "Tim Schneider", email = "tim@meltingplot.net" },
109
{ name = "SimplyPrint", email = "dev@simplyprint.io" },
10+
{ name = "Tim Schneider", email = "tim@meltingplot.net" },
1111
]
1212
dependencies = [
1313
"aiohttp>=3.11.13",

simplyprint_duet3d/cli/autodiscover.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import ipaddress
2323
import json
2424
import urllib.parse
25+
from typing import Optional
2526

2627
import aiohttp
2728

@@ -97,7 +98,7 @@ def normalize_url(url: str) -> str:
9798
return f'http://{url}'
9899

99100

100-
async def connect_to_duet(address: str, password: str) -> dict:
101+
async def connect_to_duet(address: str, password: str) -> Optional[dict]:
101102
"""Connect to a printer using the specified IP address and password."""
102103
duet = RepRapFirmware(
103104
address=normalize_url(address),
@@ -110,20 +111,28 @@ async def connect_to_duet(address: str, password: str) -> dict:
110111
board = board['result']
111112
duet_name = await duet.rr_model(key='network.name')
112113
duet_name = duet_name['result']
113-
webcam_uri = await get_webcam_url(duet)
114+
115+
try:
116+
webcam_uri = await get_webcam_url(duet)
117+
except aiohttp.client_exceptions.ClientResponseError:
118+
webcam_uri = None
119+
114120
try:
115121
cookie = await get_cookie(duet)
116122
except aiohttp.client_exceptions.ClientResponseError:
117123
cookie = None
124+
125+
except aiohttp.client_exceptions.ClientResponseError as e:
126+
print(e)
127+
return None
118128
except (
119129
aiohttp.client_exceptions.ClientConnectorError,
120130
aiohttp.ClientError,
121131
asyncio.exceptions.CancelledError,
122132
asyncio.exceptions.TimeoutError,
123133
OSError,
124134
KeyError,
125-
) as e:
126-
print(e)
135+
):
127136
return None
128137
finally:
129138
await duet.close()
@@ -133,7 +142,7 @@ async def connect_to_duet(address: str, password: str) -> dict:
133142
'duet_uri': normalize_url(f'{address}'),
134143
'duet_password': password,
135144
'duet_unique_id': f"{board['uniqueId']}",
136-
'webcam_uri': normalize_url(webcam_uri),
145+
'webcam_uri': normalize_url(webcam_uri) if webcam_uri is not None else None,
137146
'cookie': cookie,
138147
}
139148

0 commit comments

Comments
 (0)