-
-
Couldn't load subscription status.
- Fork 83
Check firmware version even without write access #428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR refactors firmware version handling by introducing a dedicated, read-only method to fetch and parse the RouterOS version, ensuring version checks work without write access, and updates the firmware update workflow accordingly. Sequence diagram for firmware version check in firmware update processsequenceDiagram
participant Coordinator
participant MikroTikAPI
Coordinator->>Coordinator: get_firmware_update()
Coordinator->>Coordinator: get_firmware_version()
Coordinator->>MikroTikAPI: query /system/resource
MikroTikAPI-->>Coordinator: version string
Coordinator->>Coordinator: Parse version, set major/minor
Coordinator->>Coordinator: Continue firmware update logic
Class diagram for firmware version handling refactorclassDiagram
class Coordinator {
+get_firmware_version()
+get_firmware_update()
major_fw_version
minor_fw_version
}
Coordinator : - get_firmware_version() is a new method
Coordinator : - get_firmware_update() now calls get_firmware_version()
Coordinator : - major_fw_version and minor_fw_version are set by get_firmware_version()
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @nathan818fr - I've reviewed your changes - here's some feedback:
- After failing to parse the version, you don't reset major_fw_version/minor_fw_version—set explicit defaults there to avoid carrying over stale values.
- The try/except around version parsing catches all exceptions; narrow it to ValueError (or specific parsing errors) so you don’t mask unexpected failures.
- The custom regex may not cover all RouterOS version strings—consider using a standard version‐parsing utility or extending the pattern to handle suffixes and patch numbers.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- After failing to parse the version, you don't reset major_fw_version/minor_fw_version—set explicit defaults there to avoid carrying over stale values.
- The try/except around version parsing catches all exceptions; narrow it to ValueError (or specific parsing errors) so you don’t mask unexpected failures.
- The custom regex may not cover all RouterOS version strings—consider using a standard version‐parsing utility or extending the pattern to handle suffixes and patch numbers.
## Individual Comments
### Comment 1
<location> `custom_components/mikrotik_router/coordinator.py:1580` </location>
<code_context>
+
+ full_version = resources["version"]
+ try:
+ version_match = re.match(r"^(\d+)\.(\d+)\.(\d+)", full_version)
+ if not version_match:
+ raise ValueError("Version format is not recognized")
+ version_major = int(version_match.group(1))
+ version_minor = int(version_match.group(2))
+ except Exception as e:
+ _LOGGER.error(
</code_context>
<issue_to_address>
Regex may not match all valid version formats.
The current regex may not handle versions like '7.12beta3'. Please update it to support such cases or add explicit handling.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
try:
version_match = re.match(r"^(\d+)\.(\d+)\.(\d+)", full_version)
if not version_match:
raise ValueError("Version format is not recognized")
version_major = int(version_match.group(1))
version_minor = int(version_match.group(2))
except Exception as e:
=======
try:
# Match versions like 7.12.1, 7.12beta3, 7.12, etc.
version_match = re.match(r"^(\d+)\.(\d+)", full_version)
if not version_match:
raise ValueError("Version format is not recognized")
version_major = int(version_match.group(1))
version_minor = int(version_match.group(2))
except Exception as e:
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| try: | ||
| version_match = re.match(r"^(\d+)\.(\d+)\.(\d+)", full_version) | ||
| if not version_match: | ||
| raise ValueError("Version format is not recognized") | ||
| version_major = int(version_match.group(1)) | ||
| version_minor = int(version_match.group(2)) | ||
| except Exception as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Regex may not match all valid version formats.
The current regex may not handle versions like '7.12beta3'. Please update it to support such cases or add explicit handling.
| try: | |
| version_match = re.match(r"^(\d+)\.(\d+)\.(\d+)", full_version) | |
| if not version_match: | |
| raise ValueError("Version format is not recognized") | |
| version_major = int(version_match.group(1)) | |
| version_minor = int(version_match.group(2)) | |
| except Exception as e: | |
| try: | |
| # Match versions like 7.12.1, 7.12beta3, 7.12, etc. | |
| version_match = re.match(r"^(\d+)\.(\d+)", full_version) | |
| if not version_match: | |
| raise ValueError("Version format is not recognized") | |
| version_major = int(version_match.group(1)) | |
| version_minor = int(version_match.group(2)) | |
| except Exception as e: |
e.g. "7.10beta1", "7.10rc1"
|
pretty sure this would just enable update entity which needs write access to function. |
|
From what I understand, This commit only changes how these two variables are set, but does not affect the For me, this change allowed some features that were not working before to function properly (specifically those that depend on a version check):
|
Proposed change
The current firmware version check requires
write+policy+rebootaccess.This prevents some features from working when only
read+apiaccess are granted (e.g. #381).This method appears to be compatible with both RouterOS 6 and 7 (according to the MikroTik documentation), but I have only tested it on RouterOS 7.
Type of change
Checklist
Summary by Sourcery
Enable firmware version checks using only read and API access by introducing a read-only retrieval method and removing write-dependent parsing
New Features:
Enhancements: