Example #1
0
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
    """Set up Modem Caller ID from a config entry."""
    device = entry.data[CONF_DEVICE]
    api = PhoneModem(device)
    try:
        await api.initialize(device)
    except EXCEPTIONS as ex:
        raise ConfigEntryNotReady(f"Unable to open port: {device}") from ex

    hass.data.setdefault(DOMAIN, {})[entry.entry_id] = {DATA_KEY_API: api}
    hass.config_entries.async_setup_platforms(entry, PLATFORMS)

    return True
Example #2
0
 async def validate_device_errors(self, dev_path: str,
                                  unique_id: str) -> dict[str, str] | None:
     """Handle common flow input validation."""
     self._async_abort_entries_match({CONF_DEVICE: dev_path})
     await self.async_set_unique_id(unique_id)
     self._abort_if_unique_id_configured(updates={CONF_DEVICE: dev_path})
     try:
         api = PhoneModem()
         await api.test(dev_path)
     except EXCEPTIONS:
         return {"base": "cannot_connect"}
     else:
         return None