Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix current_system_inverter_data endpoint for Gen24 devices #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 29 additions & 27 deletions pyfronius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import asyncio
import enum
from html import unescape
import json
import logging
from typing import Any, Dict
from html import unescape
from typing import Any, Dict, Union

import aiohttp

Expand Down Expand Up @@ -51,9 +51,7 @@ class API_VERSION(enum.Enum):
}
URL_SYSTEM_LED = {API_VERSION.V1: "GetLoggerLEDInfo.cgi"}
URL_SYSTEM_OHMPILOT = {API_VERSION.V1: "GetOhmPilotRealtimeData.cgi?Scope=System"}
URL_SYSTEM_STORAGE = {
API_VERSION.V1: "GetStorageRealtimeData.cgi?Scope=System"
}
URL_SYSTEM_STORAGE = {API_VERSION.V1: "GetStorageRealtimeData.cgi?Scope=System"}
URL_DEVICE_METER = {API_VERSION.V1: "GetMeterRealtimeData.cgi?Scope=Device&DeviceId={}"}
URL_DEVICE_STORAGE = {
API_VERSION.V1: "GetStorageRealtimeData.cgi?Scope=Device&DeviceId={}"
Expand Down Expand Up @@ -140,13 +138,14 @@ class InvalidAnswerError(ValueError, FroniusError):

class BadStatusError(FroniusError):
"""A bad status code was returned."""

def __init__(
self,
endpoint: str,
code: int,
reason: str = None,
response: Dict[str, Any] = {},
) -> None:
self,
endpoint: str,
code: int,
reason: Union[str, None] = None,
response: Dict[str, Any] = {},
) -> None:
"""Instantiate exception."""
self.response = response
message = (
Expand Down Expand Up @@ -309,7 +308,6 @@ async def fetch(

@staticmethod
def _status_data(res):

sensor = {}

sensor["timestamp"] = {"value": res["Head"]["Timestamp"]}
Expand Down Expand Up @@ -582,32 +580,36 @@ def _system_inverter_data(data):
if "DAY_ENERGY" in data:
for i in data["DAY_ENERGY"]["Values"]:
sensor["inverters"][i] = {}
value = data["DAY_ENERGY"]["Values"][i]
sensor["inverters"][i]["energy_day"] = {
"value": data["DAY_ENERGY"]["Values"][i],
"value": value,
"unit": data["DAY_ENERGY"]["Unit"],
}
sensor["energy_day"]["value"] += data["DAY_ENERGY"]["Values"][i]
sensor["energy_day"]["value"] += value or 0
if "TOTAL_ENERGY" in data:
for i in data["TOTAL_ENERGY"]["Values"]:
value = data["TOTAL_ENERGY"]["Values"][i]
sensor["inverters"][i]["energy_total"] = {
"value": data["TOTAL_ENERGY"]["Values"][i],
"value": value,
"unit": data["TOTAL_ENERGY"]["Unit"],
}
sensor["energy_total"]["value"] += data["TOTAL_ENERGY"]["Values"][i]
sensor["energy_total"]["value"] += value or 0
if "YEAR_ENERGY" in data:
for i in data["YEAR_ENERGY"]["Values"]:
value = data["YEAR_ENERGY"]["Values"][i]
sensor["inverters"][i]["energy_year"] = {
"value": data["YEAR_ENERGY"]["Values"][i],
"value": value,
"unit": data["YEAR_ENERGY"]["Unit"],
}
sensor["energy_year"]["value"] += data["YEAR_ENERGY"]["Values"][i]
sensor["energy_year"]["value"] += value or 0
if "PAC" in data:
for i in data["PAC"]["Values"]:
value = data["PAC"]["Values"][i]
sensor["inverters"][i]["power_ac"] = {
"value": data["PAC"]["Values"][i],
"value": value,
"unit": data["PAC"]["Unit"],
}
sensor["power_ac"]["value"] += data["PAC"]["Values"][i]
sensor["power_ac"]["value"] += value or 0

return sensor

Expand All @@ -624,7 +626,7 @@ def _device_ohmpilot_data(data):
device["state_code"] = {"value": state_code}
device["state_message"] = {
"value": OHMPILOT_STATE_CODES.get(state_code, "Unknown")
}
}

if "Details" in data:
device["hardware"] = {"value": data["Details"]["Hardware"]}
Expand All @@ -635,16 +637,18 @@ def _device_ohmpilot_data(data):

if "EnergyReal_WAC_Sum_Consumed" in data:
device["energy_real_ac_consumed"] = {
"value": data["EnergyReal_WAC_Sum_Consumed"], "unit": WATT_HOUR
}
"value": data["EnergyReal_WAC_Sum_Consumed"],
"unit": WATT_HOUR,
}

if "PowerReal_PAC_Sum" in data:
device["power_real_ac"] = {"value": data["PowerReal_PAC_Sum"], "unit": WATT}

if "Temperature_Channel_1" in data:
device["temperature_channel_1"] = {
"value": data["Temperature_Channel_1"], "unit": DEGREE_CELSIUS
}
"value": data["Temperature_Channel_1"],
"unit": DEGREE_CELSIUS,
}

return device

Expand Down Expand Up @@ -976,7 +980,6 @@ def _device_inverter_data(data):

@staticmethod
def _controller_data(data):

controller = {}

if "Capacity_Maximum" in data:
Expand Down Expand Up @@ -1024,7 +1027,6 @@ def _controller_data(data):

@staticmethod
def _module_data(data):

module = {}

if "Capacity_Maximum" in data:
Expand Down