From 94edd2b17e1e81384f0be106dbd70e4cf6634b5b Mon Sep 17 00:00:00 2001 From: Pawel Szafer Date: Thu, 31 Jan 2019 09:26:03 +0100 Subject: [PATCH 1/3] fix state update when no cleaning is yet performed allow pause vacuum when returning to base --- .../components/xiaomi_miio/vacuum.py | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/vacuum.py b/homeassistant/components/xiaomi_miio/vacuum.py index 943b487857fbb..0518a17b612f1 100644 --- a/homeassistant/components/xiaomi_miio/vacuum.py +++ b/homeassistant/components/xiaomi_miio/vacuum.py @@ -227,27 +227,31 @@ def device_state_attributes(self): ATTR_DO_NOT_DISTURB_END: str(self.dnd_state.end), # Not working --> 'Cleaning mode': # STATE_ON if self.vacuum_state.in_cleaning else STATE_OFF, - ATTR_CLEANING_TIME: int( + ATTR_CLEANING_TIME: (int( self.vacuum_state.clean_time.total_seconds() - / 60), - ATTR_CLEANED_AREA: int(self.vacuum_state.clean_area), - ATTR_CLEANING_COUNT: int(self.clean_history.count), - ATTR_CLEANED_TOTAL_AREA: int(self.clean_history.total_area), - ATTR_CLEANING_TOTAL_TIME: int( + / 60) if self.vacuum_state.clean_time else 0), + ATTR_CLEANED_AREA: (int(self.vacuum_state.clean_area) if + self.vacuum_state.clean_area else 0), + ATTR_CLEANING_COUNT: (int(self.clean_history.count) if + self.clean_history.count else 0), + ATTR_CLEANED_TOTAL_AREA: (int(self.clean_history.total_area) if + self.clean_history.total_area + else 0), + ATTR_CLEANING_TOTAL_TIME: (int( self.clean_history.total_duration.total_seconds() - / 60), - ATTR_MAIN_BRUSH_LEFT: int( + / 60) if self.clean_history.total_duration else 0), + ATTR_MAIN_BRUSH_LEFT: (int( self.consumable_state.main_brush_left.total_seconds() - / 3600), - ATTR_SIDE_BRUSH_LEFT: int( + / 3600) if self.consumable_state.main_brush_left else 0), + ATTR_SIDE_BRUSH_LEFT: (int( self.consumable_state.side_brush_left.total_seconds() - / 3600), - ATTR_FILTER_LEFT: int( + / 3600) if self.consumable_state.side_brush_left else 0), + ATTR_FILTER_LEFT: (int( self.consumable_state.filter_left.total_seconds() - / 3600), - ATTR_SENSOR_DIRTY_LEFT: int( + / 3600) if self.consumable_state.filter_left else 0), + ATTR_SENSOR_DIRTY_LEFT: (int( self.consumable_state.sensor_dirty_left.total_seconds() - / 3600), + / 3600) if self.consumable_state.sensor_dirty_left else 0), ATTR_STATUS: str(self.vacuum_state.state) }) @@ -287,7 +291,7 @@ async def async_start(self): async def async_pause(self): """Pause the cleaning task.""" - if self.state == STATE_CLEANING: + if self.state == STATE_CLEANING or self.state == STATE_RETURNING: await self._try_command( "Unable to set start/pause: %s", self._vacuum.pause) From e25e33f5167d9379b8704b9721fce8e4d90bff6a Mon Sep 17 00:00:00 2001 From: Pawel Szafer Date: Thu, 31 Jan 2019 09:57:36 +0100 Subject: [PATCH 2/3] revert checking of atttribute updates. Will be fixed in upstream lib. --- .../components/xiaomi_miio/vacuum.py | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/vacuum.py b/homeassistant/components/xiaomi_miio/vacuum.py index 0518a17b612f1..f706a71693ac4 100644 --- a/homeassistant/components/xiaomi_miio/vacuum.py +++ b/homeassistant/components/xiaomi_miio/vacuum.py @@ -227,31 +227,27 @@ def device_state_attributes(self): ATTR_DO_NOT_DISTURB_END: str(self.dnd_state.end), # Not working --> 'Cleaning mode': # STATE_ON if self.vacuum_state.in_cleaning else STATE_OFF, - ATTR_CLEANING_TIME: (int( + ATTR_CLEANING_TIME: int( self.vacuum_state.clean_time.total_seconds() - / 60) if self.vacuum_state.clean_time else 0), - ATTR_CLEANED_AREA: (int(self.vacuum_state.clean_area) if - self.vacuum_state.clean_area else 0), - ATTR_CLEANING_COUNT: (int(self.clean_history.count) if - self.clean_history.count else 0), - ATTR_CLEANED_TOTAL_AREA: (int(self.clean_history.total_area) if - self.clean_history.total_area - else 0), - ATTR_CLEANING_TOTAL_TIME: (int( + / 60), + ATTR_CLEANED_AREA: int(self.vacuum_state.clean_area), + ATTR_CLEANING_COUNT: int(self.clean_history.count), + ATTR_CLEANED_TOTAL_AREA: int(self.clean_history.total_area), + ATTR_CLEANING_TOTAL_TIME: int( self.clean_history.total_duration.total_seconds() - / 60) if self.clean_history.total_duration else 0), - ATTR_MAIN_BRUSH_LEFT: (int( + / 60), + ATTR_MAIN_BRUSH_LEFT: int( self.consumable_state.main_brush_left.total_seconds() - / 3600) if self.consumable_state.main_brush_left else 0), - ATTR_SIDE_BRUSH_LEFT: (int( + / 3600), + ATTR_SIDE_BRUSH_LEFT: int( self.consumable_state.side_brush_left.total_seconds() - / 3600) if self.consumable_state.side_brush_left else 0), - ATTR_FILTER_LEFT: (int( + / 3600), + ATTR_FILTER_LEFT: int( self.consumable_state.filter_left.total_seconds() - / 3600) if self.consumable_state.filter_left else 0), - ATTR_SENSOR_DIRTY_LEFT: (int( + / 3600), + ATTR_SENSOR_DIRTY_LEFT: int( self.consumable_state.sensor_dirty_left.total_seconds() - / 3600) if self.consumable_state.sensor_dirty_left else 0), + / 3600), ATTR_STATUS: str(self.vacuum_state.state) }) From 839a2201e93caffbdb24a239b1ddd15bcbe8fc56 Mon Sep 17 00:00:00 2001 From: Pawel Szafer Date: Thu, 31 Jan 2019 11:55:44 +0100 Subject: [PATCH 3/3] remove unnecesarry if on pause_commadn --- homeassistant/components/xiaomi_miio/vacuum.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/xiaomi_miio/vacuum.py b/homeassistant/components/xiaomi_miio/vacuum.py index f706a71693ac4..a6613f7c3c36f 100644 --- a/homeassistant/components/xiaomi_miio/vacuum.py +++ b/homeassistant/components/xiaomi_miio/vacuum.py @@ -287,9 +287,8 @@ async def async_start(self): async def async_pause(self): """Pause the cleaning task.""" - if self.state == STATE_CLEANING or self.state == STATE_RETURNING: - await self._try_command( - "Unable to set start/pause: %s", self._vacuum.pause) + await self._try_command( + "Unable to set start/pause: %s", self._vacuum.pause) async def async_stop(self, **kwargs): """Stop the vacuum cleaner."""