mirror of
https://github.com/home-assistant/core.git
synced 2026-08-30 01:56:13 +01:00
* add config flow
* add tests
* add user step error handling
* remove unload function
* add missing test file
* handle authentication correctly
* remove old discovery mode
* better handling of remote class
* optimized abort messages
* add already configured test for user flow
* Import order
* use ip property instead context
* Black
* small syntax
* use snake_case
* Revert "use ip property instead context"
This reverts commit 91502407eb216f8a0b1b90e3e6fb165b81406f8f.
* disable wrong pylint errors
* disable wrong no-member
* Try to fix review comments
* Try to fix review comments
* Fix missing self
* Fix ip checks
* methods to functions
* simplify user check
* remove user errors
* use async_setup for config
* fix after rebase
* import config to user config flow
* patch all samsungctl
* fix after rebase
* fix notes
* remove unused variable
* ignore old setup function
* fix after merge
* pass configuration to import step
* isort
* fix recursion
* remove timeout config
* add turn on action (dry without testing)
* use upstream checks
* cleanup
* minor
* correctly await async method
* ignore unused import
* async call send_key
* Revert "async call send_key"
This reverts commit f37057819f.
* fix comments
* fix timeout test
* test turn on action
* Update media_player.py
* Update test_media_player.py
* Update test_media_player.py
* use async executor
* use newer ssdp data
* update manually configured with ssdp data
* dont setup component directly
* ensure list
* check updated device info
* Update config_flow.py
* Update __init__.py
* fix duplicate check
* simplified unique check
* move method detection to config_flow
* move unique test to init
* fix after real world test
* optimize config_validation
* update device_info on ssdp discovery
* cleaner update listener
* fix lint
* fix method signature
* add note for manual config to confirm message
* fix turn_on_action
* pass script
* patch delay
* remove device info update
98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
"""Tests for the Samsung TV Integration."""
|
|
from unittest.mock import call, patch
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components.media_player.const import DOMAIN, SUPPORT_TURN_ON
|
|
from homeassistant.components.samsungtv.const import (
|
|
CONF_ON_ACTION,
|
|
DOMAIN as SAMSUNGTV_DOMAIN,
|
|
)
|
|
from homeassistant.components.samsungtv.media_player import SUPPORT_SAMSUNGTV
|
|
from homeassistant.const import (
|
|
ATTR_ENTITY_ID,
|
|
ATTR_SUPPORTED_FEATURES,
|
|
CONF_HOST,
|
|
CONF_NAME,
|
|
CONF_PORT,
|
|
SERVICE_VOLUME_UP,
|
|
)
|
|
from homeassistant.setup import async_setup_component
|
|
|
|
ENTITY_ID = f"{DOMAIN}.fake_name"
|
|
MOCK_CONFIG = {
|
|
SAMSUNGTV_DOMAIN: [
|
|
{
|
|
CONF_HOST: "fake_host",
|
|
CONF_NAME: "fake_name",
|
|
CONF_PORT: 1234,
|
|
CONF_ON_ACTION: [{"delay": "00:00:01"}],
|
|
}
|
|
]
|
|
}
|
|
REMOTE_CALL = {
|
|
"name": "HomeAssistant",
|
|
"description": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_NAME],
|
|
"id": "ha.component.samsung",
|
|
"method": "websocket",
|
|
"port": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_PORT],
|
|
"host": MOCK_CONFIG[SAMSUNGTV_DOMAIN][0][CONF_HOST],
|
|
"timeout": 1,
|
|
}
|
|
|
|
|
|
@pytest.fixture(name="remote")
|
|
def remote_fixture():
|
|
"""Patch the samsungctl Remote."""
|
|
with patch("homeassistant.components.samsungtv.socket"), patch(
|
|
"homeassistant.components.samsungtv.config_flow.socket"
|
|
), patch("homeassistant.components.samsungtv.config_flow.Remote"), patch(
|
|
"homeassistant.components.samsungtv.media_player.SamsungRemote"
|
|
) as remote:
|
|
yield remote
|
|
|
|
|
|
async def test_setup(hass, remote):
|
|
"""Test Samsung TV integration is setup."""
|
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
|
await hass.async_block_till_done()
|
|
state = hass.states.get(ENTITY_ID)
|
|
|
|
# test name and turn_on
|
|
assert state
|
|
assert state.name == "fake_name"
|
|
assert (
|
|
state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_SAMSUNGTV | SUPPORT_TURN_ON
|
|
)
|
|
|
|
# test host and port
|
|
assert await hass.services.async_call(
|
|
DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True
|
|
)
|
|
assert remote.mock_calls[0] == call(REMOTE_CALL)
|
|
|
|
|
|
async def test_setup_duplicate_config(hass, remote, caplog):
|
|
"""Test duplicate setup of platform."""
|
|
DUPLICATE = {
|
|
SAMSUNGTV_DOMAIN: [
|
|
MOCK_CONFIG[SAMSUNGTV_DOMAIN][0],
|
|
MOCK_CONFIG[SAMSUNGTV_DOMAIN][0],
|
|
]
|
|
}
|
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, DUPLICATE)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get(ENTITY_ID) is None
|
|
assert len(hass.states.async_all()) == 0
|
|
assert "duplicate host entries found" in caplog.text
|
|
|
|
|
|
async def test_setup_duplicate_entries(hass, remote, caplog):
|
|
"""Test duplicate setup of platform."""
|
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
|
await hass.async_block_till_done()
|
|
assert hass.states.get(ENTITY_ID)
|
|
assert len(hass.states.async_all()) == 1
|
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
|
assert len(hass.states.async_all()) == 1
|