/** * 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 { const effectiveSiteId = siteId || (await this.client.getSiteId()); return this.client.request( 'GET', `/sites/${effectiveSiteId}/devices/${deviceId}/wan` ); } /** * Configure WAN port */ async configureWANPort( deviceId: string, portId: number, config: Partial, siteId?: string ): Promise { 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 { const effectiveSiteId = siteId || (await this.client.getSiteId()); return this.client.request( 'GET', `/sites/${effectiveSiteId}/devices/${deviceId}/lan` ); } /** * Configure LAN port */ async configureLANPort( deviceId: string, portId: number, config: Partial, siteId?: string ): Promise { 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 { const effectiveSiteId = siteId || (await this.client.getSiteId()); return this.client.request( 'GET', `/sites/${effectiveSiteId}/devices/${deviceId}/routing` ); } /** * Create a routing rule */ async createRoutingRule( deviceId: string, rule: Omit, siteId?: string ): Promise { const effectiveSiteId = siteId || (await this.client.getSiteId()); return this.client.request( 'POST', `/sites/${effectiveSiteId}/devices/${deviceId}/routing`, { body: rule } ); } /** * Update a routing rule */ async updateRoutingRule( deviceId: string, ruleId: string, rule: Partial, siteId?: string ): Promise { 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 { 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 { const effectiveSiteId = siteId || (await this.client.getSiteId()); await this.client.request( 'PUT', `/sites/${effectiveSiteId}/devices/${deviceId}/vlans/${vlanId}/dhcp`, { body: dhcpConfig } ); } }