-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix building list and client information (#17)
* updatin seed client to set seed org name * add get_property and get_property_view, return all results for get_buildings * fix client_information api * fix mypy * only build pull requests and dev/main push * seed_org_name not none * test both property results * fix comment about filter Co-authored-by: kflemin <[email protected]>
- Loading branch information
Showing
6 changed files
with
89 additions
and
42 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ name: CI | |
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- "develop" | ||
- "main" | ||
|
||
jobs: | ||
test: | ||
|
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 |
---|---|---|
|
@@ -89,16 +89,17 @@ def __init__( | |
) | ||
|
||
# favor the connection params over the config file | ||
self.payload = {} | ||
if connection_params: | ||
# the connetion params are simply squashed on SEEDReadWriteClient init | ||
payload = connection_params | ||
self.payload = connection_params | ||
elif connection_config_filepath: | ||
payload = SeedClientWrapper.read_connection_config_file( | ||
self.payload = SeedClientWrapper.read_connection_config_file( | ||
connection_config_filepath | ||
) | ||
# read in from config file | ||
|
||
self.client = SEEDReadWriteClient(organization_id, **payload) | ||
self.client = SEEDReadWriteClient(organization_id, **self.payload) | ||
|
||
@classmethod | ||
def read_connection_config_file(cls, filepath: Path) -> dict: | ||
|
@@ -114,7 +115,8 @@ def read_connection_config_file(cls, filepath: Path) -> dict: | |
"username": "[email protected]", | ||
"api_key": "1b5ea1ee220c8628789c61d66253d90398e6ad03", | ||
"port": 8000, | ||
"use_ssl": false | ||
"use_ssl": false, | ||
"seed_org_name: "test-org" | ||
} | ||
Args: | ||
|
@@ -139,6 +141,35 @@ def __init__( | |
) -> None: | ||
super().__init__(organization_id, connection_params, connection_config_filepath) | ||
|
||
# set org if you can | ||
if self.payload and self.payload.get('seed_org_name', None): | ||
self.get_org_by_name(self.payload['seed_org_name'], set_org_id=True) | ||
|
||
def get_org_id(self) -> int: | ||
"""Return the org ID that is set""" | ||
return self.client.org_id | ||
|
||
def get_org_by_name(self, org_name: str, set_org_id: bool = False) -> dict: | ||
"""Set the current organization by name. | ||
Args: | ||
org_name (str): name of the organization to set | ||
set_org_id (bool): set the org_id on the object for later use. Defaults to None. | ||
Returns: | ||
dict: { | ||
org data | ||
} | ||
""" | ||
orgs = self.get_organizations() | ||
for org in orgs: | ||
if org["name"] == org_name: | ||
if set_org_id: | ||
self.client.org_id = org["id"] | ||
return org | ||
|
||
raise ValueError(f"Organization '{org_name}' not found") | ||
|
||
def instance_information(self) -> dict: | ||
"""Return the instance information. | ||
|
@@ -179,21 +210,25 @@ def get_organizations(self, brief: bool = True) -> Dict: | |
) | ||
return orgs | ||
|
||
def get_buildings(self) -> list: | ||
self.client.list(endpoint="properties", data_name="pagination", per_page=1)[ | ||
"total" | ||
] | ||
buildings = self.client.list( | ||
endpoint="properties", | ||
data_name="results", | ||
per_page=100, | ||
cycle=self.cycle_id, | ||
) | ||
def get_buildings(self) -> List[dict]: | ||
total_qry = self.client.list(endpoint="properties", data_name="pagination", per_page=100) | ||
|
||
# print(f" total: {total_qry}") | ||
# step through each page of the results | ||
buildings: List[dict] = [] | ||
for i in range(1, total_qry['num_pages'] + 1): | ||
buildings = buildings + self.client.list( | ||
endpoint="properties", | ||
data_name="results", | ||
per_page=100, | ||
page=i, | ||
cycle=self.cycle_id, | ||
) | ||
# print(f"number of buildings retrieved: {len(buildings)}") | ||
|
||
# TODO: what to do with this if paginated? | ||
return buildings | ||
|
||
def get_property(self, property_view_id: int) -> dict: | ||
def get_property_view(self, property_view_id: int) -> dict: | ||
"""Return a single property (view and state) by the property view id. | ||
Args: | ||
|
@@ -213,6 +248,29 @@ def get_property(self, property_view_id: int) -> dict: | |
property_view_id, endpoint="property_views", data_name="property_views" | ||
) | ||
|
||
def get_property(self, property_id: int) -> dict: | ||
"""Return a single property by the property id. | ||
Args: | ||
property__id (int): ID of the property to return. This is the ID that is in the URL http://SEED_URL/app/#/properties/{property_view_id} | ||
Returns: | ||
dict: { | ||
'state': { | ||
'extra_data': {}, | ||
}, | ||
'cycle': {...}, | ||
'property': {...}, | ||
'labels': {...}, | ||
'measures': {...} | ||
... | ||
} | ||
""" | ||
# NOTE: this seems to be the call that OEP uses (returns property and labels dictionaries) | ||
return self.client.get( | ||
property_id, endpoint="properties", data_name="properties" | ||
) | ||
|
||
def search_buildings( | ||
self, identifier_filter: str = None, identifier_exact: str = None | ||
) -> dict: | ||
|
@@ -584,27 +642,6 @@ def get_cycle_by_name(self, cycle_name: str, set_cycle_id: bool = None) -> dict: | |
|
||
raise ValueError(f"cycle '{cycle_name}' not found") | ||
|
||
def get_org_by_name(self, org_name: str, set_org_id: bool = False) -> dict: | ||
"""Set the current organization by name. | ||
Args: | ||
org_name (str): name of the organization to set | ||
set_org_id (bool): set the org_id on the object for later use. Defaults to None. | ||
Returns: | ||
dict: { | ||
org data | ||
} | ||
""" | ||
orgs = self.get_organizations() | ||
for org in orgs: | ||
if org["name"] == org_name: | ||
if set_org_id: | ||
self.client.org_id = org["id"] | ||
return org | ||
|
||
raise ValueError(f"Organization '{org_name}' not found") | ||
|
||
def delete_cycle(self, cycle_id: str) -> dict: | ||
"""Delete the cycle. This will only work if there are no properties or tax lots in the cycle | ||
|
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