pyemoncms 0.0.3__tar.gz → 0.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyemoncms
3
+ Version: 0.0.5
4
+ Summary: A python library to interrogate emoncms API
5
+ Home-page: https://github.com/Open-Building-Management/pyemoncms
6
+ Author: Alexandre CUER
7
+ Author-email: alexandre.cuer@wanadoo.fr
8
+ Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: aiohttp
16
+
17
+ # pyemoncms
18
+ python library for emoncms API
19
+
20
+ rely on [aiohttp](https://github.com/aio-libs/aiohttp)
21
+
22
+ to install : `pip3 install pyemoncms`
23
+
24
+ how to use :
25
+
26
+ ```
27
+ import logging
28
+ import asyncio
29
+ from pyemoncms import EmoncmsClient
30
+
31
+ key = "your32bitsAPIkey"
32
+ url = "http://url:8081"
33
+ client = EmoncmsClient(url, key, request_timeout=1)
34
+ client.logger.setLevel("DEBUG")
35
+
36
+ async def get_path(path):
37
+ print(await client.async_request(path))
38
+
39
+ async def list_feeds():
40
+ print(await client.async_list_feeds())
41
+
42
+ async def get_feed_fields(feed_id):
43
+ print(await client.async_get_feed_fields(feed_id))
44
+
45
+
46
+ loop = asyncio.get_event_loop()
47
+ loop.create_task(get_path("/feed/list.json"))
48
+ loop.create_task(get_path("/user/getuuid.json"))
49
+ loop.create_task(list_feeds())
50
+ loop.create_task(get_feed_fields(1))
51
+ loop.run_forever()
52
+ ```
@@ -0,0 +1,36 @@
1
+ # pyemoncms
2
+ python library for emoncms API
3
+
4
+ rely on [aiohttp](https://github.com/aio-libs/aiohttp)
5
+
6
+ to install : `pip3 install pyemoncms`
7
+
8
+ how to use :
9
+
10
+ ```
11
+ import logging
12
+ import asyncio
13
+ from pyemoncms import EmoncmsClient
14
+
15
+ key = "your32bitsAPIkey"
16
+ url = "http://url:8081"
17
+ client = EmoncmsClient(url, key, request_timeout=1)
18
+ client.logger.setLevel("DEBUG")
19
+
20
+ async def get_path(path):
21
+ print(await client.async_request(path))
22
+
23
+ async def list_feeds():
24
+ print(await client.async_list_feeds())
25
+
26
+ async def get_feed_fields(feed_id):
27
+ print(await client.async_get_feed_fields(feed_id))
28
+
29
+
30
+ loop = asyncio.get_event_loop()
31
+ loop.create_task(get_path("/feed/list.json"))
32
+ loop.create_task(get_path("/user/getuuid.json"))
33
+ loop.create_task(list_feeds())
34
+ loop.create_task(get_feed_fields(1))
35
+ loop.run_forever()
36
+ ```
@@ -1,4 +1,16 @@
1
- """Emoncms client."""
1
+ """Emoncms client.
2
+
3
+ emoncms feed module :
4
+ an inexisting json route responds by {success: false, message : "Feed does not exist"}
5
+ examples of inexisting json routes :
6
+ - feed/aget.json?id=200 if there is no feed number 200
7
+ - feed/basket.json
8
+ the feed/list.json always returns an array of json objects, which can be empty if there is no feed
9
+
10
+ emoncms user module
11
+ an inexisting json route responds by false which is not a json object
12
+ so there is a type error if you search for a key in the response
13
+ """
2
14
 
3
15
  import asyncio
4
16
  import logging
@@ -6,11 +18,6 @@ from typing import Any
6
18
 
7
19
  import aiohttp
8
20
 
9
- client_exceptions = (
10
- aiohttp.ClientError,
11
- asyncio.TimeoutError,
12
- )
13
-
14
21
  HTTP_STATUS = {
15
22
  400: "invalid request",
16
23
  401: "unauthorized access",
@@ -50,8 +57,13 @@ class EmoncmsClient:
50
57
  response = await session.get(
51
58
  path, timeout=self.request_timeout, params=params
52
59
  )
53
- except client_exceptions as e:
54
- message = f"exception {e}"
60
+ except aiohttp.ClientError as er:
61
+ message = f"client error : {er}"
62
+ data[MESSAGE_KEY] = message
63
+ self.logger.error(message)
64
+ return data
65
+ except asyncio.TimeoutError:
66
+ message = "time out error"
55
67
  data[MESSAGE_KEY] = message
56
68
  self.logger.error(message)
57
69
  return data
@@ -59,8 +71,11 @@ class EmoncmsClient:
59
71
  data[SUCCESS_KEY] = True
60
72
  json_response = await response.json()
61
73
  data[MESSAGE_KEY] = json_response
62
- if MESSAGE_KEY in json_response:
63
- data[MESSAGE_KEY] = json_response[MESSAGE_KEY]
74
+ try:
75
+ if MESSAGE_KEY in json_response:
76
+ data[MESSAGE_KEY] = json_response[MESSAGE_KEY]
77
+ except TypeError:
78
+ data[SUCCESS_KEY] = False
64
79
  else:
65
80
  message = f"error {response.status}"
66
81
  if response.status in HTTP_STATUS:
@@ -76,6 +91,10 @@ class EmoncmsClient:
76
91
  """
77
92
  uuid_data = await self.async_request("/user/getuuid.json")
78
93
  feed_data = await self.async_request("/feed/list.json")
94
+ if not uuid_data[SUCCESS_KEY]:
95
+ message = "no uuid available"
96
+ message = f"{message} - migrate your emoncms sensor to a newer version"
97
+ self.logger.warning(message)
79
98
  if feed_data[SUCCESS_KEY] and uuid_data[SUCCESS_KEY]:
80
99
  for feed in feed_data[MESSAGE_KEY]:
81
100
  feed["uuid"] = f"{uuid_data[MESSAGE_KEY]}_{feed['id']}"
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyemoncms
3
+ Version: 0.0.5
4
+ Summary: A python library to interrogate emoncms API
5
+ Home-page: https://github.com/Open-Building-Management/pyemoncms
6
+ Author: Alexandre CUER
7
+ Author-email: alexandre.cuer@wanadoo.fr
8
+ Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: aiohttp
16
+
17
+ # pyemoncms
18
+ python library for emoncms API
19
+
20
+ rely on [aiohttp](https://github.com/aio-libs/aiohttp)
21
+
22
+ to install : `pip3 install pyemoncms`
23
+
24
+ how to use :
25
+
26
+ ```
27
+ import logging
28
+ import asyncio
29
+ from pyemoncms import EmoncmsClient
30
+
31
+ key = "your32bitsAPIkey"
32
+ url = "http://url:8081"
33
+ client = EmoncmsClient(url, key, request_timeout=1)
34
+ client.logger.setLevel("DEBUG")
35
+
36
+ async def get_path(path):
37
+ print(await client.async_request(path))
38
+
39
+ async def list_feeds():
40
+ print(await client.async_list_feeds())
41
+
42
+ async def get_feed_fields(feed_id):
43
+ print(await client.async_get_feed_fields(feed_id))
44
+
45
+
46
+ loop = asyncio.get_event_loop()
47
+ loop.create_task(get_path("/feed/list.json"))
48
+ loop.create_task(get_path("/user/getuuid.json"))
49
+ loop.create_task(list_feeds())
50
+ loop.create_task(get_feed_fields(1))
51
+ loop.run_forever()
52
+ ```
@@ -6,7 +6,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
6
6
 
7
7
  setuptools.setup(
8
8
  name="pyemoncms",
9
- version="0.0.3",
9
+ version="0.0.5",
10
10
  author="Alexandre CUER",
11
11
  author_email="alexandre.cuer@wanadoo.fr",
12
12
  description="A python library to interrogate emoncms API",
pyemoncms-0.0.3/PKG-INFO DELETED
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyemoncms
3
- Version: 0.0.3
4
- Summary: A python library to interrogate emoncms API
5
- Home-page: https://github.com/Open-Building-Management/pyemoncms
6
- Author: Alexandre CUER
7
- Author-email: alexandre.cuer@wanadoo.fr
8
- Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: aiohttp
16
-
17
- # pyemoncms
18
- python library for emoncms API
pyemoncms-0.0.3/README.md DELETED
@@ -1,2 +0,0 @@
1
- # pyemoncms
2
- python library for emoncms API
@@ -1,18 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: pyemoncms
3
- Version: 0.0.3
4
- Summary: A python library to interrogate emoncms API
5
- Home-page: https://github.com/Open-Building-Management/pyemoncms
6
- Author: Alexandre CUER
7
- Author-email: alexandre.cuer@wanadoo.fr
8
- Project-URL: Bug Tracker, https://github.com/Open-Building-Management/pyemoncms/issues
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: License :: OSI Approved :: MIT License
11
- Classifier: Operating System :: OS Independent
12
- Requires-Python: >=3.10
13
- Description-Content-Type: text/markdown
14
- License-File: LICENSE
15
- Requires-Dist: aiohttp
16
-
17
- # pyemoncms
18
- python library for emoncms API
File without changes
File without changes
File without changes