Implement source switching for homekit_controller televisions (#32526)
This commit is contained in:
10 files changed
+177
-16
No files matched your search
@@ -67,7 +67,7 @@ async def setup_accessories_from_file(hass, path):
|
||||
load_fixture, os.path.join("homekit_controller", path)
|
||||
)
|
||||
accessories_json = json.loads(accessories_fixture)
|
||||
accessories = Accessory.setup_accessories_from_list(accessories_json)
|
||||
accessories = Accessories.from_list(accessories_json)
|
||||
return accessories
|
||||
|
||||
|
||||
@@ -153,7 +153,9 @@ async def setup_test_component(hass, setup_accessory, capitalize=False, suffix=N
|
||||
|
||||
If suffix is set, entityId will include the suffix
|
||||
"""
|
||||
accessory = Accessory("TestDevice", "example.com", "Test", "0001", "0.1")
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
setup_accessory(accessory)
|
||||
|
||||
domain = None
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
"""Make sure that handling real world LG HomeKit characteristics isn't broken."""
|
||||
|
||||
|
||||
from homeassistant.components.media_player.const import SUPPORT_PAUSE, SUPPORT_PLAY
|
||||
from homeassistant.components.media_player.const import (
|
||||
SUPPORT_PAUSE,
|
||||
SUPPORT_PLAY,
|
||||
SUPPORT_SELECT_SOURCE,
|
||||
)
|
||||
|
||||
from tests.components.homekit_controller.common import (
|
||||
Helper,
|
||||
@@ -29,8 +33,22 @@ async def test_lg_tv(hass):
|
||||
# Assert that the friendly name is detected correctly
|
||||
assert state.attributes["friendly_name"] == "LG webOS TV AF80"
|
||||
|
||||
# Assert that all channels were found and that we know which is active.
|
||||
assert state.attributes["source_list"] == [
|
||||
"AirPlay",
|
||||
"Live TV",
|
||||
"HDMI 1",
|
||||
"Sony",
|
||||
"Apple",
|
||||
"AV",
|
||||
"HDMI 4",
|
||||
]
|
||||
assert state.attributes["source"] == "HDMI 4"
|
||||
|
||||
# Assert that all optional features the LS1 supports are detected
|
||||
assert state.attributes["supported_features"] == (SUPPORT_PAUSE | SUPPORT_PLAY)
|
||||
assert state.attributes["supported_features"] == (
|
||||
SUPPORT_PAUSE | SUPPORT_PLAY | SUPPORT_SELECT_SOURCE
|
||||
)
|
||||
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ def setup_mock_accessory(controller):
|
||||
"""Add a bridge accessory to a test controller."""
|
||||
bridge = Accessories()
|
||||
|
||||
accessory = Accessory(
|
||||
accessory = Accessory.create_with_info(
|
||||
name="Koogeek-LS1-20833F",
|
||||
manufacturer="Koogeek",
|
||||
model="LS1",
|
||||
@@ -500,7 +500,9 @@ async def test_user_no_unpaired_devices(hass, controller):
|
||||
|
||||
async def test_parse_new_homekit_json(hass):
|
||||
"""Test migrating recent .homekit/pairings.json files."""
|
||||
accessory = Accessory("TestDevice", "example.com", "Test", "0001", "0.1")
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
||||
on_char = service.add_char(CharacteristicsTypes.ON)
|
||||
on_char.value = 0
|
||||
@@ -549,7 +551,9 @@ async def test_parse_new_homekit_json(hass):
|
||||
|
||||
async def test_parse_old_homekit_json(hass):
|
||||
"""Test migrating original .homekit/hk-00:00:00:00:00:00 files."""
|
||||
accessory = Accessory("TestDevice", "example.com", "Test", "0001", "0.1")
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
||||
on_char = service.add_char(CharacteristicsTypes.ON)
|
||||
on_char.value = 0
|
||||
@@ -602,7 +606,9 @@ async def test_parse_old_homekit_json(hass):
|
||||
|
||||
async def test_parse_overlapping_homekit_json(hass):
|
||||
"""Test migrating .homekit/pairings.json files when hk- exists too."""
|
||||
accessory = Accessory("TestDevice", "example.com", "Test", "0001", "0.1")
|
||||
accessory = Accessory.create_with_info(
|
||||
"TestDevice", "example.com", "Test", "0001", "0.1"
|
||||
)
|
||||
service = accessory.add_service(ServicesTypes.LIGHTBULB)
|
||||
on_char = service.add_char(CharacteristicsTypes.ON)
|
||||
on_char.value = 0
|
||||
|
||||
@@ -10,6 +10,7 @@ from tests.components.homekit_controller.common import setup_test_component
|
||||
CURRENT_MEDIA_STATE = ("television", "current-media-state")
|
||||
TARGET_MEDIA_STATE = ("television", "target-media-state")
|
||||
REMOTE_KEY = ("television", "remote-key")
|
||||
ACTIVE_IDENTIFIER = ("television", "active-identifier")
|
||||
|
||||
|
||||
def create_tv_service(accessory):
|
||||
@@ -18,16 +19,33 @@ def create_tv_service(accessory):
|
||||
|
||||
The TV is not currently documented publicly - this is based on observing really TV's that have HomeKit support.
|
||||
"""
|
||||
service = accessory.add_service(ServicesTypes.TELEVISION)
|
||||
tv_service = accessory.add_service(ServicesTypes.TELEVISION)
|
||||
|
||||
cur_state = service.add_char(CharacteristicsTypes.CURRENT_MEDIA_STATE)
|
||||
cur_state = tv_service.add_char(CharacteristicsTypes.CURRENT_MEDIA_STATE)
|
||||
cur_state.value = 0
|
||||
|
||||
remote = service.add_char(CharacteristicsTypes.REMOTE_KEY)
|
||||
remote = tv_service.add_char(CharacteristicsTypes.REMOTE_KEY)
|
||||
remote.value = None
|
||||
remote.perms.append(CharacteristicPermissions.paired_write)
|
||||
|
||||
return service
|
||||
# Add a HDMI 1 channel
|
||||
input_source_1 = accessory.add_service(ServicesTypes.INPUT_SOURCE)
|
||||
input_source_1.add_char(CharacteristicsTypes.IDENTIFIER, value=1)
|
||||
input_source_1.add_char(CharacteristicsTypes.CONFIGURED_NAME, value="HDMI 1")
|
||||
tv_service.add_linked_service(input_source_1)
|
||||
|
||||
# Add a HDMI 2 channel
|
||||
input_source_2 = accessory.add_service(ServicesTypes.INPUT_SOURCE)
|
||||
input_source_2.add_char(CharacteristicsTypes.IDENTIFIER, value=2)
|
||||
input_source_2.add_char(CharacteristicsTypes.CONFIGURED_NAME, value="HDMI 2")
|
||||
tv_service.add_linked_service(input_source_2)
|
||||
|
||||
# Support switching channels
|
||||
active_identifier = tv_service.add_char(CharacteristicsTypes.ACTIVE_IDENTIFIER)
|
||||
active_identifier.value = 1
|
||||
active_identifier.perms.append(CharacteristicPermissions.paired_write)
|
||||
|
||||
return tv_service
|
||||
|
||||
|
||||
def create_tv_service_with_target_media_state(accessory):
|
||||
@@ -58,6 +76,15 @@ async def test_tv_read_state(hass, utcnow):
|
||||
assert state.state == "idle"
|
||||
|
||||
|
||||
async def test_tv_read_sources(hass, utcnow):
|
||||
"""Test that we can read the input source of a HomeKit TV."""
|
||||
helper = await setup_test_component(hass, create_tv_service)
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["source"] == "HDMI 1"
|
||||
assert state.attributes["source_list"] == ["HDMI 1", "HDMI 2"]
|
||||
|
||||
|
||||
async def test_play_remote_key(hass, utcnow):
|
||||
"""Test that we can play media on a media player."""
|
||||
helper = await setup_test_component(hass, create_tv_service)
|
||||
@@ -202,3 +229,19 @@ async def test_stop(hass, utcnow):
|
||||
)
|
||||
assert helper.characteristics[REMOTE_KEY].value is None
|
||||
assert helper.characteristics[TARGET_MEDIA_STATE].value is None
|
||||
|
||||
|
||||
async def test_tv_set_source(hass, utcnow):
|
||||
"""Test that we can set the input source of a HomeKit TV."""
|
||||
helper = await setup_test_component(hass, create_tv_service)
|
||||
|
||||
await hass.services.async_call(
|
||||
"media_player",
|
||||
"select_source",
|
||||
{"entity_id": "media_player.testdevice", "source": "HDMI 2"},
|
||||
blocking=True,
|
||||
)
|
||||
assert helper.characteristics[ACTIVE_IDENTIFIER].value == 2
|
||||
|
||||
state = await helper.poll_and_get_state()
|
||||
assert state.attributes["source"] == "HDMI 2"
|
||||
Reference in new issue
Block a user