diff --git a/docs/index.md b/docs/index.md index f5ad54f..85ee206 100644 --- a/docs/index.md +++ b/docs/index.md @@ -49,6 +49,27 @@ * [phases](#sunweg.device.Inverter.phases) * [mppts](#sunweg.device.Inverter.mppts) * [\_\_str\_\_](#sunweg.device.Inverter.__str__) +* [sunweg.const](#sunweg.const) + * [SUNWEG\_URL](#sunweg.const.SUNWEG_URL) + * [SUNWEG\_LOGIN\_PATH](#sunweg.const.SUNWEG_LOGIN_PATH) + * [SUNWEG\_PLANT\_LIST\_PATH](#sunweg.const.SUNWEG_PLANT_LIST_PATH) + * [SUNWEG\_PLANT\_DETAIL\_PATH](#sunweg.const.SUNWEG_PLANT_DETAIL_PATH) + * [SUNWEG\_INVERTER\_DETAIL\_PATH](#sunweg.const.SUNWEG_INVERTER_DETAIL_PATH) + * [SUNWEG\_MONTH\_STATS\_PATH](#sunweg.const.SUNWEG_MONTH_STATS_PATH) +* [sunweg.api](#sunweg.api) + * [SunWegApiError](#sunweg.api.SunWegApiError) + * [LoginError](#sunweg.api.LoginError) + * [convert\_situation\_status](#sunweg.api.convert_situation_status) + * [separate\_value\_metric](#sunweg.api.separate_value_metric) + * [APIHelper](#sunweg.api.APIHelper) + * [\_\_init\_\_](#sunweg.api.APIHelper.__init__) + * [authenticate](#sunweg.api.APIHelper.authenticate) + * [listPlants](#sunweg.api.APIHelper.listPlants) + * [plant](#sunweg.api.APIHelper.plant) + * [inverter](#sunweg.api.APIHelper.inverter) + * [complete\_inverter](#sunweg.api.APIHelper.complete_inverter) + * [month\_stats\_production](#sunweg.api.APIHelper.month_stats_production) + * [month\_stats\_production\_by\_id](#sunweg.api.APIHelper.month_stats_production_by_id) * [sunweg.plant](#sunweg.plant) * [Plant](#sunweg.plant.Plant) * [\_\_init\_\_](#sunweg.plant.Plant.__init__) @@ -65,13 +86,6 @@ * [last\_update](#sunweg.plant.Plant.last_update) * [inverters](#sunweg.plant.Plant.inverters) * [\_\_str\_\_](#sunweg.plant.Plant.__str__) -* [sunweg.const](#sunweg.const) - * [SUNWEG\_URL](#sunweg.const.SUNWEG_URL) - * [SUNWEG\_LOGIN\_PATH](#sunweg.const.SUNWEG_LOGIN_PATH) - * [SUNWEG\_PLANT\_LIST\_PATH](#sunweg.const.SUNWEG_PLANT_LIST_PATH) - * [SUNWEG\_PLANT\_DETAIL\_PATH](#sunweg.const.SUNWEG_PLANT_DETAIL_PATH) - * [SUNWEG\_INVERTER\_DETAIL\_PATH](#sunweg.const.SUNWEG_INVERTER_DETAIL_PATH) - * [SUNWEG\_MONTH\_STATS\_PATH](#sunweg.const.SUNWEG_MONTH_STATS_PATH) * [sunweg.util](#sunweg.util) * [Status](#sunweg.util.Status) * [ProductionStats](#sunweg.util.ProductionStats) @@ -80,20 +94,6 @@ * [production](#sunweg.util.ProductionStats.production) * [prognostic](#sunweg.util.ProductionStats.prognostic) * [\_\_str\_\_](#sunweg.util.ProductionStats.__str__) -* [sunweg.api](#sunweg.api) - * [SunWegApiError](#sunweg.api.SunWegApiError) - * [LoginError](#sunweg.api.LoginError) - * [convert\_situation\_status](#sunweg.api.convert_situation_status) - * [separate\_value\_metric](#sunweg.api.separate_value_metric) - * [APIHelper](#sunweg.api.APIHelper) - * [\_\_init\_\_](#sunweg.api.APIHelper.__init__) - * [authenticate](#sunweg.api.APIHelper.authenticate) - * [listPlants](#sunweg.api.APIHelper.listPlants) - * [plant](#sunweg.api.APIHelper.plant) - * [inverter](#sunweg.api.APIHelper.inverter) - * [complete\_inverter](#sunweg.api.APIHelper.complete_inverter) - * [month\_stats\_production](#sunweg.api.APIHelper.month_stats_production) - * [month\_stats\_production\_by\_id](#sunweg.api.APIHelper.month_stats_production_by_id) @@ -801,591 +801,591 @@ def __str__() -> str Cast Inverter to str. - - -# sunweg.plant + -Sunweg API plant. +# sunweg.const - +Sunweg API constants. -## Plant Objects + -```python -class Plant() -``` +#### SUNWEG\_URL -Plant details. +SunWEG API URL - + -#### \_\_init\_\_ +#### SUNWEG\_LOGIN\_PATH -```python -def __init__(id: int, name: str, total_power: float, kwh_per_kwp: float, - performance_rate: float, saving: float, today_energy: float, - today_energy_metric: str, total_energy: float, - total_carbon_saving: float, last_update: datetime) -> None -``` +SunWEG API login path -Initialize Plant. + -**Arguments**: +#### SUNWEG\_PLANT\_LIST\_PATH -- `id` (`int`): plant id -- `name` (`str`): plant name -- `total_power` (`float`): plant total power -- `kwh_per_kwp` (`float`): plant kWh/kWp -- `performance_rate` (`float`): plant performance rate -- `saving` (`float`): total saving in R$ -- `today_energy` (`float`): today generated energy -- `today_energy_metric` (`str`): today generated energy metric -- `total_energy` (`float`): total generated energy in kWh -- `total_carbon_saving` (`float`): total of CO2 saved -- `last_update` (`datetime`): when the data was updated +SunWEG API list plants path - + -#### id +#### SUNWEG\_PLANT\_DETAIL\_PATH -```python -@property -def id() -> int -``` +SunWEG API plant details path -Get plant id. + -**Returns**: +#### SUNWEG\_INVERTER\_DETAIL\_PATH -`int`: plant id +SunWEG API inverter details path - + -#### name +#### SUNWEG\_MONTH\_STATS\_PATH -```python -@property -def name() -> str -``` +SunWEG API month history path -Get plant name. + -**Returns**: +# sunweg.api -`str`: plant name +API Helper. - + -#### total\_power +## SunWegApiError Objects ```python -@property -def total_power() -> float +class SunWegApiError(RuntimeError) ``` -Get plant total power. +API Error. -**Returns**: + -`float`: plant total power +## LoginError Objects - +```python +class LoginError(SunWegApiError) +``` -#### kwh\_per\_kwp +Login Error. + + + +#### convert\_situation\_status ```python -@property -def kwh_per_kwp() -> float +def convert_situation_status(situation: int) -> Status ``` -Get plant kWh/kWp. +Convert situation to status. + +**Arguments**: + +- `situation` (`int`): situation **Returns**: -`float`: plant kWh/kWp +`Status`: equivalent status - + -#### performance\_rate +#### separate\_value\_metric ```python -@property -def performance_rate() -> float +def separate_value_metric(value_with_metric: str | None, + default_metric: str = "") -> tuple[float, str] ``` -Get plant performance rate. +Separate the value from the metric. + +**Arguments**: + +- `value_with_metric` (`str | None`): value with metric separated by space +- `default_metric` (`str`): metric that should be returned if `value_with_metric` is None **Returns**: -`float`: plant performance rate +`tuple[float, str]`: tuple with value and metric - + -#### saving +## APIHelper Objects ```python -@property -def saving() -> float +class APIHelper() ``` -Get plant saving in R$. - -**Returns**: - -`float`: plant saving in R$ +Class to call sunweg.net api. - + -#### today\_energy +#### \_\_init\_\_ ```python -@property -def today_energy() -> float +def __init__(username: str, password: str) -> None ``` -Get plant today generated energy. +Initialize APIHelper for SunWEG platform. -**Returns**: +**Arguments**: -`float`: plant today generated energy +- `username` (`str`): username for authentication +- `password` (`str`): password for authentication - + -#### today\_energy\_metric +#### authenticate ```python -@property -def today_energy_metric() -> str +def authenticate() -> bool ``` -Get plant today generated energy metric. +Authenticate with provided username and password. **Returns**: -`str`: plant today generated energy metric +`bool`: True on authentication success - + -#### total\_energy +#### listPlants ```python -@property -def total_energy() -> float +def listPlants(retry=True) -> list[Plant] ``` -Get plant total generated energy in kWh. +Retrieve the list of plants with incomplete inverter information. + +You may want to call `complete_inverter()` to complete the Inverter information. + +**Arguments**: + +- `retry` (`bool`): reauthenticate if token expired and retry **Returns**: -`float`: plant total generated energy in kWh +`list[Plant]`: list of Plant - + -#### total\_carbon\_saving +#### plant ```python -@property -def total_carbon_saving() -> float +def plant(id: int, retry=True) -> Plant | None ``` -Get plant total of CO2 saved. +Retrieve plant detail by plant id. + +**Arguments**: + +- `id` (`int`): plant id +- `retry` (`bool`): reauthenticate if token expired and retry **Returns**: -`float`: plant total of CO2 saved +`Plant | None`: Plant or None if `id` not found. - + -#### last\_update +#### inverter ```python -@property -def last_update() -> datetime +def inverter(id: int, retry=True) -> Inverter | None ``` -Get when the plant data was updated. +Retrieve inverter detail by inverter id. + +**Arguments**: + +- `id` (`int`): inverter id +- `retry` (`bool`): reauthenticate if token expired and retry **Returns**: -`datetime`: when the plant data was updated +`Inverter | None`: Inverter or None if `id` not found. - + -#### inverters +#### complete\_inverter ```python -@property -def inverters() -> list[Inverter] +def complete_inverter(inverter: Inverter, retry=True) -> None ``` -Get list of plant's inverters. +Complete inverter data. -**Returns**: +**Arguments**: -`list[Inverter]`: list of inverters +- `inverter` (`Inverter`): inverter object to be completed with information +- `retry` (`bool`): reauthenticate if token expired and retry - + -#### \_\_str\_\_ +#### month\_stats\_production ```python -def __str__() -> str +def month_stats_production(year: int, + month: int, + plant: Plant, + inverter: Inverter | None = None, + retry: bool = True) -> list[ProductionStats] ``` -Cast Plant to str. - - - -# sunweg.const - -Sunweg API constants. - - - -#### SUNWEG\_URL - -SunWEG API URL - - - -#### SUNWEG\_LOGIN\_PATH - -SunWEG API login path - - - -#### SUNWEG\_PLANT\_LIST\_PATH - -SunWEG API list plants path - - +Retrieve month energy production statistics. -#### SUNWEG\_PLANT\_DETAIL\_PATH +**Arguments**: -SunWEG API plant details path +- `year` (`int`): statistics year +- `month` (`int`): statistics month +- `plant` (`Plant`): statistics plant +- `inverter` (`Inverter | None`): statistics inverter, None for every inverter +- `retry` (`bool`): reauthenticate if token expired and retry - +**Returns**: -#### SUNWEG\_INVERTER\_DETAIL\_PATH +`list[ProductionStats]`: list of daily energy production statistics -SunWEG API inverter details path + - +#### month\_stats\_production\_by\_id -#### SUNWEG\_MONTH\_STATS\_PATH +```python +def month_stats_production_by_id(year: int, + month: int, + plant_id: int, + inverter_id: int | None = None, + retry: bool = True) -> list[ProductionStats] +``` -SunWEG API month history path +Retrieve month energy production statistics. - +**Arguments**: -# sunweg.util +- `year` (`int`): statistics year +- `month` (`int`): statistics month +- `plant_id` (`int`): id of statistics plant +- `inverter_id` (`int | None`): id of statistics inverter, None for every inverter +- `retry` (`bool`): reauthenticate if token expired and retry -Sunweg API util. +**Returns**: - +`list[ProductionStats]`: list of daily energy production statistics -## Status Objects + -```python -class Status(Enum) -``` +# sunweg.plant -Status enum. +Sunweg API plant. - + -## ProductionStats Objects +## Plant Objects ```python -class ProductionStats() +class Plant() ``` -Energy production statistics +Plant details. - + #### \_\_init\_\_ ```python -def __init__(date: date, production: float, prognostic: float) -> None +def __init__(id: int, name: str, total_power: float, kwh_per_kwp: float, + performance_rate: float, saving: float, today_energy: float, + today_energy_metric: str, total_energy: float, + total_carbon_saving: float, last_update: datetime | None) -> None ``` -Initialize energy production statistics. +Initialize Plant. **Arguments**: -- `date` (`date`): statistics date -- `production` (`float`): statistics production in kWh -- `prognostic`: statistics expected production in kWh +- `id` (`int`): plant id +- `name` (`str`): plant name +- `total_power` (`float`): plant total power +- `kwh_per_kwp` (`float`): plant kWh/kWp +- `performance_rate` (`float`): plant performance rate +- `saving` (`float`): total saving in R$ +- `today_energy` (`float`): today generated energy +- `today_energy_metric` (`str`): today generated energy metric +- `total_energy` (`float`): total generated energy in kWh +- `total_carbon_saving` (`float`): total of CO2 saved +- `last_update` (`datetime | None`): when the data was updated - + -#### date +#### id ```python @property -def date() -> date +def id() -> int ``` -Get date. +Get plant id. - +**Returns**: -#### production +`int`: plant id + + + +#### name ```python @property -def production() -> float +def name() -> str ``` -Get energy production in kWh. +Get plant name. - +**Returns**: -#### prognostic +`str`: plant name + + + +#### total\_power ```python @property -def prognostic() -> float +def total_power() -> float ``` -Get expected energy production in kWh. +Get plant total power. - +**Returns**: -#### \_\_str\_\_ +`float`: plant total power + + + +#### kwh\_per\_kwp ```python -def __str__() -> str +@property +def kwh_per_kwp() -> float ``` -Cast Phase to str. - - +Get plant kWh/kWp. -# sunweg.api +**Returns**: -API Helper. +`float`: plant kWh/kWp - + -## SunWegApiError Objects +#### performance\_rate ```python -class SunWegApiError(RuntimeError) +@property +def performance_rate() -> float ``` -API Error. +Get plant performance rate. - +**Returns**: -## LoginError Objects +`float`: plant performance rate + + + +#### saving ```python -class LoginError(SunWegApiError) +@property +def saving() -> float ``` -Login Error. +Get plant saving in R$. - +**Returns**: -#### convert\_situation\_status +`float`: plant saving in R$ -```python -def convert_situation_status(situation: int) -> Status -``` + -Convert situation to status. +#### today\_energy -**Arguments**: +```python +@property +def today_energy() -> float +``` -- `situation` (`int`): situation +Get plant today generated energy. **Returns**: -`Status`: equivalent status +`float`: plant today generated energy - + -#### separate\_value\_metric +#### today\_energy\_metric ```python -def separate_value_metric(value_with_metric: str | None, - default_metric: str = "") -> tuple[float, str] +@property +def today_energy_metric() -> str ``` -Separate the value from the metric. - -**Arguments**: - -- `value_with_metric` (`str | None`): value with metric separated by space -- `default_metric` (`str`): metric that should be returned if `value_with_metric` is None +Get plant today generated energy metric. **Returns**: -`tuple[float, str]`: tuple with value and metric +`str`: plant today generated energy metric - + -## APIHelper Objects +#### total\_energy ```python -class APIHelper() +@property +def total_energy() -> float ``` -Class to call sunweg.net api. +Get plant total generated energy in kWh. - +**Returns**: -#### \_\_init\_\_ +`float`: plant total generated energy in kWh + + + +#### total\_carbon\_saving ```python -def __init__(username: str, password: str) -> None +@property +def total_carbon_saving() -> float ``` -Initialize APIHelper for SunWEG platform. +Get plant total of CO2 saved. -**Arguments**: +**Returns**: -- `username` (`str`): username for authentication -- `password` (`str`): password for authentication +`float`: plant total of CO2 saved - + -#### authenticate +#### last\_update ```python -def authenticate() -> bool +@property +def last_update() -> datetime | None ``` -Authenticate with provided username and password. +Get when the plant data was updated. **Returns**: -`bool`: True on authentication success +`datetime | None`: when the plant data was updated - + -#### listPlants +#### inverters ```python -def listPlants(retry=True) -> list[Plant] +@property +def inverters() -> list[Inverter] ``` -Retrieve the list of plants with incomplete inverter information. - -You may want to call `complete_inverter()` to complete the Inverter information. - -**Arguments**: - -- `retry` (`bool`): reauthenticate if token expired and retry +Get list of plant's inverters. **Returns**: -`list[Plant]`: list of Plant +`list[Inverter]`: list of inverters - + -#### plant +#### \_\_str\_\_ ```python -def plant(id: int, retry=True) -> Plant | None +def __str__() -> str ``` -Retrieve plant detail by plant id. - -**Arguments**: +Cast Plant to str. -- `id` (`int`): plant id -- `retry` (`bool`): reauthenticate if token expired and retry + -**Returns**: +# sunweg.util -`Plant | None`: Plant or None if `id` not found. +Sunweg API util. - + -#### inverter +## Status Objects ```python -def inverter(id: int, retry=True) -> Inverter | None +class Status(Enum) ``` -Retrieve inverter detail by inverter id. +Status enum. -**Arguments**: + -- `id` (`int`): inverter id -- `retry` (`bool`): reauthenticate if token expired and retry +## ProductionStats Objects -**Returns**: +```python +class ProductionStats() +``` -`Inverter | None`: Inverter or None if `id` not found. +Energy production statistics - + -#### complete\_inverter +#### \_\_init\_\_ ```python -def complete_inverter(inverter: Inverter, retry=True) -> None +def __init__(date: date, production: float, prognostic: float) -> None ``` -Complete inverter data. +Initialize energy production statistics. **Arguments**: -- `inverter` (`Inverter`): inverter object to be completed with information -- `retry` (`bool`): reauthenticate if token expired and retry +- `date` (`date`): statistics date +- `production` (`float`): statistics production in kWh +- `prognostic`: statistics expected production in kWh - + -#### month\_stats\_production +#### date ```python -def month_stats_production(year: int, - month: int, - plant: Plant, - inverter: Inverter | None = None, - retry: bool = True) -> list[ProductionStats] +@property +def date() -> date ``` -Retrieve month energy production statistics. +Get date. -**Arguments**: + -- `year` (`int`): statistics year -- `month` (`int`): statistics month -- `plant` (`Plant`): statistics plant -- `inverter` (`Inverter | None`): statistics inverter, None for every inverter -- `retry` (`bool`): reauthenticate if token expired and retry +#### production -**Returns**: +```python +@property +def production() -> float +``` -`list[ProductionStats]`: list of daily energy production statistics +Get energy production in kWh. - + -#### month\_stats\_production\_by\_id +#### prognostic ```python -def month_stats_production_by_id(year: int, - month: int, - plant_id: int, - inverter_id: int | None = None, - retry: bool = True) -> list[ProductionStats] +@property +def prognostic() -> float ``` -Retrieve month energy production statistics. +Get expected energy production in kWh. -**Arguments**: + -- `year` (`int`): statistics year -- `month` (`int`): statistics month -- `plant_id` (`int`): id of statistics plant -- `inverter_id` (`int | None`): id of statistics inverter, None for every inverter -- `retry` (`bool`): reauthenticate if token expired and retry +#### \_\_str\_\_ -**Returns**: +```python +def __str__() -> str +``` -`list[ProductionStats]`: list of daily energy production statistics +Cast Phase to str. diff --git a/setup.py b/setup.py index dd974ba..f6137e2 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,6 @@ #!/bin/python """setup sunweg.""" + import setuptools with open("README.md", "r") as fh: @@ -11,7 +12,7 @@ setuptools.setup( name="sunweg", - version="2.1.0", + version="2.1.1", author="rokam", author_email="lucas@mindello.com.br", description="A library to retrieve data from sunweg.net",