-
Notifications
You must be signed in to change notification settings - Fork 0
/
modes.ts
65 lines (47 loc) · 1.54 KB
/
modes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
Mode,
HouseTemperatureSelection
} from './tempco.d'
const modes = [
'comfort',
'hg',
'off'
]
const celsiusToFahrenheit = (celsius: number) => celsius * 1.8 + 32
export const fahrenheitToCelsius = (fahrenheit: number) => (fahrenheit - 32) / 1.8
const validateMode = (modeName: Mode): boolean => modes.includes(modeName)
export const getModeParams = (modeName: Mode, options: HouseTemperatureSelection) => {
if (options.hasOwnProperty('celsius')) {
options.temperature = Math.floor(celsiusToFahrenheit(options.celsius) * 10)
}
if (options.temperature === undefined)
return false
// Mode does not exist
if (!validateMode(modeName)) {
return false
}
const params = new URLSearchParams()
params.append('token', options.token)
params.append('context', '1')
params.append('smarthome_id', options.smarthome_id)
params.append('query[id_device]', options.id_device)
params.append('query[time_boost]', '0')
params.append('query[gv_mode]', '0')
params.append('query[nv_mode]', '0')
params.append('peremption', '15000')
params.append('lang', 'fi_FI')
switch (modeName) {
// confort
case 'comfort':
params.append('query[consigne_confort]', `${options.temperature}`)
params.append('query[consigne_manuel]', `${options.temperature}`)
break
case modes[0]:
break
case modes[0]:
break
default:
return false
}
return params
}