Skip to content

Add support for Plugwise USB stick#44186

Closed
brefra wants to merge 18 commits intohome-assistant:devfrom
plugwise:plugwise-usb
Closed

Add support for Plugwise USB stick#44186
brefra wants to merge 18 commits intohome-assistant:devfrom
plugwise:plugwise-usb

Conversation

@brefra
Copy link
Copy Markdown
Contributor

@brefra brefra commented Dec 13, 2020

Proposed change

This PR is the successor of #35713 - adds support for legacy Plugwise Circle(+), and Stealth(+) devices.
These devices are controlled by using an USB-stick which communicates directly to the devices.
More details is written down in the related documentation PR.

We'll adhere to trying it small and per platform, so this PR only contains the switch platform to control the power relays.
In future PR's the other platforms will be added to support multiple sensors (mainly) related to the power consumption and also the legacy Scan device (motion detection sensor)

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)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example entry for configuration.yaml:

# Example configuration.yaml

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @CoMPaTech, @bouwew, mind taking a look at this pull request as its been labeled with an integration (plugwise) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

Copy link
Copy Markdown
Member

@CoMPaTech CoMPaTech left a comment

Choose a reason for hiding this comment

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

Looks good now - and most of this was in the previous PR as well as tested through our now also integrated custom_component by the beta-testers.

Copy link
Copy Markdown
Contributor

@bouwew bouwew left a comment

Choose a reason for hiding this comment

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

I agree, looking good. And tested by me as well.

@github-actions
Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 26, 2021
Comment on lines +79 to +92
stick = await self.async_add_executor_job(plugwise.stick, device_path)
try:
await self.async_add_executor_job(stick.connect)
await self.async_add_executor_job(stick.initialize_stick)
await self.async_add_executor_job(stick.disconnect)
except PortError:
errors[CONF_BASE] = "cannot_connect"
except StickInitError:
errors[CONF_BASE] = "stick_init"
except NetworkDown:
errors[CONF_BASE] = "network_down"
except TimeoutException:
errors[CONF_BASE] = "network_timeout"
return errors, stick
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please avoid all the jumps into the executor by wrapping them up in one function.

Copy link
Copy Markdown
Contributor

@bouwew bouwew Jan 30, 2021

Choose a reason for hiding this comment

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

@bdraco, first a question: why should this be avoided?

And, combining them in one function is not practical: there are 4 functions, we call use 3 of them here, and in usb.py we use all four of them but in a different combination.
Also, this happens in config_flow.py and usb.py, the functions in these 2 files are only called during init and when removing the integration, how much harm can that cause?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Switching from async to sync context is expensive. We should try to avoid doing it multiple times when we can do one call to the executor.

Comment on lines +65 to +70
_LOGGER.debug("Connect to USB-Stick")
await hass.async_add_executor_job(stick.connect)
_LOGGER.debug("Initialize USB-stick")
await hass.async_add_executor_job(stick.initialize_stick)
_LOGGER.debug("Discover Circle+ node")
await hass.async_add_executor_job(stick.initialize_circle_plus)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please avoid multiple jumps into the executor. Wrap them into a single function.

errors[CONF_BASE] = "already_configured"
return errors, None

stick = await self.async_add_executor_job(plugwise.stick, device_path)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it really necessary to call a class using async_add_executor_job()?

Maybe better to use from plugwise import stick
and then use something like api_stick = stick(device_path)?

@github-actions github-actions bot closed this Feb 6, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 7, 2021
@CoMPaTech CoMPaTech deleted the plugwise-usb branch March 13, 2022 18:59
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.

5 participants