From 7a186109d7bc7741ddf2249c2ba6469027e8d27b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 29 Jan 2020 22:03:58 -0800 Subject: [PATCH 1/6] Remove cmp=True from APIVersion --- aioesphomeapi/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aioesphomeapi/model.py b/aioesphomeapi/model.py index daf9f48..7f7045f 100644 --- a/aioesphomeapi/model.py +++ b/aioesphomeapi/model.py @@ -10,7 +10,7 @@ import attr # for a field (False, 0, empty string, enum with value 0, ...) -@attr.s(cmp=True) +@attr.s class APIVersion: major = attr.ib(type=int, default=0) minor = attr.ib(type=int, default=0) From 0b95a9daedaa04e1da55fa13cb6c2be975c23e97 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 19 Jun 2020 13:22:13 +0200 Subject: [PATCH 2/6] Add license tag --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index a7d8890..469a84e 100644 --- a/setup.py +++ b/setup.py @@ -36,6 +36,7 @@ setup( download_url=DOWNLOAD_URL, author=PROJECT_AUTHOR, author_email=PROJECT_EMAIL, + license=PROJECT_LICENSE, packages=find_packages(), include_package_data=True, zip_safe=False, From 7966c9ad835dbb81d1691e8303c905a2263fc53f Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 19 Jun 2020 13:47:25 +0200 Subject: [PATCH 3/6] Add MANIFEST.in file --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..1aba38f --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include LICENSE From a9192898e416091bea256c85413f5fe163ec48e1 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 19 Jun 2020 21:35:41 +0200 Subject: [PATCH 4/6] Add README file --- README.rst | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 README.rst diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..09a3661 --- /dev/null +++ b/README.rst @@ -0,0 +1,114 @@ +aioesphomeapi +============= + +``aioesphomeapi`` allows you to interact with devices flashed with `ESPHome `_. + +Installation +------------ + +The module is available from the `Python Package Index `_. + +.. code:: bash + + $ pip3 install aioesphomeapi + +Usage +----- + +It's required that you enable the `Native API `_ component for the device. + +.. code:: yaml + + # Example configuration entry + api: + password: 'MyPassword' + +Check the output to get the local address of the device or use the ``name:``under ``esphome:`` from the device configuration. + +.. code:: bash + + [17:56:38][C][api:095]: API Server: + [17:56:38][C][api:096]: Address: api_test.local:6053 + + +The sample code below will connect to the device and retrieve details. + +.. code:: python + + import aioesphomeapi + import asyncio + + async def main(): + """Connect to an ESPHome device and get details.""" + loop = asyncio.get_running_loop() + + # Establish connection + api = aioesphomeapi.APIClient(loop, "api_test.local", 6053, "MyPassword") + await api.connect(login=True) + + # Get API version of the device's firmware + print(api.api_version) + + # Show device details + device_info = await api.device_info() + print(device_info) + + # List all entities of the device + entities = await api.list_entities_services() + print(entities) + + loop = asyncio.get_event_loop() + loop.run_until_complete(main()) + +Subscribe to state changes of an ESPHome device. + +.. code:: python + + import aioesphomeapi + import asyncio + + async def main(): + """Connect to an ESPHome device and wait for state changes.""" + loop = asyncio.get_running_loop() + cli = aioesphomeapi.APIClient(loop, "api_test.local", 6053, "MyPassword") + + await cli.connect(login=True) + + def change_callback(state): + """Print the state changes of the device..""" + print(state) + + # Subscribe to the state changes + await cli.subscribe_states(change_callback) + + loop = asyncio.get_event_loop() + try: + asyncio.ensure_future(main()) + loop.run_forever() + except KeyboardInterrupt: + pass + finally: + loop.close() + +Other examples: + +- `Camera `_ +- `Async print `_ +- `Simple print `_ + +Development +----------- + +For development is recommended to use a Python virtual environment (``venv``). + +.. code:: bash + + $ python3 -m venv . + $ source bin/activate + $ python3 setup.py develop + +License +------- + +``aioesphomeapi`` is licensed under MIT, for more details check LICENSE. From 5cce2d52051043d3583db6ad3c60e12d66ea7967 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Fri, 19 Jun 2020 21:42:32 +0200 Subject: [PATCH 5/6] Use content of README file --- setup.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index a7d8890..ddd0a0b 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,21 @@ #!/usr/bin/env python3 """aioesphomeapi setup script.""" +import os + from setuptools import find_packages, setup +here = os.path.abspath(os.path.dirname(__file__)) + +with open(os.path.join(here, 'README.rst'), encoding='utf-8') as readme_file: + long_description = readme_file.read() + + VERSION = '2.6.1' PROJECT_NAME = 'aioesphomeapi' PROJECT_PACKAGE_NAME = 'aioesphomeapi' PROJECT_LICENSE = 'MIT' PROJECT_AUTHOR = 'Otto Winter' -PROJECT_COPYRIGHT = ' 2019, Otto Winter' +PROJECT_COPYRIGHT = ' 2019-2020, Otto Winter' PROJECT_URL = 'https://esphome.io/' PROJECT_EMAIL = 'contact@otto-winter.com' @@ -36,6 +44,8 @@ setup( download_url=DOWNLOAD_URL, author=PROJECT_AUTHOR, author_email=PROJECT_EMAIL, + description='Python API for interacting with ESPHome devices.', + long_description=long_description, packages=find_packages(), include_package_data=True, zip_safe=False, From 43565e4a6d5607fea65b52ae820718819b727c21 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Wed, 1 Jul 2020 03:53:11 +0200 Subject: [PATCH 6/6] Fix URL representation (#12) --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 09a3661..0f6100e 100644 --- a/README.rst +++ b/README.rst @@ -94,7 +94,7 @@ Other examples: - `Camera `_ - `Async print `_ -- `Simple print `_ - `InfluxDB `_ Development