Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use entity_category in litterrobot #59074

Merged
merged 1 commit into from Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions homeassistant/components/litterrobot/entity.py
Expand Up @@ -9,6 +9,7 @@
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
Expand Down Expand Up @@ -111,3 +112,9 @@ def parse_time_at_default_timezone(time_str: str) -> time | None:
)
.timetz()
)


class LitterRobotConfigEntity(LitterRobotControlEntity):
"""A Litter-Robot entity that can control configuration of the unit."""

_attr_entity_category = ENTITY_CATEGORY_CONFIG
natekspencer marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 2 additions & 2 deletions homeassistant/components/litterrobot/select.py
Expand Up @@ -9,7 +9,7 @@
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"
Expand All @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/litterrobot/switch.py
Expand Up @@ -9,11 +9,11 @@
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
Expand All @@ -35,7 +35,7 @@ async def async_turn_off(self, **kwargs: Any) -> None:
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
Expand All @@ -57,7 +57,7 @@ async def async_turn_off(self, **kwargs: Any) -> None:
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"),
]
Expand Down
8 changes: 7 additions & 1 deletion tests/components/litterrobot/test_select.py
Expand Up @@ -10,8 +10,9 @@
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
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tests/components/litterrobot/test_switch.py
Expand Up @@ -9,7 +9,8 @@
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
Expand All @@ -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",
Expand Down