Skip to content
Open
116 changes: 116 additions & 0 deletions homeassistant/components/smartthings/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .entity import SmartThingsEntity
from .util import deprecate_entity


THERMOSTAT_CAPABILITIES = {
Capability.TEMPERATURE_MEASUREMENT,
Capability.THERMOSTAT_HEATING_SETPOINT,
Expand Down Expand Up @@ -143,6 +144,55 @@

WASHER_OPTIONS = ["pause", "run", "stop"]

WASHER_CYCLES = [
"1c",
"2b",
"1b",
"1e",
"1d",
"96",
"8f",
"25",
"26",
"33",
"24",
"32",
"20",
"22",
"23",
"2f",
"21",
"66",
"2e",
"2d",
"30",
"29",
"27",
"28",
]
Comment thread
gielk marked this conversation as resolved.

DRYER_CYCLES = [
"51",
"53",
"23",
"17",
"18",
"19",
"1d",
"1b",
"1c",
"21",
"1a",
"1e",
"20",
"27",
"25",
"24",
"4e",
"4c",
]
Comment thread
gielk marked this conversation as resolved.



def power_attributes(status: dict[str, Any]) -> dict[str, Any]:
"""Return the power attributes."""
Expand Down Expand Up @@ -1278,6 +1328,68 @@
)
]
},
"samsungce.washerCycle": {

Check failure on line 1331 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 70 has incompatible type "str": "dict[Attribute, list[SmartThingsSensorEntityDescription]]"; expected "Capability": "dict[Attribute, list[SmartThingsSensorEntityDescription]]" [dict-item]
"washerCycle": [

Check failure on line 1332 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 0 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="washerCycle",
translation_key="washer_cycle",
icon="mdi:washing-machine",
options=WASHER_CYCLES,
device_class=SensorDeviceClass.ENUM,
Comment on lines +1357 to +1359
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 👍 / 👎.

)
]
},
"samsungce.dryerCycle": {

Check failure on line 1342 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 71 has incompatible type "str": "dict[Attribute, list[SmartThingsSensorEntityDescription]]"; expected "Capability": "dict[Attribute, list[SmartThingsSensorEntityDescription]]" [dict-item]
"dryerCycle": [

Check failure on line 1343 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 0 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="dryerCycle",
translation_key="dryer_cycle",
icon="mdi:tumble-dryer",
options=DRYER_CYCLES,
device_class=SensorDeviceClass.ENUM,
)
]
},
"samsungce.washerOperatingState": {

Check failure on line 1353 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 72 has incompatible type "str": "dict[Attribute, list[SmartThingsSensorEntityDescription]]"; expected "Capability": "dict[Attribute, list[SmartThingsSensorEntityDescription]]" [dict-item]
"progress": [

Check failure on line 1354 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 0 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="progress",
translation_key="washer_progress",
icon="mdi:washing-machine",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
)
],
"remainingTime": [

Check failure on line 1363 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 1 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="remainingTime",
translation_key="washer_remaining_time",
icon="mdi:timer-sand",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement="min",
)
Comment thread
gielk marked this conversation as resolved.
Comment thread
gielk marked this conversation as resolved.
]
},
"samsungce.dryerOperatingState": {

Check failure on line 1373 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 73 has incompatible type "str": "dict[Attribute, list[SmartThingsSensorEntityDescription]]"; expected "Capability": "dict[Attribute, list[SmartThingsSensorEntityDescription]]" [dict-item]
"progress": [

Check failure on line 1374 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 0 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="progress",
translation_key="dryer_progress",
icon="mdi:tumble-dryer",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
)
],
"remainingTime": [

Check failure on line 1383 in homeassistant/components/smartthings/sensor.py

View workflow job for this annotation

GitHub Actions / Check mypy

Dict entry 1 has incompatible type "str": "list[SmartThingsSensorEntityDescription]"; expected "Attribute": "list[SmartThingsSensorEntityDescription]" [dict-item]
SmartThingsSensorEntityDescription(
key="remainingTime",
translation_key="dryer_remaining_time",
icon="mdi:timer-sand",
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement="min",
)
Comment thread
gielk marked this conversation as resolved.
]
},
}


Expand Down Expand Up @@ -1424,6 +1536,10 @@
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 on lines 1562 to 1567
Expand Down
64 changes: 64 additions & 0 deletions homeassistant/components/smartthings/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,70 @@
"stop": "[%key:common::state::stopped%]"
}
},
"washer_cycle": {
"name": "Washer cycle",
"state": {
"1c": "Eco 40-60",
"2b": "AI Wash",
"1b": "Cotton",
"1e": "15' Quick Wash",
"1d": "Super Speed",
"96": "Less Microfiber",
"8f": "Intense Cold",
"25": "Synthetics",
"26": "Delicates",
"33": "Towels",
"24": "Bedding",
"32": "Shirts",
"20": "Hygiene Steam",
"22": "Wool",
"23": "Outdoor",
"2f": "Activewear",
"21": "Colors",
"66": "Denim",
"2e": "Baby Care",
"2d": "Silent Wash",
"30": "Cloudy day",
Comment thread
gielk marked this conversation as resolved.
Outdated
"29": "Drum Clean+",
"27": "Rinse+Spin",
"28": "Drain/Spin"
}
},
"dryer_cycle": {
"name": "Dryer cycle",
"state": {
"51": "Eco Cotton",
"53": "AI Dry+",
"23": "Quick Dry 35'",
"17": "Super Speed",
"18": "Synthetics",
"19": "Delicates",
"1d": "Towels",
"1b": "Bedding",
"1c": "Shirts",
"21": "Hygiene Care",
"1a": "Wool",
"1e": "Outdoor",
"20": "Iron Dry",
"27": "Time Dry",
"25": "Warm Air",
"24": "Cool Air",
"4e": "Self Dry",
"4c": "Air Refresh"
}
},
"washer_progress": {
"name": "Washing progress"
},
"dryer_progress": {
"name": "Drying progress"
},
"washer_remaining_time": {
"name": "Washer remaining time"
},
"dryer_remaining_time": {
"name": "Dryer remaining time"
},
"washer_mode": {
"name": "Washer mode"
},
Expand Down
Loading