mezz64 / pyEight

Python library to interface with the Eight Sleep API
MIT License
59 stars 15 forks source link

Can't turn on the heat #22

Closed ilyavolodin closed 2 years ago

ilyavolodin commented 2 years ago

I'm opening a local issue as instructed in the original Home Assistant issue here: https://github.com/home-assistant/core/issues/62813 I've removed partner option from the configuration, and I'm still seeing the same errors whenever I try to turn on the heat in my eight mattress topper. I've verified that my login information is correct, and logged out and back in on my phone. Everything is working fine in the phone app, but not working through this integration. No changes has been made on my account in a very very long time. And this used to work just a few month ago. Here are the error messages I get:

2021-12-26 15:13:49 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: None
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/__init__.py", line 178, in async_service_handler
    usrobj = eight.users[userid]
KeyError: None
2021-12-26 15:13:49 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139940582132224] Error handling message: Unknown error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 527, in handle_execute_script
    await script_obj.async_run(msg.get("variables"), context=context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1260, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/__init__.py", line 178, in async_service_handler
    usrobj = eight.users[userid]
KeyError: None
mezz64 commented 2 years ago

Can you please follow the instructions here (https://github.com/mezz64/pyEight/issues/12#issuecomment-612727727) to manually interact with the api and let me know what kind of responses you are receiving? Please post sanitized responses from all steps (including 1) so I can compare to my test cases.

From your original HA issue it looks like an invalid user ID is being returned. It's possible Eight has changed something in the formatting and posting the responses will help me troubleshoot.

ilyavolodin commented 2 years ago

Here're the responses requested: STEP 2:

{
    "user": {
        "userId": "REMOVED",
        "email": "REMOVED",
        "firstName": "Ilya",
        "lastName": "Volodin",
        "gender": "male",
        "dob": "REMOVED",
        "zip": 11111,
        "devices": [
            "REMOVED"
        ],
        "emailVerified": true,
        "sharingMetricsTo": [
            "REMOVED"
        ],
        "sharingMetricsFrom": [],
        "timezone": "America/New_York",
        "notifications": {
            "weeklyReportEmail": true,
            "sessionProcessed": true,
            "temperatureRecommendation": true,
            "healthInsight": true,
            "sleepInsight": true,
            "marketingUpdates": true,
            "bedtimeReminder": true,
            "alarmWakeupPush": true
        },
        "createdAt": "2017-12-24T00:22:10.599Z",
        "experimentalFeatures": false,
        "autopilotEnabled": false,
        "lastReset": "1970-01-01T00:00:00.000Z",
        "nextReset": "2100-01-01T00:00:00.000Z",
        "features": [
            "warming"
        ],
        "currentDevice": {
            "id": "REMOVED",
            "side": "left"
        },
        "tempPreferenceUpdatedAt": "2018-04-03T12:23:32.499Z",
        "hotelGuest": false
    }
}

STEP 3:

{
    "result": {
        "deviceId": "REMOVED",
        "ownerId": "REMOVED",
        "leftUserId": "REMOVED (Same as ownerId and userId from step 2)",
        "leftHeatingLevel": 0,
        "leftTargetHeatingLevel": 0,
        "leftNowHeating": false,
        "leftHeatingDuration": 0,
        "leftSchedule": {
            "daysUTC": {
                "sunday": true,
                "monday": true,
                "tuesday": true,
                "wednesday": true,
                "thursday": true,
                "friday": true,
                "saturday": true
            },
            "enabled": true,
            "startUTCHour": 3,
            "startUTCMinute": 30,
            "durationSeconds": 2700
        },
        "rightUserId": "REMOVED",
        "rightHeatingLevel": 0,
        "rightTargetHeatingLevel": 0,
        "rightNowHeating": false,
        "rightHeatingDuration": 0,
        "rightSchedule": {
            "daysUTC": {
                "sunday": true,
                "monday": true,
                "tuesday": true,
                "wednesday": true,
                "thursday": true,
                "friday": true,
                "saturday": true
            },
            "enabled": true,
            "startUTCHour": 3,
            "startUTCMinute": 15,
            "durationSeconds": 3600
        },
        "lastLowWater": "2021-12-30T04:35:31.575Z",
        "needsPriming": true,
        "ledBrightnessLevel": 20,
        "sensorInfo": {
            "label": "20003-0002-B02-00002CEB",
            "partNumber": "20003",
            "sku": "0002",
            "hwRevision": "B02",
            "serialNumber": "00002CEB",
            "lastConnected": "2021-12-30T04:35:31.575Z",
            "skuName": "king",
            "connected": true
        },
        "hubInfo": "20001-0001-A08-00003FA4",
        "timezone": "America/New_York",
        "location": [
            REMOVED
        ],
        "mattressInfo": {
            "firstUsedDate": null,
            "eightMattress": false,
            "brand": "I don't know"
        },
        "firmwareCommit": "d4ccf93",
        "firmwareVersion": "2.4.2.0",
        "firmwareUpdated": true,
        "firmwareUpdating": false,
        "lastFirmwareUpdateStart": "1970-01-01T00:00:00.000+00:00",
        "lastHeard": "2021-12-30T04:35:46.590Z",
        "online": true,
        "encasementType": null,
        "leftKelvin": {
            "targetLevels": [
                0,
                0,
                0
            ],
            "alarms": [],
            "scheduleProfiles": [],
            "level": 0,
            "currentTargetLevel": 0,
            "active": false,
            "currentActivity": "off"
        },
        "rightKelvin": {
            "targetLevels": [
                0,
                0,
                0
            ],
            "alarms": [],
            "scheduleProfiles": [],
            "level": 0,
            "currentTargetLevel": 0,
            "active": false,
            "currentActivity": "off"
        },
        "features": [
            "warming"
        ],
        "modelString": "Sleep Tracker",
        "hubSerial": "00003FA4",
        "wifiInfo": {
            "signalStrength": -46,
            "ssid": "HomeNetwork",
            "ipAddr": "192.168.1.14",
            "macAddr": "e0:4f:43:3e:c8:b8",
            "asOf": "2021-12-30T04:35:46.590Z"
        }
    }
}

Step 4 results are over 8000 lines long, and it's just information about last week worth of sleep data. Do you need that?

mezz64 commented 2 years ago

Thanks. Do either of the user id's match the one you see in the original error log?

Unable to fetch user profile data for a7547578########0e4d42d69c59f6
ilyavolodin commented 2 years ago

Yes, that profile ID matches my wife's profile ID. But that error shows up in the logs occasionally only.

mezz64 commented 2 years ago

I was able to reproduce this in my test setup. Give me a few days and i'll get a fix in place and submit a PR to get HASS updated.

mezz64 commented 2 years ago

After checking a few scenarios over a couple days I believe I've got a working solution as well as some other changes to hopefully minimize 504 errors. PR is pending to get HASS updated: https://github.com/home-assistant/core/pull/63405

ilyavolodin commented 2 years ago

I can verify that the issue has been fixed. Integration is still pretty unstable, but I think that's mostly due to eight APIs having pretty terrible uptime and eight hub having terrible wifi chip that disconnects constantly.