Skip to content

smartthings: retain state for appliances when powered off#169870

Open
CSdread wants to merge 6 commits intohome-assistant:devfrom
CSdread:fix/smartthings-appliance-unavailable-on-poweroff
Open

smartthings: retain state for appliances when powered off#169870
CSdread wants to merge 6 commits intohome-assistant:devfrom
CSdread:fix/smartthings-appliance-unavailable-on-poweroff

Conversation

@CSdread
Copy link
Copy Markdown
Contributor

@CSdread CSdread commented May 5, 2026

Proposed change

Samsung appliances (washers, dryers, dishwashers, ovens, ranges, etc.) report HealthStatus.OFFLINE when physically powered off — not just when network-disconnected. Since the SmartThings integration rewrite in 2025.6, every OFFLINE event unconditionally marks all entities as unavailable, breaking automations that depend on appliance state (e.g. "notify me when the wash is finished").

This fix makes appliance entities retain their last-known state instead of going unavailable when the device powers off. Non-appliance devices (lights, switches, AC units, TVs) continue to go unavailable on OFFLINE as before — for those, OFFLINE means genuinely unreachable and the state is unknown.

The fix also corrects boot-time behaviour: appliances that are offline when HA starts now show their last-known state immediately, since get_device_status() is always called before get_device_health() during setup, so _internal_state is fully populated regardless of online status.

Changes

  • const.py — Adds APPLIANCE_CATEGORIES covering device categories that emit OFFLINE during normal power-off (WASHER, DRYER, DISHWASHER, OVEN, RANGE, COOKTOP, MICROWAVE, CLOTHING_CARE_MACHINE). Kept separate from INVALID_SWITCH_CATEGORIES because the sets serve different purposes and have different members.
  • util.py — Promotes get_main_component_category() from binary_sensor.py into the shared utility module so entity.py can use it without duplicating the logic.
  • binary_sensor.py — Removes the now-duplicate local definition; imports from util.py.
  • entity.py — Adds _is_appliance() method; rewrites _availability_handler with a flat two-guard pattern that retains state for appliance devices on OFFLINE and UNHEALTHY events while avoiding spurious async_write_ha_state() calls; updates the constructor to initialise appliances as available at boot.
  • test_select.py — Updates existing dryer availability tests to assert state is retained; parametrizes over both HealthStatus.OFFLINE and HealthStatus.UNHEALTHY to cover all non-ONLINE statuses.

Type of change

  • Bugfix (non-breaking change which fixes an issue)

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.

CSdread and others added 2 commits April 30, 2026 16:01
Samsung appliances (washers, dryers, dishwashers, ovens, etc.) report
HealthStatus.OFFLINE when powered off, not just when network-disconnected.
Since 2025.6 the integration marks all entities unavailable on any OFFLINE
event, breaking automations that monitor appliance state (e.g. "notify me
when the wash is finished").

Fix _availability_handler to retain last-known state for appliances
instead of marking them unavailable. Non-appliance devices (lights,
switches, AC units) continue to go unavailable as before, since OFFLINE
for them means genuinely unreachable.

- Add APPLIANCE_CATEGORIES to const.py covering device categories that
  power off without losing meaningful state
- Promote get_main_component_category to util.py so entity.py can use
  it without duplicating logic from binary_sensor.py
- SmartThingsEntity._is_appliance() checks the device category
- _availability_handler retains state for OFFLINE and UNHEALTHY events
  on appliance devices, avoids spurious async_write_ha_state calls
- Constructor initialises appliances as available at boot since
  get_device_status is always called before get_device_health, so
  _internal_state holds valid last-known data even when offline

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 5, 2026 19:43
@home-assistant home-assistant Bot added bugfix cla-signed has-tests integration: smartthings Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels May 5, 2026
@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 5, 2026

Hey there @joostlek, mind taking a look at this pull request as it has been labeled with an integration (smartthings) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of smartthings can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign smartthings Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

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

This PR adjusts SmartThings entity availability handling so Samsung appliance devices don’t become unavailable when SmartThings reports them OFFLINE/UNHEALTHY (common during physical power-off), retaining their last-known state to avoid breaking state-based automations.

Changes:

  • Add an APPLIANCE_CATEGORIES allowlist to identify device categories that should retain state when health is not ONLINE.
  • Move get_main_component_category() into util.py for shared use across platforms.
  • Update appliance availability logic in the SmartThings entity base class and adjust select-platform tests to expect retained state (including at boot).

Reviewed changes

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

Show a summary per file
File Description
tests/components/smartthings/test_select.py Updates dryer select availability expectations to retain last state and parametrizes non-ONLINE health statuses.
homeassistant/components/smartthings/util.py Introduces shared get_main_component_category() helper for device categorization.
homeassistant/components/smartthings/entity.py Changes base entity availability logic to keep appliance entities available when health is not ONLINE.
homeassistant/components/smartthings/const.py Adds APPLIANCE_CATEGORIES used to decide whether to retain state on OFFLINE/UNHEALTHY.
homeassistant/components/smartthings/binary_sensor.py Removes local get_main_component_category() and imports the shared utility version.

Comment thread homeassistant/components/smartthings/entity.py Outdated
Comment thread homeassistant/components/smartthings/const.py
CSdread and others added 2 commits May 5, 2026 14:28
Copilot AI review requested due to automatic review settings May 5, 2026 20:30
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 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread homeassistant/components/smartthings/entity.py
CSdread and others added 2 commits May 5, 2026 14:37
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 5, 2026 20:39
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 7 out of 7 changed files in this pull request and generated no new comments.

@CSdread
Copy link
Copy Markdown
Contributor Author

CSdread commented May 5, 2026

@home-assistant ready-for-review

@CSdread CSdread marked this pull request as ready for review May 5, 2026 21:00
@CSdread CSdread requested a review from joostlek as a code owner May 5, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix cla-signed has-tests integration: smartthings Quality Scale: bronze Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SmartThings entities for Samsung washer/dryer become “unavailable” after power off

3 participants