diff --git a/custom_components/whatsapp_bridge_integration/sensor.py b/custom_components/whatsapp_bridge_integration/sensor.py index b46c6c1..c7bf63f 100644 --- a/custom_components/whatsapp_bridge_integration/sensor.py +++ b/custom_components/whatsapp_bridge_integration/sensor.py @@ -1,22 +1,44 @@ from homeassistant.components.sensor import SensorEntity -from .const import DOMAIN, CONF_ACCOUNT_NAME +from .const import DOMAIN async def async_setup_entry(hass, entry, async_add_entities): - """Add a sensor for each WhatsApp account.""" - async_add_entities([WhatsAppAccountEntity(entry)], True) + """Add sensors for WhatsApp accounts and a global broadcast sensor.""" + entities = [WhatsAppAccountEntity(entry)] + + # Wir prüfen, ob die Broadcast-Entität schon existiert + # Falls nicht, legen wir sie einmalig an + if not hass.data[DOMAIN].get("broadcast_registered"): + entities.append(WhatsAppBroadcastEntity()) + hass.data[DOMAIN]["broadcast_registered"] = True + + async_add_entities(entities, True) class WhatsAppAccountEntity(SensorEntity): - """Representation of a WhatsApp Account as an entity.""" + """Individual Account (e.g., Rene, Work).""" 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") + "phone_number": entry.data.get("phone_number"), + "is_broadcast": False } @property def state(self): - return "Ready" \ No newline at end of file + return "Ready" + +class WhatsAppBroadcastEntity(SensorEntity): + """Virtual 'All Accounts' Entity.""" + def __init__(self): + self._attr_name = "WhatsApp Broadcast (All)" + self._attr_unique_id = "whatsapp_bridge_broadcast_all" + self._attr_icon = "mdi:whatsapp-arrow-up" + self._attr_extra_state_attributes = { + "is_broadcast": True + } + + @property + def state(self): + return "Global" \ No newline at end of file