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)]) async_add_entities([AppleTVRemote(atv, power, name)])
class AppleTVRemote(remote.RemoteDevice): class AppleTVRemote(remote.RemoteEntity):
"""Device that sends commands to an Apple TV.""" """Device that sends commands to an Apple TV."""
def __init__(self, atv, power, name): def __init__(self, atv, power, name):

View file

@ -22,7 +22,7 @@ from homeassistant.components.remote import (
DOMAIN as COMPONENT, DOMAIN as COMPONENT,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
SUPPORT_LEARN_COMMAND, SUPPORT_LEARN_COMMAND,
RemoteDevice, RemoteEntity,
) )
from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_TIMEOUT, CONF_TYPE from homeassistant.const import CONF_HOST, CONF_MAC, CONF_NAME, CONF_TIMEOUT, CONF_TYPE
from homeassistant.core import callback 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) async_add_entities([remote], False)
class BroadlinkRemote(RemoteDevice): class BroadlinkRemote(RemoteEntity):
"""Representation of a Broadlink remote.""" """Representation of a Broadlink remote."""
def __init__(self, name, unique_id, api, code_storage, flag_storage): def __init__(self, name, unique_id, api, code_storage, flag_storage):

View file

@ -1,5 +1,5 @@
"""Demo platform that has two fake remotes.""" """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 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.""" """Representation of a demo remote."""
def __init__(self, name, state, icon): 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 directv import DIRECTV, DIRECTVError
from homeassistant.components.remote import RemoteDevice from homeassistant.components.remote import RemoteEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
@ -36,7 +36,7 @@ async def async_setup_entry(
async_add_entities(entities, True) async_add_entities(entities, True)
class DIRECTVRemote(DIRECTVEntity, RemoteDevice): class DIRECTVRemote(DIRECTVEntity, RemoteEntity):
"""Device that sends commands to a DirecTV receiver.""" """Device that sends commands to a DirecTV receiver."""
def __init__(self, *, dtv: DIRECTV, name: str, address: str = "0") -> None: 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.""" """Remote representation used to control a Harmony device."""
def __init__(self, name, unique_id, host, activity, out_path, delay_secs): 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 return True
class ITachIP2IRRemote(remote.RemoteDevice): class ITachIP2IRRemote(remote.RemoteEntity):
"""Device that sends commands to an ITachIP2IR device.""" """Device that sends commands to an ITachIP2IR device."""
def __init__(self, itachip2ir, name): 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) return await cast(EntityComponent, hass.data[DOMAIN]).async_unload_entry(entry)
class RemoteDevice(ToggleEntity): class RemoteEntity(ToggleEntity):
"""Representation of a remote.""" """Representation of a remote."""
@property @property
@ -149,3 +149,15 @@ class RemoteDevice(ToggleEntity):
"""Learn a command from a device.""" """Learn a command from a device."""
assert self.hass is not None assert self.hass is not None
await self.hass.async_add_executor_job(ft.partial(self.learn_command, **kwargs)) 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 roku import RokuException
from homeassistant.components.remote import RemoteDevice from homeassistant.components.remote import RemoteEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.helpers.typing import HomeAssistantType from homeassistant.helpers.typing import HomeAssistantType
@ -24,7 +24,7 @@ async def async_setup_entry(
async_add_entities([RokuRemote(roku)], True) async_add_entities([RokuRemote(roku)], True)
class RokuRemote(RemoteDevice): class RokuRemote(RemoteEntity):
"""Device that sends commands to an Roku.""" """Device that sends commands to an Roku."""
def __init__(self, roku): def __init__(self, roku):

View file

@ -12,7 +12,7 @@ from homeassistant.components.remote import (
ATTR_NUM_REPEATS, ATTR_NUM_REPEATS,
DEFAULT_DELAY_SECS, DEFAULT_DELAY_SECS,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
RemoteDevice, RemoteEntity,
) )
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, 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.""" """Representation of a Xiaomi Miio Remote device."""
def __init__(self, friendly_name, device, unique_id, slot, timeout, commands): 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.domain == remote.DOMAIN
assert call.service == SERVICE_LEARN_COMMAND assert call.service == SERVICE_LEARN_COMMAND
assert call.data[ATTR_ENTITY_ID] == "entity_id_val" 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