-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Fix Roomba setup #34089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Roomba setup #34089
Changes from all commits
f5f20ee
92fb6ba
0847a38
ff09850
d9cc239
a926eb3
93ff2c0
3ff7523
226d285
17bef11
791ab1c
af6f29b
682edda
8aa831e
5a23851
fc41810
d4b729e
7dc9c29
039dcc0
e28381d
329d8c1
f450335
62f3615
b0a0141
0ac43bb
1a9cac5
ff352e8
aab7610
b61d307
9c5fc70
6531c53
5e81b37
32dcadc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| DEFAULT_CONTINUOUS, | ||
| DEFAULT_DELAY, | ||
| DOMAIN, | ||
| LISTENER, | ||
| ROOMBA_SESSION, | ||
| ) | ||
|
|
||
|
|
@@ -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 | ||
|
|
||
|
|
||
|
|
@@ -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) | ||
| 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) | ||
|
|
@@ -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 | ||
|
cyr-ius marked this conversation as resolved.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| except asyncio.TimeoutError: | ||
| _LOGGER.error("Timeout exceeded when disconnecting the vacuum cleaner") | ||
| raise CannotDisconnect | ||
|
|
||
|
|
||
| async def async_update_options(hass, config_entry): | ||
|
|
@@ -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]) | ||
|
cyr-ius marked this conversation as resolved.
|
||
| except CannotDisconnect: | ||
| return False | ||
|
|
||
| if unload_ok: | ||
| hass.data[DOMAIN].pop(config_entry.entry_id) | ||
|
cyr-ius marked this conversation as resolved.
|
||
|
|
||
| return unload_ok | ||
|
|
@@ -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.""" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,6 @@ def icon(self): | |
| return self.ICON | ||
|
|
||
| @property | ||
| def state(self): | ||
| def is_on(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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"} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,3 +11,4 @@ | |
| DEFAULT_DELAY = 1 | ||
| ROOMBA_SESSION = "roomba_session" | ||
| BLID = "blid_key" | ||
| LISTENER = "listener_options" | ||
Uh oh!
There was an error while loading. Please reload this page.