mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Fix zone cleaning and raise config entry not ready when needed (#37741)
This commit is contained in:
parent
d8c2732bcb
commit
ddfbeffd28
@ -9,6 +9,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT
|
from homeassistant.config_entries import SOURCE_IMPORT
|
||||||
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
@ -91,9 +92,8 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
async def async_setup_entry(hass, entry):
|
async def async_setup_entry(hass, entry):
|
||||||
"""Set up config entry."""
|
"""Set up config entry."""
|
||||||
hass.data[NEATO_LOGIN] = NeatoHub(hass, entry.data, Account)
|
hub = NeatoHub(hass, entry.data, Account)
|
||||||
|
|
||||||
hub = hass.data[NEATO_LOGIN]
|
|
||||||
await hass.async_add_executor_job(hub.login)
|
await hass.async_add_executor_job(hub.login)
|
||||||
if not hub.logged_in:
|
if not hub.logged_in:
|
||||||
_LOGGER.debug("Failed to login to Neato API")
|
_LOGGER.debug("Failed to login to Neato API")
|
||||||
@ -103,10 +103,12 @@ async def async_setup_entry(hass, entry):
|
|||||||
await hass.async_add_executor_job(hub.update_robots)
|
await hass.async_add_executor_job(hub.update_robots)
|
||||||
except NeatoRobotException:
|
except NeatoRobotException:
|
||||||
_LOGGER.debug("Failed to connect to Neato API")
|
_LOGGER.debug("Failed to connect to Neato API")
|
||||||
return False
|
raise ConfigEntryNotReady
|
||||||
|
|
||||||
|
hass.data[NEATO_LOGIN] = hub
|
||||||
|
|
||||||
for component in ("camera", "vacuum", "switch", "sensor"):
|
for component in ("camera", "vacuum", "switch", "sensor"):
|
||||||
hass.async_create_task(
|
hass.async_add_job(
|
||||||
hass.config_entries.async_forward_entry_setup(entry, component)
|
hass.config_entries.async_forward_entry_setup(entry, component)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,6 +156,7 @@ class NeatoHub:
|
|||||||
_LOGGER.error("Invalid credentials")
|
_LOGGER.error("Invalid credentials")
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("Unable to connect to Neato API")
|
_LOGGER.error("Unable to connect to Neato API")
|
||||||
|
raise ConfigEntryNotReady
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ NEATO_MAP_DATA = "neato_map_data"
|
|||||||
NEATO_PERSISTENT_MAPS = "neato_persistent_maps"
|
NEATO_PERSISTENT_MAPS = "neato_persistent_maps"
|
||||||
NEATO_ROBOTS = "neato_robots"
|
NEATO_ROBOTS = "neato_robots"
|
||||||
|
|
||||||
SCAN_INTERVAL_MINUTES = 5
|
SCAN_INTERVAL_MINUTES = 1
|
||||||
|
|
||||||
SERVICE_NEATO_CUSTOM_CLEANING = "custom_cleaning"
|
SERVICE_NEATO_CUSTOM_CLEANING = "custom_cleaning"
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ class NeatoConnectedVacuum(StateVacuumEntity):
|
|||||||
self._clean_error_time = None
|
self._clean_error_time = None
|
||||||
self._launched_from = None
|
self._launched_from = None
|
||||||
self._battery_level = None
|
self._battery_level = None
|
||||||
self._robot_boundaries = {}
|
self._robot_boundaries = []
|
||||||
self._robot_stats = None
|
self._robot_stats = None
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
@ -241,14 +241,27 @@ class NeatoConnectedVacuum(StateVacuumEntity):
|
|||||||
and self._robot_maps[self._robot_serial]
|
and self._robot_maps[self._robot_serial]
|
||||||
):
|
):
|
||||||
allmaps = self._robot_maps[self._robot_serial]
|
allmaps = self._robot_maps[self._robot_serial]
|
||||||
|
_LOGGER.debug("Found the following maps for '%s': %s", self._name, allmaps)
|
||||||
|
self._robot_boundaries = [] # Reset boundaries before refreshing boundaries
|
||||||
for maps in allmaps:
|
for maps in allmaps:
|
||||||
try:
|
try:
|
||||||
self._robot_boundaries = self.robot.get_map_boundaries(
|
robot_boundaries = self.robot.get_map_boundaries(maps["id"]).json()
|
||||||
maps["id"]
|
|
||||||
).json()
|
|
||||||
except NeatoRobotException as ex:
|
except NeatoRobotException as ex:
|
||||||
_LOGGER.error("Could not fetch map boundaries: %s", ex)
|
_LOGGER.error("Could not fetch map boundaries: %s", ex)
|
||||||
self._robot_boundaries = {}
|
return
|
||||||
|
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Boundaries for robot '%s' in map '%s': %s",
|
||||||
|
self._name,
|
||||||
|
maps["name"],
|
||||||
|
robot_boundaries,
|
||||||
|
)
|
||||||
|
self._robot_boundaries += robot_boundaries["data"]["boundaries"]
|
||||||
|
_LOGGER.debug(
|
||||||
|
"List of boundaries for '%s': %s",
|
||||||
|
self._name,
|
||||||
|
self._robot_boundaries,
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -323,6 +336,7 @@ class NeatoConnectedVacuum(StateVacuumEntity):
|
|||||||
info["manufacturer"] = self._robot_stats["battery"]["vendor"]
|
info["manufacturer"] = self._robot_stats["battery"]["vendor"]
|
||||||
info["model"] = self._robot_stats["model"]
|
info["model"] = self._robot_stats["model"]
|
||||||
info["sw_version"] = self._robot_stats["firmware"]
|
info["sw_version"] = self._robot_stats["firmware"]
|
||||||
|
return info
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start cleaning or resume cleaning."""
|
"""Start cleaning or resume cleaning."""
|
||||||
@ -376,7 +390,7 @@ class NeatoConnectedVacuum(StateVacuumEntity):
|
|||||||
"""Zone cleaning service call."""
|
"""Zone cleaning service call."""
|
||||||
boundary_id = None
|
boundary_id = None
|
||||||
if zone is not None:
|
if zone is not None:
|
||||||
for boundary in self._robot_boundaries["data"]["boundaries"]:
|
for boundary in self._robot_boundaries:
|
||||||
if zone in boundary["name"]:
|
if zone in boundary["name"]:
|
||||||
boundary_id = boundary["id"]
|
boundary_id = boundary["id"]
|
||||||
if boundary_id is None:
|
if boundary_id is None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user