-
Notifications
You must be signed in to change notification settings - Fork 1
/
AlphaEssMonitor.py
67 lines (56 loc) · 2.4 KB
/
AlphaEssMonitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import re
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
import settings
class AlphaEssMonitor:
def __init__(self, user_name, password, host=settings.ALPHAESS_HOST):
# print("AlphaEssMonitor: __init__")
self.user_name = user_name
self.password = password
self.host = host
self.started = False
self.driver = None
def start(self, driver):
if self.started:
return
self.driver = driver
self.started = True
self.driver.get(self.host)
self.driver.set_window_size(968, 1030)
print("AlphaEssMonitor: login")
self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(2) .el-input__inner").send_keys(self.user_name)
self.driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(3) .el-input__inner").send_keys(self.password)
self.driver.find_element(By.CSS_SELECTOR, ".el-button--primary").click()
self.user_name = None
self.password = None
def stop(self):
# self.driver.get(self.host + "/logout")
self.driver.quit()
self.driver = None
self.started = False
def get_data(self):
pvchartcontainerId = '1'
loadchartcontainerId = '2'
batterychartcontainerId = '3'
feedinchartcontainerId = '4'
gridchartcontainerId = '5'
self.driver.refresh()
WebDriverWait(self.driver, 60).until(
expected_conditions.visibility_of_element_located((By.ID, "tab-2")))
sleep(10)
self.driver.find_element(By.ID, "tab-2").click()
sleep(10)
return {
'pv': self.get_value(pvchartcontainerId),
'load': self.get_value(loadchartcontainerId),
'battery': self.get_value(batterychartcontainerId),
'feed_in': self.get_value(feedinchartcontainerId),
'grid_consumption': self.get_value(gridchartcontainerId)
}
def get_value(self, _id):
WebDriverWait(self.driver, 5000).until(
expected_conditions.presence_of_element_located((By.CSS_SELECTOR, ".pie-data-container > :nth-child(" + _id + ") tspan")))
sleep(2)
return float(re.sub("%|kW", "", self.driver.find_element_by_css_selector(".pie-data-container > :nth-child(" + _id + ") tspan").text))