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

'NoneType' object has no attribute 'setdefault' #24

Closed
hhuitema opened this issue May 24, 2023 · 15 comments
Closed

'NoneType' object has no attribute 'setdefault' #24

hhuitema opened this issue May 24, 2023 · 15 comments
Labels

Comments

@hhuitema
Copy link

Since 24-5-2023 this error is starting to occur in the log of HA.
Not accidentally when looking in the Carelink APP (Ios or Android) i can now select which person to follow. (up to 4 people)

So i think there might be some technical issues with the API url, and retrieved data.
For now disabling the Integration :-(

@yo-han
Copy link
Owner

yo-han commented May 24, 2023

Yup. I can see the same error now. Will take a look at it when I can.

The integration is working fine nonetheless. Is your not? The error is something with timezones in different formats through out the world. I don't think it has something to do with app changes.

@hhuitema
Copy link
Author

for me there is no data at all.. but that might be related to having a dedicated 'follower' user as a carelink account.

By the way the python client now has an update that you might need to integrate.
There is a new variable to use. (patientId username)
link to the issue

@hhuitema
Copy link
Author

From home assistant logs. I hope it helps troubleshooting

Deze fout is ontstaan door een aangepaste integratie.

Logger: custom_components.carelink
Source: custom_components/carelink/init.py:135
Integration: carelink
First occurred: 13:19:01 (315 occurrences)
Last logged: 20:41:50

Unexpected error fetching carelink data: 'NoneType' object has no attribute 'setdefault'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _async_refresh
self.data = await self._async_update_data()
File "/config/custom_components/carelink/init.py", line 135, in _async_update_data
recent_data.setdefault("clientTimeZoneName"), "Europe/London"
AttributeError: 'NoneType' object has no attribute 'setdefault'

@hhuitema
Copy link
Author

Pulled from the logs at debug level..
2023-05-25 07:31:54.947 INFO (MainThread) [httpx] HTTP Request: GET https://carelink.minimed.eu/patient/monitor/data "HTTP/1.1 200 OK"
2023-05-25 07:31:54.948 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: __get_connect_display_message()
2023-05-25 07:31:54.948 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: __get_data()
2023-05-25 07:31:55.405 INFO (MainThread) [httpx] HTTP Request: POST https://clcloud.minimed.eu/connect/carepartner/v6/display/message "HTTP/1.1 400 Bad Request"
2023-05-25 07:31:55.408 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: 400
2023-05-25 07:31:55.408 DEBUG (MainThread) [custom_components.carelink.api] Carelink API: __get_data() failed: exception __get_data() session get response is not OK400
2023-05-25 07:31:55.408 ERROR (MainThread) [custom_components.carelink] Unexpected error fetching carelink data: 'NoneType' object has no attribute 'setdefault'

@hhuitema
Copy link
Author

I got the carelink python code running on my desktop by adding the patient username to the userjson
# Build user json for request userJson = { "username":username, "role":role, "patientId":patient } requestBody = json.dumps(userJson)

a quick hack could be to introduce a new variable to allow data retrieval for 1 patient.
we would need a config variable for the integration then.

in future the integration has a whole new root level. Instead of the pump being the root, the patient would be the new root, where there can be up to four patients.
However i can live with a restriction of a single patient.. ;-)

@hhuitema
Copy link
Author

Did a manual adjustment in api.py locally on my HA instance, and it works immediately..

@GertVanderstukken
Copy link

GertVanderstukken commented May 29, 2023

Indeed, I changed this under api.py:
user_json = {"username": username, "role": role}
to
user_json = {"username": username, "role": role, "patientId":"TheUserNameAsSeenunderSettingsinCareLinkConnect"}

And it worked...

@hhuitema
Copy link
Author

Indeed, line 350 in api.py.

The whole community behind the Java coding and the Python port on which this integration is relying on is debating how to implement. Making it single patient configurable or as medtronic is exposing it, enabling for 4 patients.
Regardless, for me it now works and in most cases a single patient will do just fine.

@yo-han
Copy link
Owner

yo-han commented Jun 1, 2023

Looks good guys. Is there anyone who can make a PR of it. I'm happy to to approve it. Otherwise it make take a little while because I'm quite busy with work and home stuff at the moment.

@yo-han
Copy link
Owner

yo-han commented Jun 1, 2023

Thanks to your research a fix for the Carelink Partner accounts was not that hard to make. I made a pre-release available for testing here.

I tested with a running integration with a normal account. Removed the integration and logged in with a partner account. Both worked fine. But I would love to here from more people that it is working well before releasing it to a greater group of people.

@hhuitema
Copy link
Author

hhuitema commented Jun 2, 2023

I was running with your code in the train yesterday afternoon, so i will be curious to compare my hacky solution with yours.. :)
In the meantime i installed the new RC version and it works immediately, including the hardware details being exposed.

One beautification thingy, the new field to configure does not have a title, something to add for the final version. ;)

image

@yo-han
Copy link
Owner

yo-han commented Jun 2, 2023

I can't reproduce the missing field label.

Scherm­afbeelding 2023-06-02 om 17 30 09

@yo-han
Copy link
Owner

yo-han commented Jun 5, 2023

I released a new version with Carelink Partner support and some minor fixes and translations.

@github-actions
Copy link

github-actions bot commented Jul 6, 2023

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Jul 6, 2023
@hhuitema
Copy link
Author

hhuitema commented Jul 6, 2023

Confirmed to be working, let's close this ticket

@hhuitema hhuitema closed this as completed Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants