API Reference
Welcome to the Energy Manager IoT API reference documentation. This section provides detailed information about the classes, methods, and interfaces available in the library.
Core Classes
The Energy Manager IoT library is organized around these main classes:
- EnergyManager - The main entry point for the library
- DeviceRegistry - Handles device registration and grouping
- MqttHandler - Manages MQTT communication
Types and Interfaces
The library includes several TypeScript interfaces and types:
- Device Types - Device interfaces and types
- Status Types - Status-related interfaces and enums
- Command Types - Command interfaces and enums
- Error Types - Error classes and interfaces
API Overview Diagram
API Overview Diagram
The diagram shows the relationships between core components (EnergyManager, DeviceRegistry, MqttHandler) and how they interact with types and external systems.
Usage Example
Here's a simple example showing how the main classes interact:
import {
EnergyManager,
DeviceType,
CommandType
} from 'energy-manager-iot';
// Create the main manager
const manager = new EnergyManager();
// Connect to MQTT broker
await manager.connect('mqtt://localhost:1883');
// Register a device
manager.registerDevice('sensor1', 'Temperature Sensor', DeviceType.SENSOR);
// Send a command
await manager.sendCommand('sensor1', CommandType.SET_REPORTING, { interval: 60 });
// Listen for events
manager.on('statusUpdate', (deviceId, status) => {
console.log(`Status update from ${deviceId}:`, status);
});
Explore the documentation for each class to learn more about the available methods and properties.