From eef070b142afb8e2dc3c29604e49ea31f76c4046 Mon Sep 17 00:00:00 2001 From: Guido Diener Date: Sun, 22 Apr 2018 10:50:11 +0200 Subject: [PATCH] Release 1.2.0.0 - total new with Websocket / Asyncio --- README.md | 67 +++++++++------ README.rst | 81 +++++++++++-------- async_server.py => example/async_server.py | 0 example/playwith.py | 77 ------------------ example/sample.py | 29 ------- example/sample_smart_button.py | 28 ------- .../instll_test_env.sh | 0 test_script.sh => scripts/test_script.sh | 4 +- setup.py | 2 +- 9 files changed, 91 insertions(+), 197 deletions(-) rename async_server.py => example/async_server.py (100%) delete mode 100644 example/playwith.py delete mode 100644 example/sample.py delete mode 100644 example/sample_smart_button.py rename instll_test_env.sh => scripts/instll_test_env.sh (100%) rename test_script.sh => scripts/test_script.sh (79%) diff --git a/README.md b/README.md index 52dbe2e..9b489f8 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,62 @@ -## ZeptrionAir +## Zeptrion Air This are the Classes to use the Zeptrion Air Lights etc. Zeptrion Air is a product from Feller. Zeptrion Air Panel are switches for Light, Blinds etc. A panel can have up to 8 switches. Each of this switches are called -Channels. +Button. -### 1) ZeptrionAir Hub +### 1) Hub The ZeptrionAir Hub handles all the ZeptrionAir Panel. The Hub is searching (browse) the panels with mDNS (zeroconf). If panels are found with mDNS the Hub is requesting the panels for all additional needed informations -### 2) ZeptrionAirPanel +### 2) Panel -ZeptrionAirPanel is the panel that can have up to 8 channels (Switches) +Panel is the panel that can have up to 8 buttons (Switches) -### 3) ZeptrionAirChannel +### 3) Button -The ZeptrionAirChannel is on of the channel that are hold on a Panel A -Channel is Switch for example for a Light or Blinds etc. With the -ZeptrionAirChannel Class you can read the status and control the device +The Button is on of the button that are hold on a Panel A +Button is Switch for example for a Light or Blinds etc. With the +Button Class you can read the status and control the device +Button Status is handled with websocket and is implemented with asyncio ### Python compatibility -Only working with Python 3 and above +Only working with Python 3.6 and above ### Sample to use it: ``` python -from zeptrionAirApi import ZeptrionAirHub - -hub = ZeptrionAirHub(3) #Initialize the ZeptrionAIrHub and browse for 5sec -allZeptrionPanels = hub.get_all_panels() #returns all found panels -allZeptrionChannels = hub.get_all_channels() #returns all found channels -allLightChannels = hub.get_all_light_channels() #returns all found channels that are Light switches -allGroups = hub.get_all_group() #returns all groups, that have been defined on the zeptrion app -for group in allGroups: - print("Channels in Group: " + str(group)) - print(hub.get_all_channels_by_group(group)) #returns all channles that are defined for that group - -channels = hub.get_all_channels_by_cat(1) #returns all found channels that are Light switches --> Category 1 -channel = channels[0] #pick the first light -channel.toggle_light() #toggle the light -channel.turn_on_light() #turn the light on -channel.turn_off_light() #turn the light off +import asyncio +import time +import json +from zeptrion_air_api import Hub + +async def do_close(hub): + """Close the System.""" + await hub.close() + +def press_info_handler(press_info): + """Handle if the button is pressed.""" + print(press_info) + +def found_new_panels(panel): + """Handle if a new Zeptrion Air Panel is found.""" + for button in panel.all_buttons: + if button: + button.listen_to(press_info_handler) + +if __name__ == '__main__': + """Init the main test.""" + loop = asyncio.get_event_loop() + za_hub = Hub(loop, found_new_panels) + try: + loop.run_forever() + except KeyboardInterrupt: + print("Unregistering...") + loop.run_until_complete(do_close(za_hub)) + finally: + loop.close() ``` diff --git a/README.rst b/README.rst index 4be3996..777dced 100644 --- a/README.rst +++ b/README.rst @@ -1,53 +1,66 @@ =========== ZeptrionAir =========== -This are the Classes to use the Zeptrion Air Lights etc. -Zeptrion Air is a product from Feller. -Zeptrion Air Panel are switches for Light, Blinds etc. -A panel can have up to 8 switches. -Each of this switches are called Channels. +This are the Classes to use the Zeptrion Air Lights etc. Zeptrion Air is +a product from Feller. Zeptrion Air Panel are switches for Light, Blinds +etc. A panel can have up to 8 switches. Each of this switches are called +Button. -1) ZeptrionAir Hub +1) Hub ------------------ -The ZeptrionAir Hub handles all the ZeptrionAir Panel. -The Hub is searching (browse) the panels with mDNS (zeroconf). -If panels are found with mDNS the Hub is requesting the panels -for all additional needed informations +The ZeptrionAir Hub handles all the ZeptrionAir Panel. The Hub is +searching (browse) the panels with mDNS (zeroconf). If panels are found +with mDNS the Hub is requesting the panels for all additional needed +informations -2) ZeptrionAirPanel +2) Panel ------------------- -ZeptrionAirPanel is the panel that can have up to 8 channels (Switches) +Panel is the panel that can have up to 8 buttons (Switches) -3) ZeptrionAirChannel +3) Button --------------------- -The ZeptrionAirChannel is on of the channel that are hold on a Panel -A Channel is Switch for example for a Light or Blinds etc. -With the ZeptrionAirChannel Class you can read the status -and control the device +The Button is on of the button that are hold on a Panel A +Button is Switch for example for a Light or Blinds etc. With the +Button Class you can read the status and control the device +Button Status is handled with websocket and is implemented with asyncio Python compatibility --------------------- -Only working with Python 3 and above +Only working with Python 3.6 and above Sample to use it: ----------------- .. code-block:: python - from zeptrionAirApi import ZeptrionAirHub - - hub = ZeptrionAirHub(3) #Initialize the ZeptrionAIrHub and browse for 5sec - allZeptrionPanels = hub.get_all_panels() #returns all found panels - allZeptrionChannels = hub.get_all_channels() #returns all found channels - allLightChannels = hub.get_all_light_channels() #returns all found channels that are Light switches - allGroups = hub.get_all_group() #returns all groups, that have been defined on the zeptrion app - for group in allGroups: - print("Channels in Group: " + str(group)) - print(hub.get_all_channels_by_group(group)) #returns all channles that are defined for that group - - channels = hub.get_all_channels_by_cat(1) #returns all found channels that are Light switches --> Category 1 - channel = channels[0] #pick the first light - channel.toggle_light() #toggle the light - channel.turn_on_light() #turn the light on - channel.turn_off_light() #turn the light off + import asyncio + import time + import json + from zeptrion_air_api import Hub + + async def do_close(hub): + """Close the System.""" + await hub.close() + + def press_info_handler(press_info): + """Handle if the button is pressed.""" + print(press_info) + + def found_new_panels(panel): + """Handle if a new Zeptrion Air Panel is found.""" + for button in panel.all_buttons: + if button: + button.listen_to(press_info_handler) + + if __name__ == '__main__': + """Init the main test.""" + loop = asyncio.get_event_loop() + za_hub = Hub(loop, found_new_panels) + try: + loop.run_forever() + except KeyboardInterrupt: + print("Unregistering...") + loop.run_until_complete(do_close(za_hub)) + finally: + loop.close() .. \ No newline at end of file diff --git a/async_server.py b/example/async_server.py similarity index 100% rename from async_server.py rename to example/async_server.py diff --git a/example/playwith.py b/example/playwith.py deleted file mode 100644 index 61c43aa..0000000 --- a/example/playwith.py +++ /dev/null @@ -1,77 +0,0 @@ -"""This is the test to play around.""" - -import requests -import xml.etree.ElementTree as ET -import time - -current_position = None - - -def get_state(): - """Get the state.""" - full_url = "http://192.168.86.114/zrap/chscan/ch1" - device_info_response = requests.get(full_url) - root = ET.fromstring(device_info_response.text) - return str(root[0][0].text) - - -def count_time_till_stop(): - """Count the time till stop.""" - start = time.time() - time.sleep(float(0.5)) - while(get_state() != '0'): - time.sleep(float(0.2)) - end = time.time() - print(end - start) - - -def go_to_position(postion): - """Go to position.""" - sleep_time = None - global current_position - if current_position is None: - payload = "cmd=close" - full_url = "http://192.168.86.114/zrap/chctrl/ch1" - requests.post(full_url, data=payload) - time.sleep(float(0.2)) - while(get_state() != '0'): - time.sleep(float(0.2)) - payload = "cmd=open" - full_url = "http://192.168.86.114/zrap/chctrl/ch1" - requests.post(full_url, data=payload) - sleep_time = float(55.3/100*postion) - elif postion < current_position: - payload = "cmd=open" - full_url = "http://192.168.86.114/zrap/chctrl/ch1" - requests.post(full_url, data=payload) - sleep_time = float(53.7/100*(current_position-postion)) - elif postion > current_position: - payload = "cmd=close" - full_url = "http://192.168.86.114/zrap/chctrl/ch1" - requests.post(full_url, data=payload) - sleep_time = float(55.3/100*(postion-current_position)) - time.sleep(sleep_time) - payload = "cmd=stop" - full_url = "http://192.168.86.114/zrap/chctrl/ch1" - requests.post(full_url, data=payload) - current_position = postion - - -device_info_response = requests.get("http://192.168.86.114/zrap/chdes") - -# payload = "cmd=open" -# full_url = "http://192.168.86.114/zrap/chctrl/ch1" -# device_info_response = requests.post(full_url, data=payload) -# print(device_info_response) - -go_to_position(50) -time.sleep(float(2)) -go_to_position(20) -time.sleep(float(2)) -go_to_position(90) -time.sleep(float(2)) -go_to_position(100) -time.sleep(float(2)) -go_to_position(10) -time.sleep(float(2)) -go_to_position(0) diff --git a/example/sample.py b/example/sample.py deleted file mode 100644 index b37ff20..0000000 --- a/example/sample.py +++ /dev/null @@ -1,29 +0,0 @@ -"""This is a Sample how to use the zeptrion Air Api.""" - -from zeptrionAirApi import ZeptrionAirHub - -# Initialize the ZeptrionAIrHub and browse for 5sec -hub = ZeptrionAirHub(3) -# returns all found panels -allZeptrionPanels = hub.get_all_panels() -# returns all found channels -allZeptrionChannels = hub.get_all_channels() -# returns all found channels that are Light switches -allLightChannels = hub.get_all_light_channels() -# returns all groups, that have been defined on the zeptrion app -allGroups = hub.get_all_group() -for group in allGroups: - output_to_return = "Channels in Group: " + str(group) - # returns all channles that are defined for that group - hub.get_all_channels_by_group(group) - -# returns all found channels that are Light switches --> Category 1 -channels = hub.get_all_channels_by_cat(1) -# pick the first light -channel = channels[0] -# toggle the light -channel.toggle_light() -# turn the light on -channel.turn_on_light() -# turn the light off -channel.turn_off_light() diff --git a/example/sample_smart_button.py b/example/sample_smart_button.py deleted file mode 100644 index 9441982..0000000 --- a/example/sample_smart_button.py +++ /dev/null @@ -1,28 +0,0 @@ -"""This is the test for Smart Button.""" - -from zeptrionAirApi import ZeptrionAirHub -import json - -hub = ZeptrionAirHub(3) # Initialize the ZeptrionAIrHub and browse for 5sec -allZeptrionPanels = hub.get_all_panels() # returns all found panels -# smartBtns = hub.get_all_smart_buttons() # returns all found smart buttons -# hub.set_all_smart_buttons_to_program_mode() - -prog_elements = {} -prog_elements['prog_req_type'] = 'POST' -prog_elements['prog_url'] = '192.168.86.167' -prog_elements['prog_path'] = '/test' -prog_elements['prog_typ'] = 'application/json' -prog_elements['prog_header_field'] = '' -prog_elements['prog_port'] = '1880' -body = {} -body['state'] = 20 -body['attributes'] = {} -body['attributes']['unit_of_measurement'] = '°C' -body['attributes']['friendly_name'] = 'Bathroom Temperature' -prog_elements['prog_body'] = json.dumps(body) - -# result = hub.programm_smart_btn(prog_elements) -# print(result) -result = hub.get_panels_with_smart_button() -print(result) diff --git a/instll_test_env.sh b/scripts/instll_test_env.sh similarity index 100% rename from instll_test_env.sh rename to scripts/instll_test_env.sh diff --git a/test_script.sh b/scripts/test_script.sh similarity index 79% rename from test_script.sh rename to scripts/test_script.sh index a04ce15..a89af2f 100755 --- a/test_script.sh +++ b/scripts/test_script.sh @@ -13,7 +13,7 @@ echo " ### pycodestyle --first test - "+$1 pycodestyle --first $1 echo " ### pylint 3.6 test - "+$1 -# /Users/diener/Library/Python/3.6/bin/pylint ./zeptrion_air_api +# /Users/diener/Library/Python/3.6/bin/pylint ../zeptrion_air_api pylint ./zeptrion_air_api echo " ### python3 setup.py test" @@ -22,4 +22,4 @@ python3 setup.py test echo " ### pytest and coverage" py.test --cov ./zeptrionAirApi -# py.test -s --cov-report html --cov ./zeptrionAirApi \ No newline at end of file +# py.test -s --cov-report html --cov ../zeptrionAirApi \ No newline at end of file diff --git a/setup.py b/setup.py index e7c07f9..ee7dcbc 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ setup( name='zeptrionAirApi', packages=find_packages(exclude=['contrib', 'docs', 'tests']), - version='1.1.0.1', + version='1.2.0.0', description="This are the Classes to use the Zeptrion Air Lights etc.", long_description=long_description, author="Swissglider",