-
-
Notifications
You must be signed in to change notification settings - Fork 352
Same bug as #182 but for encode instead of parse #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Owner
|
👍 everything appears to be fixed except for cases when the stub device emits a packet with two responses. It feels wrong, but they'll probably pass on Travis due to running more slowly than they do on my local machine. Still working on #176 to fix this (don't need a code review yet, but if you could comment there on what you've experienced with devices it'd be very helpful). |
codetheweb
added a commit
that referenced
this pull request
Jun 1, 2019
…gle packet (#203) * Terse defaults (#162) * Replaced manual argument default checking with ES6 style default arguments and destructuring assignments Improves code clarity through easy to see defaults and reduced boilerplate Tiny tweaks for terse code; less code, less reading, less maintenance :) * Fixed namespace collision with timeout accidentally introduced in last commit * Travis doesn't like how terse my code is ;P * Removed check for IP address in _send which will never be reached, since we're checking .isConnected() first * Parser cipher updates (#160) * Fixed a few parsing issues: zero-padding is actually the return code from the device where 0 = success Added _returnCode, _crc to MessageParser (reordered to match order in memory) (crc is not actually checked here, but it could be!) More restrictive length checks, taking into account _returnCode and _crc _commandByte is a uint32 Fill _leftOver with, well, leftovers Reordered parse logic to match order in memory (this also allows us to extract more data in case of a suffix mismatch) suffix indexed relative to _payloadSize, relevant in the case of leftovers (which happens when two messages are sent in one) These changes were made with the best attempt to adhere to the existing coding style I would personally make parse and encode both static functions We could check the crc value for data integrity If _leftOver is populated, better try decoding that too A more drastic overhaul can be found: https://github.com/kueblc/mocktuyacloud/blob/master/lib/lan-frame.js But no attempt has been made to maintain the previous coding style This adaptation was made to integrate seamlessly into the existing tuyapi project * Reimplemented encrypt, decrypt, and md5 using built in crypto library Removes dependency on third party node-forge library Clarified md5 documentation * Default encrypt options.base64 to true * Fix lint no-negated-condition * Cleaned up _encode implementation using one buffer to assemble payload and remove string representations of binary data * Fixed test for encrypting with base64 option disabled Had previously made a poor assumption about the meaning of the flag and hadn't realized utf8 is not binary safe * Fixed cipher.encrypt base64 option, now correctly outputs a Buffer when base64 = false * Throw appropriate errors when parsing fails Replaced 16 with a constant HEADER_SIZE for better code readability Cleverly account for return code or lack thereof by checking if the first 3 bytes are zero, which they often (always?) are for return code Moving forward, we should decide whether this parser should serve both client and device emulation * Removed unused _parsed flag * Added tests for message-parser, bringing coverage to 100 Test decoding a plaintext payload, as is the case when a device reports an error Test for several types of corrupt messages; short, way too short, prefix and suffix mismatch Test handling of two packets coming through at the same time (for the time being, we just don't catch the second message; this should change) * Removed unused crc package from dependencies * Move clone from prod dependencies to dev dependencies * Moved parse and encode from static wrapped Class methods into static functions, skipping the middle man This change touched a lot of lines due to indentation and a few renames but code was otherwise unmodified More cleanup to come once we move on to breaking changes (ie its possible to receive multiple packets in one buffer, should therefore change parse to return an array of parsed packets) (this will require touching index.js and so is left for another revision) We can also return more information about the packet than we currently are (ie sequence index, return code) We can also generate and check CRCs (to be ported from MockTuyaCloud) * Pin dependency clone to 2.1.2 (#167) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | clone | devDependencies | pin | `^2.1.2` -> `2.1.2` | [source](https://togithub.com/pvorb/node-clone) | :pushpin: **Important**: Renovate will wait until you have merged this Pin PR before creating any *upgrade* PRs for the affected packages. Add the preset `:preserveSemverRanges` your config if you instead don't wish to pin dependencies. --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR is stale, or if you modify the PR title to begin with "`rebase!`". :ghost: **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://togithub.com/renovatebot/config-help/issues) if that's undesired. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency ava to v1.3.0 (#170) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | ava | devDependencies | minor | `1.2.1` -> `1.3.0` | [homepage](https://ava.li), [source](https://togithub.com/avajs/ava) | --- ### Release Notes <details> <summary>avajs/ava</summary> ### [`v1.3.0`](https://togithub.com/avajs/ava/releases/v1.3.0) [Compare Source](https://togithub.com/avajs/ava/compare/v1.2.1...v1.3.0) #### Bug fixes - We've fixed a rather embarrasing bug with `t.throws()` and `t.throwsAsync()`. If you'd set a `code` expectation to a number we never actually _checked_ that the thrown error had such a code! Thanks to [@​qlonik](https://togithub.com/qlonik) for both spotting and fixing this. [`82daa5e`](https://togithub.com/avajs/ava/commit/82daa5e373ef0587693927acc63ce5590e8d8eb2) - 1.2.0 contained a regression which meant that if you [faked](https://www.npmjs.com/package/lolex) `clearTimeout()`, you'd break AVA. That's now been fixed. [`40f331c`](https://togithub.com/avajs/ava/commit/40f331c27e70690e724f9ddc893fed0556058987) - Snapshot files are now recognized as source files, so if you're using watch mode and you delete one, AVA won't rerun _all_ your test files. [`d066f6f`](https://togithub.com/avajs/ava/commit/d066f6fbc06ab2fa2d391ff373f5f09b2585b900) #### New features You can now use `require()` in `ava.config.js` files to load non-ES modules. [`334e15b`](https://togithub.com/avajs/ava/commit/334e15b4af06492c9aed2800a0764f245d6a908b) #### All changes [`v1.2.1...v1.3.0`](https://togithub.com/avajs/ava/compare/v1.2.1...v1.3.0) #### Thanks Thank you [@​itaisteinherz](https://togithub.com/itaisteinherz), [@​jdalton](https://togithub.com/jdalton), [@​kagawagao](https://togithub.com/kagawagao), [@​KompKK](https://togithub.com/KompKK), [@​SleeplessByte](https://togithub.com/SleeplessByte), [@​Chrisyee22](https://togithub.com/Chrisyee22) and [@​qlonik](https://togithub.com/qlonik) for helping us with this release. We couldn't have done this without you! #### Get involved We welcome new contributors. AVA is a friendly place to get started in open source. We have a [great article](https://medium.com/@​vadimdemedes/making-your-first-contribution-de6576ddb190#.umxr7id07) on getting started contributing and a comprehensive [contributing guide](https://togithub.com/avajs/ava/blob/master/contributing.md). </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency ava to v1.3.1 (#171) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | ava | devDependencies | patch | `1.3.0` -> `1.3.1` | [homepage](https://ava.li), [source](https://togithub.com/avajs/ava) | --- ### Release Notes <details> <summary>avajs/ava</summary> ### [`v1.3.1`](https://togithub.com/avajs/ava/releases/v1.3.1) [Compare Source](https://togithub.com/avajs/ava/compare/v1.3.0...v1.3.1) #### Bug fixes - We've fixed a rather embarrasing bug with `t.throws()` and `t.throwsAsync()`. If you'd set a `code` expectation to a number we never actually _checked_ that the thrown error had such a code! Thanks to [@​qlonik](https://togithub.com/qlonik) for both spotting and fixing this. [`82daa5e`](https://togithub.com/avajs/ava/commit/82daa5e373ef0587693927acc63ce5590e8d8eb2) - 1.2.0 contained a regression which meant that if you [faked](https://www.npmjs.com/package/lolex) `clearTimeout()`, you'd break AVA. That's now been fixed. [`40f331c`](https://togithub.com/avajs/ava/commit/40f331c27e70690e724f9ddc893fed0556058987) - Snapshot files are now recognized as source files, so if you're using watch mode and you delete one, AVA won't rerun _all_ your test files. [`d066f6f`](https://togithub.com/avajs/ava/commit/d066f6fbc06ab2fa2d391ff373f5f09b2585b900) #### New features You can now use `require()` in `ava.config.js` files to load non-ES modules. [`334e15b`](https://togithub.com/avajs/ava/commit/334e15b4af06492c9aed2800a0764f245d6a908b) #### All changes [`v1.2.1...v1.3.1`](https://togithub.com/avajs/ava/compare/v1.2.1...v1.3.1) #### Thanks Thank you [@​itaisteinherz](https://togithub.com/itaisteinherz), [@​jdalton](https://togithub.com/jdalton), [@​kagawagao](https://togithub.com/kagawagao), [@​KompKK](https://togithub.com/KompKK), [@​SleeplessByte](https://togithub.com/SleeplessByte), [@​Chrisyee22](https://togithub.com/Chrisyee22) and [@​qlonik](https://togithub.com/qlonik) for helping us with this release. We couldn't have done this without you! #### Get involved We welcome new contributors. AVA is a friendly place to get started in open source. We have a [great article](https://medium.com/@​vadimdemedes/making-your-first-contribution-de6576ddb190#.umxr7id07) on getting started contributing and a comprehensive [contributing guide](https://togithub.com/avajs/ava/blob/master/contributing.md). </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency p-retry to v4 (#172) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | p-retry | dependencies | major | [`3.0.1` -> `4.0.0`](https://diff.intrinsic.com/p-retry/3.0.1/4.0.0) | [source](https://togithub.com/sindresorhus/p-retry) | --- ### Release Notes <details> <summary>sindresorhus/p-retry</summary> ### [`v4.0.0`](https://togithub.com/sindresorhus/p-retry/releases/v4.0.0) [Compare Source](https://togithub.com/sindresorhus/p-retry/compare/v3.0.1...v4.0.0) Breaking: - Require Node.js 8 [`0ed8d5d`](https://togithub.com/sindresorhus/p-retry/commit/0ed8d5d) ([#​21](https://togithub.com/sindresorhus/p-retry/issues/21)) [`4b6ec19`](https://togithub.com/sindresorhus/p-retry/commit/4b6ec19) Enhancements: - Throw a useful error if a non-error is thrown [`a9d75a5`](https://togithub.com/sindresorhus/p-retry/commit/a9d75a5) - Add TypeScript definition ([#​21](https://togithub.com/sindresorhus/p-retry/issues/21)) [`4b6ec19`](https://togithub.com/sindresorhus/p-retry/commit/4b6ec19) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency p-timeout to v3 (#173) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | p-timeout | dependencies | major | [`2.0.1` -> `3.0.0`](https://diff.intrinsic.com/p-timeout/2.0.1/3.0.0) | [source](https://togithub.com/sindresorhus/p-timeout) | --- ### Release Notes <details> <summary>sindresorhus/p-timeout</summary> ### [`v3.0.0`](https://togithub.com/sindresorhus/p-timeout/releases/v3.0.0) [Compare Source](https://togithub.com/sindresorhus/p-timeout/compare/v2.0.1...v3.0.0) Breaking: - Require Node.js 8 ([#​10](https://togithub.com/sindresorhus/p-timeout/issues/10)) [`9a429bc`](https://togithub.com/sindresorhus/p-timeout/commit/9a429bc) Enhancements: - Add TypeScript definition ([#​10](https://togithub.com/sindresorhus/p-timeout/issues/10)) [`9a429bc`](https://togithub.com/sindresorhus/p-timeout/commit/9a429bc) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency documentation to v9.3.1 (#174) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | documentation | devDependencies | minor | [`9.2.0` -> `9.3.1`](https://diff.intrinsic.com/documentation/9.2.0/9.3.1) | [source](https://togithub.com/documentationjs/documentation) | --- ### Release Notes <details> <summary>documentationjs/documentation</summary> ### [`v9.3.1`](https://togithub.com/documentationjs/documentation/blob/master/CHANGELOG.md#​1000-alpha0httpsgithubcomdocumentationjsdocumentationcomparev931v1000-alpha0-2019-03-12) [Compare Source](https://togithub.com/documentationjs/documentation/compare/v9.3.0...v9.3.1) ##### Features - Support custom babel config ([#​1205](https://togithub.com/documentationjs/documentation/issues/1205)) ([746d0a9](https://togithub.com/documentationjs/documentation/commit/746d0a9)) ##### BREAKING CHANGES - this may change babel configuration loading, and is a major change to the documentation.js approach to Babel. #### [9.3.1](https://togithub.com/documentationjs/documentation/compare/v9.3.0...v9.3.1) (2019-03-12) ### [`v9.3.0`](https://togithub.com/documentationjs/documentation/blob/master/CHANGELOG.md#​930httpsgithubcomdocumentationjsdocumentationcomparev921v930-2019-02-27) [Compare Source](https://togithub.com/documentationjs/documentation/compare/v9.2.1...v9.3.0) ##### Features - Add inner section ([#​1212](https://togithub.com/documentationjs/documentation/issues/1212)) ([64c9ca6](https://togithub.com/documentationjs/documentation/commit/64c9ca6)) #### [9.2.1](https://togithub.com/documentationjs/documentation/compare/v9.2.0...v9.2.1) (2019-02-26) ### [`v9.2.1`](https://togithub.com/documentationjs/documentation/blob/master/CHANGELOG.md#​930httpsgithubcomdocumentationjsdocumentationcomparev921v930-2019-02-27) [Compare Source](https://togithub.com/documentationjs/documentation/compare/v9.2.0...v9.2.1) ##### Features - Add inner section ([#​1212](https://togithub.com/documentationjs/documentation/issues/1212)) ([64c9ca6](https://togithub.com/documentationjs/documentation/commit/64c9ca6)) #### [9.2.1](https://togithub.com/documentationjs/documentation/compare/v9.2.0...v9.2.1) (2019-02-26) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * First attempt at queue system * Update dependency ava to v1.4.0 (#177) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | ava | devDependencies | minor | [`1.3.1` -> `1.4.0`](https://diff.intrinsic.com/ava/1.3.1/1.4.0) | [homepage](https://ava.li), [source](https://togithub.com/avajs/ava) | --- ### Release Notes <details> <summary>avajs/ava</summary> ### [`v1.4.0`](https://togithub.com/avajs/ava/releases/v1.4.0) [Compare Source](https://togithub.com/avajs/ava/compare/v1.3.1...v1.4.0) #### Focusing [`power-assert`](https://togithub.com/power-assert-js/power-assert) AVA comes with [`power-assert`](https://togithub.com/power-assert-js/power-assert) built-in, giving you more descriptive assertion messages. However it's been confusing to understand _which_ assertions come with `power-assert`. To address this we've added the new `t.assert()` assertion. It's now the only assertion that is `power-assert` enabled. The assertion passes if called with a truthy value. Consider this example: ```js test('enhanced assertions', t => { const a = /foo/; const b = 'bar'; const c = 'baz'; t.assert(a.test(b) || b === c); }); ``` <details> <summary>AVA will output:</summary> <pre><code>6: const c = 'baz'; 7: t.assert(a.test(b) || b === c); 8: }); Value is not truthy: false a.test(b) || b === c => false b === c => false c => 'baz' b => 'bar' a.test(b) => false b => 'bar' a => /foo/</code></pre> </details> Our [ESLint plugin](https://togithub.com/avajs/eslint-plugin-ava) has been updated to support this new assertion. Many thanks to [@​eemed](https://togithub.com/eemed) for implementing this! [`9406470`](https://togithub.com/avajs/ava/commit/94064702837583f1cd3920142c5d0ce50e71e255) #### Watch mode Watch mode now prints the available commands. Thanks [@​KompKK](https://togithub.com/KompKK)! [`cd256ac`](https://togithub.com/avajs/ava/commit/cd256ac53c975d51ddabd3d80a9f909424f5d7e3) #### Bug fixes - Filtered tests (when using `--match`, `.skip()` or `.only()`) are no longer included in the list of pending tests when timeouts occur or when you interrupt a test run. Thanks [@​vancouverwill](https://togithub.com/vancouverwill)! [`23e302a`](https://togithub.com/avajs/ava/commit/23e302a8dc35d03ba82916bd6591822a28d499d1) - We're now shimming all TTY methods in the worker processes, thanks to [@​okyantoro](https://togithub.com/okyantoro). [`c1f6fdf`](https://togithub.com/avajs/ava/commit/c1f6fdfed61c99c1144cff56b58d113810c630c8) #### Documentation updates - We've added a note to say that, by default, AVA does not have a default test timeout. Thanks [@​amokmen](https://togithub.com/amokmen)! [`99a10a1`](https://togithub.com/avajs/ava/commit/99a10a16a3e3037326c91fb23c2a052acd3abef9) #### All changes [`v1.3.1...v1.4.0`](https://togithub.com/avajs/ava/compare/v1.3.1...v1.4.0) #### Thanks Thank you [@​eemed](https://togithub.com/eemed), [@​KompKK](https://togithub.com/KompKK), [@​vancouverwill](https://togithub.com/vancouverwill), [@​okyantoro](https://togithub.com/okyantoro) and [@​amokmen](https://togithub.com/amokmen). We couldn't have done this without you! #### Get involved We welcome new contributors. AVA is a friendly place to get started in open source. We have a [great article](https://medium.com/@​vadimdemedes/making-your-first-contribution-de6576ddb190#.umxr7id07) on getting started contributing and a comprehensive [contributing guide](https://togithub.com/avajs/ava/blob/master/contributing.md). </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Implement Tuya flavored CRC (#178) * Fixed a few parsing issues: zero-padding is actually the return code from the device where 0 = success Added _returnCode, _crc to MessageParser (reordered to match order in memory) (crc is not actually checked here, but it could be!) More restrictive length checks, taking into account _returnCode and _crc _commandByte is a uint32 Fill _leftOver with, well, leftovers Reordered parse logic to match order in memory (this also allows us to extract more data in case of a suffix mismatch) suffix indexed relative to _payloadSize, relevant in the case of leftovers (which happens when two messages are sent in one) These changes were made with the best attempt to adhere to the existing coding style I would personally make parse and encode both static functions We could check the crc value for data integrity If _leftOver is populated, better try decoding that too A more drastic overhaul can be found: https://github.com/kueblc/mocktuyacloud/blob/master/lib/lan-frame.js But no attempt has been made to maintain the previous coding style This adaptation was made to integrate seamlessly into the existing tuyapi project * Reimplemented encrypt, decrypt, and md5 using built in crypto library Removes dependency on third party node-forge library Clarified md5 documentation * Default encrypt options.base64 to true * Fix lint no-negated-condition * Cleaned up _encode implementation using one buffer to assemble payload and remove string representations of binary data * Replaced manual argument default checking with ES6 style default arguments and destructuring assignments Improves code clarity through easy to see defaults and reduced boilerplate Tiny tweaks for terse code; less code, less reading, less maintenance :) * Fixed namespace collision with timeout accidentally introduced in last commit * Travis doesn't like how terse my code is ;P * Fixed test for encrypting with base64 option disabled Had previously made a poor assumption about the meaning of the flag and hadn't realized utf8 is not binary safe * Fixed cipher.encrypt base64 option, now correctly outputs a Buffer when base64 = false * Throw appropriate errors when parsing fails Replaced 16 with a constant HEADER_SIZE for better code readability Cleverly account for return code or lack thereof by checking if the first 3 bytes are zero, which they often (always?) are for return code Moving forward, we should decide whether this parser should serve both client and device emulation * Removed unused _parsed flag * Added tests for message-parser, bringing coverage to 100 Test decoding a plaintext payload, as is the case when a device reports an error Test for several types of corrupt messages; short, way too short, prefix and suffix mismatch Test handling of two packets coming through at the same time (for the time being, we just don't catch the second message; this should change) * Removed unused crc package from dependencies * Move clone from prod dependencies to dev dependencies * Moved parse and encode from static wrapped Class methods into static functions, skipping the middle man This change touched a lot of lines due to indentation and a few renames but code was otherwise unmodified More cleanup to come once we move on to breaking changes (ie its possible to receive multiple packets in one buffer, should therefore change parse to return an array of parsed packets) (this will require touching index.js and so is left for another revision) We can also return more information about the packet than we currently are (ie sequence index, return code) We can also generate and check CRCs (to be ported from MockTuyaCloud) * Removed check for IP address in _send which will never be reached, since we're checking .isConnected() first * Added implementation of Tuya's modified CRC32 algorithm * Restore package-lock from upstream/development * Fix lint warnings * Integrate CRC check in message-parser * Hack in support for sequence bytes * Update dependency ava to v1.4.1 (#179) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | ava | devDependencies | patch | [`1.4.0` -> `1.4.1`](https://diff.intrinsic.com/ava/1.4.0/1.4.1) | [homepage](https://ava.li), [source](https://togithub.com/avajs/ava) | --- ### Release Notes <details> <summary>avajs/ava</summary> ### [`v1.4.1`](https://togithub.com/avajs/ava/releases/v1.4.1) [Compare Source](https://togithub.com/avajs/ava/compare/v1.4.0...v1.4.1) #### Focusing [`power-assert`](https://togithub.com/power-assert-js/power-assert) AVA comes with [`power-assert`](https://togithub.com/power-assert-js/power-assert) built-in, giving you more descriptive assertion messages. However it's been confusing to understand _which_ assertions come with `power-assert`. To address this we've added the new `t.assert()` assertion. It's now the only assertion that is `power-assert` enabled. The assertion passes if called with a truthy value. Consider this example: ```js test('enhanced assertions', t => { const a = /foo/; const b = 'bar'; const c = 'baz'; t.assert(a.test(b) || b === c); }); ``` <details> <summary>AVA will output:</summary> <pre><code>6: const c = 'baz'; 7: t.assert(a.test(b) || b === c); 8: }); Value is not truthy: false a.test(b) || b === c => false b === c => false c => 'baz' b => 'bar' a.test(b) => false b => 'bar' a => /foo/</code></pre> </details> Our [ESLint plugin](https://togithub.com/avajs/eslint-plugin-ava) has been updated to support this new assertion. Many thanks to [@​eemed](https://togithub.com/eemed) for implementing this! [`9406470`](https://togithub.com/avajs/ava/commit/94064702837583f1cd3920142c5d0ce50e71e255) #### Watch mode Watch mode now prints the available commands. Thanks [@​KompKK](https://togithub.com/KompKK)! [`cd256ac`](https://togithub.com/avajs/ava/commit/cd256ac53c975d51ddabd3d80a9f909424f5d7e3) #### Bug fixes - Filtered tests (when using `--match`, `.skip()` or `.only()`) are no longer included in the list of pending tests when timeouts occur or when you interrupt a test run. Thanks [@​vancouverwill](https://togithub.com/vancouverwill)! [`23e302a`](https://togithub.com/avajs/ava/commit/23e302a8dc35d03ba82916bd6591822a28d499d1) - We're now shimming all TTY methods in the worker processes, thanks to [@​okyantoro](https://togithub.com/okyantoro). [`c1f6fdf`](https://togithub.com/avajs/ava/commit/c1f6fdfed61c99c1144cff56b58d113810c630c8) #### Documentation updates - We've added a note to say that, by default, AVA does not have a default test timeout. Thanks [@​amokmen](https://togithub.com/amokmen)! [`99a10a1`](https://togithub.com/avajs/ava/commit/99a10a16a3e3037326c91fb23c2a052acd3abef9) #### All changes [`v1.3.1...v1.4.1`](https://togithub.com/avajs/ava/compare/v1.3.1...v1.4.1) #### Thanks Thank you [@​eemed](https://togithub.com/eemed), [@​KompKK](https://togithub.com/KompKK), [@​vancouverwill](https://togithub.com/vancouverwill), [@​okyantoro](https://togithub.com/okyantoro) and [@​amokmen](https://togithub.com/amokmen). We couldn't have done this without you! #### Get involved We welcome new contributors. AVA is a friendly place to get started in open source. We have a [great article](https://medium.com/@​vadimdemedes/making-your-first-contribution-de6576ddb190#.umxr7id07) on getting started contributing and a comprehensive [contributing guide](https://togithub.com/avajs/ava/blob/master/contributing.md). </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Fix CRC computation; wrong payload range (my bad! no coding before coffee) (#182) * Update dependency p-retry to v4.1.0 (#181) * Same bug as #182 but for encode instead of parse (#184) I give up * Update dependency p-timeout to v3.1.0 (#186) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | p-timeout | dependencies | minor | [`3.0.0` -> `3.1.0`](https://diff.intrinsic.com/p-timeout/3.0.0/3.1.0) | [source](https://togithub.com/sindresorhus/p-timeout) | --- ### Release Notes <details> <summary>sindresorhus/p-timeout</summary> ### [`v3.1.0`](https://togithub.com/sindresorhus/p-timeout/releases/v3.1.0) [Compare Source](https://togithub.com/sindresorhus/p-timeout/compare/v3.0.0...v3.1.0) - Refactor TypeScript definition to CommonJS compatible export ([#​11](https://togithub.com/sindresorhus/p-timeout/issues/11)) [`695a09c`](https://togithub.com/sindresorhus/p-timeout/commit/695a09c) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Add support for parsing multiple packets in a single response * Add documentation * Remove TODO from README * Add `encrypted` option to MessageParser.encode() * Fix find() for new MessageParser class * Fix find() for new MessageParser class * Write sequence number in inital call to encode() * Update dependency nyc to v14 (#190) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | nyc | devDependencies | major | [`13.3.0` -> `14.0.0`](https://diff.intrinsic.com/nyc/13.3.0/14.0.0) | [source](https://togithub.com/istanbuljs/nyc) | --- ### Release Notes <details> <summary>istanbuljs/nyc</summary> ### [`v14.0.0`](https://togithub.com/istanbuljs/nyc/blob/master/CHANGELOG.md#​1400httpsgithubcomistanbuljsnyccomparev1330v1400-2019-04-15) [Compare Source](https://togithub.com/istanbuljs/nyc/compare/v13.3.0...v14.0.0) ##### Bug Fixes - Add `cwd` option to instrument command ([#​1024](https://togithub.com/istanbuljs/nyc/issues/1024)) ([051d95a](https://togithub.com/istanbuljs/nyc/commit/051d95a)) - Add config values to hash salt ([#​988](https://togithub.com/istanbuljs/nyc/issues/988)) ([7ac325d](https://togithub.com/istanbuljs/nyc/commit/7ac325d)), closes [#​522](https://togithub.com/istanbuljs/nyc/issues/522) - Exclude negated not working with '--all' switch ([#​977](https://togithub.com/istanbuljs/nyc/issues/977)) ([91de23c](https://togithub.com/istanbuljs/nyc/commit/91de23c)) - Make --all work for transpiled code ([#​1047](https://togithub.com/istanbuljs/nyc/issues/1047)) ([18e04ba](https://togithub.com/istanbuljs/nyc/commit/18e04ba)) - Resolve absolute paths in nyc instrument ([#​1012](https://togithub.com/istanbuljs/nyc/issues/1012)) ([3cb1861](https://togithub.com/istanbuljs/nyc/commit/3cb1861)), closes [#​1014](https://togithub.com/istanbuljs/nyc/issues/1014) - Set processinfo pid/ppid to actual numbers ([#​1057](https://togithub.com/istanbuljs/nyc/issues/1057)) ([32f75b0](https://togithub.com/istanbuljs/nyc/commit/32f75b0)) - Use a single instance of nyc for all actions of main command. ([#​1059](https://togithub.com/istanbuljs/nyc/issues/1059)) ([b909575](https://togithub.com/istanbuljs/nyc/commit/b909575)) ##### Features - Add `delete` option to instrument command ([#​1005](https://togithub.com/istanbuljs/nyc/issues/1005)) ([d6db551](https://togithub.com/istanbuljs/nyc/commit/d6db551)) - Add `include` and `exclude` options to instrument command ([#​1007](https://togithub.com/istanbuljs/nyc/issues/1007)) ([8da097e](https://togithub.com/istanbuljs/nyc/commit/8da097e)) - Add processinfo index, add externalId ([#​1055](https://togithub.com/istanbuljs/nyc/issues/1055)) ([8dcf180](https://togithub.com/istanbuljs/nyc/commit/8dcf180)) - Add support for nyc.config.js ([#​1019](https://togithub.com/istanbuljs/nyc/issues/1019)) ([3b203c7](https://togithub.com/istanbuljs/nyc/commit/3b203c7)) - Add support to exclude files on coverage report generation ([#​982](https://togithub.com/istanbuljs/nyc/issues/982)) ([509c6aa](https://togithub.com/istanbuljs/nyc/commit/509c6aa)) - Add test-exclude args to check-coverage and report subcommands. ([0fc217e](https://togithub.com/istanbuljs/nyc/commit/0fc217e)) - Always build the processinfo temp dir ([#​1061](https://togithub.com/istanbuljs/nyc/issues/1061)) ([c213469](https://togithub.com/istanbuljs/nyc/commit/c213469)) - Enable `es-modules` option for nyc instrument command ([#​1006](https://togithub.com/istanbuljs/nyc/issues/1006)) ([596b120](https://togithub.com/istanbuljs/nyc/commit/596b120)) - Fix excludeAfterRemap functionality. ([36bcc0b](https://togithub.com/istanbuljs/nyc/commit/36bcc0b)) - Implement `nyc instrument --complete-copy` ([#​1056](https://togithub.com/istanbuljs/nyc/issues/1056)) ([2eb13c6](https://togithub.com/istanbuljs/nyc/commit/2eb13c6)) - Remove bundling ([#​1017](https://togithub.com/istanbuljs/nyc/issues/1017)) ([b25492a](https://togithub.com/istanbuljs/nyc/commit/b25492a)) - Support turning off node_modules default exclude via `exclude-node-modules` option ([#​912](https://togithub.com/istanbuljs/nyc/issues/912)) ([b7e16cd](https://togithub.com/istanbuljs/nyc/commit/b7e16cd)) - Add support for `--exclude-node-modules` to subcommands. ([#​1053](https://togithub.com/istanbuljs/nyc/issues/1053)) ([e597c46](https://togithub.com/istanbuljs/nyc/commit/e597c46)) ##### BREAKING CHANGES - The `--exclude-after-remap` option is now functional and enabled by default. This causes the `include` and `exclude` lists to be processed after using source maps to determine the original filename of sources. - Add a file named 'index.json' to the .nyc_output/processinfo directory, which has a different format from the other files in this dir. - Change the data type of the pid/ppid fields in processinfo files - `nyc instrument` now honors `include` and `exclude` settings, potentially resulting in some files that were previously instrumented being ignored. - The `plugins` option has been renamed to `parser-plugins`. - The logic involving include/exclude processing has changed. Results should be verified to ensure all desired sources have coverage data. - `nyc instrument` now enables the `--es-module` option by default. This can cause failures to instrument scripts which violate `'use strict'` rules. </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency documentation to v10 (#191) This PR contains the following updates: | Package | Type | Update | Change | References | |---|---|---|---|---| | documentation | devDependencies | major | [`9.3.1` -> `10.0.0`](https://diff.intrinsic.com/documentation/9.3.1/10.0.0) | [source](https://togithub.com/documentationjs/documentation) | --- ### Release Notes <details> <summary>documentationjs/documentation</summary> ### [`v10.0.0`](https://togithub.com/documentationjs/documentation/blob/master/CHANGELOG.md#​1000httpsgithubcomdocumentationjsdocumentationcomparev1000-alpha0v1000-2019-04-18) [Compare Source](https://togithub.com/documentationjs/documentation/compare/v9.3.1...v10.0.0) ##### Features - Add flow inference for generators ([7947e97](https://togithub.com/documentationjs/documentation/commit/7947e97)) - Support async functions ([d31c3b7](https://togithub.com/documentationjs/documentation/commit/d31c3b7)) - Support classPrivateProperties in parser ([64ef671](https://togithub.com/documentationjs/documentation/commit/64ef671)), closes [#​1216](https://togithub.com/documentationjs/documentation/issues/1216) - Support generator functions ([8e3cd47](https://togithub.com/documentationjs/documentation/commit/8e3cd47)) </details> --- ### Renovate configuration :date: **Schedule**: At any time (no schedule defined). :vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied. :recycle: **Rebasing**: Whenever PR becomes conflicted, or if you modify the PR title to begin with "`rebase!`". :no_bell: **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- renovate-rebase -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://togithub.com/marketplace/renovate). View repository job log [here](https://renovatebot.com/dashboard#codetheweb/tuyapi). * Update dependency documentation to v10.1.0 (#192) * Remove Cipher instance * Add seperate utils file * Clean up Cipher and MessageParser * Make behavior when receiving a sequence number of 0 more clear * Check for version number at beginning of payload * Add CommandType enum * Update dependency nyc to v14.1.0 (#194) * Update dependency documentation to v11 (#195) * Update dependency nyc to v14.1.1 (#196) * Add sequence number to heartbeat packets Allow heartbeat packets to use revolver logic * Fix heartbeat resolver logic * Add sequence number to heartbeat packet * Fix set() resolver
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I give up 😝
Please forgive me
Didn't catch this when testing with real devices because as you already know they don't enforce CRC
Tests now pass