8000 WIP: vacuum.xiaomi_miio: read dnd status properly instead of using impreci… by rytilahti · Pull Request #9733 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

WIP: vacuum.xiaomi_miio: read dnd status properly instead of using impreci… #9733

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

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 12 additions & 4 deletions homeassistant/components/vacuum/xiaomi_miio.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ATTR_ENTITY_ID, CONF_HOST, CONF_NAME, CONF_TOKEN, STATE_OFF, STATE_ON)
import homeassistant.helpers.config_validation as cv

REQUIREMENTS = ['python-mirobo==0.2.0']
REQUIREMENTS = ['python-miio==0.3.0']

_LOGGER = logging.getLogger(__name__)

Expand All @@ -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 @@ -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 @@ -196,11 +199,14 @@ def fan_speed_list(self):
@property
def device_state_attributes(self):
"""Return the specific state attributes of this vacuum cleaner."""

attrs = {}
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in python-miio v0.2.0, self.dnd_state is a list with one dict, I suppose with the new version that would be an object. If not, this won't work.

# Not working --> 'Cleaning mode':
# STATE_ON if self.vacuum_state.in_cleaning else STATE_OFF,
ATTR_CLEANING_TIME: int(
Expand All @@ -223,7 +229,6 @@ def device_state_attributes(self):
/ 3600)})
if self.vacuum_state.got_error:
attrs[ATTR_ERROR] = self.vacuum_state.error

return attrs

@property
Expand Down Expand Up @@ -366,7 +371,7 @@ def async_remote_control_move_step(self,
@asyncio.coroutine
def async_update(self):
"""Fetch state from the device."""
from mirobo import DeviceException
from miio import DeviceException
try:
state = yield from self.hass.async_add_job(self._vacuum.status)
_LOGGER.debug("Got new state from the vacuum: %s", state.data)
Expand All @@ -375,6 +380,9 @@ def async_update(self):
self._vacuum.consumable_status)
self.clean_history = yield from self.hass.async_add_job(
self._vacuum.clean_history)
self.dnd_state = yield from self.hass.async_add_job(
self._vacuum.dnd_status)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my last comment

self._is_on = state.is_on
self._available = True
except OSError as exc:
Expand Down
4 changes: 3 additions & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,11 @@ python-juicenet==0.0.5

# homeassistant.components.light.xiaomi_miio
# homeassistant.components.switch.xiaomi_miio
# homeassistant.components.vacuum.xiaomi_miio
python-mirobo==0.2.0

# homeassistant.components.vacuum.xiaomi_miio
python-miio==0.3.0

# homeassistant.components.media_player.mpd
python-mpd2==0.5.5

Expand Down
0