Implemented tplink_lte components and notify service via SMS (#17111)
* Implemented tplink_lte components and notify service * Device discovery for the notify component * Improved the config schema. Small fixes * Improved login retry mechanism * Log successful connection only on retries * Removed CancelledError handlers and small fixes
This commit is contained in:
parent
922f34f72d
commit
1c3ef8be55
4 changed files with 206 additions and 0 deletions
50
homeassistant/components/notify/tplink_lte.py
Normal file
50
homeassistant/components/notify/tplink_lte.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
"""TP-Link LTE platform for notify component.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/notify.tplink_lte/
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import attr
|
||||
|
||||
from homeassistant.components.notify import (
|
||||
ATTR_TARGET, BaseNotificationService)
|
||||
|
||||
from ..tplink_lte import DATA_KEY
|
||||
|
||||
DEPENDENCIES = ['tplink_lte']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_get_service(hass, config, discovery_info=None):
|
||||
"""Get the notification service."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
return TplinkNotifyService(hass, discovery_info)
|
||||
|
||||
|
||||
@attr.s
|
||||
class TplinkNotifyService(BaseNotificationService):
|
||||
"""Implementation of a notification service."""
|
||||
|
||||
hass = attr.ib()
|
||||
config = attr.ib()
|
||||
|
||||
async def async_send_message(self, message="", **kwargs):
|
||||
"""Send a message to a user."""
|
||||
import tp_connected
|
||||
modem_data = self.hass.data[DATA_KEY].get_modem_data(self.config)
|
||||
if not modem_data:
|
||||
_LOGGER.error("No modem available")
|
||||
return
|
||||
|
||||
phone = self.config[ATTR_TARGET]
|
||||
targets = kwargs.get(ATTR_TARGET, phone)
|
||||
if targets and message:
|
||||
for target in targets:
|
||||
try:
|
||||
await modem_data.modem.sms(target, message)
|
||||
except tp_connected.Error:
|
||||
_LOGGER.error("Unable to send to %s", target)
|
Loading…
Add table
Add a link
Reference in a new issue