From db2c4ec8806b370bdecd059704fa3f4cc558a3cb Mon Sep 17 00:00:00 2001 From: bittles Date: Tue, 3 Jan 2023 22:21:14 -0500 Subject: [PATCH] optimizations split out sucks constants to their own file, no need to define verify ssl. if bumper is true then verify ssl false --- custom_components/ecovacs/__init__.py | 18 ++-- custom_components/ecovacs/const.py | 111 +---------------------- custom_components/ecovacs/sucks_const.py | 109 ++++++++++++++++++++++ custom_components/ecovacs/sucksbumper.py | 3 +- 4 files changed, 120 insertions(+), 121 deletions(-) create mode 100644 custom_components/ecovacs/sucks_const.py diff --git a/custom_components/ecovacs/__init__.py b/custom_components/ecovacs/__init__.py index 718eda4..14024e4 100644 --- a/custom_components/ecovacs/__init__.py +++ b/custom_components/ecovacs/__init__.py @@ -1,12 +1,11 @@ """Support for Ecovacs Deebot vacuums.""" import random import string -##import asyncio ## to do will need to convert to slixmpp to do this i believe +#import asyncio ## to do will need to convert to slixmpp to do this i believe from homeassistant.const import ( CONF_PASSWORD, CONF_USERNAME, - CONF_VERIFY_SSL, # added EVENT_HOMEASSISTANT_STOP, Platform, ) @@ -25,6 +24,7 @@ from .const import ( CONF_BUMPER, CONF_BUMPER_SERVER, SERVER_ADDRESS, + VERIFY_SSL, LOGGER ) @@ -37,8 +37,7 @@ CONFIG_SCHEMA = vol.Schema( vol.Required(CONF_COUNTRY): 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_SERVER): cv.string, - vol.Optional(CONF_VERIFY_SSL, default=True): cv.boolean, # can probably get rid of this and set verify ssl false if bumper true + vol.Optional(CONF_BUMPER_SERVER): cv.string } ) }, @@ -58,9 +57,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: # 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 + VERIFY_SSL = False + # if not server address is null and verify ssl true from const ecovacs_api = EcoVacsAPI( ECOVACS_API_DEVICEID, @@ -68,7 +66,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), # add to class call + VERIFY_SSL # add to class call ) devices = ecovacs_api.devices() @@ -88,8 +86,8 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: device, config[DOMAIN].get(CONF_CONTINENT).lower(), 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, + VERIFY_SSL, # verify ssl or not + monitor=True ) hass.data[ECOVACS_DEVICES].append(vacbot) diff --git a/custom_components/ecovacs/const.py b/custom_components/ecovacs/const.py index cd7e20a..fd60050 100644 --- a/custom_components/ecovacs/const.py +++ b/custom_components/ecovacs/const.py @@ -11,113 +11,4 @@ CONF_CONTINENT = "continent" CONF_BUMPER = "bumper" CONF_BUMPER_SERVER = "bumper_server" SERVER_ADDRESS = None - -#sucks constants -# These consts define all of the vocabulary used by this library when presenting various states and components. -# Applications implementing this library should import these rather than hard-code the strings, for future-proofing. - -CLEAN_MODE_AUTO = 'auto' -CLEAN_MODE_EDGE = 'edge' -CLEAN_MODE_SPOT = 'spot' -CLEAN_MODE_SPOT_AREA = 'spot_area' -CLEAN_MODE_SINGLE_ROOM = 'single_room' -CLEAN_MODE_STOP = 'stop' - -CLEAN_ACTION_START = 'start' -CLEAN_ACTION_PAUSE = 'pause' -CLEAN_ACTION_RESUME = 'resume' -CLEAN_ACTION_STOP = 'stop' - -FAN_SPEED_NORMAL = 'normal' -FAN_SPEED_HIGH = 'high' - -CHARGE_MODE_RETURN = 'return' -CHARGE_MODE_RETURNING = 'returning' -CHARGE_MODE_CHARGING = 'charging' -CHARGE_MODE_IDLE = 'idle' - -COMPONENT_SIDE_BRUSH = 'side_brush' -COMPONENT_MAIN_BRUSH = 'main_brush' -COMPONENT_FILTER = 'filter' - -VACUUM_STATUS_OFFLINE = 'offline' - -CLEANING_STATES = {CLEAN_MODE_AUTO, CLEAN_MODE_EDGE, CLEAN_MODE_SPOT, CLEAN_MODE_SPOT_AREA, CLEAN_MODE_SINGLE_ROOM} -CHARGING_STATES = {CHARGE_MODE_CHARGING} - -# These dictionaries convert to and from Sucks's consts (which closely match what the UI and manuals use) -# to and from what the Ecovacs API uses (which are sometimes very oddly named and have random capitalization.) -CLEAN_MODE_TO_ECOVACS = { - CLEAN_MODE_AUTO: 'auto', - CLEAN_MODE_EDGE: 'border', - CLEAN_MODE_SPOT: 'spot', - CLEAN_MODE_SPOT_AREA: 'SpotArea', - CLEAN_MODE_SINGLE_ROOM: 'singleroom', - CLEAN_MODE_STOP: 'stop' -} - -CLEAN_ACTION_TO_ECOVACS = { - CLEAN_ACTION_START: 's', - CLEAN_ACTION_PAUSE: 'p', - CLEAN_ACTION_RESUME: 'r', - CLEAN_ACTION_STOP: 'h', -} - -CLEAN_ACTION_FROM_ECOVACS = { - 's': CLEAN_ACTION_START, - 'p': CLEAN_ACTION_PAUSE, - 'r': CLEAN_ACTION_RESUME, - 'h': CLEAN_ACTION_STOP, -} - -CLEAN_MODE_FROM_ECOVACS = { - 'auto': CLEAN_MODE_AUTO, - 'border': CLEAN_MODE_EDGE, - 'spot': CLEAN_MODE_SPOT, - 'spot_area': CLEAN_MODE_SPOT_AREA, - 'SpotArea': CLEAN_MODE_SPOT_AREA, - 'singleroom': CLEAN_MODE_SINGLE_ROOM, - 'stop': CLEAN_MODE_STOP, - 'going': CHARGE_MODE_RETURNING, -} - -FAN_SPEED_TO_ECOVACS = { - FAN_SPEED_NORMAL: 'standard', - FAN_SPEED_HIGH: 'strong' -} - -FAN_SPEED_FROM_ECOVACS = { - 'standard': FAN_SPEED_NORMAL, - 'strong': FAN_SPEED_HIGH, -} - -CHARGE_MODE_TO_ECOVACS = { - CHARGE_MODE_RETURN: 'go', - CHARGE_MODE_RETURNING: 'Going', - CHARGE_MODE_CHARGING: 'SlotCharging', - CHARGE_MODE_IDLE: 'Idle', -} - -CHARGE_MODE_FROM_ECOVACS = { - 'going': CHARGE_MODE_RETURNING, -# 'Going': CHARGE_MODE_RETURNING, - 'slot_charging': CHARGE_MODE_CHARGING, -# 'SlotCharging': CHARGE_MODE_CHARGING, - 'idle': CHARGE_MODE_IDLE, -# 'Idle': CHARGE_MODE_IDLE, -} - -COMPONENT_TO_ECOVACS = { - COMPONENT_MAIN_BRUSH: 'Brush', - COMPONENT_SIDE_BRUSH: 'SideBrush', - COMPONENT_FILTER: 'DustCaseHeap', -} - -COMPONENT_FROM_ECOVACS = { - 'brush': COMPONENT_MAIN_BRUSH, -# 'Brush': COMPONENT_MAIN_BRUSH, - 'side_brush': COMPONENT_SIDE_BRUSH, -# 'SideBrush': COMPONENT_SIDE_BRUSH, - 'dust_case_heap': COMPONENT_FILTER, -# 'DustCaseHeap': COMPONENT_FILTER, -} \ No newline at end of file +VERIFY_SSL = True \ No newline at end of file diff --git a/custom_components/ecovacs/sucks_const.py b/custom_components/ecovacs/sucks_const.py new file mode 100644 index 0000000..bee3313 --- /dev/null +++ b/custom_components/ecovacs/sucks_const.py @@ -0,0 +1,109 @@ +#sucks constants +# These consts define all of the vocabulary used by this library when presenting various states and components. +# Applications implementing this library should import these rather than hard-code the strings, for future-proofing. + +CLEAN_MODE_AUTO = 'auto' +CLEAN_MODE_EDGE = 'edge' +CLEAN_MODE_SPOT = 'spot' +CLEAN_MODE_SPOT_AREA = 'spot_area' +CLEAN_MODE_SINGLE_ROOM = 'single_room' +CLEAN_MODE_STOP = 'stop' + +CLEAN_ACTION_START = 'start' +CLEAN_ACTION_PAUSE = 'pause' +CLEAN_ACTION_RESUME = 'resume' +CLEAN_ACTION_STOP = 'stop' + +FAN_SPEED_NORMAL = 'normal' +FAN_SPEED_HIGH = 'high' + +CHARGE_MODE_RETURN = 'return' +CHARGE_MODE_RETURNING = 'returning' +CHARGE_MODE_CHARGING = 'charging' +CHARGE_MODE_IDLE = 'idle' + +COMPONENT_SIDE_BRUSH = 'side_brush' +COMPONENT_MAIN_BRUSH = 'main_brush' +COMPONENT_FILTER = 'filter' + +VACUUM_STATUS_OFFLINE = 'offline' + +CLEANING_STATES = {CLEAN_MODE_AUTO, CLEAN_MODE_EDGE, CLEAN_MODE_SPOT, CLEAN_MODE_SPOT_AREA, CLEAN_MODE_SINGLE_ROOM} +CHARGING_STATES = {CHARGE_MODE_CHARGING} + +# These dictionaries convert to and from Sucks's consts (which closely match what the UI and manuals use) +# to and from what the Ecovacs API uses (which are sometimes very oddly named and have random capitalization.) +CLEAN_MODE_TO_ECOVACS = { + CLEAN_MODE_AUTO: 'auto', + CLEAN_MODE_EDGE: 'border', + CLEAN_MODE_SPOT: 'spot', + CLEAN_MODE_SPOT_AREA: 'SpotArea', + CLEAN_MODE_SINGLE_ROOM: 'singleroom', + CLEAN_MODE_STOP: 'stop' +} + +CLEAN_ACTION_TO_ECOVACS = { + CLEAN_ACTION_START: 's', + CLEAN_ACTION_PAUSE: 'p', + CLEAN_ACTION_RESUME: 'r', + CLEAN_ACTION_STOP: 'h', +} + +CLEAN_ACTION_FROM_ECOVACS = { + 's': CLEAN_ACTION_START, + 'p': CLEAN_ACTION_PAUSE, + 'r': CLEAN_ACTION_RESUME, + 'h': CLEAN_ACTION_STOP, +} + +CLEAN_MODE_FROM_ECOVACS = { + 'auto': CLEAN_MODE_AUTO, + 'border': CLEAN_MODE_EDGE, + 'spot': CLEAN_MODE_SPOT, + 'spot_area': CLEAN_MODE_SPOT_AREA, + 'SpotArea': CLEAN_MODE_SPOT_AREA, + 'singleroom': CLEAN_MODE_SINGLE_ROOM, + 'stop': CLEAN_MODE_STOP, + 'going': CHARGE_MODE_RETURNING, +} + +FAN_SPEED_TO_ECOVACS = { + FAN_SPEED_NORMAL: 'standard', + FAN_SPEED_HIGH: 'strong' +} + +FAN_SPEED_FROM_ECOVACS = { + 'standard': FAN_SPEED_NORMAL, + 'strong': FAN_SPEED_HIGH, +} + +CHARGE_MODE_TO_ECOVACS = { + CHARGE_MODE_RETURN: 'go', + CHARGE_MODE_RETURNING: 'Going', + CHARGE_MODE_CHARGING: 'SlotCharging', + CHARGE_MODE_IDLE: 'Idle', +} + +CHARGE_MODE_FROM_ECOVACS = { + 'going': CHARGE_MODE_RETURNING, +# 'Going': CHARGE_MODE_RETURNING, + 'slot_charging': CHARGE_MODE_CHARGING, +# 'SlotCharging': CHARGE_MODE_CHARGING, + 'idle': CHARGE_MODE_IDLE, +# 'Idle': CHARGE_MODE_IDLE, +} + +COMPONENT_TO_ECOVACS = { + COMPONENT_MAIN_BRUSH: 'Brush', + COMPONENT_SIDE_BRUSH: 'SideBrush', + COMPONENT_FILTER: 'DustCaseHeap', +} + +COMPONENT_FROM_ECOVACS = { + 'brush': COMPONENT_MAIN_BRUSH, +# 'Brush': COMPONENT_MAIN_BRUSH, + 'side_brush': COMPONENT_SIDE_BRUSH, +# 'SideBrush': COMPONENT_SIDE_BRUSH, + 'dust_case_heap': COMPONENT_FILTER, +# 'DustCaseHeap': COMPONENT_FILTER, +} \ No newline at end of file diff --git a/custom_components/ecovacs/sucksbumper.py b/custom_components/ecovacs/sucksbumper.py index 032c5b6..8cf4829 100644 --- a/custom_components/ecovacs/sucksbumper.py +++ b/custom_components/ecovacs/sucksbumper.py @@ -10,7 +10,8 @@ from sleekxmppfs.exceptions import XMPPError from .mqtt_ecovacs import EcoVacsIOTMQ from .xmpp_ecovacs import EcoVacsXMPP -from .const import * +from .const import LOGGER +from .sucks_const import * def str_to_bool_or_cert(s): if s == 'True' or s == True: