Skip to content

Commit

Permalink
Add vendor support for vorwerk robots and fix zone retrieval (#25200)
Browse files Browse the repository at this point in the history
* Add vendor support for vorwerk robots and fix zone retrieval

* Lint

* Review comments

* Lint

* Review commeent

* Remove unused variable

* Review comment

* Remove unused variable
  • Loading branch information
dshokouhi authored and balloob committed Jul 18, 2019
1 parent 93970b5 commit 32e89dc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
21 changes: 16 additions & 5 deletions homeassistant/components/neato/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

_LOGGER = logging.getLogger(__name__)

CONF_VENDOR = 'vendor'
DOMAIN = 'neato'
NEATO_ROBOTS = 'neato_robots'
NEATO_LOGIN = 'neato_login'
Expand All @@ -22,6 +23,8 @@
DOMAIN: vol.Schema({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_VENDOR, default='neato'): vol.In(
['neato', 'vorwerk'])
})
}, extra=vol.ALLOW_EXTRA)

Expand Down Expand Up @@ -169,9 +172,13 @@

def setup(hass, config):
"""Set up the Neato component."""
from pybotvac import Account
from pybotvac import Account, Neato, Vorwerk

hass.data[NEATO_LOGIN] = NeatoHub(hass, config[DOMAIN], Account)
if config[DOMAIN][CONF_VENDOR] == 'neato':
hass.data[NEATO_LOGIN] = NeatoHub(hass, config[DOMAIN], Account, Neato)
elif config[DOMAIN][CONF_VENDOR] == 'vorwerk':
hass.data[NEATO_LOGIN] = NeatoHub(hass, config[DOMAIN], Account,
Vorwerk)
hub = hass.data[NEATO_LOGIN]
if not hub.login():
_LOGGER.debug("Failed to login to Neato API")
Expand All @@ -186,15 +193,17 @@ def setup(hass, config):
class NeatoHub:
"""A My Neato hub wrapper class."""

def __init__(self, hass, domain_config, neato):
def __init__(self, hass, domain_config, neato, vendor):
"""Initialize the Neato hub."""
self.config = domain_config
self._neato = neato
self._hass = hass
self._vendor = vendor

self.my_neato = neato(
domain_config[CONF_USERNAME],
domain_config[CONF_PASSWORD])
domain_config[CONF_PASSWORD],
vendor)
self._hass.data[NEATO_ROBOTS] = self.my_neato.robots
self._hass.data[NEATO_PERSISTENT_MAPS] = self.my_neato.persistent_maps
self._hass.data[NEATO_MAP_DATA] = self.my_neato.maps
Expand All @@ -204,7 +213,9 @@ def login(self):
try:
_LOGGER.debug("Trying to connect to Neato API")
self.my_neato = self._neato(
self.config[CONF_USERNAME], self.config[CONF_PASSWORD])
self.config[CONF_USERNAME],
self.config[CONF_PASSWORD],
self._vendor)
return True
except HTTPError:
_LOGGER.error("Unable to connect to Neato API")
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/neato/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Neato",
"documentation": "https://www.home-assistant.io/components/neato",
"requirements": [
"pybotvac==0.0.13"
"pybotvac==0.0.15"
],
"dependencies": [],
"codeowners": []
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/neato/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,10 @@ def update(self):
if self._robot_has_map:
if self._state['availableServices']['maps'] != "basic-1":
if self._robot_maps[self._robot_serial]:
robot_map_id = (
self._robot_maps[self._robot_serial][0]['id'])

self._robot_boundaries = self.robot.get_map_boundaries(
robot_map_id).json()
allmaps = self._robot_maps[self._robot_serial]
for maps in allmaps:
self._robot_boundaries = self.robot.get_map_boundaries(
maps['id']).json()

@property
def name(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ pyblackbird==0.5
# pybluez==0.22

# homeassistant.components.neato
pybotvac==0.0.13
pybotvac==0.0.15

# homeassistant.components.nissan_leaf
pycarwings2==2.8
Expand Down

0 comments on commit 32e89dc

Please sign in to comment.