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

Bugfix and small refactor for zwave_js.device_action #93261

Merged
merged 1 commit into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions homeassistant/components/zwave_js/device_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ async def async_get_actions(
# underlying value is not being monitored by HA so we shouldn't allow
# actions against it.
if (
state := hass.states.get(entry.entity_id)
) and state.state == STATE_UNAVAILABLE:
not (state := hass.states.get(entry.entity_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not about test coverage, it's about handling the case where the entity has been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is actually a bug fix because if the state is not found, we should just continue and that was not handled properly. The test coverage piece is the change below to reduce missed lines. Renamed the PR accordingly

or state.state == STATE_UNAVAILABLE
):
continue
entity_action = {**base_action, CONF_ENTITY_ID: entry.entity_id}
actions.append({**entity_action, CONF_TYPE: SERVICE_REFRESH_VALUE})
Expand All @@ -209,9 +210,7 @@ async def async_get_actions(
# If the value has the meterType CC specific value, we can add a reset_meter
# action for it
if CC_SPECIFIC_METER_TYPE in value.metadata.cc_specific:
endpoint_idx = value.endpoint
if endpoint_idx is None:
endpoint_idx = 0
endpoint_idx = value.endpoint or 0
meter_endpoints[endpoint_idx].setdefault(
CONF_ENTITY_ID, entry.entity_id
)
Expand Down