Skip to content

Commit

Permalink
feat: expose skip also as buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
vermut committed May 24, 2024
1 parent a619a11 commit 9fa3b63
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_components/openmower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Platform.LAWN_MOWER,
Platform.SENSOR,
Platform.BINARY_SENSOR,
Platform.BUTTON,
Platform.DEVICE_TRACKER,
]
_LOGGER = logging.getLogger(__name__)
Expand Down
61 changes: 61 additions & 0 deletions custom_components/openmower/button.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from __future__ import annotations

import logging

from homeassistant.components import mqtt
from homeassistant.components.button import ButtonEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PREFIX
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .entity import OpenMowerMqttEntity

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant,
entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
# Make sure MQTT integration is enabled and the client is available
if not await mqtt.async_wait_for_mqtt_client(hass):
_LOGGER.error("MQTT integration is not available")
return

prefix = entry.data[CONF_PREFIX]
async_add_entities(
[
OpenMowerSkipAreaButton("Skip Area", prefix, "DUMMY", None),
OpenMowerSkipPathButton("Skip Path", prefix, "DUMMY", None),
]
)


class OpenMowerMqttButtonEntity(OpenMowerMqttEntity, ButtonEntity):
async def async_added_to_hass(self) -> None:
pass

def _async_robot_state_received(self, msg: mqtt.ReceiveMessage) -> None:
pass

def _update_state(self, msg):
pass


class OpenMowerSkipAreaButton(OpenMowerMqttButtonEntity):
async def async_press(self) -> None:
await mqtt.async_publish(
self.hass,
self._mqtt_topic_prefix + "action",
"mower_logic:mowing/skip_area",
)


class OpenMowerSkipPathButton(OpenMowerMqttButtonEntity):
async def async_press(self) -> None:
await mqtt.async_publish(
self.hass,
self._mqtt_topic_prefix + "action",
"mower_logic:mowing/skip_path",
)

0 comments on commit 9fa3b63

Please sign in to comment.