powervaultpy 0.0.9__tar.gz → 1.0.1__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: powervaultpy
3
- Version: 0.0.9
3
+ Version: 1.0.1
4
4
  Summary: An integration to control the Powervault battery
5
5
  Author-email: Adam McDonagh <adam@elitemonkey.net>
6
6
  License: GPLv3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "powervaultpy"
7
- version = "0.0.9"
7
+ version = "1.0.1"
8
8
  authors = [
9
9
  { name="Adam McDonagh", email="adam@elitemonkey.net" },
10
10
  ]
@@ -43,7 +43,7 @@ dev = [
43
43
  profile = 'black'
44
44
 
45
45
  [tool.bumpver]
46
- current_version = "0.0.9"
46
+ current_version = "1.0.1"
47
47
  version_pattern = "MAJOR.MINOR.PATCH"
48
48
  commit_message = "bump version {old_version} -> {new_version}"
49
49
  commit = true
@@ -56,10 +56,16 @@ class PowerVault:
56
56
  self._session.headers.update(
57
57
  {
58
58
  "x-api-key": self._api_key,
59
- "accept": "application/json",
59
+ "accept": "*/*",
60
60
  }
61
61
  )
62
62
 
63
+ # Get list of header keys, and remove any that are not in the list above
64
+ headers = list(self._session.headers.keys())
65
+ for key in headers:
66
+ if key not in ["x-api-key", "accept"]:
67
+ self._session.headers.pop(key)
68
+
63
69
  def get_units(self, account_id: int) -> any:
64
70
  """Get the user's units from the API."""
65
71
  url = f"{self._base_url}/unit?customerAccountId={account_id}"
@@ -113,14 +119,12 @@ class PowerVault:
113
119
  _LOGGER.error("Failed to retrieve account")
114
120
 
115
121
  def get_data(
116
- self, unit_id: str, from_: int = -1, to: int = -1, period: str = None
122
+ self, unit_id: str, period: str = None
117
123
  ) -> any:
118
124
  """Get the latest metrics from the unit."""
119
125
  url = f"{self._base_url}/unit/{unit_id}/data"
120
126
 
121
- if from_ > 0 and to > 0:
122
- url = f"{url}?from={from_}&to={to}"
123
- elif period is not None:
127
+ if period is not None:
124
128
  if period not in [
125
129
  "today",
126
130
  "yesterday",
@@ -134,7 +138,13 @@ class PowerVault:
134
138
  "last-month",
135
139
  ]:
136
140
  raise Exception(f"Invalid period: {period}")
137
- url = f"{url}?period={period}"
141
+
142
+ if not period:
143
+ # If period is not set, set it to anything,
144
+ # because for some reason if you leave it blank you get nulls most of the time
145
+ period = "past_hour" # This is not a valid period, but it gets you the last live values regardless
146
+
147
+ url = f"{url}?period={period}"
138
148
 
139
149
  data_response = self._read_response(self._session.get(url), url)
140
150
  _LOGGER.debug("Data: %s", data_response)
@@ -162,10 +172,11 @@ class PowerVault:
162
172
  for row in data:
163
173
  for attribute in attributes:
164
174
  if attribute in row:
165
- if attribute not in totals:
175
+ if attribute not in totals or not totals[attribute]:
166
176
  totals[attribute] = 0
167
- totals[attribute] += round(row[attribute] / 1000 * (5/60), 2)
168
-
177
+ value = row[attribute]
178
+ if value:
179
+ totals[attribute] += round(value / 1000 * (5/60), 2)
169
180
  return totals
170
181
 
171
182
  def set_battery_state(self, unit_id: str, battery_state) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: powervaultpy
3
- Version: 0.0.9
3
+ Version: 1.0.1
4
4
  Summary: An integration to control the Powervault battery
5
5
  Author-email: Adam McDonagh <adam@elitemonkey.net>
6
6
  License: GPLv3
File without changes