rename logger
to define in const
This commit is contained in:
@@ -25,7 +25,7 @@ from .const import (
|
|||||||
CONF_BUMPER,
|
CONF_BUMPER,
|
||||||
CONF_BUMPER_SERVER,
|
CONF_BUMPER_SERVER,
|
||||||
SERVER_ADDRESS,
|
SERVER_ADDRESS,
|
||||||
_LOGGER
|
LOGGER
|
||||||
)
|
)
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema(
|
CONFIG_SCHEMA = vol.Schema(
|
||||||
@@ -52,7 +52,7 @@ ECOVACS_API_DEVICEID = "".join(
|
|||||||
|
|
||||||
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 we're using bumper then define the server address
|
||||||
@@ -72,10 +72,10 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
devices = ecovacs_api.devices()
|
devices = ecovacs_api.devices()
|
||||||
_LOGGER.debug("Ecobot devices: %s", devices)
|
LOGGER.debug("Ecobot devices: %s", devices)
|
||||||
|
|
||||||
for device in devices:
|
for device in devices:
|
||||||
_LOGGER.info(
|
LOGGER.info(
|
||||||
"Discovered Ecovacs device on account: %s with nickname %s",
|
"Discovered Ecovacs device on account: %s with nickname %s",
|
||||||
device.get("did"),
|
device.get("did"),
|
||||||
device.get("nick"),
|
device.get("nick"),
|
||||||
@@ -96,7 +96,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
def stop(event: object) -> None:
|
def stop(event: object) -> None:
|
||||||
"""Shut down open connections to Ecovacs XMPP server."""
|
"""Shut down open connections to Ecovacs XMPP server."""
|
||||||
for device in hass.data[ECOVACS_DEVICES]:
|
for device in hass.data[ECOVACS_DEVICES]:
|
||||||
_LOGGER.info(
|
LOGGER.info(
|
||||||
"Shutting down connection to Ecovacs device %s",
|
"Shutting down connection to Ecovacs device %s",
|
||||||
device.vacuum.get("did"),
|
device.vacuum.get("did"),
|
||||||
)
|
)
|
||||||
@@ -106,7 +106,7 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop)
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop)
|
||||||
|
|
||||||
if hass.data[ECOVACS_DEVICES]:
|
if hass.data[ECOVACS_DEVICES]:
|
||||||
_LOGGER.debug("Starting vacuum components")
|
LOGGER.debug("Starting vacuum components")
|
||||||
discovery.load_platform(hass, Platform.VACUUM, DOMAIN, {}, config)
|
discovery.load_platform(hass, Platform.VACUUM, DOMAIN, {}, config)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import logging
|
import logging
|
||||||
_LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
#ecovacs constants
|
#ecovacs constants
|
||||||
#init constants
|
#init constants
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from paho.mqtt import publish as MQTTPublish
|
|||||||
from paho.mqtt import subscribe as MQTTSubscribe
|
from paho.mqtt import subscribe as MQTTSubscribe
|
||||||
from sleekxmppfs.xmlstream import ET
|
from sleekxmppfs.xmlstream import ET
|
||||||
|
|
||||||
from .const import _LOGGER
|
from .const import LOGGER
|
||||||
|
|
||||||
#This is used by EcoVacsIOTMQ and EcoVacsXMPP for _ctl_to_dict
|
#This is used by EcoVacsIOTMQ and EcoVacsXMPP for _ctl_to_dict
|
||||||
def RepresentsInt(stringvar):
|
def RepresentsInt(stringvar):
|
||||||
@@ -84,19 +84,19 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
|
|
||||||
def on_connect(self, client, userdata, flags, rc):
|
def on_connect(self, client, userdata, flags, rc):
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
_LOGGER.error("EcoVacsMQTT - error connecting with MQTT Return {}".format(rc))
|
LOGGER.error("EcoVacsMQTT - error connecting with MQTT Return {}".format(rc))
|
||||||
raise RuntimeError("EcoVacsMQTT - error connecting with MQTT Return {}".format(rc))
|
raise RuntimeError("EcoVacsMQTT - error connecting with MQTT Return {}".format(rc))
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("EcoVacsMQTT - Connected with result code "+str(rc))
|
LOGGER.debug("EcoVacsMQTT - Connected with result code "+str(rc))
|
||||||
_LOGGER.debug("EcoVacsMQTT - Subscribing to all")
|
LOGGER.debug("EcoVacsMQTT - Subscribing to all")
|
||||||
self.subscribe('iot/atr/+/' + self.vacuum['did'] + '/' + self.vacuum['class'] + '/' + self.vacuum['resource'] + '/+', qos=0)
|
self.subscribe('iot/atr/+/' + self.vacuum['did'] + '/' + self.vacuum['class'] + '/' + self.vacuum['resource'] + '/+', qos=0)
|
||||||
self.ready_flag.set()
|
self.ready_flag.set()
|
||||||
|
|
||||||
#def on_log(self, client, userdata, level, buf): #This is very noisy and verbose
|
#def on_log(self, client, userdata, level, buf): #This is very noisy and verbose
|
||||||
# _LOGGER.debug("EcoVacsMQTT Log: {} ".format(buf))
|
# LOGGER.debug("EcoVacsMQTT Log: {} ".format(buf))
|
||||||
|
|
||||||
def send_ping(self):
|
def send_ping(self):
|
||||||
_LOGGER.debug("*** MQTT sending ping ***")
|
LOGGER.debug("*** MQTT sending ping ***")
|
||||||
rc = self._send_simple_command(MQTTPublish.paho.PINGREQ)
|
rc = self._send_simple_command(MQTTPublish.paho.PINGREQ)
|
||||||
if rc == MQTTPublish.paho.MQTT_ERR_SUCCESS:
|
if rc == MQTTPublish.paho.MQTT_ERR_SUCCESS:
|
||||||
return True
|
return True
|
||||||
@@ -107,7 +107,7 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
if action.name == "Clean": #For handling Clean when action not specified (i.e. CLI)
|
if action.name == "Clean": #For handling Clean when action not specified (i.e. CLI)
|
||||||
action.args['clean']['act'] = CLEAN_ACTION_TO_ECOVACS['start'] #Inject a start action
|
action.args['clean']['act'] = CLEAN_ACTION_TO_ECOVACS['start'] #Inject a start action
|
||||||
c = self._wrap_command(action, recipient)
|
c = self._wrap_command(action, recipient)
|
||||||
_LOGGER.debug('Sending command {0}'.format(c))
|
LOGGER.debug('Sending command {0}'.format(c))
|
||||||
self._handle_ctl_api(action,
|
self._handle_ctl_api(action,
|
||||||
self.__call_iotdevmanager_api(c ,verify_ssl=self.verify_ssl )
|
self.__call_iotdevmanager_api(c ,verify_ssl=self.verify_ssl )
|
||||||
)
|
)
|
||||||
@@ -135,7 +135,7 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def __call_iotdevmanager_api(self, args, verify_ssl=True):
|
def __call_iotdevmanager_api(self, args, verify_ssl=True):
|
||||||
_LOGGER.debug("calling iotdevmanager api with {}".format(args))
|
LOGGER.debug("calling iotdevmanager api with {}".format(args))
|
||||||
params = {}
|
params = {}
|
||||||
params.update(args)
|
params.update(args)
|
||||||
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/iot/devmanager.do").format(continent=self.continent)
|
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/iot/devmanager.do").format(continent=self.continent)
|
||||||
@@ -143,7 +143,7 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
try: #The RestAPI sometimes doesnt provide a response depending on command, reduce timeout to 3 to accomodate and make requests faster
|
try: #The RestAPI sometimes doesnt provide a response depending on command, reduce timeout to 3 to accomodate and make requests faster
|
||||||
response = requests.post(url, json=params, timeout=3, verify=verify_ssl) #May think about having timeout as an arg that could be provided in the future
|
response = requests.post(url, json=params, timeout=3, verify=verify_ssl) #May think about having timeout as an arg that could be provided in the future
|
||||||
except requests.exceptions.ReadTimeout:
|
except requests.exceptions.ReadTimeout:
|
||||||
_LOGGER.debug("call to iotdevmanager failed with ReadTimeout")
|
LOGGER.debug("call to iotdevmanager failed with ReadTimeout")
|
||||||
return {}
|
return {}
|
||||||
json = response.json()
|
json = response.json()
|
||||||
if json['ret'] == 'ok':
|
if json['ret'] == 'ok':
|
||||||
@@ -152,11 +152,11 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
if 'debug' in json:
|
if 'debug' in json:
|
||||||
if json['debug'] == 'wait for response timed out':
|
if json['debug'] == 'wait for response timed out':
|
||||||
#TODO - Maybe handle timeout for IOT better in the future
|
#TODO - Maybe handle timeout for IOT better in the future
|
||||||
_LOGGER.error("call to iotdevmanager failed with {}".format(json))
|
LOGGER.error("call to iotdevmanager failed with {}".format(json))
|
||||||
return {}
|
return {}
|
||||||
else:
|
else:
|
||||||
#TODO - Not sure if we want to raise an error yet, just return empty for now
|
#TODO - Not sure if we want to raise an error yet, just return empty for now
|
||||||
_LOGGER.error("call to iotdevmanager failed with {}".format(json))
|
LOGGER.error("call to iotdevmanager failed with {}".format(json))
|
||||||
return {}
|
return {}
|
||||||
#raise RuntimeError(
|
#raise RuntimeError(
|
||||||
#"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
#"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
||||||
@@ -196,7 +196,7 @@ class EcoVacsIOTMQ(ClientMQTT):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def _handle_ctl_mqtt(self, client, userdata, message):
|
def _handle_ctl_mqtt(self, client, userdata, message):
|
||||||
#_LOGGER.debug("EcoVacs MQTT Received Message on Topic: {} - Message: {}".format(message.topic, str(message.payload.decode("utf-8"))))
|
#LOGGER.debug("EcoVacs MQTT Received Message on Topic: {} - Message: {}".format(message.topic, str(message.payload.decode("utf-8"))))
|
||||||
as_dict = self._ctl_to_dict_mqtt(message.topic, str(message.payload.decode("utf-8")))
|
as_dict = self._ctl_to_dict_mqtt(message.topic, str(message.payload.decode("utf-8")))
|
||||||
if as_dict is not None:
|
if as_dict is not None:
|
||||||
for s in self.ctl_subscribers:
|
for s in self.ctl_subscribers:
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class EcoVacsAPI:
|
|||||||
#'deviceType': '2' - iphone
|
#'deviceType': '2' - iphone
|
||||||
}
|
}
|
||||||
self.verify_ssl = str_to_bool_or_cert(verify_ssl)
|
self.verify_ssl = str_to_bool_or_cert(verify_ssl)
|
||||||
_LOGGER.debug("Setting up EcoVacsAPI")
|
LOGGER.debug("Setting up EcoVacsAPI")
|
||||||
self.resource = device_id[0:8]
|
self.resource = device_id[0:8]
|
||||||
self.country = country
|
self.country = country
|
||||||
self.continent = continent
|
self.continent = continent
|
||||||
@@ -85,34 +85,34 @@ class EcoVacsAPI:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def __call_main_api(self, function, *args):
|
def __call_main_api(self, function, *args):
|
||||||
_LOGGER.debug("calling main api {} with {}".format(function, args))
|
LOGGER.debug("calling main api {} with {}".format(function, args))
|
||||||
params = OrderedDict(args)
|
params = OrderedDict(args)
|
||||||
params['requestId'] = self.md5(time.time())
|
params['requestId'] = self.md5(time.time())
|
||||||
url = (EcoVacsAPI.MAIN_URL_FORMAT + "/" + function).format(**self.meta)
|
url = (EcoVacsAPI.MAIN_URL_FORMAT + "/" + function).format(**self.meta)
|
||||||
api_response = requests.get(url, self.__sign(params), verify=self.verify_ssl)
|
api_response = requests.get(url, self.__sign(params), verify=self.verify_ssl)
|
||||||
json = api_response.json()
|
json = api_response.json()
|
||||||
_LOGGER.debug("got {}".format(json))
|
LOGGER.debug("got {}".format(json))
|
||||||
if json['code'] == '0000':
|
if json['code'] == '0000':
|
||||||
return json['data']
|
return json['data']
|
||||||
elif json['code'] == '1005':
|
elif json['code'] == '1005':
|
||||||
_LOGGER.warning("incorrect email or password")
|
LOGGER.warning("incorrect email or password")
|
||||||
raise ValueError("incorrect email or password")
|
raise ValueError("incorrect email or password")
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("call to {} failed with {}".format(function, json))
|
LOGGER.error("call to {} failed with {}".format(function, json))
|
||||||
raise RuntimeError("failure code {} ({}) for call {} and parameters {}".format(
|
raise RuntimeError("failure code {} ({}) for call {} and parameters {}".format(
|
||||||
json['code'], json['msg'], function, args))
|
json['code'], json['msg'], function, args))
|
||||||
|
|
||||||
def __call_user_api(self, function, args):
|
def __call_user_api(self, function, args):
|
||||||
_LOGGER.debug("calling user api {} with {}".format(function, args))
|
LOGGER.debug("calling user api {} with {}".format(function, args))
|
||||||
params = {'todo': function}
|
params = {'todo': function}
|
||||||
params.update(args)
|
params.update(args)
|
||||||
response = requests.post(EcoVacsAPI.USER_URL_FORMAT.format(continent=self.continent), json=params, verify=self.verify_ssl)
|
response = requests.post(EcoVacsAPI.USER_URL_FORMAT.format(continent=self.continent), json=params, verify=self.verify_ssl)
|
||||||
json = response.json()
|
json = response.json()
|
||||||
_LOGGER.debug("got {}".format(json))
|
LOGGER.debug("got {}".format(json))
|
||||||
if json['result'] == 'ok':
|
if json['result'] == 'ok':
|
||||||
return json
|
return json
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("call to {} failed with {}".format(function, json))
|
LOGGER.error("call to {} failed with {}".format(function, json))
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
||||||
|
|
||||||
@@ -123,33 +123,33 @@ class EcoVacsAPI:
|
|||||||
else:
|
else:
|
||||||
params = {}
|
params = {}
|
||||||
params.update(args)
|
params.update(args)
|
||||||
_LOGGER.debug("calling portal api {} function {} with {}".format(api, function, params))
|
LOGGER.debug("calling portal api {} function {} with {}".format(api, function, params))
|
||||||
continent = self.continent
|
continent = self.continent
|
||||||
if 'continent' in kwargs:
|
if 'continent' in kwargs:
|
||||||
continent = kwargs.get('continent')
|
continent = kwargs.get('continent')
|
||||||
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/" + api).format(continent=continent, **self.meta)
|
url = (EcoVacsAPI.PORTAL_URL_FORMAT + "/" + api).format(continent=continent, **self.meta)
|
||||||
response = requests.post(url, json=params, verify=verify_ssl)
|
response = requests.post(url, json=params, verify=verify_ssl)
|
||||||
json = response.json()
|
json = response.json()
|
||||||
_LOGGER.debug("got {}".format(json))
|
LOGGER.debug("got {}".format(json))
|
||||||
if api == self.USERSAPI:
|
if api == self.USERSAPI:
|
||||||
if json['result'] == 'ok':
|
if json['result'] == 'ok':
|
||||||
return json
|
return json
|
||||||
elif json['result'] == 'fail':
|
elif json['result'] == 'fail':
|
||||||
if json['error'] == 'set token error.': # If it is a set token error try again
|
if json['error'] == 'set token error.': # If it is a set token error try again
|
||||||
if not 'set_token' in kwargs:
|
if not 'set_token' in kwargs:
|
||||||
_LOGGER.debug("loginByItToken set token error, trying again (2/3)")
|
LOGGER.debug("loginByItToken set token error, trying again (2/3)")
|
||||||
return self.__call_portal_api(self.USERSAPI, function, args, verify_ssl=verify_ssl, set_token=1)
|
return self.__call_portal_api(self.USERSAPI, function, args, verify_ssl=verify_ssl, set_token=1)
|
||||||
elif kwargs.get('set_token') == 1:
|
elif kwargs.get('set_token') == 1:
|
||||||
_LOGGER.debug("loginByItToken set token error, trying again with ww (3/3)")
|
LOGGER.debug("loginByItToken set token error, trying again with ww (3/3)")
|
||||||
return self.__call_portal_api(self.USERSAPI, function, args, verify_ssl=verify_ssl, set_token=2, continent="ww")
|
return self.__call_portal_api(self.USERSAPI, function, args, verify_ssl=verify_ssl, set_token=2, continent="ww")
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("loginByItToken set token error, failed after 3 attempts")
|
LOGGER.debug("loginByItToken set token error, failed after 3 attempts")
|
||||||
if api.startswith(self.PRODUCTAPI):
|
if api.startswith(self.PRODUCTAPI):
|
||||||
if json['code'] == 0:
|
if json['code'] == 0:
|
||||||
return json
|
return json
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_LOGGER.error("call to {} failed with {}".format(function, json))
|
LOGGER.error("call to {} failed with {}".format(function, json))
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
"failure {} ({}) for call {} and parameters {}".format(json['error'], json['errno'], function, params))
|
||||||
|
|
||||||
@@ -317,23 +317,23 @@ class VacBot():
|
|||||||
error = event['errs']
|
error = event['errs']
|
||||||
if not error == '':
|
if not error == '':
|
||||||
self.errorEvents.notify(error)
|
self.errorEvents.notify(error)
|
||||||
_LOGGER.debug("*** error = " + error)
|
LOGGER.debug("*** error = " + error)
|
||||||
|
|
||||||
def _handle_life_span(self, event):
|
def _handle_life_span(self, event):
|
||||||
type = event['type']
|
type = event['type']
|
||||||
try:
|
try:
|
||||||
type = COMPONENT_FROM_ECOVACS[type]
|
type = COMPONENT_FROM_ECOVACS[type]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning("Unknown component type: '" + type + "'")
|
LOGGER.warning("Unknown component type: '" + type + "'")
|
||||||
if 'val' in event:
|
if 'val' in event:
|
||||||
lifespan = int(event['val']) / 100
|
lifespan = int(event['val']) / 100
|
||||||
_LOGGER.debug("**********Component " + type + " has lifespan of " + str(lifespan) + ".")
|
LOGGER.debug("**********Component " + type + " has lifespan of " + str(lifespan) + ".")
|
||||||
else:
|
else:
|
||||||
lifespan = int(event['left']) / 60 #This works for a D901
|
lifespan = int(event['left']) / 60 #This works for a D901
|
||||||
self.components[type] = lifespan
|
self.components[type] = lifespan
|
||||||
lifespan_event = {'type': type, 'lifespan': lifespan}
|
lifespan_event = {'type': type, 'lifespan': lifespan}
|
||||||
self.lifespanEvents.notify(lifespan_event)
|
self.lifespanEvents.notify(lifespan_event)
|
||||||
_LOGGER.debug("*** life_span " + type + " = " + str(lifespan))
|
LOGGER.debug("*** life_span " + type + " = " + str(lifespan))
|
||||||
|
|
||||||
def _handle_clean_report(self, event):
|
def _handle_clean_report(self, event):
|
||||||
type = event['type']
|
type = event['type']
|
||||||
@@ -345,7 +345,7 @@ class VacBot():
|
|||||||
if statustype == CLEAN_ACTION_STOP or statustype == CLEAN_ACTION_PAUSE:
|
if statustype == CLEAN_ACTION_STOP or statustype == CLEAN_ACTION_PAUSE:
|
||||||
type = statustype
|
type = statustype
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning("Unknown cleaning status '" + type + "'")
|
LOGGER.warning("Unknown cleaning status '" + type + "'")
|
||||||
self.clean_status = type
|
self.clean_status = type
|
||||||
self.vacuum_status = type
|
self.vacuum_status = type
|
||||||
fan = event.get('speed', None)
|
fan = event.get('speed', None)
|
||||||
@@ -353,22 +353,22 @@ class VacBot():
|
|||||||
try:
|
try:
|
||||||
fan = FAN_SPEED_FROM_ECOVACS[fan]
|
fan = FAN_SPEED_FROM_ECOVACS[fan]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning("Unknown fan speed: '" + fan + "'")
|
LOGGER.warning("Unknown fan speed: '" + fan + "'")
|
||||||
self.fan_speed = fan
|
self.fan_speed = fan
|
||||||
self.statusEvents.notify(self.vacuum_status)
|
self.statusEvents.notify(self.vacuum_status)
|
||||||
if self.fan_speed:
|
if self.fan_speed:
|
||||||
_LOGGER.debug("*** clean_status = " + self.clean_status + " fan_speed = " + self.fan_speed)
|
LOGGER.debug("*** clean_status = " + self.clean_status + " fan_speed = " + self.fan_speed)
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("*** clean_status = " + self.clean_status + " fan_speed = None")
|
LOGGER.debug("*** clean_status = " + self.clean_status + " fan_speed = None")
|
||||||
|
|
||||||
def _handle_battery_info(self, iq):
|
def _handle_battery_info(self, iq):
|
||||||
try:
|
try:
|
||||||
self.battery_status = float(iq['power']) / 100
|
self.battery_status = float(iq['power']) / 100
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("couldn't parse battery status " + ET.tostring(iq))
|
LOGGER.warning("couldn't parse battery status " + ET.tostring(iq))
|
||||||
else:
|
else:
|
||||||
self.batteryEvents.notify(self.battery_status)
|
self.batteryEvents.notify(self.battery_status)
|
||||||
_LOGGER.debug("*** battery_status = {:.0%}".format(self.battery_status))
|
LOGGER.debug("*** battery_status = {:.0%}".format(self.battery_status))
|
||||||
|
|
||||||
def _handle_charge_state(self, event):
|
def _handle_charge_state(self, event):
|
||||||
if 'type' in event:
|
if 'type' in event:
|
||||||
@@ -382,11 +382,11 @@ class VacBot():
|
|||||||
status = 'idle'
|
status = 'idle'
|
||||||
else:
|
else:
|
||||||
status = 'idle' #Fall back to Idle status
|
status = 'idle' #Fall back to Idle status
|
||||||
_LOGGER.error("Unknown charging status '" + event['errno'] + "'") #Log this so we can identify more errors
|
LOGGER.error("Unknown charging status '" + event['errno'] + "'") #Log this so we can identify more errors
|
||||||
try:
|
try:
|
||||||
status = CHARGE_MODE_FROM_ECOVACS[status]
|
status = CHARGE_MODE_FROM_ECOVACS[status]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.warning("Unknown charging status '" + status + "'")
|
LOGGER.warning("Unknown charging status '" + status + "'")
|
||||||
self.charge_status = status
|
self.charge_status = status
|
||||||
if status != 'idle' or self.vacuum_status == 'charging':
|
if status != 'idle' or self.vacuum_status == 'charging':
|
||||||
# We have to ignore the idle messages, because all it means is that it's not
|
# We have to ignore the idle messages, because all it means is that it's not
|
||||||
@@ -394,7 +394,7 @@ class VacBot():
|
|||||||
# of what the vacuum is currently up to.
|
# of what the vacuum is currently up to.
|
||||||
self.vacuum_status = status
|
self.vacuum_status = status
|
||||||
self.statusEvents.notify(self.vacuum_status)
|
self.statusEvents.notify(self.vacuum_status)
|
||||||
_LOGGER.debug("*** charge_status = " + self.charge_status)
|
LOGGER.debug("*** charge_status = " + self.charge_status)
|
||||||
|
|
||||||
def _vacuum_address(self):
|
def _vacuum_address(self):
|
||||||
if not self.vacuum['iotmq']:
|
if not self.vacuum['iotmq']:
|
||||||
@@ -418,15 +418,15 @@ class VacBot():
|
|||||||
if not self.iotmq.send_ping():
|
if not self.iotmq.send_ping():
|
||||||
raise RuntimeError()
|
raise RuntimeError()
|
||||||
except XMPPError as err:
|
except XMPPError as err:
|
||||||
_LOGGER.warning("Ping did not reach VacBot. Will retry.")
|
LOGGER.warning("Ping did not reach VacBot. Will retry.")
|
||||||
_LOGGER.debug("*** Error type: " + err.etype)
|
LOGGER.debug("*** Error type: " + err.etype)
|
||||||
_LOGGER.debug("*** Error condition: " + err.condition)
|
LOGGER.debug("*** Error condition: " + err.condition)
|
||||||
self._failed_pings += 1
|
self._failed_pings += 1
|
||||||
if self._failed_pings >= 4:
|
if self._failed_pings >= 4:
|
||||||
self.vacuum_status = 'offline'
|
self.vacuum_status = 'offline'
|
||||||
self.statusEvents.notify(self.vacuum_status)
|
self.statusEvents.notify(self.vacuum_status)
|
||||||
except RuntimeError as err:
|
except RuntimeError as err:
|
||||||
_LOGGER.warning("Ping did not reach VacBot. Will retry.")
|
LOGGER.warning("Ping did not reach VacBot. Will retry.")
|
||||||
self._failed_pings += 1
|
self._failed_pings += 1
|
||||||
if self._failed_pings >= 4:
|
if self._failed_pings >= 4:
|
||||||
self.vacuum_status = 'offline'
|
self.vacuum_status = 'offline'
|
||||||
@@ -449,9 +449,9 @@ class VacBot():
|
|||||||
self.run(GetLifeSpan('side_brush'))
|
self.run(GetLifeSpan('side_brush'))
|
||||||
self.run(GetLifeSpan('filter'))
|
self.run(GetLifeSpan('filter'))
|
||||||
except XMPPError as err:
|
except XMPPError as err:
|
||||||
_LOGGER.warning("Component refresh requests failed to reach VacBot. Will try again later.")
|
LOGGER.warning("Component refresh requests failed to reach VacBot. Will try again later.")
|
||||||
_LOGGER.debug("*** Error type: " + err.etype)
|
LOGGER.debug("*** Error type: " + err.etype)
|
||||||
_LOGGER.debug("*** Error condition: " + err.condition)
|
LOGGER.debug("*** Error condition: " + err.condition)
|
||||||
|
|
||||||
def refresh_statuses(self):
|
def refresh_statuses(self):
|
||||||
try:
|
try:
|
||||||
@@ -459,9 +459,9 @@ class VacBot():
|
|||||||
self.run(GetChargeState())
|
self.run(GetChargeState())
|
||||||
self.run(GetBatteryState())
|
self.run(GetBatteryState())
|
||||||
except XMPPError as err:
|
except XMPPError as err:
|
||||||
_LOGGER.warning("Initial status requests failed to reach VacBot. Will try again on next ping.")
|
LOGGER.warning("Initial status requests failed to reach VacBot. Will try again on next ping.")
|
||||||
_LOGGER.debug("*** Error type: " + err.etype)
|
LOGGER.debug("*** Error type: " + err.etype)
|
||||||
_LOGGER.debug("*** Error condition: " + err.condition)
|
LOGGER.debug("*** Error condition: " + err.condition)
|
||||||
|
|
||||||
def request_all_statuses(self):
|
def request_all_statuses(self):
|
||||||
self.refresh_statuses()
|
self.refresh_statuses()
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from threading import Event
|
|||||||
from sleekxmppfs import ClientXMPP, Callback, MatchXPath
|
from sleekxmppfs import ClientXMPP, Callback, MatchXPath
|
||||||
from sleekxmppfs.xmlstream import ET
|
from sleekxmppfs.xmlstream import ET
|
||||||
#from sleekxmppfs.exceptions import XMPPError
|
#from sleekxmppfs.exceptions import XMPPError
|
||||||
from .const import _LOGGER
|
from .const import LOGGER
|
||||||
|
|
||||||
#This is used by EcoVacsIOTMQ and EcoVacsXMPP for _ctl_to_dict
|
#This is used by EcoVacsIOTMQ and EcoVacsXMPP for _ctl_to_dict
|
||||||
def RepresentsInt(stringvar):
|
def RepresentsInt(stringvar):
|
||||||
@@ -35,8 +35,8 @@ class EcoVacsXMPP(ClientXMPP):
|
|||||||
self.ready_flag.wait()
|
self.ready_flag.wait()
|
||||||
|
|
||||||
def session_start(self, event):
|
def session_start(self, event):
|
||||||
_LOGGER.debug("----------------- starting session ----------------")
|
LOGGER.debug("----------------- starting session ----------------")
|
||||||
_LOGGER.debug("event = {}".format(event))
|
LOGGER.debug("event = {}".format(event))
|
||||||
self.register_handler(Callback("general",
|
self.register_handler(Callback("general",
|
||||||
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}'),
|
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}'),
|
||||||
self._handle_ctl))
|
self._handle_ctl))
|
||||||
@@ -63,7 +63,7 @@ class EcoVacsXMPP(ClientXMPP):
|
|||||||
try: # check for child xml
|
try: # check for child xml
|
||||||
childxml = xml[0]
|
childxml = xml[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
_LOGGER.debug("No child xml")
|
LOGGER.debug("No child xml")
|
||||||
if 'td' not in result:
|
if 'td' not in result:
|
||||||
# Handle response data with no 'td'
|
# Handle response data with no 'td'
|
||||||
if 'type' in result: # single element with type and val
|
if 'type' in result: # single element with type and val
|
||||||
@@ -98,7 +98,7 @@ class EcoVacsXMPP(ClientXMPP):
|
|||||||
|
|
||||||
def send_command(self, xml, recipient):
|
def send_command(self, xml, recipient):
|
||||||
c = self._wrap_command(xml, recipient)
|
c = self._wrap_command(xml, recipient)
|
||||||
_LOGGER.debug('Sending command {0}'.format(c))
|
LOGGER.debug('Sending command {0}'.format(c))
|
||||||
c.send()
|
c.send()
|
||||||
|
|
||||||
def _wrap_command(self, ctl, recipient):
|
def _wrap_command(self, ctl, recipient):
|
||||||
@@ -129,12 +129,12 @@ class EcoVacsXMPP(ClientXMPP):
|
|||||||
def send_ping(self, to):
|
def send_ping(self, to):
|
||||||
q = self.make_iq_get(ito=to, ifrom=self._my_address())
|
q = self.make_iq_get(ito=to, ifrom=self._my_address())
|
||||||
q.xml.append(ET.Element('ping', {'xmlns': 'urn:xmpp:ping'}))
|
q.xml.append(ET.Element('ping', {'xmlns': 'urn:xmpp:ping'}))
|
||||||
_LOGGER.debug("*** sending ping ***")
|
LOGGER.debug("*** sending ping ***")
|
||||||
q.send()
|
q.send()
|
||||||
|
|
||||||
# used some code from a sleekxmppfs plugin, seems to work fine
|
# used some code from a sleekxmppfs plugin, seems to work fine
|
||||||
def _handle_ping(self, iq):
|
def _handle_ping(self, iq):
|
||||||
_LOGGER.debug("Pinged by %s", iq['from'])
|
LOGGER.debug("Pinged by %s", iq['from'])
|
||||||
iq.reply().send()
|
iq.reply().send()
|
||||||
|
|
||||||
def connect_and_wait_until_ready(self):
|
def connect_and_wait_until_ready(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user