Metadata-Version: 2.1
Name: lmcloud
Version: 1.0.0a0
Summary: A Python implementation of the new La Marzocco API
Home-page: https://github.com/zweckj/lmcloud
Author: Josef Zweck
Author-email: 24647999+zweckj@users.noreply.github.com
License: MIT
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: Implementation :: CPython
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx >=0.16.1
Requires-Dist: authlib >=0.15.5
Requires-Dist: websockets >=11.0.2
Requires-Dist: bleak >=0.20.2

# La Marzocco Client
This is a library to interface with La Marzocco's "new" Home machines (currently only the Micra).

It's in experimentals stages and meant mainly to connect to the Micra, as for the other IoT enabled machines you can use the [lmdirect](https://github.com/rccoleman/lmdirect) library.

# Libraries in this project
- `LaMarzoccoLocalClient` calls the new local API the Micra exposes, using the Bearer token from the customer cloud endpoint. However, this API currently only supports getting the config, and some status objects (like shottimer) over websockets, but does not support setting anything (to my knowledge). Local settings appear to only happen through [Bluetooth connections](#lmbluetooth). 
- `LaMarzoccoCloudClient` interacts with `gw-lmz.lamarzocco.com` to send commands. lmcloud can be initialized to only issue remote commands, or to initialize an instance of `lmlocalapi` for getting the current machine settings. This helps to avoid flooding the cloud API and is faster overall.
- `LaMarzoccoBluetoothClient` provides a bluetooth client to send settings to the machine via bluetooth

# Setup

## LaMarzoccoCloudClient


You need `username` and `password` which are the credentials you're using to sign into the La Marzocco Home app.


It is initialized like this
```python
cloud_client = await LaMarzoccoCloudClient.create(username, password)
```

## LaMarzoccoLocalClient
If you just want to run the local API you need the IP of your machine, the Port it is listening on (8081 by default), the Bearer token (`communicationKey`) used for local communication. 
You can obtain that key by inspecting a call to `https://cms.lamarzocco.io/api/customer`, while connected to `mitmproxy` (process above), or making a new (authenticated) call to that endpoint. 

Then you can init the class with 
```python
local_client = LaMarzoccoLocalClient(ip, local_token)
```


## LaMarzoccoBluetoothClient
Some commands, like turning the machine on and off are always sent through bluetooth whenever possible. The available bluetooth characteristics are described in [bluetooth_characteristics](docs/bluetooth_characteristics.md).
The class `LaMarzoccoBluetoothClient` discovers any bluetooth devices connects to it. Then we can send local bluetooth commands.

To use Bluetooth you can either init LMCloud with
```python
    bluetooth_client = await LaMarzoccoBluetoothClient.create(username, serial_number, local_token)
```

The local_token is the same token you need to initialize the local API, which you need to get from LM's cloud once. The serial number is your machine's serial number and the username is the email of your LaMarzocco account.


## Machine
Once you have any or all of the clients, you can initialize a machine object with
```python
machine = Machine.create(model, serial_number, name, cloud_client, local_client, bluetooth_client)
```

You can then use the machine object to send commands to the machine, or to get the current status of the machine. If you're running in cloud only mode, please be mindful with the requests to not flood the cloud API.

### Websockets
The local API initiates a websocket connection to
```
http://{IP}:8081/api/v1/streaming
```
The packets which are received on that WebSocket are documented in [websockets](docs/websockets.md)

If WebSockets are enabled the shot timer becomes available to use, however as long as the library is running in WebSocket mode, the App will no longer be able to connect.

To use WebSockets start the integration with
```python
await machine.websocket_connect(callback)
```
with an optional callback function that will be called whenever there have been updates for the machine from the websocket.
