Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Update decorated sensor state changes to look a little flux-ier #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alenia
Copy link
Owner

@alenia alenia commented Oct 25, 2020

Not sure if I want to do this refactor or not. This makes all the state changes more explicit but also wordier. If it looks like I want to move this direction in the future I can build on it?

const newBracket = this.calculateAQINotifyBracket(data.AQI) || this.currentAQINotifyBracket;
this.calculateAQIThresholds(data.AQI);
if(newBracket && newBracket !== this.currentAQINotifyBracket) {
this.currentAQINotifyBracket = this.calculateAQINotifyBracket(data.AQI);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the "magic" line that becomes way more explicit in the updateAQIMonitoringState method

@alenia
Copy link
Owner Author

alenia commented Oct 25, 2020

Note this does not add any functionality except in more explicit logging, it's a strict refactor that keeps the tests green.

return this.formatReport(data);
}

private updateAQIMonitoringState(AQI: number, forceReset = false) : { old: monitoringState; new: monitoringState, bracketChange: notifyBracket, changed: boolean } {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Old and new states are only used for logging at this point. The bracketChange and changed flags are the relevant ones. Bracket change is whether the AQI is outside of the previous AQI boundaries (and in what direction).

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant