Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ vars:
GOLANGCI_LINT_VERSION: v2.4.0
GOIMPORTS_VERSION: v0.29.0
DPRINT_VERSION: 0.48.0
EXAMPLE_VERSION: "0.5.1"
RUNNER_VERSION: "0.5.0"
EXAMPLE_VERSION: "0.6.0"
RUNNER_VERSION: "0.6.0"
VERSION: # if version is not passed we hack the semver by encoding the commit as pre-release
sh: echo "${VERSION:-0.0.0-$(git rev-parse --short HEAD)}"

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
# air_quality_monitoring API Reference

## Index

- Class `AQILevel`
- Class `AirQualityData`
- Class `AirQualityMonitoring`
- Class `AirQualityLookupError`

---

## `AQILevel` dataclass

```python
class AQILevel()
```

Data class to represent AQI levels.

### Attributes

- **min_value** (*int*): Minimum AQI value for the level.
- **max_value** (*int*): Maximum AQI value for the level.
- **description** (*str*): Description of the AQI level.
- **color** (*str*): Color associated with the AQI level in hex.


---

## `AirQualityData` dataclass

```python
class AirQualityData()
```

Data class to represent air quality data.

### Attributes

- **city** (*str*): Name of the city.
- **lat** (*float*): Latitude of the city.
- **lon** (*float*): Longitude of the city.
- **url** (*str*): URL for more information about the air quality data.
- **last_update** (*str*): Last update timestamp of the air quality data.
- **aqi** (*int*): Air Quality Index value.
- **dominantpol** (*str*): Dominant pollutant in the air.
- **iaqi** (*dict*): Individual AQI values for various pollutants.

### Methods

#### `pandas_dict()`

Return the data as a dictionary suitable for pandas DataFrame.


---

## `AirQualityMonitoring` class

```python
class AirQualityMonitoring(token: str)
```

Class to get air quality data from AQICN API.

### Parameters

- **token** (*str*): API token for AQICN service.

### Raises

- **ValueError**: If the token is not provided.

### Methods

#### `get_air_quality_by_city(city: str)`

Get air quality data by city name.

##### Parameters

- **city** (*str*): Name of the city.

##### Returns

- (*AirQualityData*): Air quality assembled data.

##### Raises

- **AirQualityLookupError**: If the API request fails.

#### `get_air_quality_by_coords(latitude: float, longitude: float)`

Get air quality data by coordinates.

##### Parameters

- **latitude** (*float*): Latitude.
- **longitude** (*float*): Longitude.

##### Returns

- (*AirQualityData*): Air quality assembled data.

##### Raises

- **AirQualityLookupError**: If the API request fails.

#### `get_air_quality_by_ip()`

Get air quality data by IP address.

##### Returns

- (*AirQualityData*): Air quality assembled data.

##### Raises

- **AirQualityLookupError**: If the API request fails.

#### `process(item: dict)`

Process the input dictionary to get air quality data.

##### Parameters

- **item** (*dict*): Input dictionary containing either 'city', 'latitude' and 'longitude', or 'ip'.

##### Returns

- (*dict*): Air quality data.

##### Raises

- **ValueError**: If the input dictionary is not valid.

#### `assemble_data(data: dict)`

Create a payload for the air quality data.

##### Parameters

- **data** (*dict*): Air quality data.

##### Returns

- (*dict*): Payload with relevant air quality information.

#### `map_aqi_level(aqi: int)`

Returns AQILevel class matching provided AQI.


---

## `AirQualityLookupError` class

```python
class AirQualityLookupError(message: str, status: str)
```

Custom exception for air quality lookup errors.

### Parameters

- **message** (*str*): Error message.
- **status** (*str*): Status of the error, defaults to None.

### Methods

#### `from_api_response(cls, data: dict)`

AirQualityLookupError error handling based on response provided by AQI API.

Documented errors:
- {"status": "error", "data": "Invalid key"}
- {"status": "error", "data": "Unknown station"}
- {"status": "error", "data": "Over quota"}
- {"status": "error", "data": "Invalid query"}
- {"status": "error", "data": "Too Many Requests"}
- {"status": "error", "data": "IP not allowed"}
- {"status": "error", "data": "Unknown error"}
- {"status": "error", "data": {"message": "..."}}

##### Parameters

- **data** (*dict*): Response data from the AQI API.

##### Returns

- (*AirQualityLookupError*): An instance of AirQualityLookupError with the error message and status.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# arduino_cloud API Reference

## Index

- Class `ArduinoCloud`

---

## `ArduinoCloud` class

```python
class ArduinoCloud(device_id: str, secret: str, server: str, port: int)
```

Arduino Cloud client for managing devices and data.

### Parameters

- **device_id** (*str*): The unique identifier for the device.
If omitted, uses ARDUINO_DEVICE_ID environment variable.
- **secret** (*str*): The password for Arduino Cloud authentication.
If omitted, uses ARDUINO_SECRET environment variable.
- **server** (*str*) (optional): The server address for Arduino Cloud (default: "iot.arduino.cc").
- **port** (*int*) (optional): The port to connect to the Arduino Cloud server (default: 8884).

### Raises

- **ValueError**: If either device_id or secret is not provided explicitly or via environment variable.

### Methods

#### `start()`

Start the Arduino IoT Cloud client.

#### `loop()`

Run a single iteration of the Arduino IoT Cloud client loop, processing commands and updating state.

#### `register(aiotobj: str | Any)`

Register a variable or object with the Arduino Cloud client.

##### Parameters

- **aiotobj** (*str | Any*): The variable name or object from which to derive the variable name to register.
- ****kwargs** (*Any*): Additional keyword arguments for registration.

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# audio_classification API Reference

## Index

- Class `AudioClassificationException`
- Class `AudioClassification`

---

## `AudioClassificationException` class

```python
class AudioClassificationException()
```

Custom exception for AudioClassification errors.


---

## `AudioClassification` class

```python
class AudioClassification(mic: Microphone, confidence: float)
```

AudioClassification module for detecting sounds and classifying audio using a specified model.

### Parameters

- **mic** (*Microphone*) (optional): Microphone instance used as the audio source. If None, a default Microphone will be initialized.
- **confidence** (*float*) (optional): Minimum confidence threshold (0.0–1.0) required
for a detection to be considered valid. Defaults to 0.8 (80%).

### Raises

- **ValueError**: If the model information cannot be retrieved, or if model parameters are missing or incomplete.

### Methods

#### `on_detect(class_name: str, callback: Callable[[], None])`

Register a callback function to be invoked when a specific class is detected.

##### Parameters

- **class_name** (*str*): The class to check for in the classification results.
Must match one of the classes defined in the loaded model.
- **callback** (*callable*): Function to execute when the class is detected.
The callback must take no arguments and return None.

##### Raises

- **TypeError**: If `callback` is not callable.
- **ValueError**: If `callback` accepts any argument.

#### `start()`

Start real-time audio classification.

Begins capturing audio from the configured microphone and
continuously classifies the incoming audio stream until stopped.

#### `stop()`

Stop real-time audio classification.

Terminates audio capture and releases any associated resources.

#### `classify_from_file(audio_path: str, confidence: float)`

Classify audio content from a WAV file.

Supported sample widths:
- 8-bit unsigned
- 16-bit signed
- 24-bit signed
- 32-bit signed

##### Parameters

- **audio_path** (*str*): Path to the `.wav` audio file to classify.
- **confidence** (*float*) (optional): Minimum confidence threshold (0.0–1.0) required
for a detection to be considered valid. Defaults to 0.8 (80%).

##### Returns

-: dict | None: A dictionary with keys:
- ``class_name`` (str): The detected sound class.
- ``confidence`` (float): Confidence score of the detection.
Returns None if no valid classification is found.

##### Raises

- **AudioClassificationException**: If the file cannot be found, read, or processed.
- **ValueError**: If the file uses an unsupported sample width.

Loading