Add icon translations to Litterrobot (#111899)
This commit is contained in:
parent
f0be33fc6a
commit
e43c62af1e
6 changed files with 46 additions and 17 deletions
|
@ -52,7 +52,6 @@ BINARY_SENSOR_MAP: dict[type[Robot], tuple[RobotBinarySensorEntityDescription, .
|
|||
RobotBinarySensorEntityDescription[LitterRobot](
|
||||
key="sleeping",
|
||||
translation_key="sleeping",
|
||||
icon="mdi:sleep",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
is_on_fn=lambda robot: robot.is_sleeping,
|
||||
|
@ -60,7 +59,6 @@ BINARY_SENSOR_MAP: dict[type[Robot], tuple[RobotBinarySensorEntityDescription, .
|
|||
RobotBinarySensorEntityDescription[LitterRobot](
|
||||
key="sleep_mode",
|
||||
translation_key="sleep_mode",
|
||||
icon="mdi:sleep",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
entity_registry_enabled_default=False,
|
||||
is_on_fn=lambda robot: robot.sleep_mode_enabled,
|
||||
|
|
|
@ -61,14 +61,12 @@ class RobotButtonEntityDescription(ButtonEntityDescription, RequiredKeysMixin[_R
|
|||
LITTER_ROBOT_BUTTON = RobotButtonEntityDescription[LitterRobot3](
|
||||
key="reset_waste_drawer",
|
||||
translation_key="reset_waste_drawer",
|
||||
icon="mdi:delete-variant",
|
||||
entity_category=EntityCategory.CONFIG,
|
||||
press_fn=lambda robot: robot.reset_waste_drawer(),
|
||||
)
|
||||
FEEDER_ROBOT_BUTTON = RobotButtonEntityDescription[FeederRobot](
|
||||
key="give_snack",
|
||||
translation_key="give_snack",
|
||||
icon="mdi:candy-outline",
|
||||
press_fn=lambda robot: robot.give_snack(),
|
||||
)
|
||||
|
||||
|
|
45
homeassistant/components/litterrobot/icons.json
Normal file
45
homeassistant/components/litterrobot/icons.json
Normal file
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"sleeping": {
|
||||
"default": "mdi:sleep"
|
||||
},
|
||||
"sleep_mode": {
|
||||
"default": "mdi:sleep"
|
||||
}
|
||||
},
|
||||
"button": {
|
||||
"reset_waste_drawer": {
|
||||
"default": "mdi:delete-variant"
|
||||
},
|
||||
"give_snack": {
|
||||
"default": "mdi:candy-outline"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"cycle_delay": {
|
||||
"default": "mdi:timer-outline"
|
||||
},
|
||||
"meal_insert_size": {
|
||||
"default": "mdi:scale"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"night_light_mode": {
|
||||
"default": "mdi:lightbulb-off",
|
||||
"state": {
|
||||
"on": "mdi:lightbulb-on"
|
||||
}
|
||||
},
|
||||
"panel_lockout": {
|
||||
"default": "mdi:lock-open",
|
||||
"state": {
|
||||
"on": "mdi:lock"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"set_sleep_mode": "mdi:sleep"
|
||||
}
|
||||
}
|
|
@ -51,7 +51,6 @@ ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = {
|
|||
LitterRobot: RobotSelectEntityDescription[LitterRobot, int]( # type: ignore[type-abstract] # only used for isinstance check
|
||||
key="cycle_delay",
|
||||
translation_key="cycle_delay",
|
||||
icon="mdi:timer-outline",
|
||||
unit_of_measurement=UnitOfTime.MINUTES,
|
||||
current_fn=lambda robot: robot.clean_cycle_wait_time_minutes,
|
||||
options_fn=lambda robot: robot.VALID_WAIT_TIMES,
|
||||
|
@ -72,7 +71,6 @@ ROBOT_SELECT_MAP: dict[type[Robot], RobotSelectEntityDescription] = {
|
|||
FeederRobot: RobotSelectEntityDescription[FeederRobot, float](
|
||||
key="meal_insert_size",
|
||||
translation_key="meal_insert_size",
|
||||
icon="mdi:scale",
|
||||
unit_of_measurement="cups",
|
||||
current_fn=lambda robot: robot.meal_insert_size,
|
||||
options_fn=lambda robot: robot.VALID_MEAL_INSERT_SIZES,
|
||||
|
|
|
@ -22,7 +22,6 @@ from .hub import LitterRobotHub
|
|||
class RequiredKeysMixin(Generic[_RobotT]):
|
||||
"""A class that describes robot switch entity required keys."""
|
||||
|
||||
icons: tuple[str, str]
|
||||
set_fn: Callable[[_RobotT, bool], Coroutine[Any, Any, bool]]
|
||||
|
||||
|
||||
|
@ -37,13 +36,11 @@ ROBOT_SWITCHES = [
|
|||
RobotSwitchEntityDescription[LitterRobot | FeederRobot](
|
||||
key="night_light_mode_enabled",
|
||||
translation_key="night_light_mode",
|
||||
icons=("mdi:lightbulb-on", "mdi:lightbulb-off"),
|
||||
set_fn=lambda robot, value: robot.set_night_light(value),
|
||||
),
|
||||
RobotSwitchEntityDescription[LitterRobot | FeederRobot](
|
||||
key="panel_lock_enabled",
|
||||
translation_key="panel_lockout",
|
||||
icons=("mdi:lock", "mdi:lock-open"),
|
||||
set_fn=lambda robot, value: robot.set_panel_lockout(value),
|
||||
),
|
||||
]
|
||||
|
@ -59,12 +56,6 @@ class RobotSwitchEntity(LitterRobotEntity[_RobotT], SwitchEntity):
|
|||
"""Return true if switch is on."""
|
||||
return bool(getattr(self.robot, self.entity_description.key))
|
||||
|
||||
@property
|
||||
def icon(self) -> str:
|
||||
"""Return the icon."""
|
||||
icon_on, icon_off = self.entity_description.icons
|
||||
return icon_on if self.is_on else icon_off
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the switch on."""
|
||||
await self.entity_description.set_fn(self.robot, True)
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest.mock import MagicMock
|
|||
from freezegun import freeze_time
|
||||
|
||||
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||
from homeassistant.const import ATTR_ENTITY_ID, ATTR_ICON, STATE_UNKNOWN, EntityCategory
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN, EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
|
@ -21,7 +21,6 @@ async def test_button(
|
|||
|
||||
state = hass.states.get(BUTTON_ENTITY)
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:delete-variant"
|
||||
assert state.state == STATE_UNKNOWN
|
||||
|
||||
entry = entity_registry.async_get(BUTTON_ENTITY)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue