Home Assistant Unofficial Reference 2024.12.1
hub.py
Go to the documentation of this file.
1 """Support for Neato botvac connected vacuum cleaners."""
2 
3 from datetime import timedelta
4 import logging
5 
6 from pybotvac import Account
7 from urllib3.response import HTTPResponse
8 
9 from homeassistant.config_entries import ConfigEntry
10 from homeassistant.core import HomeAssistant
11 from homeassistant.util import Throttle
12 
13 from .const import NEATO_MAP_DATA, NEATO_PERSISTENT_MAPS, NEATO_ROBOTS
14 
15 _LOGGER = logging.getLogger(__name__)
16 
17 
18 class NeatoHub:
19  """A My Neato hub wrapper class."""
20 
21  def __init__(self, hass: HomeAssistant, neato: Account) -> None:
22  """Initialize the Neato hub."""
23  self._hass_hass = hass
24  self.my_neato: Account = neato
25 
26  @Throttle(timedelta(minutes=1))
27  def update_robots(self) -> None:
28  """Update the robot states."""
29  _LOGGER.debug("Running HUB.update_robots %s", self._hass_hass.data.get(NEATO_ROBOTS))
30  self._hass_hass.data[NEATO_ROBOTS] = self.my_neato.robots
31  self._hass_hass.data[NEATO_PERSISTENT_MAPS] = self.my_neato.persistent_maps
32  self._hass_hass.data[NEATO_MAP_DATA] = self.my_neato.maps
33 
34  def download_map(self, url: str) -> HTTPResponse:
35  """Download a new map image."""
36  map_image_data: HTTPResponse = self.my_neato.get_map_image(url)
37  return map_image_data
38 
39  async def async_update_entry_unique_id(self, entry: ConfigEntry) -> str:
40  """Update entry for unique_id."""
41 
42  await self._hass_hass.async_add_executor_job(self.my_neato.refresh_userdata)
43  unique_id: str = self.my_neato.unique_id
44 
45  if entry.unique_id == unique_id:
46  return unique_id
47 
48  _LOGGER.debug("Updating user unique_id for previous config entry")
49  self._hass_hass.config_entries.async_update_entry(entry, unique_id=unique_id)
50  return unique_id
HTTPResponse download_map(self, str url)
Definition: hub.py:34
None __init__(self, HomeAssistant hass, Account neato)
Definition: hub.py:21
str async_update_entry_unique_id(self, ConfigEntry entry)
Definition: hub.py:39