1 """Integrate with NO-IP Dynamic DNS service."""
5 from datetime
import datetime, timedelta
9 from aiohttp.hdrs
import AUTHORIZATION, USER_AGENT
10 import voluptuous
as vol
16 async_get_clientsession,
22 _LOGGER = logging.getLogger(__name__)
27 EMAIL =
"hello@home-assistant.io"
34 "nohost":
"Hostname supplied does not exist under specified account",
35 "badauth":
"Invalid username password combination",
36 "badagent":
"Client disabled",
37 "!donator":
"An update request was sent with a feature that is not available",
38 "abuse":
"Username is blocked due to abuse",
39 "911":
"A fatal error on NO-IP's side such as a database outage",
42 UPDATE_URL =
"https://dynupdate.no-ip.com/nic/update"
43 HA_USER_AGENT = f
"{SERVER_SOFTWARE} {EMAIL}"
45 CONFIG_SCHEMA = vol.Schema(
49 vol.Required(CONF_DOMAIN): cv.string,
50 vol.Required(CONF_USERNAME): cv.string,
51 vol.Required(CONF_PASSWORD): cv.string,
52 vol.Optional(CONF_TIMEOUT, default=DEFAULT_TIMEOUT): cv.positive_int,
56 extra=vol.ALLOW_EXTRA,
60 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
61 """Initialize the NO-IP component."""
62 domain = config[DOMAIN].
get(CONF_DOMAIN)
63 user = config[DOMAIN].
get(CONF_USERNAME)
64 password = config[DOMAIN].
get(CONF_PASSWORD)
65 timeout = config[DOMAIN].
get(CONF_TIMEOUT)
67 auth_str = base64.b64encode(f
"{user}:{password}".encode())
71 result = await
_update_no_ip(hass, session, domain, auth_str, timeout)
76 async
def update_domain_interval(now: datetime) ->
None:
77 """Update the NO-IP entry."""
87 session: aiohttp.ClientSession,
95 params = {
"hostname": domain}
97 headers: dict[str, str] = {
98 AUTHORIZATION: f
"Basic {auth_str.decode('utf-8')}",
99 USER_AGENT: HA_USER_AGENT,
103 async
with asyncio.timeout(timeout):
104 resp = await session.get(url, params=params, headers=headers)
105 body = await resp.text()
107 if body.startswith((
"good",
"nochg")):
108 _LOGGER.debug(
"Updating NO-IP success: %s", domain)
112 "Updating NO-IP failed: %s => %s", domain, NO_IP_ERRORS[body.strip()]
115 except aiohttp.ClientError:
116 _LOGGER.warning(
"Can't connect to NO-IP API")
119 _LOGGER.warning(
"Timeout from NO-IP API for domain: %s", domain)
web.Response get(self, web.Request request, str config_key)
bool async_setup(HomeAssistant hass, ConfigType config)
bool _update_no_ip(HomeAssistant hass, aiohttp.ClientSession session, str domain, bytes auth_str, int timeout)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)