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
422ba89c
Commit
422ba89c
authored
5 years ago
by
Paulus Schoutsen
Browse files
Options
Downloads
Patches
Plain Diff
Google: catch query not supported (#27559)
parent
134137dd
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/google_assistant/report_state.py
+11
-1
11 additions, 1 deletion
homeassistant/components/google_assistant/report_state.py
tests/components/google_assistant/test_report_state.py
+15
-2
15 additions, 2 deletions
tests/components/google_assistant/test_report_state.py
with
26 additions
and
3 deletions
homeassistant/components/google_assistant/report_state.py
+
11
−
1
View file @
422ba89c
"""
Google Report State implementation.
"""
import
logging
from
homeassistant.core
import
HomeAssistant
,
callback
from
homeassistant.const
import
MATCH_ALL
from
homeassistant.helpers.event
import
async_call_later
from
.helpers
import
AbstractConfig
,
GoogleEntity
,
async_get_entities
from
.error
import
SmartHomeError
# Time to wait until the homegraph updates
# https://github.com/actions-on-google/smart-home-nodejs/issues/196#issuecomment-439156639
INITIAL_REPORT_DELAY
=
60
_LOGGER
=
logging
.
getLogger
(
__name__
)
@callback
def
async_enable_report_state
(
hass
:
HomeAssistant
,
google_config
:
AbstractConfig
):
"""
Enable state reporting.
"""
...
...
@@ -26,7 +32,11 @@ def async_enable_report_state(hass: HomeAssistant, google_config: AbstractConfig
if
not
entity
.
is_supported
():
return
entity_data
=
entity
.
query_serialize
()
try
:
entity_data
=
entity
.
query_serialize
()
except
SmartHomeError
as
err
:
_LOGGER
.
debug
(
"
Not reporting state for %s: %s
"
,
changed_entity
,
err
.
code
)
return
if
old_state
:
old_entity
=
GoogleEntity
(
hass
,
google_config
,
old_state
)
...
...
This diff is collapsed.
Click to expand it.
tests/components/google_assistant/test_report_state.py
+
15
−
2
View file @
422ba89c
"""
Test Google report state.
"""
from
unittest.mock
import
patch
from
homeassistant.components.google_assistant
import
report_state
from
homeassistant.components.google_assistant
import
report_state
,
error
from
homeassistant.util.dt
import
utcnow
from
.
import
BASIC_CONFIG
...
...
@@ -10,7 +10,7 @@ from . import BASIC_CONFIG
from
tests.common
import
mock_coro
,
async_fire_time_changed
async
def
test_report_state
(
hass
):
async
def
test_report_state
(
hass
,
caplog
):
"""
Test report state works.
"""
hass
.
states
.
async_set
(
"
light.ceiling
"
,
"
off
"
)
hass
.
states
.
async_set
(
"
switch.ac
"
,
"
on
"
)
...
...
@@ -57,6 +57,19 @@ async def test_report_state(hass):
assert
len
(
mock_report
.
mock_calls
)
==
0
# Test that entities that we can't query don't report a state
with
patch
.
object
(
BASIC_CONFIG
,
"
async_report_state
"
,
side_effect
=
mock_coro
)
as
mock_report
,
patch
(
"
homeassistant.components.google_assistant.report_state.GoogleEntity.query_serialize
"
,
side_effect
=
error
.
SmartHomeError
(
"
mock-error
"
,
"
mock-msg
"
),
):
hass
.
states
.
async_set
(
"
light.kitchen
"
,
"
off
"
)
await
hass
.
async_block_till_done
()
assert
"
Not reporting state for light.kitchen: mock-error
"
assert
len
(
mock_report
.
mock_calls
)
==
0
unsub
()
with
patch
.
object
(
...
...
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