Skip to content

feat(power): add Wake-on-LAN power module (type: wol)#217

Open
Ulrond wants to merge 1 commit into
rdkcentral:developfrom
Ulrond:feature/216-wake-on-lan-power-module
Open

feat(power): add Wake-on-LAN power module (type: wol)#217
Ulrond wants to merge 1 commit into
rdkcentral:developfrom
Ulrond:feature/216-wake-on-lan-power-module

Conversation

@Ulrond

@Ulrond Ulrond commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Closes #216.

What

Adds framework/core/powerModules/wol.py (powerWol) and a type: "wol" branch in powerControlClass, so RAFT can wake a device that is asleep or in a Wake-on-LAN soft-off state.

  • powerOn() sends the WoL magic packet (6x 0xFF + target MAC x16) to broadcast:port.
  • Wake-on-LAN is wake-only, so powerOff() is a logged no-op and reboot() is a best-effort wake.
  • Config (under a device powerSwitch:): mac (required), broadcast (default 255.255.255.255), port (default 9).
  • Standard-library only (socket) — no new dependencies.
powerSwitch:
  type: "wol"
  mac: "aa:bb:cc:dd:ee:ff"
  broadcast: "255.255.255.255"   # optional, subnet broadcast for directed WoL
  port: 9                        # optional (7 or 9)

Why

powerControlClass supports hs100 / apc / apcAos / olimex / kasa / tapo / SLP / none, but none can bring back a target that has dropped its console to sleep. Targets that aggressively deep-sleep can only be woken by a magic packet; without this, runs against them need an out-of-band wake step before the session opens.

Testing

  • powerOn() builds a correct magic packet and woke a real armv7 target on the same broadcast domain.
  • powerOff() / reboot() behave as documented (no-op / best-effort wake).
  • Invalid and missing MAC are rejected with clear errors.
  • powerControl dispatch (type: "wol") constructs the module; both files pass a syntax check.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Wake-on-LAN (WoL) “power switch” implementation and wires it into the existing powerControlClass dispatch so RAFT can wake devices that are asleep/soft-off via a WoL magic packet.

Changes:

  • Added powerWol module that constructs and sends a WoL magic packet to a configurable broadcast address/UDP port.
  • Added type == "wol" dispatch branch in powerControlClass to instantiate the new module.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
framework/core/powerModules/wol.py Implements WoL magic-packet creation and UDP broadcast send; includes wake-only semantics for powerOff()/reboot().
framework/core/powerControl.py Adds import and type: "wol" dispatch branch to construct powerWol.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

raise ValueError("powerWol requires a 'mac' address")
self.mac = mac
self.broadcast = broadcast or "255.255.255.255"
self.port = int(port) if port else 9
self.log.info("powerWol(mac={}, broadcast={}, port={})".format(
self.mac, self.broadcast, self.port))

def _magicPacket(self):
Comment on lines +72 to +75
hexMac = self.mac.replace(":", "").replace("-", "").replace(".", "")
if len(hexMac) != 12:
raise ValueError("Invalid MAC address: {}".format(self.mac))
return b"\xff" * 6 + bytes.fromhex(hexMac) * 16
bool: True if the packet was sent, False on error.
"""
try:
packet = self._magicPacket()
powerControlClass had no way to wake a device that is asleep or in a
Wake-on-LAN soft-off state. Add framework/core/powerModules/wol.py
(powerWol) and a `type: "wol"` dispatch branch:

- powerOn() sends the WoL magic packet (6x 0xFF + MAC x16) to broadcast:port.
- Wake-on-LAN is wake-only: powerOff() is a logged no-op, reboot() a
  best-effort wake.
- Config: mac (required), broadcast (default 255.255.255.255), port (default 9).
- Standard-library only (socket); no new dependencies.

Fixes rdkcentral#216
@Ulrond Ulrond force-pushed the feature/216-wake-on-lan-power-module branch from c5d9760 to 0a32b41 Compare July 14, 2026 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a Wake-on-LAN power module (type: wol)

2 participants