powervaultpy 0.0.6__tar.gz → 0.0.8__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.
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/PKG-INFO +1 -1
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/pyproject.toml +1 -1
- powervaultpy-0.0.8/src/powervaultpy/__init__.py +1 -0
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy/powervault.py +66 -2
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy.egg-info/PKG-INFO +1 -1
- powervaultpy-0.0.6/src/powervaultpy/__init__.py +0 -1
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/setup.cfg +0 -0
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy.egg-info/SOURCES.txt +0 -0
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy.egg-info/dependency_links.txt +0 -0
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy.egg-info/requires.txt +0 -0
- {powervaultpy-0.0.6 → powervaultpy-0.0.8}/src/powervaultpy.egg-info/top_level.txt +0 -0
@@ -0,0 +1 @@
|
|
1
|
+
from powervaultpy.powervault import PowerVault, VALID_STATUSES
|
@@ -2,11 +2,21 @@
|
|
2
2
|
|
3
3
|
import json
|
4
4
|
import logging
|
5
|
-
from datetime import datetime
|
5
|
+
from datetime import datetime, timedelta
|
6
6
|
|
7
7
|
import pytz
|
8
8
|
import requests
|
9
9
|
|
10
|
+
VALID_STATUSES = [
|
11
|
+
"normal",
|
12
|
+
"only-charge",
|
13
|
+
"only-discharge",
|
14
|
+
"force-charge",
|
15
|
+
"force-discharge",
|
16
|
+
"disable",
|
17
|
+
"dormant",
|
18
|
+
]
|
19
|
+
|
10
20
|
_LOGGER = logging.getLogger(__name__)
|
11
21
|
_LOGGER.setLevel(logging.DEBUG)
|
12
22
|
|
@@ -134,6 +144,60 @@ class PowerVault:
|
|
134
144
|
|
135
145
|
_LOGGER.error("Failed to retrieve data")
|
136
146
|
|
147
|
+
def get_kwh(self, data: dict) -> dict:
|
148
|
+
# List of attributes to retrieve from data dict
|
149
|
+
attributes = [
|
150
|
+
"batteryInputFromGrid",
|
151
|
+
"batteryInputFromSolar",
|
152
|
+
"batteryOutputConsumedByHome",
|
153
|
+
"batteryOutputExported",
|
154
|
+
"homeConsumed",
|
155
|
+
"gridConsumedByHome",
|
156
|
+
"solarConsumedByHome",
|
157
|
+
"solarExported",
|
158
|
+
"solarGenerated",
|
159
|
+
]
|
160
|
+
# For each attribute, loop through the data dict and conver the W reading to kWh over the 5 minute period
|
161
|
+
totals = {}
|
162
|
+
for row in data:
|
163
|
+
for attribute in attributes:
|
164
|
+
if attribute in row:
|
165
|
+
if attribute not in totals:
|
166
|
+
totals[attribute] = 0
|
167
|
+
totals[attribute] += round(row[attribute] / 1000 * (5/60), 2)
|
168
|
+
|
169
|
+
return totals
|
170
|
+
|
171
|
+
def set_battery_state(self, unit_id: str, battery_state) -> bool:
|
172
|
+
"""Override the current battery status with the provided one."""
|
173
|
+
url = f"{self._base_url}/unit/{unit_id}/stateOverride"
|
174
|
+
|
175
|
+
start_time = datetime.now(pytz.timezone('UTC')).strftime("%Y-%m-%d %H:%M:%S")
|
176
|
+
end_time = (datetime.now(pytz.timezone('UTC')) + timedelta(hours=24)).strftime("%Y-%m-%d %H:%M:%S")
|
177
|
+
|
178
|
+
payload = {
|
179
|
+
"stateOverrides": [
|
180
|
+
{
|
181
|
+
"start": start_time,
|
182
|
+
"end": end_time,
|
183
|
+
"state": battery_state
|
184
|
+
}
|
185
|
+
]
|
186
|
+
}
|
187
|
+
|
188
|
+
_LOGGER.debug("Payload: %s", payload)
|
189
|
+
|
190
|
+
state_override_response = self._read_response(
|
191
|
+
self._session.post(url, json=payload), url)
|
192
|
+
|
193
|
+
_LOGGER.debug("State Override: %s", state_override_response)
|
194
|
+
|
195
|
+
if (state_override_response is not None) and ("stateOverrides" in state_override_response) and "message" in state_override_response and state_override_response["message"] == "success":
|
196
|
+
return True
|
197
|
+
else:
|
198
|
+
return False
|
199
|
+
|
200
|
+
|
137
201
|
def get_battery_state(self, unit_id: str) -> any:
|
138
202
|
"""Query the schedule and overrides to determine the current battery state."""
|
139
203
|
url = f"{self._base_url}/unit/{unit_id}/schedule"
|
@@ -147,7 +211,7 @@ class PowerVault:
|
|
147
211
|
_LOGGER.debug("State Override: %s", state_override_response)
|
148
212
|
|
149
213
|
# Get the current local datetime
|
150
|
-
current_dow = datetime.now().strftime("%A").lower()
|
214
|
+
current_dow = datetime.now(pytz.timezone("Europe/London")).strftime("%A").lower()
|
151
215
|
|
152
216
|
# Log the current day of the week
|
153
217
|
_LOGGER.debug("Current day of the week: %s", current_dow)
|
@@ -1 +0,0 @@
|
|
1
|
-
from powervaultpy.powervault import PowerVault
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|