mirror of
https://github.com/home-assistant/core.git
synced 2025-11-17 15:00:12 +00:00
Adjust litterrobot tests and code to match guidelines (#47060)
* Use SwitchEntity instead of ToggleEntity and adjust test patches as recommended * Move async_create_entry out of try block in config_flow * Patch pypi package instead of HA code * Bump pylitterbot to 2021.2.6, fix tests, and implement other code review suggestions * Bump pylitterbot to 2021.2.8, remove sleep mode start/end time from vacuum, adjust and add sensors for sleep mode start/end time * Move icon helper back to Litter-Robot component and isoformat times on time sensors
This commit is contained in:
committed by
Paulus Schoutsen
parent
939da2403f
commit
3b05a12e62
@@ -1,20 +1,57 @@
|
||||
"""Test the Litter-Robot sensor entity."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
from homeassistant.components.litterrobot.sensor import LitterRobotSleepTimeSensor
|
||||
from homeassistant.components.sensor import DOMAIN as PLATFORM_DOMAIN
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.const import DEVICE_CLASS_TIMESTAMP, PERCENTAGE
|
||||
|
||||
from .conftest import setup_hub
|
||||
from .conftest import create_mock_robot, setup_integration
|
||||
|
||||
ENTITY_ID = "sensor.test_waste_drawer"
|
||||
WASTE_DRAWER_ENTITY_ID = "sensor.test_waste_drawer"
|
||||
|
||||
|
||||
async def test_sensor(hass, mock_hub):
|
||||
"""Tests the sensor entity was set up."""
|
||||
await setup_hub(hass, mock_hub, PLATFORM_DOMAIN)
|
||||
async def test_waste_drawer_sensor(hass, mock_account):
|
||||
"""Tests the waste drawer sensor entity was set up."""
|
||||
await setup_integration(hass, mock_account, PLATFORM_DOMAIN)
|
||||
|
||||
sensor = hass.states.get(ENTITY_ID)
|
||||
sensor = hass.states.get(WASTE_DRAWER_ENTITY_ID)
|
||||
assert sensor
|
||||
assert sensor.state == "50"
|
||||
assert sensor.attributes["cycle_count"] == 15
|
||||
assert sensor.attributes["cycle_capacity"] == 30
|
||||
assert sensor.attributes["cycles_after_drawer_full"] == 0
|
||||
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()
|
||||
robot.sleep_mode_active = False
|
||||
sensor = LitterRobotSleepTimeSensor(
|
||||
robot, "Sleep Mode Start Time", Mock(), "sleep_mode_start_time"
|
||||
)
|
||||
|
||||
assert sensor
|
||||
assert sensor.state is None
|
||||
assert sensor.device_class == DEVICE_CLASS_TIMESTAMP
|
||||
|
||||
|
||||
async def test_gauge_icon():
|
||||
"""Test icon generator for gauge sensor."""
|
||||
from homeassistant.components.litterrobot.sensor import icon_for_gauge_level
|
||||
|
||||
GAUGE_EMPTY = "mdi:gauge-empty"
|
||||
GAUGE_LOW = "mdi:gauge-low"
|
||||
GAUGE = "mdi:gauge"
|
||||
GAUGE_FULL = "mdi:gauge-full"
|
||||
|
||||
assert icon_for_gauge_level(None) == GAUGE_EMPTY
|
||||
assert icon_for_gauge_level(0) == GAUGE_EMPTY
|
||||
assert icon_for_gauge_level(5) == GAUGE_LOW
|
||||
assert icon_for_gauge_level(40) == GAUGE
|
||||
assert icon_for_gauge_level(80) == GAUGE_FULL
|
||||
assert icon_for_gauge_level(100) == GAUGE_FULL
|
||||
|
||||
assert icon_for_gauge_level(None, 10) == GAUGE_EMPTY
|
||||
assert icon_for_gauge_level(0, 10) == GAUGE_EMPTY
|
||||
assert icon_for_gauge_level(5, 10) == GAUGE_EMPTY
|
||||
assert icon_for_gauge_level(40, 10) == GAUGE_LOW
|
||||
assert icon_for_gauge_level(80, 10) == GAUGE
|
||||
assert icon_for_gauge_level(100, 10) == GAUGE_FULL
|
||||
|
||||
Reference in New Issue
Block a user