Skip to content

Commit

Permalink
Merge pull request adafruit#205 from vladak/web_api_check
Browse files Browse the repository at this point in the history
refuse any device with web API version stricly less than 4
  • Loading branch information
dhalbert committed Mar 9, 2024
2 parents 38dd524 + eb108fe commit 27ae1f9
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions circup/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,31 @@ def get_file_path(self, filename):

def is_device_present(self):
"""
returns True if the device is currently connected
returns True if the device is currently connected and running supported version
"""
try:
_ = self.session.get(f"{self.device_location}/cp/version.json")
return True
with self.session.get(f"{self.device_location}/cp/version.json") as r:
r.raise_for_status()
web_api_version = r.json().get("web_api_version")
if web_api_version is None:
self.logger.error("Unable to get web API version from device.")
click.secho("Unable to get web API version from device.", fg="red")
return False

if web_api_version < 4:
self.logger.error(
f"Device running unsupported web API version {web_api_version} < 4."
)
click.secho(
f"Device running unsupported web API version {web_api_version} < 4.",
fg="red",
)
return False
except requests.exceptions.ConnectionError:
return False

return True

def get_device_versions(self):
"""
Returns a dictionary of metadata from modules on the connected device.
Expand Down

0 comments on commit 27ae1f9

Please sign in to comment.