1
mirror of https://github.com/home-assistant/core synced 2024-09-12 15:16:21 +02:00

Rename RemoteDevice to RemoteEntity (#34676)

This commit is contained in:
Erik Montnemery 2020-04-26 02:12:36 +02:00 committed by GitHub
parent d3ed80cf53
commit aa60d362fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 14 deletions

View File

@ -17,7 +17,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([AppleTVRemote(atv, power, name)])
class AppleTVRemote(remote.RemoteDevice):
class AppleTVRemote(remote.RemoteEntity):
"""Device that sends commands to an Apple TV."""
def __init__(self, atv, power, name):

View File

@ -22,7 +22,7 @@ from homeassistant.components.remote import (
DOMAIN as COMPONENT,
PLATFORM_SCHEMA,
SUPPORT_LEARN_COMMAND,
RemoteDevice,
RemoteEntity,
)
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_TIMEOUT, CONF_TYPE
from homeassistant.core import callback
@ -124,7 +124,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities([remote], False)
class BroadlinkRemote(RemoteDevice):
class BroadlinkRemote(RemoteEntity):
"""Representation of a Broadlink remote."""
def __init__(self, name, unique_id, api, code_storage, flag_storage):

View File

@ -1,5 +1,5 @@
"""Demo platform that has two fake remotes."""
from homeassistant.components.remote import RemoteDevice
from homeassistant.components.remote import RemoteEntity
from homeassistant.const import DEVICE_DEFAULT_NAME
@ -18,7 +18,7 @@ def setup_platform(hass, config, add_entities_callback, discovery_info=None):
)
class DemoRemote(RemoteDevice):
class DemoRemote(RemoteEntity):
"""Representation of a demo remote."""
def __init__(self, name, state, icon):

View File

@ -5,7 +5,7 @@ from typing import Any, Callable, Iterable, List
from directv import DIRECTV, DIRECTVError
from homeassistant.components.remote import RemoteDevice
from homeassistant.components.remote import RemoteEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
@ -36,7 +36,7 @@ async def async_setup_entry(
async_add_entities(entities, True)
class DIRECTVRemote(DIRECTVEntity, RemoteDevice):
class DIRECTVRemote(DIRECTVEntity, RemoteEntity):
"""Device that sends commands to a DirecTV receiver."""
def __init__(self, *, dtv: DIRECTV, name: str, address: str = "0") -> None:

View File

@ -125,7 +125,7 @@ async def async_setup_entry(
)
class HarmonyRemote(remote.RemoteDevice):
class HarmonyRemote(remote.RemoteEntity):
"""Remote representation used to control a Harmony device."""
def __init__(self, name, unique_id, host, activity, out_path, delay_secs):

View File

@ -84,7 +84,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
return True
class ITachIP2IRRemote(remote.RemoteDevice):
class ITachIP2IRRemote(remote.RemoteEntity):
"""Device that sends commands to an ITachIP2IR device."""
def __init__(self, itachip2ir, name):

View File

@ -122,7 +122,7 @@ async def async_unload_entry(hass: HomeAssistantType, entry: ConfigEntry) -> boo
return await cast(EntityComponent, hass.data[DOMAIN]).async_unload_entry(entry)
class RemoteDevice(ToggleEntity):
class RemoteEntity(ToggleEntity):
"""Representation of a remote."""
@property
@ -149,3 +149,15 @@ class RemoteDevice(ToggleEntity):
"""Learn a command from a device."""
assert self.hass is not None
await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs))
class RemoteDevice(RemoteEntity):
"""Representation of a remote (for backwards compatibility)."""
def __init_subclass__(cls, **kwargs):
"""Print deprecation warning."""
super().__init_subclass__(**kwargs)
_LOGGER.warning(
"RemoteDevice is deprecated, modify %s to extend RemoteEntity",
cls.__name__,
)

View File

@ -7,7 +7,7 @@ from requests.exceptions import (
)
from roku import RokuException
from homeassistant.components.remote import RemoteDevice
from homeassistant.components.remote import RemoteEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType
@ -24,7 +24,7 @@ async def async_setup_entry(
async_add_entities([RokuRemote(roku)], True)
class RokuRemote(RemoteDevice):
class RokuRemote(RemoteEntity):
"""Device that sends commands to an Roku."""
def __init__(self, roku):

View File

@ -12,7 +12,7 @@ from homeassistant.components.remote import (
ATTR_NUM_REPEATS,
DEFAULT_DELAY_SECS,
PLATFORM_SCHEMA,
RemoteDevice,
RemoteEntity,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -165,7 +165,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
)
class XiaomiMiioRemote(RemoteDevice):
class XiaomiMiioRemote(RemoteEntity):
"""Representation of a Xiaomi Miio Remote device."""
def __init__(self, friendly_name, device, unique_id, slot, timeout, commands):

View File

@ -117,3 +117,13 @@ class TestRemote(unittest.TestCase):
assert call.domain == remote.DOMAIN
assert call.service == SERVICE_LEARN_COMMAND
assert call.data[ATTR_ENTITY_ID] == "entity_id_val"
def test_deprecated_base_class(caplog):
"""Test deprecated base class."""
class CustomRemote(remote.RemoteDevice):
pass
CustomRemote()
assert "RemoteDevice is deprecated, modify CustomRemote" in caplog.text