Skip to content

Add the apps and widgets API - #1167

Merged
joostlek merged 1 commit into
frenck:mainfrom
joostlek:device-apps
Sep 10, 2026
Merged

Add the apps and widgets API#1167
joostlek merged 1 commit into
frenck:mainfrom
joostlek:device-apps

Conversation

@joostlek

Copy link
Copy Markdown
Collaborator

Proposed Changes

(Describe the changes and rationale behind them)

Only next and prev were covered, which left the whole app control surface unreachable. This adds the remaining four endpoints:

Method Endpoint
apps() GET /device/apps
app() GET /device/apps/:package
activate_widget() PUT /device/apps/:pkg/widgets/:id/activate
app_action() POST /device/apps/:pkg/widgets/:id/actions
apps = await lametric.apps()
clock = apps["com.lametric.clock"]

await lametric.activate_widget(
    package=clock.package,
    widget_id="1_com.lametric.clock",
)
await lametric.app_action(
    package=clock.package,
    widget_id="1_com.lametric.clock",
    action="clock.alarm",
    params={"enabled": True, "time": "07:00:00"},
)

Apps and widgets come back keyed by package name and widget ID, the way the device reports them, rather than converted to lists — the keys are meaningful and are what the other endpoints take as path segments.

Actions are addressed by name with a free form params mapping. Each app declares its own actions and their parameter specs, and both are reported by apps() and app(), so callers can discover what is available rather than having it hardcoded here.

Model notes

App, Widget and AppParameter follow what the device actually sends. Three fields are optional, each for a specific reason worth recording:

  • App.actions — apps with no actions omit the key entirely, as com.lametric.custommessage does.
  • AppParameter.required — present on action parameters, absent on trigger parameters.
  • Widget.visible — only reported by GET /device/apps, not by GET /device/apps/:package. The app() docstring points at apps() for visibility, and both cases are covered by tests.

Widget.settings is dict[str, Any], since its contents are specific to each app.

The fixtures are real responses from a LaMetric TIME (model sa8, OS 3.2.7). All six of its apps parse, including the empty-actions and empty-parameter cases. All four methods were verified against that device: listing, fetching one app, activating a widget, and running stopwatch.start, stopwatch.pause and stopwatch.reset.

app_action() carries a pylint: disable=too-many-arguments, matching how display() already handles the same limit.

Related Issues

(Github link to related issues or pull requests)

None.

🤖 Generated with Claude Code

The only app endpoints covered were next and prev, which left the whole
app control surface unreachable. This adds the remaining four:

  apps()             GET  /device/apps
  app()              GET  /device/apps/:package
  activate_widget()  PUT  /device/apps/:pkg/widgets/:id/activate
  app_action()       POST /device/apps/:pkg/widgets/:id/actions

Apps and widgets are returned keyed by package name and widget ID, the
way the device reports them, rather than as lists.

The App, Widget and AppParameter models follow what the device actually
sends. Three fields are optional for reasons worth recording: apps with
no actions leave the key out entirely, trigger parameters carry no
required flag, and widget visibility is only reported when listing all
apps, not when fetching one.

Actions are addressed by name with a free form params mapping, since
each app declares its own actions and their parameters. Both are
reported by apps() and app(), so callers can discover them.

The fixtures are real responses from a LaMetric TIME (sa8, OS 3.2.7),
which all four methods were verified against.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@joostlek joostlek added the new-feature New features or options. label Sep 10, 2026
@joostlek
joostlek merged commit bfb257b into frenck:main Sep 10, 2026
13 of 14 checks passed
@joostlek
joostlek deleted the device-apps branch September 10, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant