diff --git a/custom_components/gsm_call/notify.py b/custom_components/gsm_call/notify.py index c2a5537..8f0b557 100644 --- a/custom_components/gsm_call/notify.py +++ b/custom_components/gsm_call/notify.py @@ -81,24 +81,21 @@ async def async_send_message(self, _message="", **kwargs): _LOGGER.info("Already making a voice call") return - try: - await self.connect() - - for target in targets: - phone_number_re = re.compile(r"^\+?[1-9]\d{1,14}$") - if not phone_number_re.match(target): - raise Exception("Invalid phone number") - phone_number = re.sub(r"\D", "", target) - - call_state = await self.dialer.dial(self.modem, phone_number) - self.hass.bus.async_fire( - EVENT_GSM_CALL_ENDED, - {ATTR_PHONE_NUMBER: phone_number, ATTR_REASON: call_state}, - ) - except Exception as ex: - _LOGGER.exception(ex) - finally: - await self.terminate() + await self.connect() + + for target in targets: + phone_number_re = re.compile(r"^\+?[1-9]\d{1,14}$") + if not phone_number_re.match(target): + raise Exception("Invalid phone number") + phone_number = re.sub(r"\D", "", target) + + call_state = await self.dialer.dial(self.modem, phone_number) + self.hass.bus.async_fire( + EVENT_GSM_CALL_ENDED, + {ATTR_PHONE_NUMBER: phone_number, ATTR_REASON: call_state}, + ) + + await self.terminate() async def connect(self): _LOGGER.debug(f"Connecting to {self.device_path}...")