-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.mts
172 lines (146 loc) · 4.56 KB
/
types.mts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import type { DerogMode, LoginPostData, Mode } from '@olivierzal/heatzy-api'
import type HeatzyDevice from './drivers/heatzy/device.mjs'
export type PreviousMode = Exclude<keyof typeof Mode, 'stop'>
export type OnMode = 'previous' | PreviousMode
export interface SetCapabilities {
readonly derog_time_boost: string
readonly derog_time_vacation: string
readonly locked: boolean
readonly onoff: boolean
readonly 'onoff.timer': boolean
readonly target_temperature: number
readonly 'target_temperature.complement': number
readonly thermostat_mode: keyof typeof Mode
}
export interface Capabilities extends SetCapabilities {
readonly derog_end: string | null
readonly derog_mode: keyof typeof DerogMode
}
export type ValueOf<T> = T[keyof T]
export interface Settings
extends Record<string, boolean | number | string | null | undefined> {
readonly always_on?: boolean
readonly on_mode?: OnMode
}
export interface Store {
readonly previousMode?: PreviousMode
}
export interface HomeySettingsUI {
readonly expireAt?: string
readonly password?: string
readonly token?: string
readonly username?: string
}
interface LocalizedStrings extends Partial<Record<string, string>> {
readonly en: string
}
interface CapabilitiesOptionsValues<T extends string> {
readonly id: T
readonly title: LocalizedStrings
}
export interface ManifestDriverSettingData {
readonly id: string
readonly label: LocalizedStrings
readonly type: string
readonly max?: number
readonly min?: number
readonly units?: string
readonly values?: readonly {
readonly id: string
readonly label: LocalizedStrings
}[]
}
export interface ManifestDriverSetting {
readonly label: LocalizedStrings
readonly children?: readonly ManifestDriverSettingData[]
readonly id?: string
}
export interface PairSetting {
readonly id: string
}
export interface LoginSetting extends PairSetting {
readonly id: 'login'
readonly options: {
readonly passwordLabel: LocalizedStrings
readonly passwordPlaceholder: LocalizedStrings
readonly usernameLabel: LocalizedStrings
readonly usernamePlaceholder: LocalizedStrings
}
}
export interface ManifestDriverCapabilitiesOptions {
readonly title: LocalizedStrings
readonly type: string
readonly values?: readonly CapabilitiesOptionsValues<string>[]
}
export interface ManifestDriver {
readonly id: string
readonly capabilities?: readonly string[]
readonly capabilitiesOptions?: Record<
string,
ManifestDriverCapabilitiesOptions
>
readonly pair?: LoginSetting & readonly PairSetting[]
readonly settings?: readonly ManifestDriverSetting[]
}
export interface Manifest {
readonly drivers: readonly ManifestDriver[]
readonly version: string
}
export interface DriverSetting {
readonly driverId: string
readonly id: string
title: string
readonly type: string
readonly groupId?: string
readonly groupLabel?: string
readonly max?: number
readonly min?: number
placeholder?: string
readonly units?: string
readonly values?: readonly { readonly id: string; readonly label: string }[]
}
export interface DriverCapabilitiesOptions {
readonly title: string
readonly type: string
readonly values?: readonly { readonly id: string; readonly label: string }[]
}
export interface LoginDriverSetting extends DriverSetting {
readonly id: keyof LoginPostData
}
export type DeviceSetting = Record<string, ValueOf<Settings>>
export type DeviceSettings = Record<string, DeviceSetting>
export interface CapabilitiesOptions {
readonly thermostat_mode: {
readonly values: readonly CapabilitiesOptionsValues<keyof typeof Mode>[]
}
}
export interface DeviceDetails {
readonly capabilities: readonly string[]
readonly capabilitiesOptions: CapabilitiesOptions
readonly data: { readonly id: string }
readonly name: string
}
export interface FlowArgs {
readonly derog_time: string
readonly device: HeatzyDevice
readonly mode: keyof typeof Mode
readonly onoff: boolean
readonly target_temperature: number
}
const baseValues = [
{ id: 'cft', title: { en: 'Comfort', fr: 'Confort' } },
{ id: 'eco', title: { en: 'Eco', fr: 'Éco' } },
{ id: 'fro', title: { en: 'Anti-frost', fr: 'Anti-gel' } },
{ id: 'stop', title: { en: 'Off', fr: 'Désactivé' } },
] as const
const newPilotValues = [
{ id: 'cft2', title: { en: 'Comfort 2', fr: 'Confort 2' } },
{ id: 'cft1', title: { en: 'Comfort 1', fr: 'Confort 1' } },
] as const
export const getCapabilitiesOptions = (
isFirstPilot: boolean,
): CapabilitiesOptions => ({
thermostat_mode: {
values: [...(isFirstPilot ? [] : newPilotValues), ...baseValues],
},
})