Metadata-Version: 2.5
Name: somestuff-husqvarnaapi
Version: 0.1.1
Summary: Strictly typed client for the Husqvarna Automower Connect API: REST plus the WebSocket event stream, with OAuth2 client-credentials handling and pydantic models
Project-URL: Homepage, https://github.com/vroomfondel/somestuff
Project-URL: Repository, https://github.com/vroomfondel/somestuff
Project-URL: Issues, https://github.com/vroomfondel/somestuff/issues
Author-email: Henning Thieß <ht@xomox.cc>
License-File: LICENSE.md
Keywords: automower,husqvarna,oauth2,pydantic,rest,robotic-mower,websocket
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.13
Requires-Dist: httpx>=0.28
Requires-Dist: loguru>=0.7.3
Requires-Dist: pydantic>=2.5
Requires-Dist: websocket-client>=1.9
Description-Content-Type: text/markdown

# husqvarnaapi

Strictly typed client for the Husqvarna Automower Connect API (pydantic v2, httpx, websocket-client): OAuth2
client credentials, the REST API (`AutomowerClient`) and the real-time WebSocket event stream (`EventStream`).
Responses, commands and events are frozen pydantic models, unknown enum values are tolerated, the package ships
`py.typed` and passes `mypy --strict`.

```bash
pip install somestuff-husqvarnaapi
```

You need an application key and secret from the [Husqvarna developer portal](https://developer.husqvarnagroup.cloud/)
with the Automower Connect API connected.

## REST

```python
from somestuff.husqvarnaapi import AutomowerClient, ClientCredentialsTokenSource

tokens = ClientCredentialsTokenSource("<client-id>", "<client-secret>")
with AutomowerClient(tokens, api_key="<client-id>") as client:
    for mower in client.list_mowers():
        print(mower.id, mower.attributes.mower.activity)
```

Every call returns typed models (`MowerResource`, `Message`, `StayOutZones`, `CommandResult`, ...). Failed calls
raise subclasses of `ApiError` (`AuthenticationError`, `TransportError`, `UnexpectedResponseError`, ...).

| Area     | Methods                                                                                             |
|----------|-----------------------------------------------------------------------------------------------------|
| Read     | `list_mowers`, `get_mower`, `get_messages`, `get_stay_out_zones`, `list_work_areas`, `get_map`      |
| Actions  | `start`, `park`, `pause`, `resume_schedule`, `confirm_error`, `park_until_next_schedule`            |
| Settings | `set_cutting_height`, `set_headlight_mode`, `set_calendar`, `update_work_area`, `set_stay_out_zone` |
| Profiles | `list_profiles`, `create_profile`, `activate_profile`, `rename_current_profile`, `delete_profile`   |

## WebSocket events

```python
from somestuff.husqvarnaapi import ClientCredentialsTokenSource, EventStream, PositionEvent, StreamEvent

tokens = ClientCredentialsTokenSource("<client-id>", "<client-secret>")


def on_event(event: StreamEvent) -> None:
    match event:
        case PositionEvent():
            print(event.id, event.attributes.position)


EventStream(tokens, on_event=on_event).run_forever()
```

`EventStream` reconnects with exponential backoff and sends keep-alive pings; `stop()` ends `run_forever()`.
Use `parse_event(frame)` to turn a raw text frame into a typed event (unknown payloads become `UnknownEvent`
instead of raising) and `apply_event(state, event)` to fold a state event into the last known
`MowerAttributes`, which returns a new instance.

## Dependencies

| Package            | Used for                |
|--------------------|-------------------------|
| `pydantic` >= 2.5  | Models and validation   |
| `httpx`            | REST and token requests |
| `websocket-client` | Event stream            |
| `loguru`           | Logging                 |

Python 3.13 or newer.
