Skip to main content
Glama
madorn
by madorn

get_device_state

Retrieve the current operational status of a Bond Bridge smart home device, including power state, speed, and direction settings.

Instructions

Get current state of a Bond device.

Args: device_id: The Bond device identifier

Returns: Current device state including power, speed, direction, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
device_idYes

Implementation Reference

  • The FastMCP tool handler for 'get_device_state', registered via @mcp.tool(). It creates a BondClient instance, calls get_device_state on it, and returns the state wrapped with the device_id or an error.
    @mcp.tool()
    async def get_device_state(device_id: str) -> Dict[str, Any]:
        """Get current state of a Bond device.
        
        Args:
            device_id: The Bond device identifier
            
        Returns:
            Current device state including power, speed, direction, etc.
        """
        try:
            async with await get_bond_client() as client:
                state = await client.get_device_state(device_id)
                return {
                    "device_id": device_id,
                    "state": state
                }
        except BondAPIError as e:
            return {"error": f"Failed to get device state: {str(e)}"}
        except Exception as e:
            logger.error(f"Unexpected error getting device state: {e}")
            return {"error": f"Unexpected error: {str(e)}"}
  • BondClient helper method that performs the actual HTTP GET request to the Bond Bridge API endpoint /v2/devices/{device_id}/state to retrieve the raw device state.
    async def get_device_state(self, device_id: str) -> Dict[str, Any]:
        """Get current state of a device.
        
        Args:
            device_id: Device identifier
            
        Returns:
            Device state
        """
        return await self._request("GET", f"devices/{device_id}/state")
  • Pydantic model defining the structure and validation for Bond device states, relevant to the output of get_device_state.
    class DeviceState(BaseModel):
        """Device state model."""
        power: Optional[int] = None  # 0 = off, 1 = on
        speed: Optional[int] = None  # Fan speed (0-8)
        direction: Optional[int] = None  # Fan direction (1 = forward, -1 = reverse)
        brightness: Optional[int] = None  # Light brightness (0-100)
        position: Optional[int] = None  # Shade position (0-100)
        timer: Optional[int] = None  # Timer in seconds
        
        @validator('speed')
        def validate_speed(cls, v):
            if v is not None and not (0 <= v <= 8):
                raise ValueError('Speed must be between 0 and 8')
            return v
        
        @validator('brightness', 'position')
        def validate_percentage(cls, v):
            if v is not None and not (0 <= v <= 100):
                raise ValueError('Value must be between 0 and 100')
            return v
        
        @validator('direction')
        def validate_direction(cls, v):
            if v is not None and v not in [-1, 1]:
                raise ValueError('Direction must be -1 (reverse) or 1 (forward)')
            return v

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/madorn/bond-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server