Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Refactor Neato botvac components as a vacuum #9946

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

Merged
merged 6 commits into from
Nov 3, 2017

Conversation

jabesq
Copy link
Contributor

@jabesq jabesq commented Oct 18, 2017

Description:

Refactor Neato botvac components as a vacuum
A switch is still use to enable/disable the schedule

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3674

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

def turn_on(self, **kwargs):
"""Turn the vacuum on and start cleaning."""
self.robot.start_cleaning()

Choose a reason for hiding this comment

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

blank line contains whitespace

def battery_level(self):
"""Return the battery level of the vacuum cleaner."""
return self._state['details']['charge']

Choose a reason for hiding this comment

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

blank line contains whitespace

def supported_features(self):
"""Flag vacuum cleaner robot features that are supported."""
return SUPPORT_NEATO

Choose a reason for hiding this comment

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

blank line contains whitespace

def icon(self):
"""Return the icon to use for device."""
return ICON

Choose a reason for hiding this comment

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

blank line contains whitespace

if (self.robot.state['action'] == 1 or
self.robot.state['action'] == 2 or
self.robot.state['action'] == 3 and
self.robot.state['state'] == 2):

Choose a reason for hiding this comment

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

visually indented line with same indent as next logical line

_LOGGER.debug("Adding vacuums %s", dev)
add_devices(dev)

class NeatoConnectedVacuum(VacuumDevice):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

SUPPORT_MAP, ATTR_STATUS,
ATTR_BATTERY_LEVEL,
ATTR_BATTERY_ICON, VacuumDevice)
from homeassistant.components.neato import (

Choose a reason for hiding this comment

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

'homeassistant.components.neato.NEATO_MAP_DATA' imported but unused

import logging
import requests
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.components.vacuum import (SUPPORT_BATTERY,

Choose a reason for hiding this comment

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

'homeassistant.components.vacuum.SUPPORT_FAN_SPEED' imported but unused

requests.exceptions.HTTPError) as ex:
_LOGGER.warning("Neato connection error: %s", ex)
self._state = None
self._mapdata = hass.data[NEATO_MAP_DATA]

Choose a reason for hiding this comment

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

undefined name 'NEATO_MAP_DATA'

ATTR_CLEAN_SUSP_COUNT = 'clean_suspension_count'
ATTR_CLEAN_SUSP_TIME = 'clean_suspension_time'

def setup_platform(hass, config, add_devices, discovery_info=None):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

@property
def is_on(self):
"""Return true if switch is on."""
if self._clean_state == STATE_ON:
Copy link
Member

Choose a reason for hiding this comment

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

return self._clean_state == STATE_ON

if self._state['state'] == 1:
self.robot.start_cleaning()
elif self._state['state'] == 2:
if ALERTS.get(self._state['error']) is None:
Copy link
Member

Choose a reason for hiding this comment

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

Connect this statement to the previous line with and.

self._status_state = None
self._clean_state = None
try:
self._state = self.robot.state
Copy link
Member

Choose a reason for hiding this comment

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

Initial this as None and call update instead during entity addition by adding True as second argument to add_devices.

if self._state['state'] == 1:
self.robot.start_cleaning()
elif self._state['state'] == 2 and\
ALERTS.get(self._state['error']) is None:

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

if self._state['state'] == 1:
self.robot.start_cleaning()
elif self._state['state'] == 2 and\
ALERTS.get(self._state['error']) is None:

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

self.clean_battery_end = None
self.clean_suspension_charge_count = None
self.clean_suspension_time = None
self.update()
Copy link
Member

Choose a reason for hiding this comment

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

Remove this and instead call add_devices in setup_platform like this:

add_devices(dev, True)

update will then be called during adding the devices to home assistant.

jabesq and others added 5 commits November 2, 2017 14:30
A switch is still use to enable/disable the schedule

Signed-off-by: Hugo D. (jabesq) <[email protected]>
Signed-off-by: Hugo D. (jabesq) <[email protected]>
@pvizeli pvizeli merged commit 1347c31 into home-assistant:dev Nov 3, 2017
@pvizeli
Copy link
Member

pvizeli commented Nov 3, 2017

As future improvment, you can remove the switch and make platform service calls for that function or maybe it make sense to add it to base vacumm

@balloob balloob mentioned this pull request Nov 17, 2017
@balloob
Copy link
Member

balloob commented Nov 18, 2017

This PR should have included a section for the breaking changes section of the release notes.

@home-assistant home-assistant locked and limited conversation to collaborators Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants