From 248f5c02094ec0d9b59e3af39e320a78fc859392 Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Tue, 22 Nov 2016 04:36:44 +0100 Subject: [PATCH] Neato Fixes (#4490) * Fix, switch state. Move constants to hub * Responsiveness * Whitespace * Delay was not needed as commands does not return until done. --- homeassistant/components/neato.py | 47 +++++++++++++++++++++++ homeassistant/components/sensor/neato.py | 49 +----------------------- homeassistant/components/switch/neato.py | 8 ++-- 3 files changed, 54 insertions(+), 50 deletions(-) diff --git a/homeassistant/components/neato.py b/homeassistant/components/neato.py index 0c77c3a6b5c..e0b36721f74 100644 --- a/homeassistant/components/neato.py +++ b/homeassistant/components/neato.py @@ -31,6 +31,53 @@ CONFIG_SCHEMA = vol.Schema({ }) }, extra=vol.ALLOW_EXTRA) +STATES = { + 1: 'Idle', + 2: 'Busy', + 3: 'Pause', + 4: 'Error' +} + +MODE = { + 1: 'Eco', + 2: 'Turbo' +} + +ACTION = { + 0: 'No action', + 1: 'House cleaning', + 2: 'Spot cleaning', + 3: 'Manual cleaning', + 4: 'Docking', + 5: 'User menu active', + 6: 'Cleaning cancelled', + 7: 'Updating...', + 8: 'Copying logs...', + 9: 'Calculating position...', + 10: 'IEC test' +} + +ERRORS = { + 'ui_error_brush_stuck': 'Brush stuck', + 'ui_error_brush_overloaded': 'Brush overloaded', + 'ui_error_bumper_stuck': 'Bumper stuck', + 'ui_error_dust_bin_missing': 'Dust bin missing', + 'ui_error_dust_bin_full': 'Dust bin full', + 'ui_error_dust_bin_emptied': 'Dust bin emptied', + 'ui_error_navigation_backdrop_leftbump': 'Clear my path', + 'ui_error_navigation_noprogress': 'Clear my path', + 'ui_error_navigation_origin_unclean': 'Clear my path', + 'ui_error_navigation_pathproblems_returninghome': 'Cannot return to base', + 'ui_error_navigation_falling': 'Clear my path', + 'ui_error_picked_up': 'Picked up', + 'ui_error_stuck': 'Stuck!' +} + +ALERTS = { + 'ui_alert_dust_bin_full': 'Please empty dust bin', + 'ui_alert_recovering_location': 'Returning to start' +} + def setup(hass, config): """Setup the Verisure component.""" diff --git a/homeassistant/components/sensor/neato.py b/homeassistant/components/sensor/neato.py index bbc0570740c..438e5fb189b 100644 --- a/homeassistant/components/sensor/neato.py +++ b/homeassistant/components/sensor/neato.py @@ -7,7 +7,8 @@ https://home-assistant.io/components/sensor.neato/ import logging from homeassistant.helpers.entity import Entity -from homeassistant.components.neato import NEATO_ROBOTS, NEATO_LOGIN +from homeassistant.components.neato import ( + NEATO_ROBOTS, NEATO_LOGIN, ACTION, ERRORS, MODE, ALERTS) _LOGGER = logging.getLogger(__name__) SENSOR_TYPE_STATUS = 'status' @@ -18,52 +19,6 @@ SENSOR_TYPES = { SENSOR_TYPE_BATTERY: ['Battery'] } -STATES = { - 1: 'Idle', - 2: 'Busy', - 3: 'Pause', - 4: 'Error' -} - -MODE = { - 1: 'Eco', - 2: 'Turbo' -} - -ACTION = { - 0: 'No action', - 1: 'House cleaning', - 2: 'Spot cleaning', - 3: 'Manual cleaning', - 4: 'Docking', - 5: 'User menu active', - 6: 'Cleaning cancelled', - 7: 'Updating...', - 8: 'Copying logs...', - 9: 'Calculating position...', - 10: 'IEC test' -} - -ERRORS = { - 'ui_error_brush_stuck': 'Brush stuck', - 'ui_error_brush_overloaded': 'Brush overloaded', - 'ui_error_bumper_stuck': 'Bumper stuck', - 'ui_error_dust_bin_missing': 'Dust bin missing', - 'ui_error_dust_bin_full': 'Dust bin full', - 'ui_error_dust_bin_emptied': 'Dust bin emptied', - 'ui_error_navigation_noprogress': 'Clear my path', - 'ui_error_navigation_origin_unclean': 'Clear my path', - 'ui_error_navigation_falling': 'Clear my path', - 'ui_error_picked_up': 'Picked up', - 'ui_error_stuck': 'Stuck!' - -} - -ALERTS = { - 'ui_alert_dust_bin_full': 'Please empty dust bin', - 'ui_alert_recovering_location': 'Returning to start' -} - def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Neato sensor platform.""" diff --git a/homeassistant/components/switch/neato.py b/homeassistant/components/switch/neato.py index fdc5f9352b7..3b723acb748 100644 --- a/homeassistant/components/switch/neato.py +++ b/homeassistant/components/switch/neato.py @@ -4,7 +4,6 @@ Support for Neato Connected Vaccums switches. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/switch.neato/ """ -import time import logging from homeassistant.const import STATE_OFF, STATE_ON @@ -57,17 +56,21 @@ class NeatoConnectedSwitch(ToggleEntity): self._state = self.robot.state _LOGGER.debug('self._state=%s', self._state) if self.type == SWITCH_TYPE_CLEAN: - if (self.robot.state['action'] == 1 and + if (self.robot.state['action'] == 1 or + self.robot.state['action'] == 2 or + self.robot.state['action'] == 3 and self.robot.state['state'] == 2): self._clean_state = STATE_ON else: self._clean_state = STATE_OFF + _LOGGER.debug('schedule_state=%s', self._schedule_state) if self.type == SWITCH_TYPE_SCHEDULE: _LOGGER.debug('self._state=%s', self._state) if self.robot.schedule_enabled: self._schedule_state = STATE_ON else: self._schedule_state = STATE_OFF + _LOGGER.debug('schedule_state=%s', self._schedule_state) @property def name(self): @@ -105,7 +108,6 @@ class NeatoConnectedSwitch(ToggleEntity): """Turn the switch off.""" if self.type == SWITCH_TYPE_CLEAN: self.robot.pause_cleaning() - time.sleep(1) self.robot.send_to_base() elif self.type == SWITCH_TYPE_SCHEDULE: self.robot.disable_schedule()