1 """Support for loading picture from Neato."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from pybotvac.exceptions
import NeatoRobotException
10 from pybotvac.robot
import Robot
11 from urllib3.response
import HTTPResponse
18 from .const
import NEATO_LOGIN, NEATO_MAP_DATA, NEATO_ROBOTS, SCAN_INTERVAL_MINUTES
19 from .entity
import NeatoEntity
20 from .hub
import NeatoHub
22 _LOGGER = logging.getLogger(__name__)
24 SCAN_INTERVAL =
timedelta(minutes=SCAN_INTERVAL_MINUTES)
25 ATTR_GENERATED_AT =
"generated_at"
29 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
31 """Set up Neato camera with config entry."""
32 neato: NeatoHub = hass.data[NEATO_LOGIN]
33 mapdata: dict[str, Any] |
None = hass.data.get(NEATO_MAP_DATA)
36 for robot
in hass.data[NEATO_ROBOTS]
37 if "maps" in robot.traits
43 _LOGGER.debug(
"Adding robots for cleaning maps %s", dev)
48 """Neato cleaning map for last clean."""
50 _attr_translation_key =
"cleaning_map"
53 self, neato: NeatoHub, robot: Robot, mapdata: dict[str, Any] |
None
55 """Initialize Neato cleaning map."""
61 self._robot_serial: str = self.
robotrobot.serial
65 self.
_image_image: bytes |
None =
None
68 self, width: int |
None =
None, height: int |
None =
None
70 """Return image response."""
75 """Check the contents of the map list."""
77 _LOGGER.debug(
"Running camera update for '%s'", self.
entity_identity_id)
79 self.
neatoneato.update_robots()
80 except NeatoRobotException
as ex:
83 "Neato camera connection error for '%s': %s", self.
entity_identity_id, ex
91 map_data: dict[str, Any] = self.
_mapdata_mapdata[self._robot_serial][
"maps"][0]
92 if (image_url := map_data[
"url"]) == self.
_image_url_image_url:
94 "The map image_url for '%s' is the same as old", self.
entity_identity_id
99 image: HTTPResponse = self.
neatoneato.download_map(image_url)
100 except NeatoRobotException
as ex:
103 "Neato camera connection error for '%s': %s", self.
entity_identity_id, ex
110 self.
_image_image = image.read()
117 """Return if the robot is available."""
122 """Return the state attributes of the vacuum cleaner."""
123 data: dict[str, Any] = {}
None __init__(self, NeatoHub neato, Robot robot, dict[str, Any]|None mapdata)
dict[str, Any] extra_state_attributes(self)
bytes|None camera_image(self, int|None width=None, int|None height=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)