### Extract WiFi Credentials for Offline Setup Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Extracts MQTT credentials directly from device WiFi information. Useful for offline setup by parsing the device's WiFi SSID and password from its label. Handles different SSID formats for standard devices and 360 Eye vacuums. ```python from libdyson import get_mqtt_info_from_wifi_info, get_device from libdyson.exceptions import DysonFailedToParseWifiInfo # WiFi info from device label wifi_ssid = "DYSON-ABC-US-12345678-438" # Format: DYSON-{serial}-{type} wifi_password = "aBcDeFgH" # 8-character password from device try: serial, credential, device_type = get_mqtt_info_from_wifi_info( wifi_ssid, wifi_password ) print(f"Serial: {serial}") # ABC-US-12345678 print(f"Type: {device_type}") # 438 print(f"Credential: {credential[:20]}...") # SHA512 hash base64 encoded # Create and connect device device = get_device(serial, credential, device_type) device.connect("192.168.1.100") # Device IP address except DysonFailedToParseWifiInfo: print("Could not parse WiFi SSID format") # 360 Eye vacuum has different SSID format vacuum_ssid = "ABC-US-12345678" # No DYSON prefix for 360 Eye vacuum_password = "aBcDeFgH" serial, credential, device_type = get_mqtt_info_from_wifi_info( vacuum_ssid, vacuum_password ) # device_type will be "N223" (DEVICE_TYPE_360_EYE) ``` -------------------------------- ### Get Dyson Device Instance Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Use `get_device` to obtain the correct device class instance based on serial, credential, and device type. Handles unknown device types gracefully. ```python from libdyson import get_device # Example usage (assuming serial, credential, device_type are obtained elsewhere) device = get_device(serial, credential, device_type) if device is None: print(f"Unknown device type: {device_type}") else: print(f"Created {type(device).__name__} instance") ``` -------------------------------- ### Cleaning Controls for Dyson360Eye Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Start, pause, resume, and abort cleaning cycles. The robot will return to its dock after aborting. ```python # Cleaning controls device.start() # Start immediate full clean device.pause() # Pause cleaning device.resume() # Resume paused cleaning device.abort() # Abort and return to dock ``` -------------------------------- ### Retrieve and Print Device Information Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Fetches a list of devices associated with an account and iterates through them to print basic information, version details, and product type. It also demonstrates how to obtain the device type code for MQTT and create a device instance. ```python devices = account.devices() for info in devices: # Basic device info print(f"Name: {info.name}") print(f"Serial: {info.serial}") print(f"Active: {info.active}") # Version info print(f"Firmware: {info.version}") print(f"Update available: {info.new_version_available}") print(f"Auto-update: {info.auto_update}") # Type information print(f"Cloud product type: {info.product_type}") print(f"Variant: {info.variant}") # E, K, M variants # Get internal device type code for MQTT device_type = info.get_device_type() print(f"Device type code: {device_type}") # Create device instance using info device = get_device( info.serial, info.credential, # Automatically decrypted device_type ) if device: print(f"Created: {type(device).__name__}") ``` -------------------------------- ### Discover Dyson Devices on Local Network Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Utilize DysonDiscovery with Zeroconf/mDNS to find Dyson fans and vacuums. Register a callback to handle discovered devices and connect to them. ```python from libdyson import DysonDiscovery, get_device import threading # Create discovery instance discovery = DysonDiscovery() # Event to signal when device is found device_found = threading.Event() device_ip = None def on_device_discovered(ip_address): global device_ip device_ip = ip_address print(f"Device found at: {ip_address}") device_found.set() # Create device instance (credentials from cloud API) serial = "ABC-US-12345678" credential = "base64_credential_from_cloud" device_type = "438" # Pure Cool device = get_device(serial, credential, device_type) # Register device for discovery discovery.register_device(device, on_device_discovered) # Start discovery (optionally pass existing Zeroconf instance) discovery.start_discovery() # Wait for device to be found (with timeout) if device_found.wait(timeout=30): print(f"Connecting to device at {device_ip}") device.connect(device_ip) else: print("Device not found on network") # Cleanup when done discovery.stop_discovery() ``` -------------------------------- ### Handle Device Connection and Command Exceptions Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Use try-except blocks to manage potential issues during device connection, such as timeouts or invalid credentials, and command execution, like sending commands to a disconnected device. ```python from libdyson import get_device from libdyson.cloud import DysonAccount from libdyson.exceptions import ( # Cloud API exceptions DysonNetworkError, # Network connectivity issue DysonServerError, # Dyson server 5xx error DysonInvalidAuth, # Invalid credentials (401/403) DysonAuthRequired, # Not logged in DysonLoginFailure, # OTP/password incorrect DysonOTPTooFrequently, # Rate limited (429) DysonInvalidAccountStatus, # Account not active DysonAPIProvisionFailure, # API provisioning failed # MQTT/Device exceptions DysonConnectTimeout, # Connection timed out DysonConnectionRefused, # MQTT refused connection DysonInvalidCredential, # Wrong MQTT password DysonNotConnected, # Command sent while disconnected DysonFailedToParseWifiInfo, # Invalid WiFi SSID format ) # Device connection error handling device = get_device("ABC-US-12345678", "credential", "438") try: device.connect("192.168.1.100") except DysonConnectTimeout: print("Device not reachable - check IP and network") except DysonInvalidCredential: print("Wrong credential - re-fetch from cloud API") except DysonConnectionRefused: print("Device refused connection - may be in use") # Command error handling try: device.turn_on() except DysonNotConnected: print("Must connect() before sending commands") ``` -------------------------------- ### Initialize DysonAccount with Saved Authentication Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Restore a previous authentication session by initializing DysonAccount with saved auth_info. This avoids the need to re-authenticate on subsequent runs. ```python from libdyson.cloud import DysonAccount from libdyson import get_device account = DysonAccount(auth_info=saved_auth) # Restore previous auth ``` -------------------------------- ### Initialize and Connect DysonPurifierHumidifyCool Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Initialize and connect to a Dyson Purifier Humidify+Cool device. Requires serial, credential, device type, and IP address. ```python from libdyson import get_device from libdyson.const import HumidifyOscillationMode, WaterHardness serial = "ABC-US-12345678" credential = "mqtt_credential" device_type = "358" device = get_device(serial, credential, device_type) device.connect("192.168.1.100") ``` -------------------------------- ### Instantiate Dyson Device with get_device Factory Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Use the get_device factory function to create the correct Dyson device class instance based on its type code. Maps type codes to specific implementations. ```python from libdyson import get_device, DEVICE_TYPE_NAMES # Device type constants from libdyson.const import ( DEVICE_TYPE_360_EYE, # "N223" DEVICE_TYPE_360_HEURIST, # "276" DEVICE_TYPE_360_VIS_NAV, # "277" DEVICE_TYPE_PURE_COOL, # "438" - TP04/TP07/TP09 DEVICE_TYPE_PURE_HOT_COOL, # "527" - HP04/HP07/HP09 DEVICE_TYPE_PURE_HUMIDIFY_COOL, # "358" - PH01/PH02/PH03 DEVICE_TYPE_PURE_COOL_LINK, # "475" - TP02 DEVICE_TYPE_PURE_HOT_COOL_LINK, # "455" - HP02 DEVICE_TYPE_PURIFIER_BIG_QUIET, # "664" - BP02/BP03/BP04 ) # Get device name for display device_type = "438" print(f"Device: {DEVICE_TYPE_NAMES.get(device_type, 'Unknown')}") # Output: Device: Pure Cool Series (TP04/TP07/TP09/TP11/PC1) # Create device instance serial = "ABC-US-12345678" credential = "mqtt_credential_base64" ``` -------------------------------- ### Subscribe to Device Status Updates Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Register a message listener to receive real-time updates for device state and environmental sensor data. Ensure the listener is added before connecting to the device. ```python from libdyson import get_device from libdyson.const import MessageType, ENVIRONMENTAL_OFF, ENVIRONMENTAL_INIT device = get_device("ABC-US-12345678", "credential", "438") def handle_update(message_type): if message_type == MessageType.STATE: # Device state changed (power, speed, mode, etc.) print("=== Device State ===") print(f"Power: {'ON' if device.is_on else 'OFF'}") print(f"Fan running: {device.fan_state}") print(f"Speed: {device.speed}") # None if auto print(f"Auto mode: {device.auto_mode}") print(f"Oscillation: {device.oscillation}") print(f"Night mode: {device.night_mode}") print(f"Connected: {device.is_connected}") elif message_type == MessageType.ENVIRONMENTAL: # Sensor data updated print("=== Environmental Data ===") # Handle special sensor values temp = device.temperature if temp == ENVIRONMENTAL_OFF: print("Temperature sensor: OFF") elif temp == ENVIRONMENTAL_INIT: print("Temperature sensor: Initializing") elif temp is not None: celsius = temp - 273.15 print(f"Temperature: {celsius:.1f}C") humidity = device.humidity if humidity not in [ENVIRONMENTAL_OFF, ENVIRONMENTAL_INIT]: print(f"Humidity: {humidity}%") # Formaldehyde (if supported) if device.formaldehyde is not None: print(f"HCHO: {device.formaldehyde} mg/m3") print(f"Sleep timer: {device.sleep_timer} min") # Register listener before connecting device.add_message_listener(handle_update) device.connect("192.168.1.100") # Manually request data refresh device.request_current_status() device.request_environmental_data() # Later: remove listener device.remove_message_listener(handle_update) ``` -------------------------------- ### Initialize and Connect Dyson360Eye Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Initialize and connect to a Dyson 360 Eye robot vacuum. Requires serial, credential, device type, and IP address. ```python from libdyson import get_device from libdyson.const import VacuumState, VacuumEyePowerMode, CleaningType serial = "ABC-US-12345678" credential = "mqtt_credential" device_type = "N223" # 360 Eye device = get_device(serial, credential, device_type) device.connect("192.168.1.100") ``` -------------------------------- ### Handle Cloud API Exceptions Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Implement try-except blocks to gracefully handle network issues, server errors, authentication problems, and rate limiting during cloud API interactions. ```python from libdyson import get_device from libdyson.cloud import DysonAccount from libdyson.exceptions import ( # Cloud API exceptions DysonNetworkError, # Network connectivity issue DysonServerError, # Dyson server 5xx error DysonInvalidAuth, # Invalid credentials (401/403) DysonAuthRequired, # Not logged in DysonLoginFailure, # OTP/password incorrect DysonOTPTooFrequently, # Rate limited (429) DysonInvalidAccountStatus, # Account not active DysonAPIProvisionFailure, # API provisioning failed # MQTT/Device exceptions DysonConnectTimeout, # Connection timed out DysonConnectionRefused, # MQTT refused connection DysonInvalidCredential, # Wrong MQTT password DysonNotConnected, # Command sent while disconnected DysonFailedToParseWifiInfo, # Invalid WiFi SSID format ) # Cloud API error handling account = DysonAccount() try: verify = account.login_email_otp("user@example.com", "US") auth = verify("123456", "password") devices = account.devices() except DysonNetworkError: print("Check internet connection") except DysonServerError: print("Dyson servers unavailable, try again later") except DysonOTPTooFrequently: print("Wait a few minutes before requesting new OTP") except DysonLoginFailure: print("Incorrect OTP code or password") except DysonInvalidAuth: print("Session expired, re-authenticate") ``` -------------------------------- ### Initialize and Connect Dyson360Heurist Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Initialize and connect to a Dyson 360 Heurist robot vacuum. Requires serial, credential, device type, and IP address. ```python from libdyson import get_device from libdyson.const import VacuumHeuristPowerMode, CleaningMode serial = "ABC-US-12345678" credential = "mqtt_credential" device_type = "276" # 360 Heurist device = get_device(serial, credential, device_type) device.connect("192.168.1.100") ``` -------------------------------- ### Basic Fan Controls for DysonPurifierHumidifyCool Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Control basic fan settings like turning on and setting speed. Inherited from Pure Cool functionality. ```python # Fan controls (inherited from Pure Cool) device.turn_on() device.set_speed(3) ``` -------------------------------- ### Focus Mode and Disconnect for Dyson Devices Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Control focus mode and disconnect the device. Ensure the device object is properly initialized before use. ```python print(f"Focus mode: {device.focus_mode}") # Disable heating (fan only) device.disable_heat_mode() device.disconnect() ``` -------------------------------- ### Authenticate with Dyson Cloud API Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Use DysonAccount for global authentication and DysonAccountCN for China region. Requires email/mobile and OTP verification. Retrieves device credentials for local MQTT. ```python from libdyson.cloud import DysonAccount from libdyson.cloud.account import DysonAccountCN from libdyson.exceptions import DysonOTPTooFrequently, DysonLoginFailure # Global authentication (outside China) account = DysonAccount() email = "user@example.com" region = "US" # Country code try: # Initiates OTP code email - returns verification callback verify = account.login_email_otp(email, region) # User receives OTP code via email otp_code = "123456" password = "your_dyson_password" # Complete authentication auth_info = verify(otp_code, password) print(f"Authenticated! Token type: {auth_info.get('tokenType')}") # Retrieve all devices linked to account devices = account.devices() for device in devices: print(f"Device: {device.name}") print(f" Serial: {device.serial}") print(f" Type: {device.product_type}") print(f" Credential: {device.credential}") # Used for MQTT auth except DysonOTPTooFrequently: print("OTP requested too frequently, wait before retrying") except DysonLoginFailure: print("Invalid OTP or password") # China region authentication account_cn = DysonAccountCN() mobile = "+8613800138000" verify = account_cn.login_mobile_otp(mobile) auth_info = verify("123456") # Only OTP required for China ``` -------------------------------- ### Cleaning Modes for Dyson360Heurist Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Configure and check the current and default cleaning modes, including global and zone cleaning. ```python # Cleaning modes print(f"Current cleaning mode: {device.current_cleaning_mode}") print(f"Default cleaning mode: {device.default_cleaning_mode}") # CleaningMode.GLOBAL - full house # CleaningMode.ZONE_CONFIGURED - selected zones # Start all-zone cleaning device.start_all_zones() # Standard controls device.pause() device.resume() device.abort() ``` -------------------------------- ### Oscillation Modes for DysonPurifierHumidifyCool Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Set various oscillation modes, including fixed degrees, breeze, and custom. Check the current mode after setting. ```python # Oscillation modes specific to humidifier device.enable_oscillation(HumidifyOscillationMode.DEGREE_45) device.enable_oscillation(HumidifyOscillationMode.DEGREE_90) device.enable_oscillation(HumidifyOscillationMode.BREEZE) # Variable device.enable_oscillation(HumidifyOscillationMode.CUST) # Custom print(f"Oscillation mode: {device.oscillation_mode}") ``` -------------------------------- ### Humidification Control for DysonPurifierHumidifyCool Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Enable, disable, and set humidity targets for the device. Supports both manual and automatic modes. ```python # Humidification control device.enable_humidification() print(f"Humidifying: {device.humidification}") # Manual humidity target (percentage) device.set_target_humidity(50) # Auto mode disabled print(f"Target humidity: {device.target_humidity}%") # Auto humidity mode device.enable_humidification_auto_mode() print(f"Auto mode: {device.humidification_auto_mode}") print(f"Auto target: {device.auto_target_humidity}%") device.disable_humidification_auto_mode() device.disable_humidification() ``` -------------------------------- ### Water Hardness and Deep Cleaning for DysonPurifierHumidifyCool Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Set the water hardness level, which influences deep cleaning frequency. Monitor deep cleaning status. ```python # Water hardness setting (affects deep clean frequency) device.set_water_hardness(WaterHardness.SOFT) device.set_water_hardness(WaterHardness.MEDIUM) device.set_water_hardness(WaterHardness.HARD) print(f"Water hardness: {device.water_hardness}") # Deep cleaning status print(f"Hours until next clean: {device.time_until_next_clean}") print(f"Clean time remaining: {device.clean_time_remaining} minutes") ``` -------------------------------- ### Status Monitoring for Dyson360Eye Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Check the current state, battery level, charging status, and position of the robot vacuum. ```python # Check current state print(f"State: {device.state}") print(f"Battery: {device.battery_level}%") print(f"Charging: {device.is_charging}") print(f"Position: {device.position}") # (x, y) tuple or None # State examples if device.state == VacuumState.INACTIVE_CHARGED: print("Ready to clean") elif device.state == VacuumState.FULL_CLEAN_RUNNING: print("Currently cleaning") elif device.state == VacuumState.FAULT_USER_RECOVERABLE: print("Needs user intervention") ``` -------------------------------- ### Control Dyson Pure Hot+Cool Heater Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Controls Dyson Pure Hot+Cool heaters, inheriting all Pure Cool features and adding heating capabilities. Allows setting target temperatures and monitoring heating status. Temperature is set in Kelvin. ```python from libdyson import get_device serial = "ABC-US-12345678" credential = "mqtt_credential" device_type = "527" # Pure Hot+Cool device = get_device(serial, credential, device_type) device.connect("192.168.1.100") # All Pure Cool features available (turn_on, set_speed, oscillation, etc.) device.turn_on() device.set_speed(5) # Heating controls device.enable_heat_mode() print(f"Heat mode active: {device.heat_mode_is_on}") print(f"Currently heating: {device.heat_status_is_on}") # Set target temperature (in Kelvin, 274-310K = 1-37C) target_celsius = 22 target_kelvin = target_celsius + 273.15 device.set_heat_target(target_kelvin) # Sets heat mode ON + target print(f"Heat target: {device.heat_target - 273.15:.1f}C") ``` -------------------------------- ### Heurist-Specific Features for Dyson360Heurist Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Check specific features like bin fullness for the Heurist model. ```python # Heurist-specific features print(f"Bin full: {device.is_bin_full}") ``` -------------------------------- ### Cleaning Information for Dyson360Eye Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Retrieve details about the current cleaning session, including type and ID. ```python # Cleaning info if device.cleaning_type: print(f"Clean type: {device.cleaning_type}") # immediate, manual, scheduled print(f"Cleaning ID: {device.cleaning_id}") ``` -------------------------------- ### Power Modes for Dyson360Eye Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Set the power mode for cleaning operations. Options include QUIET and MAX. ```python # Power modes print(f"Current power: {device.power_mode}") device.set_power_mode(VacuumEyePowerMode.QUIET) # "halfPower" device.set_power_mode(VacuumEyePowerMode.MAX) # "fullPower" ``` -------------------------------- ### Basic Status for Dyson360Heurist Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Retrieve basic status information including state, battery level, and position. This is inherited from the base vacuum class. ```python # Basic status (inherited) print(f"State: {device.state}") print(f"Battery: {device.battery_level}%") print(f"Position: {device.position}") ``` -------------------------------- ### Power Modes for Dyson360Heurist Robot Vacuum Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Set the default power mode for cleaning. Heurist offers more options than the Eye model. ```python # Power modes (more options than Eye) print(f"Current power: {device.current_power_mode}") print(f"Default power: {device.default_power_mode}") device.set_default_power_mode(VacuumHeuristPowerMode.QUIET) # "1" device.set_default_power_mode(VacuumHeuristPowerMode.HIGH) # "2" device.set_default_power_mode(VacuumHeuristPowerMode.MAX) # "3" ``` -------------------------------- ### Control Dyson Pure Cool Fan Source: https://context7.com/libdyson-wg/libdyson-neon/llms.txt Controls Dyson Pure Cool air purifiers (TP04, TP07, TP09, TP11). Supports fan speed, oscillation with angle control, auto mode, front airflow direction, night mode, sleep timers, and continuous monitoring. Requires adding a message listener for status updates. ```python from libdyson import get_device from libdyson.const import MessageType serial = "ABC-US-12345678" credential = "mqtt_credential" device_type = "438" device = get_device(serial, credential, device_type) # Add status change callback def on_status_change(message_type): if message_type == MessageType.STATE: print(f"Fan on: {device.is_on}, Speed: {device.speed}") elif message_type == MessageType.ENVIRONMENTAL: print(f"Temperature: {(device.temperature - 273.15):.1f}C") print(f"Humidity: {device.humidity}%") print(f"PM2.5: {device.particulate_matter_2_5} ug/m3") print(f"PM10: {device.particulate_matter_10} ug/m3") print(f"VOC Index: {device.volatile_organic_compounds}") print(f"NO2 Index: {device.nitrogen_dioxide}") device.add_message_listener(on_status_change) device.connect("192.168.1.100") # Basic controls device.turn_on() device.set_speed(5) # Speed 1-10 device.turn_off() # Auto mode device.enable_auto_mode() device.disable_auto_mode() # Oscillation with angle control device.enable_oscillation(angle_low=45, angle_high=270) # Custom angles device.enable_oscillation() # Use current angles device.disable_oscillation() # Read oscillation angles print(f"Oscillation: {device.oscillation}") print(f"Angle range: {device.oscillation_angle_low} - {device.oscillation_angle_high}") # Airflow direction device.enable_front_airflow() # Jet focus device.disable_front_airflow() # Diffused mode # Night mode (quieter operation) device.enable_night_mode() print(f"Night mode speed: {device.night_mode_speed}") # Sleep timer (1-540 minutes) device.set_sleep_timer(60) device.disable_sleep_timer() # Continuous monitoring (sensors active when fan off) device.enable_continuous_monitoring() # Filter status print(f"HEPA filter: {device.hepa_filter_life}%") print(f"Carbon filter: {device.carbon_filter_life}%") # None if not applicable device.reset_filter() # Reset filter life counter # Error/warning codes print(f"Error: {device.error_code}, Warning: {device.warning_code}") # Cleanup device.remove_message_listener(on_status_change) device.disconnect() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.