get_home
Retrieve home details and list all devices in it by providing the home ID.
Instructions
获取家庭详情,包含该家庭下的所有设备列表。
Args:
home_id: 家庭IDInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| home_id | Yes |
Implementation Reference
- mcp_server/server.py:145-152 (handler)MCP tool handler for get_home. Makes an HTTP GET request to /homes/{home_id} via the MCP server, returning home details with all devices.
@mcp.tool() async def get_home(home_id: str) -> dict: """获取家庭详情,包含该家庭下的所有设备列表。 Args: home_id: 家庭ID """ return await _request("GET", f"/homes/{home_id}") - app/api/homes.py:39-67 (handler)Flask API route handler for GET /homes/<home_id>. Authenticated endpoint that delegates to HomeService.get_home().
@homes_ns.route("/<home_id>", methods=["GET"]) @auth_required @limiter.limit("60 per minute") def get_home(home_id): """获取家庭详情 --- tags: - 家庭 security: - cookieAuth: [] - bearerAuth: [] parameters: - in: path name: home_id type: string required: true responses: 200: description: 家庭详情 404: description: 家庭未找到 """ try: home = HomeService.get_home(get_current_user_id(), home_id) return success(home) except ValueError as e: return error(str(e), 404) except Exception as e: return error(str(e), 500) - app/services/home_service.py:28-37 (helper)Service layer method that retrieves home details from the HomeCache database table by user_id and home_id.
def get_home(user_id: int, home_id: str) -> dict: cached = HomeCache.query.filter_by(user_id=user_id, home_id=home_id).first() if not cached: raise ValueError(f"家庭 {home_id} 未找到") return { "home_id": cached.home_id, "name": cached.name, "room_list": cached.room_list, "raw_data": cached.raw_data, } - app/models/home_cache.py:6-21 (schema)SQLAlchemy model (HomeCache) that stores cached home data including home_id, name, room_list, and raw_data per user.
class HomeCache(db.Model): __tablename__ = "home_caches" id = db.Column(db.Integer, primary_key=True, autoincrement=True) user_id = db.Column(db.Integer, db.ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True) home_id = db.Column(db.String(64), nullable=False) name = db.Column(db.String(128), nullable=False) room_list = db.Column(db.JSON, nullable=True) raw_data = db.Column(db.JSON, nullable=True) cached_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc)) __table_args__ = (db.UniqueConstraint("user_id", "home_id", name="uk_home_caches_user_home"),) def __repr__(self): return f"<HomeCache {self.name} home_id={self.home_id}>" - mcp_server/server.py:145-152 (registration)MCP tool registration via @mcp.tool() decorator. The FastMCP instance 'mcp' is created in the same file.
@mcp.tool() async def get_home(home_id: str) -> dict: """获取家庭详情,包含该家庭下的所有设备列表。 Args: home_id: 家庭ID """ return await _request("GET", f"/homes/{home_id}")