forked from awesomestvi/navet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-hvac-visual-mode.ts
More file actions
61 lines (49 loc) · 1.15 KB
/
Copy pathuse-hvac-visual-mode.ts
File metadata and controls
61 lines (49 loc) · 1.15 KB
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
import { useMemo } from 'react';
interface UseHvacVisualModeParams {
action?: string;
currentTemp: number;
isOn: boolean;
mode: string;
targetTemp: number;
}
export function useHvacVisualMode({
action,
currentTemp,
isOn,
mode,
targetTemp,
}: UseHvacVisualModeParams) {
return useMemo(() => {
const normalizedAction = action?.toLowerCase() ?? '';
const normalizedMode = mode.toLowerCase();
const temperatureDelta = targetTemp - currentTemp;
if (!isOn) {
return 'off';
}
if (normalizedAction.includes('fan')) {
return 'fan';
}
if (normalizedAction.includes('heat')) {
return 'heat';
}
if (normalizedAction.includes('cool')) {
return 'cool';
}
if (normalizedMode === 'fan' || normalizedMode === 'fan_only') {
return 'fan';
}
if (temperatureDelta > 0.05) {
return 'heat';
}
if (temperatureDelta < -0.05) {
return 'cool';
}
if (normalizedMode === 'heat') {
return 'heat';
}
if (normalizedMode === 'cool') {
return 'cool';
}
return normalizedMode;
}, [action, currentTemp, isOn, mode, targetTemp]);
}