13 Commits
0.1.2 ... 0.1.6

Author SHA1 Message Date
ec6a9c6dd8 custom_components/whatsapp_bridge_integration/manifest.json aktualisiert 2026-04-14 13:48:34 +00:00
aa5a060aef custom_components/whatsapp_bridge_integration/services.yaml aktualisiert 2026-04-14 13:47:33 +00:00
7bea9bbbbb custom_components/whatsapp_bridge_integration/manifest.json aktualisiert 2026-04-14 13:43:28 +00:00
8dc6cfb7c1 custom_components/whatsapp_bridge_integration/services.yaml aktualisiert 2026-04-14 13:43:03 +00:00
b4fd722d8a custom_components/whatsapp_bridge_integration/services.yaml aktualisiert 2026-04-14 13:40:46 +00:00
20e6090f65 custom_components/whatsapp_bridge_integration/services.py hinzugefügt 2026-04-14 13:40:31 +00:00
d9ada23f3e custom_components/whatsapp_bridge_integration/sensor.py hinzugefügt 2026-04-14 13:40:10 +00:00
276d4a63cb custom_components/whatsapp_bridge_integration/__init__.py aktualisiert 2026-04-14 13:39:51 +00:00
adfe5dfe9d custom_components/whatsapp_bridge_integration/manifest.json aktualisiert 2026-04-14 13:29:15 +00:00
037cd9c9c7 custom_components/whatsapp_bridge_integration/__init__.py aktualisiert 2026-04-14 13:28:19 +00:00
498c059aa8 custom_components/whatsapp_bridge_integration/manifest.json aktualisiert 2026-04-14 13:24:38 +00:00
dbdf987501 custom_components/whatsapp_bridge_integration/__init__.py aktualisiert 2026-04-14 13:24:24 +00:00
370e33da7c custom_components/whatsapp_bridge_integration/services.yaml aktualisiert 2026-04-14 13:24:10 +00:00
5 changed files with 95 additions and 62 deletions

View File

@@ -1,50 +1,31 @@
import logging
import requests
from homeassistant.core import HomeAssistant, ServiceCall
from .const import DOMAIN, CONF_PHONE_NUMBER, CONF_ACCOUNT_NAME
from homeassistant.core import HomeAssistant
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: dict):
return True
async def async_setup_entry(hass: HomeAssistant, entry):
"""Set up a profile from a config entry."""
"""Set up entry and forward to sensor platform."""
# Lege die Daten im hass-Objekt ab
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN][entry.entry_id] = entry.data
# Forward the setup to the sensor platform to create entities
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
# Registriere den Service (nur beim ersten Mal)
if not hass.services.has_service(DOMAIN, "send_message"):
async def handle_send_message(call: ServiceCall):
message = call.data.get("message")
target_account = call.data.get("account")
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:
for e in entries:
targets.append(e.data.get(CONF_PHONE_NUMBER))
elif target_number:
targets.append(target_number)
elif target_account:
for e in entries:
if e.title.lower() == target_account.lower():
targets.append(e.data.get(CONF_PHONE_NUMBER))
for num in targets:
url = "http://866fd2eb-whatsapp-bridge:3000/send"
try:
await hass.async_add_executor_job(
lambda: requests.post(url, json={
"number": num,
"message": message
}, timeout=10)
)
_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)
from .services import async_setup_services
await async_setup_services(hass)
return True
async def async_unload_entry(hass, entry):
return True
async def async_unload_entry(hass: HomeAssistant, entry):
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, ["sensor"])
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok

View File

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

View File

@@ -0,0 +1,22 @@
from homeassistant.components.sensor import SensorEntity
from .const import DOMAIN, CONF_ACCOUNT_NAME
async def async_setup_entry(hass, entry, async_add_entities):
"""Add a sensor for each WhatsApp account."""
async_add_entities([WhatsAppAccountEntity(entry)], True)
class WhatsAppAccountEntity(SensorEntity):
"""Representation of a WhatsApp Account as an entity."""
def __init__(self, entry):
self._entry = entry
self._attr_name = f"WhatsApp {entry.title}"
self._attr_unique_id = f"{entry.entry_id}_status"
self._attr_icon = "mdi:whatsapp"
# Wir speichern die Nummer in den Attributen, damit der Service sie findet
self._attr_extra_state_attributes = {
"phone_number": entry.data.get("phone_number")
}
@property
def state(self):
return "Ready"

View File

@@ -0,0 +1,43 @@
import requests
import logging
from homeassistant.core import HomeAssistant, ServiceCall
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_services(hass: HomeAssistant):
async def handle_send_message(call: ServiceCall):
message = call.data.get("message")
target_entity = call.data.get("recipient")
targets = []
# 1. Fall: Broadcast an alle
if target_entity == "all":
entities = hass.states.async_all("sensor")
for entity in entities:
if entity.entity_id.startswith("sensor.whatsapp_"):
targets.append(entity.attributes.get("phone_number"))
# 2. Fall: Einzelne Entity ausgewählt
else:
state = hass.states.get(target_entity)
if state:
num = state.attributes.get("phone_number")
if num:
targets.append(num)
else:
# Fallback für manuelle Eingabe in YAML
targets.append(target_entity)
for num in targets:
url = "http://866fd2eb-whatsapp-bridge:3000/send"
try:
await hass.async_add_executor_job(
lambda: requests.post(url, json={"number": num, "message": message}, timeout=10)
)
_LOGGER.info("Sent to %s", num)
except Exception as e:
_LOGGER.error("Error: %s", str(e))
hass.services.async_register(DOMAIN, "send_message", handle_send_message)

View File

@@ -1,30 +1,17 @@
send_message:
name: Send Message
description: Sends a WhatsApp message via the Bahmcloud Bridge.
description: Sends a WhatsApp message via the Bridge.
fields:
account:
name: Account Profile
description: The name of a saved profile (e.g., Max). Leave empty if using a manual number.
example: "Max"
recipient:
name: Recipient
description: Select an account entity or type a manual number.
required: true
selector:
text:
number:
name: Manual Number
description: "Direct phone number (Format: 491701234567). Overwrites the Account field."
example: "491701234567"
selector:
text:
text: {}
message:
name: Message
description: The content of your WhatsApp message.
description: The content of your message.
required: true
example: "The garage door is open!"
selector:
text:
multiline: true
all_accounts:
name: Send to All
description: If enabled, the message is sent to all registered profiles.
default: false
selector:
boolean:
multiline: true