export type UpdateApiItemsItemnameStateArgs = {'Accept-Language'?: string | undefined, 'X-OpenHAB-Source'?: string | undefined, itemname: string, source?: string | undefined, body: BodyInit}; export type UpdateApiItemsItemnameStateOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Updates the state of an item. * * PUT /items/{itemname}/state */ export const updateApiItemsItemnameState = async (args: UpdateApiItemsItemnameStateArgs, options: UpdateApiItemsItemnameStateOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "text/plain") if (args['Accept-Language'] != null) headers.set("Accept-Language", String(args['Accept-Language'])) if (args['X-OpenHAB-Source'] != null) headers.set("X-OpenHAB-Source", String(args['X-OpenHAB-Source'])) if (args.source != null) query.append("source", String(args.source)) const url = `${baseUrl.replace(/\/+$/, '')}/items/${encodeURIComponent(String(args.itemname))}/state${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };