mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 03:07:50 +00:00
Deprecate YAML in SamsungTV (#89743)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
0c0c86bf7b
commit
dd1700954b
@ -26,8 +26,12 @@ from homeassistant.const import (
|
|||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import (
|
||||||
import homeassistant.helpers.config_validation as cv
|
config_validation as cv,
|
||||||
|
device_registry as dr,
|
||||||
|
entity_registry as er,
|
||||||
|
issue_registry as ir,
|
||||||
|
)
|
||||||
from homeassistant.helpers.debounce import Debouncer
|
from homeassistant.helpers.debounce import Debouncer
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
@ -92,6 +96,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
ir.async_create_issue(
|
||||||
|
hass,
|
||||||
|
DOMAIN,
|
||||||
|
"deprecated_yaml",
|
||||||
|
breaks_in_ha_version="2023.6.0",
|
||||||
|
is_fixable=False,
|
||||||
|
severity=ir.IssueSeverity.WARNING,
|
||||||
|
translation_key="deprecated_yaml",
|
||||||
|
translation_placeholders={
|
||||||
|
"on_action_url": "https://www.home-assistant.io/integrations/samsungtv/#turn-on-action"
|
||||||
|
},
|
||||||
|
learn_more_url="https://www.home-assistant.io/integrations/samsungtv/#turn-on-action",
|
||||||
|
)
|
||||||
for entry_config in config[DOMAIN]:
|
for entry_config in config[DOMAIN]:
|
||||||
ip_address = await hass.async_add_executor_job(
|
ip_address = await hass.async_add_executor_job(
|
||||||
socket.gethostbyname, entry_config[CONF_HOST]
|
socket.gethostbyname, entry_config[CONF_HOST]
|
||||||
|
@ -33,10 +33,12 @@ from homeassistant.components.media_player import (
|
|||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_MODEL, CONF_NAME
|
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_MODEL, CONF_NAME
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_component
|
from homeassistant.helpers import (
|
||||||
|
config_validation as cv,
|
||||||
|
device_registry as dr,
|
||||||
|
entity_component,
|
||||||
|
)
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
|
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.script import Script
|
from homeassistant.helpers.script import Script
|
||||||
@ -144,7 +146,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||||||
self._attr_device_info["identifiers"] = {(DOMAIN, self.unique_id)}
|
self._attr_device_info["identifiers"] = {(DOMAIN, self.unique_id)}
|
||||||
if self._mac:
|
if self._mac:
|
||||||
self._attr_device_info["connections"] = {
|
self._attr_device_info["connections"] = {
|
||||||
(CONNECTION_NETWORK_MAC, self._mac)
|
(dr.CONNECTION_NETWORK_MAC, self._mac)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Mark the end of a shutdown command (need to wait 15 seconds before
|
# Mark the end of a shutdown command (need to wait 15 seconds before
|
||||||
@ -475,8 +477,8 @@ class SamsungTVDevice(MediaPlayerEntity):
|
|||||||
"""Turn the media player on."""
|
"""Turn the media player on."""
|
||||||
if self._turn_on:
|
if self._turn_on:
|
||||||
await self._turn_on.async_run(self.hass, self._context)
|
await self._turn_on.async_run(self.hass, self._context)
|
||||||
# on_script is deprecated - replaced by turn_on trigger
|
elif self._on_script:
|
||||||
if self._on_script:
|
# YAML on_script is deprecated - replaced by turn_on trigger
|
||||||
await self._on_script.async_run(context=self._context)
|
await self._on_script.async_run(context=self._context)
|
||||||
elif self._mac:
|
elif self._mac:
|
||||||
await self.hass.async_add_executor_job(self._wake_on_lan)
|
await self.hass.async_add_executor_job(self._wake_on_lan)
|
||||||
|
@ -44,5 +44,11 @@
|
|||||||
"trigger_type": {
|
"trigger_type": {
|
||||||
"samsungtv.turn_on": "Device is requested to turn on"
|
"samsungtv.turn_on": "Device is requested to turn on"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"issues": {
|
||||||
|
"deprecated_yaml": {
|
||||||
|
"title": "The SamsungTV YAML configuration is being removed",
|
||||||
|
"description": "Configuring SamsungTV using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove the SamsungTV YAML configuration from your `configuration.yaml` file and restart Home Assistant to fix this issue.\n\nPlease note that previously configured `turn_on_action` needs to be manually converted to use the `turn_on` trigger ([documentation]({on_action_url}))."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
tests/components/samsungtv/snapshots/test_init.ambr
Normal file
10
tests/components/samsungtv/snapshots/test_init.ambr
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_setup
|
||||||
|
IssueRegistryItemSnapshot({
|
||||||
|
'created': <ANY>,
|
||||||
|
'dismissed_version': None,
|
||||||
|
'domain': 'samsungtv',
|
||||||
|
'is_persistent': False,
|
||||||
|
'issue_id': 'deprecated_yaml',
|
||||||
|
})
|
||||||
|
# ---
|
@ -1,6 +1,4 @@
|
|||||||
"""The tests for Samsung TV device triggers."""
|
"""The tests for Samsung TV device triggers."""
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import automation
|
from homeassistant.components import automation
|
||||||
@ -90,15 +88,11 @@ async def test_if_fires_on_turn_on_request(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.samsungtv.media_player.send_magic_packet"):
|
await hass.services.async_call(
|
||||||
await hass.services.async_call(
|
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
"media_player",
|
)
|
||||||
"turn_on",
|
await hass.async_block_till_done()
|
||||||
{"entity_id": ENTITY_ID},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(calls) == 2
|
assert len(calls) == 2
|
||||||
assert calls[0].data["some"] == device.id
|
assert calls[0].data["some"] == device.id
|
||||||
assert calls[0].data["id"] == 0
|
assert calls[0].data["id"] == 0
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.media_player import DOMAIN, MediaPlayerEntityFeature
|
from homeassistant.components.media_player import DOMAIN, MediaPlayerEntityFeature
|
||||||
from homeassistant.components.samsungtv.const import (
|
from homeassistant.components.samsungtv.const import (
|
||||||
@ -31,6 +32,7 @@ from homeassistant.const import (
|
|||||||
SERVICE_VOLUME_UP,
|
SERVICE_VOLUME_UP,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import issue_registry as ir
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from . import setup_samsungtv_entry
|
from . import setup_samsungtv_entry
|
||||||
@ -77,7 +79,9 @@ REMOTE_CALL = {
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
@pytest.mark.usefixtures("remotews", "remoteencws_failing", "rest_api")
|
||||||
async def test_setup(hass: HomeAssistant) -> None:
|
async def test_setup(
|
||||||
|
hass: HomeAssistant, issue_registry: ir.IssueRegistry, snapshot: SnapshotAssertion
|
||||||
|
) -> None:
|
||||||
"""Test Samsung TV integration is setup."""
|
"""Test Samsung TV integration is setup."""
|
||||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -96,6 +100,10 @@ async def test_setup(hass: HomeAssistant) -> None:
|
|||||||
DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True
|
DOMAIN, SERVICE_VOLUME_UP, {ATTR_ENTITY_ID: ENTITY_ID}, True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# ensure deprecated_yaml issue is raised
|
||||||
|
issue = issue_registry.async_get_issue(SAMSUNGTV_DOMAIN, "deprecated_yaml")
|
||||||
|
assert issue == snapshot
|
||||||
|
|
||||||
|
|
||||||
async def test_setup_from_yaml_without_port_device_offline(hass: HomeAssistant) -> None:
|
async def test_setup_from_yaml_without_port_device_offline(hass: HomeAssistant) -> None:
|
||||||
"""Test import from yaml when the device is offline."""
|
"""Test import from yaml when the device is offline."""
|
||||||
|
@ -48,15 +48,11 @@ async def test_turn_on_trigger_device_id(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.samsungtv.media_player.send_magic_packet"):
|
await hass.services.async_call(
|
||||||
await hass.services.async_call(
|
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
"media_player",
|
)
|
||||||
"turn_on",
|
await hass.async_block_till_done()
|
||||||
{"entity_id": ENTITY_ID},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data["some"] == device.id
|
assert calls[0].data["some"] == device.id
|
||||||
assert calls[0].data["id"] == 0
|
assert calls[0].data["id"] == 0
|
||||||
@ -66,16 +62,17 @@ async def test_turn_on_trigger_device_id(
|
|||||||
|
|
||||||
calls.clear()
|
calls.clear()
|
||||||
|
|
||||||
with patch("homeassistant.components.samsungtv.media_player.send_magic_packet"):
|
# Ensure WOL backup is called when trigger not present
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.samsungtv.media_player.send_magic_packet"
|
||||||
|
) as mock_send_magic_packet:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
"media_player",
|
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
"turn_on",
|
|
||||||
{"entity_id": ENTITY_ID},
|
|
||||||
blocking=True,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert len(calls) == 0
|
assert len(calls) == 0
|
||||||
|
mock_send_magic_packet.assert_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures("remoteencws", "rest_api")
|
@pytest.mark.usefixtures("remoteencws", "rest_api")
|
||||||
@ -107,15 +104,11 @@ async def test_turn_on_trigger_entity_id(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("homeassistant.components.samsungtv.media_player.send_magic_packet"):
|
await hass.services.async_call(
|
||||||
await hass.services.async_call(
|
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||||
"media_player",
|
)
|
||||||
"turn_on",
|
await hass.async_block_till_done()
|
||||||
{"entity_id": ENTITY_ID},
|
|
||||||
blocking=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data["some"] == ENTITY_ID
|
assert calls[0].data["some"] == ENTITY_ID
|
||||||
assert calls[0].data["id"] == 0
|
assert calls[0].data["id"] == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user