コード例 #1
0
def fanspeed(vac: miio.Vacuum, speed):
    """Query and adjust the fan speed."""
    if speed:
        click.echo("Setting fan speed to %s" % speed)
        vac.set_fan_speed(speed)
    else:
        click.echo("Current fan speed: %s" % vac.fan_speed())
コード例 #2
0
class XVCHelper(XVCHelperBase):
    """
    Helper class to abstract and simplify vacuum methods.
    """
    def __init__(self, ip: str, token: str) -> None:
        """
        Initialize a object of class XVCHelper.

        :param ip: IP address of the vacuum cleaner.
        :param token: Token of the vacuum cleaner.
        """
        self.__vacuum = Vacuum(ip=ip, token=token, start_id=1)

        # check connection
        for _ in range(3):
            try:
                self.__vacuum.do_discover()
                break
            except DeviceException:
                continue
        else:
            raise ConnectionError(
                'Cannot establish connection to Vacuum Cleaner at {}'.format(
                    ip))

    def status(self) -> Tuple[bool, str]:
        """
        Gets current status.

        :return: True on success, otherwise False.
        :return: Vacuum status.
        """
        vacuum_status = None
        try:
            vacuum_status = self.__vacuum.status().state
            result = True
        except DeviceException:
            result = False
        return result, vacuum_status

    def pause(self) -> bool:
        """
        Pause vacuum cleaner.

        :return: True on success, otherwise False.
        """
        result = self.__vacuum.pause()
        return result == XVCHelper.RESPONSE_SUCCEEDED

    def home(self) -> bool:
        """
        Stops cleaning and sends vacuum cleaner back to the dock.

        :return: True on success, otherwise False.
        """
        result = self.__vacuum.home()
        return result == XVCHelper.RESPONSE_SUCCEEDED

    def start_zone_cleaning(self, zones: List[XVCListable]) -> bool:
        """
        Start the zone cleanup.

        :param zones: Different zones to clean.
        :return: True on success, otherwise False.
        """
        self.pause()
        zones_list = [zone.get_list() for zone in zones]
        result = self.__vacuum.zoned_clean(zones_list)
        return result == XVCHelper.RESPONSE_SUCCEEDED

    def set_fan_level(self, fan_level: XVCHelperBase.FanLevel) -> bool:
        """
        Sets the fan level.

        :param fan_level: New fan level.
        :return: True on success, otherwise False.
        """
        result = self.__vacuum.set_fan_speed(fan_level.value)
        return result == XVCHelper.RESPONSE_SUCCEEDED