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
6e7fe13d
Unverified
Commit
6e7fe13d
authored
3 years ago
by
jjlawren
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Disable polling Sonos switches by default (#58705)
parent
a4a5a2e7
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/sonos/switch.py
+1
-0
1 addition, 0 deletions
homeassistant/components/sonos/switch.py
tests/components/sonos/test_switch.py
+38
-0
38 additions, 0 deletions
tests/components/sonos/test_switch.py
with
39 additions
and
0 deletions
homeassistant/components/sonos/switch.py
+
1
−
0
View file @
6e7fe13d
...
...
@@ -136,6 +136,7 @@ class SonosSwitchEntity(SonosEntity, SwitchEntity):
self
.
_attr_icon
=
FEATURE_ICONS
.
get
(
feature_type
)
if
feature_type
in
POLL_REQUIRED
:
self
.
_attr_entity_registry_enabled_default
=
False
self
.
_attr_should_poll
=
True
async
def
_async_poll
(
self
)
->
None
:
...
...
This diff is collapsed.
Click to expand it.
tests/components/sonos/test_switch.py
+
38
−
0
View file @
6e7fe13d
"""
Tests for the Sonos Alarm switch platform.
"""
from
copy
import
copy
from
datetime
import
timedelta
from
unittest.mock
import
patch
from
homeassistant.components.sonos
import
DOMAIN
from
homeassistant.components.sonos.const
import
DATA_SONOS_DISCOVERY_MANAGER
from
homeassistant.components.sonos.switch
import
(
ATTR_DURATION
,
ATTR_ID
,
...
...
@@ -10,9 +13,15 @@ from homeassistant.components.sonos.switch import (
ATTR_RECURRENCE
,
ATTR_VOLUME
,
)
from
homeassistant.config_entries
import
RELOAD_AFTER_UPDATE_DELAY
from
homeassistant.const
import
ATTR_TIME
,
STATE_ON
from
homeassistant.helpers.entity_registry
import
async_get
as
async_get_entity_registry
from
homeassistant.setup
import
async_setup_component
from
homeassistant.util
import
dt
from
.conftest
import
SonosMockEvent
from
tests.common
import
async_fire_time_changed
async
def
setup_platform
(
hass
,
config_entry
,
config
):
...
...
@@ -67,7 +76,36 @@ async def test_switch_attributes(hass, config_entry, config, soco):
crossfade_state
=
hass
.
states
.
get
(
crossfade
.
entity_id
)
assert
crossfade_state
.
state
==
STATE_ON
# Ensure switches are disabled
status_light
=
entity_registry
.
entities
[
"
switch.sonos_zone_a_status_light
"
]
assert
hass
.
states
.
get
(
status_light
.
entity_id
)
is
None
touch_controls
=
entity_registry
.
entities
[
"
switch.sonos_zone_a_touch_controls
"
]
assert
hass
.
states
.
get
(
touch_controls
.
entity_id
)
is
None
# Enable disabled switches
for
entity
in
(
status_light
,
touch_controls
):
entity_registry
.
async_update_entity
(
entity_id
=
entity
.
entity_id
,
disabled_by
=
None
)
await
hass
.
async_block_till_done
()
# Fire event to cancel poll timer and avoid triggering errors during time jump
service
=
soco
.
contentDirectory
empty_event
=
SonosMockEvent
(
soco
,
service
,
{})
subscription
=
service
.
subscribe
.
return_value
subscription
.
callback
(
event
=
empty_event
)
await
hass
.
async_block_till_done
()
# Mock shutdown calls during config entry reload
with
patch
.
object
(
hass
.
data
[
DATA_SONOS_DISCOVERY_MANAGER
],
"
async_shutdown
"
)
as
m
:
async_fire_time_changed
(
hass
,
dt
.
utcnow
()
+
timedelta
(
seconds
=
RELOAD_AFTER_UPDATE_DELAY
+
1
),
)
await
hass
.
async_block_till_done
()
assert
m
.
called
status_light_state
=
hass
.
states
.
get
(
status_light
.
entity_id
)
assert
status_light_state
.
state
==
STATE_ON
...
...
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