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
c9ac0b49
Unverified
Commit
c9ac0b49
authored
3 years ago
by
J. Nick Koston
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Prevent scene from restoring unavailable states (#67836)
parent
a75bbc79
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/scene/__init__.py
+6
-2
6 additions, 2 deletions
homeassistant/components/scene/__init__.py
tests/components/scene/test_init.py
+29
-0
29 additions, 0 deletions
tests/components/scene/test_init.py
with
35 additions
and
2 deletions
homeassistant/components/scene/__init__.py
+
6
−
2
View file @
c9ac0b49
...
@@ -10,7 +10,7 @@ import voluptuous as vol
...
@@ -10,7 +10,7 @@ import voluptuous as vol
from
homeassistant.components.light
import
ATTR_TRANSITION
from
homeassistant.components.light
import
ATTR_TRANSITION
from
homeassistant.config_entries
import
ConfigEntry
from
homeassistant.config_entries
import
ConfigEntry
from
homeassistant.const
import
CONF_PLATFORM
,
SERVICE_TURN_ON
from
homeassistant.const
import
CONF_PLATFORM
,
SERVICE_TURN_ON
,
STATE_UNAVAILABLE
from
homeassistant.core
import
DOMAIN
as
HA_DOMAIN
,
HomeAssistant
from
homeassistant.core
import
DOMAIN
as
HA_DOMAIN
,
HomeAssistant
from
homeassistant.helpers.entity_component
import
EntityComponent
from
homeassistant.helpers.entity_component
import
EntityComponent
from
homeassistant.helpers.restore_state
import
RestoreEntity
from
homeassistant.helpers.restore_state
import
RestoreEntity
...
@@ -117,7 +117,11 @@ class Scene(RestoreEntity):
...
@@ -117,7 +117,11 @@ class Scene(RestoreEntity):
"""
Call when the scene is added to hass.
"""
"""
Call when the scene is added to hass.
"""
await
super
().
async_internal_added_to_hass
()
await
super
().
async_internal_added_to_hass
()
state
=
await
self
.
async_get_last_state
()
state
=
await
self
.
async_get_last_state
()
if
state
is
not
None
and
state
.
state
is
not
None
:
if
(
state
is
not
None
and
state
.
state
is
not
None
and
state
.
state
!=
STATE_UNAVAILABLE
):
self
.
__last_activated
=
state
.
state
self
.
__last_activated
=
state
.
state
def
activate
(
self
,
**
kwargs
:
Any
)
->
None
:
def
activate
(
self
,
**
kwargs
:
Any
)
->
None
:
...
...
This diff is collapsed.
Click to expand it.
tests/components/scene/test_init.py
+
29
−
0
View file @
c9ac0b49
...
@@ -9,6 +9,7 @@ from homeassistant.const import (
...
@@ -9,6 +9,7 @@ from homeassistant.const import (
ATTR_ENTITY_ID
,
ATTR_ENTITY_ID
,
ENTITY_MATCH_ALL
,
ENTITY_MATCH_ALL
,
SERVICE_TURN_ON
,
SERVICE_TURN_ON
,
STATE_UNAVAILABLE
,
STATE_UNKNOWN
,
STATE_UNKNOWN
,
)
)
from
homeassistant.core
import
State
from
homeassistant.core
import
State
...
@@ -177,6 +178,34 @@ async def test_restore_state(hass, entities, enable_custom_integrations):
...
@@ -177,6 +178,34 @@ async def test_restore_state(hass, entities, enable_custom_integrations):
assert
hass
.
states
.
get
(
"
scene.test
"
).
state
==
"
2021-01-01T23:59:59+00:00
"
assert
hass
.
states
.
get
(
"
scene.test
"
).
state
==
"
2021-01-01T23:59:59+00:00
"
async
def
test_restore_state_does_not_restore_unavailable
(
hass
,
entities
,
enable_custom_integrations
):
"""
Test we restore state integration but ignore unavailable.
"""
mock_restore_cache
(
hass
,
(
State
(
"
scene.test
"
,
STATE_UNAVAILABLE
),))
light_1
,
light_2
=
await
setup_lights
(
hass
,
entities
)
assert
await
async_setup_component
(
hass
,
scene
.
DOMAIN
,
{
"
scene
"
:
[
{
"
name
"
:
"
test
"
,
"
entities
"
:
{
light_1
.
entity_id
:
"
on
"
,
light_2
.
entity_id
:
"
on
"
,
},
}
]
},
)
await
hass
.
async_block_till_done
()
assert
hass
.
states
.
get
(
"
scene.test
"
).
state
==
STATE_UNKNOWN
async
def
activate
(
hass
,
entity_id
=
ENTITY_MATCH_ALL
):
async
def
activate
(
hass
,
entity_id
=
ENTITY_MATCH_ALL
):
"""
Activate a scene.
"""
"""
Activate a scene.
"""
data
=
{}
data
=
{}
...
...
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