Skip to content

Commit

Permalink
Respect WyomingSatelliteMuteSwitch state on start (#118320)
Browse files Browse the repository at this point in the history
* Respect WyomingSatelliteMuteSwitch state on start

* Fix test

---------

Co-authored-by: Kostas Chatzikokolakis <kostas@chatzi.org>
  • Loading branch information
synesthesiam and chatziko authored May 28, 2024
1 parent 75ab4d2 commit 06d6f99
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
1 change: 1 addition & 0 deletions homeassistant/components/wyoming/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async def async_added_to_hass(self) -> None:

# Default to off
self._attr_is_on = (state is not None) and (state.state == STATE_ON)
self._device.is_muted = self._attr_is_on

async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn on."""
Expand Down
19 changes: 6 additions & 13 deletions tests/components/wyoming/test_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
from wyoming.wake import Detect, Detection

from homeassistant.components import assist_pipeline, wyoming
from homeassistant.components.wyoming.data import WyomingService
from homeassistant.components.wyoming.devices import SatelliteDevice
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.const import STATE_ON
from homeassistant.core import HomeAssistant, State
from homeassistant.helpers import intent as intent_helper
from homeassistant.setup import async_setup_component

Expand Down Expand Up @@ -444,17 +443,8 @@ async def test_satellite_muted(hass: HomeAssistant) -> None:
"""Test callback for a satellite that has been muted."""
on_muted_event = asyncio.Event()

original_make_satellite = wyoming._make_satellite
original_on_muted = wyoming.satellite.WyomingSatellite.on_muted

def make_muted_satellite(
hass: HomeAssistant, config_entry: ConfigEntry, service: WyomingService
):
satellite = original_make_satellite(hass, config_entry, service)
satellite.device.set_is_muted(True)

return satellite

async def on_muted(self):
# Trigger original function
self._muted_changed_event.set()
Expand All @@ -472,7 +462,10 @@ async def on_muted(self):
"homeassistant.components.wyoming.data.load_wyoming_info",
return_value=SATELLITE_INFO,
),
patch("homeassistant.components.wyoming._make_satellite", make_muted_satellite),
patch(
"homeassistant.components.wyoming.switch.WyomingSatelliteMuteSwitch.async_get_last_state",
return_value=State("switch.test_mute", STATE_ON),
),
patch(
"homeassistant.components.wyoming.satellite.WyomingSatellite.on_muted",
on_muted,
Expand Down
1 change: 1 addition & 0 deletions tests/components/wyoming/test_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ async def test_muted(
state = hass.states.get(muted_id)
assert state is not None
assert state.state == STATE_ON
assert satellite_device.is_muted

0 comments on commit 06d6f99

Please sign in to comment.