Skip to content

Comments

Main API cleanup. Breaking changes#198

Merged
sveinse merged 3 commits intocustom-components:masterfrom
sveinse:feature-api-improvements
Jul 16, 2025
Merged

Main API cleanup. Breaking changes#198
sveinse merged 3 commits intocustom-components:masterfrom
sveinse:feature-api-improvements

Conversation

@sveinse
Copy link
Collaborator

@sveinse sveinse commented Jul 16, 2025

  • class Zaptec

    • Make class Zaptec an async context in order to close the web session
    • Make the class a Mapping of (Zaptec) objects with dict-like interface.
    • Mapping changes must go via register and unregister.
    • register will fail on re-registeringing an existing object
    • Add .objects(), .installations and chargers as methods to fetch subset of data from the class
    • .build() can be called multiple times. If run again it will update the existing objects
    • Stop exposing .map
    • Remove get_circuits_id(). Its too specialized and is handled directly where its used.
    • .get_chargers() is not the property .chargers
    • .installations is now a property and not a variable
    • Add warnings on removal of or standalone chargers. We don't handle this yet.
  • class ZaptecBase

    • Make class ZaptecBase a Mapping with a RO dict-like interface for parameters
    • Removed .__getattr__() so obj.something doesn't work. However .id and .name is explicitly kept.
  • class Installation

    • Update .build() to support re-runs without creating new objects
  • class Charger

    • Remove unused .live() method
    • Remove empty .build() method
  • General

    • Cleanup and reorganization
    • Adopt the HA integration to the API changes

* class Zaptec
  * Make class Zaptec an async context in order to close the web session
  * Make the class a `Mapping` of (Zaptec) objects with dict-like interface.
  * Mapping changes must go via `register` and `unregister`.
  * `register` will fail on re-registeringing an existing object
  * Add `.objects()`, `.installations` and `chargers` as methods to fetch subset of data from the class
  * `.build()` can be called multiple times. If run again it will update the existing objects
  * Stop exposing `.map`
  * Remove `get_circuits_id()`. Its too specialized and is handled directly where its used.
  * `.get_chargers()` is not the property `.chargers`
  * `.installations` is now a property and not a variable
  * Add warnings on removal of or standalone chargers. We don't handle this yet.

* class ZaptecBase
  * Make class ZaptecBase a `Mapping` with a RO dict-like interface for parameters
  * Removed `.__getattr__()` so `obj.something` doesn't work. However `.id` and `.name` is explicitly kept.

* class Installation
  * Update `.build()` to support re-runs without creating new objects

* class Charger
  * Remove unused `.live()` method
  * Remove empty `.build()` method

* General
  * Cleanup and reorganization
  * Adopt the HA integration to the API changes
@sveinse
Copy link
Collaborator Author

sveinse commented Jul 16, 2025

@steinmn I'm shooting from the hip here, but I would really appreciate if you could take a look at this one. It's not a small one, so I'm grateful if you have the time and opportunity. This is out of the blue, so please feel free to ignore if it doesn't.

It's a major lift on the overall methods and API for the classes in the Zaptec-facing api.

@sveinse sveinse added this to the v0.8 milestone Jul 16, 2025
Copy link
Contributor

@steinmn steinmn left a comment

Choose a reason for hiding this comment

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

I'm a bit too unfamiliar with async to fully grasp everything going on, but apart from a couple of nitpicks, the rest looks good to me 👍

_LOGGER.warning("To remove them, please restart the integration.")
if extra_chargers := (new_chargers - have_chargers):
_LOGGER.warning(
"These standalone chargers will not added: %s", extra_chargers
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"These standalone chargers will not added: %s", extra_chargers
"These standalone chargers will not be added: %s", extra_chargers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. Good catch.

charger = Charger(charger_item, self.zaptec, installation=self)
self.zaptec.register(charger_item["Id"], charger)

await charger.build()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this? charger.build() still does nothing, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I first argued that it should be there for consistency. But then I was thinking that if we need something to happen in Charger.build() we have to run a PR for it, so why not also update this part then? So I removed it.

@sveinse sveinse merged commit 25f950c into custom-components:master Jul 16, 2025
1 check passed
@sveinse sveinse deleted the feature-api-improvements branch July 16, 2025 21:40
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.

2 participants