pybroadlink
Control Broadlink devices with Python 3 using asyncio (single threaded with event loop). Currently supports the RM3 Smart Remote.
Usage
import sys
import logging
import traceback
from pybroadlink.broadlink_udp import BroadlinkRM3
import asyncio
import binascii
from base64 import b64decode
from pybroadlink import _LOGGER
async def testFake(n):
for i in range(n):
_LOGGER.debug("Counter is %d",i)
await asyncio.sleep(1)
async def discovery_test(*args):
rv = await BroadlinkUDP.discovery(local_ip_address=args[2],timeout=int(args[3]))
if rv:
_LOGGER.info("Discovery OK %s",rv)
else:
_LOGGER.warning("Discovery failed")
async def emit_test(*args):
import re
mo = re.search('^[a-fA-F0-9]+$', args[4])
if mo:
payload = binascii.unhexlify(args[4])
else:
payload = b64decode(args[4])
a = BroadlinkRM3((args[2],PORT),args[3])
rv = await a.emit_ir(payload,retry=1)
if rv:
_LOGGER.info("Emit OK %s",binascii.hexlify(rv[0]).decode('utf-8'))
else:
_LOGGER.warning("Emit failed")
a.destroy_remote()
async def learn_test(*args):
a = BroadlinkRM3((args[2],PORT),args[3])
rv = await a.enter_learning_mode()
if rv:
_LOGGER.info("Entered learning mode (%s): please press key",rv)
rv = await a.learn_ir_get(30)
if rv:
_LOGGER.info("Obtained %s",binascii.hexlify(rv[0]).decode('utf-8'))
else:
_LOGGER.warning("No key pressed")
else:
_LOGGER.warning("Enter learning failed")
a.destroy_remote()
_LOGGER.setLevel(logging.DEBUG)
handler = logging.StreamHandler(sys.stderr)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
_LOGGER.addHandler(handler)
loop = asyncio.get_event_loop()
try:
asyncio.ensure_future(testFake(150))
if sys.argv[1]=="learn":
loop.run_until_complete(learn_test(*sys.argv))
elif sys.argv[1]=="discovery":
loop.run_until_complete(discovery_test(*sys.argv))
else:
loop.run_until_complete(emit_test(*sys.argv))
except BaseException as ex:
_LOGGER.error("Test error %s",str(ex))
traceback.print_exc()
except:
_LOGGER.error("Test error")
traceback.print_exc()
finally:
loop.close()
Contributions
Pull requests are welcome. Possible areas for improvement:
- Additional Broadlink devices (switches).
Disclaimer
Not affiliated with Broadlink.
Metadata
Release files for pybroadlink 1.5
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 |
|---|---|---|---|---|
| pybroadlink-1.5.tar.gz | 8.7 kB | Without provenance | Details for pybroadlink-1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pybroadlink-1.5-py3-none-any.whl | Python 3 | none | any | Details for pybroadlink-1.5-py3-none-any.whl |
Total release size: 19.0 kB
Release files / pybroadlink-1.5.tar.gz
| Download URL | pybroadlink-1.5.tar.gz |
|---|---|
| Size | 8.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea3712597be0ae14daa446c3dee4e2099bef4c492866019f176d51478364e356
|
|
BLAKE2b-256 checksum How to use checksums |
c8740b77d383e87c540df09b136c4025258a0645759b9db050a49c74de35d934
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Release files / pybroadlink-1.5-py3-none-any.whl
| Download URL | pybroadlink-1.5-py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f406a977dfda6985819802b7163f5ca2b26d377e6e27899edad1f540d86f39f
|
|
BLAKE2b-256 checksum How to use checksums |
4555cd9a96218e76f9f04c67ca7e415204762ffa25d8050606d0d0aeab134833
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
|
Security for pybroadlink 1.5
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.