mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Remove yessssms integration (#43200)
This commit is contained in:
parent
9a21421807
commit
a6f47ac380
@ -518,7 +518,6 @@ homeassistant/components/yamaha_musiccast/* @jalmeroth
|
||||
homeassistant/components/yandex_transport/* @rishatik92 @devbis
|
||||
homeassistant/components/yeelight/* @rytilahti @zewelor @shenxn
|
||||
homeassistant/components/yeelightsunflower/* @lindsaymarkward
|
||||
homeassistant/components/yessssms/* @flowolf
|
||||
homeassistant/components/yi/* @bachya
|
||||
homeassistant/components/zeroconf/* @bdraco
|
||||
homeassistant/components/zerproc/* @emlove
|
||||
|
@ -1 +0,0 @@
|
||||
"""The yessssms component."""
|
@ -1,3 +0,0 @@
|
||||
"""Const for YesssSMS."""
|
||||
|
||||
CONF_PROVIDER = "provider"
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"domain": "yessssms",
|
||||
"name": "yesss! SMS",
|
||||
"documentation": "https://www.home-assistant.io/integrations/yessssms",
|
||||
"requirements": ["YesssSMS==0.4.1"],
|
||||
"codeowners": ["@flowolf"]
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
"""Support for the YesssSMS platform."""
|
||||
import logging
|
||||
|
||||
from YesssSMS import YesssSMS
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_RECIPIENT, CONF_USERNAME
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
from .const import CONF_PROVIDER
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
vol.Required(CONF_RECIPIENT): cv.string,
|
||||
vol.Optional(CONF_PROVIDER, default="YESSS"): cv.string,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
def get_service(hass, config, discovery_info=None):
|
||||
"""Get the YesssSMS notification service."""
|
||||
|
||||
try:
|
||||
yesss = YesssSMS(
|
||||
config[CONF_USERNAME], config[CONF_PASSWORD], provider=config[CONF_PROVIDER]
|
||||
)
|
||||
except YesssSMS.UnsupportedProviderError as ex:
|
||||
_LOGGER.error("Unknown provider: %s", ex)
|
||||
return None
|
||||
try:
|
||||
if not yesss.login_data_valid():
|
||||
_LOGGER.error(
|
||||
"Login data is not valid! Please double check your login data at %s",
|
||||
yesss.get_login_url(),
|
||||
)
|
||||
return None
|
||||
|
||||
_LOGGER.debug("Login data for '%s' valid", yesss.get_provider())
|
||||
except YesssSMS.ConnectionError:
|
||||
_LOGGER.warning(
|
||||
"Connection Error, could not verify login data for '%s'",
|
||||
yesss.get_provider(),
|
||||
)
|
||||
|
||||
_LOGGER.debug(
|
||||
"initialized; library version: %s, with %s",
|
||||
yesss.version(),
|
||||
yesss.get_provider(),
|
||||
)
|
||||
return YesssSMSNotificationService(yesss, config[CONF_RECIPIENT])
|
||||
|
||||
|
||||
class YesssSMSNotificationService(BaseNotificationService):
|
||||
"""Implement a notification service for the YesssSMS service."""
|
||||
|
||||
def __init__(self, client, recipient):
|
||||
"""Initialize the service."""
|
||||
self.yesss = client
|
||||
self._recipient = recipient
|
||||
|
||||
def send_message(self, message="", **kwargs):
|
||||
"""Send a SMS message via Yesss.at's website."""
|
||||
if self.yesss.account_is_suspended():
|
||||
# only retry to login after Home Assistant was restarted with (hopefully)
|
||||
# new login data.
|
||||
_LOGGER.error(
|
||||
"Account is suspended, cannot send SMS. "
|
||||
"Check your login data and restart Home Assistant"
|
||||
)
|
||||
return
|
||||
try:
|
||||
self.yesss.send(self._recipient, message)
|
||||
except self.yesss.NoRecipientError as ex:
|
||||
_LOGGER.error(
|
||||
"You need to provide a recipient for SMS notification: %s", ex
|
||||
)
|
||||
except self.yesss.EmptyMessageError as ex:
|
||||
_LOGGER.error("Cannot send empty SMS message: %s", ex)
|
||||
except self.yesss.SMSSendingError as ex:
|
||||
_LOGGER.error(ex)
|
||||
except self.yesss.ConnectionError as ex:
|
||||
_LOGGER.error(
|
||||
"Unable to connect to server of provider (%s): %s",
|
||||
self.yesss.get_provider(),
|
||||
ex,
|
||||
)
|
||||
except self.yesss.AccountSuspendedError as ex:
|
||||
_LOGGER.error(
|
||||
"Wrong login credentials!! Verify correct credentials and "
|
||||
"restart Home Assistant: %s",
|
||||
ex,
|
||||
)
|
||||
except self.yesss.LoginError as ex:
|
||||
_LOGGER.error("Wrong login credentials: %s", ex)
|
||||
else:
|
||||
_LOGGER.info("SMS sent")
|
@ -95,9 +95,6 @@ WSDiscovery==2.0.0
|
||||
# homeassistant.components.waze_travel_time
|
||||
WazeRouteCalculator==0.12
|
||||
|
||||
# homeassistant.components.yessssms
|
||||
YesssSMS==0.4.1
|
||||
|
||||
# homeassistant.components.abode
|
||||
abodepy==1.1.0
|
||||
|
||||
|
@ -38,9 +38,6 @@ RtmAPI==0.7.2
|
||||
# homeassistant.components.onvif
|
||||
WSDiscovery==2.0.0
|
||||
|
||||
# homeassistant.components.yessssms
|
||||
YesssSMS==0.4.1
|
||||
|
||||
# homeassistant.components.abode
|
||||
abodepy==1.1.0
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
"""Tests for the yessssms component."""
|
@ -1,367 +0,0 @@
|
||||
"""The tests for the notify yessssms platform."""
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.yessssms.const import CONF_PROVIDER
|
||||
import homeassistant.components.yessssms.notify as yessssms
|
||||
from homeassistant.const import (
|
||||
CONF_PASSWORD,
|
||||
CONF_RECIPIENT,
|
||||
CONF_USERNAME,
|
||||
HTTP_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.async_mock import patch
|
||||
|
||||
|
||||
@pytest.fixture(name="config")
|
||||
def config_data():
|
||||
"""Set valid config data."""
|
||||
config = {
|
||||
"notify": {
|
||||
"platform": "yessssms",
|
||||
"name": "sms",
|
||||
CONF_USERNAME: "06641234567",
|
||||
CONF_PASSWORD: "secretPassword",
|
||||
CONF_RECIPIENT: "06509876543",
|
||||
CONF_PROVIDER: "educom",
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
||||
|
||||
@pytest.fixture(name="valid_settings")
|
||||
def init_valid_settings(hass, config):
|
||||
"""Initialize component with valid settings."""
|
||||
return async_setup_component(hass, "notify", config)
|
||||
|
||||
|
||||
@pytest.fixture(name="invalid_provider_settings")
|
||||
def init_invalid_provider_settings(hass, config):
|
||||
"""Set invalid provider data and initialize component."""
|
||||
config["notify"][CONF_PROVIDER] = "FantasyMobile" # invalid provider
|
||||
return async_setup_component(hass, "notify", config)
|
||||
|
||||
|
||||
@pytest.fixture(name="invalid_login_data")
|
||||
def mock_invalid_login_data():
|
||||
"""Mock invalid login data."""
|
||||
path = "homeassistant.components.yessssms.notify.YesssSMS.login_data_valid"
|
||||
with patch(path, return_value=False):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="valid_login_data")
|
||||
def mock_valid_login_data():
|
||||
"""Mock valid login data."""
|
||||
path = "homeassistant.components.yessssms.notify.YesssSMS.login_data_valid"
|
||||
with patch(path, return_value=True):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.fixture(name="connection_error")
|
||||
def mock_connection_error():
|
||||
"""Mock a connection error."""
|
||||
path = "homeassistant.components.yessssms.notify.YesssSMS.login_data_valid"
|
||||
with patch(path, side_effect=yessssms.YesssSMS.ConnectionError()):
|
||||
yield
|
||||
|
||||
|
||||
async def test_unsupported_provider_error(hass, caplog, invalid_provider_settings):
|
||||
"""Test for error on unsupported provider."""
|
||||
await invalid_provider_settings
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert (
|
||||
"Unknown provider: provider (fantasymobile) is not known to YesssSMS"
|
||||
in record.message
|
||||
)
|
||||
assert (
|
||||
"Unknown provider: provider (fantasymobile) is not known to YesssSMS"
|
||||
in caplog.text
|
||||
)
|
||||
assert not hass.services.has_service("notify", "sms")
|
||||
|
||||
|
||||
async def test_false_login_data_error(hass, caplog, valid_settings, invalid_login_data):
|
||||
"""Test login data check error."""
|
||||
await valid_settings
|
||||
assert not hass.services.has_service("notify", "sms")
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert (
|
||||
"Login data is not valid! Please double check your login data at"
|
||||
in record.message
|
||||
)
|
||||
|
||||
|
||||
async def test_init_success(hass, caplog, valid_settings, valid_login_data):
|
||||
"""Test for successful init of yessssms."""
|
||||
caplog.set_level(logging.DEBUG)
|
||||
await valid_settings
|
||||
assert hass.services.has_service("notify", "sms")
|
||||
messages = []
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "DEBUG"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
messages.append(record.message)
|
||||
assert "Login data for 'educom' valid" in messages[0]
|
||||
assert (
|
||||
"initialized; library version: {}".format(yessssms.YesssSMS("", "").version())
|
||||
in messages[1]
|
||||
)
|
||||
|
||||
|
||||
async def test_connection_error_on_init(hass, caplog, valid_settings, connection_error):
|
||||
"""Test for connection error on init."""
|
||||
caplog.set_level(logging.DEBUG)
|
||||
await valid_settings
|
||||
assert hass.services.has_service("notify", "sms")
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "WARNING"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert (
|
||||
"Connection Error, could not verify login data for 'educom'"
|
||||
in record.message
|
||||
)
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "DEBUG"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert (
|
||||
"initialized; library version: {}".format(
|
||||
yessssms.YesssSMS("", "").version()
|
||||
)
|
||||
in record.message
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(name="yessssms")
|
||||
def yessssms_init():
|
||||
"""Set up things to be run when tests are started."""
|
||||
login = "06641234567"
|
||||
passwd = "testpasswd"
|
||||
recipient = "06501234567"
|
||||
client = yessssms.YesssSMS(login, passwd)
|
||||
return yessssms.YesssSMSNotificationService(client, recipient)
|
||||
|
||||
|
||||
async def test_login_error(yessssms, requests_mock, caplog):
|
||||
"""Test login that fails."""
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
status_code=200,
|
||||
text="BlaBlaBla<strong>Login nicht erfolgreichBlaBla",
|
||||
)
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 1
|
||||
|
||||
|
||||
async def test_empty_message_error(yessssms, caplog):
|
||||
"""Test for an empty SMS message error."""
|
||||
message = ""
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert "Cannot send empty SMS message" in record.message
|
||||
|
||||
|
||||
async def test_error_account_suspended(yessssms, requests_mock, caplog):
|
||||
"""Test login that fails after multiple attempts."""
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
status_code=200,
|
||||
text="BlaBlaBla<strong>Login nicht erfolgreichBlaBla",
|
||||
)
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
yessssms.send_message(message)
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 1
|
||||
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
status_code=200,
|
||||
text="Wegen 3 ungültigen Login-Versuchen ist Ihr Account für "
|
||||
"eine Stunde gesperrt.",
|
||||
)
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 2
|
||||
|
||||
|
||||
async def test_error_account_suspended_2(yessssms, caplog):
|
||||
"""Test login that fails after multiple attempts."""
|
||||
message = "Testing YesssSMS platform :)"
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._suspended = True
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert "Account is suspended, cannot send SMS." in record.message
|
||||
|
||||
|
||||
async def test_send_message(yessssms, requests_mock, caplog):
|
||||
"""Test send message."""
|
||||
message = "Testing YesssSMS platform :)"
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
status_code=302,
|
||||
# pylint: disable=protected-access
|
||||
headers={"location": yessssms.yesss._kontomanager},
|
||||
)
|
||||
# pylint: disable=protected-access
|
||||
login = yessssms.yesss._logindata["login_rufnummer"]
|
||||
requests_mock.get(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._kontomanager,
|
||||
status_code=200,
|
||||
text=f"test...{login}</a>",
|
||||
)
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._websms_url,
|
||||
status_code=200,
|
||||
text="<h1>Ihre SMS wurde erfolgreich verschickt!</h1>",
|
||||
)
|
||||
requests_mock.get(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._logout_url,
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
with caplog.at_level(logging.INFO):
|
||||
yessssms.send_message(message)
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "INFO"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert "SMS sent" in record.message
|
||||
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 4
|
||||
assert (
|
||||
requests_mock.last_request.scheme
|
||||
+ "://"
|
||||
+ requests_mock.last_request.hostname
|
||||
+ requests_mock.last_request.path
|
||||
+ "?"
|
||||
+ requests_mock.last_request.query
|
||||
) in yessssms.yesss._logout_url # pylint: disable=protected-access
|
||||
|
||||
|
||||
async def test_no_recipient_error(yessssms, caplog):
|
||||
"""Test for missing/empty recipient."""
|
||||
message = "Testing YesssSMS platform :)"
|
||||
# pylint: disable=protected-access
|
||||
yessssms._recipient = ""
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert (
|
||||
"You need to provide a recipient for SMS notification" in record.message
|
||||
)
|
||||
|
||||
|
||||
async def test_sms_sending_error(yessssms, requests_mock, caplog):
|
||||
"""Test sms sending error."""
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
status_code=302,
|
||||
# pylint: disable=protected-access
|
||||
headers={"location": yessssms.yesss._kontomanager},
|
||||
)
|
||||
# pylint: disable=protected-access
|
||||
login = yessssms.yesss._logindata["login_rufnummer"]
|
||||
requests_mock.get(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._kontomanager,
|
||||
status_code=200,
|
||||
text=f"test...{login}</a>",
|
||||
)
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._websms_url,
|
||||
status_code=HTTP_INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 3
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert "YesssSMS: error sending SMS" in record.message
|
||||
|
||||
|
||||
async def test_connection_error(yessssms, requests_mock, caplog):
|
||||
"""Test connection error."""
|
||||
requests_mock.post(
|
||||
# pylint: disable=protected-access
|
||||
yessssms.yesss._login_url,
|
||||
exc=yessssms.yesss.ConnectionError,
|
||||
)
|
||||
|
||||
message = "Testing YesssSMS platform :)"
|
||||
|
||||
with caplog.at_level(logging.ERROR):
|
||||
yessssms.send_message(message)
|
||||
|
||||
assert requests_mock.called is True
|
||||
assert requests_mock.call_count == 1
|
||||
for record in caplog.records:
|
||||
if (
|
||||
record.levelname == "ERROR"
|
||||
and record.name == "homeassistant.components.yessssms.notify"
|
||||
):
|
||||
assert "cannot connect to provider" in record.message
|
Loading…
x
Reference in New Issue
Block a user