mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Rename VacuumDevice to VacuumEntity (#34674)
This commit is contained in:
parent
90e0a1af8a
commit
d3ed80cf53
@ -21,8 +21,8 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
SUPPORT_TURN_OFF,
|
SUPPORT_TURN_OFF,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
VacuumDevice,
|
VacuumEntity,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -95,7 +95,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DemoVacuum(VacuumDevice):
|
class DemoVacuum(VacuumEntity):
|
||||||
"""Representation of a demo vacuum."""
|
"""Representation of a demo vacuum."""
|
||||||
|
|
||||||
def __init__(self, name, supported_features):
|
def __init__(self, name, supported_features):
|
||||||
@ -254,7 +254,7 @@ class DemoVacuum(VacuumDevice):
|
|||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class StateDemoVacuum(StateVacuumDevice):
|
class StateDemoVacuum(StateVacuumEntity):
|
||||||
"""Representation of a demo vacuum supporting states."""
|
"""Representation of a demo vacuum supporting states."""
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
|
@ -13,7 +13,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
SUPPORT_TURN_OFF,
|
SUPPORT_TURN_OFF,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
VacuumDevice,
|
VacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class Dyson360EyeDevice(VacuumDevice):
|
class Dyson360EyeDevice(VacuumEntity):
|
||||||
"""Dyson 360 Eye robot vacuum device."""
|
"""Dyson 360 Eye robot vacuum device."""
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
|
@ -14,7 +14,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
SUPPORT_TURN_OFF,
|
SUPPORT_TURN_OFF,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
VacuumDevice,
|
VacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.icon import icon_for_battery_level
|
from homeassistant.helpers.icon import icon_for_battery_level
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
add_entities(vacuums, True)
|
add_entities(vacuums, True)
|
||||||
|
|
||||||
|
|
||||||
class EcovacsVacuum(VacuumDevice):
|
class EcovacsVacuum(VacuumEntity):
|
||||||
"""Ecovacs Vacuums such as Deebot."""
|
"""Ecovacs Vacuums such as Deebot."""
|
||||||
|
|
||||||
def __init__(self, device):
|
def __init__(self, device):
|
||||||
|
@ -25,7 +25,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
SUPPORT_TURN_OFF,
|
SUPPORT_TURN_OFF,
|
||||||
SUPPORT_TURN_ON,
|
SUPPORT_TURN_ON,
|
||||||
VacuumDevice,
|
VacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, CONF_DEVICE, CONF_NAME
|
from homeassistant.const import ATTR_SUPPORTED_FEATURES, CONF_DEVICE, CONF_NAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -174,7 +174,7 @@ class MqttVacuum(
|
|||||||
MqttAvailability,
|
MqttAvailability,
|
||||||
MqttDiscoveryUpdate,
|
MqttDiscoveryUpdate,
|
||||||
MqttEntityDeviceInfo,
|
MqttEntityDeviceInfo,
|
||||||
VacuumDevice,
|
VacuumEntity,
|
||||||
):
|
):
|
||||||
"""Representation of a MQTT-controlled legacy vacuum."""
|
"""Representation of a MQTT-controlled legacy vacuum."""
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_START,
|
SUPPORT_START,
|
||||||
SUPPORT_STATUS,
|
SUPPORT_STATUS,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_SUPPORTED_FEATURES, CONF_DEVICE, CONF_NAME
|
from homeassistant.const import ATTR_SUPPORTED_FEATURES, CONF_DEVICE, CONF_NAME
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@ -162,7 +162,7 @@ class MqttStateVacuum(
|
|||||||
MqttAvailability,
|
MqttAvailability,
|
||||||
MqttDiscoveryUpdate,
|
MqttDiscoveryUpdate,
|
||||||
MqttEntityDeviceInfo,
|
MqttEntityDeviceInfo,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
):
|
):
|
||||||
"""Representation of a MQTT-controlled state vacuum."""
|
"""Representation of a MQTT-controlled state vacuum."""
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_START,
|
SUPPORT_START,
|
||||||
SUPPORT_STATE,
|
SUPPORT_STATE,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_MODE
|
from homeassistant.const import ATTR_ENTITY_ID, ATTR_MODE
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
@ -126,7 +126,7 @@ async def async_setup_entry(hass, entry, async_add_entities):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NeatoConnectedVacuum(StateVacuumDevice):
|
class NeatoConnectedVacuum(StateVacuumEntity):
|
||||||
"""Representation of a Neato Connected Vacuum."""
|
"""Representation of a Neato Connected Vacuum."""
|
||||||
|
|
||||||
def __init__(self, neato, robot, mapdata, persistent_maps):
|
def __init__(self, neato, robot, mapdata, persistent_maps):
|
||||||
|
@ -17,7 +17,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_START,
|
SUPPORT_START,
|
||||||
SUPPORT_STATE,
|
SUPPORT_STATE,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
@ -104,7 +104,7 @@ class IRobotEntity(Entity):
|
|||||||
self.schedule_update_ha_state()
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
|
|
||||||
class IRobotVacuum(IRobotEntity, StateVacuumDevice):
|
class IRobotVacuum(IRobotEntity, StateVacuumEntity):
|
||||||
"""Base class for iRobot robots."""
|
"""Base class for iRobot robots."""
|
||||||
|
|
||||||
def __init__(self, roomba, blid):
|
def __init__(self, roomba, blid):
|
||||||
|
@ -28,7 +28,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_START,
|
SUPPORT_START,
|
||||||
SUPPORT_STATE,
|
SUPPORT_STATE,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
@ -144,7 +144,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
async_add_entities(vacuums)
|
async_add_entities(vacuums)
|
||||||
|
|
||||||
|
|
||||||
class TemplateVacuum(StateVacuumDevice):
|
class TemplateVacuum(StateVacuumEntity):
|
||||||
"""A template vacuum component."""
|
"""A template vacuum component."""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -228,7 +228,7 @@ class _BaseVacuum(Entity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class VacuumDevice(_BaseVacuum, ToggleEntity):
|
class VacuumEntity(_BaseVacuum, ToggleEntity):
|
||||||
"""Representation of a vacuum cleaner robot."""
|
"""Representation of a vacuum cleaner robot."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -309,7 +309,19 @@ class VacuumDevice(_BaseVacuum, ToggleEntity):
|
|||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
|
|
||||||
class StateVacuumDevice(_BaseVacuum):
|
class VacuumDevice(VacuumEntity):
|
||||||
|
"""Representation of a vacuum (for backwards compatibility)."""
|
||||||
|
|
||||||
|
def __init_subclass__(cls, **kwargs):
|
||||||
|
"""Print deprecation warning."""
|
||||||
|
super().__init_subclass__(**kwargs)
|
||||||
|
_LOGGER.warning(
|
||||||
|
"VacuumDevice is deprecated, modify %s to extend VacuumEntity",
|
||||||
|
cls.__name__,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class StateVacuumEntity(_BaseVacuum):
|
||||||
"""Representation of a vacuum cleaner robot that supports states."""
|
"""Representation of a vacuum cleaner robot that supports states."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -377,3 +389,15 @@ class StateVacuumDevice(_BaseVacuum):
|
|||||||
|
|
||||||
async def async_toggle(self, **kwargs):
|
async def async_toggle(self, **kwargs):
|
||||||
"""Not supported."""
|
"""Not supported."""
|
||||||
|
|
||||||
|
|
||||||
|
class StateVacuumDevice(StateVacuumEntity):
|
||||||
|
"""Representation of a vacuum (for backwards compatibility)."""
|
||||||
|
|
||||||
|
def __init_subclass__(cls, **kwargs):
|
||||||
|
"""Print deprecation warning."""
|
||||||
|
super().__init_subclass__(**kwargs)
|
||||||
|
_LOGGER.warning(
|
||||||
|
"StateVacuumDevice is deprecated, modify %s to extend StateVacuumEntity",
|
||||||
|
cls.__name__,
|
||||||
|
)
|
||||||
|
@ -25,7 +25,7 @@ from homeassistant.components.vacuum import (
|
|||||||
SUPPORT_START,
|
SUPPORT_START,
|
||||||
SUPPORT_STATE,
|
SUPPORT_STATE,
|
||||||
SUPPORT_STOP,
|
SUPPORT_STOP,
|
||||||
StateVacuumDevice,
|
StateVacuumEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
@ -229,7 +229,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class MiroboVacuum(StateVacuumDevice):
|
class MiroboVacuum(StateVacuumEntity):
|
||||||
"""Representation of a Xiaomi Vacuum cleaner robot."""
|
"""Representation of a Xiaomi Vacuum cleaner robot."""
|
||||||
|
|
||||||
def __init__(self, name, vacuum):
|
def __init__(self, name, vacuum):
|
||||||
|
@ -228,7 +228,7 @@ async def test_unsupported_methods(hass):
|
|||||||
assert "spot" not in state.attributes.get(ATTR_STATUS)
|
assert "spot" not in state.attributes.get(ATTR_STATUS)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
# VacuumDevice should not support start and pause methods.
|
# VacuumEntity should not support start and pause methods.
|
||||||
hass.states.async_set(ENTITY_VACUUM_COMPLETE, STATE_ON)
|
hass.states.async_set(ENTITY_VACUUM_COMPLETE, STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
assert vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||||
@ -243,7 +243,7 @@ async def test_unsupported_methods(hass):
|
|||||||
await common.async_start(hass, ENTITY_VACUUM_COMPLETE)
|
await common.async_start(hass, ENTITY_VACUUM_COMPLETE)
|
||||||
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
assert not vacuum.is_on(hass, ENTITY_VACUUM_COMPLETE)
|
||||||
|
|
||||||
# StateVacuumDevice does not support on/off
|
# StateVacuumEntity does not support on/off
|
||||||
await common.async_turn_on(hass, entity_id=ENTITY_VACUUM_STATE)
|
await common.async_turn_on(hass, entity_id=ENTITY_VACUUM_STATE)
|
||||||
state = hass.states.get(ENTITY_VACUUM_STATE)
|
state = hass.states.get(ENTITY_VACUUM_STATE)
|
||||||
assert state.state != STATE_CLEANING
|
assert state.state != STATE_CLEANING
|
||||||
|
18
tests/components/vacuum/test_init.py
Normal file
18
tests/components/vacuum/test_init.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
"""The tests for Vacuum."""
|
||||||
|
from homeassistant.components import vacuum
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecated_base_class(caplog):
|
||||||
|
"""Test deprecated base class."""
|
||||||
|
|
||||||
|
class CustomVacuum(vacuum.VacuumDevice):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class CustomStateVacuum(vacuum.StateVacuumDevice):
|
||||||
|
pass
|
||||||
|
|
||||||
|
CustomVacuum()
|
||||||
|
assert "VacuumDevice is deprecated, modify CustomVacuum" in caplog.text
|
||||||
|
|
||||||
|
CustomStateVacuum()
|
||||||
|
assert "StateVacuumDevice is deprecated, modify CustomStateVacuum" in caplog.text
|
Loading…
x
Reference in New Issue
Block a user