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 UpdateApiDevicesDeviceMacArgs = {deviceMac: string, body: LocalNetworkDevice}; export type UpdateApiDevicesDeviceMacOptions = {baseUrl: string, userAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set name to a device. * * PUT /devices/{deviceMac} * * Also accepts auth: adminAuth */ export const updateApiDevicesDeviceMac = async (args: UpdateApiDevicesDeviceMacArgs, options: UpdateApiDevicesDeviceMacOptions) => { 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(/\/+$/, '')}/devices/${encodeURIComponent(String(args.deviceMac))}${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 };