-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: implement back-end for HA switches
- Loading branch information
Showing
8 changed files
with
299 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { emptySplitApi as api } from "../emptyApi"; | ||
export const addTagTypes = [] as const; | ||
const injectedRtkApi = api | ||
.enhanceEndpoints({ | ||
addTagTypes, | ||
}) | ||
.injectEndpoints({ | ||
endpoints: (build) => ({ | ||
updateHaSwitch: build.mutation< | ||
UpdateHaSwitchApiResponse, | ||
UpdateHaSwitchApiArg | ||
>({ | ||
query: (queryArg) => ({ | ||
url: `/api/switches/ha/${queryArg.entityId}`, | ||
method: "POST", | ||
body: queryArg.body, | ||
}), | ||
}), | ||
}), | ||
overrideExisting: false, | ||
}); | ||
export { injectedRtkApi as switchesApi }; | ||
export type UpdateHaSwitchApiResponse = | ||
/** status 200 updateHaSwitch */ UpdateHaSwitchResponse; | ||
export type UpdateHaSwitchApiArg = { | ||
/** Entity ID */ | ||
entityId: string; | ||
body: { | ||
/** Target state, On or Off */ | ||
state?: "On" | "Off"; | ||
}; | ||
}; | ||
export type UpdateHaSwitchResponse = string; | ||
export type ErrorResponse = { | ||
/** Time when error happened */ | ||
timestamp?: string; | ||
/** Code describing the error */ | ||
status?: number; | ||
/** Short error name */ | ||
error?: string; | ||
/** Message explaining the error */ | ||
message?: string; | ||
/** Code of the error */ | ||
code?: number; | ||
}; | ||
export const { useUpdateHaSwitchMutation } = injectedRtkApi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# npx mock-to-openapi ./libs/types/examples | ||
# https://editor.swagger.io/ | ||
|
||
openapi: 3.0.1 | ||
info: | ||
title: Switches Controller API | ||
description: Switches Controller | ||
version: 1.0.0 | ||
servers: | ||
- url: https://example.com | ||
description: Generated server url | ||
paths: | ||
/api/switches/ha/{entity_id}: | ||
post: | ||
operationId: updateHaSwitch | ||
parameters: | ||
- name: entity_id | ||
in: path | ||
description: Entity ID | ||
required: true | ||
schema: | ||
type: string | ||
requestBody: | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
state: | ||
type: string | ||
description: Target state, On or Off | ||
enum: [On, Off] | ||
responses: | ||
"200": | ||
description: updateHaSwitch | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/UpdateHaSwitchResponse" | ||
"400": | ||
description: Bad request. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ErrorResponse" | ||
"401": | ||
description: Unauthorized. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: "#/components/schemas/ErrorResponse" | ||
components: | ||
schemas: | ||
ErrorResponse: | ||
type: object | ||
properties: | ||
timestamp: | ||
type: string | ||
description: Time when error happened | ||
status: | ||
type: integer | ||
description: Code describing the error | ||
format: int32 | ||
error: | ||
type: string | ||
description: Short error name | ||
message: | ||
type: string | ||
description: Message explaining the error | ||
code: | ||
type: integer | ||
description: Code of the error | ||
format: int32 | ||
description: Error information details | ||
UpdateHaSwitchResponse: | ||
type: string | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/** | ||
* This file was auto-generated by openapi-typescript. | ||
* Do not make direct changes to the file. | ||
*/ | ||
|
||
export interface paths { | ||
"/api/switches/ha/{entity_id}": { | ||
parameters: { | ||
query?: never; | ||
header?: never; | ||
path?: never; | ||
cookie?: never; | ||
}; | ||
get?: never; | ||
put?: never; | ||
post: operations["updateHaSwitch"]; | ||
delete?: never; | ||
options?: never; | ||
head?: never; | ||
patch?: never; | ||
trace?: never; | ||
}; | ||
} | ||
export type webhooks = Record<string, never>; | ||
export interface components { | ||
schemas: { | ||
/** @description Error information details */ | ||
ErrorResponse: { | ||
/** @description Time when error happened */ | ||
timestamp?: string; | ||
/** | ||
* Format: int32 | ||
* @description Code describing the error | ||
*/ | ||
status?: number; | ||
/** @description Short error name */ | ||
error?: string; | ||
/** @description Message explaining the error */ | ||
message?: string; | ||
/** | ||
* Format: int32 | ||
* @description Code of the error | ||
*/ | ||
code?: number; | ||
}; | ||
UpdateHaSwitchResponse: string; | ||
}; | ||
responses: never; | ||
parameters: never; | ||
requestBodies: never; | ||
headers: never; | ||
pathItems: never; | ||
} | ||
export type $defs = Record<string, never>; | ||
export interface operations { | ||
updateHaSwitch: { | ||
parameters: { | ||
query?: never; | ||
header?: never; | ||
path: { | ||
/** @description Entity ID */ | ||
entity_id: string; | ||
}; | ||
cookie?: never; | ||
}; | ||
requestBody: { | ||
content: { | ||
"application/json": { | ||
/** | ||
* @description Target state, On or Off | ||
* @enum {string} | ||
*/ | ||
state?: "On" | "Off"; | ||
}; | ||
}; | ||
}; | ||
responses: { | ||
/** @description updateHaSwitch */ | ||
200: { | ||
headers: { | ||
[name: string]: unknown; | ||
}; | ||
content: { | ||
"application/json": components["schemas"]["UpdateHaSwitchResponse"]; | ||
}; | ||
}; | ||
/** @description Bad request. */ | ||
400: { | ||
headers: { | ||
[name: string]: unknown; | ||
}; | ||
content: { | ||
"application/json": components["schemas"]["ErrorResponse"]; | ||
}; | ||
}; | ||
/** @description Unauthorized. */ | ||
401: { | ||
headers: { | ||
[name: string]: unknown; | ||
}; | ||
content: { | ||
"application/json": components["schemas"]["ErrorResponse"]; | ||
}; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters