Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## Unreleased

## 0.3.3

- Add the adaptive Weather widget with a native Home Assistant weather entity
selector and live designer preview.
- Resolve current conditions from entity state and daily forecasts through
`weather.get_forecasts`, deduplicated across regions.
- Allow widget packages to provide native Home Assistant selector schemas while
keeping executable provider code inside the integration.

## 0.3.2

- Make the designer preview use the live Liquid/TRMNL HTML composed by the
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ Home Assistant data.

Open **OpenDisplay Studio** in the Home Assistant sidebar to create predefined
or custom displays, edit their logical grids, compose rectangular regions, and
assign Entity State, Calendar, or Text widgets. Project configuration is stored
with Home Assistant's versioned `Store`; browser `localStorage` is not used.
assign Entity State, Calendar, Weather, or Text widgets. Weather configuration
uses Home Assistant's native entity selector and renders current conditions plus
the selected entity's daily forecast. Project configuration is stored with Home
Assistant's versioned `Store`; browser `localStorage` is not used.

Draft projects remain private to the designer. A Ready project is exposed at a
stable URI based on its immutable server-generated ID:
Expand All @@ -21,12 +23,13 @@ media-source://opendisplay_studio/<project-id>
```

On every resolution the integration deduplicates widget data requirements,
reads current entity states and calendar events, renders widget Liquid
templates, composes one TRMNL Framework document, and sends that final HTML to
the Renderer. The Renderer App still knows only HTML, width, and height.
reads current entity states, calendar events, and requested weather forecasts,
renders widget Liquid templates, composes one TRMNL Framework document, and
sends that final HTML to the Renderer. The Renderer App still knows only HTML,
width, and height.

See [the widget contract](WIDGET_CONTRACT.md) for the schema/data/template
boundary and the planned multi-entity Table and optional-source Weather model.
boundary, native Home Assistant selectors, and the controlled provider model.
See [Stage 2 compatibility](STAGE2_COMPATIBILITY.md) for the Liquid/TRMNL
compatibility baseline retained by Stage 3.

Expand Down
50 changes: 31 additions & 19 deletions WIDGET_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,27 @@ data requirements
Liquid template
```

The panel builds controls from `fields`. Home Assistant-aware field types
currently include `entity` and `calendar`; the contract already represents an
`entities` multi-selector for future widgets. Configuration stores references,
never current values.
Widget packages are declarative and never contain executable Python. A package
can only request provider names registered by OpenDisplay Studio Integration.
This keeps installation reviewable and prevents a downloaded widget from
executing arbitrary code inside Home Assistant.

The panel builds controls from `fields`. A field can contain a native Home
Assistant `selector` object, using the same schema as blueprint inputs. The
panel passes that object to `ha-form` without recreating selector behavior.
Legacy built-in fields can continue using the shorthand `type` property while
packages migrate. Configuration stores references, never current values.

```yaml
fields:
- key: weather
label: Weather entity
required: true
selector:
entity:
filter:
domain: weather
```

Data requirements are declarative. A requirement names its provider, the
configuration key containing its source, whether the source has cardinality
Expand Down Expand Up @@ -62,32 +79,27 @@ A Table can use ordinary presentation fields plus a multi-entity requirement:
Its normalized Liquid context can then contain five room-temperature rows
without exposing the full Home Assistant state machine.

## Future Weather
## Weather

Weather can declare a required forecast source and a second optional current
temperature sensor. Both are resolved at render time:
Weather declares one required entity. The provider combines its current state
with the requested daily forecast at render time:

```json
{
"dataRequirements": [
{
"key": "forecast",
"key": "weather",
"provider": "weather_forecast",
"configKey": "weather",
"cardinality": "one",
"optional": false
},
{
"key": "externalTemperature",
"provider": "entity_state",
"configKey": "temperatureEntity",
"cardinality": "one",
"optional": true
"optional": false,
"forecastType": "daily"
}
]
}
```

Adding that widget requires a `WeatherProvider` and its definition/template;
it does not change project storage, Media Source identity, the frontend/backend
transport, or the Renderer API.
The `weather_forecast` provider belongs to the integration. It uses the selected
entity's state for current conditions and the public `weather.get_forecasts`
action for forecasts, then exposes one normalized Liquid object. Multiple
widgets selecting the same entity share the same collected provider result.
33 changes: 27 additions & 6 deletions custom_components/opendisplay_studio/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

from __future__ import annotations

import asyncio
from dataclasses import dataclass
from time import perf_counter
from typing import Any

from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError

from .data_providers import ICON_PATHS, CalendarProvider, EntityStateProvider
from .data_providers import (
ICON_PATHS,
CalendarProvider,
EntityStateProvider,
WeatherForecastProvider,
)
from .liquid_renderer import LIQUID
from .projects import Project
from .widgets import TEMPLATES, definition, with_defaults
Expand Down Expand Up @@ -122,10 +128,11 @@ def _calendar_value(

def _collect_requirements(
project: Project,
) -> tuple[set[str], dict[str, int]]:
) -> tuple[set[str], dict[str, int], set[str]]:
"""Compile widget declarations into one deduplicated screen request."""
entity_ids: set[str] = set()
calendar_requests: dict[str, int] = {}
weather_requests: set[str] = set()
for region in project["regions"]:
widget = region.get("widget")
if widget is None:
Expand All @@ -142,14 +149,17 @@ def _collect_requirements(
calendar_requests[entity_id] = max(
calendar_requests.get(entity_id, 0), days
)
return entity_ids, calendar_requests
elif requirement["provider"] == "weather_forecast":
weather_requests.update(sources)
return entity_ids, calendar_requests, weather_requests


def _resolve_widget_data(
widget_type: str,
config: dict[str, Any],
entities: dict[str, dict[str, str]],
calendars: dict[str, list[dict[str, str | bool | int]]],
weather: dict[str, dict[str, Any]],
) -> dict[str, Any]:
"""Hydrate declared requirements with normalized provider values."""
data: dict[str, Any] = {}
Expand Down Expand Up @@ -188,6 +198,8 @@ def _resolve_widget_data(
)
for source in sources
]
elif requirement["provider"] == "weather_forecast":
values = [weather.get(source) for source in sources]
data[requirement["key"]] = (
values
if requirement.get("cardinality") == "many"
Expand All @@ -203,10 +215,13 @@ async def async_compose_project(
) -> ComposedProject:
"""Collect requirements once, render fragments, and create one screen."""
started = perf_counter()
entity_ids, calendar_requests = _collect_requirements(project)
entity_ids, calendar_requests, weather_requests = _collect_requirements(project)
entities = EntityStateProvider(hass).get_many(entity_ids)
try:
calendars = await CalendarProvider(hass).async_get_many(calendar_requests)
calendars, weather = await asyncio.gather(
CalendarProvider(hass).async_get_many(calendar_requests),
WeatherForecastProvider(hass).async_get_many(weather_requests),
)
except HomeAssistantError as err:
raise ProjectComposeError("Could not resolve widget data") from err
data_ms = (perf_counter() - started) * 1_000
Expand All @@ -222,7 +237,13 @@ async def async_compose_project(
if widget is not None:
widget_type = widget["type"]
config = with_defaults(widget_type, widget["config"])
data = _resolve_widget_data(widget_type, config, entities, calendars)
data = _resolve_widget_data(
widget_type,
config,
entities,
calendars,
weather,
)
if widget_type == "entity-state" and data.get("entity") is not None:
title = str(config.get("title", "")).strip()
data["entity"]["displayName"] = title or data["entity"]["name"]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/opendisplay_studio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

DOMAIN = "opendisplay_studio"
NAME = "OpenDisplay Studio"
INTEGRATION_VERSION = "0.3.2"
INTEGRATION_VERSION = "0.3.3"

API_VERSION = 1
DEFAULT_WIDTH = 800
Expand Down
Loading