1 """Support for Free Mobile SMS platform."""
3 from __future__
import annotations
5 from http
import HTTPStatus
8 from freesms
import FreeClient
9 import voluptuous
as vol
12 PLATFORM_SCHEMA
as NOTIFY_PLATFORM_SCHEMA,
13 BaseNotificationService,
20 _LOGGER = logging.getLogger(__name__)
22 PLATFORM_SCHEMA = NOTIFY_PLATFORM_SCHEMA.extend(
23 {vol.Required(CONF_USERNAME): cv.string, vol.Required(CONF_ACCESS_TOKEN): cv.string}
30 discovery_info: DiscoveryInfoType |
None =
None,
31 ) -> FreeSMSNotificationService:
32 """Get the Free Mobile SMS notification service."""
37 """Implement a notification service for the Free Mobile SMS service."""
40 """Initialize the service."""
41 self.
free_clientfree_client = FreeClient(username, access_token)
44 """Send a message to the Free Mobile user cell."""
45 resp = self.
free_clientfree_client.send_sms(message)
47 if resp.status_code == HTTPStatus.BAD_REQUEST:
48 _LOGGER.error(
"At least one parameter is missing")
49 elif resp.status_code == HTTPStatus.PAYMENT_REQUIRED:
50 _LOGGER.error(
"Too much SMS send in a few time")
51 elif resp.status_code == HTTPStatus.FORBIDDEN:
52 _LOGGER.error(
"Wrong Username/Password")
53 elif resp.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
54 _LOGGER.error(
"Server error, try later")
def send_message(self, message="", **kwargs)
def __init__(self, username, access_token)
FreeSMSNotificationService get_service(HomeAssistant hass, ConfigType config, DiscoveryInfoType|None discovery_info=None)