Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async def main():
async with ClientSession() as websession:
try:
soliscloud = SoliscloudAPI(
'https://soliscloud.com:13333', websession)
SoliscloudAPI.DEFAULT_DOMAIN, websession)

# Retrieve list of Stations, a.k.a. plants
station_list = await soliscloud.user_station_list(
Expand Down
50 changes: 33 additions & 17 deletions example_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
attributes of the plant, inverters and collectors.

There are 2 ways to create the entity classes:
1. Use the class method 'initialize_from_data' to create entity instances
1. Use the class method 'from_data' to create entity instances
from data retrieved from the API. It will create one or more entity
instances from the data passed in. This method will not retrieve any data
from the API, so you need to do that yourself first. It will not
recursively create all entities, i.e. plants, inverters and collectors.
You need to call it separately for each entity class.
2. Use the class method 'initialize_from_session' to create entity instances
2. Use the class method 'from_session' to create entity instances
by passing in the aiohttp session and API credentials. This method will
retrieve the data from the API and create the entity instances. It
will recursively create all entities, i.e. plants, inverters
Expand Down Expand Up @@ -51,24 +51,30 @@ async def main():

async with ClientSession() as websession:
try:
the_api = api('https://soliscloud.com:13333', websession)
data = await the_api.inverter_list(
the_api = api(api.DEFAULT_DOMAIN, websession)
plants = await Plant.from_session(
websession, api_key, api_secret)
# Whole entity tree is now created, print it out
print("*** from_session ***")
print(plants[0])
# Alternatively, get started by getting data from API
# and then create entity instances from that data.
plant_data = await the_api.station_detail_list(
api_key, api_secret, page_no=1, page_size=100)
# use plant_id of your own plant here to get inverters for that plant
plants = Plant.from_data(plant_data)
# use plant_id of your own plant here to get inverters
# for that plant.
# use inverter_id to only get one specific inverter
inverters = Inverter.initialize_from_data(
data, plant_id='your plant id goes here')
plants = await Plant.initialize_from_session(
websession, api_key, api_secret)
except (
SoliscloudError,
SoliscloudHttpError,
SoliscloudTimeoutError,
SoliscloudApiError,
) as error:
print(f"Error: {error}")
else:
inverter_data = await the_api.inverter_list(
api_key, api_secret, page_no=1, page_size=100)
inverters = Inverter.from_data(
inverter_data, plant_id=plants[0].plant_id)
plants[0].add_inverters(inverters)
print("\n*** from_data ***")
print(plants[0])
p = plants[0]
# Now access some attributes of the entities
print("\n*** Accessing attributes ***")
print(f"Plant id: {p.plant_id}")
print(f"Plant name: {p.data['station_name']}")
print(f"Number of inverters: {len(p.inverters)}")
Expand All @@ -77,9 +83,19 @@ async def main():
# The attributes if the inverter are in inv.data
# If an attribute has a unit then the value is of
# dimensioned type
print(f"Inverter state: {inv.data['state']}")
# Print full energy type attribute
print(f"Total energy: {inv.data['etotal']}")
# print value and unit separately
print(f"Total energy value: {inv.data['etotal'].value}")
print(f"Total energy unit: {inv.data['etotal'].unit}")
except (
SoliscloudError,
SoliscloudHttpError,
SoliscloudTimeoutError,
SoliscloudApiError,
) as error:
print(f"Error: {error}")
loop = asyncio.new_event_loop()
loop.run_until_complete(main())
loop.close()
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "soliscloud-api"
version = "1.3.0"
version = "1.4.0"
authors = [
{ name="Peter van Hulten", email="peter.vanhulten@gmx.net" },
]
Expand Down Expand Up @@ -33,3 +33,9 @@ exclude = ["soliscloud_api.tests*"]

[tool.setuptools.packages.find]
exclude = ["soliscloud_api.tests*"]

[tool.pytest.ini_options]
#addopts = ["--disable-warnings"]
testpaths = ["test"]
asyncio_default_fixture_loop_scope = "function"

1 change: 1 addition & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ asyncio
aiohttp
pytest-mock
pytest-asyncio
pytest-cov
throttler
11 changes: 10 additions & 1 deletion soliscloud_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
from .client import SoliscloudError, SoliscloudHttpError # noqa: F401
from .client import SoliscloudTimeoutError, SoliscloudApiError # noqa: F401
from .entities import Plant, Inverter, Collector # noqa: F401
from .types import ( # noqa: F401
EntityType,
State,
InverterOfflineState,
InverterType,
PlantType,
CollectorState
)
from .helpers import Helpers # noqa: F401

# VERSION
VERSION = '1.3.0'
VERSION = '1.4.0'
__version__ = VERSION
Loading