3 Commits
0.1.2 ... 0.1.3

3 changed files with 34 additions and 45 deletions

View File

@@ -1,34 +1,27 @@
import logging async def handle_send_message(call: ServiceCall):
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):
message = call.data.get("message") 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") target_number = call.data.get("number")
all_accounts = call.data.get("all_accounts", False)
entries = hass.config_entries.async_entries(DOMAIN) entries = hass.config_entries.async_entries(DOMAIN)
targets = [] 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: for e in entries:
targets.append(e.data.get(CONF_PHONE_NUMBER)) targets.append(e.data.get(CONF_PHONE_NUMBER))
elif target_number: elif recipient:
targets.append(target_number) # Fall C: Spezifisches Profil (Recipient Name)
elif target_account:
for e in entries: 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)) targets.append(e.data.get(CONF_PHONE_NUMBER))
# Senden (wie gehabt)
for num in targets: for num in targets:
url = "http://866fd2eb-whatsapp-bridge:3000/send" url = "http://866fd2eb-whatsapp-bridge:3000/send"
try: try:
@@ -40,11 +33,4 @@ async def async_setup_entry(hass: HomeAssistant, entry):
) )
_LOGGER.info("WhatsApp sent to %s", num) _LOGGER.info("WhatsApp sent to %s", num)
except Exception as e: except Exception as e:
_LOGGER.error("Failed to send to %s: %s", num, str(e)) _LOGGER.error("Error sending 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

View File

@@ -4,7 +4,7 @@
"documentation": "https://git.bahmcloud.de/bahmcloud/Whatsapp-Bridge-Integration", "documentation": "https://git.bahmcloud.de/bahmcloud/Whatsapp-Bridge-Integration",
"dependencies": [], "dependencies": [],
"codeowners": ["@bahmcloud"], "codeowners": ["@bahmcloud"],
"version": "0.1.2", "version": "0.1.3",
"iot_class": "local_polling", "iot_class": "local_polling",
"config_flow": true "config_flow": true
} }

View File

@@ -2,29 +2,32 @@ send_message:
name: Send Message name: Send Message
description: Sends a WhatsApp message via the Bahmcloud Bridge. description: Sends a WhatsApp message via the Bahmcloud Bridge.
fields: fields:
account: recipient:
name: Account Profile name: Recipient
description: The name of a saved profile (e.g., Max). Leave empty if using a manual number. description: Select a saved profile or choose "Broadcast to all".
example: "Max" required: true
selector: selector:
text: select:
number: options:
name: Manual Number - label: "Broadcast to all"
description: "Direct phone number (Format: 491701234567). Overwrites the Account field." value: "all_accounts"
example: "491701234567" # Dieser Teil sorgt dafür, dass HA die Namen deiner Accounts anzeigt
selector: custom_value: true
text:
message: message:
name: Message name: Message
description: The content of your WhatsApp message. description: The content of your WhatsApp message.
required: true required: true
example: "The garage door is open!"
selector: selector:
text: text:
multiline: true multiline: true
all_accounts: use_manual_number:
name: Send to All name: Use Manual Number
description: If enabled, the message is sent to all registered profiles. description: Enable this to ignore the recipient and use the number field below.
default: false default: false
selector: selector:
boolean: boolean:
number:
name: Manual Number
description: "Direct phone number (e.g., 491701234567)."
selector:
text: