bcontrolpy
bcontrolpy is an asynchronous Python client for the TQ-Systems EM300 energy meter, providing authentication, session management, and data retrieval via the MUM webservice.
Table of Contents
Installation
Install the latest release from PyPI:
pip install bcontrolpy
Or install the development version directly from GitHub:
pip install git+https://github.com/ITTV-tools/bcontrolpy.git
Quickstart
import asyncio
from bcontrolpy import BControl, AuthenticationError
async def main():
# Connect to EM300 meter on local network
async with BControl(ip="192.168.1.100", password="your_password") as bc:
try:
info = await bc.login()
print("Login successful:", info)
data = await bc.get_data()
print("Meter readings:", data)
except AuthenticationError:
print("Authentication failed: check your credentials")
asyncio.run(main())
Usage
Python API
| Method | Returns | Raises |
|---|---|---|
login() -> dict |
{'serial', 'app_version', 'authentication'} |
AuthenticationError, CookieRetrievalError, LoginValueError, CookieValueError |
get_data() -> dict |
Measurement values mapped to human-readable keys | NotAuthenticatedError, HTTP errors |
async_get_data() -> dict |
Alias of get_data() for coordinator usage |
Same as get_data() |
async_test_connection() -> None |
Validates credentials and connectivity | AuthenticationError, BControlCommunicationError |
close() -> None |
Example:
async with BControl(ip="192.168.1.100", password="your_password") as bc:
info = await bc.login()
values = await bc.get_data()
Home Assistant Integration
bcontrolpy is designed to work with Home Assistant's DataUpdateCoordinator pattern.
from datetime import timedelta
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from bcontrolpy import AuthenticationError, BControl, BControlCommunicationError
class BControlCoordinator(DataUpdateCoordinator):
def __init__(self, hass, entry):
super().__init__(
hass,
logger=LOGGER,
name="bcontrolpy",
update_interval=timedelta(seconds=30),
always_update=False,
)
self.client = BControl(
ip=entry.data["ip"],
password=entry.data["password"],
session=async_get_clientsession(hass),
)
async def _async_update_data(self):
try:
return await self.client.async_get_data()
except AuthenticationError as err:
raise ConfigEntryAuthFailed("Authentication failed") from err
except BControlCommunicationError as err:
raise UpdateFailed(f"Communication error: {err}") from err
This aligns with Home Assistant best practices:
- Reuse Home Assistant's shared
aiohttpsession. - Poll through a single
DataUpdateCoordinator. - Map auth errors to
ConfigEntryAuthFailedand transport errors toUpdateFailed.
Command Line Example
Run the provided example script:
python example/example.py --ip 192.168.1.100 --password "your_password"
This prints the login details and current meter readings.
Configuration
- Reuse
aiohttp.ClientSession: Pass an existing session (e.g., from Home Assistant) toBControlto take advantage of connection pooling. An external session will not be closed byBControl.close(). - Handle Exceptions: Catch
AuthenticationErrorto trigger re-authentication flows. - Customize Mapping: The OBIS code mapping resides in
key_mapping.pyand can be extended for additional measurements.
License
bcontrolpy is distributed under the Apache 2.0 License. See LICENSE for details.
Metadata
Release files for bcontrolpy 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bcontrolpy-0.0.7.tar.gz | 10.6 kB | Without provenance | Details for bcontrolpy-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bcontrolpy-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for bcontrolpy-0.0.7-py3-none-any.whl |
Total release size: 20.8 kB
Release files / bcontrolpy-0.0.7.tar.gz
| Download URL | bcontrolpy-0.0.7.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7911c7caa3c19702361ec07de759febf330b1eba9474614587ee98065ab810d4
|
|
BLAKE2b-256 checksum How to use checksums |
6311bb83b864311c09a6a3a7caa89e0aace721bc2828d1606377b327f059c114
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / bcontrolpy-0.0.7-py3-none-any.whl
| Download URL | bcontrolpy-0.0.7-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85a63ebf36bc15be1547569d90c7d4a4ee6e2c2e3a9bfb8956293844e4417fdb
|
|
BLAKE2b-256 checksum How to use checksums |
57861829a6956c2cbf5a3ae4e479d3efa75e23d6d4821ff2d546648b3e299a9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for bcontrolpy 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.