Ver Fonte

Fixed client behaviour when not allowed to register

Stan Janssen há 5 anos atrás
pai
commit
944db6569a
4 ficheiros alterados com 20 adições e 14 exclusões
  1. 4 1
      README.md
  2. 9 0
      pyopenadr/client.py
  3. 0 12
      pyopenadr/datatypes.py
  4. 7 1
      setup.py

+ 4 - 1
README.md

@@ -21,7 +21,7 @@ The `poll()` method will return a tuple of (message type, message payload) for y
 
 ### Auto Mode
 
-The client can handle the automatic polling and call your own functions or coroutines whenever there is an event or report that your application needs to see or needs to respond to. If you want to use automatic polling, set `auto_polling` = `True`, and also implement the `on_event` and `on_report` handlers. All handlers can be implemented as regular methods or coroutines; the coroutines having the advantage of not blocking the rest of the client (polling for example).
+The client can handle the automatic polling and call your own functions or coroutines whenever there is an event or report that your application needs to see or needs to respond to. If you want to use automatic polling, implement the `on_event` and `on_report` handlers, and call `client.run()` to start. All handlers can be implemented as regular methods or coroutines; the coroutines having the advantage of not blocking the rest of the client (polling for example).
 
 ### Handling events
 
@@ -79,6 +79,7 @@ OpenADR revolves around the VEN polling for messages from the VTN.
 
 ### Registration
 
+(To be added)
 
 
 ### Reporting
@@ -113,3 +114,5 @@ An OpenADR Event is built up of the following properties (more or less):
 
 
 ### Polling
+
+(To be added)

+ 9 - 0
pyopenadr/client.py

@@ -26,6 +26,10 @@ class OpenADRClient:
 
         self.create_party_registration()
 
+        if not self.ven_id:
+            print("No VEN ID received from the VTN, aborting registration.")
+            return
+
         # Set up automatic polling
         self.scheduler = AsyncIOScheduler()
         if self.poll_frequency.total_seconds() < 60:
@@ -74,6 +78,11 @@ class OpenADRClient:
             payload['ven_id'] = ven_id
         message = create_message('oadrCreatePartyRegistration', request_id=new_request_id(), **payload)
         response_type, response_payload = self._perform_request(service, message)
+        if response_payload['response']['response_code'] != 200:
+            status_code = response_payload['response']['response_code']
+            status_description = response_payload['response']['response_description']
+            print(f"Got error on Create Party Registration: {status_code} {status_description}")
+            return
         self.ven_id = response_payload['ven_id']
         self.poll_frequency = response_payload['requested_oadr_poll_freq']
         print(f"VEN is now registered with ID {self.ven_id}")

+ 0 - 12
pyopenadr/datatypes.py

@@ -1,12 +0,0 @@
-def event_descriptor(event_id, modification_number, modification_date_time, priority,
-                     market_context, created_date_time, event_status, test_event, vtn_comment):
-    data = {"event_id": event_id,
-            "modification_number": modification_number,
-            "modification_date_time": modification_date_time,
-            "priority": priority,
-            "market_context": market_context,
-            "created_date_time": created_date_time,
-            "event_status": event_status,
-            "test_event": test_event,
-            "vtn_comment": vtn_comment}
-    return {key: value for key, value in data.items() if value}

+ 7 - 1
setup.py

@@ -1,8 +1,14 @@
 from setuptools import setup
 
+with open("README.md", "r") as fh:
+    long_description = fh.read()
+
 setup(name="pyopenadr",
-      version="0.1.2",
+      version="0.1.4",
       description="Python library for dealing with OpenADR",
+      long_description=long_description,
+      long_description_content_type="text/markdown",
+      url="https://git.finetuned.nl/stan/pyopenadr",
       packages=['pyopenadr', 'pyopenadr.service'],
       include_package_data=True,
       install_requires=['xmltodict', 'responder', 'apscheduler'])