export type SwitchOptions = 'on' | 'off'; export type Toggle = {status: SwitchOptions}; export type Switch = {status: SwitchOptions}; export type RollerDirection = 'up' | 'down'; export type Roller = {status: SwitchOptions, direction: RollerDirection}; export type CleanerMode = 'dock' | 'clean'; export type FanStrengthOptions = 'low' | 'med' | 'high' | 'auto'; export type Cleaner = {status: SwitchOptions, mode: CleanerMode, fanSpeed: FanStrengthOptions}; export type ACModeOptions = 'hot' | 'cold' | 'dry' | 'auto'; export type AirConditioning = {status: SwitchOptions, temperature: number, mode: ACModeOptions, fanStrength: FanStrengthOptions}; export type Light = {status: SwitchOptions, brightness: number}; export type TemperatureLight = {status: SwitchOptions, brightness: number, temperature: number}; export type ColorLight = {status: SwitchOptions, brightness: number, temperature: number, red: number, green: number, blue: number}; export type TemperatureSensor = {status: SwitchOptions, temperature: number}; export type MinionStatus = {toggle?: Toggle | undefined, switch?: Switch | undefined, roller?: Roller | undefined, cleaner?: Cleaner | undefined, airConditioning?: AirConditioning | undefined, light?: Light | undefined, temperatureLight?: TemperatureLight | undefined, colorLight?: ColorLight | undefined, temperatureSensor?: TemperatureSensor | undefined}; export type OperationActivity = {minionId: string, minionStatus: MinionStatus}; export type TimingTypes = 'dailySunTrigger' | 'dailyTimeTrigger' | 'once' | 'timeout'; export type DaysOptions = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday'; export type SunTriggerOptions = 'sunrise' | 'sunset'; export type DailySunTrigger = {days: Array, durationMinutes: number, sunTrigger: SunTriggerOptions}; export type DailyTimeTrigger = {days: Array, hour: number, minutes: number}; export type OnceTiming = {date: number}; export type TimeoutTiming = {startDate: number, durationInMinutes: number}; export type TimingProperties = {dailySunTrigger?: DailySunTrigger | undefined, dailyTimeTrigger?: DailyTimeTrigger | undefined, once?: OnceTiming | undefined, timeout?: TimeoutTiming | undefined}; export type CalibrationMode = 'LOCK_ON' | 'LOCK_OFF' | 'SHABBAT' | 'AUTO' | 'LOCK_DASHBOARD'; export type Timing = {timingId: string, timingName?: string | undefined, triggerOperationId?: string | undefined, triggerDirectAction?: OperationActivity | undefined, isActive: boolean, timingType: TimingTypes, timingProperties: TimingProperties, setLock?: CalibrationMode | undefined, overrideLock?: boolean | undefined}; export type CreateApiTimingsArgs = {body: Timing}; export type CreateApiTimingsOptions = {baseUrl: string, userAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new timing. * * POST /timings * * Also accepts auth: adminAuth */ export const createApiTimings = async (args: CreateApiTimingsArgs, options: CreateApiTimingsOptions) => { const {baseUrl, fetch: fetchFn = fetch, userAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (userAuth !== undefined) headers.set("authentication", userAuth) const url = `${baseUrl.replace(/\/+$/, '')}/timings${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };