From ea4009fd81ad6aeb25c09e5e7fa7c2a7efcb96b2 Mon Sep 17 00:00:00 2001 From: Nathan Spencer Date: Thu, 4 Nov 2021 15:34:54 -0600 Subject: [PATCH] Use entity_category in litterrobot (#59074) --- homeassistant/components/litterrobot/entity.py | 7 +++++++ homeassistant/components/litterrobot/select.py | 4 ++-- homeassistant/components/litterrobot/switch.py | 8 ++++---- tests/components/litterrobot/test_select.py | 8 +++++++- tests/components/litterrobot/test_switch.py | 8 +++++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/litterrobot/entity.py b/homeassistant/components/litterrobot/entity.py index 5a6590f9360..064c9bcf8f1 100644 --- a/homeassistant/components/litterrobot/entity.py +++ b/homeassistant/components/litterrobot/entity.py @@ -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 diff --git a/homeassistant/components/litterrobot/select.py b/homeassistant/components/litterrobot/select.py index ceb20b52d40..c1a0718510d 100644 --- a/homeassistant/components/litterrobot/select.py +++ b/homeassistant/components/litterrobot/select.py @@ -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" diff --git a/homeassistant/components/litterrobot/switch.py b/homeassistant/components/litterrobot/switch.py index 25385ecf650..9a08a008d96 100644 --- a/homeassistant/components/litterrobot/switch.py +++ b/homeassistant/components/litterrobot/switch.py @@ -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"), ] diff --git a/tests/components/litterrobot/test_select.py b/tests/components/litterrobot/test_select.py index c0c436764af..dfb1b0e639e 100644 --- a/tests/components/litterrobot/test_select.py +++ b/tests/components/litterrobot/test_select.py @@ -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 diff --git a/tests/components/litterrobot/test_switch.py b/tests/components/litterrobot/test_switch.py index 2659b1cc049..d651b09fadc 100644 --- a/tests/components/litterrobot/test_switch.py +++ b/tests/components/litterrobot/test_switch.py @@ -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",