Skip to content

Conversation

@chestm007
Copy link
Contributor

@chestm007 chestm007 commented Aug 20, 2025

Description

Attempt at de-duping, tidying, and a slight restructure. Alot of the query body is now self generated by the objects themselves, I think its easily extendable, but im probably biased.

Associated tasks

None.

Test Steps

any code that worked before, should work exactly the same aside from needing the eas_client constructor to be changed to include auth

Checklist

If any of these are not applicable, strikethrough the line ~like this~. Do not delete it!. Let the reviewer decide if you should have done it.

Code

  • I have performed a self review of my own code (including checking issues raised when creating the PR).
  • I have added/updated unit tests for these changes, and if not I have explained why they are not necessary.
  • I have commented my code in any hard-to-understand or hacky areas.
  • I have handled all new warnings generated by the compiler or IDE.
  • I have rebased onto the target branch (usually main).

Security

When developing applications, use following guidelines for information security considerations:

  • Access to applications should be protected with security keys/tokens or usernames and passwords;
  • All sessions are encrypted if possible;
  • All application input is sanitised before being acted on (ie SQL statements, etc);
  • Log messages, and especially client-facing ones, must be handled securely and must not leak credentials information (internal URLs, passwords, tokens).
  • I have considered if this change impacts information security and made sure those impacts are handled.

Documentation

  • I have updated the changelog.
  • I have updated any documentation required for these changes.

Breaking Changes

  • I have considered if this is a breaking change and will communicate it with other team members by posting it on the Slack breaking-changes channel.

Please leave a summary of the breaking changes here and then post it on the Slack breaking-changes channel to notify the team about it.

  • EasClient will now need auth= passed with an auth object. either BaseAuthMethod or TokenAuth, this allows cleaner documenting of accepted constructor arguments.

@kgreav
Copy link
Member

kgreav commented Aug 20, 2025

i think your changes were meant to be on ewb-network-routes?
haha bad troll... just saw your other PR

Copy link
Member

@vincewhite vincewhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not full review. Just random comments.

## [0.23.0] - UNRELEASED
### Breaking Changes
* None.
* EasClient will now need `auth=` passed with an auth object. either `BaseAuthMethod` or `TokenAuth`, this allows
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This task should probably include the PR to update to this happy little repo: https://github.com/zepben/hosting-capacity-runner , maybe https://github.com/zepben/ewb-sdk-examples-python as well?


def get_hosting_capacity_calibration_run(self, id: str):
def get_hosting_capacity_calibration_run(self, id_: str) -> dict:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably has to be mentioned as a breaking change?

:param client_id: The Auth0 client ID used to specify to the auth server which application to request a token for.
:param client_secret: The Auth0 client secret used for M2M authentication.
"""
...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this magic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allows you to define multiple combinations of var/types to pass to the non @overloaded init.
Makes type hinting pick up when people have put a bad combination of auth params that would throw an error anyway.

@chestm007 chestm007 changed the title The great refactor The great refactor [EWB-4557] Aug 25, 2025
@ryanjcoleman
Copy link
Member

@chestm007 chestm007 force-pushed the the-great-refactor branch 2 times, most recently from b3c5406 to 7fd17c8 Compare August 27, 2025 07:39
Signed-off-by: Max Chesterfield <[email protected]>
tests pass

Signed-off-by: Max Chesterfield <[email protected]>
Signed-off-by: Max Chesterfield <[email protected]>
Signed-off-by: Max Chesterfield <[email protected]>
Copy link
Member

@vincewhite vincewhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

half review, run out of time.

Comment on lines +1 to +2
from zepben.eas.client.auth_method import TokenAuth

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from zepben.eas.client.auth_method import TokenAuth

json_serialiser=None


class BaseAuthMethod:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is actually the connection that an authenticated connection is an extension on top of? To connect to an EAS without authentication I'm still required to pass a auth = BaseAuthMethod(host = ...) since it holds the connection/EAS host details.

This also makes it less optional than is suggested in the eas_client.py

elif not response.ok:
response.raise_for_status()

def _do_request(self): # TODO: can this just be called once per run?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely

response.raise_for_status()

@catch_warnings
async def _do_get_request(self, *, run_id: int): # TODO: Terrible name probably
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least there is a matching _do_post_request(), for _get_request_headers() you just have to hope _get doesn't refer to HTTP GET.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...but also this seems hardcoded to retrieve opendss-models so yeh...

return get_event_loop().run_until_complete(self.async_get_opendss_model(model_id))

async def async_get_opendss_model(self, model_id: int):
async def async_get_opendss_model(self, model_id: int) -> dict: # TODO: this logic should be hidden behind a generator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone should update the backend to provide this functionality...


@dataclass
class HostingCapacityDataclass(ABC): # TODO: Another terrible name
_snake_to_camel_overrides = dict(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anyway these can be tested to confirm someone didn't forget to add an override when they were adding new fields.

Comment on lines +75 to +83
def __del__(self):
self.close()

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.close()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume these call close when this the object is deleted/unneeded etc/used by other things. Should we be closing the session if it was passed into the eas client/would this be the least unexpected behaviour?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants