Skip to content

Commit

Permalink
Task/vis nav (#150)
Browse files Browse the repository at this point in the history
* Vis Nav Fan Speeds and bug fix

* Adds handling for MACHINE_OFF state from Vis Nav vacuum
  • Loading branch information
dotvezz committed Apr 5, 2024
1 parent e61637f commit d723fba
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/dyson_local/binary_sensor.py
Expand Up @@ -37,7 +37,7 @@ async def async_setup_entry(
entities.extend(
[
DysonVacuumBatteryChargingSensor(device, name),
g(device, name),
Dyson360VisNavBinFullSensor(device, name),
]
)
if isinstance(device, Dyson360VisNav):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/dyson_local/manifest.json
Expand Up @@ -8,6 +8,6 @@
"import_executor": true,
"iot_class": "local_push",
"issue_tracker": "https://github.com/libdyson-wg/ha-dyson/issues",
"version": "1.4.0-rc2",
"version": "1.4.0-rc3",
"import_executor": true
}
33 changes: 33 additions & 0 deletions custom_components/dyson_local/vacuum.py
Expand Up @@ -4,8 +4,10 @@

from .vendor.libdyson import (
Dyson360Eye,
Dyson360VisNav,
VacuumEyePowerMode,
VacuumHeuristPowerMode,
VacuumVisNavPowerMode,
VacuumState,
)

Expand Down Expand Up @@ -68,6 +70,7 @@
VacuumState.MAPPING_NEEDS_CHARGE: "Mapping - Needs charging",
VacuumState.MAPPING_PAUSED: "Mapping - Paused",
VacuumState.MAPPING_RUNNING: "Mapping - Running",
VacuumState.MACHINE_OFF: "Off",
}

DYSON_STATES = {
Expand Down Expand Up @@ -103,6 +106,7 @@
VacuumState.MAPPING_NEEDS_CHARGE: STATE_RETURNING,
VacuumState.MAPPING_PAUSED: STATE_PAUSED,
VacuumState.MAPPING_RUNNING: STATE_CLEANING,
VacuumState.MACHINE_OFF: STATE_DOCKED,
}

EYE_POWER_MODE_ENUM_TO_STR = {
Expand All @@ -120,6 +124,15 @@
HEURIST_POWER_MODE_STR_TO_ENUM = {
value: key for key, value in HEURIST_POWER_MODE_ENUM_TO_STR.items()
}
VIS_NAV_POWER_MODE_ENUM_TO_STR = {
VacuumVisNavPowerMode.AUTO: "Auto",
VacuumVisNavPowerMode.QUICK: "Quick",
VacuumVisNavPowerMode.QUIET: "Quiet",
VacuumVisNavPowerMode.BOOST: "Boost",
}
VIS_NAV_POWER_MODE_STR_TO_ENUM = {
value: key for key, value in HEURIST_POWER_MODE_ENUM_TO_STR.items()
}

ATTR_POSITION = "position"

Expand All @@ -132,6 +145,8 @@ async def async_setup_entry(
name = config_entry.data[CONF_NAME]
if isinstance(device, Dyson360Eye):
entity = Dyson360EyeEntity(device, name)
elif isinstance(device, Dyson360VisNav): # Dyson360VisNav
entity = Dyson360VisNavEntity(device, name)
else: # Dyson360Heurist
entity = Dyson360HeuristEntity(device, name)
async_add_entities([entity])
Expand Down Expand Up @@ -230,3 +245,21 @@ def start(self) -> None:
def set_fan_speed(self, fan_speed: str, **kwargs) -> None:
"""Set fan speed."""
self._device.set_default_power_mode(HEURIST_POWER_MODE_STR_TO_ENUM[fan_speed])


class Dyson360VisNavEntity(Dyson360HeuristEntity):
"""Dyson 360 Vis Nav robot vacuum entity."""

@property
def fan_speed(self) -> str:
"""Return the fan speed of the vacuum cleaner."""
return VIS_NAV_POWER_MODE_ENUM_TO_STR[self._device.current_power_mode]

@property
def fan_speed_list(self) -> List[str]:
"""Get the list of available fan speed steps of the vacuum cleaner."""
return list(VIS_NAV_POWER_MODE_STR_TO_ENUM.keys())

def set_fan_speed(self, fan_speed: str, **kwargs) -> None:
"""Set fan speed."""
self._device.set_default_power_mode(VIS_NAV_POWER_MODE_STR_TO_ENUM[fan_speed])
2 changes: 2 additions & 0 deletions custom_components/dyson_local/vendor/libdyson/__init__.py
Expand Up @@ -28,6 +28,7 @@
from .const import MessageType # noqa: F401
from .const import VacuumEyePowerMode # noqa: F401
from .const import VacuumHeuristPowerMode # noqa: F401
from .const import VacuumVisNavPowerMode # noqa: F401
from .const import VacuumState # noqa: F401
from .const import WaterHardness # noqa: F401
from .discovery import DysonDiscovery # noqa: F401
Expand Down Expand Up @@ -83,3 +84,4 @@ def get_device(serial: str, credential: str, device_type: str) -> Optional[Dyson
}:
return DysonBigQuiet(serial, credential, device_type)
return None

10 changes: 10 additions & 0 deletions custom_components/dyson_local/vendor/libdyson/const.py
Expand Up @@ -113,6 +113,7 @@ class VacuumState(Enum):
MAPPING_NEEDS_CHARGE = "MAPPING_NEEDS_CHARGE"
MAPPING_PAUSED = "MAPPING_PAUSED"
MAPPING_RUNNING = "MAPPING_RUNNING"
MACHINE_OFF = "MACHINE_OFF"


class VacuumEyePowerMode(Enum):
Expand All @@ -130,6 +131,15 @@ class VacuumHeuristPowerMode(Enum):
MAX = "3"


class VacuumVisNavPowerMode(Enum):
"""Dyson 360 Heurist power mode."""

AUTO = "1"
QUICK = "2"
QUIET = "3"
BOOST = "4"


class CleaningType(Enum):
"""Vacuum cleaning type."""

Expand Down

0 comments on commit d723fba

Please sign in to comment.