piphi-runtime-kit-python 0.3.0__py3-none-any.whl → 0.4.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,7 +70,7 @@ from .runtime.mqtt import (
70
70
  )
71
71
  from .runtime.registry import RuntimeRegistry
72
72
  from .runtime.state import RuntimeProcessState
73
- from .runtime.starter import RuntimeStarter, create_runtime_starter
73
+ from .runtime.starter import RuntimeStarter, build_entities_response, create_runtime_starter
74
74
  from .runtime.tasks import create_tracked_task, shutdown_background_tasks, track_background_task
75
75
  from .runtime.telemetry import TelemetryClient, build_core_auth_headers
76
76
  from .schemas import (
@@ -80,6 +80,9 @@ from .schemas import (
80
80
  IntegrationCommandRequest,
81
81
  IntegrationDiscoveryRequest,
82
82
  IntegrationDiscoveryResponse,
83
+ RuntimeEntityDashboardResponse,
84
+ RuntimeEntitiesResponse,
85
+ RuntimeEntityResponse,
83
86
  IntegrationEventIngestResponse,
84
87
  IntegrationEventListResponse,
85
88
  IntegrationEventRequest,
@@ -110,6 +113,9 @@ __all__ = [
110
113
  "IntegrationCommandRequest",
111
114
  "IntegrationDiscoveryRequest",
112
115
  "IntegrationDiscoveryResponse",
116
+ "RuntimeEntityDashboardResponse",
117
+ "RuntimeEntitiesResponse",
118
+ "RuntimeEntityResponse",
113
119
  "IntegrationEventRequest",
114
120
  "RuntimeAuthContext",
115
121
  "RuntimeAuthHeaders",
@@ -141,6 +147,7 @@ __all__ = [
141
147
  "build_core_auth_headers",
142
148
  "build_config_apply_response",
143
149
  "build_config_remove_response",
150
+ "build_entities_response",
144
151
  "build_runtime_auth_headers",
145
152
  "build_runtime_diagnostics_response",
146
153
  "build_runtime_health_response",
@@ -11,6 +11,7 @@ from .events import DEFAULT_CORE_BASE_URL as DEFAULT_EVENTS_CORE_BASE_URL, Event
11
11
  from .health import build_runtime_diagnostics_response, build_runtime_health_response
12
12
  from .registry import RuntimeRegistry
13
13
  from .telemetry import DEFAULT_CORE_BASE_URL as DEFAULT_TELEMETRY_CORE_BASE_URL, TelemetryClient
14
+ from ..schemas import RuntimeEntitiesResponse
14
15
 
15
16
 
16
17
  @dataclass(slots=True)
@@ -77,6 +78,34 @@ class RuntimeStarter:
77
78
  },
78
79
  )
79
80
 
81
+ def entities_response(
82
+ self,
83
+ *,
84
+ entities: list[dict[str, Any]],
85
+ capabilities: dict[str, Any] | None = None,
86
+ commands: dict[str, Any] | None = None,
87
+ ) -> RuntimeEntitiesResponse:
88
+ """Build the standard /entities response body for this runtime."""
89
+ return build_entities_response(
90
+ entities=entities,
91
+ capabilities=capabilities,
92
+ commands=commands,
93
+ )
94
+
95
+
96
+ def build_entities_response(
97
+ *,
98
+ entities: list[dict[str, Any]],
99
+ capabilities: dict[str, Any] | None = None,
100
+ commands: dict[str, Any] | None = None,
101
+ ) -> RuntimeEntitiesResponse:
102
+ """Return the standard runtime /entities response wrapper."""
103
+ return RuntimeEntitiesResponse(
104
+ entities=entities,
105
+ capabilities=capabilities or {},
106
+ commands=commands or {},
107
+ )
108
+
80
109
 
81
110
  def create_runtime_starter(
82
111
  *,
@@ -6,7 +6,7 @@ from datetime import datetime, timezone
6
6
  from enum import Enum
7
7
  from typing import Any
8
8
 
9
- from pydantic import BaseModel, ConfigDict, Field
9
+ from pydantic import AliasChoices, BaseModel, ConfigDict, Field
10
10
 
11
11
 
12
12
  class RuntimeConfig(BaseModel):
@@ -74,6 +74,68 @@ class IntegrationCommandRequest(BaseModel):
74
74
  args: dict[str, Any] = Field(default_factory=dict)
75
75
 
76
76
 
77
+ class RuntimeEntityDashboardResponse(BaseModel):
78
+ """Optional per-entity dashboard hints returned by a runtime."""
79
+
80
+ model_config = ConfigDict(populate_by_name=True, extra="allow")
81
+
82
+ allowed_widgets: list[str] = Field(
83
+ default_factory=list,
84
+ validation_alias=AliasChoices("allowed_widgets", "allowedWidgets"),
85
+ )
86
+ default_widget: str | None = Field(
87
+ default=None,
88
+ validation_alias=AliasChoices("default_widget", "defaultWidget"),
89
+ )
90
+ recommended_widgets: list[str] = Field(
91
+ default_factory=list,
92
+ validation_alias=AliasChoices("recommended_widgets", "recommendedWidgets"),
93
+ )
94
+ metadata: dict[str, Any] = Field(default_factory=dict)
95
+
96
+
97
+ class RuntimeEntityResponse(BaseModel):
98
+ """One live runtime entity tied to a configured device/account."""
99
+
100
+ model_config = ConfigDict(populate_by_name=True, extra="allow")
101
+
102
+ id: str
103
+ name: str
104
+ capabilities: list[str] = Field(default_factory=list)
105
+ config_id: str | None = Field(
106
+ default=None,
107
+ validation_alias=AliasChoices("config_id", "configId"),
108
+ )
109
+ device_id: str | None = Field(
110
+ default=None,
111
+ validation_alias=AliasChoices("device_id", "deviceId"),
112
+ )
113
+ device_type: str | None = Field(
114
+ default=None,
115
+ validation_alias=AliasChoices("device_type", "deviceType"),
116
+ )
117
+ device_class: str | None = Field(
118
+ default=None,
119
+ validation_alias=AliasChoices("device_class", "deviceClass"),
120
+ )
121
+ entity_type: str | None = Field(
122
+ default=None,
123
+ validation_alias=AliasChoices("entity_type", "entityType"),
124
+ )
125
+ dashboard: RuntimeEntityDashboardResponse | None = None
126
+ metadata: dict[str, Any] = Field(default_factory=dict)
127
+
128
+
129
+ class RuntimeEntitiesResponse(BaseModel):
130
+ """Standard response body returned by runtime /entities endpoints."""
131
+
132
+ model_config = ConfigDict(populate_by_name=True, extra="allow")
133
+
134
+ entities: list[RuntimeEntityResponse] = Field(default_factory=list)
135
+ capabilities: dict[str, Any] = Field(default_factory=dict)
136
+ commands: dict[str, Any] = Field(default_factory=dict)
137
+
138
+
77
139
  class IntegrationEventRequest(BaseModel):
78
140
  """Generic event payload emitted by a runtime integration."""
79
141
  event_type: str
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: piphi-runtime-kit-python
3
- Version: 0.3.0
3
+ Version: 0.4.1
4
4
  Summary: PiPhi Network runtime integration helpers
5
5
  Keywords: piphi,runtime,integration,iot
6
6
  Author-Email: KelvinSan <support@piphi.network>
@@ -113,18 +113,28 @@ hide vendor logic behind an overly magical abstraction.
113
113
 
114
114
  The package currently supports Python `>=3.11`.
115
115
 
116
- Install from a local checkout:
116
+ Install from PyPI:
117
117
 
118
118
  ```bash
119
- pdm add /path/to/piphi-runtime-kit-python
119
+ pdm add piphi-runtime-kit-python
120
120
  ```
121
121
 
122
122
  If you need the optional FastAPI helpers:
123
123
 
124
124
  ```bash
125
- pdm add "/path/to/piphi-runtime-kit-python[fastapi]"
125
+ pdm add "piphi-runtime-kit-python[fastapi]"
126
126
  ```
127
127
 
128
+ If you prefer `pip`:
129
+
130
+ ```bash
131
+ pip install piphi-runtime-kit-python
132
+ ```
133
+
134
+ Package page:
135
+
136
+ - https://pypi.org/project/piphi-runtime-kit-python/0.3.0/
137
+
128
138
  ## First 15 Minutes
129
139
 
130
140
  If you want the shortest path to a working runtime, do this:
@@ -160,9 +170,71 @@ These are the most common runtime routes and what they are for.
160
170
  | `/deconfigure` | `POST` | Usually | Remove one config | `RuntimeConfigRemoveResponse` |
161
171
  | `/events` | `GET` | Common | Show recent local runtime events | `build_event_list_response(...)` |
162
172
  | `/state` | `GET` | Common | Show current runtime state | `registry.entries`, `registry.state_snapshots` |
163
- | `/entities` | `GET` | Integration-specific | Show normalized entity list | integration-owned |
173
+ | `/entities` | `GET` | Integration-specific | Show normalized entity list | `build_entities_response(...)`, `starter.entities_response(...)` |
164
174
  | `/ui` or `/ui-config` | `GET` | Optional | Return config UI metadata | integration-owned |
165
175
 
176
+ ## Modeling `/entities`
177
+
178
+ For simple integrations, `/entities` can still be a plain list of generic
179
+ entities.
180
+
181
+ For smart-home and multi-device integrations, PiPhi now recommends a richer
182
+ runtime-owned entity shape that ties each entity to a real saved config or
183
+ device. That lets Core make better device-first dashboard suggestions, and it
184
+ gives the frontend enough context to render better widget defaults for plugs,
185
+ bulbs, thermostats, and other device-specific entities.
186
+
187
+ Recommended fields:
188
+
189
+ - `id`: stable runtime entity id
190
+ - `name`: user-facing label
191
+ - `capabilities`: actual capabilities for that specific device
192
+ - `config_id` / `configId`: PiPhi config UUID when available
193
+ - `device_id` / `deviceId`: integration-native device id
194
+ - `device_type` / `device_class`: values like `plug`, `bulb`, `sensor`, `climate`
195
+ - `entity_type`: values like `switch`, `light`, `sensor`, `media`
196
+ - `dashboard.allowed_widgets`, `dashboard.default_widget`, `dashboard.recommended_widgets`: optional UI hints
197
+
198
+ The SDK now includes `RuntimeEntityResponse`, `RuntimeEntitiesResponse`,
199
+ `build_entities_response(...)`, and `starter.entities_response(...)` to make
200
+ that payload easier to return.
201
+
202
+ The helper returns the standard wrapper shape:
203
+
204
+ - `entities`: the runtime-owned list you generated
205
+ - `capabilities`: optional manifest capability metadata
206
+ - `commands`: optional manifest command metadata
207
+
208
+ ```python
209
+ from piphi_runtime_kit_python import build_entities_response
210
+
211
+ @app.get("/entities")
212
+ async def entities() -> dict[str, Any]:
213
+ return build_entities_response(
214
+ entities=[
215
+ {
216
+ "id": "office-plug",
217
+ "name": "Office Plug",
218
+ "config_id": "core-config-uuid",
219
+ "device_id": "office-plug",
220
+ "device_class": "plug",
221
+ "entity_type": "switch",
222
+ "capabilities": ["switch", "power", "energy_today"],
223
+ "dashboard": {
224
+ "allowed_widgets": ["tile", "button", "stat"],
225
+ "default_widget": "tile",
226
+ },
227
+ }
228
+ ],
229
+ capabilities=manifest["capabilities"],
230
+ commands=manifest.get("commands", {}),
231
+ ).model_dump(exclude_none=True)
232
+ ```
233
+
234
+ If you are already using the starter object, the same response can be built with
235
+ `starter.entities_response(...)` instead of calling the standalone helper
236
+ directly.
237
+
166
238
  ## UI Config Endpoints
167
239
 
168
240
  Many integrations expose `/ui` or `/ui-config` so the PiPhi frontend knows how
@@ -1,8 +1,8 @@
1
- piphi_runtime_kit_python-0.3.0.dist-info/METADATA,sha256=xrNx3CQWKqmAHmFVv5OXY2In7GQCSNAONP78SKeB-_M,28376
2
- piphi_runtime_kit_python-0.3.0.dist-info/WHEEL,sha256=Z36eTX6lG3PITRleSd5hAZHCcz52yg3c0JQVxKBbLW0,90
3
- piphi_runtime_kit_python-0.3.0.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
- piphi_runtime_kit_python-0.3.0.dist-info/licenses/LICENSE,sha256=pS6szQI4X7qAin1ODdoDp-XwZvsFy6ZZ28-JAwGHgzo,1070
5
- piphi_runtime_kit_python/__init__.py,sha256=ghbPOQY3QMbEZrH8xSH8ZS9rbpYwkuRITReOUtZ9NsU,5446
1
+ piphi_runtime_kit_python-0.4.1.dist-info/METADATA,sha256=ug1yodvcOA6KxVr4DkKDbOvp_s7GI2GF1tFtnVdVhPw,30934
2
+ piphi_runtime_kit_python-0.4.1.dist-info/WHEEL,sha256=Z36eTX6lG3PITRleSd5hAZHCcz52yg3c0JQVxKBbLW0,90
3
+ piphi_runtime_kit_python-0.4.1.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
4
+ piphi_runtime_kit_python-0.4.1.dist-info/licenses/LICENSE,sha256=pS6szQI4X7qAin1ODdoDp-XwZvsFy6ZZ28-JAwGHgzo,1070
5
+ piphi_runtime_kit_python/__init__.py,sha256=_2HtSbXo2VN9267D-JFDBvX0Xvtzhhg4Y1d8KQ53W0Q,5692
6
6
  piphi_runtime_kit_python/adapters/__init__.py,sha256=3jBhPZSBN3Qo7MKHlxAol2jPU3cK23BXHR2oTlircsw,361
7
7
  piphi_runtime_kit_python/adapters/fastapi.py,sha256=1QcOBYprg6AmQVrkI8g61NIelBB_7BTbdvNaMvG2-s8,2098
8
8
  piphi_runtime_kit_python/fastapi.py,sha256=OZ-ds2-g32kB4YkF90D5bM4vVVjpOWPtrNC-WdhDNyo,361
@@ -19,9 +19,9 @@ piphi_runtime_kit_python/runtime/health.py,sha256=9YO0K_UCJKTe6uSFLgb1kStr5dAgtI
19
19
  piphi_runtime_kit_python/runtime/lifespan.py,sha256=mVSdZZAS66xlcnlzAwkztFjzw_l2pyLrJqULJsb0Ezk,2850
20
20
  piphi_runtime_kit_python/runtime/mqtt.py,sha256=JKMN5zxg1BcOidu7TaYnuRD3HuoAJ_WcvXMTTSlAteo,6069
21
21
  piphi_runtime_kit_python/runtime/registry.py,sha256=AOpd5NgwSAhN8Us8nLW6084GrMtitMMaQP916EpMZrk,3103
22
- piphi_runtime_kit_python/runtime/starter.py,sha256=K62F_3qTy-HAjWYAs3TADeR_wwC0u9kCUbQbNK66ThI,3747
22
+ piphi_runtime_kit_python/runtime/starter.py,sha256=j5C4GOOcRHNLJ-HYu8fmf3bE00baDOzAfuq1MefT-Jg,4651
23
23
  piphi_runtime_kit_python/runtime/state.py,sha256=4xvQGTT59DF9rXHAtM3kDyV_UGg2a9tLPvGiCp_PFMc,674
24
24
  piphi_runtime_kit_python/runtime/tasks.py,sha256=gMd-2K96jMU8tCPvI12xdWxuyNt5gsLDss2QWOoM94k,1241
25
25
  piphi_runtime_kit_python/runtime/telemetry.py,sha256=RN6SFrhmAZ7aJLyioQMBzJEFsxQgOjjA1pV5qNeaR4E,4279
26
- piphi_runtime_kit_python/schemas.py,sha256=NDG6g0BZZOEy35O5sz9_A4HlH-BnHyztOQMLbpKqF0E,4924
27
- piphi_runtime_kit_python-0.3.0.dist-info/RECORD,,
26
+ piphi_runtime_kit_python/schemas.py,sha256=weCqTPFafourOVe1Me4282hezJ9jwttDtKLBHrEqlnU,7069
27
+ piphi_runtime_kit_python-0.4.1.dist-info/RECORD,,