Refactor litterrobot to use SensorEntityDescription (#71224)
This commit is contained in:
parent
3332c853c4
commit
ae89a1243a
3 changed files with 84 additions and 67 deletions
|
@ -67,6 +67,12 @@ def mock_account_with_sleeping_robot() -> MagicMock:
|
|||
return create_mock_account({"sleepModeActive": "102:00:00"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_account_with_sleep_disabled_robot() -> MagicMock:
|
||||
"""Mock a Litter-Robot account with a robot that has sleep mode disabled."""
|
||||
return create_mock_account({"sleepModeActive": "0"})
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_account_with_robot_not_recently_seen() -> MagicMock:
|
||||
"""Mock a Litter-Robot account with a sleeping robot."""
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
"""Test the Litter-Robot sensor entity."""
|
||||
from unittest.mock import Mock
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.components.litterrobot.sensor import LitterRobotSleepTimeSensor
|
||||
from homeassistant.components.sensor import DOMAIN as PLATFORM_DOMAIN, SensorDeviceClass
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.const import PERCENTAGE, STATE_UNKNOWN
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import create_mock_robot, setup_integration
|
||||
from .conftest import setup_integration
|
||||
|
||||
WASTE_DRAWER_ENTITY_ID = "sensor.test_waste_drawer"
|
||||
SLEEP_START_TIME_ENTITY_ID = "sensor.test_sleep_mode_start_time"
|
||||
|
||||
|
||||
async def test_waste_drawer_sensor(hass, mock_account):
|
||||
async def test_waste_drawer_sensor(
|
||||
hass: HomeAssistant, mock_account: MagicMock
|
||||
) -> None:
|
||||
"""Tests the waste drawer sensor entity was set up."""
|
||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
||||
|
||||
|
@ -20,20 +23,21 @@ async def test_waste_drawer_sensor(hass, mock_account):
|
|||
assert sensor.attributes["unit_of_measurement"] == PERCENTAGE
|
||||
|
||||
|
||||
async def test_sleep_time_sensor_with_none_state(hass):
|
||||
"""Tests the sleep mode start time sensor where sleep mode is inactive."""
|
||||
robot = create_mock_robot({"sleepModeActive": "0"})
|
||||
sensor = LitterRobotSleepTimeSensor(
|
||||
robot, "Sleep Mode Start Time", Mock(), "sleep_mode_start_time"
|
||||
async def test_sleep_time_sensor_with_sleep_disabled(
|
||||
hass: HomeAssistant, mock_account_with_sleep_disabled_robot: MagicMock
|
||||
) -> None:
|
||||
"""Tests the sleep mode start time sensor where sleep mode is disabled."""
|
||||
await setup_integration(
|
||||
hass, mock_account_with_sleep_disabled_robot, PLATFORM_DOMAIN
|
||||
)
|
||||
sensor.hass = hass
|
||||
|
||||
sensor = hass.states.get(SLEEP_START_TIME_ENTITY_ID)
|
||||
assert sensor
|
||||
assert sensor.state is None
|
||||
assert sensor.device_class is SensorDeviceClass.TIMESTAMP
|
||||
assert sensor.state == STATE_UNKNOWN
|
||||
assert sensor.attributes["device_class"] == SensorDeviceClass.TIMESTAMP
|
||||
|
||||
|
||||
async def test_gauge_icon():
|
||||
async def test_gauge_icon() -> None:
|
||||
"""Test icon generator for gauge sensor."""
|
||||
from homeassistant.components.litterrobot.sensor import icon_for_gauge_level
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue