Move imports to top for ecovacs (#29017)

* Moved imports in ecovacs integration

* Imported sucks once, reused it multiple times
This commit is contained in:
springstan 2019-11-26 03:01:48 +01:00 committed by Paulus Schoutsen
parent cc346e57e6
commit cc255da038
2 changed files with 11 additions and 19 deletions

View File

@ -3,6 +3,7 @@ import logging
import random import random
import string import string
from sucks import EcoVacsAPI, VacBot
import voluptuous as vol import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
@ -44,8 +45,6 @@ def setup(hass, config):
hass.data[ECOVACS_DEVICES] = [] hass.data[ECOVACS_DEVICES] = []
from sucks import EcoVacsAPI, VacBot
ecovacs_api = EcoVacsAPI( ecovacs_api = EcoVacsAPI(
ECOVACS_API_DEVICEID, ECOVACS_API_DEVICEID,
config[DOMAIN].get(CONF_USERNAME), config[DOMAIN].get(CONF_USERNAME),

View File

@ -1,6 +1,8 @@
"""Support for Ecovacs Ecovacs Vaccums.""" """Support for Ecovacs Ecovacs Vaccums."""
import logging import logging
import sucks
from homeassistant.components.vacuum import ( from homeassistant.components.vacuum import (
SUPPORT_BATTERY, SUPPORT_BATTERY,
SUPPORT_CLEAN_SPOT, SUPPORT_CLEAN_SPOT,
@ -123,9 +125,8 @@ class EcovacsVacuum(VacuumDevice):
def return_to_base(self, **kwargs): def return_to_base(self, **kwargs):
"""Set the vacuum cleaner to return to the dock.""" """Set the vacuum cleaner to return to the dock."""
from sucks import Charge
self.device.run(Charge()) self.device.run(sucks.Charge())
@property @property
def battery_icon(self): def battery_icon(self):
@ -150,15 +151,13 @@ class EcovacsVacuum(VacuumDevice):
@property @property
def fan_speed_list(self): def fan_speed_list(self):
"""Get the list of available fan speed steps of the vacuum cleaner.""" """Get the list of available fan speed steps of the vacuum cleaner."""
from sucks import FAN_SPEED_NORMAL, FAN_SPEED_HIGH
return [FAN_SPEED_NORMAL, FAN_SPEED_HIGH] return [sucks.FAN_SPEED_NORMAL, sucks.FAN_SPEED_HIGH]
def turn_on(self, **kwargs): def turn_on(self, **kwargs):
"""Turn the vacuum on and start cleaning.""" """Turn the vacuum on and start cleaning."""
from sucks import Clean
self.device.run(Clean()) self.device.run(sucks.Clean())
def turn_off(self, **kwargs): def turn_off(self, **kwargs):
"""Turn the vacuum off stopping the cleaning and returning home.""" """Turn the vacuum off stopping the cleaning and returning home."""
@ -166,34 +165,28 @@ class EcovacsVacuum(VacuumDevice):
def stop(self, **kwargs): def stop(self, **kwargs):
"""Stop the vacuum cleaner.""" """Stop the vacuum cleaner."""
from sucks import Stop
self.device.run(Stop()) self.device.run(sucks.Stop())
def clean_spot(self, **kwargs): def clean_spot(self, **kwargs):
"""Perform a spot clean-up.""" """Perform a spot clean-up."""
from sucks import Spot
self.device.run(Spot()) self.device.run(sucks.Spot())
def locate(self, **kwargs): def locate(self, **kwargs):
"""Locate the vacuum cleaner.""" """Locate the vacuum cleaner."""
from sucks import PlaySound
self.device.run(PlaySound()) self.device.run(sucks.PlaySound())
def set_fan_speed(self, fan_speed, **kwargs): def set_fan_speed(self, fan_speed, **kwargs):
"""Set fan speed.""" """Set fan speed."""
if self.is_on: if self.is_on:
from sucks import Clean
self.device.run(Clean(mode=self.device.clean_status, speed=fan_speed)) self.device.run(sucks.Clean(mode=self.device.clean_status, speed=fan_speed))
def send_command(self, command, params=None, **kwargs): def send_command(self, command, params=None, **kwargs):
"""Send a command to a vacuum cleaner.""" """Send a command to a vacuum cleaner."""
from sucks import VacBotCommand self.device.run(sucks.VacBotCommand(command, params))
self.device.run(VacBotCommand(command, params))
@property @property
def device_state_attributes(self): def device_state_attributes(self):