Coder Social home page Coder Social logo

jfarmer08 / wyze-api Goto Github PK

View Code? Open in Web Editor NEW
11.0 11.0 5.0 280 KB

An un-official API wrapper for Wyze products

License: MIT License

JavaScript 100.00%
home-automation javascript node node-js nodejs wyze wyze-bulbs wyze-plug wyze-sensors wyze-switches wyzecam

wyze-api's People

Contributors

dependabot[bot] avatar hgoscenski avatar jfarmer08 avatar tj-noor avatar togiles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wyze-api's Issues

Make sure all other request don't exceed 1 request per second

All other MAX Request per time == 1 request per sec

Request 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300
seconds 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240 250 260 270 280 290 300

Error when refresh token expires

After token expires, it appears that without checking the code/msg of the response the wyze-api is not attempting to refresh the token.

[2/13/2024, 3:08:58 PM] [Wyze Smart home] Refreshing devices...
[2/13/2024, 3:08:58 PM] [Wyze Smart home] Performing request: app/v2/home_page/get_object_list
[2/13/2024, 3:08:58 PM] [Wyze Smart home] Request config: {"method":"POST","url":"app/v2/home_page/get_object_list","data":{"access_token":"<SNIP>","app_name":"com.hualai.WyzeCam","app_ver":"wyze_developer_api","app_version":"wyze_developer_api","phone_id":"wyze_developer_api","phone_system_type":"1","sc":"wyze_developer_api","sv":"wyze_developer_api","ts":1707836938928},"baseURL":"https://api.wyzecam.com"}
[2/13/2024, 3:08:59 PM] [Wyze Smart home] API response PerformRequest: {"code":"2001","msg":"access token is error","traceId":"265862178700f9a907ae2dc979f8daa7","data":{}}
[2/13/2024, 3:08:59 PM] [Wyze Smart home] access token is error
[2/13/2024, 3:08:59 PM] [Wyze Smart home] Error getting devices: TypeError: Cannot read properties of undefined (reading 'length')

Add calls to use async request(url, data = {}) command instead of direct

Some of these calls are using Patch, Post, Get or delete. So the main Request call would need to handle this.

getIotProp
controlLock
getLockInfo
setIotProp
getUserProfile
disableRemeAlarm
getPlanBindingListByUser
monitoringProfileStateStatus
monitoringProfileActive
thermostatGetIotProp
thermostatSetIotProp

Getting an authentication error via Wyze Homebridge plug-in

Hi,

I received an e-mail from Wyze that they had reset my password after detecting suspicious access (homebridge?) - I am not sure. But I played along and changed my password, etc. Since then, it has broken the Wyze HomeBridge plug-in and keeps failing with a Cloudfront "Blocked Access" error.

I looked at the plug-in source and saw that it was using this wyze-api as it's connector to Wyze. I figured the auth error was lower down than the HomeBridge Wyze plugin - so I cloned this repo and ran the "example".

It failed with the same error:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">\n' +
      '<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">\n' +
      '<TITLE>ERROR: The request could not be satisfied</TITLE>\n' +
      '</HEAD><BODY>\n' +
      '<H1>403 ERROR</H1>\n' +
      '<H2>The request could not be satisfied.</H2>\n' +
      '<HR noshade size="1px">\n' +
      'Request blocked.\n' +
      "We can't connect to the server for this app or website at this time. There might be too much traffic or a configuration error. Try again later, or contact the app or website owner.\n" +
      '<BR clear="all">\n' +
      'If you provide content to customers through CloudFront, you can find steps to troubleshoot and help prevent this error by reviewing the CloudFront documentation.\n' +
      '<BR clear="all">\n' +
      '<HR noshade size="1px">\n' +
      '<PRE>\n' +
      'Generated by cloudfront (CloudFront)\n' +
      'Request ID: K12IGdVcVbcgkfCluSWeGKjZPK2hQT1U84W3rS9JmNJwdkb693Pf7Q==\n' +
      '</PRE>\n' +
      '<ADDRESS>\n' +
      '</ADDRESS>\n' +
      '</BODY></HTML>

This is vague, but I tried making some direct HTTPS requests to the endpoint (wyze auth api) and got some BAD REQUEST 400's - so something made me think maybe the userAgent was bad. It didn't seem like Wyze was blocking our requests entirely - just that it didn't like them for some reason.

I noticed the userAgent was hard-coded into the plug-in, and then saw that options.userAgent would allow me to override it. I'm not sure why I went here, but anyway - I specified my current Firefox userAgent and it worked!

I don't know if Wyze + Cloudfront have started blocking the old userAgent as being invalid/too old --- or knowing it is coming from this plugin in some way? (I searched issues on the wyze plugin and Reddit for "fresh" info but nobody else appears to be reporting this...)

The constant I currently see is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1 Safari/605.1.15

which is OSX 10.15 (same as mine! - but it's old) - and Safari 14 - but 17 is out.

I'm reporting this here because I'm not entirely certain how to fast-track a custom wyze-api module into my Homebridge configuration and escalating here so that it can hopefully get incorporated/fixed here and bumped up into an update on the Homebridge plug-in side.

Here is the index.js changes I have in the example that did work:

//const WyzeAPI = require('../src/index') // Local Debug
const WyzeAPI = require("wyze-api");
const Logger = require("@ptkdev/logger");

const logger = new Logger();

const options = {
  username: "***
  password: "***",
  keyId: "****",
  apiKey: "****,
  persistPath: "./scratch",
  logLevel: "debug",
  apiLogEnabled: true,
  userAgent:
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0",
};
const wyze = new WyzeAPI(options, logger);

(async () => {
  const devices = await wyze.getDeviceList();
  logger.debug(JSON.stringify(devices));
})();

Without fully understanding this codebase - I'm not saying the userAgent is the only fix needed here. I am not sure why Wyze/Cloudfront would be blocking the UserAgent defined in the constants.

FWIW, I tested the example with the following user agents from my other browsers:

WORKS - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6.1 Safari/605.1.1

WORKS - Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0

WORKS Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36

Thanks for all your work on this lib and the HomeBridge plug-in. Much appreciated!

I hope this info helps.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.