custom_components/whatsapp_bridge_integration/sensor.py hinzugefügt
This commit is contained in:
22
custom_components/whatsapp_bridge_integration/sensor.py
Normal file
22
custom_components/whatsapp_bridge_integration/sensor.py
Normal 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"
|
||||||
Reference in New Issue
Block a user