Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
42e59b46
Commit
42e59b46
authored
7 years ago
by
Fabian Affolter
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make host optional (#10063)
* Make host optional * Update test to reflect code changes
parent
e8a701ff
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/namecheapdns.py
+25
-16
25 additions, 16 deletions
homeassistant/components/namecheapdns.py
tests/components/test_namecheapdns.py
+7
-7
7 additions, 7 deletions
tests/components/test_namecheapdns.py
with
32 additions
and
23 deletions
homeassistant/components/namecheapdns.py
+
25
−
16
View file @
42e59b46
"""
Integrate with NamecheapDNS.
"""
"""
Integrate with namecheap DNS services.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/namecheapdns/
"""
import
asyncio
import
asyncio
from
datetime
import
timedelta
import
logging
import
logging
from
datetime
import
timedelta
import
voluptuous
as
vol
import
voluptuous
as
vol
from
homeassistant.const
import
CONF_HOST
,
CONF_ACCESS_TOKEN
,
CONF_DOMAIN
import
homeassistant.helpers.config_validation
as
cv
import
homeassistant.helpers.config_validation
as
cv
from
homeassistant.const
import
CONF_HOST
,
CONF_PASSWORD
,
CONF_DOMAIN
from
homeassistant.helpers.event
import
async_track_time_interval
from
homeassistant.helpers.event
import
async_track_time_interval
from
homeassistant.helpers.aiohttp_client
import
async_get_clientsession
from
homeassistant.helpers.aiohttp_client
import
async_get_clientsession
_LOGGER
=
logging
.
getLogger
(
__name__
)
DOMAIN
=
'
namecheapdns
'
DOMAIN
=
'
namecheapdns
'
UPDATE_URL
=
'
https://dynamicdns.park-your-domain.com/update
'
INTERVAL
=
timedelta
(
minutes
=
5
)
INTERVAL
=
timedelta
(
minutes
=
5
)
_LOGGER
=
logging
.
getLogger
(
__name__
)
UPDATE_URL
=
'
https://dynamicdns.park-your-domain.com/update
'
CONFIG_SCHEMA
=
vol
.
Schema
({
CONFIG_SCHEMA
=
vol
.
Schema
({
DOMAIN
:
vol
.
Schema
({
DOMAIN
:
vol
.
Schema
({
vol
.
Required
(
CONF_HOST
):
cv
.
string
,
vol
.
Required
(
CONF_DOMAIN
):
cv
.
string
,
vol
.
Required
(
CONF_DOMAIN
):
cv
.
string
,
vol
.
Required
(
CONF_ACCESS_TOKEN
):
cv
.
string
,
vol
.
Required
(
CONF_PASSWORD
):
cv
.
string
,
vol
.
Optional
(
CONF_HOST
,
default
=
'
@
'
):
cv
.
string
,
})
})
},
extra
=
vol
.
ALLOW_EXTRA
)
},
extra
=
vol
.
ALLOW_EXTRA
)
@asyncio.coroutine
@asyncio.coroutine
def
async_setup
(
hass
,
config
):
def
async_setup
(
hass
,
config
):
"""
Initialize the
N
amecheapDNS component.
"""
"""
Initialize the
n
amecheap
DNS component.
"""
host
=
config
[
DOMAIN
][
CONF_HOST
]
host
=
config
[
DOMAIN
][
CONF_HOST
]
domain
=
config
[
DOMAIN
][
CONF_DOMAIN
]
domain
=
config
[
DOMAIN
][
CONF_DOMAIN
]
token
=
config
[
DOMAIN
][
CONF_ACCESS_TOKEN
]
password
=
config
[
DOMAIN
][
CONF_PASSWORD
]
session
=
async_get_clientsession
(
hass
)
session
=
async_get_clientsession
(
hass
)
result
=
yield
from
_update_namecheapdns
(
session
,
host
,
domain
,
token
)
result
=
yield
from
_update_namecheapdns
(
session
,
host
,
domain
,
password
)
if
not
result
:
if
not
result
:
return
False
return
False
@asyncio.coroutine
@asyncio.coroutine
def
update_domain_interval
(
now
):
def
update_domain_interval
(
now
):
"""
Update the
N
amecheapDNS entry.
"""
"""
Update the
n
amecheap
DNS entry.
"""
yield
from
_update_namecheapdns
(
session
,
host
,
domain
,
token
)
yield
from
_update_namecheapdns
(
session
,
host
,
domain
,
password
)
async_track_time_interval
(
hass
,
update_domain_interval
,
INTERVAL
)
async_track_time_interval
(
hass
,
update_domain_interval
,
INTERVAL
)
...
@@ -48,14 +57,14 @@ def async_setup(hass, config):
...
@@ -48,14 +57,14 @@ def async_setup(hass, config):
@asyncio.coroutine
@asyncio.coroutine
def
_update_namecheapdns
(
session
,
host
,
domain
,
token
):
def
_update_namecheapdns
(
session
,
host
,
domain
,
password
):
"""
Update
N
amecheapDNS.
"""
"""
Update
n
amecheap
DNS
entry
.
"""
import
xml.etree.ElementTree
as
ET
import
xml.etree.ElementTree
as
ET
params
=
{
params
=
{
'
host
'
:
host
,
'
host
'
:
host
,
'
domain
'
:
domain
,
'
domain
'
:
domain
,
'
password
'
:
token
,
'
password
'
:
password
,
}
}
resp
=
yield
from
session
.
get
(
UPDATE_URL
,
params
=
params
)
resp
=
yield
from
session
.
get
(
UPDATE_URL
,
params
=
params
)
...
@@ -64,7 +73,7 @@ def _update_namecheapdns(session, host, domain, token):
...
@@ -64,7 +73,7 @@ def _update_namecheapdns(session, host, domain, token):
err_count
=
root
.
find
(
'
ErrCount
'
).
text
err_count
=
root
.
find
(
'
ErrCount
'
).
text
if
int
(
err_count
)
!=
0
:
if
int
(
err_count
)
!=
0
:
_LOGGER
.
warning
(
'
Updating
N
amecheap domain
%s
failed
'
,
domain
)
_LOGGER
.
warning
(
"
Updating
n
amecheap domain failed
: %s
"
,
domain
)
return
False
return
False
return
True
return
True
This diff is collapsed.
Click to expand it.
tests/components/test_namecheapdns.py
+
7
−
7
View file @
42e59b46
...
@@ -12,7 +12,7 @@ from tests.common import async_fire_time_changed
...
@@ -12,7 +12,7 @@ from tests.common import async_fire_time_changed
HOST
=
'
test
'
HOST
=
'
test
'
DOMAIN
=
'
bla
'
DOMAIN
=
'
bla
'
TOKEN
=
'
abcdefgh
'
PASSWORD
=
'
abcdefgh
'
@pytest.fixture
@pytest.fixture
...
@@ -21,7 +21,7 @@ def setup_namecheapdns(hass, aioclient_mock):
...
@@ -21,7 +21,7 @@ def setup_namecheapdns(hass, aioclient_mock):
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
password
'
:
TOKEN
'
password
'
:
PASSWORD
,
},
text
=
'
<interface-response><ErrCount>0</ErrCount></interface-response>
'
)
},
text
=
'
<interface-response><ErrCount>0</ErrCount></interface-response>
'
)
hass
.
loop
.
run_until_complete
(
async_setup_component
(
hass
.
loop
.
run_until_complete
(
async_setup_component
(
...
@@ -29,7 +29,7 @@ def setup_namecheapdns(hass, aioclient_mock):
...
@@ -29,7 +29,7 @@ def setup_namecheapdns(hass, aioclient_mock):
'
namecheapdns
'
:
{
'
namecheapdns
'
:
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
access_token
'
:
TOKEN
'
password
'
:
PASSWORD
,
}
}
}))
}))
...
@@ -40,14 +40,14 @@ def test_setup(hass, aioclient_mock):
...
@@ -40,14 +40,14 @@ def test_setup(hass, aioclient_mock):
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
password
'
:
TOKEN
'
password
'
:
PASSWORD
},
text
=
'
<interface-response><ErrCount>0</ErrCount></interface-response>
'
)
},
text
=
'
<interface-response><ErrCount>0</ErrCount></interface-response>
'
)
result
=
yield
from
async_setup_component
(
hass
,
namecheapdns
.
DOMAIN
,
{
result
=
yield
from
async_setup_component
(
hass
,
namecheapdns
.
DOMAIN
,
{
'
namecheapdns
'
:
{
'
namecheapdns
'
:
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
access_token
'
:
TOKEN
'
password
'
:
PASSWORD
,
}
}
})
})
assert
result
assert
result
...
@@ -64,14 +64,14 @@ def test_setup_fails_if_update_fails(hass, aioclient_mock):
...
@@ -64,14 +64,14 @@ def test_setup_fails_if_update_fails(hass, aioclient_mock):
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
aioclient_mock
.
get
(
namecheapdns
.
UPDATE_URL
,
params
=
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
password
'
:
TOKEN
'
password
'
:
PASSWORD
,
},
text
=
'
<interface-response><ErrCount>1</ErrCount></interface-response>
'
)
},
text
=
'
<interface-response><ErrCount>1</ErrCount></interface-response>
'
)
result
=
yield
from
async_setup_component
(
hass
,
namecheapdns
.
DOMAIN
,
{
result
=
yield
from
async_setup_component
(
hass
,
namecheapdns
.
DOMAIN
,
{
'
namecheapdns
'
:
{
'
namecheapdns
'
:
{
'
host
'
:
HOST
,
'
host
'
:
HOST
,
'
domain
'
:
DOMAIN
,
'
domain
'
:
DOMAIN
,
'
access_token
'
:
TOKEN
'
password
'
:
PASSWORD
,
}
}
})
})
assert
not
result
assert
not
result
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment