zzstoatzz commited on
Commit
8d91200
·
1 Parent(s): 7bce40a

dead branch

Browse files

push code

push code

push

examples/smart_home/pyproject.toml CHANGED
@@ -5,10 +5,7 @@ description = "Add your description here"
5
  readme = "README.md"
6
  authors = [{ name = "zzstoatzz", email = "thrast36@gmail.com" }]
7
  requires-python = ">=3.12"
8
- dependencies = [
9
- "fastmcp@git+https://github.com/jlowin/fastmcp.git@2.x",
10
- "phue2",
11
- ]
12
 
13
  [project.scripts]
14
  smart-home = "smart_home.__main__:main"
 
5
  readme = "README.md"
6
  authors = [{ name = "zzstoatzz", email = "thrast36@gmail.com" }]
7
  requires-python = ">=3.12"
8
+ dependencies = ["fastmcp@git+https://github.com/jlowin/fastmcp.git", "phue2"]
 
 
 
9
 
10
  [project.scripts]
11
  smart-home = "smart_home.__main__:main"
examples/smart_home/src/smart_home/hub.py CHANGED
@@ -1,5 +1,7 @@
 
 
1
  from fastmcp import FastMCP
2
- from smart_home.lights.server import bridge, lights_mcp
3
 
4
  hub_mcp = FastMCP(
5
  "Smart Home Hub (phue2)",
@@ -9,14 +11,14 @@ hub_mcp = FastMCP(
9
  )
10
 
11
  # Mount the lights service under the 'hue' prefix
12
- hub_mcp.mount("hue", lights_mcp)
13
 
14
 
15
  # Add a status check for the hub
16
  @hub_mcp.tool()
17
  def hub_status() -> str:
18
  """Checks the status of the main hub and connections."""
19
- if bridge:
20
  # Access the bridge instance directly
21
  return "Hub OK. Hue Bridge Connected (via phue2)."
22
  else:
 
1
+ from phue2 import Bridge
2
+
3
  from fastmcp import FastMCP
4
+ from smart_home.settings import settings
5
 
6
  hub_mcp = FastMCP(
7
  "Smart Home Hub (phue2)",
 
11
  )
12
 
13
  # Mount the lights service under the 'hue' prefix
14
+ # hub_mcp.mount("hue", lights_mcp)
15
 
16
 
17
  # Add a status check for the hub
18
  @hub_mcp.tool()
19
  def hub_status() -> str:
20
  """Checks the status of the main hub and connections."""
21
+ if Bridge(settings.hue_bridge_ip).connect():
22
  # Access the bridge instance directly
23
  return "Hub OK. Hue Bridge Connected (via phue2)."
24
  else:
examples/smart_home/src/smart_home/lights/server.py CHANGED
@@ -11,7 +11,6 @@ from phue2.exceptions import (
11
  from fastmcp import FastMCP
12
  from smart_home.settings import settings
13
 
14
- bridge: Bridge | None = None
15
  BRIDGE_IP = str(settings.hue_bridge_ip)
16
 
17
  try:
@@ -66,31 +65,6 @@ def list_lights() -> list[str]:
66
  return [f"Unexpected error listing lights: {e}"]
67
 
68
 
69
- @lights_mcp.resource("hue://light/{light_name}/status")
70
- def get_light_status(light_name: str) -> dict[str, Any]:
71
- """Gets the current status of a specific light using phue2."""
72
- if not bridge:
73
- return {"error": "Bridge not connected"}
74
- try:
75
- light_state = bridge.get_light(light_name, "state")
76
- if light_state and isinstance(light_state, dict):
77
- return {
78
- "name": light_name,
79
- "on": light_state.get("on"),
80
- "brightness": light_state.get("bri"),
81
- "reachable": light_state.get("reachable"),
82
- "raw_state": light_state,
83
- }
84
- else:
85
- return {"error": f"Light '{light_name}' not found or state unavailable."}
86
- except KeyError:
87
- return {"error": f"Light '{light_name}' not found (KeyError)."}
88
- except PhueException as e:
89
- return {"error": f"phue2 error getting status for '{light_name}': {e}"}
90
- except Exception as e:
91
- return {"error": f"Unexpected error getting status for '{light_name}': {e}"}
92
-
93
-
94
  # --- Tools ---
95
 
96
 
 
11
  from fastmcp import FastMCP
12
  from smart_home.settings import settings
13
 
 
14
  BRIDGE_IP = str(settings.hue_bridge_ip)
15
 
16
  try:
 
65
  return [f"Unexpected error listing lights: {e}"]
66
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  # --- Tools ---
69
 
70
 
examples/smart_home/src/smart_home/settings.py CHANGED
@@ -3,7 +3,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
3
 
4
 
5
  class Settings(BaseSettings):
6
- model_config = SettingsConfigDict(env_file=".env")
7
 
8
  hue_bridge_ip: IPvAnyAddress = Field(default=...)
9
 
 
3
 
4
 
5
  class Settings(BaseSettings):
6
+ model_config = SettingsConfigDict(env_file=".env", extra="ignore")
7
 
8
  hue_bridge_ip: IPvAnyAddress = Field(default=...)
9
 
justfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ build:
2
+ uv sync
3
+
4
+ test: build
5
+ uv run --frozen pytest -xvs tests
6
+
7
+ # Run pyright on all files
8
+ typecheck:
9
+ uv run pyright