@@ -32,9 +32,15 @@ async def _get_software_version(vid: int, pid: int, software_version: int) -> An
32
32
33
33
34
34
async def _check_update_version (
35
- vid : int , pid : int , version : int , current_software_version : int
35
+ vid : int ,
36
+ pid : int ,
37
+ current_software_version : int ,
38
+ requested_software_version : int ,
39
+ requested_software_version_string : str | None = None ,
36
40
) -> None | dict :
37
- version_res : dict = await _get_software_version (vid , pid , version )
41
+ version_res : dict = await _get_software_version (
42
+ vid , pid , requested_software_version
43
+ )
38
44
if not isinstance (version_res , dict ):
39
45
raise TypeError ("Unexpected DCL response." )
40
46
@@ -43,6 +49,14 @@ async def _check_update_version(
43
49
44
50
version_candidate : dict = cast (dict , version_res ["modelVersion" ])
45
51
52
+ # If we are looking for a specific version by string, check if it matches
53
+ if (
54
+ requested_software_version_string is not None
55
+ and version_candidate ["softwareVersionString" ]
56
+ != requested_software_version_string
57
+ ):
58
+ return None
59
+
46
60
# Check minApplicableSoftwareVersion/maxApplicableSoftwareVersion
47
61
min_sw_version = version_candidate ["minApplicableSoftwareVersion" ]
48
62
max_sw_version = version_candidate ["maxApplicableSoftwareVersion" ]
@@ -59,13 +73,14 @@ async def check_for_update(
59
73
vid : int ,
60
74
pid : int ,
61
75
current_software_version : int ,
62
- requested_software_version : int | None = None ,
76
+ requested_software_version : int | str | None = None ,
63
77
) -> None | dict :
64
78
"""Check if there is a software update available on the DCL."""
65
79
try :
66
- if requested_software_version is not None :
80
+ # If a specific version as integer is requested, just fetch it (and hope it exists)
81
+ if isinstance (requested_software_version , int ):
67
82
return await _check_update_version (
68
- vid , pid , requested_software_version , current_software_version
83
+ vid , pid , current_software_version , requested_software_version
69
84
)
70
85
71
86
# Get all versions and check each one of them.
@@ -78,15 +93,15 @@ async def check_for_update(
78
93
if version > current_software_version
79
94
]
80
95
81
- # Check if there is a newer software version available
96
+ # Check if there is a newer software version available, no downgrade possible
82
97
if not newer_software_versions :
83
98
LOGGER .info ("No newer software version available." )
84
99
return None
85
100
86
101
# Check if latest firmware is applicable, and backtrack from there
87
102
for version in sorted (newer_software_versions , reverse = True ):
88
103
if version_candidate := await _check_update_version (
89
- vid , pid , version , current_software_version
104
+ vid , pid , current_software_version , version , requested_software_version
90
105
):
91
106
return version_candidate
92
107
LOGGER .debug ("Software version %d not applicable." , version )
0 commit comments