mirror of
https://github.com/natekspencer/hacs-oasis_mini.git
synced 2025-12-06 18:44:14 -05:00
📝 Add docstrings to mqtt
Docstrings generation was requested by @natekspencer. * https://github.com/natekspencer/hacs-oasis_mini/pull/98#issuecomment-3568450288 The following files were modified: * `custom_components/oasis_mini/__init__.py` * `custom_components/oasis_mini/binary_sensor.py` * `custom_components/oasis_mini/button.py` * `custom_components/oasis_mini/config_flow.py` * `custom_components/oasis_mini/coordinator.py` * `custom_components/oasis_mini/entity.py` * `custom_components/oasis_mini/helpers.py` * `custom_components/oasis_mini/image.py` * `custom_components/oasis_mini/light.py` * `custom_components/oasis_mini/media_player.py` * `custom_components/oasis_mini/number.py` * `custom_components/oasis_mini/pyoasiscontrol/clients/cloud_client.py` * `custom_components/oasis_mini/pyoasiscontrol/clients/http_client.py` * `custom_components/oasis_mini/pyoasiscontrol/clients/mqtt_client.py` * `custom_components/oasis_mini/pyoasiscontrol/clients/transport.py` * `custom_components/oasis_mini/pyoasiscontrol/device.py` * `custom_components/oasis_mini/pyoasiscontrol/utils.py` * `custom_components/oasis_mini/select.py` * `custom_components/oasis_mini/sensor.py` * `custom_components/oasis_mini/switch.py` * `custom_components/oasis_mini/update.py` * `update_tracks.py`
This commit is contained in:
committed by
GitHub
parent
cf21a5d995
commit
4ef28fc741
37
custom_components/oasis_mini/helpers.py
Executable file → Normal file
37
custom_components/oasis_mini/helpers.py
Executable file → Normal file
@@ -19,13 +19,33 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def create_client(hass: HomeAssistant, data: dict[str, Any]) -> OasisCloudClient:
|
||||
"""Create a Oasis cloud client."""
|
||||
"""
|
||||
Create an Oasis cloud client configured with the Home Assistant HTTP session and access token.
|
||||
|
||||
Parameters:
|
||||
hass: Home Assistant instance used to obtain the shared HTTP client session.
|
||||
data: Configuration mapping; the function reads the `CONF_ACCESS_TOKEN` key for the cloud access token.
|
||||
|
||||
Returns:
|
||||
An `OasisCloudClient` initialized with the Home Assistant HTTP session and the configured access token.
|
||||
"""
|
||||
session = async_get_clientsession(hass)
|
||||
return OasisCloudClient(session=session, access_token=data.get(CONF_ACCESS_TOKEN))
|
||||
|
||||
|
||||
async def add_and_play_track(device: OasisDevice, track: int) -> None:
|
||||
"""Add and play a track."""
|
||||
"""
|
||||
Ensure a track is present in the device playlist, position it as the next item, select it, and start playback if necessary.
|
||||
|
||||
Adds the specified track to the device playlist if missing, waits up to 10 seconds for the track to appear, moves it to be the next item after the current playlist index if needed, selects that track, and starts playback when the device is not already playing.
|
||||
|
||||
Parameters:
|
||||
device (OasisDevice): The target Oasis device.
|
||||
track (int): The track id to add and play.
|
||||
|
||||
Raises:
|
||||
async_timeout.TimeoutError: If the operation does not complete within 10 seconds.
|
||||
"""
|
||||
async with async_timeout.timeout(10):
|
||||
if track not in device.playlist:
|
||||
await device.async_add_track_to_playlist(track)
|
||||
@@ -46,9 +66,14 @@ async def add_and_play_track(device: OasisDevice, track: int) -> None:
|
||||
|
||||
|
||||
def get_track_id(track: str) -> int | None:
|
||||
"""Get a track id.
|
||||
|
||||
`track` can be either an id or title
|
||||
"""
|
||||
Convert a track identifier or title to its integer track id.
|
||||
|
||||
Parameters:
|
||||
track: A track reference, either a numeric id as a string or a track title.
|
||||
|
||||
Returns:
|
||||
The integer track id if the input is a valid id or matches a known title, `None` if the input is invalid.
|
||||
"""
|
||||
track = track.lower().strip()
|
||||
if track not in map(str, TRACKS):
|
||||
@@ -60,4 +85,4 @@ def get_track_id(track: str) -> int | None:
|
||||
return int(track)
|
||||
except ValueError:
|
||||
_LOGGER.warning("Invalid track: %s", track)
|
||||
return None
|
||||
return None
|
||||
Reference in New Issue
Block a user