Skip to content
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

Adds support for EX511 router #54

Merged
merged 4 commits into from
Nov 15, 2024
Merged

Conversation

krlosrenan
Copy link
Contributor

This pull request adds support for the EX511 router, I tested it with the Home Assistant integration and it seems to be working.

Here I'm using the following version:
Firmware Version:0.7.0 3.0.0 v607e.0 Build 240930 Rel.11206n
Hardware Version:EX511 v2.0 00000000

If you want me to change anything, please let me know.

@AlexandrErohin
Copy link
Owner

AlexandrErohin commented Nov 11, 2024

Hi @krlosrenan
Thank you very much for this!
Could you create file test_client_ex.py and write tests for methods please ? like for Tp-Link MR here - https://github.com/AlexandrErohin/TP-Link-Archer-C6U/blob/main/test/test_client_mr.py

Tests are needed for supporting the router, as there is always would need to fix something in code and without tests it would be very difficult to do

class TplinkRouterProvider:
@staticmethod
def get_client(host: str, password: str, username: str = 'admin', logger: Logger = None,
verify_ssl: bool = True, timeout: int = 30) -> AbstractRouter:
for client in [TplinkC5400XRouter, TPLinkMRClient, TplinkC6V4Router, TPLinkDecoClient, TplinkRouter]:
for client in [TPLinkEXClient, TplinkC5400XRouter, TPLinkMRClient, TplinkC6V4Router, TPLinkDecoClient, TplinkRouter]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change it to

for client in [TplinkC5400XRouter, TPLinkMRClient, TPLinkEXClient, TplinkC6V4Router, TPLinkDecoClient, TplinkRouter]:

and test for your router TplinkRouterProvider.get_client(...) as there is a possibility that requests for TPLinkEXClient may take the main role before TPLinkMRClient. As we dont have now MR router - so it is better to test it in reverse order

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About creating test_client_ex.py, it will take me a few days, but I can create it too.

About the order, if we change the order, it will always assume MR, since the MR test consists of a query to /getParm, and EX511 also has this query, so MR will return true.

Another possibility would be to make the EX test more robust.

What do you think of this solution:

   def supports(self) -> bool:
        try:
            supported_routers = ['EX511', 'EX220']

            url = self._get_url('js/oid_str.js')
            (code, response) = self._request(url)
            assert code == 200
            
            pattern = r'\s*var\s+INCLUDE_BOOT_AGINETCONFIG_MODEL\s*=\s*"([^"]*)"'
            match = search(pattern, response)
            assert match and match.group(1) in supported_routers

            self._req_rsa_key()
            return True
        except AssertionError:
            return False

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you could add tests test_client_ex.py. Thank you!
In your client method supports calls self._get_url('cgi/getGDPRParm'). In MR client method supports calls self._get_url('cgi/getParm'), So your router can response on self._get_url('cgi/getGDPRParm') and self._get_url('cgi/getParm') with same response?

Adding routers model to the method supports - greatly reduces the possibilities. As I was very surprised how many different types routers have same API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 - I added the tests (test_client_ex.py)
2 - Yes, the router I tested on responds to "cgi/getGDPRParm" and "cgi/getParm" in the same way.
3 - I believe this new model will support several other routers

Looking at the oid_str.js file, I noticed that there are possibly several other routers that may be supported.

Note the lines that start with INCLUDE_SPEC_

I will test it on a friend's EX220 soon.

I am attaching the file.
oid_str.txt

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 - Thank you for the tests
2 - Thats bad. Because this may break the MR support. I will try to find MR series router - to check response to "cgi/getGDPRParm". Hope it doesnt have

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this won't be a problem because I adjusted the supports method so that it only responds positively for the EX511 and EX220 models.

Before, the verification was only by requesting getGDPRParm, but now, in addition to that, the router needs to be on the list of supported models.

However, it would be great to test on a MR, because if there is no conflict, we could simplify the code so that it could support models that we haven't tested, but that use the same API.

If you need to change anything else, let me know.

@AlexandrErohin AlexandrErohin merged commit 91d1e69 into AlexandrErohin:main Nov 15, 2024
0 of 4 checks passed
@AlexandrErohin
Copy link
Owner

Could you please post the hardware version for EX220 - when you test it?

@AlexandrErohin
Copy link
Owner

I have tested it with MR router and it works - I have changed support method.
Could you pull the changes from main branch and test for your router please? If it works - Ill push the new client version

Thank you for help and for your work for adding support for your router

@krlosrenan
Copy link
Contributor Author

I have tested it with MR router and it works - I have changed support method.
Could you pull the changes from main branch and test for your router please? If it works - Ill push the new client version

Thank you for help and for your work for adding support for your router

Everything is working. I just did some tests and no errors occurred.

@krlosrenan
Copy link
Contributor Author

@krlosrenan Hi Could you add

Hello, in a few minutes I will make the pull request.

@lebdim
Copy link

lebdim commented Nov 20, 2024

This implementation works for NX510v as well.

388243139-8927e979-2257-4879-bd63-5a0ce8afdee4

@AlexandrErohin
Copy link
Owner

@lebdim Thank you for the info!
P.S. Would be great if you could give a star to the repo :) Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants