Skip to content

Commit

Permalink
Move imports to top for ecovacs (#29017)
Browse files Browse the repository at this point in the history
* Moved imports in ecovacs integration

* Imported sucks once, reused it multiple times
  • Loading branch information
springstan authored and balloob committed Nov 26, 2019
1 parent cc346e5 commit cc255da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
3 changes: 1 addition & 2 deletions homeassistant/components/ecovacs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
import string

from sucks import EcoVacsAPI, VacBot
import voluptuous as vol

from homeassistant.const import CONF_PASSWORD, CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
Expand Down Expand Up @@ -44,8 +45,6 @@ def setup(hass, config):

hass.data[ECOVACS_DEVICES] = []

from sucks import EcoVacsAPI, VacBot

ecovacs_api = EcoVacsAPI(
ECOVACS_API_DEVICEID,
config[DOMAIN].get(CONF_USERNAME),
Expand Down
27 changes: 10 additions & 17 deletions homeassistant/components/ecovacs/vacuum.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Support for Ecovacs Ecovacs Vaccums."""
import logging

import sucks

from homeassistant.components.vacuum import (
SUPPORT_BATTERY,
SUPPORT_CLEAN_SPOT,
Expand Down Expand Up @@ -123,9 +125,8 @@ def status(self):

def return_to_base(self, **kwargs):
"""Set the vacuum cleaner to return to the dock."""
from sucks import Charge

self.device.run(Charge())
self.device.run(sucks.Charge())

@property
def battery_icon(self):
Expand All @@ -150,50 +151,42 @@ def fan_speed(self):
@property
def fan_speed_list(self):
"""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):
"""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):
"""Turn the vacuum off stopping the cleaning and returning home."""
self.return_to_base()

def stop(self, **kwargs):
"""Stop the vacuum cleaner."""
from sucks import Stop

self.device.run(Stop())
self.device.run(sucks.Stop())

def clean_spot(self, **kwargs):
"""Perform a spot clean-up."""
from sucks import Spot

self.device.run(Spot())
self.device.run(sucks.Spot())

def locate(self, **kwargs):
"""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):
"""Set fan speed."""
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):
"""Send a command to a vacuum cleaner."""
from sucks import VacBotCommand

self.device.run(VacBotCommand(command, params))
self.device.run(sucks.VacBotCommand(command, params))

@property
def device_state_attributes(self):
Expand Down

0 comments on commit cc255da

Please sign in to comment.