dgreif / homebridge-hatch-baby-rest

A homebridge plugin for Hatch Baby Rest night light
MIT License
70 stars 19 forks source link

BUGFIX - Add USER_AGENT: hatch_rest_api #108

Closed brentleeper closed 1 year ago

brentleeper commented 1 year ago

The following header now appears to be required for all requests.

USER_AGENT: hatch_rest_api

Made this on my phone, sorry if there are any issues with tabs / spaces. Feel free to edit but the primary goal is to injected the newly required header.

brentleeper commented 1 year ago

Addresses issue: https://github.com/dgreif/homebridge-hatch-baby-rest/issues/107

uberfastman commented 1 year ago

Tried this out just by adding the extra header to the request options directly in the homebridge-hatch-baby-rest package in node_modules in my homebridge data dir, then restarted the plugin, and voila, working again! Nice fix @brentleeper!

👍 for this PR!

brentleeper commented 1 year ago

You’re welcome. Glad it worked! I never got to test this 😅

brentleeper commented 1 year ago

@dgreif can I get a review please? 🙏

uberfastman commented 1 year ago

From a testing standpoint I only had to add the header to make it work. Since the node_modules package is compiled JS from TypeScript, adding the second change in place was a bit wonky so I figured I'd just try it with only the header, and that seemed sufficient.

That being said, maybe there's extra utility there that I wasn't accounting for?

Regardless I hope this gets approved and merged ASAP so a new version can be released. When my Pico remote stopped being able to trigger my Hatch Baby Rest HomeKit scene, it was genuinely making bedtime with my son more challenging, so big kudos @brentleeper 🤣

eightball011854 commented 1 year ago

@uberfastman would love to see a screenshot of this so I can mimic, please? not an expert by any means but good a monkey see monkey do

uberfastman commented 1 year ago

@eightball011854 I'm running Homebridge in a docker container on an RPi 4, but I have the Homebridge directory mounted as a volume so it can be accessed outside of the container, so I edited the compiled code by running sudo vim homebridge/node_modules/homebridge-hatch-baby-rest/lib/homebridge-hatch-baby-rest/rest-client.js, and updated the following code block to include the header like below:

const apiBaseUrl = 'https://data.hatchbaby.com/', defaultRequestOptions = {
    http2: true,
    responseType: 'json',
    method: 'GET',
    headers: {
        USER_AGENT: 'hatch_rest_api',
    },
};

Then I just restarted the plugin (I have it running as a child bridge so I restarted that, although you could accomplish the same thing by just restarting Homebridge), and then it was good to go!

eightball011854 commented 1 year ago

thanks @uberfastman !

dgreif commented 1 year ago

Looks like there are some lint issues in this PR. I went ahead and made a similar change in main and will release it shortly. Thanks for the PR @brentleeper!

brentleeper commented 1 year ago

I figured that might be the case. I literally wrote this on my phone while in traffic and I’ve been too busy to circle back. Thank you @dgreif

dgreif commented 1 year ago

No problem, thanks for the fix!