Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
call setScheduleUpdates in separate Task to create the config entry q…
Browse files Browse the repository at this point in the history
…uicker
  • Loading branch information
edenhaus committed Mar 11, 2021
1 parent d08f71c commit 03dc3cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
27 changes: 15 additions & 12 deletions custom_components/deebot/hub.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import asyncio
import random
import logging
import threading
import async_timeout
import random
import string
from datetime import timedelta
from homeassistant.util import Throttle
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
import threading

from deebotozmo import EcoVacsAPI, VacBot
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant

from .const import *

_LOGGER = logging.getLogger(__name__)
Expand All @@ -21,7 +20,7 @@
class DeebotHub:
"""Deebot Hub"""

def __init__(self, hass, domain_config):
def __init__(self, hass: HomeAssistant, domain_config):
"""Initialize the Deebot Vacuum."""

self.config = domain_config
Expand All @@ -46,6 +45,11 @@ def __init__(self, hass, domain_config):
continent = domain_config.get(CONF_CONTINENT).lower()
self.vacbots = []

async def async_init_vacuums(vacuums: [VacBot]):
for vacuum in vacuums:
await hass.async_add_executor_job(vacuum.setScheduleUpdates)
_LOGGER.debug("Vacuums scheduler initialized")

# CREATE VACBOT FOR EACH DEVICE
for device in devices:
if device["name"] in domain_config.get(CONF_DEVICEID)[CONF_DEVICEID]:
Expand All @@ -61,11 +65,10 @@ def __init__(self, hass, domain_config):
)

_LOGGER.debug("New vacbot found: " + device["name"])
vacbot.setScheduleUpdates()

self.vacbots.append(vacbot)

_LOGGER.debug("Hub initialized")
_LOGGER.debug("Hub initialized - Vacuums scheduler initialization pending")
hass.async_create_task(async_init_vacuums(self.vacbots))

def disconnect(self):
for device in self.vacbots:
Expand All @@ -74,4 +77,4 @@ def disconnect(self):
@property
def name(self):
""" Return the name of the hub."""
return "Deebot Hub"
return "Deebot Hub"
5 changes: 2 additions & 3 deletions custom_components/deebot/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ def __init__(self, hass: HomeAssistant, vacbot: VacBot):

self.att_data = {}

_LOGGER.debug("Vacuum initialized: %s", self.name)

async def async_added_to_hass(self) -> None:
"""Set up the event listeners now that hass is ready."""
listeners = [
Expand Down Expand Up @@ -215,7 +213,8 @@ def device_state_attributes(self) -> Optional[Dict[str, Any]]:
# Convert from int to list
self.att_data[room_name] = [room_values, r["id"]]

self.att_data["status"] = STATE_CODE_TO_STATE[self.device.vacuum_status]
if self.device.vacuum_status:
self.att_data["status"] = STATE_CODE_TO_STATE[self.device.vacuum_status]

return self.att_data

Expand Down

4 comments on commit 03dc3cd

@And3rsL
Copy link
Owner

Choose a reason for hiding this comment

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

it doesn't work as intended, components and sensors will never update
need to find out why, for now i just replaced it

@edenhaus
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since I have done a lot on bumper maybe I know a solution. If you want we can make a meeting and I describe it to you

@And3rsL
Copy link
Owner

Choose a reason for hiding this comment

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

Since I have done a lot on bumper maybe I know a solution. If you want we can make a meeting and I describe it to you

Im about to integrate bumper too, i just need to understand how does it work!

@edenhaus
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Se vuoi ti spiego tutto in 15 min :) Scrivi una mail a [email protected] per fissare un appuntamento ;)

Please sign in to comment.