Skip to main content
Glama

Home Assistant MCP Server

by miguelg719
import pytest from unittest.mock import patch, Mock import sys from pathlib import Path sys.path.append(str(Path(__file__).parent.parent / 'src')) from home_assistant_mcp.server import HomeAssistantMcpServer @pytest.mark.asyncio async def test_turn_light_on_success(): server = HomeAssistantMcpServer() # Mock the httpx client call mock_response = Mock() mock_response.json.return_value = {'state': 'on', 'attributes': {'brightness': 100}} with patch('httpx.AsyncClient.post', return_value=mock_response): result = await server.turn_light_on('ceiling_lights', brightness_pct=100) assert result == {'state': 'on', 'attributes': {'brightness': 100}} @pytest.mark.asyncio async def test_turn_light_on_error(): server = HomeAssistantMcpServer() # Mock a failed request with patch('httpx.AsyncClient.post', side_effect=Exception('Connection error')): with pytest.raises(Exception, match='Connection error'): await server.turn_light_on('ceiling_lights') @pytest.mark.asyncio async def test_turn_light_on_no_brightness(): server = HomeAssistantMcpServer() mock_response = Mock() mock_response.json.return_value = {'state': 'on', 'attributes': {}} with patch('httpx.AsyncClient.post', return_value=mock_response): result = await server.turn_light_on('ceiling_lights') assert result == {'state': 'on', 'attributes': {}}

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/miguelg719/home-assistant-mcp'

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