Skip to content

Commit

Permalink
feat: Add support for Vacuum entity
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerSelwyn committed Jan 19, 2025
1 parent 4c4cc8a commit 60ceffb
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 83 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Provides discovery & command support for:
|:----------------|:-------------------|:--------------------------|:----------|
| Binary Sensor | binary_sensor | | |
| Button | button | Press | |
| Climate | climate | Set HVAC Mode, Set Preset Mode, Set Temperature | |
| Cover | cover | Open, Close, Stop, Set Position, Set Tilt Position | |
| Climate | climate | Set HVAC Mode, Set Preset Mode, Set Temperature | |
| Cover | cover | Open, Close, Stop, Set Position, Set Tilt Position | |
| Device Tracker | device_tracker | | |
| Event | event | | |
| Fan | Fan | Turn On, Turn Off, Set Percentage, Set Preset Mode, Set Oscillating, Set Direction | |
| Fan | Fan | Turn On, Turn Off, Set Percentage, Set Preset Mode, Set Oscillating, Set Direction | |
| Image | image | | References master HA image |
| Input Boolean | switch | Turn On, Turn Off | |
| Input Button | button | Press | |
Expand All @@ -35,6 +35,7 @@ Provides discovery & command support for:
| Switch | switch | Turn On, Turn Off | |
| Text | text | Set Value | |
| Update | update | Install | Not able to install specific version or trigger backup |
| Vacuum | vacuum | Start, Stop, Pause, Return To Base, Locate, Clean Spot, Set Fan Speed, Send Custom Command | |

## [Buy Me A Beer 🍻](https://buymeacoffee.com/rogtp)
I work on this integration because I like things to work well for myself and others. Whilst I have now made significant changes to the integration, it would not be as it stands today without the initial creation by @koying. Please don't feel you are obligated to donate, but of course it is appreciated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from ..const import (
ATTR_MODE,
ATTR_SET,
COMMAND_SET,
CONF_CMD_T,
CONF_MAX,
CONF_MIN,
Expand All @@ -52,7 +52,7 @@ class ButtonDiscoveryEntity(DiscoveryEntity):
def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a button."""
del config[CONF_STAT_T]
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

async def _async_handle_message(self, msg):
"""Handle a message for a button."""
Expand All @@ -73,7 +73,7 @@ class NumberDiscoveryEntity(DiscoveryEntity):

def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a number."""
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)
config[CONF_MAX] = entity_info.attributes[ATTR_MAX]
config[CONF_MIN] = entity_info.attributes[ATTR_MIN]
config[CONF_MODE] = entity_info.attributes[ATTR_MODE]
Expand Down Expand Up @@ -101,7 +101,7 @@ def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a select."""
if ATTR_OPTIONS in entity_info.attributes:
config[CONF_OPS] = entity_info.attributes[ATTR_OPTIONS]
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

async def _async_handle_message(self, msg):
"""Handle a message for a select."""
Expand All @@ -127,7 +127,7 @@ def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a switch."""
config[CONF_PL_OFF] = STATE_OFF
config[CONF_PL_ON] = STATE_ON
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

async def _async_handle_message(self, msg):
"""Handle a message for a switch."""
Expand Down Expand Up @@ -156,7 +156,7 @@ class TextDiscoveryEntity(DiscoveryEntity):

def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a text."""
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)
config[CONF_MAX] = entity_info.attributes[ATTR_MAX]
config[CONF_MIN] = entity_info.attributes[ATTR_MIN]
config[CONF_MODE] = entity_info.attributes[ATTR_MODE]
Expand Down
20 changes: 9 additions & 11 deletions custom_components/mqtt_discoverystream_alt/classes/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
)

from ..const import (
ATTR_MODE_COMMAND,
ATTR_PRESET_COMMAND,
ATTR_TEMP_COMMAND,
COMMAND_MODE,
COMMAND_PRESET,
COMMAND_TEMPERATURE,
CONF_STAT_T,
)
from ..utils import (
Expand Down Expand Up @@ -72,9 +72,7 @@ def build_config(self, config, entity_info: EntityInfo):
config[CONF_CURRENT_TEMP_TOPIC] = build_topic(ATTR_CURRENT_TEMPERATURE)
config[CONF_TEMP_MAX] = entity_info.attributes[ATTR_MAX_TEMP]
config[CONF_TEMP_MIN] = entity_info.attributes[ATTR_MIN_TEMP]
add_config_command(
config, entity_info, CONF_MODE_COMMAND_TOPIC, ATTR_MODE_COMMAND
)
add_config_command(config, entity_info, CONF_MODE_COMMAND_TOPIC, COMMAND_MODE)
config[CONF_MODE_LIST] = entity_info.attributes[ATTR_HVAC_MODES]
config[CONF_MODE_STATE_TOPIC] = build_topic(ATTR_HVAC_MODE)
if ATTR_PRESET_MODES in entity_info.attributes:
Expand All @@ -86,12 +84,12 @@ def build_config(self, config, entity_info: EntityInfo):
config,
entity_info,
CONF_PRESET_MODE_COMMAND_TOPIC,
ATTR_PRESET_COMMAND,
COMMAND_PRESET,
)
if ATTR_PRESET_MODE in entity_info.attributes:
config[CONF_PRESET_MODE_STATE_TOPIC] = build_topic(ATTR_PRESET_MODE)
add_config_command(
config, entity_info, CONF_TEMP_COMMAND_TOPIC, ATTR_TEMP_COMMAND
config, entity_info, CONF_TEMP_COMMAND_TOPIC, COMMAND_TEMPERATURE
)
config[CONF_TEMP_STATE_TOPIC] = build_topic(ATTR_TEMPERATURE)
config[CONF_TEMP_STEP] = (
Expand Down Expand Up @@ -140,13 +138,13 @@ async def _async_handle_message(self, msg):
ATTR_ENTITY_ID: f"{domain}.{entity}",
}
service_name = None
if command == ATTR_MODE_COMMAND:
if command == COMMAND_MODE:
service_payload[ATTR_HVAC_MODE] = msg.payload
service_name = SERVICE_SET_HVAC_MODE
elif command == ATTR_PRESET_COMMAND:
elif command == COMMAND_PRESET:
service_payload[ATTR_PRESET_MODE] = msg.payload
service_name = SERVICE_SET_PRESET_MODE
elif command == ATTR_TEMP_COMMAND:
elif command == COMMAND_TEMPERATURE:
service_payload[ATTR_TEMPERATURE] = msg.payload
service_name = SERVICE_SET_TEMPERATURE

Expand Down
20 changes: 11 additions & 9 deletions custom_components/mqtt_discoverystream_alt/classes/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@

from ..const import (
ATTR_ATTRIBUTES,
ATTR_SET,
ATTR_SET_POSITION,
ATTR_SET_TILT,
COMMAND_SET,
COMMAND_SET_POSITION,
COMMAND_SET_TILT,
CONF_CMD_T,
CONF_SET_POS_T,
CONF_TILT_CMD_T,
Expand All @@ -57,7 +57,7 @@ class DiscoveryItem(DiscoveryEntity):

def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a cover."""
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

if ATTR_CURRENT_POSITION in entity_info.attributes or (
entity_info.attributes[ATTR_SUPPORTED_FEATURES]
Expand All @@ -72,13 +72,15 @@ def build_config(self, config, entity_info: EntityInfo):
entity_info.attributes[ATTR_SUPPORTED_FEATURES]
& CoverEntityFeature.SET_POSITION
):
add_config_command(config, entity_info, CONF_SET_POS_T, ATTR_SET_POSITION)
add_config_command(
config, entity_info, CONF_SET_POS_T, COMMAND_SET_POSITION
)

if (
entity_info.attributes[ATTR_SUPPORTED_FEATURES]
& CoverEntityFeature.SET_TILT_POSITION
):
add_config_command(config, entity_info, CONF_TILT_CMD_T, ATTR_SET_TILT)
add_config_command(config, entity_info, CONF_TILT_CMD_T, COMMAND_SET_TILT)

if ATTR_CURRENT_TILT_POSITION in entity_info.attributes:
config[CONF_TILT_STATUS_TOPIC] = build_topic(ATTR_ATTRIBUTES)
Expand All @@ -97,7 +99,7 @@ async def _async_handle_message(self, msg):
service_payload = {
ATTR_ENTITY_ID: f"{domain}.{entity}",
}
if command == ATTR_SET:
if command == COMMAND_SET:
if msg.payload == DEFAULT_PAYLOAD_OPEN:
await self._hass.services.async_call(
domain, SERVICE_OPEN_COVER, service_payload
Expand All @@ -112,12 +114,12 @@ async def _async_handle_message(self, msg):
)
else:
command_error(command, msg.payload, entity)
elif command == ATTR_SET_POSITION:
elif command == COMMAND_SET_POSITION:
service_payload[ATTR_POSITION] = msg.payload
await self._hass.services.async_call(
domain, SERVICE_SET_COVER_POSITION, service_payload
)
elif command == ATTR_SET_TILT:
elif command == COMMAND_SET_TILT:
service_payload[ATTR_TILT_POSITION] = msg.payload
await self._hass.services.async_call(
domain, SERVICE_SET_COVER_TILT_POSITION, service_payload
Expand Down
30 changes: 15 additions & 15 deletions custom_components/mqtt_discoverystream_alt/classes/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@

from ..const import (
ATTR_ATTRIBUTES,
ATTR_DIRECTION_COMMAND,
ATTR_OSCILLATION_COMMAND,
ATTR_PERCENTAGE_COMMAND,
ATTR_PRESET_COMMAND,
ATTR_SET,
COMMAND_DIRECTION,
COMMAND_OSCILLATION,
COMMAND_PERCENTAGE,
COMMAND_PRESET,
COMMAND_SET,
CONF_CMD_T,
)
from ..utils import (
Expand All @@ -74,7 +74,7 @@ class DiscoveryItem(DiscoveryEntity):

def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a fan."""
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

config[CONF_PAYLOAD_OFF] = STATE_OFF
config[CONF_PAYLOAD_ON] = STATE_ON
Expand All @@ -89,7 +89,7 @@ def build_config(self, config, entity_info: EntityInfo):
config,
entity_info,
CONF_DIRECTION_COMMAND_TOPIC,
ATTR_DIRECTION_COMMAND,
COMMAND_DIRECTION,
)

if ATTR_OSCILLATING in entity_info.attributes or (
Expand All @@ -103,7 +103,7 @@ def build_config(self, config, entity_info: EntityInfo):
config,
entity_info,
CONF_OSCILLATION_COMMAND_TOPIC,
ATTR_OSCILLATION_COMMAND,
COMMAND_OSCILLATION,
)
config[CONF_PAYLOAD_OSCILLATION_ON] = True
config[CONF_PAYLOAD_OSCILLATION_OFF] = False
Expand All @@ -120,7 +120,7 @@ def build_config(self, config, entity_info: EntityInfo):
config,
entity_info,
CONF_PRESET_MODE_COMMAND_TOPIC,
ATTR_PRESET_COMMAND,
COMMAND_PRESET,
)
config[CONF_PRESET_MODE_STATE_TOPIC] = build_topic(ATTR_ATTRIBUTES)
config[CONF_PRESET_MODE_VALUE_TEMPLATE] = (
Expand All @@ -136,7 +136,7 @@ def build_config(self, config, entity_info: EntityInfo):
config,
entity_info,
CONF_PERCENTAGE_COMMAND_TOPIC,
ATTR_PERCENTAGE_COMMAND,
COMMAND_PERCENTAGE,
)

if ATTR_PERCENTAGE_STEP in entity_info.attributes:
Expand Down Expand Up @@ -179,7 +179,7 @@ async def _async_handle_message(self, msg):
service_payload = {
ATTR_ENTITY_ID: entity_id,
}
if command == ATTR_SET:
if command == COMMAND_SET:
if msg.payload == STATE_ON:
await self._hass.services.async_call(
domain, SERVICE_TURN_ON, service_payload
Expand All @@ -191,17 +191,17 @@ async def _async_handle_message(self, msg):
else:
command_error(command, msg.payload, entity)

elif command == ATTR_DIRECTION_COMMAND:
elif command == COMMAND_DIRECTION:
service_payload[ATTR_DIRECTION] = msg.payload
await self._hass.services.async_call(
domain, SERVICE_SET_DIRECTION, service_payload
)
elif command == ATTR_OSCILLATION_COMMAND:
elif command == COMMAND_OSCILLATION:
service_payload[ATTR_OSCILLATING] = msg.payload
await self._hass.services.async_call(
domain, SERVICE_OSCILLATE, service_payload
)
elif command == ATTR_PERCENTAGE_COMMAND:
elif command == COMMAND_PERCENTAGE:
state_obj = self._hass.states.get(entity_id)
if pct_step := state_obj.attributes.get(ATTR_PERCENTAGE_STEP):
service_payload[ATTR_PERCENTAGE] = int(msg.payload) * pct_step
Expand All @@ -210,7 +210,7 @@ async def _async_handle_message(self, msg):
await self._hass.services.async_call(
domain, SERVICE_SET_PERCENTAGE, service_payload
)
elif command == ATTR_PRESET_COMMAND:
elif command == COMMAND_PRESET:
service_payload[ATTR_PRESET_MODE] = msg.payload
await self._hass.services.async_call(
domain, SERVICE_SET_PRESET_MODE, service_payload
Expand Down
6 changes: 3 additions & 3 deletions custom_components/mqtt_discoverystream_alt/classes/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
ATTR_JSON,
ATTR_R,
ATTR_S,
ATTR_SET_LIGHT,
ATTR_X,
ATTR_Y,
COMMAND_SET_LIGHT,
CONF_CMD_T,
CONF_JSON_ATTR_T,
STATE_CAPITAL_OFF,
Expand All @@ -64,7 +64,7 @@ class DiscoveryItem(DiscoveryEntity):
def build_config(self, config, entity_info: EntityInfo): # noqa: F821
"""Build the config for a light."""
del config[CONF_JSON_ATTR_T]
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET_LIGHT)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET_LIGHT)
config[CONF_SCHEMA] = ATTR_JSON

supported_features = get_supported_features(self._hass, entity_info.entity_id)
Expand Down Expand Up @@ -187,7 +187,7 @@ async def _async_handle_message(self, msg):
else:
_LOGGER.error(
'Invalid state for "%s" - payload: %s for %s',
ATTR_SET_LIGHT,
COMMAND_SET_LIGHT,
{msg.payload},
{entity},
)
4 changes: 2 additions & 2 deletions custom_components/mqtt_discoverystream_alt/classes/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_ON, STATE_ON, Platform

from ..const import ATTR_SET, CONF_CMD_T, CONF_PL_ON
from ..const import COMMAND_SET, CONF_CMD_T, CONF_PL_ON
from ..utils import EntityInfo, add_config_command, validate_message
from .base_entity import DiscoveryEntity

Expand All @@ -20,7 +20,7 @@ class DiscoveryItem(DiscoveryEntity):
def build_config(self, config, entity_info: EntityInfo):
"""Build the config for a scene."""
config[CONF_PL_ON] = STATE_ON
add_config_command(config, entity_info, CONF_CMD_T, ATTR_SET)
add_config_command(config, entity_info, CONF_CMD_T, COMMAND_SET)

async def _async_handle_message(self, msg):
"""Handle a message for a scene."""
Expand Down
6 changes: 3 additions & 3 deletions custom_components/mqtt_discoverystream_alt/classes/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Platform,
)

from ..const import ATTR_ATTRIBUTES, ATTR_INSTALL, ATTR_INSTALL_COMMAND, CONF_CMD_T
from ..const import ATTR_ATTRIBUTES, ATTR_INSTALL, COMMAND_INSTALL, CONF_CMD_T
from ..utils import (
EntityInfo,
add_config_command,
Expand All @@ -52,7 +52,7 @@ def build_config(self, config, entity_info: EntityInfo):
& UpdateEntityFeature.INSTALL
):
add_config_command(config, entity_info, CONF_CMD_T, ATTR_INSTALL)
config[CONF_PAYLOAD_INSTALL] = ATTR_INSTALL_COMMAND
config[CONF_PAYLOAD_INSTALL] = COMMAND_INSTALL
config[CONF_LATEST_VERSION_TOPIC] = build_topic(ATTR_ATTRIBUTES)
config[CONF_LATEST_VERSION_TEMPLATE] = (
"{{ value_json['" + ATTR_LATEST_VERSION + "'] }}"
Expand Down Expand Up @@ -93,7 +93,7 @@ async def _async_handle_message(self, msg):
service_payload = {
ATTR_ENTITY_ID: entity_id,
}
if command == ATTR_INSTALL_COMMAND:
if command == COMMAND_INSTALL:
await self._hass.services.async_call(
domain, SERVICE_INSTALL, service_payload
)
Loading

0 comments on commit 60ceffb

Please sign in to comment.