1
0
mirror of https://github.com/natekspencer/hacs-oasis_mini.git synced 2025-12-06 18:44:14 -05:00

Add missing async_send_auto_clean_command to http client

This commit is contained in:
Nathan Spencer
2025-11-24 02:22:20 +00:00
parent 81668c595a
commit 2f28f7c4bd

View File

@@ -24,7 +24,7 @@ class OasisHttpClient(OasisClientProtocol):
def __init__(self, host: str, session: ClientSession | None = None) -> None: def __init__(self, host: str, session: ClientSession | None = None) -> None:
""" """
Initialize the HTTP client for a specific device host. Initialize the HTTP client for a specific device host.
Parameters: Parameters:
host (str): Hostname or IP address of the target device (used to build the base HTTP URL). host (str): Hostname or IP address of the target device (used to build the base HTTP URL).
session (ClientSession | None): Optional aiohttp ClientSession to reuse for requests. If omitted, a new session will be created and owned by this client. session (ClientSession | None): Optional aiohttp ClientSession to reuse for requests. If omitted, a new session will be created and owned by this client.
@@ -37,9 +37,9 @@ class OasisHttpClient(OasisClientProtocol):
def session(self) -> ClientSession: def session(self) -> ClientSession:
""" """
Ensure and return a usable aiohttp ClientSession for this client. Ensure and return a usable aiohttp ClientSession for this client.
If no session exists or the existing session is closed, a new ClientSession is created and the client records ownership of that session so it can be closed later. If no session exists or the existing session is closed, a new ClientSession is created and the client records ownership of that session so it can be closed later.
Returns: Returns:
An active aiohttp ClientSession instance associated with this client. An active aiohttp ClientSession instance associated with this client.
""" """
@@ -51,7 +51,7 @@ class OasisHttpClient(OasisClientProtocol):
async def async_close(self) -> None: async def async_close(self) -> None:
""" """
Close the client's owned HTTP session if one exists and is open. Close the client's owned HTTP session if one exists and is open.
Does nothing when there is no session, the session is already closed, or the client does not own the session. Does nothing when there is no session, the session is already closed, or the client does not own the session.
""" """
if self._session and not self._session.closed and self._owns_session: if self._session and not self._session.closed and self._owns_session:
@@ -62,7 +62,7 @@ class OasisHttpClient(OasisClientProtocol):
# These devices are plain HTTP, no TLS # These devices are plain HTTP, no TLS
""" """
Base HTTP URL for the target device. Base HTTP URL for the target device.
Returns: Returns:
The device base URL using plain HTTP (no TLS), including a trailing slash (e.g. "http://{host}/"). The device base URL using plain HTTP (no TLS), including a trailing slash (e.g. "http://{host}/").
""" """
@@ -71,12 +71,12 @@ class OasisHttpClient(OasisClientProtocol):
async def _async_request(self, method: str, url: str, **kwargs: Any) -> Any: async def _async_request(self, method: str, url: str, **kwargs: Any) -> Any:
""" """
Perform an HTTP request using the client's session and decode the response. Perform an HTTP request using the client's session and decode the response.
Logs the request URL and query parameters. If the response status is 200, returns the response body as a string for `text/plain`, the parsed JSON for `application/json`, or `None` for other content types. On non-200 responses, raises the client response error. Logs the request URL and query parameters. If the response status is 200, returns the response body as a string for `text/plain`, the parsed JSON for `application/json`, or `None` for other content types. On non-200 responses, raises the client response error.
Returns: Returns:
The response body as `str` for `text/plain`, the parsed JSON value for `application/json`, or `None` for other content types. The response body as `str` for `text/plain`, the parsed JSON value for `application/json`, or `None` for other content types.
Raises: Raises:
aiohttp.ClientResponseError: If the response status is not 200. aiohttp.ClientResponseError: If the response status is not 200.
""" """
@@ -102,10 +102,10 @@ class OasisHttpClient(OasisClientProtocol):
async def _async_get(self, **kwargs: Any) -> str | None: async def _async_get(self, **kwargs: Any) -> str | None:
""" """
Perform a GET request to the client's base URL using the provided request keyword arguments. Perform a GET request to the client's base URL using the provided request keyword arguments.
Parameters: Parameters:
**kwargs: Additional request keyword arguments forwarded to the underlying request (for example `params`, `headers`, `timeout`). **kwargs: Additional request keyword arguments forwarded to the underlying request (for example `params`, `headers`, `timeout`).
Returns: Returns:
`str` response text when the server responds with `text/plain`, `None` otherwise. `str` response text when the server responds with `text/plain`, `None` otherwise.
""" """
@@ -114,10 +114,10 @@ class OasisHttpClient(OasisClientProtocol):
async def _async_command(self, **kwargs: Any) -> str | None: async def _async_command(self, **kwargs: Any) -> str | None:
""" """
Execute a device command by issuing a GET request with the provided query parameters and return the parsed response. Execute a device command by issuing a GET request with the provided query parameters and return the parsed response.
Parameters: Parameters:
**kwargs: Mapping of query parameter names to values sent with the GET request. **kwargs: Mapping of query parameter names to values sent with the GET request.
Returns: Returns:
str | None: The device response as a string, a parsed JSON value, or None when the response has an unsupported content type. str | None: The device response as a string, a parsed JSON value, or None when the response has an unsupported content type.
""" """
@@ -128,7 +128,7 @@ class OasisHttpClient(OasisClientProtocol):
async def async_get_mac_address(self, device: OasisDevice) -> str | None: async def async_get_mac_address(self, device: OasisDevice) -> str | None:
""" """
Fetch the device MAC address using the device's HTTP GETMAC endpoint. Fetch the device MAC address using the device's HTTP GETMAC endpoint.
Returns: Returns:
str: The MAC address with surrounding whitespace removed, or `None` if it could not be retrieved. str: The MAC address with surrounding whitespace removed, or `None` if it could not be retrieved.
""" """
@@ -142,6 +142,22 @@ class OasisHttpClient(OasisClientProtocol):
) )
return None return None
async def async_send_auto_clean_command(
self,
device: OasisDevice,
auto_clean: bool,
) -> None:
"""
Enable or disable the device's auto-clean mode.
Parameters:
device (OasisDevice): The target Oasis device to send the command to.
auto_clean (bool): `True` to enable auto-clean mode, `False` to disable it.
"""
await self._async_command(
params={"WRIAUTOCLEAN": 1 if auto_clean else 0},
)
async def async_send_ball_speed_command( async def async_send_ball_speed_command(
self, self,
device: OasisDevice, device: OasisDevice,
@@ -149,7 +165,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Send a ball speed command to the specified device. Send a ball speed command to the specified device.
Parameters: Parameters:
device (OasisDevice): Target device for the command. device (OasisDevice): Target device for the command.
speed (int): Speed value to set for the device's ball mechanism. speed (int): Speed value to set for the device's ball mechanism.
@@ -166,7 +182,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Send an LED control command to the device. Send an LED control command to the device.
Parameters: Parameters:
device (OasisDevice): Target device to receive the command. device (OasisDevice): Target device to receive the command.
led_effect (str): Effect name or identifier to apply to the LEDs. led_effect (str): Effect name or identifier to apply to the LEDs.
@@ -180,7 +196,7 @@ class OasisHttpClient(OasisClientProtocol):
async def async_send_sleep_command(self, device: OasisDevice) -> None: async def async_send_sleep_command(self, device: OasisDevice) -> None:
""" """
Send a sleep command to the device. Send a sleep command to the device.
Requests the device to enter sleep mode. Requests the device to enter sleep mode.
""" """
await self._async_command(params={"CMDSLEEP": ""}) await self._async_command(params={"CMDSLEEP": ""})
@@ -193,7 +209,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Move a job in the device's playlist from one index to another. Move a job in the device's playlist from one index to another.
Parameters: Parameters:
device (OasisDevice): Target device whose job list will be modified. device (OasisDevice): Target device whose job list will be modified.
from_index (int): Zero-based index of the job to move. from_index (int): Zero-based index of the job to move.
@@ -208,7 +224,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Change the device's current track to the specified track index. Change the device's current track to the specified track index.
Parameters: Parameters:
index (int): Zero-based index of the track to select. index (int): Zero-based index of the track to select.
""" """
@@ -222,9 +238,9 @@ class OasisHttpClient(OasisClientProtocol):
# The old code passed the list directly; if the device expects CSV: # The old code passed the list directly; if the device expects CSV:
""" """
Send an "add joblist" command to the device with a list of track indices. Send an "add joblist" command to the device with a list of track indices.
The provided track indices are serialized as a comma-separated string and sent to the device using the `ADDJOBLIST` parameter. The provided track indices are serialized as a comma-separated string and sent to the device using the `ADDJOBLIST` parameter.
Parameters: Parameters:
device (OasisDevice): Target device to receive the command. device (OasisDevice): Target device to receive the command.
tracks (list[int]): Track indices to add; these are sent as a CSV string (e.g., [1,2,3] -> "1,2,3"). tracks (list[int]): Track indices to add; these are sent as a CSV string (e.g., [1,2,3] -> "1,2,3").
@@ -238,7 +254,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Set the device's playlist on the target device and optimistically update the local device state. Set the device's playlist on the target device and optimistically update the local device state.
Parameters: Parameters:
device (OasisDevice): Target device to receive the playlist command; its state will be updated optimistically. device (OasisDevice): Target device to receive the playlist command; its state will be updated optimistically.
playlist (list[int]): Ordered list of track indices to set as the device's playlist. playlist (list[int]): Ordered list of track indices to set as the device's playlist.
@@ -254,7 +270,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Set the device's playlist repeat flag. Set the device's playlist repeat flag.
Parameters: Parameters:
repeat (bool): `True` to enable playlist repeat, `False` to disable it. repeat (bool): `True` to enable playlist repeat, `False` to disable it.
""" """
@@ -267,7 +283,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Set the device's autoplay (wait-after) option. Set the device's autoplay (wait-after) option.
Parameters: Parameters:
device (OasisDevice): Target device whose autoplay option will be updated. device (OasisDevice): Target device whose autoplay option will be updated.
option (str): The value for the device's wait-after/autoplay setting as expected by the device firmware. option (str): The value for the device's wait-after/autoplay setting as expected by the device firmware.
@@ -281,7 +297,7 @@ class OasisHttpClient(OasisClientProtocol):
) -> None: ) -> None:
""" """
Send a firmware upgrade command to the specified device. Send a firmware upgrade command to the specified device.
Parameters: Parameters:
device (OasisDevice): Target device to receive the upgrade command. device (OasisDevice): Target device to receive the upgrade command.
beta (bool): If True, request the beta firmware; if False, request the stable firmware. beta (bool): If True, request the beta firmware; if False, request the stable firmware.
@@ -303,7 +319,7 @@ class OasisHttpClient(OasisClientProtocol):
async def async_send_stop_command(self, device: OasisDevice) -> None: async def async_send_stop_command(self, device: OasisDevice) -> None:
""" """
Sends the device stop command to halt playback or activity. Sends the device stop command to halt playback or activity.
Sends an HTTP command to request the device stop its current operation. Sends an HTTP command to request the device stop its current operation.
""" """
await self._async_command(params={"CMDSTOP": ""}) await self._async_command(params={"CMDSTOP": ""})
@@ -311,7 +327,7 @@ class OasisHttpClient(OasisClientProtocol):
async def async_send_reboot_command(self, device: OasisDevice) -> None: async def async_send_reboot_command(self, device: OasisDevice) -> None:
""" """
Send a reboot command to the device. Send a reboot command to the device.
Sends a reboot request to the target device using the CMDBOOT control parameter. Sends a reboot request to the target device using the CMDBOOT control parameter.
""" """
await self._async_command(params={"CMDBOOT": ""}) await self._async_command(params={"CMDBOOT": ""})
@@ -319,9 +335,9 @@ class OasisHttpClient(OasisClientProtocol):
async def async_get_status(self, device: OasisDevice) -> None: async def async_get_status(self, device: OasisDevice) -> None:
""" """
Retrieve the device status from the device and apply it to the given OasisDevice. Retrieve the device status from the device and apply it to the given OasisDevice.
If the device does not return a status, the device object is not modified. If the device does not return a status, the device object is not modified.
Parameters: Parameters:
device (OasisDevice): Device instance to update with the fetched status. device (OasisDevice): Device instance to update with the fetched status.
""" """
@@ -330,4 +346,4 @@ class OasisHttpClient(OasisClientProtocol):
return return
_LOGGER.debug("Status for %s: %s", device.serial_number, raw_status) _LOGGER.debug("Status for %s: %s", device.serial_number, raw_status)
device.update_from_status_string(raw_status) device.update_from_status_string(raw_status)