Files
Whatsapp-Bridge-Integration/custom_components/whatsapp_bridge_integration/sensor.py

22 lines
847 B
Python

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"