Neato config flow (#26579)

* initial commit

* Minor changes

* add async setup entry

* Add translations and some other stuff

* add and remove entry

* use async_setup_entry

* Update config_flows.py

* dshokouhi's changes

* Improve workflow

* Add valid_vendors

* Add entity registry

* Add device registry

* Update entry from configuration.yaml

* Revert unneccesary changes

* Update .coveragerc

* Prepared tests

* Add dshokouhi and Santobert as codeowners

* Fix unload entry and abort when already_configured

* First tests

* Add test for abort cases

* Add test for invalid credentials on import

* Add one last test

* Add test_init.py with some tests

* Address reviews, part 1

* Update outdated entry

* await instead of add_job

* run IO inside an executor

* remove faulty test

* Fix pylint issues

* Move IO out of constructur

* Edit error translations

* Edit imports

* Minor changes

* Remove test for invalid vendor

* Async setup platform

* Edit login function

* Moved IO out if init

* Update switches after added to hass

* Revert update outdated entry

* try and update new entrys from config.yaml

* Add test invalid vendor

* Default to neato
This commit is contained in:
Santobert 2019-10-06 13:05:51 +02:00 committed by Martin Hjelmare
parent 476f24e451
commit bd6bbcd5af
17 changed files with 691 additions and 190 deletions

View file

@ -7,7 +7,7 @@ import requests
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.helpers.entity import ToggleEntity
from . import NEATO_LOGIN, NEATO_ROBOTS
from .const import NEATO_DOMAIN, NEATO_LOGIN, NEATO_ROBOTS
_LOGGER = logging.getLogger(__name__)
@ -18,14 +18,23 @@ SWITCH_TYPE_SCHEDULE = "schedule"
SWITCH_TYPES = {SWITCH_TYPE_SCHEDULE: ["Schedule"]}
def setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Neato switches."""
pass
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up Neato switch with config entry."""
dev = []
for robot in hass.data[NEATO_ROBOTS]:
for type_name in SWITCH_TYPES:
dev.append(NeatoConnectedSwitch(hass, robot, type_name))
if not dev:
return
_LOGGER.debug("Adding switches %s", dev)
add_entities(dev)
async_add_entities(dev, True)
class NeatoConnectedSwitch(ToggleEntity):
@ -37,14 +46,7 @@ class NeatoConnectedSwitch(ToggleEntity):
self.robot = robot
self.neato = hass.data[NEATO_LOGIN]
self._robot_name = "{} {}".format(self.robot.name, SWITCH_TYPES[self.type][0])
try:
self._state = self.robot.state
except (
requests.exceptions.ConnectionError,
requests.exceptions.HTTPError,
) as ex:
_LOGGER.warning("Neato connection error: %s", ex)
self._state = None
self._state = None
self._schedule_state = None
self._clean_state = None
self._robot_serial = self.robot.serial
@ -94,6 +96,11 @@ class NeatoConnectedSwitch(ToggleEntity):
return True
return False
@property
def device_info(self):
"""Device info for neato robot."""
return {"identifiers": {(NEATO_DOMAIN, self._robot_serial)}}
def turn_on(self, **kwargs):
"""Turn the switch on."""
if self.type == SWITCH_TYPE_SCHEDULE: