Storage & Schema¶
Schema-driven per-device configuration rendered as UI forms by the host. DeviceStorage plus the JsonSchema* shapes.
camera_ui_sdk.storage ¶
OnSetCallback
module-attribute
¶
OnSetCallback = Callable[[Any, Any], None | Any] | Callable[[Any, Any], Awaitable[None | Any]] | Callable[[Any, Any], Coroutine[Any, Any, None | Any]]
Callback type for onSet handlers.
OnGetCallback
module-attribute
¶
OnGetCallback = Callable[[], None | Any] | Callable[[], Awaitable[None | Any]] | Callable[[], Coroutine[Any, Any, None | Any]]
Callback type for onGet handlers.
JsonSchemaType
module-attribute
¶
Available schema field types for configuration UI.
StringFormat
module-attribute
¶
StringFormat = Literal['date-time', 'date', 'time', 'email', 'uuid', 'ipv4', 'ipv6', 'password', 'textarea', 'qrCode', 'image']
String format types for validation/display.
Used on string-typed schemas to render a specialized UI control:
date-time: ISO 8601 date+time picker.date: date-only picker.time: time-only picker.email: email input with format validation.uuid: UUID input with format validation.ipv4: IPv4 address input.ipv6: IPv6 address input.password: masked input that hides characters.textarea: multi-line text area for longer free text.qrCode: value is rendered as a QR code (read-only display).image: value is a data URL or path; rendered as a thumbnail.
ButtonColor
module-attribute
¶
Button color variants.
SchemaConditionOperator
module-attribute
¶
Comparison operators for conditional field visibility.
T
module-attribute
¶
T = TypeVar('T', str, int, float, bool, list[str], list[int], list[float], list[bool], str | list[str])
Generic type variable for schema default values.
V2
module-attribute
¶
TypeVar for generic storage values type. Compatible with TypedDict.
JsonSchema
module-attribute
¶
JsonSchema = JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaEnum | JsonSchemaArray | JsonSchemaObject | JsonSchemaButton | JsonSchemaSubmit
Union of every top-level schema type (with callbacks).
Use this when defining the schemas you pass to defineSchemas,
addSchema, or changeSchema. Each entry describes one configurable
field rendered in the UI; the discriminator is the type property.
JsonSchemaWithoutKey
module-attribute
¶
JsonSchemaWithoutKey = JsonSchemaString | JsonSchemaNumber | JsonSchemaBoolean | JsonSchemaEnum | JsonSchemaArray | JsonSchemaObject | JsonSchemaButton | JsonSchemaSubmit
Schema accepted where the key is supplied externally, e.g. as a dict property.
JsonSchemaWithoutCallbacks
module-attribute
¶
JsonSchemaWithoutCallbacks = JsonSchemaStringWithoutCallbacks | JsonSchemaNumberWithoutCallbacks | JsonSchemaBooleanWithoutCallbacks | JsonSchemaEnumWithoutCallbacks | JsonSchemaArrayWithoutCallbacks | JsonSchemaObjectWithoutCallbacks
Union type of schemas without callbacks. Use this for nested schemas (e.g., array items).
SchemaCondition ¶
Bases: TypedDict
Condition that controls when a field is visible. The field is shown only when the condition evaluates to true against the current form values.
Combine multiple conditions on a field via a list: all must pass (logical AND).
Example
Show apiKey only when authMode equals token::
{
"key": "apiKey",
"type": "string",
"title": "API Key",
"description": "",
"condition": {"key": "authMode", "value": "token"},
}
Show port only when protocol is one of the listed values::
{"key": "protocol", "operator": "in", "value": ["http", "https"]}
JsonFactorySchema ¶
Bases: TypedDict
Base schema interface for all schema types. Contains common fields like type, key, title, description.
JsonBaseSchemaWithoutCallbacks ¶
Bases: JsonFactorySchema, Generic[T]
Base schema without callbacks, used for nested schemas. Extends factory schema with common display options.
condition
instance-attribute
¶
Condition for conditional field visibility. List = all must be true (AND).
JsonBaseSchema ¶
Bases: JsonBaseSchemaWithoutCallbacks[T], Generic[T]
Base schema with callbacks, the full schema interface. Adds storage and callback options for dynamic behavior.
onSet
instance-attribute
¶
Called after setValue writes the key, changed or not. setConfig
calls it only for keys that changed. Receives (new_value, old_value).
JsonStringSchema ¶
Bases: TypedDict
String-specific schema options.
format
instance-attribute
¶
String format for validation/display. See StringFormat for behavior per format.
JsonNumberSchema ¶
Bases: TypedDict
Number-specific schema options.
JsonBooleanSchema ¶
Bases: TypedDict
Boolean-specific schema options.
JsonEnumSchema ¶
Bases: TypedDict
Enum/select schema options.
enumLabels
instance-attribute
¶
Display labels per enum value; values without a label show the raw value.
JsonArraySchema ¶
Bases: TypedDict
Array schema options.
JsonObjectSchema ¶
Bases: TypedDict
Object schema options.
The value is a plain dict; each property is its own keyed sub-field.
As array items this yields structured lists, e.g. [{"name", "cameras"}].
JsonSchemaString ¶
Bases: JsonBaseSchema[str]
Complete string schema with callbacks.
JsonSchemaStringWithoutCallbacks ¶
JsonSchemaNumber ¶
JsonSchemaNumberWithoutCallbacks ¶
Bases: JsonBaseSchemaWithoutCallbacks[int | float]
Number schema without callbacks (for nested use).
JsonSchemaBoolean ¶
JsonSchemaBooleanWithoutCallbacks ¶
JsonSchemaEnum ¶
JsonSchemaEnumWithoutCallbacks ¶
Bases: JsonBaseSchemaWithoutCallbacks[str | list[str]]
Enum schema without callbacks (for nested use).
JsonSchemaArray ¶
Bases: JsonBaseSchema[list[str] | list[int] | list[float] | list[bool]]
Complete array schema with callbacks.
JsonSchemaArrayWithoutCallbacks ¶
Bases: JsonBaseSchemaWithoutCallbacks[list[str] | list[int] | list[float] | list[bool]]
Array schema without callbacks (for nested use).
JsonSchemaObject ¶
JsonSchemaObjectWithoutCallbacks ¶
Bases: JsonBaseSchemaWithoutCallbacks[dict[str, Any]]
Object schema without callbacks (for nested use).
JsonSchemaButton ¶
Bases: TypedDict
Button schema: triggers an action without storing a value.
JsonSchemaSubmit ¶
Bases: TypedDict
Submit button schema: submits form data and can return an updated schema.
onClick
instance-attribute
¶
Submit handler; receives form values, can return toast/schema updates.
ToastMessage ¶
Bases: TypedDict
Toast notification message.
Returned from a submit handler (JsonSchemaSubmit.onClick) inside a
FormSubmitResponse to surface a transient banner in the UI, for example
to confirm that a credential check succeeded or failed.
FormSubmitSchema ¶
Bases: TypedDict
Form submit input data.
FormSubmitResponse ¶
Bases: TypedDict
Form submit response, returned by JsonSchemaSubmit.onClick.
Used to react to a user-triggered submit (e.g. "Test connection", "Pair device") with optional UI feedback. Either field may be set:
toastshows a transient banner.schemareplaces the current form schema, useful for multi-step flows where the next step depends on the submitted values.
SchemaConfig ¶
DeviceStorage ¶
Bases: Protocol, Generic[V2]
Device storage interface for plugin/camera configuration.
Provides methods to read/write configuration values and manage schemas. Each plugin and camera can have its own storage instance.
Example
# Get a value with default
threshold = await storage.getValue("motionThreshold", 50)
# Set a value
await storage.setValue("motionThreshold", 75)
# Add a new schema field
await storage.addSchema(
{
"type": "number",
"key": "sensitivity",
"title": "Sensitivity",
"description": "Detection sensitivity (0-100)",
"minimum": 0,
"maximum": 100,
"defaultValue": 50,
}
)
getValue
async
¶
Get a configuration value.
If the schema declares an onGet callback, its result is returned
as-is, with no fallback. Otherwise resolves in order: the stored value,
then the schema default, then the provided default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
default_value
|
V1 | None
|
Default value if key doesn't exist |
None
|
Returns:
| Type | Description |
|---|---|
V1 | None
|
The configuration value or default |
setValue
async
¶
Set a configuration value.
Takes effect only if a schema exists for the key. Passing None
deletes the key: it reads as never-set again and the schema default
applies. For a field whose schema opts into storage (store: True)
the value is durably persisted before the coroutine completes; the
schema's onSet fires afterwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
new_value
|
Any
|
New value to set, or |
required |
submitValue
async
¶
Submit a value (for submit-type schemas).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Schema key |
required |
new_value
|
Any
|
Submitted value |
required |
Returns:
| Type | Description |
|---|---|
FormSubmitResponse | None
|
Optional response with toast/schema updates |
hasValue ¶
Check if a configuration value exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Configuration key |
required |
getConfig
async
¶
Get the schema definitions and the values they own.
Internal values written with setInternalValue are left out, read them
with getValue.
Returns:
| Type | Description |
|---|---|
SchemaConfig
|
Schema definitions and their current values |
setConfig
async
¶
Merge configuration values into the current config.
Only keys present in new_config are updated (not a full replace);
arrays are replaced, not merged. Keys without a schema are ignored.
Values are durably persisted before the coroutine completes; onSet
fires for each key whose value changed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
new_config
|
V2
|
Configuration values to merge in |
required |
defineSchemas ¶
Define all schemas for this storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas
|
list[JsonSchema]
|
Array of schema definitions |
required |
addSchema
async
¶
Add a new schema field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
JsonSchema
|
Schema definition to add |
required |
removeSchema
async
¶
Remove a schema field.
The field's stored value is deleted along with the schema; the removal is durably persisted when the coroutine completes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Schema key to remove |
required |
changeSchema
async
¶
Replace an existing schema field with a full schema.
The whole schema is replaced, individual fields are not merged. It is
a no-op when no schema with that key is registered (use addSchema to
add a new field). The passed key always wins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Schema key to replace |
required |
new_schema
|
dict[str, Any]
|
Full schema definition that replaces the current one |
required |
getSchema ¶
Get a schema definition by key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Schema key |
required |
Returns:
| Type | Description |
|---|---|
JsonSchema | None
|
Schema or None |
hasSchema ¶
Check if a schema exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Schema key |
required |
setInternalValue
async
¶
Set an internal value without a schema and persist it.
Internal values stay out of getConfig and can only be written by the
plugin itself. When the coroutine completes, the value is durably persisted.
Passing None deletes the key; it reads as never-set again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Internal key (typically prefixed with '_') |
required |
value
|
Any
|
Value to set, or |
required |
setInternalValueSync ¶
Set an internal value and write it to disk before returning.
For callbacks that must not return before the value is safe, such as the
synchronous storage hook of a library. The write blocks the event loop, so
use setInternalValue everywhere else. Once the call returns, the value
survives a crash of the plugin. Passing None deletes the key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Internal key (typically prefixed with '_') |
required |
value
|
Any
|
Value to set, or |
required |
save
async
¶
Persist all changes to storage.
When the coroutine completes, all values are durably persisted.