From dbdf987501d3737c616dbc27db8da93da57ad83a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Tue, 14 Apr 2026 13:24:24 +0000 Subject: [PATCH] custom_components/whatsapp_bridge_integration/__init__.py aktualisiert --- .../whatsapp_bridge_integration/__init__.py | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/custom_components/whatsapp_bridge_integration/__init__.py b/custom_components/whatsapp_bridge_integration/__init__.py index 8db37c1..340750d 100644 --- a/custom_components/whatsapp_bridge_integration/__init__.py +++ b/custom_components/whatsapp_bridge_integration/__init__.py @@ -1,34 +1,27 @@ -import logging -import requests -from homeassistant.core import HomeAssistant, ServiceCall -from .const import DOMAIN, CONF_PHONE_NUMBER, CONF_ACCOUNT_NAME - -_LOGGER = logging.getLogger(__name__) - -async def async_setup_entry(hass: HomeAssistant, entry): - """Set up a profile from a config entry.""" - - if not hass.services.has_service(DOMAIN, "send_message"): - - async def handle_send_message(call: ServiceCall): +async def handle_send_message(call: ServiceCall): message = call.data.get("message") - target_account = call.data.get("account") + recipient = call.data.get("recipient") + use_manual = call.data.get("use_manual_number", False) target_number = call.data.get("number") - all_accounts = call.data.get("all_accounts", False) entries = hass.config_entries.async_entries(DOMAIN) targets = [] - if all_accounts: + # Logik-Prüfung + if use_manual and target_number: + # Fall A: Manuelle Nummer + targets.append(target_number) + elif recipient == "all_accounts": + # Fall B: Rundruf for e in entries: targets.append(e.data.get(CONF_PHONE_NUMBER)) - elif target_number: - targets.append(target_number) - elif target_account: + elif recipient: + # Fall C: Spezifisches Profil (Recipient Name) for e in entries: - if e.title.lower() == target_account.lower(): + if e.title.lower() == recipient.lower(): targets.append(e.data.get(CONF_PHONE_NUMBER)) + # Senden (wie gehabt) for num in targets: url = "http://866fd2eb-whatsapp-bridge:3000/send" try: @@ -40,11 +33,4 @@ async def async_setup_entry(hass: HomeAssistant, entry): ) _LOGGER.info("WhatsApp sent to %s", num) except Exception as e: - _LOGGER.error("Failed to send to %s: %s", num, str(e)) - - hass.services.async_register(DOMAIN, "send_message", handle_send_message) - - return True - -async def async_unload_entry(hass, entry): - return True \ No newline at end of file + _LOGGER.error("Error sending to %s: %s", num, str(e)) \ No newline at end of file