| OpenHAP::DeviceLoader(3p) | Perl Library Manual | OpenHAP::DeviceLoader(3p) |
NAME
OpenHAP::DeviceLoader - Device configuration loading and instantiation
SYNOPSIS
use OpenHAP::DeviceLoader;
use OpenHAP::Config;
use OpenHAP::HAP;
use OpenHAP::MQTT;
my $config = OpenHAP::Config->new(file => '/etc/openhapd.conf');
$config->load();
my $hap = OpenHAP::HAP->new(...);
my $mqtt = OpenHAP::MQTT->new(...);
my $loader = OpenHAP::DeviceLoader->new();
my $count = $loader->load_devices($config, $hap, $mqtt);
print "Loaded $count devices\n";
DESCRIPTION
OpenHAP::DeviceLoader handles loading device configurations, validating them, instantiating the appropriate device classes, and registering them with the HAP bridge. It centralizes device management logic and provides extensibility for adding new device types.
METHODS
new
my $loader = OpenHAP::DeviceLoader->new()
Create a new device loader instance. The loader maintains an internal counter for assigning Accessory IDs (AIDs), starting at 2 (AID 1 is reserved for the bridge itself).
load_devices
my $count = $loader->load_devices($config, $hap, $mqtt)
Load all devices from the configuration and add them to the HAP bridge. Returns the number of successfully loaded devices.
The method:
- Retrieves device list from configuration
- Validates each device configuration
- Instantiates appropriate device classes
- Subscribes devices to MQTT topics (if connected)
- Registers devices with HAP bridge
- Logs progress and errors
Errors are logged but don't stop processing of remaining devices.
get_devices
my @devices = $loader->get_devices()
Return a list of all successfully loaded device accessory objects.
DEVICE VALIDATION
Each device configuration must include:
- name - Human-readable device name
- type - Device type (e.g., 'tasmota')
- subtype - Device subtype (e.g., 'thermostat')
- topic - MQTT topic for communication
- id - Unique identifier (defaults to topic if not specified)
Devices missing required fields are skipped with appropriate error logging.
SUPPORTED DEVICES
Currently supported device types:
- •
- tasmota/thermostat - Tasmota-based thermostat devices
Additional device types can be added by:
- 1. Adding type check to _is_supported_device()
- 2. Adding instantiation case to _instantiate_device()
- 3. Ensuring device class implements required interface
ERROR HANDLING
The loader uses eval blocks to catch errors during device instantiation and MQTT subscription. Errors are logged but don't stop processing of other devices. This ensures one misconfigured device doesn't prevent the entire system from starting.
LOGGING
The loader logs at various levels:
- debug - Device processing details, MQTT subscriptions
- info - Successfully loaded devices, summary counts
- warning - Missing optional fields, recoverable issues
- error - Invalid configurations, instantiation failures
SEE ALSO
OpenHAP::Config, OpenHAP::HAP, OpenHAP::MQTT, OpenHAP::Tasmota::Thermostat
AUTHOR
Dick Olsson <hi@senzilla.io>
| 2026-07-27 | OpenBSD |