mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add battery support for Sonos S1 speakers (#50864)
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
"""Tests for the Sonos battery sensor platform."""
|
||||
from pysonos.exceptions import NotSupportedException
|
||||
|
||||
from homeassistant.components.sonos import DOMAIN
|
||||
from homeassistant.components.sonos import DATA_SONOS, DOMAIN
|
||||
from homeassistant.components.sonos.binary_sensor import ATTR_BATTERY_POWER_SOURCE
|
||||
from homeassistant.const import STATE_ON
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
@@ -55,3 +55,32 @@ async def test_battery_attributes(hass, config_entry, config, soco):
|
||||
assert (
|
||||
power_state.attributes.get(ATTR_BATTERY_POWER_SOURCE) == "SONOS_CHARGING_RING"
|
||||
)
|
||||
|
||||
|
||||
async def test_battery_on_S1(hass, config_entry, config, soco, battery_event):
|
||||
"""Test battery state updates on a Sonos S1 device."""
|
||||
soco.get_battery_info.return_value = {}
|
||||
|
||||
await setup_platform(hass, config_entry, config)
|
||||
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
|
||||
battery = entity_registry.entities["sensor.zone_a_battery"]
|
||||
battery_state = hass.states.get(battery.entity_id)
|
||||
assert battery_state.state == STATE_UNAVAILABLE
|
||||
|
||||
power = entity_registry.entities["binary_sensor.zone_a_power"]
|
||||
power_state = hass.states.get(power.entity_id)
|
||||
assert power_state.state == STATE_UNAVAILABLE
|
||||
|
||||
# Update the speaker with a callback event
|
||||
speaker = hass.data[DATA_SONOS].discovered[soco.uid]
|
||||
speaker.async_dispatch_properties(battery_event)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
battery_state = hass.states.get(battery.entity_id)
|
||||
assert battery_state.state == "100"
|
||||
|
||||
power_state = hass.states.get(power.entity_id)
|
||||
assert power_state.state == STATE_OFF
|
||||
assert power_state.attributes.get(ATTR_BATTERY_POWER_SOURCE) == "BATTERY"
|
||||
|
||||
Reference in New Issue
Block a user