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
ca0d4226
Commit
ca0d4226
authored
6 years ago
by
Paulus Schoutsen
Committed by
Paulus Schoutsen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Decouple emulated hue from http server (#15530)
parent
dff2e4eb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/emulated_hue/__init__.py
+33
-27
33 additions, 27 deletions
homeassistant/components/emulated_hue/__init__.py
with
33 additions
and
27 deletions
homeassistant/components/emulated_hue/__init__.py
+
33
−
27
View file @
ca0d4226
...
...
@@ -6,6 +6,7 @@ https://home-assistant.io/components/emulated_hue/
"""
import
logging
from
aiohttp
import
web
import
voluptuous
as
vol
from
homeassistant
import
util
...
...
@@ -13,7 +14,6 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START
,
EVENT_HOMEASSISTANT_STOP
,
)
from
homeassistant.components.http
import
REQUIREMENTS
# NOQA
from
homeassistant.components.http
import
HomeAssistantHTTP
from
homeassistant.exceptions
import
HomeAssistantError
from
homeassistant.helpers.deprecation
import
get_deprecated
import
homeassistant.helpers.config_validation
as
cv
...
...
@@ -85,28 +85,17 @@ def setup(hass, yaml_config):
"""
Activate the emulated_hue component.
"""
config
=
Config
(
hass
,
yaml_config
.
get
(
DOMAIN
,
{}))
server
=
HomeAssistantHTTP
(
hass
,
server_host
=
config
.
host_ip_addr
,
server_port
=
config
.
listen_port
,
api_password
=
None
,
ssl_certificate
=
None
,
ssl_peer_certificate
=
None
,
ssl_key
=
None
,
cors_origins
=
None
,
use_x_forwarded_for
=
False
,
trusted_proxies
=
[],
trusted_networks
=
[],
login_threshold
=
0
,
is_ban_enabled
=
False
)
server
.
register_view
(
DescriptionXmlView
(
config
))
server
.
register_view
(
HueUsernameView
)
server
.
register_view
(
HueAllLightsStateView
(
config
))
server
.
register_view
(
HueOneLightStateView
(
config
))
server
.
register_view
(
HueOneLightChangeView
(
config
))
server
.
register_view
(
HueGroupView
(
config
))
app
=
web
.
Application
()
app
[
'
hass
'
]
=
hass
handler
=
None
server
=
None
DescriptionXmlView
(
config
).
register
(
app
.
router
)
HueUsernameView
().
register
(
app
.
router
)
HueAllLightsStateView
(
config
).
register
(
app
.
router
)
HueOneLightStateView
(
config
).
register
(
app
.
router
)
HueOneLightChangeView
(
config
).
register
(
app
.
router
)
HueGroupView
(
config
).
register
(
app
.
router
)
upnp_listener
=
UPNPResponderThread
(
config
.
host_ip_addr
,
config
.
listen_port
,
...
...
@@ -116,14 +105,31 @@ def setup(hass, yaml_config):
async
def
stop_emulated_hue_bridge
(
event
):
"""
Stop the emulated hue bridge.
"""
upnp_listener
.
stop
()
await
server
.
stop
()
if
server
:
server
.
close
()
await
server
.
wait_closed
()
await
app
.
shutdown
()
if
handler
:
await
handler
.
shutdown
(
10
)
await
app
.
cleanup
()
async
def
start_emulated_hue_bridge
(
event
):
"""
Start the emulated hue bridge.
"""
upnp_listener
.
start
()
await
server
.
start
()
hass
.
bus
.
async_listen_once
(
EVENT_HOMEASSISTANT_STOP
,
stop_emulated_hue_bridge
)
nonlocal
handler
nonlocal
server
handler
=
app
.
make_handler
(
loop
=
hass
.
loop
)
try
:
server
=
await
hass
.
loop
.
create_server
(
handler
,
config
.
host_ip_addr
,
config
.
listen_port
)
except
OSError
as
error
:
_LOGGER
.
error
(
"
Failed to create HTTP server at port %d: %s
"
,
config
.
listen_port
,
error
)
else
:
hass
.
bus
.
async_listen_once
(
EVENT_HOMEASSISTANT_STOP
,
stop_emulated_hue_bridge
)
hass
.
bus
.
listen_once
(
EVENT_HOMEASSISTANT_START
,
start_emulated_hue_bridge
)
...
...
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