1 """The drop_connect integration."""
3 from __future__
import annotations
6 from typing
import TYPE_CHECKING
14 from .const
import CONF_DATA_TOPIC, CONF_DEVICE_TYPE, DOMAIN
15 from .coordinator
import DROPDeviceDataUpdateCoordinator
17 _LOGGER = logging.getLogger(__name__)
19 PLATFORMS: list[Platform] = [
20 Platform.BINARY_SENSOR,
28 """Set up DROP from a config entry."""
31 if not await mqtt.async_wait_for_mqtt_client(hass):
32 _LOGGER.error(
"MQTT integration is not available")
36 assert config_entry.unique_id
is not None
38 hass, config_entry.unique_id
42 def mqtt_callback(msg: ReceiveMessage) ->
None:
43 """Pass MQTT payload to DROP API parser."""
44 if drop_data_coordinator.drop_api.parse_drop_message(
45 msg.topic, msg.payload, msg.qos, msg.retain
47 drop_data_coordinator.async_set_updated_data(
None)
49 config_entry.async_on_unload(
50 await mqtt.async_subscribe(
51 hass, config_entry.data[CONF_DATA_TOPIC], mqtt_callback
55 "Entry %s (%s) subscribed to %s",
56 config_entry.unique_id,
57 config_entry.data[CONF_DEVICE_TYPE],
58 config_entry.data[CONF_DATA_TOPIC],
61 hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = drop_data_coordinator
62 await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
67 """Unload a config entry."""
68 if unload_ok := await hass.config_entries.async_unload_platforms(
69 config_entry, PLATFORMS
71 hass.data[DOMAIN].pop(config_entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry config_entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)