Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new integration for WMS WebControl pro using local API #124176

Merged
merged 8 commits into from
Sep 16, 2024

Conversation

mback2k
Copy link
Contributor

@mback2k mback2k commented Aug 18, 2024

Proposed change

Warema recently released a new local API for their WMS hub called "WebControl pro". This integration makes use of the new local API via a new dedicated Python library pywmspro.

For now this integration only supports awnings as covers, but pywmspro is device-agnostic to ease extensions. I will try to add support for more devices in future PRs. I have already developed and tested lights and scenes locally.

Python library: https://github.com/mback2k/pywmspro and https://pypi.org/project/pywmspro/
Official API documentation, unfortunately only available in German at the moment:
https://media.warema.com/dokumente/anleitungen-handbuecher/966664/warema_2064534_alhb_de_v0.pdf

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

Copy link

@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

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

@mback2k
Copy link
Contributor Author

mback2k commented Aug 18, 2024

When adding new integrations, limit included platforms to a single platform. Please reduce this PR to a single platform

Is this a must or a should? I am asking this, because I tried to limit the amount of platforms/devices to a useful minimum for the initial PR. Which platform should I keep to introduce this integration to Home Assistant?

Human reviewers, please consider that the WMS WebControl pro is a hub/gateway with support for various devices types, similar to Homematic IP for example.

@mback2k
Copy link
Contributor Author

mback2k commented Aug 22, 2024

When adding new integrations, limit included platforms to a single platform. Please reduce this PR to a single platform

Is this a must or a should? I am asking this, because I tried to limit the amount of platforms/devices to a useful minimum for the initial PR. Which platform should I keep to introduce this integration to Home Assistant?

Human reviewers, please consider that the WMS WebControl pro is a hub/gateway with support for various devices types, similar to Homematic IP for example.

Okay, I just updated this PR to only include support for scenes for now.

@joostlek
Copy link
Member

I'd recommend using a stateful platform first like light or cover

@mback2k
Copy link
Contributor Author

mback2k commented Aug 26, 2024

I will follow up with cover and light in separate PRs since I have it ready locally, but scenes would allow at least versatile indirect control already.

@mback2k mback2k marked this pull request as ready for review August 26, 2024 04:07
@joostlek
Copy link
Member

Yes, but handling a state in your integration is probably the most interesting part which also defines how your data flows between entities, while a scene is just something you can turn on. So I'd rather pick a more complex one to make sure we make the best choices to keep the integration extendable and efficient

@mback2k
Copy link
Contributor Author

mback2k commented Aug 26, 2024

Ok, will do the change then. Adding more than one platform is not an option right? Because I have lights, awnings and scenes fully working. Rotating PR content and documentation is quite cumbersome.

@mback2k
Copy link
Contributor Author

mback2k commented Aug 27, 2024

Switched the PR from scenes to awnings as covers now.

Yes, but handling a state in your integration is probably the most interesting part which also defines how your data flows between entities

The cover platform now shows how pywmspro is used and that I followed the rules described in the developer docs. Communication to the hub is only done to perform actions or on an async_update call, otherwise entity/device information is retrieved from the local object in pywmspro. The class WebControlProGenericEntity is going to be the base for all entities/devices and illustrates this approach:

class WebControlProGenericEntity(Entity):
"""Foundation of all WMS based entities."""
_attr_attribution = ATTRIBUTION
_attr_has_entity_name = True
_attr_name = None
def __init__(self, dest: Destination) -> None:
"""Initialize the entity with destination channel."""
super().__init__()
self._dest = dest
async def async_update(self) -> None:
"""Update the entity."""
await self._dest.refresh()
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self.__class__.__name__}_{self._dest.id}"
@property
def available(self) -> bool:
"""Return if entity is available."""
return self._dest.available
@property
def device_info(self) -> DeviceInfo | None:
"""Return device specific attributes."""
return DeviceInfo(
identifiers={(DOMAIN, self.unique_id)},
manufacturer=MANUFACTURER,
model=self._dest.animationType.name,
name=self._dest.name,
serial_number=self._dest.id,
suggested_area=self._dest.room.name,
via_device=(DOMAIN, self._dest.host),
configuration_url=f"http://{self._dest.host}/control",
)

@mback2k mback2k force-pushed the wmspro branch 3 times, most recently from ef7cbbd to f1f21d0 Compare August 28, 2024 13:41
@mback2k
Copy link
Contributor Author

mback2k commented Aug 28, 2024

The PR has reached 100% test coverage now 🎉

homeassistant/components/wmspro/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/cover.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/diagnostics.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/generic_entity.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/generic_entity.py Outdated Show resolved Hide resolved
homeassistant/components/wmspro/generic_entity.py Outdated Show resolved Hide resolved
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft August 30, 2024 11:04
@mback2k mback2k force-pushed the wmspro branch 2 times, most recently from d34613c to f9a2408 Compare September 2, 2024 20:16
@mback2k
Copy link
Contributor Author

mback2k commented Sep 4, 2024

Okay, I tried to incorporate more feedback. Can you please elaborate which of the parts regarding a) different mocking, b) parameterized tests and c) snapshot tests would be important/required to get this merged?

And of course I am now also curious why the cover component needs to be explicitly loaded/setup.

But I am done for today.

@joostlek
Copy link
Member

joostlek commented Sep 4, 2024

Understandable, have a good night, I will probably check the code out tomorrow. Do you have discord?

@mback2k
Copy link
Contributor Author

mback2k commented Sep 4, 2024

Yes, I am on Discord with the same username, just pinged you there. Have a good night, too.

Question to consider regarding the mocking for tomorrow: would it be okay if pywmspro provided a demo mock mode?

With that I mean, I could move the JSON fixtures there (since I will need to develop tests there anyway), add a simulation mode to the library classes and then use that during testing in HA.

@mback2k mback2k force-pushed the wmspro branch 3 times, most recently from 552c66c to db6a8b9 Compare September 11, 2024 19:06
@mback2k
Copy link
Contributor Author

mback2k commented Sep 11, 2024

I have now implemented everything except the requested complete change of mocking approach.

If the main reason for the requested mock style is to not touch library internals in HA tests, I would suggest to move this type of simulated mocking into the library as described above. This way end-to-end tests could be simulated.

@mback2k mback2k marked this pull request as ready for review September 11, 2024 20:28
@home-assistant home-assistant bot requested a review from joostlek September 11, 2024 20:28
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Last comments

homeassistant/components/wmspro/entity.py Outdated Show resolved Hide resolved
tests/components/wmspro/responses.py Outdated Show resolved Hide resolved
tests/components/wmspro/test_cover.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft September 13, 2024 12:40
mback2k and others added 8 commits September 13, 2024 21:22
Warema recently released a new local API for their WMS hub
called "WebControl pro". This integration makes use of the
new local API via a new dedicated Python library pywmspro.

For now this integration only supports awnings as covers.
But pywmspro is device-agnostic to ease future extensions.
@mback2k mback2k marked this pull request as ready for review September 13, 2024 19:59
@home-assistant home-assistant bot requested a review from joostlek September 13, 2024 19:59
@joostlek joostlek merged commit 587ebd5 into home-assistant:dev Sep 16, 2024
44 checks passed
@mback2k
Copy link
Contributor Author

mback2k commented Sep 16, 2024

Thanks a lot @joostlek !

@joostlek
Copy link
Member

Ugh, I always realize this too late. Let me double check if others think wmspro is a good domain name. It could be that others have a better opinion on it

@mback2k
Copy link
Contributor Author

mback2k commented Sep 16, 2024

Ugh, I always realize this too late. Let me double check if others think wmspro is a good domain name. It could be that others have a better opinion on it

Ah, good point. Alternatives could be "wmswebcontrolpro", "webcontrolpro", "warema_wms" or any more detailed combination of "Warema" as vendor, "WMS" as protocol and "WebControl pro" as required hub.

bealex pushed a commit to DevPocket/homeassistant-core that referenced this pull request Sep 16, 2024
…stant#124176)

* Add new integration for WMS WebControl pro using local API

Warema recently released a new local API for their WMS hub
called "WebControl pro". This integration makes use of the
new local API via a new dedicated Python library pywmspro.

For now this integration only supports awnings as covers.
But pywmspro is device-agnostic to ease future extensions.

* Incorporated review feedback from joostlek

Thanks a lot!

* Incorporated more review feedback from joostlek

Thanks a lot!

* Incorporated more review feedback from joostlek

Thanks a lot!

* Fix

* Follow-up fix

* Improve handling of DHCP discovery

* Further test improvements suggested by joostlek, thanks!

---------

Co-authored-by: Joostlek <joostlek@outlook.com>
@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants