-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wip * wip * solarman * update token * update inverters * undo some changes * add docstring * mock inverter docstring * remove dotenv * update givenergy * enphase * try to fix tests running twice * delete event * pr comments * revert workflow changes * split inverters into separate modules * import * Revert "import" This reverts commit f9f3c5f. * Revert "split inverters into separate modules" This reverts commit 94a9e70. * add pydantic_settings * set config within settings classes * add dependency * add victron * use named argument * start and end times * add a line to the documentation * dependencies * add test * add test * update script * add username and password to example env variable file * move vrmapi dependency to optional-dependencies * comment * update to use ocf_vrmapi
- Loading branch information
Showing
6 changed files
with
1,518 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import Callable | ||
|
||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
from quartz_solar_forecast.inverters.inverter import AbstractInverter | ||
from pydantic import Field | ||
from pydantic_settings import BaseSettings, SettingsConfigDict | ||
from ocf_vrmapi.vrm import VRM_API | ||
|
||
|
||
class VictronSettings(BaseSettings): | ||
model_config = SettingsConfigDict(env_file='.env', extra='ignore') | ||
|
||
username: str = Field(alias="VICTRON_USER") | ||
password: str = Field(alias="VICTRON_PASS") | ||
|
||
|
||
class VictronInverter(AbstractInverter): | ||
|
||
def __init__(self, get_sites: Callable, get_kwh_stats: Callable): | ||
self.__get_sites = get_sites | ||
self.__get_kwh_stats = get_kwh_stats | ||
|
||
@classmethod | ||
def from_settings(cls, settings: VictronSettings): | ||
api = VRM_API(username=settings.username, password=settings.password) | ||
get_sites = lambda: api.get_user_sites(api.user_id) | ||
end = datetime.now() | ||
start = end - timedelta(weeks=1) | ||
get_kwh_stats = lambda site_id: api.get_kwh_stats(site_id, start=start, end=end) | ||
return cls(get_sites, get_kwh_stats) | ||
|
||
def get_data(self, ts: pd.Timestamp) -> pd.DataFrame: | ||
sites = self.__get_sites() | ||
# get first site (bit of a guess) | ||
first_site_id = sites["records"][0]["idSite"] | ||
|
||
stats = self.__get_kwh_stats(first_site_id) | ||
|
||
kwh = stats["records"]["kwh"] | ||
|
||
df = pd.DataFrame(kwh) | ||
|
||
df[0] = pd.to_datetime(df[0], unit='ms') | ||
df.columns = ["timestamp", "power_kw"] | ||
return df |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.