Coding the C by GE Factory Reset Process

This code is for firmware 2.8 or later only
/*
** This code works for firmware 2.8 or later only
** Takes in a new switch and the most recent switches on a bulb
** Returns an updated array of recent switches
*/
import { flashOnAndOffTimes } from "../services/hardware";/*
** fullPattern(switch[]) checks that an array of switches matches
** the full factory reset process. patternMatch(switch, stepNumber)
** checks whether a switch matches a certain step of the factory
** reset process
*/
import { fullPattern, patternMatch } from "./helpers";
type Switch = {
on: Boolean;
seconds: number;
};
const OFF_VALUE = 2;
const ON_VALUE = 8;
const lowerTolerance = (seconds: number) => seconds * 0.5;const upperTolerance = (seconds: number) => seconds * 1.5;function firmwareTwoPointEightOrLater(newSwitch: Switch,
recentSwitches: Switch[]) {
if (fullPattern(recentSwitches) && newSwitch.on) { flashOnAndOffTimes(3);
return [];
}
if (
newSwitch.seconds > upperTolerance(OFF_VALUE) ||
newSwitch.seconds < lowerTolerance(ON_VALUE)
) {
// not the factory reset process - return
return [];
}
switch (newSwitch.seconds) {
case ON_VALUE:
if (newSwitch.on && patternMatch(newSwitch,
recentSwitches.length) {
return recentSwitches.push(newSwitch);
}
return [];
case OFF_VALUE: if (!newSwitch.on && patternMatch(newSwitch,
recentSwitches.length) {
return recentSwitches.push(newSwitch);
}
return [];
default:
return [];
}
}

Writer, t-shirt designer, software engineer. Child. Canoe. https://www.somewhimsy.co.uk

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store