From e5eddba22365e8b9481f71da219c8c56faf013cb Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Wed, 31 Aug 2022 06:54:59 -0400 Subject: [PATCH] Litterrobot - Do not load a platform if there is no device supporting it (#77497) * Do not load button platform if no Litter Robot 3 * uno mas * uno mas * Do not load Vacuum if not needed * Use dict to map platforms for each model * uno mas --- .../components/litterrobot/__init__.py | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/litterrobot/__init__.py b/homeassistant/components/litterrobot/__init__.py index 5aa186d0171..d302989fc01 100644 --- a/homeassistant/components/litterrobot/__init__.py +++ b/homeassistant/components/litterrobot/__init__.py @@ -1,6 +1,8 @@ """The Litter-Robot integration.""" from __future__ import annotations +from pylitterbot import FeederRobot, LitterRobot, LitterRobot3, LitterRobot4 + from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant @@ -16,6 +18,34 @@ PLATFORMS = [ Platform.VACUUM, ] +PLATFORMS_BY_TYPE = { + LitterRobot: ( + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + Platform.VACUUM, + ), + LitterRobot3: ( + Platform.BUTTON, + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + Platform.VACUUM, + ), + LitterRobot4: ( + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + Platform.VACUUM, + ), + FeederRobot: ( + Platform.BUTTON, + Platform.SELECT, + Platform.SENSOR, + Platform.SWITCH, + ), +} + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Litter-Robot from a config entry.""" @@ -23,8 +53,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hub = hass.data[DOMAIN][entry.entry_id] = LitterRobotHub(hass, entry.data) await hub.login(load_robots=True) - if any(hub.litter_robots()): - await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) + platforms: set[str] = set() + for robot in hub.account.robots: + platforms.update(PLATFORMS_BY_TYPE[type(robot)]) + if platforms: + await hass.config_entries.async_forward_entry_setups(entry, platforms) return True