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

Use button entity for pulse switches #245

Merged
merged 9 commits into from
Dec 18, 2021
Merged

Use button entity for pulse switches #245

merged 9 commits into from
Dec 18, 2021

Conversation

drc38
Copy link
Collaborator

@drc38 drc38 commented Dec 17, 2021

@lbbrhzn, I can't test on a live system at the moment. If you're able to on your charger before merging that'd be great.

@drc38 drc38 requested a review from lbbrhzn December 17, 2021 00:40
@lbbrhzn
Copy link
Owner

lbbrhzn commented Dec 17, 2021

I tried your branch, but it failed (see below). Let me known when I can try again.

2021-12-17 22:55:12 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry central for button
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/homeassistant/config_entries.py", line 313, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File "/usr/local/lib/python3.9/site-packages/homeassistant/components/button/init.py", line 64, in async_setup_entry
return await component.async_setup_entry(entry)
File "/usr/local/lib/python3.9/site-packages/homeassistant/helpers/entity_component.py", line 147, in async_setup_entry
platform = await async_prepare_setup_platform(
File "/usr/local/lib/python3.9/site-packages/homeassistant/setup.py", line 309, in async_prepare_setup_platform
platform = integration.get_platform(domain)
File "/usr/local/lib/python3.9/site-packages/homeassistant/loader.py", line 530, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/local/lib/python3.9/site-packages/homeassistant/loader.py", line 535, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1030, in _gcd_import
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "", line 790, in exec_module
File "", line 228, in _call_with_frames_removed
File "/config/custom_components/ocpp/button.py", line 19, in
class OcppButtonDescription(ButtonEntityDescription):
File "/config/custom_components/ocpp/button.py", line 22, in OcppButtonDescription
press_action: str | None = None
TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

class OcppButtonDescription(ButtonEntityDescription):
"""Class to describe a Button entity."""

press_action: str | None = None
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand this | None syntax.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Neither did I, I copied it over from the Wallbox integration but looks like it does not work with a string. Should be fixed now 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Looks like the issue was I forgot to import typing Any. See Union here for explanation

@lbbrhzn
Copy link
Owner

lbbrhzn commented Dec 17, 2021

i can see the buttons, and reset works for me. Unlock does not: my charger responds with 'Unsupported'.

Copy link
Owner

@lbbrhzn lbbrhzn 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 to me!

@lbbrhzn
Copy link
Owner

lbbrhzn commented Dec 17, 2021

Should we also add a button for a RemoteStopTransaction?

@drc38
Copy link
Collaborator Author

drc38 commented Dec 17, 2021

looks good to me!

This will only work with 2021.12 and above so perhaps give it a while before tagging into a release. I have updated the slider but that's not yet compatible with 2021.12.3, hopefully it'll be in .4

@drc38
Copy link
Collaborator Author

drc38 commented Dec 17, 2021

Should we also add a button for a RemoteStopTransaction?

The 'Charge_Control' switch when switched off while charging already performs a RemoteStopTransaction. So in my view it's not required.

@drc38
Copy link
Collaborator Author

drc38 commented Dec 17, 2021

i can see the buttons, and reset works for me. Unlock does not: my charger responds with 'Unsupported'.

Not sure on best way to handle chargers that don't support 'Unlock' as code-wise it is not known until the command is sent. What's your view? Eg on return of 'Unsupported' the button availability could be set to false? Or made part of the initial config flow?

@drc38 drc38 merged commit 51000b4 into lbbrhzn:main Dec 18, 2021
@drc38 drc38 deleted the buttons branch December 18, 2021 04:23
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.

None yet

2 participants