Rename BinarySensorDevice to BinarySensorEntity (#34462)

* Rename BinarySensorDevice to BinarySensorEntity

* Tweak

* Move deprecation warning to __new__, add test

* Move deprecation warning back to __init__

* Move deprecation warning to __init_subclass
This commit is contained in:
Erik Montnemery authored and GitHub committed 2020-04-23 21:57:07 +02:00
1 parent 0b64f49e3a
commit b022e08db9
147 files changed
+371 -352

No files matched your search

+21 -16
View File
@@ -1,24 +1,29 @@
"""The tests for the Binary sensor component."""
import unittest
from unittest import mock
from homeassistant.components import binary_sensor
from homeassistant.const import STATE_OFF, STATE_ON
class TestBinarySensor(unittest.TestCase):
"""Test the binary_sensor base class."""
def test_state():
"""Test binary sensor state."""
sensor = binary_sensor.BinarySensorEntity()
assert STATE_OFF == sensor.state
with mock.patch(
"homeassistant.components.binary_sensor.BinarySensorEntity.is_on", new=False,
):
assert STATE_OFF == binary_sensor.BinarySensorEntity().state
with mock.patch(
"homeassistant.components.binary_sensor.BinarySensorEntity.is_on", new=True,
):
assert STATE_ON == binary_sensor.BinarySensorEntity().state
def test_state(self):
"""Test binary sensor state."""
sensor = binary_sensor.BinarySensorDevice()
assert STATE_OFF == sensor.state
with mock.patch(
"homeassistant.components.binary_sensor.BinarySensorDevice.is_on",
new=False,
):
assert STATE_OFF == binary_sensor.BinarySensorDevice().state
with mock.patch(
"homeassistant.components.binary_sensor.BinarySensorDevice.is_on", new=True,
):
assert STATE_ON == binary_sensor.BinarySensorDevice().state
def test_deprecated_base_class(caplog):
"""Test deprecated base class."""
class CustomBinarySensor(binary_sensor.BinarySensorDevice):
pass
CustomBinarySensor()
assert "BinarySensorDevice is deprecated, modify CustomBinarySensor" in caplog.text
@@ -3,7 +3,7 @@ Provide a mock binary sensor platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorDevice
from homeassistant.components.binary_sensor import DEVICE_CLASSES, BinarySensorEntity
from tests.common import MockEntity
@@ -36,7 +36,7 @@ async def async_setup_platform(
async_add_entities_callback(list(ENTITIES.values()))
class MockBinarySensor(MockEntity, BinarySensorDevice):
class MockBinarySensor(MockEntity, BinarySensorEntity):
"""Mock Binary Sensor class."""
@property