Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xiaomi Vacuum: remove deprecated calls #10839

Merged
merged 5 commits into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions homeassistant/components/vacuum/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

ATTR_CLEANING_TIME = 'cleaning_time'
ATTR_DO_NOT_DISTURB = 'do_not_disturb'
ATTR_DO_NOT_DISTURB_START = 'do_not_disturb_start'
ATTR_DO_NOT_DISTURB_END = 'do_not_disturb_end'
ATTR_MAIN_BRUSH_LEFT = 'main_brush_left'
ATTR_SIDE_BRUSH_LEFT = 'side_brush_left'
ATTR_FILTER_LEFT = 'filter_left'
Expand Down Expand Up @@ -87,7 +89,7 @@
@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
"""Set up the Xiaomi vacuum cleaner robot platform."""
from mirobo import Vacuum
from miio import Vacuum
if PLATFORM not in hass.data:
hass.data[PLATFORM] = {}

Expand Down Expand Up @@ -155,6 +157,7 @@ def __init__(self, name, vacuum):

self.consumable_state = None
self.clean_history = None
self.dnd_state = None

@property
def name(self):
Expand Down Expand Up @@ -200,7 +203,9 @@ def device_state_attributes(self):
if self.vacuum_state is not None:
attrs.update({
ATTR_DO_NOT_DISTURB:
STATE_ON if self.vacuum_state.dnd else STATE_OFF,
STATE_ON if self.dnd_state.enabled else STATE_OFF,
ATTR_DO_NOT_DISTURB_START: str(self.dnd_state.start),
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(
Expand All @@ -223,7 +228,6 @@ def device_state_attributes(self):
/ 3600)})
if self.vacuum_state.got_error:
attrs[ATTR_ERROR] = self.vacuum_state.error

return attrs

@property
Expand All @@ -244,11 +248,11 @@ def supported_features(self):
@asyncio.coroutine
def _try_command(self, mask_error, func, *args, **kwargs):
"""Call a vacuum command handling error messages."""
from mirobo import DeviceException, VacuumException
from miio import DeviceException
try:
yield from self.hass.async_add_job(partial(func, *args, **kwargs))
return True
except (DeviceException, VacuumException) as exc:
except DeviceException as exc:
_LOGGER.error(mask_error, exc)
return False

Expand Down Expand Up @@ -365,12 +369,15 @@ def async_remote_control_move_step(self,

def update(self):
"""Fetch state from the device."""
from mirobo import DeviceException
from miio import DeviceException
try:
state = self._vacuum.status()
self.vacuum_state = state

self.consumable_state = self._vacuum.consumable_status()
self.clean_history = self._vacuum.clean_history()
self.dnd_state = self._vacuum.dnd_status()

self._is_on = state.is_on
self._available = True
except OSError as exc:
Expand Down
Loading