rename_device
Change the friendly name of a WeMo smart home device to update how it appears in the WeMo app and for identification. Provide the device's current name or IP address and specify the new name.
Instructions
Rename a WeMo device (change its friendly name).
Changes the friendly name of a WeMo device. This is the name that appears in the WeMo app and is used to identify the device. The device must have been discovered via scan_network first.
After renaming, the device cache will be updated with the new name. You may want to run scan_network again to refresh the device list.
Args:
device_identifier: Current device name (e.g., "Office Dimmer") or IP address (e.g., "192.168.1.100")
new_name: New friendly name for the device (e.g., "Office Light")Returns:
Dictionary containing:
- success: Boolean indicating if the rename succeeded
- old_name: The previous name of the device
- new_name: The new name of the device
- device_ip: IP address of the deviceInput Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device_identifier | Yes | ||
| new_name | Yes |
Implementation Reference
- src/wemo_mcp_server/server.py:1083-1192 (handler)The rename_device function handles the logic for renaming a WeMo device. It validates inputs, ensures the device is accessible via cache, performs the actual rename operation using pywemo's rename methods, and updates the cache.
async def rename_device(device_identifier: str, new_name: str) -> dict[str, Any]: """Rename a WeMo device (change its friendly name). Changes the friendly name of a WeMo device. This is the name that appears in the WeMo app and is used to identify the device. The device must have been discovered via scan_network first. After renaming, the device cache will be updated with the new name. You may want to run scan_network again to refresh the device list. Args: ---- device_identifier: Current device name (e.g., "Office Dimmer") or IP address (e.g., "192.168.1.100") new_name: New friendly name for the device (e.g., "Office Light") Returns: ------- Dictionary containing: - success: Boolean indicating if the rename succeeded - old_name: The previous name of the device - new_name: The new name of the device - device_ip: IP address of the device """ # Validate inputs try: params = RenameDeviceParams( device_identifier=device_identifier, new_name=new_name, ) except ValidationError as e: return { "error": ERR_INVALID_PARAMS, "validation_errors": [ {"field": err["loc"][0], "message": err["msg"], "input": err["input"]} for err in e.errors() ], "success": False, } try: # Try to find device in memory cache, then reconnect from file cache if needed device = _device_cache.get(params.device_identifier) if not device: device = await _reconnect_device_from_cache(params.device_identifier) if not device: return { "error": f"Device '{params.device_identifier}' not found in cache", "suggestion": ERR_RUN_SCAN_FIRST, "available_devices": [ k for k in _device_cache if isinstance(k, str) and not k.replace(".", "").isdigit() ], "success": False, } old_name = device.name device_ip = getattr(device, "host", "unknown") # Perform the rename operation in a thread pool loop = asyncio.get_event_loop() # Try both methods for compatibility with different pywemo versions def rename_operation(): if hasattr(device, "change_friendly_name"): device.change_friendly_name(params.new_name) elif hasattr(device, "basicevent"): device.basicevent.ChangeFriendlyName(FriendlyName=params.new_name) else: raise AttributeError("Device does not support renaming") await loop.run_in_executor(None, rename_operation) # Wait a moment for the device to respond await asyncio.sleep(0.5) # Update the cache with the new name # Remove old name entry and add new one _device_cache.pop(old_name, None) _device_cache[params.new_name] = device # Also update IP-based cache entry if it exists if device_ip in _device_cache: _device_cache[device_ip] = device result = { "success": True, "old_name": old_name, "new_name": params.new_name, "device_ip": device_ip, "message": f"Device renamed from '{old_name}' to '{params.new_name}'", "timestamp": time.time(), } logger.info(f"Device renamed: '{old_name}' -> '{params.new_name}' at {device_ip}") return result except Exception as e: logger.error(f"Error renaming device: {e}", exc_info=True) return build_error_response( e, "Rename device", context={ "device_identifier": device_identifier, "new_name": new_name, }, )