1 """The pushbullet component."""
3 from __future__
import annotations
7 from pushbullet
import InvalidKeyError, PushBullet, PushbulletError
13 EVENT_HOMEASSISTANT_START,
21 from .api
import PushBulletNotificationProvider
22 from .const
import DATA_HASS_CONFIG, DOMAIN
24 PLATFORMS = [Platform.SENSOR]
26 _LOGGER = logging.getLogger(__name__)
28 CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
31 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
32 """Set up the pushbullet component."""
34 hass.data[DATA_HASS_CONFIG] = config
39 """Set up pushbullet from a config entry."""
42 pushbullet = await hass.async_add_executor_job(
43 PushBullet, entry.data[CONF_API_KEY]
45 except InvalidKeyError:
46 _LOGGER.error(
"Invalid API key for Pushbullet")
48 except PushbulletError
as err:
49 raise ConfigEntryNotReady
from err
52 hass.data.setdefault(DOMAIN, {})[entry.entry_id] = pb_provider
54 def start_listener(event: Event) ->
None:
55 """Start the listener thread."""
56 _LOGGER.debug(
"Starting listener for pushbullet")
59 hass.bus.async_listen_once(EVENT_HOMEASSISTANT_START, start_listener)
61 hass.async_create_task(
62 discovery.async_load_platform(
66 {CONF_NAME: entry.data[CONF_NAME],
"entry_id": entry.entry_id},
67 hass.data[DATA_HASS_CONFIG],
70 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
76 """Unload a config entry."""
77 if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
78 pb_provider: PushBulletNotificationProvider = hass.data[DOMAIN].pop(
81 await hass.async_add_executor_job(pb_provider.close)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup(HomeAssistant hass, ConfigType config)