Skip to content

Victron GX switch platform#167859

Merged
joostlek merged 18 commits intohome-assistant:devfrom
tomer-w:victron_gx_switch
Apr 10, 2026
Merged

Victron GX switch platform#167859
joostlek merged 18 commits intohome-assistant:devfrom
tomer-w:victron_gx_switch

Conversation

@tomer-w
Copy link
Copy Markdown
Contributor

@tomer-w tomer-w commented Apr 10, 2026

Proposed change

Adding switch platform for Victron GX integration

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

  • I understand the code I am submitting and can explain how it works.
  • 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.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

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 diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new switch entity platform to the Victron GX integration so writable “switch” metrics (e.g., EV charger start/stop) are exposed as Home Assistant switch entities with translations and tests.

Changes:

  • Add SwitchEntity implementation and discovery wiring for MetricKind.SWITCH.
  • Register the switch platform in the integration’s platform list.
  • Add entity name translations and new switch-focused tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
homeassistant/components/victron_gx/__init__.py Adds Platform.SWITCH so config entries set up the new platform.
homeassistant/components/victron_gx/switch.py Implements switch entity discovery, state updates, and on/off commands for writable switch metrics.
homeassistant/components/victron_gx/strings.json Adds switch entity translation keys/names used by the new platform.
tests/components/victron_gx/test_switch.py Introduces tests covering switch creation, updates, and service calls.

Comment thread tests/components/victron_gx/test_switch.py Outdated
Comment thread tests/components/victron_gx/test_switch.py Outdated
Comment thread homeassistant/components/victron_gx/switch.py Outdated
Comment thread homeassistant/components/victron_gx/switch.py Outdated
@erwindouna
Copy link
Copy Markdown
Member

Wasn't this recently closed, due too much PRs are being submitted and first ones need to be merged?

#167780

@tomer-w
Copy link
Copy Markdown
Contributor Author

tomer-w commented Apr 10, 2026

Wasn't this recently closed, due too much PRs are being submitted and first ones need to be merged?

#167780

Yes, and I did get 2 platforms merged so I'm moving to the next set.

Copy link
Copy Markdown
Member

@erwindouna erwindouna left a comment

Choose a reason for hiding this comment

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

Shouldn't we also cover faulty situations? For instance if toggle failed to update raise a Home assistant error?

Comment thread homeassistant/components/victron_gx/strings.json Outdated
Comment thread homeassistant/components/victron_gx/switch.py Outdated
Comment thread homeassistant/components/victron_gx/switch.py Outdated
Comment thread tests/components/victron_gx/test_binary_sensor.py Outdated
Comment thread tests/components/victron_gx/test_switch.py Outdated
Copilot AI review requested due to automatic review settings April 10, 2026 07:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread homeassistant/components/victron_gx/strings.json
Comment thread homeassistant/components/victron_gx/strings.json Outdated
Comment thread homeassistant/components/victron_gx/strings.json Outdated
@tomer-w
Copy link
Copy Markdown
Contributor Author

tomer-w commented Apr 10, 2026

@erwindouna, thanks for the quick review. I fix all comments.

@tomer-w tomer-w requested a review from erwindouna April 10, 2026 08:02
@tomer-w
Copy link
Copy Markdown
Contributor Author

tomer-w commented Apr 10, 2026

Shouldn't we also cover faulty situations? For instance if toggle failed to update raise a Home assistant error?

@erwindouna , the update is just sending mqtt message. I have no idea if the other side actually got it. When they do get it they change another topic which will actually change the switch position but theoretically that message can get for state change for other reasons.

Copilot AI review requested due to automatic review settings April 10, 2026 10:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread tests/components/victron_gx/test_switch.py Outdated
Comment thread homeassistant/components/victron_gx/binary_sensor.py Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 10, 2026 10:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread tests/components/victron_gx/test_switch.py
Comment thread tests/components/victron_gx/test_switch.py
@tomer-w tomer-w requested a review from erwindouna April 10, 2026 14:13
@tomer-w
Copy link
Copy Markdown
Contributor Author

tomer-w commented Apr 10, 2026

@erwindouna, thanks for your review. Can you mark it as approved by you?

@joostlek joostlek merged commit 547830b into home-assistant:dev Apr 10, 2026
33 checks passed
Copy link
Copy Markdown
Member

@erwindouna erwindouna 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, thanks @tomer-w!

Comment on lines +1801 to +1811
"name": "Relay on Multi RS state"
},
"solarcharger_relay_state": {
"name": "Relay state"
},
"switch_output_state": {
"name": "Switch {output} state"
},
"switchable_output_output_state": {
"name": "Switchable output {output} state"
},
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.

Noticed this while translating: We should drop "state" from these entities as this results in really clumsy translations. In many languages you cannot simply place 4 nouns in a row, so this has to be reworded as

State of switchable output X : On

But you would just say something like "Switchable output X is on", and not "The state of (the) switchable output X is on". Thus those entities work just fine as:

Switchable output X : On

Shortening also helps a lot on mobile and with small column widths in general.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@NoRi2909, I will take it to the dedupe PR which I will publish the moment we get all the platforms in. I hope early next week.

@tomer-w tomer-w deleted the victron_gx_switch branch April 10, 2026 17:38
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 11, 2026
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