How to use pybotvac - 10 common examples

To help you get started, we’ve selected a few pybotvac examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github home-assistant / home-assistant / tests / components / neato / test_config_flow.py View on Github external
async def test_abort_on_invalid_credentials(hass):
    """Test when we have invalid credentials."""
    flow = init_config_flow(hass)

    with patch(
        "homeassistant.components.neato.config_flow.Account",
        side_effect=NeatoLoginException(),
    ):
        result = await flow.async_step_user(
            {
                CONF_USERNAME: USERNAME,
                CONF_PASSWORD: PASSWORD,
                CONF_VENDOR: VENDOR_NEATO,
            }
        )
        assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
        assert result["errors"] == {"base": "invalid_credentials"}

        result = await flow.async_step_import(
            {
                CONF_USERNAME: USERNAME,
                CONF_PASSWORD: PASSWORD,
                CONF_VENDOR: VENDOR_NEATO,
github home-assistant / home-assistant / tests / components / neato / test_init.py View on Github external
async def test_config_entries_not_in_sync_error(hass):
    """The config entry and configuration.yaml are not in sync, the new configuration is wrong."""
    MockConfigEntry(domain=NEATO_DOMAIN, data=VALID_CONFIG).add_to_hass(hass)

    assert hass.config_entries.async_entries(NEATO_DOMAIN)
    with patch(
        "homeassistant.components.neato.config_flow.Account",
        side_effect=NeatoLoginException(),
    ):
        assert not await async_setup_component(
            hass, NEATO_DOMAIN, {NEATO_DOMAIN: DIFFERENT_CONFIG}
        )
    await hass.async_block_till_done()

    entries = hass.config_entries.async_entries(NEATO_DOMAIN)
    assert entries
    assert entries[0].data[CONF_USERNAME] == USERNAME
    assert entries[0].data[CONF_PASSWORD] == PASSWORD
    assert entries[0].data[CONF_VENDOR] == VENDOR_NEATO
github stianaske / pybotvac / pybotvac / account.py View on Github external
if dest_path:
                image_url = url.rsplit('/', 2)[1] + '-' + url.rsplit('/', 1)[1]
                if file_name:
                    image_filename = file_name
                else:
                    image_filename = image_url.split('?')[0]

                dest = os.path.join(dest_path, image_filename)
                image.raise_for_status()
                with open(dest, 'wb') as data:
                    image.raw.decode_content = True
                    shutil.copyfileobj(image.raw, data)
        except (requests.exceptions.ConnectionError,
                requests.exceptions.HTTPError):
            raise NeatoRobotException("Unable to get robot map")

        return image.raw
github dshokouhi / hass-neato-custom-component / neato / __init__.py View on Github external
async def async_setup_entry(hass, entry):
    """Set up config entry."""
    hub = NeatoHub(hass, entry.data, Account)

    await hass.async_add_executor_job(hub.login)
    if not hub.logged_in:
        _LOGGER.debug("Failed to login to Neato API")
        return False

    try:
        await hass.async_add_executor_job(hub.update_robots)
    except NeatoRobotException:
        _LOGGER.debug("Failed to connect to Neato API")
        raise ConfigEntryNotReady

    hass.data[NEATO_LOGIN] = hub

    for component in ("camera", "vacuum", "switch", "sensor"):
        hass.async_add_job(
            hass.config_entries.async_forward_entry_setup(entry, component)
        )

    return True
github stianaske / pybotvac / pybotvac / robot.py View on Github external
"""
        Sends message to robot with data from parameter 'json'
        :param json: dict containing data to send
        :return: server response
        """

        try:
            response = requests.post(self._url,
                                    json=json,
                                    verify=self._vendor.cert_path,
                                    auth=Auth(self.serial, self.secret),
                                    headers=self._headers)
            response.raise_for_status()
        except (requests.exceptions.ConnectionError,
                requests.exceptions.HTTPError):
            raise NeatoRobotException("Unable to communicate with robot")

        return response
github home-assistant / home-assistant / homeassistant / components / neato / vacuum.py View on Github external
def return_to_base(self, **kwargs):
        """Set the vacuum cleaner to return to the dock."""
        try:
            if self._clean_state == STATE_CLEANING:
                self.robot.pause_cleaning()
            self._clean_state = STATE_RETURNING
            self.robot.send_to_base()
        except NeatoRobotException as ex:
            _LOGGER.error("Neato vacuum connection error: %s", ex)
github stianaske / pybotvac / pybotvac / account.py View on Github external
def refresh_robots(self):
        """
        Get information about robots connected to account.

        :return:
        """

        try:
            resp = requests.get(urljoin(self._endpoint, 'dashboard'),
                                headers=self._headers)
            resp.raise_for_status()
        except (requests.exceptions.ConnectionError,
                requests.exceptions.HTTPError):
            raise NeatoRobotException("Unable to refresh robots")

        for robot in resp.json()['robots']:
            if robot['mac_address'] is None:
                continue    # Ignore robots without mac-address

            try:
                self._robots.add(Robot(name=robot['name'],
                                       vendor=self._vendor,
                                       serial=robot['serial'],
                                       secret=robot['secret_key'],
                                       traits=robot['traits'],
                                       endpoint=robot['nucleo_url']))
            except NeatoRobotException:
                print ("Your '{}' robot is offline.".format(robot['name']))
                continue
github stianaske / pybotvac / pybotvac / account.py View on Github external
"""
        Get information about maps of the robots.

        :return:
        """

        try:
            for robot in self.robots:
                resp2 = (
                    requests.get(urljoin(self._endpoint, 'users/me/robots/{}/maps'.format(robot.serial)),
                                headers=self._headers))
                resp2.raise_for_status()
                self._maps.update({robot.serial: resp2.json()})
        except (requests.exceptions.ConnectionError,
                requests.exceptions.HTTPError):
            raise NeatoRobotException("Unable to refresh robot maps")
github home-assistant / home-assistant / homeassistant / components / neato / config_flow.py View on Github external
def try_login(username, password, vendor):
        """Try logging in to device and return any errors."""
        this_vendor = None
        if vendor == "vorwerk":
            this_vendor = Vorwerk()
        else:  # Neato
            this_vendor = Neato()

        try:
            Account(username, password, this_vendor)
        except NeatoLoginException:
            return "invalid_credentials"
        except NeatoRobotException:
            return "unexpected_error"

        return None
github home-assistant / home-assistant / homeassistant / components / neato / switch.py View on Github external
def turn_on(self, **kwargs):
        """Turn the switch on."""
        if self.type == SWITCH_TYPE_SCHEDULE:
            try:
                self.robot.enable_schedule()
            except NeatoRobotException as ex:
                _LOGGER.error("Neato switch connection error: %s", ex)

pybotvac

Python package for controlling Neato pybotvac Connected vacuum robot

MIT
Latest version published 7 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages