mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37: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.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers import (
|
||||
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.typing import ConfigType
|
||||
|
||||
@ -92,6 +96,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
if DOMAIN not in config:
|
||||
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]:
|
||||
ip_address = await hass.async_add_executor_job(
|
||||
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.const import CONF_HOST, CONF_MAC, CONF_MODEL, CONF_NAME
|
||||
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
|
||||
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_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.script import Script
|
||||
@ -144,7 +146,7 @@ class SamsungTVDevice(MediaPlayerEntity):
|
||||
self._attr_device_info["identifiers"] = {(DOMAIN, self.unique_id)}
|
||||
if self._mac:
|
||||
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
|
||||
@ -475,8 +477,8 @@ class SamsungTVDevice(MediaPlayerEntity):
|
||||
"""Turn the media player on."""
|
||||
if self._turn_on:
|
||||
await self._turn_on.async_run(self.hass, self._context)
|
||||
# on_script is deprecated - replaced by turn_on trigger
|
||||
if self._on_script:
|
||||
elif self._on_script:
|
||||
# YAML on_script is deprecated - replaced by turn_on trigger
|
||||
await self._on_script.async_run(context=self._context)
|
||||
elif self._mac:
|
||||
await self.hass.async_add_executor_job(self._wake_on_lan)
|
||||
|
@ -44,5 +44,11 @@
|
||||
"trigger_type": {
|
||||
"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."""
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
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(
|
||||
"media_player",
|
||||
"turn_on",
|
||||
{"entity_id": ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.services.async_call(
|
||||
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 2
|
||||
assert calls[0].data["some"] == device.id
|
||||
assert calls[0].data["id"] == 0
|
||||
|
@ -2,6 +2,7 @@
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN, MediaPlayerEntityFeature
|
||||
from homeassistant.components.samsungtv.const import (
|
||||
@ -31,6 +32,7 @@ from homeassistant.const import (
|
||||
SERVICE_VOLUME_UP,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_samsungtv_entry
|
||||
@ -77,7 +79,9 @@ REMOTE_CALL = {
|
||||
|
||||
|
||||
@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."""
|
||||
await async_setup_component(hass, SAMSUNGTV_DOMAIN, MOCK_CONFIG)
|
||||
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
|
||||
)
|
||||
|
||||
# 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:
|
||||
"""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(
|
||||
"media_player",
|
||||
"turn_on",
|
||||
{"entity_id": ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.services.async_call(
|
||||
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == device.id
|
||||
assert calls[0].data["id"] == 0
|
||||
@ -66,16 +62,17 @@ async def test_turn_on_trigger_device_id(
|
||||
|
||||
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(
|
||||
"media_player",
|
||||
"turn_on",
|
||||
{"entity_id": ENTITY_ID},
|
||||
blocking=True,
|
||||
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(calls) == 0
|
||||
mock_send_magic_packet.assert_called()
|
||||
|
||||
|
||||
@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(
|
||||
"media_player",
|
||||
"turn_on",
|
||||
{"entity_id": ENTITY_ID},
|
||||
blocking=True,
|
||||
)
|
||||
await hass.services.async_call(
|
||||
"media_player", "turn_on", {"entity_id": ENTITY_ID}, blocking=True
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
await hass.async_block_till_done()
|
||||
assert len(calls) == 1
|
||||
assert calls[0].data["some"] == ENTITY_ID
|
||||
assert calls[0].data["id"] == 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user