2019-02-14 05:35:12 +01:00
|
|
|
"""Support for loading picture from Neato."""
|
2019-03-20 22:56:46 -07:00
|
|
|
from datetime import timedelta
|
2017-04-13 16:41:25 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.camera import Camera
|
2019-03-20 22:56:46 -07:00
|
|
|
|
2019-10-06 13:05:51 +02:00
|
|
|
from .const import NEATO_DOMAIN, NEATO_MAP_DATA, NEATO_ROBOTS, NEATO_LOGIN
|
2017-04-13 16:41:25 +02:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-06-27 13:55:27 -07:00
|
|
|
SCAN_INTERVAL = timedelta(minutes=10)
|
|
|
|
|
2017-04-13 16:41:25 +02:00
|
|
|
|
2019-10-06 13:05:51 +02:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2017-04-30 07:04:49 +02:00
|
|
|
"""Set up the Neato Camera."""
|
2019-10-06 13:05:51 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
|
|
"""Set up Neato camera with config entry."""
|
2017-04-13 16:41:25 +02:00
|
|
|
dev = []
|
|
|
|
for robot in hass.data[NEATO_ROBOTS]:
|
2019-07-31 12:25:30 -07:00
|
|
|
if "maps" in robot.traits:
|
2017-04-13 16:41:25 +02:00
|
|
|
dev.append(NeatoCleaningMap(hass, robot))
|
2019-10-06 13:05:51 +02:00
|
|
|
|
|
|
|
if not dev:
|
|
|
|
return
|
|
|
|
|
2017-04-30 07:04:49 +02:00
|
|
|
_LOGGER.debug("Adding robots for cleaning maps %s", dev)
|
2019-10-06 13:05:51 +02:00
|
|
|
async_add_entities(dev, True)
|
2017-04-13 16:41:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
class NeatoCleaningMap(Camera):
|
|
|
|
"""Neato cleaning map for last clean."""
|
|
|
|
|
|
|
|
def __init__(self, hass, robot):
|
|
|
|
"""Initialize Neato cleaning map."""
|
|
|
|
super().__init__()
|
|
|
|
self.robot = robot
|
2019-07-31 12:25:30 -07:00
|
|
|
self._robot_name = "{} {}".format(self.robot.name, "Cleaning Map")
|
2017-04-13 16:41:25 +02:00
|
|
|
self._robot_serial = self.robot.serial
|
|
|
|
self.neato = hass.data[NEATO_LOGIN]
|
|
|
|
self._image_url = None
|
|
|
|
self._image = None
|
|
|
|
|
|
|
|
def camera_image(self):
|
|
|
|
"""Return image response."""
|
|
|
|
self.update()
|
|
|
|
return self._image
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Check the contents of the map list."""
|
|
|
|
self.neato.update_robots()
|
|
|
|
image_url = None
|
|
|
|
map_data = self.hass.data[NEATO_MAP_DATA]
|
2019-07-31 12:25:30 -07:00
|
|
|
image_url = map_data[self._robot_serial]["maps"][0]["url"]
|
2017-04-13 16:41:25 +02:00
|
|
|
if image_url == self._image_url:
|
2017-04-30 07:04:49 +02:00
|
|
|
_LOGGER.debug("The map image_url is the same as old")
|
2017-04-13 16:41:25 +02:00
|
|
|
return
|
|
|
|
image = self.neato.download_map(image_url)
|
|
|
|
self._image = image.read()
|
|
|
|
self._image_url = image_url
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of this camera."""
|
|
|
|
return self._robot_name
|
2018-10-12 15:33:13 -07:00
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
"""Return unique ID."""
|
|
|
|
return self._robot_serial
|
2019-10-06 13:05:51 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def device_info(self):
|
|
|
|
"""Device info for neato robot."""
|
|
|
|
return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}}
|