-
-
Notifications
You must be signed in to change notification settings - Fork 37.5k
Add Samsung washer and dryer cycle and state sensors to SmartThings #171684
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
base: dev
Are you sure you want to change the base?
Changes from all commits
72b81a1
de2014d
9e9f674
22f9d4d
791deca
8210b02
e73a0bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| UnitOfPower, | ||
| UnitOfPressure, | ||
| UnitOfTemperature, | ||
| UnitOfTime, | ||
| UnitOfVolume, | ||
| ) | ||
| from homeassistant.core import HomeAssistant | ||
|
|
@@ -141,7 +142,64 @@ | |
| "UVPaused": "uv_paused", | ||
| } | ||
|
|
||
| WASHER_OPTIONS = ["pause", "run", "stop"] | ||
| DISHWASHER_MACHINE_STATE_OPTIONS = ["pause", "run", "stop"] | ||
| WASHER_MACHINE_STATE_OPTIONS = [ | ||
| "pause", | ||
| "paused", | ||
| "ready", | ||
| "run", | ||
| "running", | ||
| "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", | ||
| ] | ||
|
|
||
| DRYER_CYCLES = [ | ||
| "51", | ||
| "53", | ||
| "23", | ||
| "17", | ||
| "18", | ||
| "19", | ||
| "1d", | ||
| "1b", | ||
| "1c", | ||
| "21", | ||
| "1a", | ||
| "1e", | ||
| "20", | ||
| "27", | ||
| "25", | ||
| "24", | ||
| "4e", | ||
| "4c", | ||
| ] | ||
|
gielk marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def power_attributes(status: dict[str, Any]) -> dict[str, Any]: | ||
|
|
@@ -153,6 +211,18 @@ def power_attributes(status: dict[str, Any]) -> dict[str, Any]: | |
| return state | ||
|
|
||
|
|
||
| def _normalize_cycle_value(value: Any) -> str | None: | ||
| """Normalize washer/dryer cycle names.""" | ||
| if not value: | ||
| return None | ||
| value_str = str(value) | ||
| return ( | ||
| value_str.rsplit("_", maxsplit=1)[-1].lower() | ||
| if "_" in value_str | ||
|
Comment on lines
+220
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The normalization logic drops everything before the final underscore, so cycle IDs like Useful? React with 👍 / 👎. |
||
| else value_str.lower() | ||
| ) | ||
|
|
||
|
|
||
|
Comment on lines
+216
to
+225
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class SmartThingsSensorEntityDescription(SensorEntityDescription): | ||
| """Describe a SmartThings sensor entity.""" | ||
|
|
@@ -365,7 +435,7 @@ class SmartThingsSensorEntityDescription(SensorEntityDescription): | |
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.MACHINE_STATE, | ||
| translation_key="dishwasher_machine_state", | ||
| options=WASHER_OPTIONS, | ||
| options=DISHWASHER_MACHINE_STATE_OPTIONS, | ||
| device_class=SensorDeviceClass.ENUM, | ||
| ) | ||
| ], | ||
|
|
@@ -413,7 +483,7 @@ class SmartThingsSensorEntityDescription(SensorEntityDescription): | |
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.MACHINE_STATE, | ||
| translation_key="dryer_machine_state", | ||
| options=WASHER_OPTIONS, | ||
| options=WASHER_MACHINE_STATE_OPTIONS, | ||
| device_class=SensorDeviceClass.ENUM, | ||
| ) | ||
| ], | ||
|
|
@@ -1153,7 +1223,7 @@ class SmartThingsSensorEntityDescription(SensorEntityDescription): | |
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.MACHINE_STATE, | ||
| translation_key="washer_machine_state", | ||
| options=WASHER_OPTIONS, | ||
| options=WASHER_MACHINE_STATE_OPTIONS, | ||
| device_class=SensorDeviceClass.ENUM, | ||
| component_fn=lambda component: component == "sub", | ||
| component_translation_key={ | ||
|
|
@@ -1278,6 +1348,74 @@ class SmartThingsSensorEntityDescription(SensorEntityDescription): | |
| ) | ||
| ] | ||
| }, | ||
| Capability.SAMSUNG_CE_WASHER_CYCLE: { | ||
| Attribute.WASHER_CYCLE: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.WASHER_CYCLE, | ||
| translation_key="washer_cycle", | ||
| icon="mdi:washing-machine", | ||
| options=WASHER_CYCLES, | ||
| options_attribute=Attribute.SUPPORTED_CYCLES, | ||
| device_class=SensorDeviceClass.ENUM, | ||
|
Comment on lines
+1357
to
+1359
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
These new enum sensors hardcode Useful? React with 👍 / 👎. |
||
| value_fn=_normalize_cycle_value, | ||
| ) | ||
| ] | ||
| }, | ||
| Capability.SAMSUNG_CE_DRYER_CYCLE: { | ||
| Attribute.DRYER_CYCLE: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.DRYER_CYCLE, | ||
| translation_key="dryer_cycle", | ||
| icon="mdi:tumble-dryer", | ||
| options=DRYER_CYCLES, | ||
| options_attribute=Attribute.SUPPORTED_CYCLES, | ||
| device_class=SensorDeviceClass.ENUM, | ||
| value_fn=_normalize_cycle_value, | ||
| ) | ||
| ] | ||
| }, | ||
| Capability.SAMSUNG_CE_WASHER_OPERATING_STATE: { | ||
| Attribute.PROGRESS: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.PROGRESS, | ||
| translation_key="washer_progress", | ||
| icon="mdi:washing-machine", | ||
| state_class=SensorStateClass.MEASUREMENT, | ||
| native_unit_of_measurement=PERCENTAGE, | ||
| ) | ||
| ], | ||
| Attribute.REMAINING_TIME: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.REMAINING_TIME, | ||
| translation_key="washer_remaining_time", | ||
| icon="mdi:timer-sand", | ||
| state_class=SensorStateClass.MEASUREMENT, | ||
| device_class=SensorDeviceClass.DURATION, | ||
| native_unit_of_measurement=UnitOfTime.MINUTES, | ||
| ) | ||
|
gielk marked this conversation as resolved.
gielk marked this conversation as resolved.
|
||
| ], | ||
| }, | ||
| Capability.SAMSUNG_CE_DRYER_OPERATING_STATE: { | ||
| Attribute.PROGRESS: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.PROGRESS, | ||
| translation_key="dryer_progress", | ||
| icon="mdi:tumble-dryer", | ||
| state_class=SensorStateClass.MEASUREMENT, | ||
| native_unit_of_measurement=PERCENTAGE, | ||
| ) | ||
| ], | ||
| Attribute.REMAINING_TIME: [ | ||
| SmartThingsSensorEntityDescription( | ||
| key=Attribute.REMAINING_TIME, | ||
| translation_key="dryer_remaining_time", | ||
| icon="mdi:timer-sand", | ||
| state_class=SensorStateClass.MEASUREMENT, | ||
| device_class=SensorDeviceClass.DURATION, | ||
| native_unit_of_measurement=UnitOfTime.MINUTES, | ||
| ) | ||
|
gielk marked this conversation as resolved.
|
||
| ], | ||
| }, | ||
| } | ||
|
|
||
|
|
||
|
|
@@ -1461,13 +1599,48 @@ def extra_state_attributes(self) -> Mapping[str, Any] | None: | |
| def options(self) -> list[str] | None: | ||
| """Return the options for this sensor.""" | ||
| if self.entity_description.options_attribute: | ||
| if ( | ||
| options := self.get_attribute_value( | ||
| self.capability, self.entity_description.options_attribute | ||
| ) | ||
| ) is None: | ||
| 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()) | ||
|
Comment on lines
+1602
to
+1622
|
||
| # Fall back to static options in description if attribute is missing/None | ||
| elif (static_options := super().options) is not None: | ||
| options_list = [str(opt).lower() for opt in static_options] | ||
| else: | ||
| return [] | ||
|
|
||
| if options_map := self.entity_description.options_map: | ||
| return [options_map[option] for option in options] | ||
| return [option.lower() for option in options] | ||
| return super().options | ||
| elif (static_options := super().options) is not None: | ||
| options_list = [str(opt).lower() for opt in static_options] | ||
| else: | ||
| return None | ||
|
|
||
| # Deduplicate while preserving order | ||
| seen: set[str] = set() | ||
| unique_options: list[str] = [] | ||
| for opt in options_list: | ||
| if opt not in seen: | ||
| seen.add(opt) | ||
| unique_options.append(opt) | ||
|
|
||
| if (current_value := self.native_value) is not None: | ||
| current_value_str = str(current_value).lower() | ||
| if current_value_str not in seen: | ||
| unique_options.append(current_value_str) | ||
|
|
||
| return unique_options | ||
Uh oh!
There was an error while loading. Please reload this page.