This repository was archived by the owner on Nov 15, 2024. It is now read-only.
feat minut noise thresholds list#181
Merged
Merged
Conversation
itelo
commented
Apr 18, 2023
Contributor
- feat: add new method to list noise thresholds
- add noise thresholds list
- fix variable NOISE_DETECTION_DEVICE_TYPES
- debug ci
- maybe the error is in minut scenario
- more debug
- even more debug
- retry
- missing await
- final try
- remove logs
- another try
- add serial to test
- add serial
- remove serial add modifiesState
- remove ts-ignore from startandseedserver
fac2be2 to
af387a0
Compare
seveibar
reviewed
Apr 18, 2023
Comment on lines
+98
to
+113
| const devices = { | ||
| ...load_devices_from.reduce((acc, provider, index) => { | ||
| if (provider === "schlage") { | ||
| acc["schlageLock"] = devicesByProvider[index] | ||
| return acc | ||
| } | ||
|
|
||
| if (provider === "august") { | ||
| acc["augustLock"] = devicesByProvider[index] | ||
| return acc | ||
| } | ||
|
|
||
| acc[provider] = devicesByProvider[index] | ||
| return acc | ||
| }, {} as Record<"augustLock" | "minut" | "schlageLock", any>), | ||
| } |
Contributor
There was a problem hiding this comment.
The readability here is hard, here's why:
- There's an indexing scheme that's not clear, particularly because some of the variable names are unclear. I would consider renaming
devicesByProviderandload_devices_from(poor name more generally, it is a verb which implies it's a function) - The type is buried in the implementation, if something starts getting complicated, better to lift the type up to the top
.reduceisn't a great function because it moves the type definition towards the bottom, in practice loops tend to be preferable- Mark deprecated or legacy behavior explicitly
- I THINK there's a spread here for no reason? Why spread the reduce
Principally, we should try to avoid letting optimizations like Promise.all impact readability.
Suggested change
| const devices = { | |
| ...load_devices_from.reduce((acc, provider, index) => { | |
| if (provider === "schlage") { | |
| acc["schlageLock"] = devicesByProvider[index] | |
| return acc | |
| } | |
| if (provider === "august") { | |
| acc["augustLock"] = devicesByProvider[index] | |
| return acc | |
| } | |
| acc[provider] = devicesByProvider[index] | |
| return acc | |
| }, {} as Record<"augustLock" | "minut" | "schlageLock", any>), | |
| } | |
| const devices: Record<keyof providersMap & 'schlageLock' | 'augustLock', any> = {} | |
| for (let i = 0; i < load_devices_from.length; i++) { | |
| const provider = load_devices_from[i] | |
| devices[provider] = devicesByProvider[i] | |
| } | |
| // TODO: remove when we deprecate schlageLock and augustLock | |
| if (devices.august) { | |
| devices.augustLock = devices.august | |
| } | |
| if (devices.schlage) { | |
| devices.schlageLock = devices.schlage | |
| } |
seveibar
approved these changes
Apr 18, 2023
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.