Skip to content

Commit 4d23447

Browse files
author
Nicolas Nunge
committed
Initial Commit
0 parents  commit 4d23447

15 files changed

+1413
-0
lines changed

.gitignore

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
2+
# Created by https://www.gitignore.io/api/git,osx,node,linux,windows
3+
example/
4+
### Git ###
5+
*.orig
6+
7+
### Linux ###
8+
*~
9+
10+
# temporary files which can be created if a process still has a handle open of a deleted file
11+
.fuse_hidden*
12+
13+
# KDE directory preferences
14+
.directory
15+
16+
# Linux trash folder which might appear on any partition or disk
17+
.Trash-*
18+
19+
# .nfs files are created when an open file is removed but is still being accessed
20+
.nfs*
21+
22+
### Node ###
23+
# Logs
24+
logs
25+
*.log
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# Runtime data
31+
pids
32+
*.pid
33+
*.seed
34+
*.pid.lock
35+
36+
# Directory for instrumented libs generated by jscoverage/JSCover
37+
lib-cov
38+
39+
# Coverage directory used by tools like istanbul
40+
coverage
41+
42+
# nyc test coverage
43+
.nyc_output
44+
45+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
46+
.grunt
47+
48+
# Bower dependency directory (https://bower.io/)
49+
bower_components
50+
51+
# node-waf configuration
52+
.lock-wscript
53+
54+
# Compiled binary addons (https://nodejs.org/api/addons.html)
55+
build/Release
56+
dist
57+
58+
# Dependency directories
59+
node_modules/
60+
jspm_packages/
61+
62+
# TypeScript v1 declaration files
63+
typings/
64+
65+
# Optional npm cache directory
66+
.npm
67+
68+
# Optional eslint cache
69+
.eslintcache
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variables file
81+
.env
82+
83+
# parcel-bundler cache (https://parceljs.org/)
84+
.cache
85+
86+
# next.js build output
87+
.next
88+
89+
# nuxt.js build output
90+
.nuxt
91+
92+
# vuepress build output
93+
.vuepress/dist
94+
95+
# Serverless directories
96+
.serverless
97+
98+
### OSX ###
99+
# General
100+
.DS_Store
101+
.AppleDouble
102+
.LSOverride
103+
104+
# Icon must end with two \r
105+
Icon
106+
107+
# Thumbnails
108+
._*
109+
110+
# Files that might appear in the root of a volume
111+
.DocumentRevisions-V100
112+
.fseventsd
113+
.Spotlight-V100
114+
.TemporaryItems
115+
.Trashes
116+
.VolumeIcon.icns
117+
.com.apple.timemachine.donotpresent
118+
119+
# Directories potentially created on remote AFP share
120+
.AppleDB
121+
.AppleDesktop
122+
Network Trash Folder
123+
Temporary Items
124+
.apdisk
125+
126+
### Windows ###
127+
# Windows thumbnail cache files
128+
Thumbs.db
129+
ehthumbs.db
130+
ehthumbs_vista.db
131+
132+
# Dump file
133+
*.stackdump
134+
135+
# Folder config file
136+
[Dd]esktop.ini
137+
138+
# Recycle Bin used on file shares
139+
$RECYCLE.BIN/
140+
141+
# Windows Installer files
142+
*.cab
143+
*.msi
144+
*.msix
145+
*.msm
146+
*.msp
147+
148+
# Windows shortcuts
149+
*.lnk
150+
151+
152+
# End of https://www.gitignore.io/api/git,osx,node,linux,windows

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Node Flipr
2+
3+
![https://img.shields.io/npm/l/node-flipr.svg](https://img.shields.io/npm/l/node-flipr.svg) ![https://www.buymeacoffee.com/nikkow](https://img.shields.io/badge/Support-Buy%20me%20a%20coffee!-yellow.svg)
4+
5+
## Intro
6+
7+
...
8+
9+
## Usage
10+
11+
### Setup
12+
13+
### Basic usage
14+
15+
### API Reference

lib/classes/measure.ts

Lines changed: 218 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/**
2+
* Measure specific module.
3+
* @module Flipr
4+
* @author Nicolas Nunge <[email protected]>
5+
* @version 1.0.0
6+
*/
7+
8+
import { TemperatureUnit } from '../enums/temperature-unit.enum';
9+
import { DisinfectantType } from '../enums/disinfectanttype.enum';
10+
import { Deviation } from '../enums/deviation.enum';
11+
12+
/** FliprMeasure is used to handle metrics returned by Flipr */
13+
export class FliprMeasure {
14+
15+
private measureDate: Date | null = null;
16+
17+
private batteryLevel: number | null = null;
18+
19+
private uvIndex: number | null = null;
20+
21+
private cloudCoverage: number | null = null;
22+
23+
private temperature: number | null = null;
24+
25+
private disinfectantType: DisinfectantType | null = null;
26+
27+
private disinfectantDeviation: number | null = null;
28+
29+
private disinfectantDeviationSector: Deviation = Deviation.UNKNOWN;
30+
31+
private phValue: number | null = null;
32+
33+
private phDeviation: number | null = null;
34+
35+
private phDeviationSector: Deviation = Deviation.UNKNOWN;
36+
37+
// TODO: Replace with proper interface
38+
/**
39+
* Creates a new instance of FliprMeasure
40+
*/
41+
constructor(rawMeasureObject: any) {
42+
if(rawMeasureObject.hasOwnProperty('DateTime')) {
43+
this.measureDate = new Date(rawMeasureObject.DateTime);
44+
}
45+
46+
if(rawMeasureObject.hasOwnProperty('Battery') && rawMeasureObject.Battery.hasOwnProperty('Deviation')) {
47+
this.batteryLevel = rawMeasureObject.Battery.Deviation;
48+
}
49+
50+
if(rawMeasureObject.hasOwnProperty('CloudCoverage')) {
51+
this.cloudCoverage = rawMeasureObject.CloudCoverage;
52+
}
53+
54+
if(rawMeasureObject.hasOwnProperty('UvIndex')) {
55+
this.uvIndex = rawMeasureObject.UvIndex;
56+
}
57+
58+
if(rawMeasureObject.hasOwnProperty('Temperature')) {
59+
this.temperature = rawMeasureObject.Temperature;
60+
}
61+
62+
if(rawMeasureObject.hasOwnProperty('Desinfectant')) {
63+
if(rawMeasureObject.Desinfectant.hasOwnProperty('Label')) {
64+
switch(rawMeasureObject.Desinfectant.Label) {
65+
case "Chlore":
66+
this.disinfectantType = DisinfectantType.CHLORINE;
67+
break;
68+
69+
case "Brome":
70+
this.disinfectantType = DisinfectantType.BROMINE;
71+
break;
72+
73+
case "Sel":
74+
this.disinfectantType = DisinfectantType.SALT;
75+
break;
76+
}
77+
}
78+
79+
if(rawMeasureObject.Desinfectant.hasOwnProperty('Deviation')) {
80+
this.disinfectantDeviation = rawMeasureObject.Desinfectant.Deviation;
81+
}
82+
83+
if(rawMeasureObject.Desinfectant.hasOwnProperty('DeviationSector')) {
84+
this.disinfectantDeviationSector = this.stringToDeviation(rawMeasureObject.Desinfectant.DeviationSector);
85+
}
86+
}
87+
88+
if(rawMeasureObject.hasOwnProperty('PH')) {
89+
if(rawMeasureObject.PH.hasOwnProperty('Value')) {
90+
this.phValue = rawMeasureObject.PH.Value;
91+
}
92+
93+
if(rawMeasureObject.PH.hasOwnProperty('Deviation')) {
94+
this.phDeviation = rawMeasureObject.PH.Deviation;
95+
}
96+
97+
if(rawMeasureObject.PH.hasOwnProperty('DeviationSector')) {
98+
this.phDeviationSector = this.stringToDeviation(rawMeasureObject.PH.DeviationSector);
99+
}
100+
}
101+
}
102+
103+
/**
104+
* Returns the date when these metrics were captured by Flipr.
105+
* @return {Date|null} a native Date object of the metric capture date.
106+
*/
107+
public getDate(): Date | null {
108+
return this.measureDate;
109+
}
110+
111+
/**
112+
* Returns the UV index at the moment the metrics were captured.
113+
* @return {number|null}
114+
*/
115+
public getUVIndex(): number | null {
116+
return this.uvIndex;
117+
}
118+
119+
/**
120+
* Returns the cloud coverage at the moment the metrics were captured.
121+
* @param {boolean} expectRawValue
122+
* @return {number|null} When the "expectRawValue" parameter is set to true, the method will return the cloud coverage as returned by Flipr: a float 0 <= x <= 1. Otherwhise, the result will be returned as a percentage 0 <= x <= 100.
123+
*/
124+
public getCloudCoverage(expectRawValue: boolean): number | null {
125+
if(expectRawValue) {
126+
return this.cloudCoverage;
127+
}
128+
129+
return this.cloudCoverage !== null ? (this.cloudCoverage * 100) : null;
130+
}
131+
132+
/**
133+
* Returns the device's battery level at the moment the metrics were captured.
134+
* @param {boolean} expectRawValue
135+
* @return {number|null} When the "expectRawValue" parameter is set to true, the method will return the battery level as returned by Flipr: a float 0 <= x <= 1. Otherwise, the result will be returned as a percentage 0 <= x <= 100.
136+
*/
137+
public getBatteryLevel(expectRawValue: boolean): number | null {
138+
if(expectRawValue) {
139+
return this.batteryLevel;
140+
}
141+
142+
return this.batteryLevel !== null ? (this.batteryLevel * 100) : null;
143+
}
144+
145+
/**
146+
* Returns the water's temperature in various units.
147+
* @param {TemperatureUnit} unit Specifies the unit the result should be returned. See TemperatureUnit enum for possible values.
148+
* @return {number|null}
149+
*/
150+
public getTemperature(unit: TemperatureUnit = TemperatureUnit.CELCIUS): number | null {
151+
if(this.temperature === null) {
152+
return null;
153+
}
154+
155+
switch(unit) {
156+
case TemperatureUnit.FAHRENHEIT:
157+
return this.temperature * (9/5) + 32;
158+
159+
case TemperatureUnit.KELVIN:
160+
return this.temperature + 273.15;
161+
162+
case TemperatureUnit.CELCIUS:
163+
default:
164+
return this.temperature
165+
}
166+
}
167+
168+
/**
169+
* Returns the type of disinfectant currently in use.
170+
* @return {DisinfectantType|null}
171+
*/
172+
public getDisinfectantType(): DisinfectantType | null {
173+
return this.disinfectantType;
174+
}
175+
176+
/**
177+
* Returns the current disinfectant deviation/variation.
178+
* @param {boolean} expectRawValue When true, the result will be the raw deviation (as a number, -1 <= x <= 1). Otherwise, the deviation sector (see Deviation enum)
179+
* @return {number|null}
180+
*/
181+
public getDisinfectantDeviation(expectRawValue: boolean): Deviation | number | null {
182+
return expectRawValue ? this.disinfectantDeviation : this.disinfectantDeviationSector;
183+
}
184+
185+
/**
186+
* Returns the raw PH value.
187+
* @return {number|null}
188+
*/
189+
public getPHValue(): number | null {
190+
return this.phValue;
191+
}
192+
193+
/**
194+
* Returns the current PH deviation/variation.
195+
* @param {boolean} expectRawValue When true, the result will be the raw deviation (as a number, -1 <= x <= 1). Otherwise, the deviation sector (see Deviation enum)
196+
* @return {number|null}
197+
*/
198+
public getPHDeviation(expectRawValue: boolean): Deviation | number | null {
199+
return expectRawValue ? this.phDeviation : this.phDeviationSector;
200+
}
201+
202+
/**
203+
* Converts API values to Deviation
204+
* @private
205+
* @param {string} input
206+
* @return {Deviation}
207+
*/
208+
private stringToDeviation(input: string): Deviation {
209+
switch(input.toUpperCase()) {
210+
case "TOOHIGH": return Deviation.TOO_HIGH;
211+
case "MEDIUMHIGH": return Deviation.MEDIUM_HIGH;
212+
case "MEDIUM": return Deviation.MEDIUM;
213+
case "MEDIUMLOW": return Deviation.MEDIUM_LOW;
214+
case "TOOLOW": return Deviation.TOO_LOW;
215+
default: return Deviation.UNKNOWN;
216+
}
217+
}
218+
}

0 commit comments

Comments
 (0)