From 0f2d5f38f596e6d52e907d522898b8564b00c550 Mon Sep 17 00:00:00 2001 From: bittles Date: Wed, 14 Dec 2022 02:22:15 -0500 Subject: [PATCH] small cleanup, add some comments --- custom_components/ecovacs/__init__.py | 16 +++++++++------- custom_components/ecovacs/sucksbumper.py | 6 ++++++ custom_components/ecovacs/vacuum.py | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/custom_components/ecovacs/__init__.py b/custom_components/ecovacs/__init__.py index b9c6100..34ab975 100644 --- a/custom_components/ecovacs/__init__.py +++ b/custom_components/ecovacs/__init__.py @@ -3,13 +3,14 @@ import logging import random import string +#just included the modified sucks in component from .sucksbumper import EcoVacsAPI, VacBot import voluptuous as vol from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, - CONF_VERIFY_SSL, + CONF_VERIFY_SSL, # added EVENT_HOMEASSISTANT_STOP, Platform, ) @@ -24,11 +25,11 @@ DOMAIN = "ecovacs" CONF_COUNTRY = "country" CONF_CONTINENT = "continent" +#bumper config vars CONF_BUMPER = "bumper" CONF_BUMPER_SERVER = "bumper_server" server_address = None - CONFIG_SCHEMA = vol.Schema( { DOMAIN: vol.Schema( @@ -39,7 +40,7 @@ CONFIG_SCHEMA = vol.Schema( vol.Required(CONF_CONTINENT): vol.All(vol.Lower, cv.string), vol.Optional(CONF_BUMPER, default=False): cv.boolean, 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) ) - def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the Ecovacs component.""" _LOGGER.debug("Creating new Ecovacs component") hass.data[ECOVACS_DEVICES] = [] + # if we're using bumper then define the server address if CONF_BUMPER == True: server_address = (config[DOMAIN].get(CONF_BUMPER_SERVER), 5223) + # if not make sure it's null else: server_address = None @@ -70,7 +72,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: EcoVacsAPI.md5(config[DOMAIN].get(CONF_PASSWORD)), config[DOMAIN].get(CONF_COUNTRY), 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() @@ -89,8 +91,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: ecovacs_api.user_access_token, device, config[DOMAIN].get(CONF_CONTINENT).lower(), - server_address, - config[DOMAIN].get(CONF_VERIFY_SSL), + server_address, # include server address in class, if it's null shoul be no effect + config[DOMAIN].get(CONF_VERIFY_SSL), # verify ssl or not monitor=True, ) hass.data[ECOVACS_DEVICES].append(vacbot) diff --git a/custom_components/ecovacs/sucksbumper.py b/custom_components/ecovacs/sucksbumper.py index 2386f7d..5950f51 100644 --- a/custom_components/ecovacs/sucksbumper.py +++ b/custom_components/ecovacs/sucksbumper.py @@ -376,11 +376,13 @@ class EventListener(object): self._emitter.unsubscribe(self) 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): self.vacuum = vacuum self.server_address = server_address + # If True, the VacBot object will handle keeping track of all statuses, # including the initial request for statuses, and new requests after the # VacBot returns from being offline. It will also cause it to regularly @@ -411,9 +413,11 @@ class VacBot(): self.iotmq = None 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: vacuum = {"did": "none", "class": "none"} 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: self.xmpp = EcoVacsXMPP(user, domain, resource, secret, continent, vacuum, server_address) #Uncomment line to allow unencrypted plain auth @@ -431,11 +435,13 @@ class VacBot(): #self.xmpp.subscribe_to_ctls(self._handle_ctl) 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: logging.info("connecting") self.xmpp.connect(self.server_address) self.xmpp.process() self.xmpp.wait_until_ready() + # keep rest of bmartins fork intact else: if not self.vacuum['iotmq']: self.xmpp.connect_and_wait_until_ready() diff --git a/custom_components/ecovacs/vacuum.py b/custom_components/ecovacs/vacuum.py index f3a15bd..06157d2 100644 --- a/custom_components/ecovacs/vacuum.py +++ b/custom_components/ecovacs/vacuum.py @@ -4,6 +4,7 @@ from __future__ import annotations import logging from typing import Any +#sucks from . import sucksbumper from homeassistant.components.vacuum import VacuumEntity, VacuumEntityFeature