Add support for Sonos microphone binary_sensor (#63097)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
jjlawren 2022-01-04 11:45:40 -06:00 committed by GitHub
parent ec75b0caf0
commit 8a8ffa1c08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 93 additions and 31 deletions

View file

@ -45,7 +45,7 @@ async def test_battery_attributes(hass, async_autosetup_sonos, soco):
)
async def test_battery_on_S1(hass, async_setup_sonos, soco, battery_event):
async def test_battery_on_s1(hass, async_setup_sonos, soco, device_properties_event):
"""Test battery state updates on a Sonos S1 device."""
soco.get_battery_info.return_value = {}
@ -60,7 +60,7 @@ async def test_battery_on_S1(hass, async_setup_sonos, soco, battery_event):
assert "binary_sensor.zone_a_power" not in entity_registry.entities
# Update the speaker with a callback event
sub_callback(battery_event)
sub_callback(device_properties_event)
await hass.async_block_till_done()
battery = entity_registry.entities["sensor.zone_a_battery"]
@ -74,7 +74,7 @@ async def test_battery_on_S1(hass, async_setup_sonos, soco, battery_event):
async def test_device_payload_without_battery(
hass, async_setup_sonos, soco, battery_event, caplog
hass, async_setup_sonos, soco, device_properties_event, caplog
):
"""Test device properties event update without battery info."""
soco.get_battery_info.return_value = None
@ -85,16 +85,16 @@ async def test_device_payload_without_battery(
sub_callback = subscription.callback
bad_payload = "BadKey:BadValue"
battery_event.variables["more_info"] = bad_payload
device_properties_event.variables["more_info"] = bad_payload
sub_callback(battery_event)
sub_callback(device_properties_event)
await hass.async_block_till_done()
assert bad_payload in caplog.text
async def test_device_payload_without_battery_and_ignored_keys(
hass, async_setup_sonos, soco, battery_event, caplog
hass, async_setup_sonos, soco, device_properties_event, caplog
):
"""Test device properties event update without battery info and ignored keys."""
soco.get_battery_info.return_value = None
@ -105,18 +105,35 @@ async def test_device_payload_without_battery_and_ignored_keys(
sub_callback = subscription.callback
ignored_payload = "SPID:InCeiling,TargetRoomName:Bouncy House"
battery_event.variables["more_info"] = ignored_payload
device_properties_event.variables["more_info"] = ignored_payload
sub_callback(battery_event)
sub_callback(device_properties_event)
await hass.async_block_till_done()
assert ignored_payload not in caplog.text
async def test_audio_input_sensor(hass, async_autosetup_sonos, soco):
"""Test sonos device with battery state."""
"""Test audio input sensor."""
entity_registry = ent_reg.async_get(hass)
audio_input_sensor = entity_registry.entities["sensor.zone_a_audio_input_format"]
audio_input_state = hass.states.get(audio_input_sensor.entity_id)
assert audio_input_state.state == "Dolby 5.1"
async def test_microphone_binary_sensor(
hass, async_autosetup_sonos, soco, device_properties_event
):
"""Test microphone binary sensor."""
entity_registry = ent_reg.async_get(hass)
assert "binary_sensor.zone_a_microphone" not in entity_registry.entities
# Update the speaker with a callback event
subscription = soco.deviceProperties.subscribe.return_value
subscription.callback(device_properties_event)
await hass.async_block_till_done()
mic_binary_sensor = entity_registry.entities["binary_sensor.zone_a_microphone"]
mic_binary_sensor_state = hass.states.get(mic_binary_sensor.entity_id)
assert mic_binary_sensor_state.state == STATE_ON