Skip to content

v1.8.11#233

Merged
TiTidom-RC merged 20 commits into
betafrom
dev
Apr 12, 2026
Merged

v1.8.11#233
TiTidom-RC merged 20 commits into
betafrom
dev

Conversation

@TiTidom-RC
Copy link
Copy Markdown
Owner

This pull request introduces significant enhancements and refactoring to the AI integration and TTS notification system in the ttscast plugin. The main focus is on supporting a new virtual equipment for AI reformulation, improving the handling and routing of notification commands, and generalizing the management of AI-related virtual equipments. It also adds new synchronous communication with the daemon and ensures that AI features are tightly controlled by global configuration.

Key changes are grouped below:

AI Equipment & Command Management:

  • Introduced a new virtual equipment TTSCast_AI for AI text reformulation, with associated commands (ai_reformat, ai_reformat_message, ai_reformat_input). The management logic is now generalized under manageAIEquipments, which handles both TTSCast_AI_Stats and TTSCast_AI based on the global AI enablement setting. Equipments are enabled/disabled instead of deleted when AI is toggled. [1] [2] [3]
  • Updated the postSave, preRemove, and command removal logic to correctly handle both AI-related virtual equipments, preventing unwanted manual activation or deletion when AI is disabled. [1] [2] [3]
  • Added a mechanism to block manual reactivation of TTSCast_AI if AI is globally disabled, with user feedback.

Daemon Communication & Command Execution:

  • Added sendToDaemonSync, a new static method for synchronous request/response communication with the daemon, used for AI reformulation.
  • Enhanced the execute method in ttscastCmd to support the new ai_reformat command, including storing the result in commands or variables as specified, and robust error handling.
  • Modified TTS command execution to support notification command chaining, passing notification command IDs through the TTS flow and handling their execution upon daemon callback. [1] [2] [3]

UI & Template Handling:

  • Updated getImage and widget template logic to support the new AI equipment and its commands, including scenario widget templates for tts and ai_reformat. [1] [2]

Other Improvements:

  • Added a new info command tts_last_message to each device (when AI is enabled) and updated it via callback from the daemon. [1] [2]
  • Relaxed flake8 linting rules to ignore E241 (multiple spaces after comma).

These changes collectively improve the flexibility, maintainability, and feature set of the plugin's AI and notification handling.

Introduce ai_last_message support end-to-end: add an ai_last_message info command in ttscast class (created only if global AI is enabled), handle incoming aiLastMessage callbacks in core/php/jeettscast.php to update the device command, and send aiLastMessage from the daemon when AI reformulation occurs (resources/ttscastd/ttscastd.py). Also trim extracted text in Functions.get_text() and bump plugin version to 1.8.11. Includes debug logs for tracing the new flow.
Expose AI reformulated text from test TTS back to Jeedom. PHP: handle an incoming 'aiTestResult' callback and add a debug log plus a message::add entry so the AI test result appears in Jeedom messages. Python daemon: track _aiReformulatedText when AI reformulates TTS text in various paths and, after TestTTS processing, send it to Jeedom via Comm.sendToJeedom.add_changes('aiTestResult', ...), with debug logging.
Replace usages of Comm.sendToJeedom.add_changes with send_change_immediate in resources/ttscastd/ttscastd.py. The aiTestResult is now sent as {'aiTestResult': text} and aiLastMessage is sent as {'aiLastMessage': {uuid: text}} to ensure immediate dispatch and a consistent payload shape when reporting AI reformulations.
In core/php/jeettscast.php, simplify the message::add call in the AI test callback by removing the extra empty and boolean parameters. The AI test result is now passed as message::add('ttscast', '[AI Test] ' . strval(...)) to match the expected usage and avoid passing unused/deprecated arguments.
Introduce a static helper _sendAIResult to centralize sending AI reformulation results to Jeedom (aiTestResult for tests, aiLastMessage for normal TTS with UUID). Replace duplicated send_to_jeedom blocks in generateTestTTS and generateTTS with calls to this helper and remove the now-redundant send logic. Keeps existing logging and behavior while reducing code duplication.
Change default visibility for a generated command in core/class/ttscast.class.php from visible to hidden (setIsVisible(0)). This keeps the command functional but prevents it from appearing in the UI by default.
Introduce DAEMON_OPTION_KEYS as a frozenset in the Config class to enumerate AI-related option keys consumed by the daemon and never returned as notification options (genai, aitone, aisysprompt, aitemp, ssml, before, voice). Keeps these keys grouped with existing AI configuration.
Add support for sending a notification/action when AI reformatting is performed. Introduces a new scenario template (cmd.aiReformatSend.html) and creates an ai_reformat_send action command for devices. The playTTS signature now accepts cmdNotificationId and passes it through to the daemon; the daemon (ttscastd) accepts the new parameter, captures passthrough options (excluding DAEMON_OPTION_KEYS), and sends aiReformatResult back to Jeedom. jeettscast.php processes aiReformatResult, updates the device ai_last_message and executes the configured notification command with the reformulated text and original options. Also expands DAEMON_OPTION_KEYS to exclude additional runtime keys from being forwarded to notifications.
Replace occurrences of "and _useSSML is False" with the Pythonic "and not _useSSML" in resources/ttscastd/ttscastd.py (two TTS generation branches). No functional change; improves readability and adheres to common Python style.
Rename the AI reformat feature to TTS Notify across the codebase: create/handle a new 'tts_notify' action (logicalId, name and template), update ttscastCmd handling and log messages, and replace callback payload/key from 'aiReformatResult' to 'ttsNotifyResult' in jeettscast.php. Rename template core/template/scenario/cmd.aiReformatSend.html to cmd.ttsNotify.html and update its placeholder options. Update daemon (resources/ttscastd/ttscastd.py) to emit 'ttsNotifyResult' and adjust its logs. Also add E241 to the .flake8 ignore list.
Update the tts_notify action command name in core/class/ttscast.class.php from 'TTS & Notifier' to 'TTS Notify' for clearer, more concise labeling.
Remove the hardcoded 'template' configuration for the tts_notify action and add a getWidgetTemplateCode override to supply the scenario widget template (cmd.ttsNotify). For scenario views and commands with logicalId 'tts_notify' the code loads and translates the template, injects a unique uid, and returns it as a non-core widget; otherwise it falls back to the parent implementation.
Add an empty '#cmdNotification#' replacement to the array used when rendering the 'cmd.ttsNotify' template in core/class/ttscast.class.php. This ensures the template placeholder is always defined (avoiding missing replacement issues) and includes a minor alignment cleanup of the array entries.
Improve example placeholders in core/template/scenario/cmd.ttsNotify.html: replace the options example with a JSON-like example ("volume": 80, "ding": false, "genai": true, "aitone": "sérieux") — HTML-escaped in the template — and add a placeholder for the Notification field demonstrating the #[Maison][Mobile][Notifier]# syntax to make configuration clearer for users.
Remove the unused '#cmdNotification#' replacement entry and tidy the '#uid#' mapping in ttscast.class.php. Add JS in cmd.ttsNotify.html to grab the cmdNotification element and set its value to an empty string if it's empty or still contains the placeholder (checks against '#' + 'cmdNotification#' to avoid template replacement). This prevents leftover placeholder text and ensures the notification field initializes empty.
Replace AI-specific identifiers and handlers with TTS equivalents for consistency. Updated core/class/ttscast.class.php to create/info command logicalId and name as tts_last_message, adjusted core/php/jeettscast.php to handle ttsTestResult/ttsLastMessage callbacks and to use tts_last_message command, and refactored resources/ttscastd/ttscastd.py to rename _sendAIResult to _sendTTSResult and to send ttsTestResult/ttsLastMessage payloads; also updated related logging and removed direct ai_last_message updates where the daemon now handles tts_last_message updates. These changes align naming and flow between the daemon and Jeedom plugin callbacks.
Remove creation and legacy handling of the tts_notify action command, update widget/template lookup from 'tts_notify' to 'tts' and rename the scenario template file accordingly. Add support for an optional cmdNotification option: resolve the referenced command, log a warning if missing, and pass its ID to ttscast::playTTS; update debug logs to include the cmdNotification id. Also adjust the scenario UI label from "Message" to "TTS".
Implements synchronous request/response support for AI reformulation and expands AI equipment management. PHP: add sendToDaemonSync(), rename/manageAIEquipments() to create/disable TTSCast_AI_Stats and TTSCast_AI virtual equipments, update postSave/preRemove/dontRemoveCmd and ttscastCmd to provide an ai_reformat action (sends sync payload, updates info cmds and optional storeTarget). Add scenario template cmd.aiReformat.html and call manageAIEquipments() during install. Python (daemon): switch to ThreadingTCPServer, add sync_command_handlers and expected_apikey to jeedom socket handler, handle sync commands inline (respond on socket), fix callback logging, improve queue handling in events loop, add TTSCast.handleAiReformat() and register it at startup. Various robustness and minor refactors for socket/message parsing and queue handling.
Return the AI icon for both TTSCast_AI_Stats and TTSCast_AI logical IDs so AI virtual devices use the ai_stats image. In jeedom.py, move the apikey validation into the synchronous-command branch so the apikey is only enforced for sync commands; this prevents non-sync messages from being wrongly rejected and the client connection from being closed.
Change the command name for ai_reformat_input in ttscast to use 'Message pré-IA' instead of 'Texte pré-IA'. This updates the label when creating the ttscastCmd in core/class/ttscast.class.php to better reflect the input semantics.
@TiTidom-RC TiTidom-RC merged commit bd3d12d into beta Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant