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
7516db36
Unverified
Commit
7516db36
authored
3 years ago
by
J. Nick Koston
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Avoid circular import in network integration (#58655)
parent
c6157d55
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/network/__init__.py
+6
-55
6 additions, 55 deletions
homeassistant/components/network/__init__.py
homeassistant/components/network/websocket.py
+66
-0
66 additions, 0 deletions
homeassistant/components/network/websocket.py
with
72 additions
and
55 deletions
homeassistant/components/network/__init__.py
+
6
−
55
View file @
7516db36
...
...
@@ -4,22 +4,12 @@ from __future__ import annotations
from
ipaddress
import
IPv4Address
,
IPv6Address
,
ip_interface
import
logging
import
voluptuous
as
vol
from
homeassistant.components
import
websocket_api
from
homeassistant.components.websocket_api.connection
import
ActiveConnection
from
homeassistant.core
import
HomeAssistant
,
callback
from
homeassistant.helpers.typing
import
ConfigType
from
homeassistant.loader
import
bind_hass
from
.
import
util
from
.const
import
(
ATTR_ADAPTERS
,
ATTR_CONFIGURED_ADAPTERS
,
DOMAIN
,
IPV4_BROADCAST_ADDR
,
NETWORK_CONFIG_SCHEMA
,
)
from
.const
import
DOMAIN
,
IPV4_BROADCAST_ADDR
from
.models
import
Adapter
from
.network
import
Network
...
...
@@ -107,50 +97,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
_LOGGER
.
debug
(
"
Adapters: %s
"
,
network
.
adapters
)
websocket_api
.
async_register_command
(
hass
,
websocket_network_adapters
)
websocket_api
.
async_register_command
(
hass
,
websocket_network_adapters_configure
)
return
True
@websocket_api.require_admin
@websocket_api.websocket_command
({
vol
.
Required
(
"
type
"
):
"
network
"
})
@websocket_api.async_response
async
def
websocket_network_adapters
(
hass
:
HomeAssistant
,
connection
:
ActiveConnection
,
msg
:
dict
,
)
->
None
:
"""
Return network preferences.
"""
network
:
Network
=
hass
.
data
[
DOMAIN
]
connection
.
send_result
(
msg
[
"
id
"
],
{
ATTR_ADAPTERS
:
network
.
adapters
,
ATTR_CONFIGURED_ADAPTERS
:
network
.
configured_adapters
,
},
# Avoid circular issue: http->network->websocket_api->http
from
.websocket
import
(
# pylint: disable=import-outside-toplevel
async_register_websocket_commands
,
)
async_register_websocket_commands
(
hass
)
@websocket_api.require_admin
@websocket_api.websocket_command
(
{
vol
.
Required
(
"
type
"
):
"
network/configure
"
,
vol
.
Required
(
"
config
"
,
default
=
{}):
NETWORK_CONFIG_SCHEMA
,
}
)
@websocket_api.async_response
async
def
websocket_network_adapters_configure
(
hass
:
HomeAssistant
,
connection
:
ActiveConnection
,
msg
:
dict
,
)
->
None
:
"""
Update network config.
"""
network
:
Network
=
hass
.
data
[
DOMAIN
]
await
network
.
async_reconfig
(
msg
[
"
config
"
])
connection
.
send_result
(
msg
[
"
id
"
],
{
ATTR_CONFIGURED_ADAPTERS
:
network
.
configured_adapters
},
)
return
True
This diff is collapsed.
Click to expand it.
homeassistant/components/network/websocket.py
0 → 100644
+
66
−
0
View file @
7516db36
"""
The Network Configuration integration websocket commands.
"""
from
__future__
import
annotations
import
voluptuous
as
vol
from
homeassistant.components
import
websocket_api
from
homeassistant.components.websocket_api.connection
import
ActiveConnection
from
homeassistant.core
import
HomeAssistant
,
callback
from
.const
import
(
ATTR_ADAPTERS
,
ATTR_CONFIGURED_ADAPTERS
,
DOMAIN
,
NETWORK_CONFIG_SCHEMA
,
)
from
.network
import
Network
@callback
def
async_register_websocket_commands
(
hass
:
HomeAssistant
)
->
None
:
"""
Register network websocket commands.
"""
websocket_api
.
async_register_command
(
hass
,
websocket_network_adapters
)
websocket_api
.
async_register_command
(
hass
,
websocket_network_adapters_configure
)
@websocket_api.require_admin
@websocket_api.websocket_command
({
vol
.
Required
(
"
type
"
):
"
network
"
})
@websocket_api.async_response
async
def
websocket_network_adapters
(
hass
:
HomeAssistant
,
connection
:
ActiveConnection
,
msg
:
dict
,
)
->
None
:
"""
Return network preferences.
"""
network
:
Network
=
hass
.
data
[
DOMAIN
]
connection
.
send_result
(
msg
[
"
id
"
],
{
ATTR_ADAPTERS
:
network
.
adapters
,
ATTR_CONFIGURED_ADAPTERS
:
network
.
configured_adapters
,
},
)
@websocket_api.require_admin
@websocket_api.websocket_command
(
{
vol
.
Required
(
"
type
"
):
"
network/configure
"
,
vol
.
Required
(
"
config
"
,
default
=
{}):
NETWORK_CONFIG_SCHEMA
,
}
)
@websocket_api.async_response
async
def
websocket_network_adapters_configure
(
hass
:
HomeAssistant
,
connection
:
ActiveConnection
,
msg
:
dict
,
)
->
None
:
"""
Update network config.
"""
network
:
Network
=
hass
.
data
[
DOMAIN
]
await
network
.
async_reconfig
(
msg
[
"
config
"
])
connection
.
send_result
(
msg
[
"
id
"
],
{
ATTR_CONFIGURED_ADAPTERS
:
network
.
configured_adapters
},
)
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