mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 15:47:12 +00:00
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
This commit is contained in:
parent
b303c8e040
commit
e5eddba223
@ -1,6 +1,8 @@
|
|||||||
"""The Litter-Robot integration."""
|
"""The Litter-Robot integration."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pylitterbot import FeederRobot, LitterRobot, LitterRobot3, LitterRobot4
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
@ -16,6 +18,34 @@ PLATFORMS = [
|
|||||||
Platform.VACUUM,
|
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:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Litter-Robot from a config entry."""
|
"""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)
|
hub = hass.data[DOMAIN][entry.entry_id] = LitterRobotHub(hass, entry.data)
|
||||||
await hub.login(load_robots=True)
|
await hub.login(load_robots=True)
|
||||||
|
|
||||||
if any(hub.litter_robots()):
|
platforms: set[str] = set()
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
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
|
return True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user