-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: unifi controller integration #2236
base: dev
Are you sure you want to change the base?
Conversation
Here's the code health analysis summary for commits Analysis Summary
|
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Outdated
Show resolved
Hide resolved
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Outdated
Show resolved
Hide resolved
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Outdated
Show resolved
Hide resolved
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Outdated
Show resolved
Hide resolved
Thanks a lot for this contribution, @pitschi . |
|
@pitschi you can simply continue in this pr if you want to address the comments |
ups... ok, thanks. have to get into the flow again. |
No worries. Here's how it works:
|
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Show resolved
Hide resolved
packages/integrations/src/unifi-controller/unifi-controller-integration.ts
Outdated
Show resolved
Hide resolved
Since there is no further activity on this PR, I will take over this pull request. Thank you for the initial contribution @pitschi |
a738c45
to
8cd2d71
Compare
8cd2d71
to
b221a88
Compare
af4fd14
to
b9970e6
Compare
31ee449
to
4ff6d7d
Compare
4ff6d7d
to
aab769f
Compare
id: integration.id, | ||
name: integration.name, | ||
kind: integration.kind, | ||
updatedAt: timestamp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it makes more sense to put this one level out?
wwwStatus: "enabled" | "disabled"; | ||
wwwLatency: number; | ||
wwwPing: number; | ||
wwwUptime: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using objects instead? Like
const a = {
www: {
status: "enabled",
latency: 5,
ping: 3,
uptime: 99999
}
};
export const throwByUnifiControllerResponseStatusCode = (statusCode: number) => { | ||
switch (statusCode) { | ||
case 400: | ||
throw new IntegrationTestConnectionError("badRequest"); | ||
case 401: | ||
throw new IntegrationTestConnectionError("unauthorized"); | ||
case 403: | ||
throw new IntegrationTestConnectionError("forbidden"); | ||
case 404: | ||
throw new IntegrationTestConnectionError("notFound"); | ||
case 429: | ||
throw new IntegrationTestConnectionError("tooManyRequests"); | ||
case 500: | ||
throw new IntegrationTestConnectionError("internalServerError"); | ||
case 503: | ||
throw new IntegrationTestConnectionError("serviceUnavailable"); | ||
default: | ||
throw new IntegrationTestConnectionError("commonError"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use throwErrorByStatusCode
instead and add the missing codes
const responseHeaders = loginResponse.headers; | ||
const newHeaders: Record<string, string> = {}; | ||
const loginToken = UnifiControllerIntegration.extractLoginTokenFromCookies(responseHeaders); | ||
newHeaders.Cookie = `${loginToken};`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about storing this login token with session-store
? Then it will also be persisted for nextjs etc. I would suggest to do it similar to what I did with pi-hole v6 (always fetch new session for test connection)
const result = unifiSummaryResponseSchema.safeParse(await statsResponse.json()); | ||
|
||
if (!result.success) { | ||
throw new Error("Error parsing response from unifi controller.", result.error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new ParseError()
@@ -51,6 +53,8 @@ export const widgetImports = { | |||
downloads, | |||
"mediaRequests-requestList": mediaRequestsList, | |||
"mediaRequests-requestStats": mediaRequestsStats, | |||
networkControllerSummary, | |||
networkControllerNetworkStatus: networkControllerStatus, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make them the same name
} | ||
|
||
return prevData.map((item) => | ||
item.integration.id === data.integration.id ? { ...item, summary: data.summary } : item, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may also need to update the updatedAt when you want it existing. If not needed, just remove it
xl2: rem(24), | ||
xl3: rem(28), | ||
xl4: rem(36), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about 2xl
instead of xl2
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two variants are very similar. Why not just one generic component for example with properties
interface NetworkStatusContentProps {
icon: TablerIcon;
title: string;
stats: StatRowProps[]
}
Then the design will always be consistent and we don't need to change (now 2) multiple components
<Box h="100%" p="sm"> | ||
<Center h={"100%"}> | ||
<List spacing={"xs"} center> | ||
<List.Item icon={<StatusIcon status={data[0]?.wanStatus} />}>WAN</List.Item> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just make it no longer an array if we only use [0]
?
Homarr
Thank you for your contribution. Please ensure that your pull request meets the following pull request:
pnpm buid
, autofix withpnpm format:fix
)dev
branchx
,y
,i
or any abbrevation)