-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
28 lines (24 loc) · 689 Bytes
/
Copy pathutils.ts
File metadata and controls
28 lines (24 loc) · 689 Bytes
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
import type { PostAttributes } from './types.ts'
import { TEMPERATURE_SCALE } from './constants.ts'
import { type Mode, Product } from './enums.ts'
enum BitHigh {
off = 0,
on = 1,
}
const BYTE_MAX = 255
export const getTargetTemperature = (
product: Product,
mode: Mode.comfort | Mode.eco,
value: number,
): PostAttributes => {
const valueNew = value * TEMPERATURE_SCALE
if (product === Product.glow) {
const temporaryH = valueNew > BYTE_MAX ? BitHigh.on : BitHigh.off
return {
[`${mode}_tempH`]: temporaryH,
[`${mode}_tempL`]:
valueNew - temporaryH * TEMPERATURE_SCALE * TEMPERATURE_SCALE,
}
}
return { [`${mode}_temp`]: valueNew }
}