Files
home-assistant-core/homeassistant/components/sms/gateway.py
T
Oscar CalvoandMartin Hjelmare 3f9e3d0905 Part 1: Support for config flow on SMS integration (#35995)
* Add support for config flow;Remove IO on main loop

* Remove not needed const

* Remove not needed method

* Small refactor

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/gateway.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/gammuasync.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Refactor gammu

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Fix pylint

* Apply PR feedback

* Update gammu version with async support

* Apply PR feedback

* Apply PR feedback

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Apply PR feedback

* Apply PR feedback

* Apply PR feedback

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/strings.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/strings.json

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/config_flow.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/sms/__init__.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Apply PR feedback

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2020-06-22 16:07:58 -07:00

43 lines
1.2 KiB
Python

"""The sms gateway to interact with a GSM modem."""
import logging
import gammu # pylint: disable=import-error, no-member
from gammu.asyncworker import ( # pylint: disable=import-error, no-member
GammuAsyncWorker,
)
_LOGGER = logging.getLogger(__name__)
class Gateway:
"""SMS gateway to interact with a GSM modem."""
def __init__(self, worker, hass):
"""Initialize the sms gateway."""
self._worker = worker
async def send_sms_async(self, message):
"""Send sms message via the worker."""
return await self._worker.send_sms_async(message)
async def get_imei_async(self):
"""Get the IMEI of the device."""
return await self._worker.get_imei_async()
async def terminate_async(self):
"""Terminate modem connection."""
return await self._worker.terminate_async()
async def create_sms_gateway(config, hass):
"""Create the sms gateway."""
try:
worker = GammuAsyncWorker()
worker.configure(config)
await worker.init_async()
gateway = Gateway(worker, hass)
return gateway
except gammu.GSMError as exc: # pylint: disable=no-member
_LOGGER.error("Failed to initialize, error %s", exc)
return None