feat(unifi): implement comprehensive UniFi API client with controllers, protect, access, account, managers, resources, HTTP client, interfaces, logging, plugins, and tests
This commit is contained in:
85
ts/classes.host.ts
Normal file
85
ts/classes.host.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import type { UnifiAccount } from './classes.unifi-account.js';
|
||||
import type { IUnifiHost } from './interfaces/index.js';
|
||||
|
||||
/**
|
||||
* Represents a UniFi host device from Site Manager
|
||||
*/
|
||||
export class UnifiHost implements IUnifiHost {
|
||||
/** Reference to parent account */
|
||||
private unifiAccount?: UnifiAccount;
|
||||
|
||||
// IUnifiHost properties
|
||||
public id: string;
|
||||
public hardwareId?: string;
|
||||
public name?: string;
|
||||
public type?: string;
|
||||
public firmwareVersion?: string;
|
||||
public isOnline?: boolean;
|
||||
public ipAddress?: string;
|
||||
public macAddress?: string;
|
||||
public siteId?: string;
|
||||
public status?: {
|
||||
state?: string;
|
||||
lastSeen?: string;
|
||||
};
|
||||
public features?: string[];
|
||||
public reportedState?: Record<string, unknown>;
|
||||
|
||||
constructor() {
|
||||
this.id = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a host instance from API response object
|
||||
*/
|
||||
public static createFromApiObject(
|
||||
apiObject: IUnifiHost,
|
||||
unifiAccount?: UnifiAccount
|
||||
): UnifiHost {
|
||||
const host = new UnifiHost();
|
||||
Object.assign(host, apiObject);
|
||||
host.unifiAccount = unifiAccount;
|
||||
return host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw API object representation
|
||||
*/
|
||||
public toApiObject(): IUnifiHost {
|
||||
return {
|
||||
id: this.id,
|
||||
hardwareId: this.hardwareId,
|
||||
name: this.name,
|
||||
type: this.type,
|
||||
firmwareVersion: this.firmwareVersion,
|
||||
isOnline: this.isOnline,
|
||||
ipAddress: this.ipAddress,
|
||||
macAddress: this.macAddress,
|
||||
siteId: this.siteId,
|
||||
status: this.status,
|
||||
features: this.features,
|
||||
reportedState: this.reportedState,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if host is online
|
||||
*/
|
||||
public checkOnline(): boolean {
|
||||
return this.isOnline === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get host type (e.g., 'udm-pro', 'cloud-key')
|
||||
*/
|
||||
public getType(): string {
|
||||
return this.type || 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if host supports a specific feature
|
||||
*/
|
||||
public hasFeature(feature: string): boolean {
|
||||
return this.features?.includes(feature) ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user