CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-homeassistant

tessl install tessl/pypi-homeassistant@2025.9.0

Open-source home automation platform running on Python 3.

Agent Success

Agent success rate when using this tile

69%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.19x

Baseline

Agent success rate without this tile

58%

task.mdevals/scenario-8/

Smart Home Device State Tracker

Build a simple device state tracking module for a smart home environment that manages entity states.

Requirements

Your module should track smart home entities (lights, sensors, switches) and their states. The system must:

  1. Set or update the state of an entity with an entity ID, state value, and optional attributes
  2. Retrieve the current state of any entity by its ID
  3. Remove an entity from the state registry
  4. Get all currently tracked entity states

Each entity state includes:

  • Entity ID (e.g., "light.living_room", "sensor.temperature")
  • State value (e.g., "on", "off", "23.5")
  • Optional attributes dictionary (e.g., {"brightness": 75})

Test Cases

  • Setting a new device state with "light.bedroom", state "on", and attributes {"brightness": 100} successfully stores the device state @test
  • Retrieving a device state for "light.bedroom" returns the correct state and attributes @test
  • Updating an existing device state changes the state value and attributes @test
  • Removing a device state for "light.bedroom" successfully removes it from tracking @test
  • Retrieving all device states returns a list of all currently tracked devices @test
  • Retrieving a non-existent device state returns None @test

Implementation

@generates

API

from homeassistant.core import HomeAssistant
from typing import Optional, Dict, Any, List

async def setup_tracker(hass: HomeAssistant) -> None:
    """Initialize the state tracker with the Home Assistant instance."""
    pass

async def set_device_state(
    hass: HomeAssistant,
    entity_id: str,
    state: str,
    attributes: Optional[Dict[str, Any]] = None
) -> None:
    """
    Set or update a device state.

    Args:
        hass: The Home Assistant instance
        entity_id: The unique identifier for the device (e.g., "light.bedroom")
        state: The state value (e.g., "on", "off", "23.5")
        attributes: Optional dictionary of device attributes
    """
    pass

def get_device_state(hass: HomeAssistant, entity_id: str) -> Optional[Any]:
    """
    Retrieve the current state of a device.

    Args:
        hass: The Home Assistant instance
        entity_id: The unique identifier for the device

    Returns:
        The State object if found, None otherwise
    """
    pass

async def remove_device_state(hass: HomeAssistant, entity_id: str) -> bool:
    """
    Remove a device from state tracking.

    Args:
        hass: The Home Assistant instance
        entity_id: The unique identifier for the device

    Returns:
        True if the device was removed, False if it didn't exist
    """
    pass

async def get_all_device_states(hass: HomeAssistant) -> List[Any]:
    """
    Retrieve all currently tracked device states.

    Args:
        hass: The Home Assistant instance

    Returns:
        A list of all State objects
    """
    pass

Dependencies { .dependencies }

homeassistant { .dependency }

Provides the core Home Assistant framework for state management and home automation.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/homeassistant@2025.9.x
tile.json