API Docs

A Wi-Fi event watcher that monitors changes to a Wi-Fi interface.

Create via hs.wifi.addWatcher(). Set a callback with setCallback(), then call start() to begin receiving events. By default only "ssidChange" is watched; use the events property to watch other event types.

The callback receives (event, info):

Event Info keys
"ssidChange" interface: string
"bssidChange" interface: string
"countryCodeChange" interface: string
"linkChange" interface: string
"linkQualityChange" interface: string, rssi: number, transmitRate: number
"modeChange" interface: string
"powerChange" interface: string
"scanCacheUpdated" interface: string

Example:

const w = hs.wifi.addWatcher()
w.setCallback((event, info) => {
    console.log(event + " on " + info.interface)
}).start()

Properties

identifier

string
The unique identifier assigned to this watcher.

events

string[]
The event types this watcher will invoke its callback for. Defaults to `["ssidChange"]`. Unrecognized values are ignored with a console warning; see `hs.wifi.watcherEventTypes` for the list of valid values. Can be changed while the watcher is running.

Methods

start() -> HSWifiWatcher

Starts monitoring the event types configured in `events`.
start() -> HSWifiWatcher
HSWifiWatcher
self, for chaining
const w = hs.wifi.addWatcher()
w.setCallback((ev, info) => console.log(ev)).start()

stop() -> HSWifiWatcher

Stops monitoring Wi-Fi events.
stop() -> HSWifiWatcher
HSWifiWatcher
self, for chaining
w.stop()

setCallback(fn) -> HSWifiWatcher

Sets the callback function invoked when a watched Wi-Fi event occurs.
setCallback(fn) -> HSWifiWatcher
Name Type Description
fn function Called with the event name and an info dictionary; see type documentation for event names and info keys.
HSWifiWatcher
self, for chaining
w.setCallback((event, info) => {
    if (event === "powerChange") console.log("power changed on " + info.interface)
})

destroy() -> None

Stops the watcher and releases all resources. Called automatically during shutdown.
destroy() -> None
None
w.destroy()