Skip to content

Commit

Permalink
Do not catch exceptions and let HASS handle them
Browse files Browse the repository at this point in the history
  • Loading branch information
black-roland committed Nov 12, 2024
1 parent 30edca9 commit b55542e
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions custom_components/gsm_call/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}...")
Expand Down

0 comments on commit b55542e

Please sign in to comment.