Skip to content

Add Samsung washer and dryer cycle and state sensors to SmartThings#171684

Open
gielk wants to merge 7 commits into
home-assistant:devfrom
gielk:smartthings-washer-dryer-sensors
Open

Add Samsung washer and dryer cycle and state sensors to SmartThings#171684
gielk wants to merge 7 commits into
home-assistant:devfrom
gielk:smartthings-washer-dryer-sensors

Conversation

@gielk
Copy link
Copy Markdown

@gielk gielk commented May 21, 2026

Proposed change

This PR adds cycle and progress/remaining time sensors to the SmartThings integration for Samsung washing machines and dryers.

Specifically, it registers the following new sensor entities:

  • samsungce.washerCycle (using SensorDeviceClass.ENUM with cycle code options, translated via strings.json)
  • samsungce.dryerCycle (using SensorDeviceClass.ENUM with cycle code options, translated via strings.json)
  • samsungce.washerOperatingState (progress in % and remainingTime in minutes)
  • samsungce.dryerOperatingState (progress in % and remainingTime in minutes)

State values from the cycle capabilities are normalized to lowercase codes (e.g. 1b, 1c, 51) and translated via Home Assistant's standard translation framework in strings.json.

Type of change

  • New feature (which adds functionality to an existing integration)

Additional information

  • This PR is related to: Samsung laundry diagnostic entities
  • Translation strings have been added to strings.json for English. Localizations in other languages will be imported via Crowdin.

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • I have followed the development checklist

@gielk gielk requested a review from joostlek as a code owner May 21, 2026 09:19
Copilot AI review requested due to automatic review settings May 21, 2026 09:19
@home-assistant home-assistant Bot added cla-needed integration: smartthings new-feature Top 100 Integration is ranked within the top 100 by usage Top 200 Integration is ranked within the top 200 by usage labels May 21, 2026
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

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

Hi @gielk

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant home-assistant Bot marked this pull request as draft May 21, 2026 09:19
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link
Copy Markdown
Contributor

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds additional Samsung CE washer/dryer telemetry to the SmartThings integration by surfacing cycle selection and operating-state progress/remaining-time as sensor entities with localized enum state labels.

Changes:

  • Add new translation keys and enum state labels for washer/dryer cycles.
  • Add SmartThings sensor entity descriptions for washer/dryer cycle, progress (%), and remaining time (minutes).
  • Normalize raw cycle values to match enum option keys.

Reviewed changes

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

File Description
homeassistant/components/smartthings/strings.json Adds translation keys and enum state labels for washer/dryer cycle sensors and operating-state sensors.
homeassistant/components/smartthings/sensor.py Defines enum options and new sensor entity descriptions; adds normalization logic for washer/dryer cycle values.

def native_value(self) -> str | float | datetime | int | None:
"""Return the state of the sensor."""
res = self.get_attribute_value(self.capability, self._attribute)
if self.capability in ("samsungce.washerCycle", "samsungce.dryerCycle"):
Comment thread homeassistant/components/smartthings/sensor.py
Comment thread homeassistant/components/smartthings/sensor.py
Comment thread homeassistant/components/smartthings/strings.json Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 21, 2026 09:23
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 2 out of 2 changed files in this pull request and generated 4 comments.

Comment on lines 1536 to 1545
def native_value(self) -> str | float | datetime | int | None:
"""Return the state of the sensor."""
res = self.get_attribute_value(self.capability, self._attribute)
if self.capability in ("samsungce.washerCycle", "samsungce.dryerCycle"):
if not res:
return None
return res.split("_")[-1].lower() if "_" in res else res.lower()
if options_map := self.entity_description.options_map:
return options_map.get(res)
value = self.entity_description.value_fn(res)
Comment thread homeassistant/components/smartthings/sensor.py
from .entity import SmartThingsEntity
from .util import deprecate_entity


Comment thread homeassistant/components/smartthings/sensor.py
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 72b81a1021

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1337 to +1338
options=WASHER_CYCLES,
device_class=SensorDeviceClass.ENUM,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use device-reported cycle options for enum sensors

These new enum sensors hardcode options to fixed code lists, but native_value can still emit any cycle code reported by SmartThings after normalization. In Home Assistant, enum sensors reject states not present in options (SensorEntity._stringify_state checks value not in options), so any model/firmware-specific or newly added cycle code will make the sensor state invalid instead of updating. This is especially likely for Samsung laundry devices where supported cycles vary by model; options should be derived from the device’s supported cycle attributes (or the state should be guarded) rather than a static list.

Useful? React with 👍 / 👎.

@gielk gielk marked this pull request as ready for review May 21, 2026 09:40
Copilot AI review requested due to automatic review settings May 21, 2026 09:41
@home-assistant home-assistant Bot dismissed their stale review May 21, 2026 09:41

Stale

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 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +1606 to +1610
# Guard against rejection: append current state if not present
if (current_value := self.native_value) is not None:
current_value_str = str(current_value)
if current_value_str not in options_list:
options_list.append(current_value_str)
Comment on lines +1613 to +1629
# Fall back to static options in description if attribute is missing/None
if (static_options := super().options) is not None:
options_list = list(static_options)
if (current_value := self.native_value) is not None:
current_value_str = str(current_value)
if current_value_str not in options_list:
options_list.append(current_value_str)
return options_list
return []

if (static_options := super().options) is not None:
options_list = list(static_options)
if (current_value := self.native_value) is not None:
current_value_str = str(current_value)
if current_value_str not in options_list:
options_list.append(current_value_str)
return options_list
Comment thread homeassistant/components/smartthings/sensor.py
Copy link
Copy Markdown
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

The CI is failing. I would love to see if we can do something similar like someone has done for the dishwasher

@home-assistant home-assistant Bot marked this pull request as draft May 21, 2026 17:32
@gielk
Copy link
Copy Markdown
Author

gielk commented May 21, 2026

The CI is failing. I would love to see if we can do something similar like someone has done for the dishwasher

What has someone done for the dishwasher? Where can I find it?

Copilot AI review requested due to automatic review settings May 21, 2026 20:25
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 4 out of 4 changed files in this pull request and generated 5 comments.

Comment on lines +1606 to +1611
# Guard against rejection: append current state if not present
if (current_value := self.native_value) is not None:
current_value_str = str(current_value)
if current_value_str not in options_list:
options_list.append(current_value_str)
return options_list
opt_str = str(opt_str)
if options_map := self.entity_description.options_map:
opt_str = options_map.get(opt_str, opt_str)
options_list.append(opt_str.lower())
Comment on lines 1216 to 1221
translation_key="washer_machine_state",
options=WASHER_OPTIONS,
device_class=SensorDeviceClass.ENUM,
component_fn=lambda component: component == "sub",
component_translation_key={
"sub": "washer_sub_machine_state",
},
@@ -143,6 +144,54 @@

WASHER_OPTIONS = ["pause", "run", "stop"]
assert _normalize_cycle_value("washer_delicate") == "delicate"
assert _normalize_cycle_value("delicate") == "delicate"


Copilot AI review requested due to automatic review settings May 22, 2026 05:03
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 4 out of 4 changed files in this pull request and generated 4 comments.

Comment on lines +216 to +225
if not value:
return None
value_str = str(value)
return (
value_str.rsplit("_", maxsplit=1)[-1].lower()
if "_" in value_str
else value_str.lower()
)


Comment on lines +1602 to +1622
options_val = self.get_attribute_value(
self.capability, self.entity_description.options_attribute
)
if options_val is not None:
options_list = []
for option in options_val:
if isinstance(option, dict):
opt_val = option.get("cycle")
else:
opt_val = option
if opt_val is not None:
if options_map := self.entity_description.options_map:
opt_val = options_map.get(opt_val, opt_val)
else:
opt_val = self.entity_description.value_fn(opt_val)
if self.entity_description.presentation_fn:
opt_val = self.entity_description.presentation_fn(
self.device.device.presentation_id, opt_val
)
if opt_val is not None:
options_list.append(str(opt_val).lower())
elif (static_options := super().options) is not None:
options_list = [str(opt).lower() for opt in static_options]
else:
return []
"state": {
"pause": "[%key:common::state::paused%]",
"paused": "[%key:common::state::paused%]",
"ready": "[%key:component::smartthings::entity::sensor::oven_machine_state::state::ready%]",
@gielk gielk marked this pull request as ready for review May 22, 2026 05:27
@home-assistant home-assistant Bot requested a review from joostlek May 22, 2026 05:27
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e73a0bda56

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +220 to +221
value_str.rsplit("_", maxsplit=1)[-1].lower()
if "_" in value_str
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve full cycle identifier when normalizing values

The normalization logic drops everything before the final underscore, so cycle IDs like NORMAL_CYCLE and DELICATE_CYCLE both become cycle. In environments where SmartThings reports underscore-delimited names instead of trailing hex codes, this collapses distinct washer/dryer cycles into one enum state, making the sensor inaccurate and breaking automations that depend on the specific cycle.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed integration: smartthings new-feature 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.

3 participants