Skip to content

Commit

Permalink
Temporary Fix for #236.
Browse files Browse the repository at this point in the history
Adding action for vacuum go_to.

Signed-off-by: [email protected] <[email protected]>
  • Loading branch information
sca075 committed Nov 4, 2024
1 parent 6a1fea4 commit e393ee3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
16 changes: 15 additions & 1 deletion custom_components/mqtt_vacuum_camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CONF_VACUUM_CONNECTION_STRING,
CONF_VACUUM_IDENTIFIERS,
DOMAIN,
VACUUM,
)
from .coordinator import MQTTVacuumCoordinator
from .utils.files_operations import (
Expand Down Expand Up @@ -72,6 +73,18 @@ async def _reload_config(call: ServiceCall) -> None:
# Optionally, trigger other reinitialization steps if needed
hass.bus.async_fire(f"event_{DOMAIN}_reloaded", context=call.context)



async def vacuum_goto(call: ServiceCall) -> None:
"""Vacuum Go To Action"""
entity_id = call.data["entity_id"]
x = call.data["x"]
y = call.data["y"]
vacuum = hass.data[VACUUM].get(entity_id)
_LOGGER.debug(f"Test {vacuum} Service on Vacuum Domain")
hass.bus.async_fire(f"event_{vacuum}_go_to", context=call.context)


async def reset_trims(call: ServiceCall) -> None:
"""Action Reset Map Trims."""
_LOGGER.debug(f"Resetting trims for {DOMAIN}")
Expand All @@ -81,6 +94,7 @@ async def reset_trims(call: ServiceCall) -> None:

# Register Services
hass.services.async_register(DOMAIN, "reset_trims", reset_trims)
hass.services.async_register(VACUUM, "go_to", vacuum_goto)
if not hass.services.has_service(DOMAIN, SERVICE_RELOAD):
async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _reload_config)

Expand Down Expand Up @@ -150,7 +164,7 @@ async def async_unload_entry(
# Remove services
hass.services.async_remove(DOMAIN, "reset_trims")
hass.services.async_remove(DOMAIN, SERVICE_RELOAD)

hass.services.async_remove(VACUUM, "go_to")
return unload_ok


Expand Down
9 changes: 8 additions & 1 deletion custom_components/mqtt_vacuum_camera/const.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
"""Constants for the mqtt_vacuum_camera integration."""

"""Version v2024.11.0"""

from homeassistant.components.vacuum import DOMAIN as VACUUM_DOMAIN
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
"""Required in Config_Flow"""
PLATFORMS = ["camera"]
DOMAIN = "mqtt_vacuum_camera"
DEFAULT_NAME = "mqtt vacuum camera"

CAMERA = CAMERA_DOMAIN
VACUUM = VACUUM_DOMAIN
SENSOR = SENSOR_DOMAIN

CAMERA_STORAGE = "valetudo_camera"
DEFAULT_ROOMS = 1 # 15 is the maximum number of rooms.
ATTR_ROTATE = "rotate_image"
Expand Down
14 changes: 7 additions & 7 deletions custom_components/mqtt_vacuum_camera/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ class VacuumSensor(CoordinatorEntity, SensorEntity):
entity_description: VacuumSensorDescription

def __init__(
self,
coordinator: MQTTVacuumCoordinator,
description: VacuumSensorDescription,
sensor_type: str,
vacuum_identifier,
self,
coordinator: MQTTVacuumCoordinator,
description: VacuumSensorDescription,
sensor_type: str,
vacuum_identifier,
):
"""Initialize the vacuum sensor."""
super().__init__(coordinator)
Expand All @@ -198,7 +198,7 @@ async def async_will_remove_from_hass(self) -> None:
async def async_update(self):
"""Update the sensor's state."""
if self.coordinator.last_update_success:
await self._handle_coordinator_update()
await self.async_handle_coordinator_update()

@property
def should_poll(self) -> bool:
Expand All @@ -220,7 +220,7 @@ async def _extract_attributes(self):
}

@callback
async def _handle_coordinator_update(self):
async def async_handle_coordinator_update(self):
"""Fetch the latest state from the coordinator and update the sensor."""
data = self.coordinator.sensor_data
if data is None:
Expand Down
23 changes: 23 additions & 0 deletions custom_components/mqtt_vacuum_camera/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,26 @@ snapshot:
text:

reset_trims:

go_to:
name: Vacuum go to
description: Go to the specified coordinates
target:
entity:
integration: mqtt_vacuum_camera
domain: vacuum
fields:
x_coord:
name: X coordinate
description: x-coordinate
required: true
example: 26300
selector:
text:
y_coord:
name: Y coordinate
description: y-coordinate
required: true
example: 22500
selector:
text:

0 comments on commit e393ee3

Please sign in to comment.