pyemoncms 0.0.7__tar.gz → 0.0.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyemoncms
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A python library to interrogate emoncms API
5
5
  Home-page: https://github.com/Open-Building-Management/pyemoncms
6
6
  Author: Alexandre CUER
@@ -36,8 +36,8 @@ client.logger.setLevel("DEBUG")
36
36
  async def get_path(path):
37
37
  print(await client.async_request(path))
38
38
 
39
- async def list_feeds(uuid=False):
40
- print(await client.async_list_feeds(uuid=uuid))
39
+ async def list_feeds():
40
+ print(await client.async_list_feeds())
41
41
 
42
42
  async def get_feed_fields(feed_id):
43
43
  print(await client.async_get_feed_fields(feed_id))
@@ -47,7 +47,6 @@ loop = asyncio.get_event_loop()
47
47
  loop.create_task(get_path("feed/list.json"))
48
48
  loop.create_task(get_path("/user/getuuid.json"))
49
49
  loop.create_task(list_feeds())
50
- loop.create_task(list_feeds(uuid=True))
51
50
  loop.create_task(get_feed_fields(1))
52
51
  try:
53
52
  loop.run_forever()
@@ -65,8 +64,7 @@ async def main():
65
64
  """fetches somes datas in emoncms"""
66
65
  async with EmoncmsClient(url, key, request_timeout=1) as client:
67
66
  client.logger.setLevel("DEBUG")
68
- print(await client.async_request("/feed/list.json"))
69
- print(await client.async_request("/user/getuuid.json"))
67
+ print(await client.async_get_uuid())
70
68
  print(await client.async_list_feeds())
71
69
  print(await client.async_get_feed_fields(1))
72
70
 
@@ -20,8 +20,8 @@ client.logger.setLevel("DEBUG")
20
20
  async def get_path(path):
21
21
  print(await client.async_request(path))
22
22
 
23
- async def list_feeds(uuid=False):
24
- print(await client.async_list_feeds(uuid=uuid))
23
+ async def list_feeds():
24
+ print(await client.async_list_feeds())
25
25
 
26
26
  async def get_feed_fields(feed_id):
27
27
  print(await client.async_get_feed_fields(feed_id))
@@ -31,7 +31,6 @@ loop = asyncio.get_event_loop()
31
31
  loop.create_task(get_path("feed/list.json"))
32
32
  loop.create_task(get_path("/user/getuuid.json"))
33
33
  loop.create_task(list_feeds())
34
- loop.create_task(list_feeds(uuid=True))
35
34
  loop.create_task(get_feed_fields(1))
36
35
  try:
37
36
  loop.run_forever()
@@ -49,8 +48,7 @@ async def main():
49
48
  """fetches somes datas in emoncms"""
50
49
  async with EmoncmsClient(url, key, request_timeout=1) as client:
51
50
  client.logger.setLevel("DEBUG")
52
- print(await client.async_request("/feed/list.json"))
53
- print(await client.async_request("/user/getuuid.json"))
51
+ print(await client.async_get_uuid())
54
52
  print(await client.async_list_feeds())
55
53
  print(await client.async_get_feed_fields(1))
56
54
 
@@ -76,11 +76,6 @@ class EmoncmsClient:
76
76
  data[SUCCESS_KEY] = True
77
77
  json_response = await response.json()
78
78
  data[MESSAGE_KEY] = json_response
79
- try:
80
- if MESSAGE_KEY in json_response:
81
- data[MESSAGE_KEY] = json_response[MESSAGE_KEY]
82
- except TypeError:
83
- data[SUCCESS_KEY] = False
84
79
  else:
85
80
  message = f"error {response.status}"
86
81
  if response.status in HTTP_STATUS:
@@ -89,21 +84,29 @@ class EmoncmsClient:
89
84
  self.logger.error(message)
90
85
  return data
91
86
 
92
- async def async_list_feeds(self, uuid: bool = False) -> list[dict[str, Any]] | None:
93
- """Request emoncms feeds list.
94
-
95
- return a uuid per feed if available
87
+ async def async_get_uuid(self) -> str | None:
88
+ """Return the unique identifier or None.
89
+
90
+ drop a warning during migration process from a non uuid emoncms to a uuid one
91
+
92
+ this warns the user to do a database update
93
+
94
+ first uuid version of emoncms is 11.5.7
96
95
  """
96
+ result = await self.async_request('/user/getuuid.json')
97
+ if result[SUCCESS_KEY]:
98
+ json_response = result[MESSAGE_KEY]
99
+ if json_response is False:
100
+ return None
101
+ if json_response[SUCCESS_KEY]:
102
+ return json_response[MESSAGE_KEY]
103
+ message = json_response[MESSAGE_KEY].replace("ADMIN", "EMONCMS ADMIN")
104
+ self.logger.warning(message)
105
+ return None
106
+
107
+ async def async_list_feeds(self) -> list[dict[str, Any]] | None:
108
+ """Request emoncms feeds list."""
97
109
  feed_data = await self.async_request("/feed/list.json")
98
- if uuid:
99
- uuid_data = await self.async_request("/user/getuuid.json")
100
- if not uuid_data[SUCCESS_KEY]:
101
- message = "no uuid available"
102
- message = f"{message} - migrate your emoncms sensor to a newer version"
103
- self.logger.warning(message)
104
- if feed_data[SUCCESS_KEY] and uuid_data[SUCCESS_KEY]:
105
- for feed in feed_data[MESSAGE_KEY]:
106
- feed["uuid"] = f"{uuid_data[MESSAGE_KEY]}_{feed['id']}"
107
110
  if feed_data[SUCCESS_KEY]:
108
111
  return feed_data[MESSAGE_KEY]
109
112
  return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyemoncms
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: A python library to interrogate emoncms API
5
5
  Home-page: https://github.com/Open-Building-Management/pyemoncms
6
6
  Author: Alexandre CUER
@@ -36,8 +36,8 @@ client.logger.setLevel("DEBUG")
36
36
  async def get_path(path):
37
37
  print(await client.async_request(path))
38
38
 
39
- async def list_feeds(uuid=False):
40
- print(await client.async_list_feeds(uuid=uuid))
39
+ async def list_feeds():
40
+ print(await client.async_list_feeds())
41
41
 
42
42
  async def get_feed_fields(feed_id):
43
43
  print(await client.async_get_feed_fields(feed_id))
@@ -47,7 +47,6 @@ loop = asyncio.get_event_loop()
47
47
  loop.create_task(get_path("feed/list.json"))
48
48
  loop.create_task(get_path("/user/getuuid.json"))
49
49
  loop.create_task(list_feeds())
50
- loop.create_task(list_feeds(uuid=True))
51
50
  loop.create_task(get_feed_fields(1))
52
51
  try:
53
52
  loop.run_forever()
@@ -65,8 +64,7 @@ async def main():
65
64
  """fetches somes datas in emoncms"""
66
65
  async with EmoncmsClient(url, key, request_timeout=1) as client:
67
66
  client.logger.setLevel("DEBUG")
68
- print(await client.async_request("/feed/list.json"))
69
- print(await client.async_request("/user/getuuid.json"))
67
+ print(await client.async_get_uuid())
70
68
  print(await client.async_list_feeds())
71
69
  print(await client.async_get_feed_fields(1))
72
70
 
@@ -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.7",
9
+ version="0.0.9",
10
10
  author="Alexandre CUER",
11
11
  author_email="alexandre.cuer@wanadoo.fr",
12
12
  description="A python library to interrogate emoncms API",
@@ -67,7 +67,7 @@ async def test_timeout():
67
67
 
68
68
  async def test_client_error():
69
69
  """Test when IP exists but client not running."""
70
- client = EmoncmsClient("http://127.0.0.1:8081", API_KEY)
70
+ client = EmoncmsClient("http://127.0.0.1:8087", API_KEY)
71
71
  datas = await client.async_request("/feed/list.json")
72
72
  assert not datas["success"]
73
73
  assert "client error" in datas["message"]
File without changes
File without changes
File without changes