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

Unsupported model: F@ST F5359 / KPN Box 12 #19

Closed
geert36 opened this issue Apr 18, 2021 · 45 comments · Fixed by #18
Closed

Unsupported model: F@ST F5359 / KPN Box 12 #19

geert36 opened this issue Apr 18, 2021 · 45 comments · Fixed by #18
Assignees
Labels
enhancement New feature or request

Comments

@geert36
Copy link

geert36 commented Apr 18, 2021

I recently got the Sagemcom box F@ST F5359. It is the new modem distributed by KPN known as the Box 12.

I tried to get some more information with executing $.xmo.getValuesTree("Device/DeviceInfo"); in the web console, this results in nothing.

Is it possible to support this device? Please let me know if you need more information.
I want to use it for presence detection in Home Assistant.

Model information

Key Value
Model name F@ST F5359
Hardware Version 1.0
Software Version SGEJ10000310
@iMicknl
Copy link
Owner

iMicknl commented Apr 18, 2021

When you are logged in, do you see any XHR requests in DevTools -> Network? See https://stackoverflow.com/questions/1820927/request-monitoring-in-chrome.

@geert36
Copy link
Author

geert36 commented Apr 20, 2021

Yes, I see json-req:
vendor.js?abc2f5c9832d68eb:3 XHR finished loading: POST "https://mijnmodem.kpn/cgi/json-req".

@iMicknl
Copy link
Owner

iMicknl commented Apr 21, 2021

@geert36 I am not sure how to debug this, do you have some Python knowledge? It seems that you have the JSON-REQ API, however it could be that you need mijnmodem.kpn instead of the IP address. However, by default it will communicate via HTTP...

Have you tried setting it up in Home Assistant or directly via the Python test script? What kind of error do you see in your logs.

@geert36
Copy link
Author

geert36 commented Apr 22, 2021

I don't have any Python knowledge. But if is just running some code, I think I can manage it.

Yes, already tried to set it up in Home Assistant. I tried mijnmodem.kpn and the default gateway adress, both encryption methods. All with the same result: "Request timed-out. This is mainly caused by selection of the wrong encryption method"

@iMicknl
Copy link
Owner

iMicknl commented Apr 28, 2021

If you login, will it do a HTTPS request to https://mijnmodem.kpn/cgi/json-req as well? It would require some code changes to support this perhaps.

@geert36
Copy link
Author

geert36 commented Apr 29, 2021

Yes, correct, https://mijnmodem.kpn/cgi/json-req is requested.

@iMicknl
Copy link
Owner

iMicknl commented May 1, 2021

@geert36 could you give https://github.com/iMicknl/ha-sagemcom-fast/archive/refs/heads/feature/add_ssl_support.zip a try? Extract this file and place custom_components/sagemcom_fast in your custom_components folder. (overwrite the previous one).

@geert36
Copy link
Author

geert36 commented May 2, 2021

Tried with the new files, but get the following error:
__init__() got an unexpected keyword argument 'ssl' Traceback (most recent call last): File "/config/custom_components/sagemcom_fast/config_flow.py", line 70, in async_step_user return await self.async_validate_input(user_input) File "/config/custom_components/sagemcom_fast/config_flow.py", line 47, in async_validate_input async with SagemcomClient( File "/usr/local/lib/python3.8/site-packages/sagemcom_api/client.py", line 80, in __init__ else ClientSession( TypeError: __init__() got an unexpected keyword argument 'ssl'

@iMicknl
Copy link
Owner

iMicknl commented May 2, 2021

@geert36 it should install the development version, that includes this fix, however it seems that this is not working in your install. I will see if I can prepare it in another way..

@iMicknl
Copy link
Owner

iMicknl commented May 2, 2021

@geert36 could you give it a new try? Just download the same zip folder again and repeat the same steps :). Make sure you select Uses SSL certificate!

@iMicknl iMicknl self-assigned this May 2, 2021
@geert36
Copy link
Author

geert36 commented May 2, 2021

Hi Mick, thanks for the update. This one works with the SHA512 encryption! I didn't check any of the check boxes (there is no text behind the check boxes).
So now the integration is added in HA, but the next error appeared:
{'code': 16777225, 'description': 'XMO_MAX_SESSION_COUNT_ERR'} Traceback (most recent call last): File "/config/custom_components/sagemcom_fast/config_flow.py", line 81, in async_step_user return await self.async_validate_input(user_input) File "/config/custom_components/sagemcom_fast/config_flow.py", line 66, in async_validate_input await client.login() File "/usr/local/lib/python3.8/site-packages/sagemcom_api/client.py", line 271, in login response = await self.__api_request_async([actions], True) File "/usr/local/lib/python3.8/site-packages/sagemcom_api/client.py", line 241, in __api_request_async raise UnknownException(action_error) sagemcom_api.exceptions.UnknownException: {'code': 16777225, 'description': 'XMO_MAX_SESSION_COUNT_ERR'}

@iMicknl
Copy link
Owner

iMicknl commented May 2, 2021

@geert36 that is weird, it should only work with the SSL check box selected. What did you fill in as host? Could you reboot and try it again + share a screenshot of your the 'new integration' form popup?

I will make sure we catch XMO_MAX_SESSION_COUNT_ERR, I hadn't seen that before. But it seems that you can only have one login session at the same time... Can you add multiple users?

@iMicknl iMicknl transferred this issue from iMicknl/python-sagemcom-api May 2, 2021
@iMicknl
Copy link
Owner

iMicknl commented May 2, 2021

@geert36 I just published a new version (same URL as before). In your case, you should be able to select 'Uses an SSL certificate':

Please let me know if it works or if you have any errors in the log.

Screen Shot 2021-05-02 at 22 44 16

@iMicknl iMicknl added the enhancement New feature or request label May 2, 2021
@iMicknl iMicknl linked a pull request May 2, 2021 that will close this issue
@geert36
Copy link
Author

geert36 commented May 3, 2021

I deleted the integration and uploaded the new files. When adding the new integration, I get the following screen: 2021_05_03_12_18_46_Window

So the integration is added and no more errors in the log file. Unfortunately no device is created or displayed in the device tab.
2021_05_03_12_32_26_Window

@iMicknl
Copy link
Owner

iMicknl commented May 3, 2021

I think you face the MaximumSessionCount again, but I accidentally changed the logging to something that is not supported in the current (non-dev) Home Assistant version yet... I added back the logging.

I wonder if this session will be killed after some time, thus that it could work after a day or so...

@geert36
Copy link
Author

geert36 commented May 3, 2021

Correct, the error is back in the logging:
2021-05-03 17_51_44-Instellingen - Home Assistant

I will wait for 24 hours and let you know if it starts working.
This is a well-known error for me, I saw this error regardly in the web UI of the KPN box.

@geert36
Copy link
Author

geert36 commented May 3, 2021

Short after taking the screenshot of previous post, fetching of data succeeded:
2021-05-03 16:13:29 DEBUG (MainThread) [custom_components.sagemcom_fast] Finished fetching sagemcom_hosts data in 0.570 seconds
2021-05-03 19:43:18 ERROR (MainThread) [custom_components.sagemcom_fast] Error fetching sagemcom_hosts data: Error communicating with API: list index out of range
2021-05-03 19:43:18 DEBUG (MainThread) [custom_components.sagemcom_fast] Finished fetching sagemcom_hosts data in 0.354 seconds

@iMicknl
Copy link
Owner

iMicknl commented May 3, 2021

But does it work? :-). Did it create devices / entities?

@geert36
Copy link
Author

geert36 commented May 3, 2021

Hmm no, unfortunately not. Still no devices /entities :( How can I help you to solve this?

@github-actions
Copy link

github-actions bot commented Jun 3, 2021

'There hasn't been any activity on this issue recently. Is this issue still present?
Please make sure to update to the latest Home Assistant version and version of this integration to see if that solves the issue. Let us know if that works for you by adding a comment 👍.
This issue now has been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.'

@copini
Copy link

copini commented Sep 18, 2021

The main issue with this device (besides the SSL requirement) is that querying Device/DeviceInfo yields an XMO_UNKNOWN_PATH_ERR error instead of device info. This custom component currently relies on that query (through client.get_device_info()) to work.

Querying individual values does work (as does client.get_hosts()), so it is possible to work around the problem by changing a few things in async_setup_entry. Instead of relying on client.get_device_info() you could use client.get_value_by_xpath() to get the individual values required to register the device in Home Assistant. The only thing I couldn't get is the device manufacturer, but I guess that could be hardcoded. The rest works:

Device/DeviceInfo/MACAddress: 84:1E:A3:xx:xx:xx
Device/DeviceInfo/SerialNumber: xxxxx
Device/DeviceInfo/ModelNumber: sagemcom_fast5359__kpn
Device/DeviceInfo/ModelName: F5359
Device/DeviceInfo/SoftwareVersion: SGEJ10000310

I'm just not sure if this would work for all other devices supported by this integration as well. Otherwise maybe this could be a toggle in the setup just like SSL support, what do you think?

I'm also wondering if there are more new Sagemcom F@st devices with this issue, and if perhaps it should be addressed in python-sagemcom-api instead?

@copini
Copy link

copini commented Sep 18, 2021

Another issue is related to the XMO_MAX_SESSION_COUNT_ERR error mentioned earlier. This device indeed seems to allow only one active session per user, and it has only one fixed (admin) user. There's no option to create extra accounts.

As this integration does not log out from the admin session, it can effectively lock you out from using the modem web interface because it's scanning every 10 seconds (by default).

It would be great if the logout API command ({"method": "logOut"}) could be added to python-sagemcom-api and this integration would log out after every scan. That way we can still log in to the web interface most of the time. The integration would not work while being logged in though, so it's best to manually log out when you're done instead of closing the browser tab (otherwise the integration can't scan for another 5 minutes).

@copini
Copy link

copini commented Sep 19, 2021

I created a very simplistic pull request that fixes the main issue. This does not solve the MaximumSessionCount issue, but it does make the device work in Home Assistant.

I got the MaximumSessionCount error on the first setup attempt, but devices started to show up a few minutes later. You can try it out in my fork (merged it to master there so it's easy to get up and running in HACS). I recommend setting the scan interval to at least 5 minutes until the MaximumSessionCount/logout problem is fixed so you're not locked out of the device's web interface.

@rhpijnacker
Copy link
Contributor

Any progress on this?
I just stumbled upon this and would love to connect my HA to my KPN Box v12.
If needed I would be happy to hack away on some code to get this to work.

@iMicknl
Copy link
Owner

iMicknl commented Dec 1, 2021

@rhpijnacker unfortunately I haven't had much time lately to work on this integration. I would be happy to release a new version, if someone has time to help out a bit.

@rhpijnacker
Copy link
Contributor

@iMicknl I send some PRs.
To make this work we will need to logout after every login/query.
With these change's I'm seeing devices and entities getting created, which is how far the current integration goes, right?
What would be the next step to get event notification on device changes?

@davidrustingha
Copy link

Hi guys, happy new year first of all!

I'd be happy to test the integration for the KPN box 12. I have it at home, and have tried to get it working by checking the pending pull requests, but I havent got it working yet.
Let me know if I can be of any help!

@rhpijnacker
Copy link
Contributor

@davidrustingha Happy new year to you too.
What is going wrong? For me it works, so I'm curious to why it does not work for you.

@davidrustingha
Copy link

davidrustingha commented Jan 2, 2022

@rhpijnacker well I tried installing the current version on this repo, that gives me the 'Failed to connect, please try again' error.

I've installed the update mentioned here, it loads properly, but then I get the 'Maximum session count reached' error. It does not create entities also.

@geert36 could you give https://github.com/iMicknl/ha-sagemcom-fast/archive/refs/heads/feature/add_ssl_support.zip a try? Extract this file and place custom_components/sagemcom_fast in your custom_components folder. (overwrite the previous one).

When I rebooted after adding a debug log output I got this error:

2022-01-02 15:12:58 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry mijnmodem.kpn for sagemcom_fast
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 313, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/config/custom_components/sagemcom_fast/__init__.py", line 122, in async_setup_entry
gateway = await client.get_device_info()
File "/usr/local/lib/python3.9/site-packages/sagemcom_api/client.py", line 337, in get_device_info
data = await self.get_value_by_xpath("Device/DeviceInfo")
File "/usr/local/lib/python3.9/site-packages/sagemcom_api/client.py", line 307, in get_value_by_xpath
response = await self.__api_request_async([actions], False)
File "/usr/local/lib/python3.9/site-packages/sagemcom_api/client.py", line 241, in __api_request_async
raise UnknownPathException(action_error)
sagemcom_api.exceptions.UnknownPathException: {'code': 16777242, 'description': 'XMO_UNKNOWN_PATH_ERR'}

After a disable/enable and reboot I get the session count error again.

What can I do from here?

@davidrustingha
Copy link

davidrustingha commented Jan 2, 2022

I have also tried to setup @copini's version, but when I fill out my information during setup it exits with the session count error before it sets up

EDIT:
after trying a couple of times I got it setup, but it gives me the session count error after that. Ill keep an eye on it

EDIT 2:
I think I have a patience issue. It created the entities!

@rhpijnacker
Copy link
Contributor

So, what you'll need is:

If you want, you could use the merge branch. This contains both PRs.

For the KPN Box v12 you will need to select SHA512 and check the "Uses a SSL-certificate" option.

@davidrustingha
Copy link

As I understood it the merge branch had all the PR's, right? After adding that it gives me this error

This error originated from a custom integration.

Logger: custom_components.sagemcom_fast.config_flow
Source: custom_components/sagemcom_fast/config_flow.py:70
Integration: sagemcom_fast (documentation, issues)
First occurred: 18:05:24 (1 occurrences)
Last logged: 18:05:24

'SagemcomClient' object has no attribute 'logout'
Traceback (most recent call last):
  File "/config/custom_components/sagemcom_fast/config_flow.py", line 86, in async_step_user
    return await self.async_validate_input(user_input)
  File "/config/custom_components/sagemcom_fast/config_flow.py", line 70, in async_validate_input
    await client.logout()
AttributeError: 'SagemcomClient' object has no attribute 'logout'

@rhpijnacker
Copy link
Contributor

rhpijnacker commented Jan 2, 2022

Looks like you're missing iMicknl/python-sagemcom-api#107. Are you sure you are using the latest sagemcom-api library from git? (Not the one from PyPI.)

@iMicknl, would you mind publishing this, so we can just update the dependency?

@davidrustingha
Copy link

davidrustingha commented Jan 2, 2022

I checked and I have version 1.0.5 installed, that should be the most recent version according to the github repo https://github.com/iMicknl/python-sagemcom-api

EDIT:
I've manually updated the client.py file and restarted the host. It still gave me the error unfortunately

@rhpijnacker
Copy link
Contributor

Version 1.0.5 indeed does not contain the logout function.
If you take the latest from master, it should, as this commit added that function.

If you still get the error that "object has no attribute 'logout'", then it isn't picking up the updated version of client.py.

@davidrustingha
Copy link

Im pretty sure I have. Installed it with pip install git+https://github.com/iMicknl/python-sagemcom-api

It either gives me the session count error or the logout error. I can't get past the initial set up.

@iMicknl
Copy link
Owner

iMicknl commented Jan 3, 2022

@rhpijnacker I tried to publish 1.06, but the automated pipelines are not working currently, thus I need to do some CI/CD updates before I am able to publish.
However, you should be able to link to a specific branch as well in the manifest.json. See https://developers.home-assistant.io/docs/creating_integration_manifest/ for the correct notation.

@rhpijnacker
Copy link
Contributor

Oh cool. I'm new to all this (Home Assistant, python, pip, etc.) so good to know how to handle dependencies.
Thanks.

@geert36
Copy link
Author

geert36 commented Jan 30, 2022

Thanks for the latest update @iMicknl !
I removed everything and did a clean install. Now I've got this error:
image
image

@iMicknl
Copy link
Owner

iMicknl commented Jan 30, 2022

Are you sure that is the right URL and port? It seems it can not connect.

@rhpijnacker could perhaps help. I updated the underlying API a bit, so that new changes can be merged faster :-). Apologies for the delays.

@geert36
Copy link
Author

geert36 commented Jan 30, 2022

Yes still using the same URL and port. When using the merge of @rhpijnacker and changing sagemcom api to 1.0.6, it is still working.

@rhpijnacker
Copy link
Contributor

rhpijnacker commented Feb 1, 2022

@geert36 Looks like @iMicknl did not yet merge my changes, or the SSL support changes.
So, basically, master is not yet ready for using on a KPN Box 12.
I updated the merge branch to include the latest changes on master.

@iMicknl
Copy link
Owner

iMicknl commented Mar 18, 2022

@rhpijnacker I will probably remove the log out after every request as the default option, but move it to the options flow. I believe it worked in your case, but you weren't able to open the normal router interface at the same time?

It is way more resource friendly to keep the session open, and in my case, the current logout() way does even break the integration. Apparently my model doesn't like to login/logout that frequent.

Would it be fine to have this as an option?

@rhpijnacker
Copy link
Contributor

@iMicknl If it causes problems for other integrations, then it makes a lot of sense to make this optional.
You are correct that the KPN Box v12 devices allow only one active login session at any time.

If you want me to test out your changes, then feel free to let me know.

@julianborghuis
Copy link

hey mick,

do you know if you want to login at the ip you can use http://192.168.2.254/2.0/gui/#/login/ instead of mijnmodem.kpn. this will bypass the redirection to mijnmodem.kpn.
Is there any progress on this model???

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

Successfully merging a pull request may close this issue.

6 participants