Skip to content

Commit

Permalink
Build brightness threshold for lighting device
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre ROTH committed Feb 16, 2016
1 parent c86bcec commit 99d5d91
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions app/js/views/widgets/legrand/lighting_brightness_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@ import {BrightnessGraphView} from '../brightness_view';

const BRIGTHNESS_DARK_COLOR = '#000000';
const BRIGTHNESS_BRIGHT_COLOR = '#d67b19';
const BRIGTHNESS_LIMIT = 210;
const DEFAULT_BRIGTHNESS_LIMIT = 210;

export class LightingBrightnessGraphView extends BrightnessGraphView {

constructor(options) {
super(options);
this.brightnessThreshold = this.buildBrightnessThreshold();
}

buildBrightnessThreshold() {
var threshold = localStorage.getItem('brightnessThreshold');
try {
threshold = parseInt(threshold, 10);
if (isNaN(threshold)) {
throw new Error('threshold is not a number');
}
return threshold;
} catch (e) {
return DEFAULT_BRIGTHNESS_LIMIT;
}
}

buildColorFromBrightness(brightness) {
return (brightness < BRIGTHNESS_LIMIT) ? BRIGTHNESS_DARK_COLOR: BRIGTHNESS_BRIGHT_COLOR;
return (brightness < this.brightnessThreshold) ? BRIGTHNESS_DARK_COLOR: BRIGTHNESS_BRIGHT_COLOR;
}

initChart() {
Expand Down

0 comments on commit 99d5d91

Please sign in to comment.