Use entity_category in litterrobot (#59074)

This commit is contained in:
Nathan Spencer 2021-11-04 15:34:54 -06:00 committed by GitHub
parent 38b61f3ff9
commit ea4009fd81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 8 deletions

View File

@ -9,6 +9,7 @@ from typing import Any
from pylitterbot import Robot
from pylitterbot.exceptions import InvalidCommandException
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.core import callback
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.event import async_call_later
@ -111,3 +112,9 @@ class LitterRobotControlEntity(LitterRobotEntity):
)
.timetz()
)
class LitterRobotConfigEntity(LitterRobotControlEntity):
"""A Litter-Robot entity that can control configuration of the unit."""
_attr_entity_category = ENTITY_CATEGORY_CONFIG

View File

@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import LitterRobotControlEntity
from .entity import LitterRobotConfigEntity
from .hub import LitterRobotHub
TYPE_CLEAN_CYCLE_WAIT_TIME_MINUTES = "Clean Cycle Wait Time Minutes"
@ -33,7 +33,7 @@ async def async_setup_entry(
)
class LitterRobotSelect(LitterRobotControlEntity, SelectEntity):
class LitterRobotSelect(LitterRobotConfigEntity, SelectEntity):
"""Litter-Robot Select."""
_attr_icon = "mdi:timer-outline"

View File

@ -9,11 +9,11 @@ from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN
from .entity import LitterRobotControlEntity
from .entity import LitterRobotConfigEntity
from .hub import LitterRobotHub
class LitterRobotNightLightModeSwitch(LitterRobotControlEntity, SwitchEntity):
class LitterRobotNightLightModeSwitch(LitterRobotConfigEntity, SwitchEntity):
"""Litter-Robot Night Light Mode Switch."""
@property
@ -35,7 +35,7 @@ class LitterRobotNightLightModeSwitch(LitterRobotControlEntity, SwitchEntity):
await self.perform_action_and_refresh(self.robot.set_night_light, False)
class LitterRobotPanelLockoutSwitch(LitterRobotControlEntity, SwitchEntity):
class LitterRobotPanelLockoutSwitch(LitterRobotConfigEntity, SwitchEntity):
"""Litter-Robot Panel Lockout Switch."""
@property
@ -57,7 +57,7 @@ class LitterRobotPanelLockoutSwitch(LitterRobotControlEntity, SwitchEntity):
await self.perform_action_and_refresh(self.robot.set_panel_lockout, False)
ROBOT_SWITCHES: list[tuple[type[LitterRobotControlEntity], str]] = [
ROBOT_SWITCHES: list[tuple[type[LitterRobotConfigEntity], str]] = [
(LitterRobotNightLightModeSwitch, "Night Light Mode"),
(LitterRobotPanelLockoutSwitch, "Panel Lockout"),
]

View File

@ -10,8 +10,9 @@ from homeassistant.components.select import (
DOMAIN as PLATFORM_DOMAIN,
SERVICE_SELECT_OPTION,
)
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_CATEGORY_CONFIG
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.util.dt import utcnow
from .conftest import setup_integration
@ -28,6 +29,11 @@ async def test_wait_time_select(hass: HomeAssistant, mock_account):
select = hass.states.get(SELECT_ENTITY_ID)
assert select
ent_reg = entity_registry.async_get(hass)
entity_entry = ent_reg.async_get(SELECT_ENTITY_ID)
assert entity_entry
assert entity_entry.entity_category == ENTITY_CATEGORY_CONFIG
data = {ATTR_ENTITY_ID: SELECT_ENTITY_ID}
count = 0

View File

@ -9,7 +9,8 @@ from homeassistant.components.switch import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.const import ATTR_ENTITY_ID, STATE_ON
from homeassistant.const import ATTR_ENTITY_ID, ENTITY_CATEGORY_CONFIG, STATE_ON
from homeassistant.helpers import entity_registry
from homeassistant.util.dt import utcnow
from .conftest import setup_integration
@ -28,6 +29,11 @@ async def test_switch(hass, mock_account):
assert switch
assert switch.state == STATE_ON
ent_reg = entity_registry.async_get(hass)
entity_entry = ent_reg.async_get(NIGHT_LIGHT_MODE_ENTITY_ID)
assert entity_entry
assert entity_entry.entity_category == ENTITY_CATEGORY_CONFIG
@pytest.mark.parametrize(
"entity_id,robot_command",