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

Cannot read property 'DropMeal' of undefined error #19

Closed ryanphillipthomas closed 3 years ago

ryanphillipthomas commented 3 years ago

Thank you for making this plugin! Im excited to get it setup, wanted to let you know I'm seeing this error on the most recent version of the plugin, 1.9.0 did not throw this error. Let me know how i can assist in debugging.

[2/7/2021, 12:42:00 PM] TypeError: Cannot read property 'DropMeal' of undefined
    at petkit_feeder_mini_plugin.getServices (/usr/local/lib/node_modules/homebridge-petkit-feeder-mini/index.js:230:42)
    at Server.createHAPAccessory (/usr/local/lib/node_modules/homebridge/src/server.ts:442:41)
    at /usr/local/lib/node_modules/homebridge/src/server.ts:360:30
    at Array.forEach (<anonymous>)
    at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/src/server.ts:330:29)
    at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:156:12)
    at cli (/usr/local/lib/node_modules/homebridge/src/cli.ts:80:10)
    at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)

[2/7/2021, 12:42:00 PM] Got SIGTERM, shutting down Homebridge...
ryanphillipthomas commented 3 years ago

Here is the config being used, X-Session is omitted for security reasons, but still supplied on my end.

       {
            "name": "Hallway Feeder B",
            "location": "north_america",
            "headers": [
                {
                    "key": "X-Session",
                    "value": "*****"
                }
            ],
            "deviceId": "100030874",
            "mealAmount": 3,
            "autoDeviceInfo": true,
            "sn": "PetkitFeederMini",
            "firmware": "1.0.0",
            "manufacturer": "Petkit",
            "model": "Petkit feeder mini",
            "enable_polling": true,
            "polling_interval": 60,
            "enable_desiccant": true,
            "enable_autoreset_desiccant": true,
            "alert_desiccant_threshold": 7,
            "reset_desiccant_threshold": 5,
            "enable_manualLock": true,
            "enable_lightMode": true,
            "reverse_foodStorage_indicator": true,
            "fast_response": true,
            "accessory": "petkit_feeder_mini"
        },
        {
            "name": "Hallway Feeder A",
            "location": "north_america",
            "headers": [
                {
                    "key": "X-Session",
                    "value": "*****"
                }
            ],
            "deviceId": "100030875",
            "mealAmount": 3,
            "autoDeviceInfo": false,
            "sn": "PetkitFeederMini",
            "firmware": "1.0.0",
            "manufacturer": "Petkit",
            "model": "Petkit feeder mini",
            "enable_polling": true,
            "polling_interval": 60,
            "enable_desiccant": false,
            "enable_autoreset_desiccant": false,
            "alert_desiccant_threshold": 7,
            "reset_desiccant_threshold": 5,
            "enable_manualLock": false,
            "enable_lightMode": false,
            "reverse_foodStorage_indicator": false,
            "fast_response": false,
            "accessory": "petkit_feeder_mini"
        }
elfive commented 3 years ago

Is your X-Session value correct? with your config, and my own X-Session ID, it works well, and when I use an invalid X-Session value, it cause an exception like yours. you can check this by starting homebridge with flag '-D' which output more detailed information you may need.

if your X-Session value is outdated, something similar will show in homebridge log:

/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] Initializing petkit_feeder_mini accessory...
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] begin to initialize petkit feeder mini.
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] header set X-Session should equal to header set F-Session, replace F-Session.
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] post request success
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] {"error":{"code":5,"msg":"Session has timed out, please log back in"}}
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] JSON.parse error with:[object Object]
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] [PetkitFeederMini] begin to initialize homebridge service.
/usr/lib/node_modules/homebridge/src/logger.ts:175
[2/9/2021, 3:57:50 PM] TypeError: Cannot read property 'DropMeal' of undefined
    at petkit_feeder_mini_plugin.getServices (/homebridge-petkit-feeder-mini/index.js:230:42)
    at Server.createHAPAccessory (/usr/lib/node_modules/homebridge/src/server.ts:448:41)
    at /usr/lib/node_modules/homebridge/src/server.ts:358:30
    at Array.forEach (<anonymous>)
    at Server._loadAccessories (/usr/lib/node_modules/homebridge/src/server.ts:328:29)
    at Server.start (/usr/lib/node_modules/homebridge/src/server.ts:154:12)
    at cli (/usr/lib/node_modules/homebridge/src/cli.ts:80:10)
    at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
[2/9/2021, 3:57:50 PM] Got SIGTERM, shutting down Homebridge...

[2/9/2021, 3:57:50 PM] [PetkitFeederMini] {"error":{"code":5,"msg":"Session has timed out, please log back in"}} this is server response to you, and you may need check it out.

since I did not check the code server response to me, so Cannot read property 'DropMeal' of undefined error will happen under this circumstance.

elfive commented 3 years ago

I published a new version, which should prevent plugin crashes homebridge.

ryanphillipthomas commented 3 years ago

Thank you for pushing the update, I just installed it but unfortunately I'm still getting the same error. I'll double check the X-Session ID too but im pretty sure its correct. Strange. Do you think it could be related to the version of Homebridge?

Started Homebridge v1.1.7 with PID: 34932

Screen Shot 2021-02-09 at 11 43 34 PM

ryanphillipthomas commented 3 years ago

Ah @elfive your right, Im getting that in the logs like you described:

[2/9/2021, 11:51:41 PM] [Hallway Feeder B] header set X-Session should equal to header set F-Session, replace F-Session. [2/9/2021, 11:51:41 PM] [Hallway Feeder B] post request success [2/9/2021, 11:51:41 PM] [Hallway Feeder B] {"result":{"d4":{"enable":1},"devices":[{"data":{"name":"Hallway Feeder A","createdAt":"2020-12-11T00:30:26.650Z","id":100030875,"state":1,"relation":{"petIds":["100191543"],"userId":"100137817"},"status":{"batteryPower":4,"batteryStatus":0,"desiccantLeftDays":21,"errorPriority":0,"feeding":0,"food":1,"ota":0,"overall":1,"pim":1,"runtime":69475,"wifi":{"bssid":"189088266e13","rsq":-36,"ssid":"Mr Lofty"}},"desc":"下次出粮时间: 周三 05:30"},"type":"FeederMini"},{"data":{"name":"Hallway Feeder B","createdAt":"2020-12-11T00:16:02.505Z","id":100030874,"state":1,"relation":{"petIds":["100191544"],"userId":"100137817"},"status":{"batteryPower":4,"batteryStatus":0,"desiccantLeftDays":21,"errorPriority":0,"feeding":0,"food":1,"ota":0,"overall":1,"pim":1,"runtime":12242,"wifi":{"bssid":"189088266e13","rsq":-46,"ssid":"Mr Lofty"}},"desc":"下次出粮时间: 周三 05:30"},"type":"FeederMini"}],"cozy":{"gearsTotal":6,"enable":1,"tempunit":0,"sTempMin":10,"isShowDeviceSafetyClause":0,"gearsOffset":3,"sTempMax":42},"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":{}}} [2/9/2021, 11:51:41 PM] [Hallway Feeder B] seems that you ownd more than one feeder mini [2/9/2021, 11:51:41 PM] [Hallway Feeder B] do you mean one of this: [{"id":100030875,"name":"Hallway Feeder A"},{"id":100030874,"name":"Hallway Feeder B"}] [2/9/2021, 11:51:41 PM] [Hallway Feeder B] begin to initialize homebridge service. [2/9/2021, 11:51:41 PM] TypeError: Cannot read property 'DropMeal' of undefined at petkit_feeder_mini_plugin.getServices (/usr/local/lib/node_modules/homebridge-petkit-feeder-mini/index.js:230:42) at Server.createHAPAccessory (/usr/local/lib/node_modules/homebridge/src/server.ts:442:41) at /usr/local/lib/node_modules/homebridge/src/server.ts:360:30 at Array.forEach (<anonymous>) at Server._loadAccessories (/usr/local/lib/node_modules/homebridge/src/server.ts:330:29) at Server.start (/usr/local/lib/node_modules/homebridge/src/server.ts:156:12) at cli (/usr/local/lib/node_modules/homebridge/src/cli.ts:80:10) at Object.<anonymous> (/usr/local/lib/node_modules/homebridge/bin/homebridge:17:22) at Module._compile (internal/modules/cjs/loader.js:1137:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10) at Module.load (internal/modules/cjs/loader.js:985:32) at Function.Module._load (internal/modules/cjs/loader.js:878:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47

Sorry let me debug the X-Session-ID again. It must be incorrect.

ryanphillipthomas commented 3 years ago

Sorry for all the updates here @elfive, so I used postman and re-verified I'm actually supplying the correct X-Session. I looked through the logs with -D as you recommended. Im noticing that Im not getting the same errors that you had above with the invalid session ID. Instead it looks like petkit is successfully returning but the error still persists and crashes.

Screen Shot 2021-02-10 at 12 03 28 AM

elfive commented 3 years ago

update: I published a new version, this should fix your problem, sorry for causing such troubles to you. please update and test if it works with you. If you found any problems, please let me know.

original reply:

thank you for your report, I have located this problem. soon I will publish a new version after I tested it.
ryanphillipthomas commented 3 years ago

That worked! Sorta. Defiantly progress made thou. Thank you for pushing the update. I appreciate it, also no worries about the issues. It's not causing any trouble, i'm happy to assist and help debug / test. Thanks for your time on this plugin and please let me know how I can donate.

So after the install I can report were no longer crashing on initialization. Everything is setting up correctly, when I go to toggle the switches for the feeders I'm getting a new set of errors, and unfortunately nothing is dispensing. Its as if the units are not receiving / relaying commands.

Here is a screenshot of what I see when starting homebridge: Screen Shot 2021-02-10 at 8 38 18 AM

Here is a screenshot of what I see in the logs when toggling the units via the switches to dispense. Screen Shot 2021-02-10 at 8 40 06 AM

Screen Shot 2021-02-10 at 8 41 47 AM

Screen Shot 2021-02-10 at 8 49 33 AM

elfive commented 3 years ago

Sorry for the delay. You can now update to version 1.10.3, which fixed a mistake in my code, so I really sorry for it.

As for donation, I'm very happy my work helped you, for some reason, in my country I can not set up a Paypal,so ... Thank you any way, I appreciate it.

ryanphillipthomas commented 3 years ago

Thank you! Confirming the last update fixed everything. Both feeders are working as expected.