sbabcock23 / pytryfi

Apache License 2.0
31 stars 10 forks source link

Error: 'batteryHealth' (possible deprecated value?) #26

Closed jldeen closed 1 year ago

jldeen commented 1 year ago

First, huge thank you for this project!

I use this package as part of your other project for Home Assistant. In the past 24 hours, HA stopped being able to properly poll my Fi devices (2 collars, 4 bases) - bases were missing entirely, and only 1 collar was available with minimal attribute data. I started to dig into the issue and focused on debugging this package.

When running print(tryfi) normally, I'd receive the following error:

Traceback (most recent call last):
  File "/Users/jessicadeen/git/upstream/pytryfi/login.py", line 31, in <module>
    print(tryfi)
  File "/Users/jessicadeen/git/upstream/pytryfi/pytryfi/__init__.py", line 77, in __str__
    petString = petString + f"{p}"
  File "/Users/jessicadeen/git/upstream/pytryfi/pytryfi/fiPet.py", line 47, in __str__
    return f"Last Updated - {self.lastUpdated} - Pet ID: {self.petId} Name: {self.name} Is Lost: {self.isLost} From: {self.homeCityState} ActivityType: {self.activityType} Located: {self.currLatitude},{self.currLongitude} Last Updated: {self.currStartTime}\n \
  File "/Users/jessicadeen/git/upstream/pytryfi/pytryfi/fiPet.py", line 362, in isLost
    return self.device.isLost
  File "/Users/jessicadeen/git/upstream/pytryfi/pytryfi/fiDevice.py", line 92, in isLost
    if self._mode == PET_MODE_LOST:
AttributeError: 'FiDevice' object has no attribute '_mode'. Did you mean: 'mode'?

When running print(tryfi) in debug mode, I noticed the error: DEBUG:pytryfi.fiDevice:tryfi Error: 'batteryHealth'

Further debugging seemed to produce various AttributeErrors such as:

I started with the batteryHealth error after I noticed the JSON payload for info was missing the batteryHealth key entirely:

"info": {
              "credentialPackHash": "qVUfFmUs/CPaRn+75XgOrcQqhAyvMrTz6QjEM8mHUs0=",
              "wifiNetworkNames": [],
              "buildId": "4.6.12-e5a6646da-fc3_f3-prod",
              "batteryPercent": 93,
              "batteryVoltage": 4208,
              "uptime": 71568,
              "clock": {
                  "low": 71568273,
                  "high": 0,
                  "unsigned": True
              },
              "wifiFirmwareVersion": 65,
              "batteryResistanceProfile": [
                  8,
                  9,
                  11,
                  13,
                  11,
                  10,
                  11,
                  11,
                  11,
                  12,
                  13,
                  16,
                  26,
                  52,
                  199
              ],
              "nrf52840GpioStats": {},
              "batteryQmaxcell0": 15709,
              "bleConnectionStats": {
                  "minConnIntervalMs": 200,
                  "maxConnIntervalMs": 200,
                  "connSupTimeoutMs": 4000,
                  "mtu": 247,
                  "dleTx": 251,
                  "dleRx": 251
              },
              "nrf52ResetReasonRegister": 4,
              "stats": {
                  "ledPowerOnCount": 1,
                  "ledPowerOnTime": 7,
                  "bleConnCount": 5,
                  "bleModeConnOnTime": 71519,
                  "noconnModeTime": 42,
                  "wifiWakeHoldUpTime": 366,
                  "mainLoopTurns": 255329,
                  "pubsubTotalPublishedMessages": 85,
                  "mainLoopSleepEnterCalls": 255329,
                  "gnssToCpuDataAnnouncements": 8,
                  "modemToCpuDataAnnouncements": 19,
                  "bleEventHandlerCalls": 10369,
                  "appTimerStartCalls": 10342,
                  "appTimerStopCalls": 13525,
                  "cpuTaskletScheduleCalls": 1060
              },
              "selfTestResults": {}
          },

I commented out references to batteryHealth in fiDevice.py on lines 24 and 60-62, restarted the debugger and the issue seemed to be resolved as the traceback error disappears and I receive the information I would expect without further error.

Further, after manually removing batteryHealth in this package, and restarting my HA instance, all issues there were resolved and all of my devices / bases's attributes were available again.

jldeen commented 1 year ago

Closing this issue as the latest fix - 0.0.019 resolves the issue. Thanks for the speedy update!