Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f5f20ee
Add unsubscribe listener
cyr-ius Apr 12, 2020
92fb6ba
Fix get name
cyr-ius Apr 12, 2020
0847a38
Replace async_add_job to async_add_exexutor_job
cyr-ius Apr 12, 2020
ff09850
Fix icon
cyr-ius Apr 12, 2020
d9cc239
Fix status
cyr-ius Apr 12, 2020
a926eb3
Fix vacuum state
cyr-ius Apr 12, 2020
93ff2c0
Update homeassistant/components/roomba/__init__.py
cyr-ius Apr 12, 2020
3ff7523
Update homeassistant/components/roomba/__init__.py
cyr-ius Apr 12, 2020
226d285
Replace async_add_job to async_add_executor_job
cyr-ius Apr 12, 2020
17bef11
Add check disconnect to vacuum
cyr-ius Apr 12, 2020
791ab1c
Fix typo
cyr-ius Apr 12, 2020
af6f29b
Fix disconnect timeout
cyr-ius Apr 14, 2020
682edda
Fix unload entry
cyr-ius Apr 14, 2020
8aa831e
Test error disconnect
cyr-ius Apr 16, 2020
5a23851
Return false if raise exception
cyr-ius Apr 16, 2020
fc41810
Remove sleep
cyr-ius Apr 25, 2020
d4b729e
Revert "Remove sleep"
cyr-ius Apr 25, 2020
7dc9c29
Remove sleep
cyr-ius Apr 25, 2020
039dcc0
Add unsubscribe listener
cyr-ius Apr 12, 2020
e28381d
Fix icon
cyr-ius Apr 12, 2020
329d8c1
Update homeassistant/components/roomba/__init__.py
cyr-ius Apr 12, 2020
f450335
Update homeassistant/components/roomba/__init__.py
cyr-ius Apr 12, 2020
62f3615
Replace async_add_job to async_add_executor_job
cyr-ius Apr 12, 2020
b0a0141
Add check disconnect to vacuum
cyr-ius Apr 12, 2020
0ac43bb
Fix typo
cyr-ius Apr 12, 2020
1a9cac5
Fix disconnect timeout
cyr-ius Apr 14, 2020
ff352e8
Fix unload entry
cyr-ius Apr 14, 2020
aab7610
Return false if raise exception
cyr-ius Apr 16, 2020
b61d307
Revert "Merge branch 'roomba_fix' of https://github.com/cyr-ius/home-a…
cyr-ius Apr 25, 2020
9c5fc70
Revert merge
cyr-ius Apr 25, 2020
6531c53
Add trace for unknown error
cyr-ius Apr 30, 2020
5e81b37
Refix roomba_connected
cyr-ius May 1, 2020
32dcadc
Lint config_flow
cyr-ius May 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions homeassistant/components/roomba/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DEFAULT_CONTINUOUS,
DEFAULT_DELAY,
DOMAIN,
LISTENER,
ROOMBA_SESSION,
)

Expand Down Expand Up @@ -104,19 +105,19 @@ async def async_setup_entry(hass, config_entry):
except CannotConnect:
raise exceptions.ConfigEntryNotReady

listener_options = config_entry.add_update_listener(async_update_options)

hass.data[DOMAIN][config_entry.entry_id] = {
ROOMBA_SESSION: roomba,
BLID: config_entry.data[CONF_BLID],
LISTENER: listener_options,
}

for component in COMPONENTS:
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, component)
)

if not config_entry.update_listeners:
config_entry.add_update_listener(async_update_options)

return True


Expand All @@ -126,10 +127,10 @@ async def async_connect_or_timeout(hass, roomba):
name = None
with async_timeout.timeout(10):
_LOGGER.debug("Initialize connection to vacuum")
await hass.async_add_job(roomba.connect)
await hass.async_add_executor_job(roomba.connect)
Comment thread
cyr-ius marked this conversation as resolved.
while not roomba.roomba_connected or name is None:
# Waiting for connection and check datas ready
name = roomba_reported_state(roomba).get("name", None)
name = roomba_reported_state(roomba).get("name")
if name:
break
await asyncio.sleep(1)
Expand All @@ -147,10 +148,16 @@ async def async_connect_or_timeout(hass, roomba):

async def async_disconnect_or_timeout(hass, roomba):
"""Disconnect to vacuum."""
_LOGGER.debug("Disconnect vacuum")
with async_timeout.timeout(3):
await hass.async_add_job(roomba.disconnect)
return True
try:
with async_timeout.timeout(3):
_LOGGER.debug("Disconnect vacuum")
await hass.async_add_executor_job(roomba.disconnect)
while roomba.roomba_connected:
await asyncio.sleep(1)
break
Comment thread
cyr-ius marked this conversation as resolved.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem here is that you are using while loop and break in the first iteration. You should either use if statement if you just want to sleep for 1 second if it is still connected, or you can remove the break so the while loop will wait until it's disconnected, or you just remove the loop and it will wait for 1 second anyway. If I understand your comment correctly, you want to wait until disconnected and then wait for another second to make sure the reconnect works well. Then you'll need to delete the break statement and add another sleep outside the while loop.

except asyncio.TimeoutError:
_LOGGER.error("Timeout exceeded when disconnecting the vacuum cleaner")
raise CannotDisconnect


async def async_update_options(hass, config_entry):
Expand All @@ -168,9 +175,19 @@ async def async_unload_entry(hass, config_entry):
]
)
)
if unload_ok:
domain_data = hass.data[DOMAIN][config_entry.entry_id]

domain_data = hass.data[DOMAIN][config_entry.entry_id]

# unsubscribe listerner
domain_data[LISTENER]()

# disconnect cleanly
try:
await async_disconnect_or_timeout(hass, roomba=domain_data[ROOMBA_SESSION])
Comment thread
cyr-ius marked this conversation as resolved.
except CannotDisconnect:
return False

if unload_ok:
hass.data[DOMAIN].pop(config_entry.entry_id)
Comment thread
cyr-ius marked this conversation as resolved.

return unload_ok
Expand All @@ -190,3 +207,7 @@ def _async_find_matching_config_entry(hass, prefix):

class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""


class CannotDisconnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot disconnect."""
2 changes: 1 addition & 1 deletion homeassistant/components/roomba/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def icon(self):
return self.ICON

@property
def state(self):
def is_on(self):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already fixed in #35443. Do a rebase and this will be no longer needed.

"""Return the state of the sensor."""
return roomba_reported_state(self.vacuum).get("bin", {}).get("full", False)
14 changes: 12 additions & 2 deletions homeassistant/components/roomba/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
from homeassistant.const import CONF_HOST, CONF_PASSWORD
from homeassistant.core import callback

from . import CannotConnect, async_connect_or_timeout, async_disconnect_or_timeout
from . import (
CannotConnect,
CannotDisconnect,
async_connect_or_timeout,
async_disconnect_or_timeout,
)
from .const import (
CONF_BLID,
CONF_CERT,
Expand Down Expand Up @@ -84,11 +89,16 @@ async def async_step_user(self, user_input=None):
self._abort_if_unique_id_configured()
try:
info = await validate_input(self.hass, user_input)
await async_disconnect_or_timeout(self.hass, info[ROOMBA_SESSION])
except CannotConnect:
errors = {"base": "cannot_connect"}
except CannotDisconnect:
errors = {"base": "cannot_disconnect"}
except Exception as error: # pylint: disable=broad-except
_LOGGER.error("An unknown error occurred: %s", error)
errors = {"base": "unknown"}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in #35005 so not needed as well.


if "base" not in errors:
await async_disconnect_or_timeout(self.hass, info[ROOMBA_SESSION])
return self.async_create_entry(title=info[CONF_NAME], data=user_input)

return self.async_show_form(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/roomba/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
DEFAULT_DELAY = 1
ROOMBA_SESSION = "roomba_session"
BLID = "blid_key"
LISTENER = "listener_options"