Skip to content

Commit

Permalink
feat: direct command service, refers to #197 and #194 (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
geertmeersman authored Sep 25, 2024
2 parents 33d43e3 + d73e00a commit fb942cb
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
17 changes: 17 additions & 0 deletions custom_components/robonect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
EVENT_ROBONECT_RESPONSE,
PLATFORMS,
SENSOR_GROUPS,
SERVICE_DIRECT,
SERVICE_DIRECT_SCHEMA,
SERVICE_JOB,
SERVICE_JOB_AFTER_VALUES,
SERVICE_JOB_CORRIDOR_VALUES,
Expand Down Expand Up @@ -122,6 +124,21 @@ async def timer(service: ServiceCall) -> bool:
DOMAIN, SERVICE_TIMER, timer, schema=SERVICE_TIMER_SCHEMA
)

async def direct(service: ServiceCall) -> bool:
"""Modify a direction."""
params = {}
try:
params |= {"left": service.data["left"]}
params |= {"right": service.data["right"]}
params |= {"timeout": service.data["timeout"]}
except ValueError as error:
raise RobonectException(error)
await async_send_command(hass, entry, "direct", params)

hass.services.async_register(
DOMAIN, SERVICE_DIRECT, direct, schema=SERVICE_DIRECT_SCHEMA
)

async def job(service: ServiceCall) -> bool:
"""Schedule a mowing job."""
params = {"mode": "job"}
Expand Down
23 changes: 23 additions & 0 deletions custom_components/robonect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
)
import voluptuous as vol


# Custom validator for degrees (allowing positive and negative integers)
def validate_degrees(value):
"""Validate degree value."""
return vol.Coerce(int)(value)


PLATFORMS: Final = [
Platform.BINARY_SENSOR,
Platform.SENSOR,
Expand Down Expand Up @@ -77,6 +84,7 @@
SERVICE_SLEEP = "sleep"
SERVICE_TIMER = "timer"
SERVICE_JOB = "job"
SERVICE_DIRECT = "direct"

CONF_ENTRY_ID = "entry_id"

Expand Down Expand Up @@ -139,6 +147,21 @@
}
)

SERVICE_DIRECT_SCHEMA = vol.Schema(
{
vol.Required(CONF_ENTITY_ID): cv.entity_id, # Validate entity ID
vol.Required(
"left"
): validate_degrees, # Validate left as an integer (positive or negative)
vol.Required(
"right"
): validate_degrees, # Validate right as an integer (positive or negative)
vol.Required("timeout"): vol.All(
cv.positive_int, vol.Range(max=5000)
), # Validate timeout as a positive integer with a max of 5000
}
)

SERVICE_MODE_SCHEMA = vol.Schema(
{
vol.Required("mode", default="auto"): vol.In(SERVICE_MODE_VALUES),
Expand Down
2 changes: 1 addition & 1 deletion custom_components/robonect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"automower/mqtt"
],
"requirements": [
"aiorobonect>=1.1.3",
"aiorobonect>=1.2.0",
"jsonpath"
],
"version": "v1.8.0"
Expand Down
42 changes: 42 additions & 0 deletions custom_components/robonect/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,45 @@ timer:
value: sa
- label: Sunday
value: su

direct:
name: Direct the mower
description: Direct a Robonect mower by setting the speed percentage for each wheel and a duration
fields:
entity_id:
name: Entity ID
description: Entity ID of the Robonect Vacuum
required: true
example: vacuum.automower_robonect
selector:
entity:
domain: vacuum
integration: robonect
left:
name: Left
description: "The percentage of speed on the left wheel. Can be positive or negative."
required: true
example: 50
selector:
number:
mode: box
unit_of_measurement: "%"
right:
name: Right
description: "The percentage of speed on the right wheel. Can be positive or negative."
required: true
example: 50
selector:
number:
mode: box
unit_of_measurement: "%"
timeout:
name: Timeout
description: "The timeout/duration in milliseconds."
required: true
example: 3000
selector:
number:
min: 1
mode: box
unit_of_measurement: ms

0 comments on commit fb942cb

Please sign in to comment.