Metadata-Version: 2.5
Name: mausy5043-common
Version: 2.12.2
Summary: Common python functions
Project-URL: Homepage, https://codeberg.org/mausy5043/mausy5043-common
Project-URL: Bug Tracker, https://codeberg.org/mausy5043/mausy5043-common/issues
Author: Mausy5043
License-Expression: MIT
License-File: LICENSE
Keywords: private
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.13
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: pyarrow
Requires-Dist: python-homewizard-energy==10.2.0
Requires-Dist: sessypy==0.2.6
Requires-Dist: zeroconf==0.150.0
Description-Content-Type: text/markdown

![StaticBadge](https://img.shields.io/badge/support-ACTIVE-green)

[![License](https://img.shields.io/github/license/mausy5043/mausy5043-common)](LICENSE)
[![PyPI version](https://img.shields.io/pypi/v/mausy5043-common.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/mausy5043-common)
[![Supported Python versions](https://img.shields.io/pypi/pyversions/mausy5043-common.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/mausy5043-common)
[![PyPI downloads](https://img.shields.io/pypi/dm/mausy5043-common.svg)](https://pypistats.org/packages/mausy5043-common)
[![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-008800.svg)](https://github.com/astral-sh/ruff)
[![Linter: ruff](https://img.shields.io/badge/linter-ruff-008800.svg)](https://github.com/astral-sh/ruff)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/Mausy5043/mausy5043-common/devel.svg)](https://results.pre-commit.ci/latest/github/Mausy5043/mausy5043-common/devel)
[![Dependabot Updates](https://github.com/Mausy5043/mausy5043-common/actions/workflows/dependabot/dependabot-updates/badge.svg)](https://github.com/Mausy5043/mausy5043-common/actions/workflows/dependabot/dependabot-updates)

# mausy5043-common

A Python 3.12+ library providing common functions and classes for interacting with various devices and services, including HomeWizard energy monitors, Sessy home batteries, SQLite3 databases, and meteorological calculations.

## Requirements

- Python 3.12 or higher
- Dependencies: `numpy`, `pandas`, `pyarrow`, `python-homewizard-energy`, `sessypy`, `zeroconf`

**NOTE:** Before using the SQLite3 functions, ensure the SQLite3 server/client and default Python package are installed.

## Installation

```bash
python3 -m pip install mausy5043-common
```

## Modules

### `funfile`
File operation utilities.
- `cat(file_name: str) -> str`: Read a file into a variable.

### `funmeteo`
Meteorological calculations and conversions.
- `moisture(temperature, relative_humidity, pressure) -> np.ndarray`: Calculate moisture content of air (kg/m³).
- `wet_bulb_temperature(temperature, relative_humidity) -> float`: Calculate wet bulb temperature (°C).
- `saturation_vapor_pressure(temperature) -> ArrayLike`: Compute saturation vapor pressure (hPa).
- `dew_point_temperature(temperature, relative_humidity) -> ArrayLike`: Compute dew point temperature (°C).
- `relative_humidity_t2(T1, RH1, T2) -> ArrayLike`: Calculate new relative humidity after a temperature change.

### `libsqlite3`
SQLite3 database interaction.
- `SqlDatabase`: A class to interact with SQLite3 databases, supporting data queuing, insertion, and retrieval.

### `funzeroconf`
ZeroConf service discovery for network devices.
- `discover_devices(search_time: float = 60.0) -> dict`: Discover services on the network using Zeroconf.
- `get_ip(service: str, filtr: str = "", timeout: float = 60.0) -> list[str]`: Retrieve IP addresses for a given service.
- `prune_services(devices: dict, services: list[str]) -> dict`: Filter devices by supported services.
- `filter_properties(devices: dict, service: str, filtr: str) -> dict`: Filter devices by property contents.

### `funhomewizard`
HomeWizard energy monitor integration.
- `HomeWizard_V1`: Class for interacting with HomeWizard P1-dongle (API v1).
- `HomeWizard_V2`: Class for interacting with HomeWizard devices (API v2).
- `MyHomeWizard`: High-level class to discover and connect to HomeWizard devices, supporting both API versions.

### `funsessy`
Sessy home battery integration.
- `Sessy_v1`: Class for interacting with Sessy batteries (API v1).
- `MySessyBattery`: High-level class to connect and retrieve data from Sessy batteries.

## Usage Examples

### Meteorological Calculations
```python
from mausy5043_common.funmeteo import moisture, wet_bulb_temperature

# Calculate moisture content
temperature = 25.0  # °C
relative_humidity = 60.0  # %
pressure = 1013.25  # hPa
moisture_content = moisture(temperature, relative_humidity, pressure)

# Calculate wet bulb temperature
wet_bulb = wet_bulb_temperature(temperature, relative_humidity)
```

### SQLite3 Database
```python
from mausy5043_common.libsqlite3 import SqlDatabase

db = SqlDatabase(
    database="example.db",
    table="measurements",
    insert="INSERT INTO measurements VALUES (?, ?, ?)"
)
db.queue({"timestamp": "2024-01-01", "value": 42})
db.insert()
```

### HomeWizard Integration
```python
from mausy5043_common.funhomewizard import MyHomeWizard

hw = MyHomeWizard(serial="YOUR_SERIAL", token="YOUR_TOKEN", debug=True)
hw.connect()
measurement = hw.get_measurement()
```

### Sessy Battery Integration
```python
from mausy5043_common.funsessy import MySessyBattery

battery = MySessyBattery(ip="192.168.1.100", user="admin", token="password", debug=True)
battery.connect()
measurement = battery.get_measurement()
```

### ZeroConf Discovery
```python
from mausy5043_common.funzeroconf import discover_devices, get_ip

# Discover all devices
devices = discover_devices(search_time=30.0)

# Get IP addresses for HomeWizard devices
homewizard_ips = get_ip(service="_homewizard", filtr="HWE-P1")
```

## License
This project is licensed under the **MIT License** - see [LICENSE](LICENSE) for details.
