Files
omada-api/src/services/RouterService.ts
2025-12-21 14:17:54 -08:00

145 lines
3.5 KiB
TypeScript

/**
* Router-specific operations (ER605, etc.)
*/
import { OmadaClient } from '../client/OmadaClient.js';
import { WANPort, LANPort } from '../types/devices.js';
import { RoutingRule, DHCPConfig } from '../types/networks.js';
export class RouterService {
constructor(private client: OmadaClient) {}
/**
* Get router WAN ports
*/
async getWANPorts(deviceId: string, siteId?: string): Promise<WANPort[]> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
return this.client.request<WANPort[]>(
'GET',
`/sites/${effectiveSiteId}/devices/${deviceId}/wan`
);
}
/**
* Configure WAN port
*/
async configureWANPort(
deviceId: string,
portId: number,
config: Partial<WANPort>,
siteId?: string
): Promise<void> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
await this.client.request(
'PUT',
`/sites/${effectiveSiteId}/devices/${deviceId}/wan/${portId}`,
{ body: config }
);
}
/**
* Get router LAN ports
*/
async getLANPorts(deviceId: string, siteId?: string): Promise<LANPort[]> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
return this.client.request<LANPort[]>(
'GET',
`/sites/${effectiveSiteId}/devices/${deviceId}/lan`
);
}
/**
* Configure LAN port
*/
async configureLANPort(
deviceId: string,
portId: number,
config: Partial<LANPort>,
siteId?: string
): Promise<void> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
await this.client.request(
'PUT',
`/sites/${effectiveSiteId}/devices/${deviceId}/lan/${portId}`,
{ body: config }
);
}
/**
* List routing rules
*/
async listRoutingRules(deviceId: string, siteId?: string): Promise<RoutingRule[]> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
return this.client.request<RoutingRule[]>(
'GET',
`/sites/${effectiveSiteId}/devices/${deviceId}/routing`
);
}
/**
* Create a routing rule
*/
async createRoutingRule(
deviceId: string,
rule: Omit<RoutingRule, 'id'>,
siteId?: string
): Promise<RoutingRule> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
return this.client.request<RoutingRule>(
'POST',
`/sites/${effectiveSiteId}/devices/${deviceId}/routing`,
{ body: rule }
);
}
/**
* Update a routing rule
*/
async updateRoutingRule(
deviceId: string,
ruleId: string,
rule: Partial<RoutingRule>,
siteId?: string
): Promise<void> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
await this.client.request(
'PUT',
`/sites/${effectiveSiteId}/devices/${deviceId}/routing/${ruleId}`,
{ body: rule }
);
}
/**
* Delete a routing rule
*/
async deleteRoutingRule(
deviceId: string,
ruleId: string,
siteId?: string
): Promise<void> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
await this.client.request(
'DELETE',
`/sites/${effectiveSiteId}/devices/${deviceId}/routing/${ruleId}`
);
}
/**
* Configure DHCP for a VLAN/network
*/
async configureDHCP(
deviceId: string,
vlanId: string,
dhcpConfig: DHCPConfig,
siteId?: string
): Promise<void> {
const effectiveSiteId = siteId || (await this.client.getSiteId());
await this.client.request(
'PUT',
`/sites/${effectiveSiteId}/devices/${deviceId}/vlans/${vlanId}/dhcp`,
{ body: dhcpConfig }
);
}
}