export type DeviceStatus = {battery?: number | undefined, charging?: boolean | undefined}; export type LocalNetworkDevice = {name?: string | undefined, mac: string, vendor?: string | undefined, ip?: string | undefined, deviceStatus?: DeviceStatus | undefined}; export type MinionDevice = {pysicalDevice: LocalNetworkDevice, brand: string, model: string, token?: string | undefined, deviceId?: string | undefined}; 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 MinionTypes = 'toggle' | 'switch' | 'temperatureSensor' | 'roller' | 'cleaner' | 'airConditioning' | 'light' | 'temperatureLight' | 'colorLight'; export type CalibrationMode = 'LOCK_ON' | 'LOCK_OFF' | 'SHABBAT' | 'AUTO' | 'LOCK_DASHBOARD'; export type MinionCalibrate = {calibrationCycleMinutes: number, calibrationMode: CalibrationMode}; export type RestrictionType = 'BLOCK' | 'READ' | 'WRITE'; export type RestrictionItem = {userEmail: string, restrictionType: RestrictionType}; export type Minion = {minionId?: string | undefined, name: string, device: MinionDevice, isProperlyCommunicated?: boolean | undefined, minionStatus: MinionStatus, minionType: MinionTypes, minionAutoTurnOffMS?: number | undefined, calibration?: MinionCalibrate | undefined, room?: string | undefined, statusChangedTime?: number | undefined, restrictions?: Array | undefined}; export type CreateApiMinionsArgs = {body: Minion}; export type CreateApiMinionsOptions = {baseUrl: string, userAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Creates a new minion. * * POST /minions * * Also accepts auth: adminAuth */ export const createApiMinions = async (args: CreateApiMinionsArgs, options: CreateApiMinionsOptions) => { 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(/\/+$/, '')}/minions${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 };