Compare commits
5 Commits
a37eb46003
...
v0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| b0d98a9d45 | |||
| d0d4958843 | |||
| de4b7cf9b4 | |||
| f84cfec43f | |||
| 6c5657618f |
@@ -0,0 +1,67 @@
|
|||||||
|
name: Release
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
release:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Fetch RELEASE_NOTES.md only
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
sparse-checkout: RELEASE_NOTES.md
|
||||||
|
sparse-checkout-cone-mode: false
|
||||||
|
|
||||||
|
- name: Create Gitea release
|
||||||
|
env:
|
||||||
|
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
|
||||||
|
run: |
|
||||||
|
TAG="${{ gitea.ref_name }}"
|
||||||
|
VERSION="${TAG#v}"
|
||||||
|
BASE_URL="${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}"
|
||||||
|
|
||||||
|
# Detect pre-release (alpha/beta/rc)
|
||||||
|
IS_PRE="false"
|
||||||
|
if echo "$TAG" | grep -qE '(alpha|beta|rc)'; then
|
||||||
|
IS_PRE="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Read release notes if present
|
||||||
|
if [ -f RELEASE_NOTES.md ]; then
|
||||||
|
export RELEASE_NOTES=$(cat RELEASE_NOTES.md)
|
||||||
|
echo "Found RELEASE_NOTES.md"
|
||||||
|
else
|
||||||
|
export RELEASE_NOTES=""
|
||||||
|
echo "No RELEASE_NOTES.md found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
BODY_JSON=$(python3 -c "
|
||||||
|
import json, os
|
||||||
|
notes = os.environ.get('RELEASE_NOTES', '')
|
||||||
|
print(json.dumps(notes.strip()))
|
||||||
|
")
|
||||||
|
|
||||||
|
# Create release via Gitea API
|
||||||
|
RELEASE=$(curl -s -X POST "$BASE_URL/releases" \
|
||||||
|
-H "Authorization: token $DEPLOY_TOKEN" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "{
|
||||||
|
\"tag_name\": \"$TAG\",
|
||||||
|
\"name\": \"$VERSION\",
|
||||||
|
\"body\": $BODY_JSON,
|
||||||
|
\"draft\": false,
|
||||||
|
\"prerelease\": $IS_PRE
|
||||||
|
}")
|
||||||
|
|
||||||
|
# Fallback: if release already exists for this tag, reuse it
|
||||||
|
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])" 2>/dev/null)
|
||||||
|
if [ -z "$RELEASE_ID" ]; then
|
||||||
|
echo "::warning::Release already exists for tag $TAG — reusing existing release"
|
||||||
|
RELEASE=$(curl -s "$BASE_URL/releases/tags/$TAG" \
|
||||||
|
-H "Authorization: token $DEPLOY_TOKEN")
|
||||||
|
RELEASE_ID=$(echo "$RELEASE" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
||||||
|
fi
|
||||||
|
echo "Created release $RELEASE_ID for $TAG"
|
||||||
@@ -103,6 +103,48 @@ Button entities for each script defined on your Media Server:
|
|||||||
- Shutdown, restart, sleep, hibernate
|
- Shutdown, restart, sleep, hibernate
|
||||||
- Custom scripts
|
- Custom scripts
|
||||||
|
|
||||||
|
### Execute Script Service
|
||||||
|
|
||||||
|
Call `remote_media_player.execute_script` to run any server-defined script with typed parameters:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
service: remote_media_player.execute_script
|
||||||
|
data:
|
||||||
|
script_name: set_brightness
|
||||||
|
params:
|
||||||
|
level: 75
|
||||||
|
monitor: primary
|
||||||
|
```
|
||||||
|
|
||||||
|
Parameters are validated against the script's schema on the server. Scripts define their parameters in `config.yaml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
scripts:
|
||||||
|
set_brightness:
|
||||||
|
command: "python set_brightness.py"
|
||||||
|
label: "Set Brightness"
|
||||||
|
icon: "mdi:brightness-6"
|
||||||
|
timeout: 10
|
||||||
|
parameters:
|
||||||
|
level:
|
||||||
|
type: integer
|
||||||
|
required: true
|
||||||
|
min: 0
|
||||||
|
max: 100
|
||||||
|
description: "Brightness level (0-100)"
|
||||||
|
monitor:
|
||||||
|
type: select
|
||||||
|
options: ["primary", "secondary", "all"]
|
||||||
|
default: "primary"
|
||||||
|
description: "Target monitor"
|
||||||
|
```
|
||||||
|
|
||||||
|
Supported parameter types: `string`, `integer`, `float`, `boolean`, `select`.
|
||||||
|
|
||||||
|
Parameters are passed to scripts as environment variables prefixed with `SCRIPT_PARAM_` (e.g., `SCRIPT_PARAM_LEVEL=75`, `SCRIPT_PARAM_MONITOR=primary`).
|
||||||
|
|
||||||
|
Scripts without parameters work as before — just omit `params`.
|
||||||
|
|
||||||
## Example Lovelace Card
|
## Example Lovelace Card
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
## v0.1.1 (2026-03-26)
|
||||||
|
|
||||||
|
### ⚠️ Breaking Changes
|
||||||
|
- Replace positional script `args` (list) with typed named `params` (dict) — update any automations calling `remote_media_player.execute_script` to use the new `params` format ([de4b7cf](https://git.dolgolyov-family.by/alexei.dolgolyov/haos-hacs-integration-media-player/commit/de4b7cf))
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- Add execute_script service documentation to README ([de4b7cf](https://git.dolgolyov-family.by/alexei.dolgolyov/haos-hacs-integration-media-player/commit/de4b7cf))
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>All Commits</summary>
|
||||||
|
|
||||||
|
| Hash | Message | Author |
|
||||||
|
|------|---------|--------|
|
||||||
|
| [de4b7cf](https://git.dolgolyov-family.by/alexei.dolgolyov/haos-hacs-integration-media-player/commit/de4b7cf) | feat: replace script args with typed named parameters | alexei.dolgolyov |
|
||||||
|
|
||||||
|
</details>
|
||||||
@@ -15,8 +15,8 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from .api_client import MediaServerClient, MediaServerError
|
from .api_client import MediaServerClient, MediaServerError
|
||||||
from .const import (
|
from .const import (
|
||||||
ATTR_FILE_PATH,
|
ATTR_FILE_PATH,
|
||||||
ATTR_SCRIPT_ARGS,
|
|
||||||
ATTR_SCRIPT_NAME,
|
ATTR_SCRIPT_NAME,
|
||||||
|
ATTR_SCRIPT_PARAMS,
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
@@ -33,9 +33,7 @@ PLATFORMS: list[Platform] = [Platform.MEDIA_PLAYER, Platform.BUTTON, Platform.NU
|
|||||||
SERVICE_EXECUTE_SCRIPT_SCHEMA = vol.Schema(
|
SERVICE_EXECUTE_SCRIPT_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(ATTR_SCRIPT_NAME): cv.string,
|
vol.Required(ATTR_SCRIPT_NAME): cv.string,
|
||||||
vol.Optional(ATTR_SCRIPT_ARGS, default=[]): vol.All(
|
vol.Optional(ATTR_SCRIPT_PARAMS, default={}): dict,
|
||||||
cv.ensure_list, [cv.string]
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -83,10 +81,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
async def async_execute_script(call: ServiceCall) -> dict[str, Any]:
|
async def async_execute_script(call: ServiceCall) -> dict[str, Any]:
|
||||||
"""Execute a script on the media server."""
|
"""Execute a script on the media server."""
|
||||||
script_name = call.data[ATTR_SCRIPT_NAME]
|
script_name = call.data[ATTR_SCRIPT_NAME]
|
||||||
script_args = call.data.get(ATTR_SCRIPT_ARGS, [])
|
script_params = call.data.get(ATTR_SCRIPT_PARAMS, {})
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Executing script '%s' with args: %s", script_name, script_args
|
"Executing script '%s' with params: %s", script_name, script_params
|
||||||
)
|
)
|
||||||
|
|
||||||
# Get all clients and execute on all of them
|
# Get all clients and execute on all of them
|
||||||
@@ -94,7 +92,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
for entry_id, data in hass.data[DOMAIN].items():
|
for entry_id, data in hass.data[DOMAIN].items():
|
||||||
client: MediaServerClient = data["client"]
|
client: MediaServerClient = data["client"]
|
||||||
try:
|
try:
|
||||||
result = await client.execute_script(script_name, script_args)
|
result = await client.execute_script(script_name, script_params)
|
||||||
results[entry_id] = result
|
results[entry_id] = result
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Script '%s' executed on %s: success=%s",
|
"Script '%s' executed on %s: success=%s",
|
||||||
|
|||||||
@@ -287,19 +287,21 @@ class MediaServerClient:
|
|||||||
return await self._request("GET", API_SCRIPTS_LIST)
|
return await self._request("GET", API_SCRIPTS_LIST)
|
||||||
|
|
||||||
async def execute_script(
|
async def execute_script(
|
||||||
self, script_name: str, args: list[str] | None = None
|
self,
|
||||||
|
script_name: str,
|
||||||
|
params: dict[str, str | int | float | bool] | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Execute a script on the server.
|
"""Execute a script on the server.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
script_name: Name of the script to execute
|
script_name: Name of the script to execute
|
||||||
args: Optional list of arguments to pass to the script
|
params: Optional named parameters (validated against script schema)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Execution result with success, exit_code, stdout, stderr
|
Execution result with success, exit_code, stdout, stderr
|
||||||
"""
|
"""
|
||||||
endpoint = f"{API_SCRIPTS_EXECUTE}/{script_name}"
|
endpoint = f"{API_SCRIPTS_EXECUTE}/{script_name}"
|
||||||
json_data = {"args": args or []}
|
json_data = {"params": params or {}}
|
||||||
return await self._request("POST", endpoint, json_data)
|
return await self._request("POST", endpoint, json_data)
|
||||||
|
|
||||||
async def get_media_folders(self) -> dict[str, dict[str, Any]]:
|
async def get_media_folders(self) -> dict[str, dict[str, Any]]:
|
||||||
|
|||||||
@@ -47,5 +47,5 @@ SERVICE_PLAY_MEDIA_FILE = "play_media_file"
|
|||||||
|
|
||||||
# Service attributes
|
# Service attributes
|
||||||
ATTR_SCRIPT_NAME = "script_name"
|
ATTR_SCRIPT_NAME = "script_name"
|
||||||
ATTR_SCRIPT_ARGS = "args"
|
ATTR_SCRIPT_PARAMS = "params"
|
||||||
ATTR_FILE_PATH = "file_path"
|
ATTR_FILE_PATH = "file_path"
|
||||||
|
|||||||
@@ -8,5 +8,5 @@
|
|||||||
"integration_type": "device",
|
"integration_type": "device",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"requirements": ["aiohttp>=3.8.0"],
|
"requirements": ["aiohttp>=3.8.0"],
|
||||||
"version": "1.0.0"
|
"version": "0.1.1"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,10 @@ execute_script:
|
|||||||
example: "launch_spotify"
|
example: "launch_spotify"
|
||||||
selector:
|
selector:
|
||||||
text:
|
text:
|
||||||
args:
|
params:
|
||||||
name: Arguments
|
name: Parameters
|
||||||
description: Optional list of arguments to pass to the script
|
description: Optional named parameters to pass to the script (validated against script schema)
|
||||||
required: false
|
required: false
|
||||||
example: '["arg1", "arg2"]'
|
example: '{"level": 75, "monitor": "primary"}'
|
||||||
selector:
|
selector:
|
||||||
object:
|
object:
|
||||||
|
|||||||
Reference in New Issue
Block a user