2018-06-08 05:46:34 +00:00
|
|
|
"""Netgear LTE platform for notify component.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/notify.netgear_lte/
|
|
|
|
"""
|
|
|
|
|
2018-09-23 16:58:09 +00:00
|
|
|
import logging
|
|
|
|
|
2018-06-08 05:46:34 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
import attr
|
|
|
|
|
|
|
|
from homeassistant.components.notify import (
|
|
|
|
BaseNotificationService, ATTR_TARGET, PLATFORM_SCHEMA)
|
|
|
|
from homeassistant.const import CONF_HOST
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
|
|
|
|
from ..netgear_lte import DATA_KEY
|
|
|
|
|
|
|
|
|
|
|
|
DEPENDENCIES = ['netgear_lte']
|
|
|
|
|
2018-09-23 16:58:09 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-06-08 05:46:34 +00:00
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
|
|
vol.Optional(CONF_HOST): cv.string,
|
|
|
|
vol.Required(ATTR_TARGET): vol.All(cv.ensure_list, [cv.string]),
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
async def async_get_service(hass, config, discovery_info=None):
|
|
|
|
"""Get the notification service."""
|
2018-09-23 16:58:09 +00:00
|
|
|
return NetgearNotifyService(hass, config)
|
2018-06-08 05:46:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
@attr.s
|
|
|
|
class NetgearNotifyService(BaseNotificationService):
|
|
|
|
"""Implementation of a notification service."""
|
|
|
|
|
2018-09-23 16:58:09 +00:00
|
|
|
hass = attr.ib()
|
|
|
|
config = attr.ib()
|
2018-06-08 05:46:34 +00:00
|
|
|
|
|
|
|
async def async_send_message(self, message="", **kwargs):
|
|
|
|
"""Send a message to a user."""
|
2018-09-23 16:58:09 +00:00
|
|
|
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.get(ATTR_TARGET)
|
|
|
|
targets = kwargs.get(ATTR_TARGET, phone)
|
2018-06-08 05:46:34 +00:00
|
|
|
if targets and message:
|
|
|
|
for target in targets:
|
2018-09-23 16:58:09 +00:00
|
|
|
import eternalegypt
|
|
|
|
try:
|
|
|
|
await modem_data.modem.sms(target, message)
|
|
|
|
except eternalegypt.Error:
|
|
|
|
_LOGGER.error("Unable to send to %s", target)
|