prestomation / resmed_myair_sensors

This is a Home Assistant custom component to pull daily CPAP data from ResMed's myAir service using an undocumented API
MIT License
90 stars 9 forks source link

EU Login - Unknown error occurred #25

Closed DavidBurstein closed 1 month ago

DavidBurstein commented 2 years ago

Hi there Attempting to add my new EU - MyAir account using the integration installed via HACS. I've tried a few times including reinstalls and restarts.

HA error log below: I'm outside my ability so I'm not sure how to interpret the below. Does the last line "Attempt to decode JSON with unexpected mimetype" shed any light?

Thanks David

This error originated from a custom integration.

Logger: aiohttp.server Source: custom_components/resmed_myair/client/legacy_client.py:85 Integration: ResMed myAir CPAP Sensors (documentation, issues) First occurred: 9:06:48 AM (1 occurrences) Last logged: 9:06:48 AM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request resp = await request_handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle resp = await handler(request) File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 220, in auth_middleware return await handler(request) File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle result = await result File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 205, in post return await super().post(request, flow_id) File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper result = await method(view, request, *args, **kwargs) File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 109, in post result = await self._flow_mgr.async_configure(flow_id, data) File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in async_configure result = await self._async_handle_step( File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) File "/config/custom_components/resmed_myair/config_flow.py", line 52, in async_step_user device: MyAirDevice = await get_device( File "/config/custom_components/resmed_myair/config_flow.py", line 31, in get_device await client.connect() File "/config/custom_components/resmed_myair/client/legacy_client.py", line 85, in connect authn_json = await authn_res.json() File "/usr/local/lib/python3.9/site-packages/aiohttp/client_reqrep.py", line 1103, in json raise ContentTypeError( aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: application/xml', url=URL('https://myair.resmed.eu/authenticationids/externalwebservices/restotprequestselect.php')

robiecz commented 2 years ago

Same here. There is 2FA (a 6-digi numeric code via e-mail) in login process. "Hi Rob, You received this email because a request was made for a one-time code that can be used for authentication. Enter the following code for verification: XXXXXX"

oveeliegmailcom commented 1 year ago

I have tried to use this connection but the problem is that EU Norway has 2 factor authentication.

A couple of days ago I started thinking that when logging in to the website I have to enter a code from my email, while I almost never have to confirm a new login when using the ResMed app.

Is it possible that an API key is used in the app and that this can be used to have a login-free connection in the home assistant.

Unfortunately, I know too little about how to scrape information from such connections, but maybe those who can think of looking at that possibility?

I would be happy to provide information if someone informs me about how I retrieve logs on my android phone.

Mvh Ove Lie (pronounced Lee)

craigmcfly commented 1 year ago

Same error. Any news on getting this investigated?

mhemmingsen commented 1 year ago

Same issue from here. Please add the option to authenticate with the 6 digit code received by e-mail somehow :-)

sunnyd24 commented 1 year ago

@prestomation @Snuffy2 I have the same issue as others from the UK. By default all accounts have 2FA enabled and require an email with 6-digit code.

On attempting to sign into integration with EU (experimental) radio button we receive the "unknown error occurred" message.

Any ideas on how to fix this? I am happy to try if someone gives me a few pointers/support......

robgough1970 commented 1 year ago

same here in the UK - would be great to have this integrated in HA

Mysticsilent commented 1 year ago

Same here in the Netherlands. Also 2FA mail code is required. I cannot add the integration into Devices. An unknown error has occurred.

jove01 commented 1 year ago

Same here in Germany. Can you Help?

reinvk commented 1 year ago

Can anybody help to fix this integration with Resmed MyAir ?

KiimaRo commented 1 year ago

Same here with 2FA mail code in Sweden.

letetram commented 11 months ago

I tried with a Luxembourg, Belgian, Swiss and French account, but they all asked for 2FA mail.

cazmir commented 9 months ago

Same here with 2FA mail code in Sweden.

+1 :-(

DLHN-cz commented 8 months ago

+1 :( from Czech republic

wynand64 commented 8 months ago

+1 👍 from South Africa

gadgetbazza commented 6 months ago

And another here from UK. There is an option during login to say always trust this device which prevents the need for the 2FA on a second visit. So need a way to complete this from the HA host really so that it remembers the device. I can see cookies stored from resmed.co.uk along with some local storage used by the browser. So I suspect that this is what needs addressing during the device workflow if possible.

Ulrar commented 5 months ago

Same here

loedeman commented 4 months ago

For me as well 😢

abeggled commented 4 months ago

Switzerland as well

paceo13 commented 3 months ago

Same problem !

aeble commented 3 months ago

Same here. Resmed seems to be very restrictive with API access and it's unclear whether they even have API access to European data. I've googled and while their website isn't very helpful, I've found that it's possible for healthcare professionals to access data after signing an NDA for their APIs.

ulope commented 2 months ago

Their app can display the data, so there's obviously an api.

craigmcfly commented 2 months ago

Their app can display the data, so there's obviously an api.

The issue isn't that there's an API, it's that it now requires 2FA and the HA integration doesn't allow for that.

craigmcfly commented 2 months ago

Same here. Resmed seems to be very restrictive with API access and it's unclear whether they even have API access to European data. I've googled and while their website isn't very helpful, I've found that it's possible for healthcare professionals to access data after signing an NDA for their APIs.

That's probably over a VPN or requires some other authentication mechanism that would be very difficult to reproduce on HA

Snuffy2 commented 2 months ago

I make zero promises that I'll be able to fix this, but I can try to take a look. I am in the US and don't have 2FA so I don't have any real ability to test this.

Questions:

craigmcfly commented 2 months ago
aeble commented 2 months ago

do you want to see the cookies of a logged in session?

On Fri, Aug 16, 2024 at 11:17 PM Snuffy2 @.***> wrote:

I make zero promises that I'll be able to fix this, but I can try to take a look. I am in the US and don't have 2FA so I don't have any real ability to test this.

Questions:

  • When logging into the MyAir website (https://myair.resmed.com/), is there an option to Remember or Always Trust this Device (or something similar)?
  • If you check this box, does MyAir then remember the login and not ask for a password and 2FA again when you return to the site from that browser?
  • How long does the saved login persist for?

— Reply to this email directly, view it on GitHub https://github.com/prestomation/resmed_myair_sensors/issues/25#issuecomment-2294326380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5HJJKHPCZT6VQ56FEIXR3ZRZT7FAVCNFSM5YWTR66KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRZGQZTENRTHAYA . You are receiving this because you commented.Message ID: @.***>

-- Axel Eble Schützenallee 70 79102 Freiburg Germany cell: +49.160.666-5028

aeble commented 2 months ago

if you need anything else, let me know.

On Fri, Aug 16, 2024 at 11:17 PM Snuffy2 @.***> wrote:

I make zero promises that I'll be able to fix this, but I can try to take a look. I am in the US and don't have 2FA so I don't have any real ability to test this.

Questions:

  • When logging into the MyAir website (https://myair.resmed.com/), is there an option to Remember or Always Trust this Device (or something similar)?
  • If you check this box, does MyAir then remember the login and not ask for a password and 2FA again when you return to the site from that browser?
  • How long does the saved login persist for?

— Reply to this email directly, view it on GitHub https://github.com/prestomation/resmed_myair_sensors/issues/25#issuecomment-2294326380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5HJJKHPCZT6VQ56FEIXR3ZRZT7FAVCNFSM5YWTR66KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMRZGQZTENRTHAYA . You are receiving this because you commented.Message ID: @.***>

-- Axel Eble Schützenallee 70 79102 Freiburg Germany cell: +49.160.666-5028

Snuffy2 commented 2 months ago

I'm looking for a couple of brave, helpful souls in the EU to help me further. As before, I'm in the US and don't have 2FA so I'm very limited in what I can test locally. Given that, I have a very alpha version of trying to support EU 2FA that I'm hoping a couple of people can test for me. It is almost 100% guaranteed to fail but that is expected. I'm trying to get the debug logs so I can see what to do next.

If you currently have a working ResMed myAir integration, do not do this

This fork is solely for trying to build support for EU and 2FA. I do not intend to maintain a separate fork of this repo. Thus, do not install this if you are not able to actively help troubleshoot this with me.

To install:

A. Install my fork and beta release via HACS

  1. Add my repo as a custom repo to HACS: https://github.com/Snuffy2/resmed_myair_sensors
  2. Find ResMed myAir CPAP Sensors (Snuffy2 EU 2FA Dev) and Download it
  3. Restart HA
  4. Go back to HACS and to ResMed myAir CPAP Sensors (Snuffy2 EU 2FA Dev)
  5. Click the ... menu in the upper right and select Redownload
  6. Enable Show beta versions and then select the latest v0.0.x-2FA version and Download
  7. Edit your configuration.yaml to enable debug logging for the ResMed integration: Example:
    logger:
    default: warning
    logs:
    custom_components.resmed_myair: debug
  8. Restart HA

B. Get the Bearer Token from ResMed myAir

  1. Go to https://myair.resmed.eu/
  2. Select your country from the list
  3. Sign into your ResMed account with your name and password
  4. It should trigger the email 2FA
  5. Before you submit the 2FA code, enable the Developer Tools in your browser (usually pressing F12) and go to the Network tab.
  6. In the ResMed login, check the box Do not challenge me on this device again, enter your Verification code and click Verify
  7. As you are logged into myAir, a lot of information should start to show in the DevTools Network tab. Wait until the myAir page fully loads
  8. In the DevTools Network data, find the first entry for graphql.hyperdrive.resmed.eu and click on it.
  9. It will open a smaller window, ensure you are on the Headers tab
  10. Scroll down to Request Headers and find the line for Authorization
  11. Copy the entire string into Notepad (or similar)
  12. Remove "Bearer " from the start of the string

C. Setup ResMed myAir (Snuffy2 EU 2FA Dev) Integration in HA

  1. Go to HA and add the ResMed myAir CPAP Sensors (Snuffy2 EU 2FA Dev) integration
  2. Enter your ResMed Name and Password and select EU (Experimental) for the region
  3. In the next page select your country and paste the full Authorization token string you got from B above (without the starting "Bearer ")
  4. Click Submit
  5. You will very likely get an error
  6. Go to your HA logs and send me the ResMed Debug logs.
  7. You can deidentify anything you'd like to but please send me the full logs with all ResMed rows.
  8. You can post them to this issue or email them to me at resmed2fatest@mail.snuffy2.com if you prefer
fmeus commented 2 months ago

Just installed it and so far it worked without any issues. BTW I am located in the Netherlands.

Only 'issue' I see is that there is a sensor 'CPAP Mask Leak %', but within the app and on the website leakage is reported in L/min.

prestomation commented 2 months ago

Hi @fmeus. The leak % is the data provided by the API. If you would like the L/min metric please open a specific issue about this.

AlexRegenbogen commented 2 months ago

Tried this, and although for the less tech savvy users among us, it could be a little errorprone when it comes to copying the bearer token, this worked in a single go for me!

One more Dutch user that can build another card on its dash, and another thankful user!

Snuffy2 commented 2 months ago

I'm sorry, but it actually worked and is giving results? I'm very surprised. Ok then.

Can some people please still send me some debug logs so I can see a few things.

From there I can better determine how to build it out to be easier to setup.

jesmak commented 2 months ago

I tried this also (I live in Finland). When entering my credentials while configuring the integration, I first got this error:

Lokikirjaaja: py.warnings
Lähde: custom_components/resmed_myair/client/__init__.py:2
integraatio: ResMed myAir (Snuffy2 EU 2FA Dev) (dokumentaatio, ongelmat)
Ensimmäistä kertaa ilmennyt: 08.54.52 (1 tapahtumat)
Viimeksi kirjattu: 08.54.52

/config/custom_components/resmed_myair/client/legacy_client.py:137: SyntaxWarning: invalid escape sequence '\[' matches = re.search(".+(\[.+?\]).+", scores_script).groups()[0]

My password had the ^ character in it so I figured that was the issue. I changed my password and tried again. Now I'm getting another error when I try to configure the integration. This happens after entering the credentials, selecting EU and clicking the button. So before even getting to enter the bearer token. Here's the log:

Lokikirjaaja: aiohttp.server
Lähde: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:427
Ensimmäistä kertaa ilmennyt: 08.55.10 (6 tapahtumat)
Viimeksi kirjattu: 09.06.33

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 456, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/resmed_myair/config_flow.py", line 52, in async_step_user
    device: MyAirDevice = await get_device(
                          ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/resmed_myair/config_flow.py", line 31, in get_device
    await client.connect()
  File "/config/custom_components/resmed_myair/client/legacy_client.py", line 85, in connect
    authn_json = await authn_res.json()
                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 80, in json
    return await super().json(*args, loads=loads, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1199, in json
    raise ContentTypeError(
aiohttp.client_exceptions.ContentTypeError: 0, message='Attempt to decode JSON with unexpected mimetype: application/xml', url='https://myair.resmed.eu/authenticationids/externalwebservices/restotprequestselect.php'
jesmak commented 2 months ago

Ok, please ignore my previous message. I had skipped the whole redownload part.

jesmak commented 2 months ago

I can confirm it also works for me now. I've sent you some debug logs via email.

aeble commented 2 months ago

Can confirm, works like a charm on first try. Well done! Will send debug logs soon.

On Wed, Aug 21, 2024 at 9:27 PM Snuffy2 @.***> wrote:

I'm sorry, but it actually worked and is giving results? I'm very surprised. Ok then.

Can some people please still send me some debug logs so I can see a few things.

From there I can better determine how to build it out to be easier to setup.

— Reply to this email directly, view it on GitHub https://github.com/prestomation/resmed_myair_sensors/issues/25#issuecomment-2302859785, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5HJJJ6NLPD7V2SGHGPPLLZSTS3ZAVCNFSM5YWTR66KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMZQGI4DKOJXHA2Q . You are receiving this because you commented.Message ID: @.***>

-- Axel Eble Schützenallee 70 79102 Freiburg Germany cell: +49.160.666-5028

londondev77 commented 2 months ago

I've been unable to get it to work in the UK. I'm able to enter my credentials which are accepted but I get an error when selecting United Kingdom and entering my bearer token.

Here are the pertinent logs:

2024-08-22 10:06:05.801 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] operation_name: getPatientWrapper, query: 
        query getPatientWrapper {
            getPatientWrapper {
                fgDevices {
                    serialNumber
                    deviceType
                    lastSleepDataReportTime
                    localizedName
                    fgDeviceManufacturerName
                    fgDevicePatientId
                    __typename
                }
            }
        }

2024-08-22 10:06:05.801 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] authz_header: bearer
**scrubbed**
2024-08-22 10:06:05.801 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] appsync_url: https://graphql.hyperdrive.resmed.eu/graphql
2024-08-22 10:06:05.801 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] headers: {'x-api-key': 'da2-o66oo6xdnfh5hlfuw5yw5g2dtm', 'Authorization': 'bearer **scrubbed**', 'rmdhandsetid': '02c1c662-c289-41fd-a9ae-196ff15b5166', 'rmdlanguage': 'en', 'rmdhandsetmodel': 'Chrome', 'rmdhandsetosversion': '127.0.6533.119', 'rmdproduct': 'myAir EU', 'rmdappversion': '2.0.0', 'rmdhandsetplatform': 'Web', 'rmdcountry': 'UK', 'accept-language': 'en-US,en;q=0.9'}
2024-08-22 10:06:05.801 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] json_query: {'operationName': 'getPatientWrapper', 'variables': {}, 'query': '\n        query getPatientWrapper {\n            getPatientWrapper {\n                fgDevices {\n                    serialNumber\n                    deviceType\n                    lastSleepDataReportTime\n                    localizedName\n                    fgDeviceManufacturerName\n                    fgDevicePatientId\n                    __typename\n                }\n            }\n        }\n        '}
2024-08-22 10:06:05.956 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [gql_query] records_response: <ClientResponse(https://graphql.hyperdrive.resmed.eu/graphql) [200 OK]>
<CIMultiDictProxy('Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '273', 'Connection': 'keep-alive', 'Date': 'Thu, 22 Aug 2024 09:06:05 GMT', 'x-amzn-RequestId': '669f07fa-8ae7-4b5d-9dad-d640834b5692', 'x-amzn-appsync-TokensConsumed': '1', 'X-Cache': 'Miss from cloudfront', 'Via': '1.1 9af44e4af2b7b71defce07d7848eb368.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'LHR5-P5', 'X-Amz-Cf-Id': 'DesEs9_KMg6MTKgBud0lCgY3GZYA4PIZCrklFnQkDIib4GF-Od2CLg==')>

2024-08-22 10:06:05.956 DEBUG (MainThread) [custom_components.resmed_myair.client.eu_client] [getPatientWrapper] {'data': {'getPatientWrapper': None}, 'errors': [{'path': ['getPatientWrapper'], 'data': None, 'errorType': 'myAir:result', 'errorInfo': {'success': False, 'errorType': 'badRequest', 'errorCode': 'invalidHeaders'}, 'locations': [{'line': 3, 'column': 13, 'sourceName': None}], 'message': 'Error'}]}
2024-08-22 10:06:05.956 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 456, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 537, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 210, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 85, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
    return await method(view, request, data, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 366, in async_configure
    result = await self._async_configure(flow_id, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 413, in _async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 516, in _async_handle_step
    result: _FlowResultT = await getattr(flow, method)(user_input)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/resmed_myair/config_flow.py", line 115, in async_step_eu_details
    device: MyAirDevice = await get_device(
                          ^^^^^^^^^^^^^^^^^
  File "/config/custom_components/resmed_myair/config_flow.py", line 45, in get_device
    device = await client.get_user_device_data()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/resmed_myair/client/eu_client.py", line 251, in get_user_device_data
    device = records_json["data"]["getPatientWrapper"]["fgDevices"][0]
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable
Snuffy2 commented 2 months ago

Thank you all for the debug logs. I think I'm a lot closer now to getting the email 2FA to work via config flow (not needing to find and enter the Bearer Token).

I'm in need of another piece of information though using the Developer Tools in your browser:

  1. Go to https://myair.resmed.eu/
  2. Select your country from the list
  3. Sign into your ResMed account with your name and password
  4. It should trigger the email 2FA
  5. Before you submit the 2FA code, enable the Developer Tools in your browser (usually pressing F12) and go to the Network tab.
  6. In the ResMed login, check the box Do not challenge me on this device again, enter your Verification code, and click Verify
  7. As you are logged into myAir, a lot of information should start to show in the DevTools Network tab. Wait until the myAir page fully loads
  8. In the DevTools Network data, find the entry for Method: GET, Domain: id.resmed.eu, and File starts with authorize?.... Single click on it
  9. It will open a smaller window, ensure you are on the Headers tab
  10. Right click on the line that starts with GET and Copy All
  11. Paste the entire thing into Notepad (or similar) so you don't lose it
  12. Please do not de-identify or change anything
  13. You can post it to this issue or email it to me at resmed2fatest@mail.snuffy2.com if you prefer

This is what it looks like for the US Version, it should look very similar but start with id.resmed.eu:

{
    "GET": {
        "scheme": "https",
        "host": "resmed-ext-1.okta.com",
        "filename": "/oauth2/aus4ccsxvnidQgLmA297/v1/authorize",
        "query": {
            "client_id": "0oa4ccq1v413ypROi297",
            "code_challenge": "kaIY4dygNyt4a_biBTu2Cyg2UQZH3eRGpL7Uj6RTdDM",
            "code_challenge_method": "S256",
            "nonce": "1UlgSTtlxahnJHycfbutKlTCW6yHk9zCuekIwyGva7WNkH29R4R2Xwp0e01RJklr",
            "prompt": "none",
            "redirect_uri": "https://myair.resmed.com",
            "response_mode": "okta_post_message",
            "response_type": "code",
            "sessionToken": "201116xBDZFOl3EEgTv3P-fbA6dlXUpfL_pnXeyX7Bd49qoMh7RlC2M",
            "state": "SpIgqrchej6nMSkRTSWiEqu2zswWr70Y2HPHHHOoWDNug2RgWu4jb5FjLKuWqnvY",
            "scope": "openid profile email"
        },
        "remote": {
            "Address": "172.20.143.29:8080"
        }
    }
}

SNAG-3600

londondev77 commented 2 months ago

I'm not seeing a line beginning with GET but I think this covers the data you're looking for apart from the remote address

/oauth2/aus2uznux2sYKTsEg417/v1/authorize?client_id=0oa2uz04d2Pks2NgR417&code_challenge=ln9oPcU_aU9OusINgm0sHO_kfXh8Vkz020TqOvTZGaQ&code_challenge_method=S256&nonce=NIXSnzyN1oSdR2yX3JxDH9Mjvc8v6tW1CXGqeV6Tko4ZHhkWjcnZi3YPj0XRc79W&prompt=none&redirect_uri=https%3A%2F%2Fmyair.resmed.eu&response_mode=okta_post_message&response_type=code&sessionToken=20111D1E5l2JC4ck_lMrfdrlG-8A9WUV66gLwUIFD2I1JfqtyloJ8-S&state=FzXI9g9012KqI6nc018WtqutpYVOwQ8c5EouVqiscpUgxGHWpsteCDd1zix1VZeB&scope=openid%20profile%20email

Snuffy2 commented 2 months ago

Ok, fingers crossed .... v0.0.2-2FA released. This one supports triggering the 2FA email and entering it into the config flow. Please test it out and let me know how it goes. If it isn't working, please give me the full debug logs (you can deidentify as needed). You can post it to this issue or email it to me at resmed2fatest@mail.snuffy2.com if you prefer.

You must delete the existing ResMed myAir (Snuffy2 EU 2FA Dev) v0.0.1-2FA integration before upgrading. You don't need to delete the actual files, just the Integration Entries. Then you need to re-Add the integration.

2024-08-22_19-24-45 2024-08-22_19-33-37
dhover commented 2 months ago

With this pre-release I get "Unknown error occurred" after I enter the 2FA code.

dhover commented 2 months ago

I'm not seeing a line beginning with GET but I think this covers the data you're looking for apart from the remote address

The instructions are for the Mozilla Firefox browser.

aeble commented 2 months ago

The 2FA email was triggered, the integration installed and I can see in the logfiles that it seems to be able to log in and pull the data, but there's "no device or entities".

On Fri, Aug 23, 2024 at 1:35 AM Snuffy2 @.***> wrote:

Ok, fingers crossed .... v0.0.2-2FA released. This one supports triggering the 2FA email and entering it into the config flow. Please test it out and let me know how it goes. If it isn't working, please give me the full debug logs (you can deidentify as needed). You can post it to this issue or email it to me at @.*** if you prefer. You must delete the existing ResMed myAir (Snuffy2 EU 2FA Dev) v0.0.1-2FA integration before upgrading. You don't need to delete the actual files, just the Integration Entries. Then you need to re-Add the integration. 2024-08-22_19-24-45.png (view on web) https://github.com/user-attachments/assets/3671da75-48c4-4865-abd2-df72d1ac3478 2024-08-22_19-33-37.png (view on web) https://github.com/user-attachments/assets/78b40748-de8f-400e-afaf-30e834685545

— Reply to this email directly, view it on GitHub https://github.com/prestomation/resmed_myair_sensors/issues/25#issuecomment-2305917898, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5HJJPQCT537YX67APXHCLZSZYSRAVCNFSM5YWTR66KU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMZQGU4TCNZYHE4A . You are receiving this because you commented.Message ID: @.***>

-- Axel Eble Schützenallee 70 79102 Freiburg Germany cell: +49.160.666-5028

dhover commented 2 months ago

@Snuffy2 I've send a debug log to your mail address.

londondev77 commented 2 months ago

I also get the unknown error after entering the 2FA code. I've emailed the logs

Snuffy2 commented 2 months ago

@londondev77 v0.0.1-2FA also wasn't working for you. Is your myAir account fully setup and working? Can you login to myair.resmed.eu or into the myAir app and see your CPAP data?

@dhover Similarly, is your myAir account fully setup and working? Can you login to myair.resmed.eu or into the myAir app and see your CPAP data?

@aeble Are you able to send the debug logs for the latest version?

I'll be putting out v0.0.3-2FA soon with some logging changes but no real functionality changes.

londondev77 commented 2 months ago

There was a message in the logs which showed that additional registration was required (despite having no issues using the site or app before). So I logged into my MyAir account in the web browser and found that in my profile, the time zone hadn’t been set (I assume I set up my account before this field was added?) So I set that and successfully then used the add on to add my account to Home Assistant.

I’m not sure if it’s expected but no devices or entities were found (although it knows which device I have).

image

Will share logs later

dhover commented 2 months ago

@dhover Similarly, is your myAir account fully setup and working? Can you login to myair.resmed.eu or into the myAir app and see your CPAP data?

Yes my account is fully setup and working. Also my timezone is setup to "Europe/Berlin". I can also see my dashboard in the myair app. Recently (Aug 5th) my Airsense device was completely removed. I think there was an outage at resmed. I've added my device again one day ago and the data of the previous night is visible in my dashboard.

Snuffy2 commented 2 months ago

Yes, sorry, it is expected that no devices or data will show in v0.0.2-2FA and v0.0.3-2FA.

@aeble thank you for the v0.0.3-2FA logs. It shows that it is actually working correctly.

@londondev77 and anyone else, I'd still like to see some additional v0.0.3-2FA or newer version debug logs. From the logs I've gotten so far, it appears that some of the IDs that were previously static are changing and I want to ensure I'm accounting for those.

@dhover from some other posts, it seems that the myAir account may be marked as incomplete even after a device is linked until there is actually data synced from the CPAP device. Since you only reconnected your device recently, you may want to retry this integration now that there is data showing in myAir. I'd wait until v0.0.4-2FA though. Obviously, please continue to send me debug logs whether it is working or not.

I'll be releasing v0.0.4-2FA soon that should actually show the sleep data again. I needed to modify the logic to use the access token that is generated when the integration is setup and not get a new access token with every update.

Snuffy2 commented 2 months ago

v0.0.4-2FA Released - Actually show sleep data

If upgrading from any previous 2FA test version (v0.0.x-2FA) you must delete the existing ResMed myAir (Snuffy2 EU 2FA Dev) integration before upgrading. You don't need to delete the actual files, just the Integration Entries. Then you need to re-Add the integration.

2024-08-22_19-24-45

Please send me both working and failing debug logs so I can continue to refine as needed. You can post them to this issue or email them to me at resmed2fatest@mail.snuffy2.com if you prefer.