From b984a0f3e181c9a024c032b73fc9b77fb149076b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Bachmann?= Date: Tue, 14 Apr 2026 12:20:01 +0000 Subject: [PATCH] =?UTF-8?q?custom=5Fcomponents/whatsapp=5Fbridge=5Fcustom/?= =?UTF-8?q?=5F=5Finit=5F=5F.py=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../whatsapp_bridge_custom/__init__.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 custom_components/whatsapp_bridge_custom/__init__.py diff --git a/custom_components/whatsapp_bridge_custom/__init__.py b/custom_components/whatsapp_bridge_custom/__init__.py new file mode 100644 index 0000000..7467eef --- /dev/null +++ b/custom_components/whatsapp_bridge_custom/__init__.py @@ -0,0 +1,47 @@ +import logging +import requests +import voluptuous as vol +from homeassistant.helpers import config_validation as cv + +_LOGGER = logging.getLogger(__name__) + +DOMAIN = "whatsapp_bridge_custom" + +# Definition der Service-Parameter +SERVICE_SEND_MESSAGE = "send_message" +ATTR_NUMBER = "number" +ATTR_MESSAGE = "message" + +SERVICE_SCHEMA = vol.Schema({ + vol.Required(ATTR_NUMBER): cv.string, + vol.Required(ATTR_MESSAGE): cv.string, +}) + +async def async_setup(hass, config): + """Set up the WhatsApp Bridge integration.""" + + def send_whatsapp_msg(call): + """Dienst-Funktion: Nachricht an das Add-on senden.""" + number = call.data.get(ATTR_NUMBER) + message = call.data.get(ATTR_MESSAGE) + + # Die interne URL zum Add-on (standardmäßig local-whatsapp-bridge) + # Port 3000 haben wir im Dockerfile definiert + url = "http://866fd2eb-whatsapp-bridge:3000/send" + + try: + response = requests.post(url, json={ + "number": number, + "message": message + }, timeout=10) + + if response.status_code != 200: + _LOGGER.error("Fehler beim Senden: %s", response.text) + except Exception as e: + _LOGGER.error("Verbindung zum Add-on fehlgeschlagen: %s", str(e)) + + hass.services.async_register( + DOMAIN, SERVICE_SEND_MESSAGE, send_whatsapp_msg, schema=SERVICE_SCHEMA + ) + + return True \ No newline at end of file