-
-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Fix Apple TV keyboard focus binary_sensor missing on cold start #170360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
frenck
merged 2 commits into
home-assistant:dev
from
kroehre:apple-tv-binary-sensor-missed-signal
May 19, 2026
+79
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| """Tests for Apple TV binary sensor.""" | ||
|
|
||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| from pyatv.const import DeviceModel, KeyboardFocusState, Protocol | ||
|
|
||
| from homeassistant.components.apple_tv.const import DOMAIN | ||
| from homeassistant.const import CONF_ADDRESS, CONF_NAME | ||
| from homeassistant.core import HomeAssistant | ||
|
|
||
| from .common import create_conf, mrp_service | ||
|
|
||
| from tests.common import MockConfigEntry | ||
|
|
||
|
|
||
| async def test_keyboard_focus_entity_created_on_setup( | ||
| hass: HomeAssistant, | ||
| mock_async_zeroconf: MagicMock, | ||
| ) -> None: | ||
| """Test the keyboard focus binary sensor is created when the device supports it. | ||
|
|
||
| Regression test for https://github.com/home-assistant/core/issues/170075 — the | ||
| initial SIGNAL_CONNECTED dispatch happens in async_first_connect (before platform | ||
| forwarding), so the binary_sensor platform must also handle the already-connected | ||
| case rather than relying solely on the dispatcher signal. | ||
| """ | ||
| atv = AsyncMock() | ||
| atv.close = MagicMock() | ||
| atv.features = MagicMock() | ||
| atv.features.in_state = MagicMock(return_value=True) | ||
| atv.keyboard = AsyncMock() | ||
| atv.keyboard.text_focus_state = KeyboardFocusState.Unfocused | ||
| atv.push_updater = MagicMock() | ||
| atv.device_info.model = DeviceModel.Gen4K | ||
| atv.device_info.raw_model = "AppleTV6,2" | ||
| atv.device_info.version = "15.0" | ||
| atv.device_info.mac = "AA:BB:CC:DD:EE:FF" | ||
|
|
||
| entry = MockConfigEntry( | ||
| domain=DOMAIN, | ||
| title="Living Room", | ||
| unique_id="mrpid", | ||
| data={ | ||
| CONF_ADDRESS: "127.0.0.1", | ||
| CONF_NAME: "Living Room", | ||
| "credentials": {str(Protocol.MRP.value): "mrp_creds"}, | ||
| "identifiers": ["mrpid"], | ||
| }, | ||
| ) | ||
| entry.add_to_hass(hass) | ||
|
|
||
| scan_result = create_conf("127.0.0.1", "Living Room", mrp_service()) | ||
|
|
||
| with ( | ||
| patch("homeassistant.components.apple_tv.scan", return_value=[scan_result]), | ||
| patch("homeassistant.components.apple_tv.connect", return_value=atv), | ||
| ): | ||
| await hass.config_entries.async_setup(entry.entry_id) | ||
| await hass.async_block_till_done() | ||
|
|
||
| state = hass.states.get("binary_sensor.living_room_keyboard_focus") | ||
| assert state is not None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.