Add device info to Panasonic Viera (#41028)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
72289b8171
commit
d1041efedf
6 changed files with 250 additions and 10 deletions
|
@ -1,5 +1,10 @@
|
|||
"""Test the Panasonic Viera setup process."""
|
||||
from homeassistant.components.panasonic_viera.const import (
|
||||
ATTR_DEVICE_INFO,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_MANUFACTURER,
|
||||
ATTR_MODEL_NUMBER,
|
||||
ATTR_UDN,
|
||||
CONF_APP_ID,
|
||||
CONF_ENCRYPTION_KEY,
|
||||
CONF_ON_ACTION,
|
||||
|
@ -26,8 +31,15 @@ MOCK_ENCRYPTION_DATA = {
|
|||
CONF_ENCRYPTION_KEY: "mock-encryption-key",
|
||||
}
|
||||
|
||||
MOCK_DEVICE_INFO = {
|
||||
ATTR_FRIENDLY_NAME: DEFAULT_NAME,
|
||||
ATTR_MANUFACTURER: "mock-manufacturer",
|
||||
ATTR_MODEL_NUMBER: "mock-model-number",
|
||||
ATTR_UDN: "mock-unique-id",
|
||||
}
|
||||
|
||||
def get_mock_remote():
|
||||
|
||||
def get_mock_remote(device_info=MOCK_DEVICE_INFO):
|
||||
"""Return a mock remote."""
|
||||
mock_remote = Mock()
|
||||
|
||||
|
@ -36,6 +48,11 @@ def get_mock_remote():
|
|||
|
||||
mock_remote.async_create_remote_control = async_create_remote_control
|
||||
|
||||
async def async_get_device_info():
|
||||
return device_info
|
||||
|
||||
mock_remote.async_get_device_info = async_get_device_info
|
||||
|
||||
return mock_remote
|
||||
|
||||
|
||||
|
@ -43,8 +60,8 @@ async def test_setup_entry_encrypted(hass):
|
|||
"""Test setup with encrypted config entry."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_CONFIG_DATA[CONF_HOST],
|
||||
data={**MOCK_CONFIG_DATA, **MOCK_ENCRYPTION_DATA},
|
||||
unique_id=MOCK_DEVICE_INFO[ATTR_UDN],
|
||||
data={**MOCK_CONFIG_DATA, **MOCK_ENCRYPTION_DATA, **MOCK_DEVICE_INFO},
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
@ -64,8 +81,89 @@ async def test_setup_entry_encrypted(hass):
|
|||
assert state.name == DEFAULT_NAME
|
||||
|
||||
|
||||
async def test_setup_entry_encrypted_missing_device_info(hass):
|
||||
"""Test setup with encrypted config entry and missing device info."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_CONFIG_DATA[CONF_HOST],
|
||||
data={**MOCK_CONFIG_DATA, **MOCK_ENCRYPTION_DATA},
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
mock_remote = get_mock_remote()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.panasonic_viera.Remote",
|
||||
return_value=mock_remote,
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_entry.data[ATTR_DEVICE_INFO] == MOCK_DEVICE_INFO
|
||||
assert mock_entry.unique_id == MOCK_DEVICE_INFO[ATTR_UDN]
|
||||
|
||||
state = hass.states.get("media_player.panasonic_viera_tv")
|
||||
|
||||
assert state
|
||||
assert state.name == DEFAULT_NAME
|
||||
|
||||
|
||||
async def test_setup_entry_encrypted_missing_device_info_none(hass):
|
||||
"""Test setup with encrypted config entry and device info set to None."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_CONFIG_DATA[CONF_HOST],
|
||||
data={**MOCK_CONFIG_DATA, **MOCK_ENCRYPTION_DATA},
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
mock_remote = get_mock_remote(device_info=None)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.panasonic_viera.Remote",
|
||||
return_value=mock_remote,
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_entry.data[ATTR_DEVICE_INFO] is None
|
||||
assert mock_entry.unique_id == MOCK_CONFIG_DATA[CONF_HOST]
|
||||
|
||||
state = hass.states.get("media_player.panasonic_viera_tv")
|
||||
|
||||
assert state
|
||||
assert state.name == DEFAULT_NAME
|
||||
|
||||
|
||||
async def test_setup_entry_unencrypted(hass):
|
||||
"""Test setup with unencrypted config entry."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_DEVICE_INFO[ATTR_UDN],
|
||||
data={**MOCK_CONFIG_DATA, **MOCK_DEVICE_INFO},
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
mock_remote = get_mock_remote()
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.panasonic_viera.Remote",
|
||||
return_value=mock_remote,
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("media_player.panasonic_viera_tv")
|
||||
|
||||
assert state
|
||||
assert state.name == DEFAULT_NAME
|
||||
|
||||
|
||||
async def test_setup_entry_unencrypted_missing_device_info(hass):
|
||||
"""Test setup with unencrypted config entry and missing device info."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_CONFIG_DATA[CONF_HOST],
|
||||
|
@ -83,6 +181,37 @@ async def test_setup_entry_unencrypted(hass):
|
|||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_entry.data[ATTR_DEVICE_INFO] == MOCK_DEVICE_INFO
|
||||
assert mock_entry.unique_id == MOCK_DEVICE_INFO[ATTR_UDN]
|
||||
|
||||
state = hass.states.get("media_player.panasonic_viera_tv")
|
||||
|
||||
assert state
|
||||
assert state.name == DEFAULT_NAME
|
||||
|
||||
|
||||
async def test_setup_entry_unencrypted_missing_device_info_none(hass):
|
||||
"""Test setup with unencrypted config entry and device info set to None."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id=MOCK_CONFIG_DATA[CONF_HOST],
|
||||
data=MOCK_CONFIG_DATA,
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
||||
mock_remote = get_mock_remote(device_info=None)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.panasonic_viera.Remote",
|
||||
return_value=mock_remote,
|
||||
):
|
||||
await hass.config_entries.async_setup(mock_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_entry.data[ATTR_DEVICE_INFO] is None
|
||||
assert mock_entry.unique_id == MOCK_CONFIG_DATA[CONF_HOST]
|
||||
|
||||
state = hass.states.get("media_player.panasonic_viera_tv")
|
||||
|
||||
assert state
|
||||
|
@ -106,7 +235,7 @@ async def test_setup_config_flow_initiated(hass):
|
|||
async def test_setup_unload_entry(hass):
|
||||
"""Test if config entry is unloaded."""
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=DOMAIN, unique_id=MOCK_CONFIG_DATA[CONF_HOST], data=MOCK_CONFIG_DATA
|
||||
domain=DOMAIN, unique_id=MOCK_DEVICE_INFO[ATTR_UDN], data=MOCK_CONFIG_DATA
|
||||
)
|
||||
|
||||
mock_entry.add_to_hass(hass)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue