custom_components/whatsapp_bridge_integration/__init__.py aktualisiert
0.2.2
This commit is contained in:
@@ -9,22 +9,34 @@ async def async_setup(hass: HomeAssistant, config: dict):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry):
|
async def async_setup_entry(hass: HomeAssistant, entry):
|
||||||
"""Set up entry, create specific contact device and forward to sensor platform."""
|
"""Set up entry, create specific contact device, central hub and forward to platforms."""
|
||||||
# Lege die Daten im hass-Objekt ab
|
|
||||||
hass.data.setdefault(DOMAIN, {})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
hass.data[DOMAIN][entry.entry_id] = entry.data
|
hass.data[DOMAIN][entry.entry_id] = entry.data
|
||||||
|
|
||||||
# 1. Eigenes Gerät SPEZIFISCH für diesen Account/Kontakt anlegen
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
|
|
||||||
|
# 1. Eigenes Gerät SPEZIFISCH für diesen Account/Kontakt anlegen
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
identifiers={(DOMAIN, entry.entry_id)}, # Einzigartig pro Eintrag
|
identifiers={(DOMAIN, entry.entry_id)}, # Einzigartig pro Eintrag
|
||||||
name=f"WhatsApp {entry.title}",
|
name=f"WhatsApp {entry.title}",
|
||||||
manufacturer="Bahmcloud",
|
manufacturer="Bahmcloud",
|
||||||
model="Kontakt-Endpunkt",
|
model="Kontakt-Endpunkt",
|
||||||
sw_version="0.2.1",
|
sw_version="0.2.2",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 2. Zentralen System-Hub NUR EINMALIG anlegen (wird an den ersten geladenen Account gekoppelt)
|
||||||
|
if not hass.data[DOMAIN].get("hub_device_created"):
|
||||||
|
device_registry.async_get_or_create(
|
||||||
|
config_entry_id=entry.entry_id,
|
||||||
|
identifiers={(DOMAIN, "global_bridge_hub")},
|
||||||
|
name="WhatsApp Bridge Hub",
|
||||||
|
manufacturer="Bahmcloud",
|
||||||
|
model="Bridge Server",
|
||||||
|
sw_version="0.2.2",
|
||||||
|
)
|
||||||
|
hass.data[DOMAIN]["hub_device_created"] = True
|
||||||
|
|
||||||
# Forward the setup to the sensor platform to create entities
|
# Forward the setup to the sensor platform to create entities
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
|
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user