MajorDom Device Integration Guide¶
An integration is a module that bridges MajorDom Hub with IoT devices of a specific protocol or vendor (e.g. HomeKit, Zigbee, Z-Wave).
Concepts¶
| Term | Meaning |
|---|---|
| Hub | The MajorDom Hub core software |
| Integration | A protocol/vendor-specific plugin |
| Discovery Service | A Hub-provided transport-level service (Zeroconf/mDNS, SSDP, or BLE) that fires raw discovery events. Injected via self.dependencies. |
| Controller (capitalized) | The class your integration must implement (AbstractController subclass) |
| a controller (lowercase) | Any third-party device that can control IoT devices (smartphone, Alexa, etc.) |
| Discovery | A detected, unpaired device that is available to be paired |
| Device | A paired and controllable device saved in the Hub's database |
| Parameter | A single controllable or observable property of a device (e.g. brightness, temperature) |
A device moves through these states:
Suggested Module Structure¶
An integration will typically need more than just a controller. Recommended minimal layout:
services/controller/myintegration/
├── controller.py # AbstractController subclass — the only required file; discovery callbacks and cancel closures are typically stored here too
├── models.py # Typed integration_data schemas for Device and Parameter subclasses, see Storing Data
├── mapper.py # Protocol ↔ MajorDom domain model conversions, isolated from the controller for readability
└── parameters_map.py # Supplemental metadata for parameters that the API does not expose, usually in a form of a static dictionary. For example, device might expose min/max limits for a number via device's API, but the unit is only defined in pdf specification.
controller.py is the only required file. The rest are a template for keeping the controller clean — separate models, pull out conversion logic into a mapper, add metadata dictionary, etc. Of course, other files can be added as needed.
Implementation Checklist¶
- [ ] Discovery service listeners fire when devices are found, and the controller calls
self.dependencies.output.controller_did_receive_discovery - [ ] Discovery services registered via
self.dependencies.zeroconf_discovery_service,ssdp_discovery_service, and/orble_discovery_serviceas appropriate; cancel closures saved and called instop - [ ] Discovery of devices already paired to the Hub on reconnect, e.g. after a reboot (
self.dependencies.output.controller_did_connect_deviceis called) - [ ]
start_pairing_windowis implemented if the protocol requires an explicit scan mode - [ ] Device pairing (
pair_deviceis implemented) - [ ] Device schema is properly mapped: device info, parameter list, and each parameter's metadata are translated to MajorDom's domain model
- [ ] Hub → Device control (
send_commandis implemented) - [ ] Device → Hub event subscription (
self.dependencies.output.controller_did_receive_device_eventsis called on incoming events) - [ ]
identify,unpair, andfetchare implemented - [ ] Graceful shutdown in
stop
See Implementing a Controller for details.
Notes¶
For IP Devices¶
- Handle IP changes. DHCP can reassign addresses. Identify devices by a stable ID (MAC, serial, mDNS hostname, domain-provided id) rather than IP. Monitor ip address regularly and keep it up to date.
- Use the Hub's provided discovery. Register your mDNS service types via
self.dependencies.zeroconf_discovery_service.register(...), and similar for SSDP and BLE. See Discovery Services for details. Do not spin up your own discovery stack unless absolutely needed.