elfive / homebridge-petkit-feeder-mini

control your petkit feeder mini from homekit, get full use of iOS automation
Apache License 2.0
31 stars 10 forks source link

Specifying deviceId as a string stops plugin from starting #23

Closed beefcheeks closed 3 years ago

beefcheeks commented 3 years ago

Describe the bug If you use the Homebridge Plugin Setting UI to specify the device ID of a feeder (or set of feeders), it will, by default, save the value as a string to the config file. However, the HTTP response returned by the PetKit servers contains the same ID, but it is a number, and not a string. Unfortunately, in this situation, the current plugin code does not find a matching device and the plugin fails to start as a result. Simply changing the deviceId from a string to a number directly in the config file fixes the issue, but I imagine most users do not have their debug logs on to see the entire http response and may not as easily come to this conclusion.

I would recommend one of two approaches to fix this issue:

  1. Save the deviceId as a number when setting it up via the Homebridge Plugin Setting UI
  2. Use a fuzzy match comparison (==) when matching the deviceIDs.

Detailed Information

  1. NodeJS version: v14.16.0

  2. Homebridge version: v1.3.4

  3. Plugin version: v2.0.2

  4. Example of configure(REMOVE sensitive info!):

    platforms: [
        {
            "log_level": 1,
            "devices": [
                {
                    "headers": [
                        {
                            "key": "X-Session",
                            "value": "<redacted>"
                        }
                    ],
                    "location": "north_america",
                    "model": "FeederMini",
                    "deviceId": "<id as string>",
                    "enable_http_retry": false,
                    "http_retry_count": 3,
                    "DropMeal_name": "Bowie Manual Meal",
                    "MealAmount_name": "Bowie Meal Amount",
                    "FoodStorage_name": "Bowie Low Food",
                    "DesiccantLevel_name": "Bowie Desiccant",
                    "ManualLock_name": "Bowie Push Button",
                    "LightMode_name": "LightMode",
                    "Battery_name": "Bowie Feeder Battery",
                    "enable_polling": true,
                    "polling_interval": 60,
                    "enable_desiccant": true,
                    "alert_desiccant_threshold": 3,
                    "enable_autoreset_desiccant": false,
                    "reset_desiccant_threshold": 1,
                    "enable_manualLock": true,
                    "enable_lightMode": false,
                    "reverse_foodStorage_indicator": true,
                    "fast_response": false
                },
                {
                    "headers": [
                        {
                            "key": "X-Session",
                            "value": "<redacted>"
                        }
                    ],
                    "location": "north_america",
                    "model": "FeederMini",
                    "deviceId": "<id as string>",
                    "enable_http_retry": false,
                    "http_retry_count": 3,
                    "DropMeal_name": "Finley Manual Meal",
                    "MealAmount_name": "Finley Meal Amount",
                    "FoodStorage_name": "Finley Low Food",
                    "DesiccantLevel_name": "Finley Desiccant",
                    "ManualLock_name": "Finley Push Button",
                    "LightMode_name": "Finley Feeder Light",
                    "Battery_name": "Finley Feeder Battery",
                    "enable_polling": true,
                    "polling_interval": 60,
                    "enable_desiccant": true,
                    "alert_desiccant_threshold": 3,
                    "enable_autoreset_desiccant": false,
                    "reset_desiccant_threshold": 1,
                    "enable_manualLock": true,
                    "enable_lightMode": false,
                    "reverse_foodStorage_indicator": true,
                    "fast_response": false
                }
            ],
            "platform": "petkit_feeder_mini"
        }
    ]
  5. Logs(REMOVE sensitive info and homebridge debug mode):

    2021-03-30 19:23:55.378  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [INFO] initializing Petkit Feeder device.
    2021-03-30 19:23:55.378  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [DEBUG] request device info from Petkit server.
    2021-03-30 19:23:55.950  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [DEBUG] http request success
    2021-03-30 19:23:55.951  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [DEBUG] {"result":{"d4":{"enable":0},"devices":[{"data":{"name":"Finley’s Feeder","createdAt":"2019-12-07T21:19:38.210Z","id":<redacted numeric id>,"state":1,"relation":{"petIds":["<redacted string value>"],"userId":"<redacted string id>"},"status":{"batteryPower":4,"batteryStatus":0,"desiccantLeftDays":0,"errorPriority":0,"feeding":0,"food":1,"ota":0,"overall":1,"pim":1,"runtime":24261,"wifi":{"bssid":"<redacted hex value>","rsq":-51,"ssid":"<redacted>"}},"desc":"Next feeding time: 21:00"},"type":"FeederMini"},{"data":{"name":"Bowie’s Feeder","createdAt":"2019-10-18T07:21:42.364Z","id":<redacted numeric id>,"state":1,"relation":{"petIds":["<redacted>"],"userId":"<redacted string id>"},"status":{"batteryPower":4,"batteryStatus":0,"desiccantLeftDays":0,"errorPriority":0,"feeding":0,"food":1,"ota":0,"overall":1,"pim":1,"runtime":40835,"wifi":{"bssid":"<redacted hex value>","rsq":-36,"ssid":"<redacted>"}},"desc":"Next feeding time: 21:00"},"type":"FeederMini"}],"cozy":{"gearsTotal":6,"enable":1,"tempunit":1,"sTempMin":50,"isShowDeviceSafetyClause":0,"gearsOffset":3,"sTempMax":108},"feeder":{"isShowDeviceSafetyClause":0},"k2":{"enable":1},"go":{"hasMarks":0,"maxMarksPerRoute":30,"markEnabled":1},"feedermini":{"isShowDeviceSafetyClause":0},"tools":[{"type":"walkpet","data":{}},{"type":"weight"},{"type":"remind","data":{}}],"t3":{"enable":1},"d3":{}}}
    2021-03-30 19:23:55.953  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [ERROR] seems that you ownd more than one feeder, but the device id you set is not here.
    2021-03-30 19:23:55.953  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [ERROR] do you mean one of this: 
    2021-03-30 19:23:55.954  homebridge-697d8cdfd6-mflh8  homebridge  [3/30/2021, 7:23:55 PM] [petkit_feeder_mini] [ERROR] initialize Petkit Feeder failed: could not find supported device.
elfive commented 3 years ago

A patch version v2.0.3 was released. This version should fix this problem.

beefcheeks commented 3 years ago

awesome, thanks!

beefcheeks commented 3 years ago

Verified working in v2.0.3 - closing this out.