Skip to content

Conversation

@igorkulman
Copy link
Contributor

Description

This PR adds a new UniFi service integration that displays network information from UniFi Network
Controllers, including connected clients, access points, and other network devices.
Screenshot 2025-09-27 at 16 56 59

The UniFi service automatically handles session-based authentication and CSRF protection,
supporting both legacy and modern UniFi API endpoints. It provides real-time monitoring of network
infrastructure with configurable refresh intervals.

Key Features:

  • Displays connected clients count with user icon
  • Shows access points count with WiFi icon
  • Shows other network devices count with network icon
  • Automatic session management and authentication
  • Configurable site monitoring
  • Error handling with visual indicators

Mock Data Included:

  • Complete mock API responses for testing and development
  • Realistic UniFi device data including access points, switches, and gateways
  • Authentication endpoints for both legacy and modern APIs

I only have a self-hosted Unifi controller running locally, so I did not test UDM or Cloud Key but they should work according to Unifi api docs.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring

Checklist:

  • I've read & comply with the contributing guidelines
  • I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.
  • I have made corresponding changes to the documentation (README.md).
  • I've checked my modifications for any breaking changes, especially in the config.yml file

Copy link
Owner

@bastienwirtz bastienwirtz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again @igorkulman. Aside a thing on the prefix management, it looks good 👍

- **Access Points**: Number of UniFi access points (UAP devices)
- **Network Devices**: Number of other UniFi network devices (switches, gateways, etc.)

The service uses UniFi's standard API endpoints and maintains session cookies automatically. For UDM/UDM Pro devices, the service will automatically use the `/proxy/network` prefix when `udm: true` is configured.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

udm option is not listed in the configuration option

});
this.sessionCookie = true;
return true;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed, there is no expected return value.

Comment on lines +75 to +82
// Check if URL indicates we need a prefix
if (this.item.apiUrl && this.item.apiUrl.includes("/manage")) {
return "/manage";
}
if (this.item.url && this.item.url.includes("/manage")) {
return "/manage";
}
return this.item.udm ? "/proxy/network" : "";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apiUrl does not exists, or at least is not documented, but more importantly:
You are using it like that:

 this.fetch(`${this.prefix}/api/s/${this.site}/stat/device`);

Considering that this.fetch will add this.item.url to the request, if the url does include /manage, you will end up with something like https://xxxxx/manage/manage/api/default/stats/devices (double prefix)

I see 2 options here:

  • You can remove the udm option and use the standard endpoint field to get the api url with the prefix
    (with the documentation saying to put the url with /manage or /proxy/network depending on the situation), and remove the prefix computed property.
  • OR update your code with the following:
Suggested change
// Check if URL indicates we need a prefix
if (this.item.apiUrl && this.item.apiUrl.includes("/manage")) {
return "/manage";
}
if (this.item.url && this.item.url.includes("/manage")) {
return "/manage";
}
return this.item.udm ? "/proxy/network" : "";
if (this.item.url && (this.item.url.includes("/manage") || this.item.url.includes("/proxy/network")) {
// the configuration already include the prefix
return "";
}
return this.item.udm ? "/proxy/network" : "/manage";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants