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 ActionSet = {minionId: string, setStatus: MinionStatus}; export type ActionApply = 'statusChange' | 'permanent'; export type Action = {actionId: string, minionId: string, active: boolean, name?: string | undefined, ifStatus: MinionStatus, thenSet: Array, apply: ActionApply}; export type UpdateApiActionsActionIdArgs = {actionId: string, body: Action}; export type UpdateApiActionsActionIdOptions = {baseUrl: string, userAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Update action properties. * * PUT /actions/{actionId} * * Also accepts auth: adminAuth */ export const updateApiActionsActionId = async (args: UpdateApiActionsActionIdArgs, options: UpdateApiActionsActionIdOptions) => { 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(/\/+$/, '')}/actions/${encodeURIComponent(String(args.actionId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 };