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
10d08701
Unverified
Commit
10d08701
authored
3 years ago
by
epenet
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Use ZeroconfServiceInfo in plugwise (#60050)
parent
29761e6e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
homeassistant/components/plugwise/config_flow.py
+21
-14
21 additions, 14 deletions
homeassistant/components/plugwise/config_flow.py
tests/components/plugwise/test_config_flow.py
+15
-14
15 additions, 14 deletions
tests/components/plugwise/test_config_flow.py
with
36 additions
and
28 deletions
homeassistant/components/plugwise/config_flow.py
+
21
−
14
View file @
10d08701
"""
Config flow for Plugwise integration.
"""
from
__future__
import
annotations
import
logging
from
plugwise.exceptions
import
InvalidAuthentication
,
PlugwiseException
...
...
@@ -6,6 +8,7 @@ from plugwise.smile import Smile
import
voluptuous
as
vol
from
homeassistant
import
config_entries
,
core
,
exceptions
from
homeassistant.components
import
zeroconf
from
homeassistant.const
import
(
CONF_BASE
,
CONF_HOST
,
...
...
@@ -16,8 +19,8 @@ from homeassistant.const import (
CONF_USERNAME
,
)
from
homeassistant.core
import
callback
from
homeassistant.data_entry_flow
import
FlowResult
from
homeassistant.helpers.aiohttp_client
import
async_get_clientsession
from
homeassistant.helpers.typing
import
DiscoveryInfoType
from
.const
import
(
API
,
...
...
@@ -98,30 +101,34 @@ class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
def
__init__
(
self
):
"""
Initialize the Plugwise config flow.
"""
self
.
discovery_info
=
{}
self
.
discovery_info
:
zeroconf
.
ZeroconfServiceInfo
|
None
=
None
self
.
_username
:
str
=
DEFAULT_USERNAME
async
def
async_step_zeroconf
(
self
,
discovery_info
:
DiscoveryInfoType
):
async
def
async_step_zeroconf
(
self
,
discovery_info
:
zeroconf
.
ZeroconfServiceInfo
)
->
FlowResult
:
"""
Prepare configuration for a discovered Plugwise Smile.
"""
self
.
discovery_info
=
discovery_info
self
.
discovery_info
[
CONF_USERNAME
]
=
DEFAULT_USERNAME
_properties
=
self
.
discovery_info
.
get
(
"
properties
"
)
_properties
=
discovery_info
[
zeroconf
.
ATTR_PROPERTIES
]
# unique_id is needed here, to be able to determine whether the discovered device is known, or not.
unique_id
=
self
.
discovery_info
.
get
(
"
hostname
"
)
.
split
(
"
.
"
)[
0
]
unique_id
=
discovery_info
[
zeroconf
.
ATTR_HOSTNAME
]
.
split
(
"
.
"
)[
0
]
await
self
.
async_set_unique_id
(
unique_id
)
self
.
_abort_if_unique_id_configured
({
CONF_HOST
:
self
.
discovery_info
[
CONF_HOST
]})
self
.
_abort_if_unique_id_configured
(
{
CONF_HOST
:
discovery_info
[
zeroconf
.
ATTR_HOST
]}
)
if
DEFAULT_USERNAME
not
in
unique_id
:
self
.
discovery_info
[
CONF_USERNAME
]
=
STRETCH_USERNAME
self
.
_username
=
STRETCH_USERNAME
_product
=
_properties
.
get
(
"
product
"
,
None
)
_version
=
_properties
.
get
(
"
version
"
,
"
n/a
"
)
_name
=
f
"
{
ZEROCONF_MAP
.
get
(
_product
,
_product
)
}
v
{
_version
}
"
self
.
context
[
"
title_placeholders
"
]
=
{
CONF_HOST
:
self
.
discovery_info
[
CONF
_HOST
],
CONF_HOST
:
discovery_info
[
zeroconf
.
ATTR
_HOST
],
CONF_NAME
:
_name
,
CONF_PORT
:
self
.
discovery_info
[
CONF
_PORT
],
CONF_USERNAME
:
self
.
discovery_info
[
CONF_USERNAME
]
,
CONF_PORT
:
discovery_info
[
zeroconf
.
ATTR
_PORT
],
CONF_USERNAME
:
self
.
_username
,
}
return
await
self
.
async_step_user_gateway
()
...
...
@@ -136,9 +143,9 @@ class PlugwiseConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
user_input
.
pop
(
FLOW_TYPE
,
None
)
if
self
.
discovery_info
:
user_input
[
CONF_HOST
]
=
self
.
discovery_info
[
CONF
_HOST
]
user_input
[
CONF_PORT
]
=
self
.
discovery_info
[
CONF
_PORT
]
user_input
[
CONF_USERNAME
]
=
self
.
discovery_info
[
CONF_USERNAME
]
user_input
[
CONF_HOST
]
=
self
.
discovery_info
[
zeroconf
.
ATTR
_HOST
]
user_input
[
CONF_PORT
]
=
self
.
discovery_info
[
zeroconf
.
ATTR
_PORT
]
user_input
[
CONF_USERNAME
]
=
self
.
_username
try
:
api
=
await
validate_gw_input
(
self
.
hass
,
user_input
)
...
...
This diff is collapsed.
Click to expand it.
tests/components/plugwise/test_config_flow.py
+
15
−
14
View file @
10d08701
...
...
@@ -8,6 +8,7 @@ from plugwise.exceptions import (
)
import
pytest
from
homeassistant.components
import
zeroconf
from
homeassistant.components.plugwise.const
import
(
API
,
DEFAULT_PORT
,
...
...
@@ -39,28 +40,28 @@ TEST_PORT = 81
TEST_USERNAME
=
"
smile
"
TEST_USERNAME2
=
"
stretch
"
TEST_DISCOVERY
=
{
"
host
"
:
TEST_HOST
,
"
port
"
:
DEFAULT_PORT
,
"
hostname
"
:
f
"
{
TEST_HOSTNAME
}
.local.
"
,
"
server
"
:
f
"
{
TEST_HOSTNAME
}
.local.
"
,
"
properties
"
:
{
TEST_DISCOVERY
=
zeroconf
.
ZeroconfServiceInfo
(
host
=
TEST_HOST
,
port
=
DEFAULT_PORT
,
hostname
=
f
"
{
TEST_HOSTNAME
}
.local.
"
,
server
=
f
"
{
TEST_HOSTNAME
}
.local.
"
,
properties
=
{
"
product
"
:
"
smile
"
,
"
version
"
:
"
1.2.3
"
,
"
hostname
"
:
f
"
{
TEST_HOSTNAME
}
.local.
"
,
},
}
TEST_DISCOVERY2
=
{
"
host
"
:
TEST_HOST
,
"
port
"
:
DEFAULT_PORT
,
"
hostname
"
:
f
"
{
TEST_HOSTNAME2
}
.local.
"
,
"
server
"
:
f
"
{
TEST_HOSTNAME2
}
.local.
"
,
"
properties
"
:
{
)
TEST_DISCOVERY2
=
zeroconf
.
ZeroconfServiceInfo
(
host
=
TEST_HOST
,
port
=
DEFAULT_PORT
,
hostname
=
f
"
{
TEST_HOSTNAME2
}
.local.
"
,
server
=
f
"
{
TEST_HOSTNAME2
}
.local.
"
,
properties
=
{
"
product
"
:
"
stretch
"
,
"
version
"
:
"
1.2.3
"
,
"
hostname
"
:
f
"
{
TEST_HOSTNAME2
}
.local.
"
,
},
}
)
@pytest.fixture
(
name
=
"
mock_smile
"
)
...
...
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