### Install opendyson CLI Source: https://github.com/libdyson-wg/opendyson/blob/main/README.md Install the opendyson CLI tool using the go install command. Ensure Go is installed and configured on your system. ```sh go install github.com/libdyson-wg/opendyson@latest ``` -------------------------------- ### Install OpenDyson CLI Source: https://context7.com/libdyson-wg/opendyson/llms.txt Install the OpenDyson CLI tool using 'go install' or download a prebuilt binary. Ensure the binary is executable before running. ```sh # Install via go install go install github.com/libdyson-wg/opendyson@latest # Or download a prebuilt binary from the releases page and mark it executable chmod +x opendyson-linux-amd64 ./opendyson-linux-amd64 help ``` -------------------------------- ### Dyson Device Interface Methods Source: https://context7.com/libdyson-wg/opendyson/llms.txt Demonstrates the usage of the `devices.Device` interface, implemented by `devices.BaseDevice`. The `CanConnect()` method indicates MQTT connectivity support. This example shows how to create a `BaseDevice` and call its methods. ```go import "github.com/libdyson-wg/opendyson/devices" // devices.Device interface methods: // GetName() string // GetSerial() string // GetModel() string // GetType() string // GetVariant() string // CanConnect() bool var d devices.Device = &devices.BaseDevice{ Name: "Living Room Purifier", Serial: "AB1-EU-KBA1234A", Model: "TP07", Type: "475", ProductCategory: "fan", ConnectionCategory: "wifiProduct", } fmt.Println(d.GetName()) // Living Room Purifier fmt.Println(d.CanConnect()) // true (not "nonConnected") ``` -------------------------------- ### Initiate Dyson Login Flow Source: https://context7.com/libdyson-wg/opendyson/llms.txt Checks account status and starts the two-factor login process. The Dyson API sends an OTP email to the user, and this function returns a challenge UUID required for `CompleteLogin`. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" ) challengeID, err := cloud.BeginLogin("user@example.com") if err != nil { // "account status is UNREGISTERED" or network error panic(err) } fmt.Printf("Challenge ID: %s\n", challengeID) // user receives an OTP email; prompt them for it ``` -------------------------------- ### Complete Dyson Login and Get Token Source: https://context7.com/libdyson-wg/opendyson/llms.txt Finalizes authentication by submitting the OTP code, password, and challenge ID. Returns a bearer token string for subsequent API calls. The token can be persisted using `config.SetToken` and activated for the current session with `cloud.SetToken`. ```go import ( "fmt" "github.com/google/uuid" "github.com/libdyson-wg/opendyson/cloud" "github.com/libdyson-wg/opendyson/internal/config" ) challengeID, _ := cloud.BeginLogin("user@example.com") token, err := cloud.CompleteLogin( "user@example.com", "123456", // OTP from email "MyP@ssword", // MyDyson account password challengeID, ) if err != nil { panic(fmt.Errorf("login failed: %w", err)) } // Persist token for future sessions _ = config.SetToken(token) // Activate token for current session cloud.SetToken(token) fmt.Println("Successfully authenticated") ``` -------------------------------- ### cloud.BeginLogin(email string) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Initiates the two-factor login flow by checking account status and sending an OTP email to the user. Returns a challenge UUID. ```APIDOC ## BeginLogin cloud.BeginLogin(email string) ### Description Checks account status, then initiates the two-factor login flow. Dyson sends an OTP email to the user; returns a challenge UUID used in `CompleteLogin`. ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the user. ### Response #### Success Response (200) - **challengeID** (uuid.UUID) - A unique identifier for the login challenge. ### Request Example ```go challengeID, err := cloud.BeginLogin("user@example.com") if err != nil { // "account status is UNREGISTERED" or network error panic(err) } fmt.Printf("Challenge ID: %s\n", challengeID) // user receives an OTP email; prompt them for it ``` ``` -------------------------------- ### devices.Device Interface Source: https://context7.com/libdyson-wg/opendyson/llms.txt The base `Device` interface and its methods, implemented by `BaseDevice`. ```APIDOC ## devices.Device Interface ### Description The `Device` interface is implemented by all Dyson devices. `BaseDevice` provides the concrete implementation. `CanConnect()` indicates whether the device supports MQTT connectivity. ### Methods - **GetName() string**: Returns the name of the device. - **GetSerial() string**: Returns the serial number of the device. - **GetModel() string**: Returns the model of the device. - **GetType() string**: Returns the type of the device. - **GetVariant() string**: Returns the variant of the device. - **CanConnect() bool**: Returns true if the device supports MQTT connectivity, false otherwise. ### Example Usage ```go import "github.com/libdyson-wg/opendyson/devices" var d devices.Device = &devices.BaseDevice{ Name: "Living Room Purifier", Serial: "AB1-EU-KBA1234A", Model: "TP07", Type: "475", ProductCategory: "fan", ConnectionCategory: "wifiProduct", } fmt.Println(d.GetName()) // Living Room Purifier fmt.Println(d.CanConnect()) // true (not "nonConnected") ``` ``` -------------------------------- ### cloud.GetDevices() Source: https://context7.com/libdyson-wg/opendyson/llms.txt Fetches a slice of `devices.Device` interfaces for all devices registered to the authenticated account. ```APIDOC ## GetDevices cloud.GetDevices() ### Description Returns a slice of `devices.Device` interfaces for all devices registered to the authenticated account. Connected devices include firmware info, decrypted MQTT credentials, and IoT credentials. ### Response #### Success Response (200) - **ds** ([]devices.Device) - A slice of `devices.Device` interfaces representing the user's registered devices. ### Request Example ```go ds, err := cloud.GetDevices() if err != nil { panic(err) } for _, d := range ds { fmt.Printf("Device: %s (serial: %s, model: %s)\n", d.GetName(), d.GetSerial(), d.GetModel()) if d.CanConnect() { fmt.Println(" -> This device supports MQTT connection") } } // Full YAML dump (includes sensitive credentials) out, _ := yaml.Marshal(ds) fmt.Println(string(out)) ``` ``` -------------------------------- ### opendyson listen SERIAL Source: https://context7.com/libdyson-wg/opendyson/llms.txt Connects to a device by serial number and subscribes to its status, fault, and command MQTT topics, printing all incoming messages continuously. Use `--iot` to connect via Dyson's AWS IoT cloud broker instead of local LAN MQTT. ```APIDOC ## opendyson listen SERIAL ### Description Connects to a device by serial number and subscribes to its status, fault, and command MQTT topics, printing all incoming messages continuously until interrupted with Ctrl+C. Use `--iot` to connect via Dyson's AWS IoT cloud broker instead of local LAN MQTT. ### Method CLI Command ### Endpoint /listen/:SERIAL ### Parameters #### Path Parameters - **SERIAL** (string) - Required - The serial number of the Dyson device. #### Query Parameters - **iot** (boolean) - Optional - Use Dyson's AWS IoT cloud broker instead of local LAN MQTT. ### Request Example ```sh # Listen over local LAN MQTT (default) $ opendyson listen AB1-EU-KBA1234A Subscribing to 475/AB1-EU-KBA1234A/status/current Subscribing to 475/AB1-EU-KBA1234A/status/fault Subscribing to 475/AB1-EU-KBA1234A/command Status: {"msg":"CURRENT-PRODUCT-STATE","product-state":{"fpwr":"ON","fnsp":"0003","auto":"OFF","nmod":"OFF","rhtm":"OFF",...}} Fault: {"msg":"ENVIRONMENTAL-CURRENT-SENSOR-DATA","data":{"tact":"2963","hact":"58","pact":"0","vact":"0","sltm":"OFF"}} # Listen via AWS IoT cloud broker $ opendyson listen AB1-EU-KBA1234A --iot Subscribing to 475/AB1-EU-KBA1234A/status/current ... ``` ``` -------------------------------- ### Listen to Device MQTT Messages Source: https://github.com/libdyson-wg/opendyson/blob/main/README.md Subscribe to a device's status, error, and command message topics via MQTT. Use the --iot flag to connect to the cloud-based IoT service instead of directly to the device. ```sh opendyson listen SERIALNUMBER ``` ```sh opendyson listen SERIALNUMBER --iot ``` -------------------------------- ### opendyson devices Source: https://context7.com/libdyson-wg/opendyson/llms.txt Fetches all registered devices from the Dyson cloud API, resolves their LAN IP addresses via Zeroconf mDNS, and prints full device information in YAML format. Triggers login automatically if no token is saved. ```APIDOC ## opendyson devices ### Description Fetches all registered devices from the Dyson cloud API, resolves their LAN IP addresses via Zeroconf mDNS, and prints full device information in YAML format. Triggers login automatically if no token is saved. ### Method CLI Command ### Endpoint /devices ### Response #### Success Response (200) - **devices** (array) - List of registered Dyson devices with their details including MQTT and IoT credentials. ### Response Example ```yaml Available devices: - name: Living Room Purifier serial: AB1-EU-KBA1234A model: TP07 type: 475 variant: "" productCategory: fan connectionCategory: wifiProduct mqtt: password: decryptedHashHere username: AB1-EU-KBA1234A root_topic: 475 address: 192.168.1.42 iot: endpoint: xxxxxx-ats.iot.eu-west-1.amazonaws.com client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx custom_authorizer_name: DysonMQTTAuthorizer token_key: x-amz-customauthorizer-token token_signature: base64signaturehere== token_value: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx firmware: version: 3.02.00 auto_update_enabled: true new_version_available: false ``` This is sensitive information that can be used to remotely control your Dyson devices. ``` -------------------------------- ### cloud.CompleteLogin(email, otpCode, password string, challengeID uuid.UUID) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Finalizes authentication by submitting the OTP code, password, and challenge ID. Returns a bearer token. ```APIDOC ## CompleteLogin cloud.CompleteLogin(email, otpCode, password string, challengeID uuid.UUID) ### Description Submits the OTP code, password, and challenge ID to finalize authentication. Returns a bearer token string for subsequent API calls. ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the user. - **otpCode** (string) - Required - The One-Time Password received via email. - **password** (string) - Required - The user's Dyson account password. - **challengeID** (uuid.UUID) - Required - The unique identifier for the login challenge obtained from `BeginLogin`. ### Response #### Success Response (200) - **token** (string) - A bearer token for authenticating subsequent API calls. ### Request Example ```go challengeID, _ := cloud.BeginLogin("user@example.com") token, err := cloud.CompleteLogin( "user@example.com", "123456", // OTP from email "MyP@ssword", // MyDyson account password challengeID, ) if err != nil { panic(fmt.Errorf("login failed: %w", err)) } // Persist token for future sessions _ = config.SetToken(token) // Activate token for current session cloud.SetToken(token) fmt.Println("Successfully authenticated") ``` ``` -------------------------------- ### opendyson login Source: https://context7.com/libdyson-wg/opendyson/llms.txt Authenticates with MyDyson account by prompting for region, email, OTP, and password. Persists the API bearer token to the configuration file. ```APIDOC ## opendyson login ### Description Authenticates with MyDyson account by prompting for region, email, OTP, and password. Persists the API bearer token to the configuration file. ### Method CLI Command ### Parameters #### Query Parameters - **region** (string) - Optional - Use China region for account? (Default is no) - **email** (string) - Required - Email Address - **code** (string) - Required - Code from confirmation email - **password** (string) - Required - Password ### Request Example ```sh $ opendyson login Use China region for account? (Default is no) [y/n]: n Email Address: user@example.com # Dyson sends a confirmation email with an OTP code Code from confirmation email: 123456 Password: ******** You are logged in. Please note that your Dyson API Token has been saved to /home/user/.config/libdyson/config.yml. This API Token is sensitive and should never be shared with anyone you don't trust. ``` ``` -------------------------------- ### Listen to Live MQTT Messages Source: https://context7.com/libdyson-wg/opendyson/llms.txt Subscribe to a device's status, fault, and command MQTT topics over local LAN or AWS IoT. Prints incoming messages continuously until interrupted. ```sh # Listen over local LAN MQTT (default) $ opendyson listen AB1-EU-KBA1234A Subscribing to 475/AB1-EU-KBA1234A/status/current Subscribing to 475/AB1-EU-KBA1234A/status/fault Subscribing to 475/AB1-EU-KBA1234A/command Status: {"msg":"CURRENT-PRODUCT-STATE","product-state":{"fpwr":"ON","fnsp":"0003","auto":"OFF","rhtm":"OFF",...}} Fault: {"msg":"ENVIRONMENTAL-CURRENT-SENSOR-DATA","data":{"tact":"2963","hact":"58","pact":"0","vact":"0","sltm":"OFF"}} # Listen via AWS IoT cloud broker $ opendyson listen AB1-EU-KBA1234A --iot Subscribing to 475/AB1-EU-KBA1234A/status/current ... ``` -------------------------------- ### List Dyson Devices Source: https://github.com/libdyson-wg/opendyson/blob/main/README.md Fetch and display all information about your Dyson devices from the Dyson API. This command also attempts to find device IP addresses on your local network using Zeroconf. Output is in YAML format and contains sensitive IoT credentials. ```sh opendyson devices ``` -------------------------------- ### Login to MyDyson Account Source: https://context7.com/libdyson-wg/opendyson/llms.txt Authenticate with your MyDyson account using email, OTP, and password. The API bearer token is saved to `~/.config/libdyson/config.yml`. ```sh $ opendyson login Use China region for account? (Default is no) [y/n]: n Email Address: user@example.com # Dyson sends a confirmation email with an OTP code Code from confirmation email: 123456 Password: ******** You are logged in. Please note that your Dyson API Token has been saved to /home/user/.config/libdyson/config.yml. This API Token is sensitive and should never be shared with anyone you don't trust. ``` -------------------------------- ### Interact with Connected Dyson Devices via MQTT Source: https://context7.com/libdyson-wg/opendyson/llms.txt Use the `ConnectedDevice` interface to resolve local addresses, subscribe to status updates, and send raw MQTT commands. Ensure devices are connected to Wi-Fi and discoverable on the local network. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" "github.com/libdyson-wg/opendyson/devices" ) ds, _ := cloud.GetDevices() for _, d := range ds { cd, ok := d.(devices.ConnectedDevice) if !ok { continue // skip non-connected devices } // Resolve device IP via mDNS/Zeroconf if err := cd.ResolveLocalAddress(); err != nil { fmt.Printf("Could not find %s on LAN: %v\n", d.GetSerial(), err) continue } fmt.Println("Status topic: ", cd.StatusTopic()) // e.g. 475/AB1-EU-KBA1234A/status/current fmt.Println("Command topic:", cd.CommandTopic()) // e.g. 475/AB1-EU-KBA1234A/command fmt.Println("Fault topic: ", cd.FaultTopic()) // e.g. 475/AB1-EU-KBA1234A/status/fault // Subscribe to live device status updates err := cd.SubscribeRaw(cd.StatusTopic(), func(payload []byte) { fmt.Printf("Status update: %s\n", string(payload)) }) if err != nil { panic(err) } // Switch to AWS IoT mode instead of local MQTT cd.SetMode(devices.ModeIoT) // Send a raw MQTT command message _ = cd.SendRaw(cd.CommandTopic(), []byte(`{"msg":"REQUEST-PRODUCT-ENVIRONMENT-CURRENT-SENSOR-DATA","time":"2024-01-01T00:00:00.000Z"}`)) } ``` -------------------------------- ### Fetch All Registered Dyson Devices Source: https://context7.com/libdyson-wg/opendyson/llms.txt Retrieves a slice of `devices.Device` interfaces for all devices associated with the authenticated account. Connected devices include firmware information and decrypted MQTT/IoT credentials. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" "github.com/libdyson-wg/opendyson/devices" "gopkg.in/yaml.v3" ) ds, err := cloud.GetDevices() if err != nil { panic(err) } for _, d := range ds { fmt.Printf("Device: %s (serial: %s, model: %s)\n", d.GetName(), d.GetSerial(), d.GetModel()) if d.CanConnect() { fmt.Println(" -> This device supports MQTT connection") } } // Full YAML dump (includes sensitive credentials) out, _ := yaml.Marshal(ds) fmt.Println(string(out)) ``` -------------------------------- ### List Registered Dyson Devices Source: https://context7.com/libdyson-wg/opendyson/llms.txt Fetch all registered devices from the Dyson cloud API, resolve their LAN IP addresses via Zeroconf mDNS, and print device information in YAML format. Automatically triggers login if no token is saved. ```sh $ opendyson devices Available devices: - name: Living Room Purifier serial: AB1-EU-KBA1234A model: TP07 type: 475 variant: "" productCategory: fan connectionCategory: wifiProduct mqtt: password: decryptedHashHere username: AB1-EU-KBA1234A root_topic: 475 address: 192.168.1.42 iot: endpoint: xxxxxx-ats.iot.eu-west-1.amazonaws.com client_id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx custom_authorizer_name: DysonMQTTAuthorizer token_key: x-amz-customauthorizer-token token_signature: base64signaturehere== token_value: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx firmware: version: 3.02.00 auto_update_enabled: true new_version_available: false This is sensitive information that can be used to remotely control your Dyson devices. ``` -------------------------------- ### ConnectedDevice Interface - MQTT Operations Source: https://context7.com/libdyson-wg/opendyson/llms.txt Provides methods for interacting with Wi-Fi connected Dyson devices via MQTT. This includes resolving the device's local IP address, subscribing to status updates, and sending raw MQTT commands. ```APIDOC ## `devices.ConnectedDevice` Interface — MQTT-Capable Device Operations Extended interface for Wi-Fi connected devices. Supports raw MQTT publish/subscribe, topic helpers, local address resolution, and mode switching between local LAN MQTT and AWS IoT. ### Methods - **ResolveLocalAddress()**: Resolves the device's local IP address using mDNS/Zeroconf. - **StatusTopic()**: Returns the MQTT topic for receiving device status updates. - **CommandTopic()**: Returns the MQTT topic for sending commands to the device. - **FaultTopic()**: Returns the MQTT topic for receiving fault information. - **SubscribeRaw(topic string, handler func([]byte))**: Subscribes to a given MQTT topic and processes incoming messages with a provided handler function. - **SendRaw(topic string, payload []byte)**: Sends a raw MQTT message to a specified topic. - **SetMode(mode devices.DeviceMode)**: Switches the device's communication mode (e.g., to AWS IoT or local LAN MQTT). ``` -------------------------------- ### Control Dyson Pure Hot+Cool Devices Source: https://context7.com/libdyson-wg/opendyson/llms.txt Utilize the `PureHotCool` type for high-level controls like power, fan speed, airflow direction, and mode settings. This interface simplifies common operations by translating them into specific MQTT commands. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" "github.com/libdyson-wg/opendyson/devices" ) ds, _ := cloud.GetDevices() for _, d := range ds { phc, ok := d.(*devices.PureHotCool) if !ok { continue } // Power control if err := phc.PowerOn(); err != nil { fmt.Println("PowerOn error:", err) } if err := phc.PowerOff(); err != nil { fmt.Println("PowerOff error:", err) } // Fan speed (0-10; also powers on) if err := phc.Speed(5); err != nil { fmt.Println("Speed error:", err) // "speed must be between 0 and 10" } // Auto mode _ = phc.AutoModeOn() _ = phc.AutoModeOff() // Airflow direction _ = phc.DirectionForward() _ = phc.DirectionReverse() // Night mode _ = phc.EnableNightMode() _ = phc.DisableNightMode() // Continuous air quality monitoring _ = phc.EnableContinuousMonitoring() _ = phc.DisableContinuousMonitoring() // Reset the filter change indicator _ = phc.ResetFilter() } ``` -------------------------------- ### Manage Dyson API Token Persistence Source: https://context7.com/libdyson-wg/opendyson/llms.txt Employ `config.GetToken` and `config.SetToken` to read from and write to a persistent YAML configuration file for storing the Dyson API bearer token. The file location is OS-dependent. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/internal/config" ) // Read saved token (empty string if not yet authenticated) tok, err := config.GetToken() if err != nil { panic(err) } fmt.Printf("Saved token: %q\n", tok) fmt.Printf("Config file: %s\n", config.GetFilePath()) // Save a new token after authentication if err := config.SetToken("new-bearer-token"); err != nil { panic(fmt.Errorf("could not save token: %w", err)) } ``` -------------------------------- ### RequestAddress - Resolve Device IP via Zeroconf Source: https://context7.com/libdyson-wg/opendyson/llms.txt Resolves a Dyson device's local IP address on the network using Zeroconf (mDNS). It returns a channel that will receive the IP address upon successful resolution or nil after a timeout. ```APIDOC ## `lan.RequestAddress(serial string)` — Resolve Device IP via Zeroconf The `internal/lan` package continuously browses the `_dyson_mqtt._tcp` mDNS service on startup. `RequestAddress` returns a channel that receives the resolved `net.IP` for the given device serial, or `nil` after a 10-second timeout. ### Parameters #### Path Parameters - **serial** (string) - Required - The serial number of the Dyson device. ``` -------------------------------- ### cloud.GetUserStatus(email string) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Queries the Dyson API to determine whether an account is active and eligible for login. Returns the account status. ```APIDOC ## GetUserStatus cloud.GetUserStatus(email string) ### Description Queries the Dyson API to determine whether an account is active and eligible for login. ### Parameters #### Path Parameters - **email** (string) - Required - The email address of the user. ### Response #### Success Response (200) - **status** (string) - The status of the account, either "ACTIVE" or "UNREGISTERED". ### Request Example ```go status, err := cloud.GetUserStatus("user@example.com") if err != nil { panic(err) } // status is either cloud.AccountStatusActive ("ACTIVE") // or cloud.AccountStatusUnregistered ("UNREGISTERED") if status != cloud.AccountStatusActive { fmt.Printf("Account is not active: %s\n", status) } ``` ``` -------------------------------- ### PureHotCool Device Controls Source: https://context7.com/libdyson-wg/opendyson/llms.txt High-level control methods for Dyson Pure Hot+Cool fan/purifier models. These methods abstract away the underlying MQTT messages for common operations like power, fan speed, and mode settings. ```APIDOC ## `devices.PureHotCool` — Device Type with High-Level Controls `PureHotCool` embeds `BaseConnectedDevice` and adds typed control methods for Dyson Pure Hot+Cool fan/purifier models (HP series). Each method translates to a `Set()` call with the appropriate MQTT setting key/value pair. ### Methods - **PowerOn()**: Turns the device on. - **PowerOff()**: Turns the device off. - **Speed(speed int)**: Sets the fan speed (0-10). This also powers on the device. - **AutoModeOn()**: Enables automatic mode. - **AutoModeOff()**: Disables automatic mode. - **DirectionForward()**: Sets the airflow direction to forward. - **DirectionReverse()**: Sets the airflow direction to reverse. - **EnableNightMode()**: Enables night mode. - **DisableNightMode()**: Disables night mode. - **EnableContinuousMonitoring()**: Enables continuous air quality monitoring. - **DisableContinuousMonitoring()**: Disables continuous air quality monitoring. - **ResetFilter()**: Resets the filter change indicator. ``` -------------------------------- ### Config - Persistent Token Storage Source: https://context7.com/libdyson-wg/opendyson/llms.txt Provides functions to manage the Dyson API bearer token, allowing it to be read from and written to a persistent configuration file. ```APIDOC ## `config.GetToken()` / `config.SetToken()` — Persistent Token Storage Reads and writes the Dyson API bearer token from/to a YAML config file at the OS user config directory (e.g., `~/.config/libdyson/config.yml` on Linux, `~/Library/Application Support/libdyson/config.yml` on macOS). ### Methods - **GetToken()**: Reads the stored bearer token from the configuration file. Returns an empty string if no token is found. - **SetToken(token string)**: Writes the provided bearer token to the configuration file. - **GetFilePath()**: Returns the absolute path to the configuration file. ``` -------------------------------- ### Resolve Dyson Device IP Address via Zeroconf Source: https://context7.com/libdyson-wg/opendyson/llms.txt Use `lan.RequestAddress` to find the local IP address of a Dyson device using its serial number. This function returns a channel that provides the IP address upon successful resolution or after a 10-second timeout. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/internal/lan" ) ch := lan.RequestAddress("AB1-EU-KBA1234A") ip := <-ch // blocks until resolved or 10s timeout if ip == nil { fmt.Println("Device not found on local network") } else { fmt.Printf("Device IP: %s\n", ip.String()) // e.g. 192.168.1.42 } ``` -------------------------------- ### cloud.SetServerRegion(region cloud.ServerRegion) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Selects the API region, switching the cloud API client between the global endpoint and the China endpoint. Must be called before any API operations if targeting a China-region account. ```APIDOC ## cloud.SetServerRegion(region cloud.ServerRegion) ### Description Selects the API region, switching the cloud API client between the global endpoint (`https://appapi.cp.dyson.com`) and the China endpoint (`https://appapi.cp.dyson.cn`). Must be called before any API operations if targeting a China-region account. ### Method Go Library Function ### Parameters #### Path Parameters - **region** (cloud.ServerRegion) - Required - The server region to use. ### Request Example ```go import "github.com/libdyson-wg/opendyson/cloud" // Use China region cloud.SetServerRegion(cloud.RegionChina) // Use global region (default) cloud.SetServerRegion(cloud.RegionGlobal) ``` ``` -------------------------------- ### cloud.GetDeviceIoT(serial string) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Retrieves AWS IoT endpoint and custom authorizer credentials for a specific device by serial number. ```APIDOC ## GetDeviceIoT cloud.GetDeviceIoT(serial string) ### Description Retrieves AWS IoT endpoint and custom authorizer credentials for a specific device by serial number. These credentials allow connecting via the Dyson cloud MQTT broker (WebSocket over TLS). ### Parameters #### Path Parameters - **serial** (string) - Required - The serial number of the device. ### Response #### Success Response (200) - **iot** (object) - An object containing IoT credentials. - **Endpoint** (string) - The AWS IoT endpoint. - **ClientID** (string) - The client ID for the IoT connection. - **TokenKey** (string) - The custom authorizer token key. ### Request Example ```go iot, err := cloud.GetDeviceIoT("AB1-EU-KBA1234A") if err != nil { panic(err) } fmt.Printf("IoT Endpoint: %s\n", iot.Endpoint) fmt.Printf("Client ID: %s\n", iot.ClientID) fmt.Printf("Token Key: %s\n", iot.TokenKey) // wss://iot.Endpoint/mqtt — connect with X-Amz-CustomAuthorizer-* headers ``` ``` -------------------------------- ### Check Dyson Account Status Source: https://context7.com/libdyson-wg/opendyson/llms.txt Queries the Dyson API to determine if an account is active and eligible for login. The status can be either `cloud.AccountStatusActive` or `cloud.AccountStatusUnregistered`. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" ) status, err := cloud.GetUserStatus("user@example.com") if err != nil { panic(err) } // status is either cloud.AccountStatusActive ("ACTIVE") // or cloud.AccountStatusUnregistered ("UNREGISTERED") if status != cloud.AccountStatusActive { fmt.Printf("Account is not active: %s\n", status) } ``` -------------------------------- ### Fetch AWS IoT Credentials for a Dyson Device Source: https://context7.com/libdyson-wg/opendyson/llms.txt Retrieves the AWS IoT endpoint and custom authorizer credentials for a specific device using its serial number. These are used for connecting to the Dyson cloud MQTT broker via WebSocket over TLS. ```go import ( "fmt" "github.com/libdyson-wg/opendyson/cloud" ) iot, err := cloud.GetDeviceIoT("AB1-EU-KBA1234A") if err != nil { panic(err) } fmt.Printf("IoT Endpoint: %s\n", iot.Endpoint) fmt.Printf("Client ID: %s\n", iot.ClientID) fmt.Printf("Token Key: %s\n", iot.TokenKey) // wss://iot.Endpoint/mqtt — connect with X-Amz-CustomAuthorizer-* headers ``` -------------------------------- ### Select Dyson Cloud API Region Source: https://context7.com/libdyson-wg/opendyson/llms.txt Switch the cloud API client between the global and China endpoints. Must be called before any API operations if targeting a China-region account. ```go import "github.com/libdyson-wg/opendyson/cloud" // Use China region cloud.SetServerRegion(cloud.RegionChina) // Use global region (default) cloud.SetServerRegion(cloud.RegionGlobal) ``` -------------------------------- ### Set Dyson API Bearer Token Source: https://context7.com/libdyson-wg/opendyson/llms.txt Manually set the API bearer token for subsequent Dyson cloud API requests. This is automatically handled at startup from the persisted config. ```go package main import "github.com/libdyson-wg/opendyson/cloud" func main() { // Manually inject a token (e.g., obtained externally) cloud.SetToken("your-dyson-api-bearer-token") } ``` -------------------------------- ### cloud.SetToken(token string) Source: https://context7.com/libdyson-wg/opendyson/llms.txt Sets the API bearer token used for all subsequent Dyson cloud API requests. This is called automatically at startup from the persisted config. ```APIDOC ## cloud.SetToken(token string) ### Description Sets the API bearer token used for all subsequent Dyson cloud API requests. This is called automatically at startup from the persisted config. ### Method Go Library Function ### Parameters #### Path Parameters - **token** (string) - Required - The API bearer token. ### Request Example ```go package main import "github.com/libdyson-wg/opendyson/cloud" func main() { // Manually inject a token (e.g., obtained externally) cloud.SetToken("your-dyson-api-bearer-token") } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.