Skip to content

Commit

Permalink
Fixed issue #10
Browse files Browse the repository at this point in the history
Removed my SiteId (sorry) from the URL's. This should fix it.
Also added logging in case of other unforeseen errors.
  • Loading branch information
ProudElm committed Oct 18, 2022
1 parent 8e0bb36 commit 76aaa20
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
12 changes: 6 additions & 6 deletions custom_components/solaredgeoptimizers/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
_LOGGER = logging.getLogger(__name__)

STEP_USER_DATA_SCHEMA = vol.Schema(
{
vol.Required("siteid"): str,
vol.Required("username"): str,
vol.Required("password"): str,
}
)
{
vol.Required("siteid"): str,
vol.Required("username"): str,
vol.Required("password"): str,
}
)


class SolarEdgeWebAuth:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solaredgeoptimizers/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"@proudelm"
],
"iot_class": "cloud_polling",
"version": "1.1.0"
"version": "1.1.1"
}
47 changes: 33 additions & 14 deletions custom_components/solaredgeoptimizers/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
_LOGGER = logging.getLogger(__name__)

temp_paneel = None
temp_lifetimeenergy = None


async def async_setup_entry(
Expand All @@ -56,9 +57,6 @@ async def async_setup_entry(
# Add the needed sensors to hass
client = hass.data[DOMAIN][entry.entry_id][DATA_API_CLIENT]

# entry.data["paneel"] = "boe"

# panelen = await hass.async_add_executor_job(client.requestAllData)
site = await hass.async_add_executor_job(client.requestListOfAllPanels)

_LOGGER.info("Found all information for site: %s", site.siteId)
Expand Down Expand Up @@ -165,12 +163,35 @@ def update(self):
# Voor totaal energie moeten we wat anders doen
if self._sensor_type is SENSOR_TYPE_ENERGY:
# waarde ophalen
lifetimeenergy = json.loads(self._client.getLifeTimeEnergy())
waarde = (
float(
lifetimeenergy[str(self._paneelobject.paneel_id)]["unscaledEnergy"]
response = ""

try:
response = self._client.getLifeTimeEnergy()

if response != "":

if "ERROR001" in response:
_LOGGER.error(
"Error updating life time energy data for panel: %s",
self._paneelobject.paneel_id,
)
_LOGGER.error("The response was: %s", response)
else:
lifetimeenergy = json.loads(self._client.getLifeTimeEnergy())
waarde = (
float(
lifetimeenergy[str(self._paneelobject.paneel_id)][
"unscaledEnergy"
]
)
) / 1000
except Exception as err:
_LOGGER.error(
"Error updating life time energy data for panel: %s",
self._paneelobject.paneel_id,
)
) / 1000
_LOGGER.error(err)
_LOGGER.error("The response was: %s", response)
else:

try:
Expand All @@ -181,19 +202,17 @@ def update(self):
)
temp_paneel = paneel_info
_LOGGER.info(
"Paneel data opgehaald, geheugen was leeg. Paneel {}".format(
self._paneelobject.paneel_desciption
)
"Paneel data opgehaald, geheugen was leeg. Paneel %s",
self._paneelobject.paneel_desciption,
)
elif temp_paneel.paneel_id is not self._paneelobject.paneel_id:
paneel_info = self._client.requestSystemData(
self._paneelobject.paneel_id
)
temp_paneel = paneel_info
_LOGGER.info(
"Paneel data opgehaald, verkeerd paneel in geheugen. Paneel {}".format(
self._paneelobject.paneel_desciption
)
"Paneel data opgehaald, verkeerd paneel in geheugen. Paneel %s",
self._paneelobject.paneel_desciption,
)
else:
paneel_info = temp_paneel
Expand Down
14 changes: 10 additions & 4 deletions custom_components/solaredgeoptimizers/solaredgeoptimizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ def requestAllData(self):
def getLifeTimeEnergy(self):
session = Session()
session.head(
"https://monitoring.solaredge.com/solaredge-apigw/api/sites/1871534/layout/energy"
"https://monitoring.solaredge.com/solaredge-apigw/api/sites/{}/layout/energy".format(
self.siteid
)
)

url = "https://monitoring.solaredge.com/solaredge-web/p/login"
Expand All @@ -103,15 +105,19 @@ def getLifeTimeEnergy(self):

# Build up the request.
response = session.post(
url="https://monitoring.solaredge.com/solaredge-apigw/api/sites/1871534/layout/energy?timeUnit=ALL",
url="https://monitoring.solaredge.com/solaredge-apigw/api/sites/{}/layout/energy?timeUnit=ALL".format(
self.siteid
),
headers={
"authority": "monitoring.solaredge.com",
"accept": "*/*",
"accept-language": "en-US,en;q=0.9,nl;q=0.8",
"content-type": "application/json",
"cookie": therightcookie,
"origin": "https://monitoring.solaredge.com",
"referer": "https://monitoring.solaredge.com/solaredge-web/p/site/1871534/",
"referer": "https://monitoring.solaredge.com/solaredge-web/p/site/{}/".format(
self.siteid
),
"sec-ch-ua": '"Google Chrome";v="105", "Not)A;Brand";v="8", "Chromium";v="105"',
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
Expand All @@ -128,7 +134,7 @@ def getLifeTimeEnergy(self):
if response.status_code == 200:
return response.text
else:
return "ERROR - HTTP CODE: {}".format(response.status_code)
return "ERROR001 - HTTP CODE: {}".format(response.status_code)

def GetThecsrfToken(self, cookies):
for cookie in cookies:
Expand Down

0 comments on commit 76aaa20

Please sign in to comment.