small cleanup, add some comments
This commit is contained in:
@@ -3,13 +3,14 @@ import logging
|
|||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
#just included the modified sucks in component
|
||||||
from .sucksbumper import EcoVacsAPI, VacBot
|
from .sucksbumper import EcoVacsAPI, VacBot
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
CONF_VERIFY_SSL,
|
CONF_VERIFY_SSL, # added
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
@@ -24,11 +25,11 @@ DOMAIN = "ecovacs"
|
|||||||
|
|
||||||
CONF_COUNTRY = "country"
|
CONF_COUNTRY = "country"
|
||||||
CONF_CONTINENT = "continent"
|
CONF_CONTINENT = "continent"
|
||||||
|
#bumper config vars
|
||||||
CONF_BUMPER = "bumper"
|
CONF_BUMPER = "bumper"
|
||||||
CONF_BUMPER_SERVER = "bumper_server"
|
CONF_BUMPER_SERVER = "bumper_server"
|
||||||
server_address = None
|
server_address = None
|
||||||
|
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
DOMAIN: vol.Schema(
|
DOMAIN: vol.Schema(
|
||||||
@@ -39,7 +40,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
vol.Required(CONF_CONTINENT): vol.All(vol.Lower, cv.string),
|
vol.Required(CONF_CONTINENT): vol.All(vol.Lower, cv.string),
|
||||||
vol.Optional(CONF_BUMPER, default=False): cv.boolean,
|
vol.Optional(CONF_BUMPER, default=False): cv.boolean,
|
||||||
vol.Optional(CONF_BUMPER_SERVER): cv.string,
|
vol.Optional(CONF_BUMPER_SERVER): cv.string,
|
||||||
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean,
|
vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean, # can probably get rid of this and set verify ssl false if bumper true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -53,14 +54,15 @@ ECOVACS_API_DEVICEID = "".join(
|
|||||||
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
random.choice(string.ascii_uppercase + string.digits) for _ in range(8)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Ecovacs component."""
|
"""Set up the Ecovacs component."""
|
||||||
_LOGGER.debug("Creating new Ecovacs component")
|
_LOGGER.debug("Creating new Ecovacs component")
|
||||||
|
|
||||||
hass.data[ECOVACS_DEVICES] = []
|
hass.data[ECOVACS_DEVICES] = []
|
||||||
|
# if we're using bumper then define the server address
|
||||||
if CONF_BUMPER == True:
|
if CONF_BUMPER == True:
|
||||||
server_address = (config[DOMAIN].get(CONF_BUMPER_SERVER), 5223)
|
server_address = (config[DOMAIN].get(CONF_BUMPER_SERVER), 5223)
|
||||||
|
# if not make sure it's null
|
||||||
else:
|
else:
|
||||||
server_address = None
|
server_address = None
|
||||||
|
|
||||||
@@ -70,7 +72,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
EcoVacsAPI.md5(config[DOMAIN].get(CONF_PASSWORD)),
|
EcoVacsAPI.md5(config[DOMAIN].get(CONF_PASSWORD)),
|
||||||
config[DOMAIN].get(CONF_COUNTRY),
|
config[DOMAIN].get(CONF_COUNTRY),
|
||||||
config[DOMAIN].get(CONF_CONTINENT),
|
config[DOMAIN].get(CONF_CONTINENT),
|
||||||
config[DOMAIN].get(CONF_VERIFY_SSL),
|
config[DOMAIN].get(CONF_VERIFY_SSL), # add to class call
|
||||||
)
|
)
|
||||||
|
|
||||||
devices = ecovacs_api.devices()
|
devices = ecovacs_api.devices()
|
||||||
@@ -89,8 +91,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
ecovacs_api.user_access_token,
|
ecovacs_api.user_access_token,
|
||||||
device,
|
device,
|
||||||
config[DOMAIN].get(CONF_CONTINENT).lower(),
|
config[DOMAIN].get(CONF_CONTINENT).lower(),
|
||||||
server_address,
|
server_address, # include server address in class, if it's null shoul be no effect
|
||||||
config[DOMAIN].get(CONF_VERIFY_SSL),
|
config[DOMAIN].get(CONF_VERIFY_SSL), # verify ssl or not
|
||||||
monitor=True,
|
monitor=True,
|
||||||
)
|
)
|
||||||
hass.data[ECOVACS_DEVICES].append(vacbot)
|
hass.data[ECOVACS_DEVICES].append(vacbot)
|
||||||
|
|||||||
@@ -376,11 +376,13 @@ class EventListener(object):
|
|||||||
self._emitter.unsubscribe(self)
|
self._emitter.unsubscribe(self)
|
||||||
|
|
||||||
class VacBot():
|
class VacBot():
|
||||||
|
# switched verify and monitor just to be consistent
|
||||||
def __init__(self, user, domain, resource, secret, vacuum, continent, server_address=None, verify_ssl=True, monitor=False):
|
def __init__(self, user, domain, resource, secret, vacuum, continent, server_address=None, verify_ssl=True, monitor=False):
|
||||||
|
|
||||||
self.vacuum = vacuum
|
self.vacuum = vacuum
|
||||||
|
|
||||||
self.server_address = server_address
|
self.server_address = server_address
|
||||||
|
|
||||||
# If True, the VacBot object will handle keeping track of all statuses,
|
# If True, the VacBot object will handle keeping track of all statuses,
|
||||||
# including the initial request for statuses, and new requests after the
|
# including the initial request for statuses, and new requests after the
|
||||||
# VacBot returns from being offline. It will also cause it to regularly
|
# VacBot returns from being offline. It will also cause it to regularly
|
||||||
@@ -411,9 +413,11 @@ class VacBot():
|
|||||||
self.iotmq = None
|
self.iotmq = None
|
||||||
|
|
||||||
if not vacuum['iotmq']:
|
if not vacuum['iotmq']:
|
||||||
|
# if server is defined then use bmartins init example for using sucks library in his docs; couldnt get this to work in hass with code he had here though, maybe not referencing everything right in component init
|
||||||
if self.server_address is not None:
|
if self.server_address is not None:
|
||||||
vacuum = {"did": "none", "class": "none"}
|
vacuum = {"did": "none", "class": "none"}
|
||||||
super().__init__("sucks", "ecouser.net", "", "", vacuum, "")
|
super().__init__("sucks", "ecouser.net", "", "", vacuum, "")
|
||||||
|
# should work with ecovacs servers but 1) havent tested with my changes and 2) havent tested with bmartins changes
|
||||||
else:
|
else:
|
||||||
self.xmpp = EcoVacsXMPP(user, domain, resource, secret, continent, vacuum, server_address)
|
self.xmpp = EcoVacsXMPP(user, domain, resource, secret, continent, vacuum, server_address)
|
||||||
#Uncomment line to allow unencrypted plain auth
|
#Uncomment line to allow unencrypted plain auth
|
||||||
@@ -431,11 +435,13 @@ class VacBot():
|
|||||||
#self.xmpp.subscribe_to_ctls(self._handle_ctl)
|
#self.xmpp.subscribe_to_ctls(self._handle_ctl)
|
||||||
|
|
||||||
def connect_and_wait_until_ready(self):
|
def connect_and_wait_until_ready(self):
|
||||||
|
# use bmartins exmaple if defining our own server, couldn't get this to work without defining, probably xmpp port but idk
|
||||||
if self.server_address:
|
if self.server_address:
|
||||||
logging.info("connecting")
|
logging.info("connecting")
|
||||||
self.xmpp.connect(self.server_address)
|
self.xmpp.connect(self.server_address)
|
||||||
self.xmpp.process()
|
self.xmpp.process()
|
||||||
self.xmpp.wait_until_ready()
|
self.xmpp.wait_until_ready()
|
||||||
|
# keep rest of bmartins fork intact
|
||||||
else:
|
else:
|
||||||
if not self.vacuum['iotmq']:
|
if not self.vacuum['iotmq']:
|
||||||
self.xmpp.connect_and_wait_until_ready()
|
self.xmpp.connect_and_wait_until_ready()
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
#sucks
|
||||||
from . import sucksbumper
|
from . import sucksbumper
|
||||||
|
|
||||||
from homeassistant.components.vacuum import VacuumEntity, VacuumEntityFeature
|
from homeassistant.components.vacuum import VacuumEntity, VacuumEntityFeature
|
||||||
|
|||||||
Reference in New Issue
Block a user