set_property
Set device properties to control smart home appliances. Change power, brightness, temperature, and more using device ID, property name, and value.
Instructions
设置设备属性值,用于控制设备。例如开灯、调亮度、设温度等。
Args:
did: 设备ID
prop_name: 属性名称,如 power、brightness、temperature
value: 属性值,类型取决于属性定义。常见值:power 为 "on"/"off",brightness 为 0-100,temperature 为数字Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| did | Yes | ||
| prop_name | Yes | ||
| value | Yes |
Implementation Reference
- mcp_server/server.py:72-81 (handler)MCP tool handler for 'set_property'. Defined as an async function decorated with @mcp.tool(). Sends an HTTP PUT request to /devices/{did}/props/{prop_name} with the value as JSON body. This is the primary entry point exposed to MCP clients.
@mcp.tool() async def set_property(did: str, prop_name: str, value) -> dict: """设置设备属性值,用于控制设备。例如开灯、调亮度、设温度等。 Args: did: 设备ID prop_name: 属性名称,如 power、brightness、temperature value: 属性值,类型取决于属性定义。常见值:power 为 "on"/"off",brightness 为 0-100,temperature 为数字 """ return await _request("PUT", f"/devices/{quote(did)}/props/{prop_name}", json_data={"value": value}) - app/services/device_service.py:177-183 (handler)Core service-layer implementation of set_property. Uses the MiJia API to call device.set(prop_name, value) with timeout support, then emits a property_change event via WebSocket. Returns a dict with did, prop_name, and value.
@staticmethod def set_property(user_id: int, did: str, prop_name: str, value, timeout=MIJIA_CALL_TIMEOUT) -> dict: api = api_pool.get_api(user_id) device = mijiaDevice(api, did=did) _call_with_timeout(device.set, prop_name, value, timeout=timeout) _emit_device_update(user_id, did, "property_change", {"prop_name": prop_name, "value": value}) return {"did": did, "prop_name": prop_name, "value": value} - app/api/devices.py:237-284 (handler)Flask REST API handler for PUT /devices/<did>/props/<prop_name>. Validates input with SetPropertySchema, calls DeviceService.set_property, and handles errors (DeviceSetError, TimeoutError).
@devices_ns.route("/<did>/props/<prop_name>", methods=["PUT"]) @auth_required @limiter.limit("30 per minute") def set_property(did, prop_name): """设置设备属性值 --- tags: - 设备 security: - cookieAuth: [] - bearerAuth: [] parameters: - in: path name: did type: string required: true - in: path name: prop_name type: string required: true - in: body name: body required: true schema: type: object required: [value] properties: value: description: 属性值(类型取决于属性定义) responses: 200: description: 设置成功 400: description: 参数验证失败 """ try: data = set_prop_schema.load(request.get_json(silent=True) or {}) except Exception as e: return error(f"输入验证失败: {e}", 400) try: result = DeviceService.set_property(get_current_user_id(), did, prop_name, data["value"]) return success(result) except DeviceSetError as e: return _mijia_error_response(e) except TimeoutError as e: return error(str(e), 504) except Exception as e: return error(str(e), 500) - app/schemas/device.py:4-5 (schema)Schema definition for set_property input validation. Defines a single required field 'value' of type Raw.
class SetPropertySchema(Schema): value = fields.Raw(required=True) - mcp_server/server.py:72-73 (registration)MCP tool registration via @mcp.tool() decorator on the set_property async function in the FastMCP server.
@mcp.tool() async def set_property(did: str, prop_name: str, value) -> dict: