Repository: home-assistant/core
Pull request #141958: Refactor Whirlpool sensor platform
Author: login: abmantis
Labels: name: cla-signed
name: has-tests
name: by-code-owner
name: code-quality
name: integration: whirlpool
name: Quality Scale: No score
Created: 2025-03-31T22:11:42Z | Merged: 2025-04-01T18:02:24Z

## Proposed change
<!--
  Describe the big picture of your changes here to communicate to the
  maintainers why we should accept this pull request. If it fixes a bug
  or resolves a feature request, be sure to link to that issue in the
  additional information section.
-->
The current implementation of Whirlpool's sensor was too tied to Washer/Dryers, but the platform supports other types of appliances.

This PR: 

- renames a few things to make them either generic or specific to Washer or Dryer.
- splits washer and dryer sensor descriptions, since they have different attributes (and a change is underway on the library to split them too).
- drop the dispense level sensor from dryers, since they don't have it.
- move common stuff into a base WhirlpoolEntity class.

## Type of change
<!--
  What type of change does your PR introduce to Home Assistant?
  NOTE: Please, check only 1! box!
  If your PR requires multiple boxes to be checked, you'll most likely need to
  split it into multiple PRs. This makes things easier and faster to code review.
-->

- [ ] Dependency upgrade
- [ ] Bugfix (non-breaking change which fixes an issue)
- [ ] New integration (thank you!)
- [ ] New feature (which adds functionality to an existing integration)
- [ ] Deprecation (breaking change to happen in the future)
- [ ] Breaking change (fix/feature causing existing functionality to break)
- [x] Code quality improvements to existing code or addition of tests

## Additional information
<!--
  Details are important, and help maintainers processing your PR.
  Please be sure to fill out additional details, if applicable.
-->

- This PR fixes or closes issue: fixes #
- This PR is related to issue: 
- Link to documentation pull request: 
- Link to developer documentation pull request: 
- Link to frontend pull request: 

## Checklist
<!--
  Put an `x` in the boxes that apply. You can also fill these out after
  creating the PR. If you're unsure about any of them, don't hesitate to ask.
  We're here to help! This is simply a reminder of what we are going to look
  for before merging your code.
-->

- [ ] The code change is tested and works locally.
- [x] Local tests pass. **Your PR cannot be merged unless tests pass**
- [x] There is no commented out code in this PR.
- [x] I have followed the [development checklist][dev-checklist]
- [x] I have followed the [perfect PR recommendations][perfect-pr]
- [x] The code has been formatted using Ruff (`ruff format homeassistant tests`)
- [ ] Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

- [ ] Documentation added/updated for [www.home-assistant.io][docs-repository]

If the code communicates with devices, web services, or third-party tools:

- [ ] The [manifest file][manifest-docs] has all fields filled out correctly.  
      Updated and included derived files by running: `python3 -m script.hassfest`.
- [ ] New or updated dependencies have been added to `requirements_all.txt`.  
      Updated by running `python3 -m script.gen_requirements_all`.
- [ ] For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

<!--
  This project is very active and we have a high turnover of pull requests.

  Unfortunately, the number of incoming pull requests is higher than what our
  reviewers can review and merge so there is a long backlog of pull requests
  waiting for review. You can help here!
  
  By reviewing another pull request, you will help raise the code quality of
  that pull request and the final review will be faster. This way the general
  pace of pull request reviews will go up and your wait time will go down.
  
  When picking a pull request to review, try to choose one that hasn't yet
  been reviewed.

  Thanks for helping out!
-->

To help with the load of incoming pull requests:

- [ ] I have reviewed two other [open pull requests][prs] in this repository.

[prs]: https://github.com/home-assistant/core/pulls?q=is%3Aopen+is%3Apr+-author%3A%40me+-draft%3Atrue+-label%3Awaiting-for-upstream+sort%3Acreated-desc+review%3Anone+-status%3Afailure

<!--
  Thank you for contributing <3

  Below, some useful links you could explore:
-->
[dev-checklist]: https://developers.home-assistant.io/docs/development_checklist/
[manifest-docs]: https://developers.home-assistant.io/docs/creating_integration_manifest/
[quality-scale]: https://developers.home-assistant.io/docs/integration_quality_scale_index/
[docs-repository]: https://github.com/home-assistant/home-assistant.io
[perfect-pr]: https://developers.home-assistant.io/docs/review-process/#creating-the-perfect-pr



Diff:
diff --git a/homeassistant/components/whirlpool/entity.py b/homeassistant/components/whirlpool/entity.py
new file mode 100644
index 00000000000000..e74ed596e1ee85
--- /dev/null
+++ b/homeassistant/components/whirlpool/entity.py
@@ -0,0 +1,38 @@
+"""Base entity for the Whirlpool integration."""
+
+from whirlpool.appliance import Appliance
+
+from homeassistant.helpers.device_registry import DeviceInfo
+from homeassistant.helpers.entity import Entity
+
+from .const import DOMAIN
+
+
+class WhirlpoolEntity(Entity):
+    """Base class for Whirlpool entities."""
+
+    _attr_has_entity_name = True
+
+    def __init__(self, appliance: Appliance, unique_id_suffix: str = "") -> None:
+        """Initialize the entity."""
+        self._appliance = appliance
+
+        self._attr_device_info = DeviceInfo(
+            identifiers={(DOMAIN, appliance.said)},
+            name=appliance.name.capitalize(),
+            manufacturer="Whirlpool",
+        )
+        self._attr_unique_id = f"{appliance.said}{unique_id_suffix}"
+
+    async def async_added_to_hass(self) -> None:
+        """Register attribute updates callback."""
+        self._appliance.register_attr_callback(self.async_write_ha_state)
+
+    async def async_will_remove_from_hass(self) -> None:
+        """Unregister attribute updates callback."""
+        self._appliance.unregister_attr_callback(self.async_write_ha_state)
+
+    @property
+    def available(self) -> bool:
+        """Return True if entity is available."""
+        return self._appliance.get_online()
diff --git a/homeassistant/components/whirlpool/icons.json b/homeassistant/components/whirlpool/icons.json
new file mode 100644
index 00000000000000..574b491090e795
--- /dev/null
+++ b/homeassistant/components/whirlpool/icons.json
@@ -0,0 +1,12 @@
+{
+  "entity": {
+    "sensor": {
+      "washer_state": {
+        "default": "mdi:washing-machine"
+      },
+      "dryer_state": {
+        "default": "mdi:tumble-dryer"
+      }
+    }
+  }
+}
diff --git a/homeassistant/components/whirlpool/sensor.py b/homeassistant/components/whirlpool/sensor.py
index 3d38883b901892..d167e3aa7306fb 100644
--- a/homeassistant/components/whirlpool/sensor.py
+++ b/homeassistant/components/whirlpool/sensor.py
@@ -3,8 +3,9 @@
 from collections.abc import Callable
 from dataclasses import dataclass
 from datetime import datetime, timedelta
-import logging
+from typing import override
 
+from whirlpool.appliance import Appliance
 from whirlpool.washerdryer import MachineState, WasherDryer
 
 from homeassistant.components.sensor import (
@@ -13,16 +14,17 @@
     SensorEntity,
     SensorEntityDescription,
 )
-from homeassistant.core import HomeAssistant, callback
-from homeassistant.helpers.device_registry import DeviceInfo
+from homeassistant.core import HomeAssistant
 from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
 from homeassistant.helpers.typing import StateType
 from homeassistant.util.dt import utcnow
 
 from . import WhirlpoolConfigEntry
-from .const import DOMAIN
+from .entity import WhirlpoolEntity
 
-TANK_FILL = {
+SCAN_INTERVAL = timedelta(minutes=5)
+
+WASHER_TANK_FILL = {
     "0": "unknown",
     "1": "empty",
     "2": "25",
@@ -31,7 +33,7 @@
     "5": "active",
 }
 
-MACHINE_STATE = {
+WASHER_DRYER_MACHINE_STATE = {
     MachineState.Standby: "standby",
     MachineState.Setting: "setting",
     MachineState.DelayCountdownMode: "delay_countdown",
@@ -53,7 +55,7 @@
     MachineState.SystemInit: "system_initialize",
 }
 
-CYCLE_FUNC = [
+WASHER_DRYER_CYCLE_FUNC = [
     (WasherDryer.get_cycle_status_filling, "cycle_filling"),
     (WasherDryer.get_cycle_status_rinsing, "cycle_rinsing"),
     (WasherDryer.get_cycle_status_sensing, "cycle_sensing"),
@@ -62,60 +64,69 @@
     (WasherDryer.get_cycle_status_washing, "cycle_washing"),
 ]
 
-DOOR_OPEN = "door_open"
-
-_LOGGER = logging.getLogger(__name__)
-SCAN_INTERVAL = timedelta(minutes=5)
+STATE_DOOR_OPEN = "door_open"
 
 
-def washer_state(washer: WasherDryer) -> str | None:
-    """Determine correct states for a washer."""
+def washer_dryer_state(washer_dryer: WasherDryer) -> str | None:
+    """Determine correct states for a washer/dryer."""
 
-    if washer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
-        return DOOR_OPEN
+    if washer_dryer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
+        return STATE_DOOR_OPEN
 
-    machine_state = washer.get_machine_state()
+    machine_state = washer_dryer.get_machine_state()
 
     if machine_state == MachineState.RunningMainCycle:
-        for func, cycle_name in CYCLE_FUNC:
-            if func(washer):
+        for func, cycle_name in WASHER_DRYER_CYCLE_FUNC:
+            if func(washer_dryer):
                 return cycle_name
 
-    return MACHINE_STATE.get(machine_state)
+    return WASHER_DRYER_MACHINE_STATE.get(machine_state)
 
 
 @dataclass(frozen=True, kw_only=True)
 class WhirlpoolSensorEntityDescription(SensorEntityDescription):
-    """Describes Whirlpool Washer sensor entity."""
+    """Describes a Whirlpool sensor entity."""
 
-    value_fn: Callable
+    value_fn: Callable[[Appliance], str | None]
 
 
-SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
+WASHER_DRYER_STATE_OPTIONS = (
+    list(WASHER_DRYER_MACHINE_STATE.values())
+    + [value for _, value in WASHER_DRYER_CYCLE_FUNC]
+    + [STATE_DOOR_OPEN]
+)
+
+WASHER_SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
     WhirlpoolSensorEntityDescription(
         key="state",
-        translation_key="whirlpool_machine",
+        translation_key="washer_state",
         device_class=SensorDeviceClass.ENUM,
-        options=(
-            list(MACHINE_STATE.values())
-            + [value for _, value in CYCLE_FUNC]
-            + [DOOR_OPEN]
-        ),
-        value_fn=washer_state,
+        options=WASHER_DRYER_STATE_OPTIONS,
+        value_fn=washer_dryer_state,
     ),
     WhirlpoolSensorEntityDescription(
         key="DispenseLevel",
         translation_key="whirlpool_tank",
         entity_registry_enabled_default=False,
         device_class=SensorDeviceClass.ENUM,
-        options=list(TANK_FILL.values()),
-        value_fn=lambda WasherDryer: TANK_FILL.get(
-            WasherDryer.get_attribute("WashCavity_OpStatusBulkDispense1Level")
+        options=list(WASHER_TANK_FILL.values()),
+        value_fn=lambda washer: WASHER_TANK_FILL.get(
+            washer.get_attribute("WashCavity_OpStatusBulkDispense1Level")
         ),
     ),
 )
 
-SENSOR_TIMER: tuple[SensorEntityDescription] = (
+DRYER_SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
+    WhirlpoolSensorEntityDescription(
+        key="state",
+        translation_key="dryer_state",
+        device_class=SensorDeviceClass.ENUM,
+        options=WASHER_DRYER_STATE_OPTIONS,
+        value_fn=washer_dryer_state,
+    ),
+)
+
+WASHER_DRYER_TIME_SENSORS: tuple[SensorEntityDescription] = (
     SensorEntityDescription(
         key="timeremaining",
         translation_key="end_time",
@@ -134,106 +145,71 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            WhirlpoolSensor(washer_dryer, description)
+            for description in sensor_descriptions
         )
         entities.extend(
-            [
-                WasherDryerTimeClass(washer_dryer, description)
-                for description in SENSOR_TIMER
-            ]
+            WasherDryerTimeSensor(washer_dryer, description)
+            for description in WASHER_DRYER_TIME_SENSORS
         )
     async_add_entities(entities)
 
 
-class WasherDryerClass(SensorEntity):
-    """A class for the whirlpool/maytag washer account."""
+class WhirlpoolSensor(WhirlpoolEntity, SensorEntity):
+    """A class for the Whirlpool sensors."""
 
     _attr_should_poll = False
-    _attr_has_entity_name = True
 
     def __init__(
-        self, washer_dryer: WasherDryer, description: WhirlpoolSensorEntityDescription
+        self, appliance: Appliance, description: WhirlpoolSensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
-
-        self._attr_icon = (
-            "mdi:tumble-dryer"
-            if "dryer" in washer_dryer.appliance_info.data_model.lower()
-            else "mdi:washing-machine"
-        )
-
+        super().__init__(appliance, unique_id_suffix=f"-{description.key}")
         self.entity_description: WhirlpoolSensorEntityDescription = description
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
-
-    async def async_added_to_hass(self) -> None:
-        """Register updates callback."""
-        self._wd.register_attr_callback(self.async_write_ha_state)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Unregister updates callback."""
-        self._wd.unregister_attr_callback(self.async_write_ha_state)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     @property
     def native_value(self) -> StateType | str:
         """Return native value of sensor."""
-        return self.entity_description.value_fn(self._wd)
+        return self.entity_description.value_fn(self._appliance)
 
 
-class WasherDryerTimeClass(RestoreSensor):
-    """A timestamp class for the whirlpool/maytag washer account."""
+class WasherDryerTimeSensor(WhirlpoolEntity, RestoreSensor):
+    """A timestamp class for the Whirlpool washer/dryer."""
 
     _attr_should_poll = True
-    _attr_has_entity_name = True
 
     def __init__(
         self, washer_dryer: WasherDryer, description: SensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
+        super().__init__(washer_dryer, unique_id_suffix=f"-{description.key}")
+        self.entity_description = description
 
-        self.entity_description: SensorEntityDescription = description
+        self._wd = washer_dryer
         self._running: bool | None = None
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
+        self._value: datetime | None = None
 
     async def async_added_to_hass(self) -> None:
-        """Connect washer/dryer to the cloud."""
+        """Register attribute updates callback."""
         if restored_data := await self.async_get_last_sensor_data():
-            self._attr_native_value = restored_data.native_value
+            if isinstance(restored_data.native_value, datetime):
+                self._value = restored_data.native_value
         await super().async_added_to_hass()
-        self._wd.register_attr_callback(self.update_from_latest_data)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Close Whrilpool Appliance sockets before removing."""
-        self._wd.unregister_attr_callback(self.update_from_latest_data)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     async def async_update(self) -> None:
         """Update status of Whirlpool."""
         await self._wd.fetch_data()
 
-    @callback
-    def update_from_latest_data(self) -> None:
+    @override
+    @property
+    def native_value(self) -> datetime | None:
         """Calculate the time stamp for completion."""
         machine_state = self._wd.get_machine_state()
         now = utcnow()
@@ -243,8 +219,7 @@ def update_from_latest_data(self) -> None:
             and self._running
         ):
             self._running = False
-            self._attr_native_value = now
-            self._async_write_ha_state()
+            self._value = now
 
         if machine_state is MachineState.RunningMainCycle:
             self._running = True
@@ -253,9 +228,9 @@ def update_from_latest_data(self) -> None:
                 seconds=int(self._wd.get_attribute("Cavity_TimeStatusEstTimeRemaining"))
             )
 
-            if self._attr_native_value is None or (
-                isinstance(self._attr_native_value, datetime)
-                and abs(new_timestamp - self._attr_native_value) > timedelta(seconds=60)
+            if self._value is None or (
+                isinstance(self._value, datetime)
+                and abs(new_timestamp - self._value) > timedelta(seconds=60)
             ):
-                self._attr_native_value = new_timestamp
-                self._async_write_ha_state()
+                self._value = new_timestamp
+        return self._value
diff --git a/homeassistant/components/whirlpool/strings.json b/homeassistant/components/whirlpool/strings.json
index 95df3fb9098b31..56fee795237a3a 100644
--- a/homeassistant/components/whirlpool/strings.json
+++ b/homeassistant/components/whirlpool/strings.json
@@ -43,35 +43,64 @@
   },
   "entity": {
     "sensor": {
-      "whirlpool_machine": {
-        "name": "State",
+      "washer_state": {
         "state": {
           "standby": "[%key:common::state::standby%]",
           "setting": "Setting",
-          "delay_countdown": "Delay Countdown",
-          "delay_paused": "Delay Paused",
-          "smart_delay": "Smart Delay",
-          "smart_grid_pause": "[%key:component::whirlpool::entity::sensor::whirlpool_machine::state::smart_delay%]",
+          "delay_countdown": "Delay countdown",
+          "delay_paused": "Delay paused",
+          "smart_delay": "Smart delay",
+          "smart_grid_pause": "[%key:component::whirlpool::entity::sensor::washer_state::state::smart_delay%]",
           "pause": "[%key:common::state::paused%]",
-          "running_maincycle": "Running Maincycle",
-          "running_postcycle": "Running Postcycle",
+          "running_maincycle": "Running maincycle",
+          "running_postcycle": "Running postcycle",
           "exception": "Exception",
           "complete": "Complete",
-          "power_failure": "Power Failure",
-          "service_diagnostic_mode": "Service Diagnostic Mode",
-          "factory_diagnostic_mode": "Factory Diagnostic Mode",
-          "life_test": "Life Test",
-          "customer_focus_mode": "Customer Focus Mode",
-          "demo_mode": "Demo Mode",
-          "hard_stop_or_error": "Hard Stop or Error",
-          "system_initialize": "System Initialize",
-          "cycle_filling": "Cycle Filling",
-          "cycle_rinsing": "Cycle Rinsing",
-          "cycle_sensing": "Cycle Sensing",
-          "cycle_soaking": "Cycle Soaking",
-          "cycle_spinning": "Cycle Spinning",
-          "cycle_washing": "Cycle Washing",
-          "door_open": "Door Open"
+          "power_failure": "Power failure",
+          "service_diagnostic_mode": "Service diagnostic mode",
+          "factory_diagnostic_mode": "Factory diagnostic mode",
+          "life_test": "Life test",
+          "customer_focus_mode": "Customer focus mode",
+          "demo_mode": "Demo mode",
+          "hard_stop_or_error": "Hard stop or error",
+          "system_initialize": "System initialize",
+          "cycle_filling": "Cycle filling",
+          "cycle_rinsing": "Cycle rinsing",
+          "cycle_sensing": "Cycle sensing",
+          "cycle_soaking": "Cycle soaking",
+          "cycle_spinning": "Cycle spinning",
+          "cycle_washing": "Cycle washing",
+          "door_open": "Door open"
+        }
+      },
+      "dryer_state": {
+        "state": {
+          "standby": "[%key:common::state::standby%]",
+          "setting": "[%key:component::whirlpool::entity::sensor::washer_state::state::setting%]",
+          "delay_countdown": "[%key:component::whirlpool::entity::sensor::washer_state::state::delay_countdown%]",
+          "delay_paused": "[%key:component::whirlpool::entity::sensor::washer_state::state::delay_paused%]",
+          "smart_delay": "[%key:component::whirlpool::entity::sensor::washer_state::state::smart_delay%]",
+          "smart_grid_pause": "[%key:component::whirlpool::entity::sensor::washer_state::state::smart_delay%]",
+          "pause": "[%key:common::state::paused%]",
+          "running_maincycle": "[%key:component::whirlpool::entity::sensor::washer_state::state::running_maincycle%]",
+          "running_postcycle": "[%key:component::whirlpool::entity::sensor::washer_state::state::running_postcycle%]",
+          "exception": "[%key:component::whirlpool::entity::sensor::washer_state::state::exception%]",
+          "complete": "[%key:component::whirlpool::entity::sensor::washer_state::state::complete%]",
+          "power_failure": "[%key:component::whirlpool::entity::sensor::washer_state::state::power_failure%]",
+          "service_diagnostic_mode": "[%key:component::whirlpool::entity::sensor::washer_state::state::service_diagnostic_mode%]",
+          "factory_diagnostic_mode": "[%key:component::whirlpool::entity::sensor::washer_state::state::factory_diagnostic_mode%]",
+          "life_test": "[%key:component::whirlpool::entity::sensor::washer_state::state::life_test%]",
+          "customer_focus_mode": "[%key:component::whirlpool::entity::sensor::washer_state::state::customer_focus_mode%]",
+          "demo_mode": "[%key:component::whirlpool::entity::sensor::washer_state::state::demo_mode%]",
+          "hard_stop_or_error": "[%key:component::whirlpool::entity::sensor::washer_state::state::hard_stop_or_error%]",
+          "system_initialize": "[%key:component::whirlpool::entity::sensor::washer_state::state::system_initialize%]",
+          "cycle_filling": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_filling%]",
+          "cycle_rinsing": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_rinsing%]",
+          "cycle_sensing": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_sensing%]",
+          "cycle_soaking": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_soaking%]",
+          "cycle_spinning": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_spinning%]",
+          "cycle_washing": "[%key:component::whirlpool::entity::sensor::washer_state::state::cycle_washing%]",
+          "door_open": "[%key:component::whirlpool::entity::sensor::washer_state::state::door_open%]"
         }
       },
       "whirlpool_tank": {
diff --git a/tests/components/whirlpool/conftest.py b/tests/components/whirlpool/conftest.py
index 93881d3735af3f..97550729761668 100644
--- a/tests/components/whirlpool/conftest.py
+++ b/tests/components/whirlpool/conftest.py
@@ -153,12 +153,12 @@ def side_effect_function(*args, **kwargs):
     return None
 
 
-def get_sensor_mock(said):
+def get_sensor_mock(said: str, data_model: str):
     """Get a mock of a sensor."""
     mock_sensor = mock.Mock(said=said)
     mock_sensor.name = f"WasherDryer {said}"
     mock_sensor.register_attr_callback = MagicMock()
-    mock_sensor.appliance_info.data_model = "washer_dryer_model"
+    mock_sensor.appliance_info.data_model = data_model
     mock_sensor.appliance_info.category = "washer_dryer"
     mock_sensor.appliance_info.model_number = "12345"
     mock_sensor.get_online.return_value = True
@@ -179,13 +179,13 @@ def get_sensor_mock(said):
 @pytest.fixture(name="mock_sensor1_api", autouse=False)
 def fixture_mock_sensor1_api():
     """Set up sensor API fixture."""
-    return get_sensor_mock(MOCK_SAID3)
+    return get_sensor_mock(MOCK_SAID3, "washer")
 
 
 @pytest.fixture(name="mock_sensor2_api", autouse=False)
 def fixture_mock_sensor2_api():
     """Set up sensor API fixture."""
-    return get_sensor_mock(MOCK_SAID4)
+    return get_sensor_mock(MOCK_SAID4, "dryer")
 
 
 @pytest.fixture(name="mock_sensor_api_instances", autouse=False)
diff --git a/tests/components/whirlpool/snapshots/test_diagnostics.ambr b/tests/components/whirlpool/snapshots/test_diagnostics.ambr
index 7ffae8bc808710..7294e914f51af7 100644
--- a/tests/components/whirlpool/snapshots/test_diagnostics.ambr
+++ b/tests/components/whirlpool/snapshots/test_diagnostics.ambr
@@ -19,12 +19,12 @@
       'washer_dryers': dict({
         'WasherDryer said3': dict({
           'category': 'washer_dryer',
-          'data_model': 'washer_dryer_model',
+          'data_model': 'washer',
           'model_number': '12345',
         }),
         'WasherDryer said4': dict({
           'category': 'washer_dryer',
-          'data_model': 'washer_dryer_model',
+          'data_model': 'dryer',
           'model_number': '12345',
         }),
       }),
diff --git a/tests/components/whirlpool/test_sensor.py b/tests/components/whirlpool/test_sensor.py
index 95fca33170731f..40c485a5b9f6dc 100644
--- a/tests/components/whirlpool/test_sensor.py
+++ b/tests/components/whirlpool/test_sensor.py
@@ -66,7 +66,7 @@ async def test_dryer_sensor_values(
 
     await init_integration(hass)
 
-    entity_id = f"sensor.washerdryer_{MOCK_SAID4}_state"
+    entity_id = f"sensor.washerdryer_{MOCK_SAID4}_none"
     mock_instance = mock_sensor2_api
     entry = entity_registry.async_get(entity_id)
     assert entry
@@ -130,7 +130,7 @@ async def test_washer_sensor_values(
     )
     await hass.async_block_till_done()
 
-    entity_id = f"sensor.washerdryer_{MOCK_SAID3}_state"
+    entity_id = f"sensor.washerdryer_{MOCK_SAID3}_none"
     mock_instance = mock_sensor1_api
     entry = entity_registry.async_get(entity_id)
     assert entry


Reviews:
user: login: joostlek
state: CHANGES_REQUESTED
author_association: MEMBER
submitted_at: 2025-04-01T09:01:44Z
user: login: abmantis
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-01T14:14:56Z
user: login: abmantis
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-01T14:43:39Z
user: login: joostlek
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-01T14:45:28Z
user: login: joostlek
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-04-01T14:53:10Z
user: login: joostlek
state: APPROVED
author_association: MEMBER
submitted_at: 2025-04-01T17:57:27Z

Review comments:
diff_hunk: @@ -62,60 +64,71 @@
     (WasherDryer.get_cycle_status_washing, "cycle_washing"),
 ]
 
-DOOR_OPEN = "door_open"
+STATE_DOOR_OPEN = "door_open"
 
-_LOGGER = logging.getLogger(__name__)
-SCAN_INTERVAL = timedelta(minutes=5)
 
+def washer_dryer_state(washer_dryer: WasherDryer) -> str | None:
+    """Determine correct states for a washer/dryer."""
 
-def washer_state(washer: WasherDryer) -> str | None:
-    """Determine correct states for a washer."""
+    if washer_dryer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
+        return STATE_DOOR_OPEN
 
-    if washer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
-        return DOOR_OPEN
-
-    machine_state = washer.get_machine_state()
+    machine_state = washer_dryer.get_machine_state()
 
     if machine_state == MachineState.RunningMainCycle:
-        for func, cycle_name in CYCLE_FUNC:
-            if func(washer):
+        for func, cycle_name in WASHER_DRYER_CYCLE_FUNC:
+            if func(washer_dryer):
                 return cycle_name
 
-    return MACHINE_STATE.get(machine_state)
+    return WASHER_DRYER_MACHINE_STATE.get(machine_state)
 
 
 @dataclass(frozen=True, kw_only=True)
 class WhirlpoolSensorEntityDescription(SensorEntityDescription):
-    """Describes Whirlpool Washer sensor entity."""
+    """Describes a Whirlpool sensor entity."""
 
     value_fn: Callable
 
 
-SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
+WASHER_DRYER_STATE_OPTIONS = (
+    list(WASHER_DRYER_MACHINE_STATE.values())
+    + [value for _, value in WASHER_DRYER_CYCLE_FUNC]
+    + [STATE_DOOR_OPEN]
+)
+
+WASHER_SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
     WhirlpoolSensorEntityDescription(
         key="state",
         translation_key="whirlpool_machine",
         device_class=SensorDeviceClass.ENUM,
-        options=(
-            list(MACHINE_STATE.values())
-            + [value for _, value in CYCLE_FUNC]
-            + [DOOR_OPEN]
-        ),
-        value_fn=washer_state,
+        icon="mdi:washing-machine",
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: let's use icon translations
created_at: 2025-04-01T08:59:43Z
author_association: MEMBER
diff_hunk: @@ -62,60 +64,71 @@
     (WasherDryer.get_cycle_status_washing, "cycle_washing"),
 ]
 
-DOOR_OPEN = "door_open"
+STATE_DOOR_OPEN = "door_open"
 
-_LOGGER = logging.getLogger(__name__)
-SCAN_INTERVAL = timedelta(minutes=5)
 
+def washer_dryer_state(washer_dryer: WasherDryer) -> str | None:
+    """Determine correct states for a washer/dryer."""
 
-def washer_state(washer: WasherDryer) -> str | None:
-    """Determine correct states for a washer."""
+    if washer_dryer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
+        return STATE_DOOR_OPEN
 
-    if washer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
-        return DOOR_OPEN
-
-    machine_state = washer.get_machine_state()
+    machine_state = washer_dryer.get_machine_state()
 
     if machine_state == MachineState.RunningMainCycle:
-        for func, cycle_name in CYCLE_FUNC:
-            if func(washer):
+        for func, cycle_name in WASHER_DRYER_CYCLE_FUNC:
+            if func(washer_dryer):
                 return cycle_name
 
-    return MACHINE_STATE.get(machine_state)
+    return WASHER_DRYER_MACHINE_STATE.get(machine_state)
 
 
 @dataclass(frozen=True, kw_only=True)
 class WhirlpoolSensorEntityDescription(SensorEntityDescription):
-    """Describes Whirlpool Washer sensor entity."""
+    """Describes a Whirlpool sensor entity."""
 
     value_fn: Callable
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: can we also type the callable?
created_at: 2025-04-01T08:59:51Z
author_association: MEMBER
diff_hunk: @@ -134,106 +147,76 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            [
+                WhirlpoolSensor(washer_dryer, description)
+                for description in sensor_descriptions
+            ]
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: ```suggestion
            WhirlpoolSensor(washer_dryer, description)
            for description in sensor_descriptions
```
created_at: 2025-04-01T09:00:09Z
author_association: MEMBER
diff_hunk: @@ -134,106 +147,76 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            [
+                WhirlpoolSensor(washer_dryer, description)
+                for description in sensor_descriptions
+            ]
         )
         entities.extend(
             [
-                WasherDryerTimeClass(washer_dryer, description)
-                for description in SENSOR_TIMER
+                WasherDryerTimeSensor(washer_dryer, description)
+                for description in WASHER_DRYER_TIME_SENSORS
             ]
         )
     async_add_entities(entities)
 
 
-class WasherDryerClass(SensorEntity):
-    """A class for the whirlpool/maytag washer account."""
+class WhirlpoolSensor(WhirlpoolEntity, SensorEntity):
+    """A class for the Whirlpool sensors."""
 
     _attr_should_poll = False
-    _attr_has_entity_name = True
 
     def __init__(
-        self, washer_dryer: WasherDryer, description: WhirlpoolSensorEntityDescription
+        self, appliance: Appliance, description: WhirlpoolSensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
-
-        self._attr_icon = (
-            "mdi:tumble-dryer"
-            if "dryer" in washer_dryer.appliance_info.data_model.lower()
-            else "mdi:washing-machine"
-        )
+        super().__init__(appliance, unique_id_suffix=f"-{description.key}")
 
         self.entity_description: WhirlpoolSensorEntityDescription = description
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
-
-    async def async_added_to_hass(self) -> None:
-        """Register updates callback."""
-        self._wd.register_attr_callback(self.async_write_ha_state)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Unregister updates callback."""
-        self._wd.unregister_attr_callback(self.async_write_ha_state)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     @property
     def native_value(self) -> StateType | str:
         """Return native value of sensor."""
-        return self.entity_description.value_fn(self._wd)
+        return self.entity_description.value_fn(self._appliance)
 
 
-class WasherDryerTimeClass(RestoreSensor):
-    """A timestamp class for the whirlpool/maytag washer account."""
+class WasherDryerTimeSensor(WhirlpoolEntity, RestoreSensor):
+    """A timestamp class for the Whirlpool washer/dryer."""
 
     _attr_should_poll = True
-    _attr_has_entity_name = True
 
     def __init__(
         self, washer_dryer: WasherDryer, description: SensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
+        super().__init__(washer_dryer, unique_id_suffix=f"-{description.key}")
         self._wd: WasherDryer = washer_dryer
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: ```suggestion
        self._wd = washer_dryer
```
created_at: 2025-04-01T09:00:46Z
author_association: MEMBER
diff_hunk: @@ -134,106 +147,76 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            [
+                WhirlpoolSensor(washer_dryer, description)
+                for description in sensor_descriptions
+            ]
         )
         entities.extend(
             [
-                WasherDryerTimeClass(washer_dryer, description)
-                for description in SENSOR_TIMER
+                WasherDryerTimeSensor(washer_dryer, description)
+                for description in WASHER_DRYER_TIME_SENSORS
             ]
         )
     async_add_entities(entities)
 
 
-class WasherDryerClass(SensorEntity):
-    """A class for the whirlpool/maytag washer account."""
+class WhirlpoolSensor(WhirlpoolEntity, SensorEntity):
+    """A class for the Whirlpool sensors."""
 
     _attr_should_poll = False
-    _attr_has_entity_name = True
 
     def __init__(
-        self, washer_dryer: WasherDryer, description: WhirlpoolSensorEntityDescription
+        self, appliance: Appliance, description: WhirlpoolSensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
-
-        self._attr_icon = (
-            "mdi:tumble-dryer"
-            if "dryer" in washer_dryer.appliance_info.data_model.lower()
-            else "mdi:washing-machine"
-        )
+        super().__init__(appliance, unique_id_suffix=f"-{description.key}")
 
         self.entity_description: WhirlpoolSensorEntityDescription = description
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
-
-    async def async_added_to_hass(self) -> None:
-        """Register updates callback."""
-        self._wd.register_attr_callback(self.async_write_ha_state)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Unregister updates callback."""
-        self._wd.unregister_attr_callback(self.async_write_ha_state)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     @property
     def native_value(self) -> StateType | str:
         """Return native value of sensor."""
-        return self.entity_description.value_fn(self._wd)
+        return self.entity_description.value_fn(self._appliance)
 
 
-class WasherDryerTimeClass(RestoreSensor):
-    """A timestamp class for the whirlpool/maytag washer account."""
+class WasherDryerTimeSensor(WhirlpoolEntity, RestoreSensor):
+    """A timestamp class for the Whirlpool washer/dryer."""
 
     _attr_should_poll = True
-    _attr_has_entity_name = True
 
     def __init__(
         self, washer_dryer: WasherDryer, description: SensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
+        super().__init__(washer_dryer, unique_id_suffix=f"-{description.key}")
         self._wd: WasherDryer = washer_dryer
 
         self.entity_description: SensorEntityDescription = description
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: ```suggestion
        self.entity_description = description
```
created_at: 2025-04-01T09:01:01Z
author_association: MEMBER
diff_hunk: @@ -134,106 +147,76 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            [
+                WhirlpoolSensor(washer_dryer, description)
+                for description in sensor_descriptions
+            ]
         )
         entities.extend(
             [
-                WasherDryerTimeClass(washer_dryer, description)
-                for description in SENSOR_TIMER
+                WasherDryerTimeSensor(washer_dryer, description)
+                for description in WASHER_DRYER_TIME_SENSORS
             ]
         )
     async_add_entities(entities)
 
 
-class WasherDryerClass(SensorEntity):
-    """A class for the whirlpool/maytag washer account."""
+class WhirlpoolSensor(WhirlpoolEntity, SensorEntity):
+    """A class for the Whirlpool sensors."""
 
     _attr_should_poll = False
-    _attr_has_entity_name = True
 
     def __init__(
-        self, washer_dryer: WasherDryer, description: WhirlpoolSensorEntityDescription
+        self, appliance: Appliance, description: WhirlpoolSensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
-
-        self._attr_icon = (
-            "mdi:tumble-dryer"
-            if "dryer" in washer_dryer.appliance_info.data_model.lower()
-            else "mdi:washing-machine"
-        )
+        super().__init__(appliance, unique_id_suffix=f"-{description.key}")
 
         self.entity_description: WhirlpoolSensorEntityDescription = description
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
-
-    async def async_added_to_hass(self) -> None:
-        """Register updates callback."""
-        self._wd.register_attr_callback(self.async_write_ha_state)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Unregister updates callback."""
-        self._wd.unregister_attr_callback(self.async_write_ha_state)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     @property
     def native_value(self) -> StateType | str:
         """Return native value of sensor."""
-        return self.entity_description.value_fn(self._wd)
+        return self.entity_description.value_fn(self._appliance)
 
 
-class WasherDryerTimeClass(RestoreSensor):
-    """A timestamp class for the whirlpool/maytag washer account."""
+class WasherDryerTimeSensor(WhirlpoolEntity, RestoreSensor):
+    """A timestamp class for the Whirlpool washer/dryer."""
 
     _attr_should_poll = True
-    _attr_has_entity_name = True
 
     def __init__(
         self, washer_dryer: WasherDryer, description: SensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
+        super().__init__(washer_dryer, unique_id_suffix=f"-{description.key}")
         self._wd: WasherDryer = washer_dryer
 
         self.entity_description: SensorEntityDescription = description
         self._running: bool | None = None
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
+        self._value: datetime | None = None
 
     async def async_added_to_hass(self) -> None:
-        """Connect washer/dryer to the cloud."""
+        """Register attribute updates callback."""
         if restored_data := await self.async_get_last_sensor_data():
-            self._attr_native_value = restored_data.native_value
+            if isinstance(restored_data.native_value, datetime):
+                self._value = restored_data.native_value
         await super().async_added_to_hass()
-        self._wd.register_attr_callback(self.update_from_latest_data)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Close Whrilpool Appliance sockets before removing."""
-        self._wd.unregister_attr_callback(self.update_from_latest_data)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     async def async_update(self) -> None:
         """Update status of Whirlpool."""
         await self._wd.fetch_data()
 
-    @callback
-    def update_from_latest_data(self) -> None:
+    @override
path: homeassistant/components/whirlpool/sensor.py
user: login: joostlek
body: I dont think we use override much
created_at: 2025-04-01T09:01:36Z
author_association: MEMBER
diff_hunk: @@ -134,106 +147,76 @@ async def async_setup_entry(
     entities: list = []
     appliances_manager = config_entry.runtime_data
     for washer_dryer in appliances_manager.washer_dryers:
+        sensor_descriptions = (
+            DRYER_SENSORS
+            if "dryer" in washer_dryer.appliance_info.data_model.lower()
+            else WASHER_SENSORS
+        )
+
         entities.extend(
-            [WasherDryerClass(washer_dryer, description) for description in SENSORS]
+            [
+                WhirlpoolSensor(washer_dryer, description)
+                for description in sensor_descriptions
+            ]
         )
         entities.extend(
             [
-                WasherDryerTimeClass(washer_dryer, description)
-                for description in SENSOR_TIMER
+                WasherDryerTimeSensor(washer_dryer, description)
+                for description in WASHER_DRYER_TIME_SENSORS
             ]
         )
     async_add_entities(entities)
 
 
-class WasherDryerClass(SensorEntity):
-    """A class for the whirlpool/maytag washer account."""
+class WhirlpoolSensor(WhirlpoolEntity, SensorEntity):
+    """A class for the Whirlpool sensors."""
 
     _attr_should_poll = False
-    _attr_has_entity_name = True
 
     def __init__(
-        self, washer_dryer: WasherDryer, description: WhirlpoolSensorEntityDescription
+        self, appliance: Appliance, description: WhirlpoolSensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
-        self._wd: WasherDryer = washer_dryer
-
-        self._attr_icon = (
-            "mdi:tumble-dryer"
-            if "dryer" in washer_dryer.appliance_info.data_model.lower()
-            else "mdi:washing-machine"
-        )
+        super().__init__(appliance, unique_id_suffix=f"-{description.key}")
 
         self.entity_description: WhirlpoolSensorEntityDescription = description
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
-
-    async def async_added_to_hass(self) -> None:
-        """Register updates callback."""
-        self._wd.register_attr_callback(self.async_write_ha_state)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Unregister updates callback."""
-        self._wd.unregister_attr_callback(self.async_write_ha_state)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     @property
     def native_value(self) -> StateType | str:
         """Return native value of sensor."""
-        return self.entity_description.value_fn(self._wd)
+        return self.entity_description.value_fn(self._appliance)
 
 
-class WasherDryerTimeClass(RestoreSensor):
-    """A timestamp class for the whirlpool/maytag washer account."""
+class WasherDryerTimeSensor(WhirlpoolEntity, RestoreSensor):
+    """A timestamp class for the Whirlpool washer/dryer."""
 
     _attr_should_poll = True
-    _attr_has_entity_name = True
 
     def __init__(
         self, washer_dryer: WasherDryer, description: SensorEntityDescription
     ) -> None:
         """Initialize the washer sensor."""
+        super().__init__(washer_dryer, unique_id_suffix=f"-{description.key}")
         self._wd: WasherDryer = washer_dryer
 
         self.entity_description: SensorEntityDescription = description
         self._running: bool | None = None
-        self._attr_device_info = DeviceInfo(
-            identifiers={(DOMAIN, washer_dryer.said)},
-            name=washer_dryer.name.capitalize(),
-            manufacturer="Whirlpool",
-        )
-        self._attr_unique_id = f"{washer_dryer.said}-{description.key}"
+        self._value: datetime | None = None
 
     async def async_added_to_hass(self) -> None:
-        """Connect washer/dryer to the cloud."""
+        """Register attribute updates callback."""
         if restored_data := await self.async_get_last_sensor_data():
-            self._attr_native_value = restored_data.native_value
+            if isinstance(restored_data.native_value, datetime):
+                self._value = restored_data.native_value
         await super().async_added_to_hass()
-        self._wd.register_attr_callback(self.update_from_latest_data)
-
-    async def async_will_remove_from_hass(self) -> None:
-        """Close Whrilpool Appliance sockets before removing."""
-        self._wd.unregister_attr_callback(self.update_from_latest_data)
-
-    @property
-    def available(self) -> bool:
-        """Return True if entity is available."""
-        return self._wd.get_online()
 
     async def async_update(self) -> None:
         """Update status of Whirlpool."""
         await self._wd.fetch_data()
 
-    @callback
-    def update_from_latest_data(self) -> None:
+    @override
path: homeassistant/components/whirlpool/sensor.py
user: login: abmantis
body: PEP 698 is recent, I think it came with Python 3.12. I personally think we should start using it more often as it makes the code easier to read and less prone to mistakes (like a method that should be overriding but isn't due to a typo or parent name change). Do you see any issue with using it?
created_at: 2025-04-01T14:14:56Z
author_association: MEMBER
diff_hunk: @@ -62,60 +64,71 @@
     (WasherDryer.get_cycle_status_washing, "cycle_washing"),
 ]
 
-DOOR_OPEN = "door_open"
+STATE_DOOR_OPEN = "door_open"
 
-_LOGGER = logging.getLogger(__name__)
-SCAN_INTERVAL = timedelta(minutes=5)
 
+def washer_dryer_state(washer_dryer: WasherDryer) -> str | None:
+    """Determine correct states for a washer/dryer."""
 
-def washer_state(washer: WasherDryer) -> str | None:
-    """Determine correct states for a washer."""
+    if washer_dryer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
+        return STATE_DOOR_OPEN
 
-    if washer.get_attribute("Cavity_OpStatusDoorOpen") == "1":
-        return DOOR_OPEN
-
-    machine_state = washer.get_machine_state()
+    machine_state = washer_dryer.get_machine_state()
 
     if machine_state == MachineState.RunningMainCycle:
-        for func, cycle_name in CYCLE_FUNC:
-            if func(washer):
+        for func, cycle_name in WASHER_DRYER_CYCLE_FUNC:
+            if func(washer_dryer):
                 return cycle_name
 
-    return MACHINE_STATE.get(machine_state)
+    return WASHER_DRYER_MACHINE_STATE.get(machine_state)
 
 
 @dataclass(frozen=True, kw_only=True)
 class WhirlpoolSensorEntityDescription(SensorEntityDescription):
-    """Describes Whirlpool Washer sensor entity."""
+    """Describes a Whirlpool sensor entity."""
 
     value_fn: Callable
 
 
-SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
+WASHER_DRYER_STATE_OPTIONS = (
+    list(WASHER_DRYER_MACHINE_STATE.values())
+    + [value for _, value in WASHER_DRYER_CYCLE_FUNC]
+    + [STATE_DOOR_OPEN]
+)
+
+WASHER_SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
     WhirlpoolSensorEntityDescription(
         key="state",
         translation_key="whirlpool_machine",
         device_class=SensorDeviceClass.ENUM,
-        options=(
-            list(MACHINE_STATE.values())
-            + [value for _, value in CYCLE_FUNC]
-            + [DOOR_OPEN]
-        ),
-        value_fn=washer_state,
+        icon="mdi:washing-machine",
path: homeassistant/components/whirlpool/sensor.py
user: login: abmantis
body: Done. I was going to leave that out for another PR to keep this one short, since it requires changing the translation_keys.
created_at: 2025-04-01T14:43:39Z
author_association: MEMBER
diff_hunk: @@ -43,15 +43,15 @@
   },
   "entity": {
     "sensor": {
-      "whirlpool_machine": {
+      "washer_state": {
         "name": "State",
         "state": {
           "standby": "[%key:common::state::standby%]",
           "setting": "Setting",
           "delay_countdown": "Delay Countdown",
           "delay_paused": "Delay Paused",
           "smart_delay": "Smart Delay",
path: homeassistant/components/whirlpool/strings.json
user: login: joostlek
body: Also, we should do this in sentence case, unless its a brand name
created_at: 2025-04-01T14:45:28Z
author_association: MEMBER
diff_hunk: @@ -74,6 +74,37 @@
           "door_open": "Door Open"
         }
       },
+      "dryer_state": {
+        "name": "State",
path: homeassistant/components/whirlpool/strings.json
user: login: joostlek
body: this can also be a reference. You can also consider just setting the name of the entity to `None` as this kinda is the main feature of the device
created_at: 2025-04-01T14:53:10Z
author_association: MEMBER

PR comments:
user: login: home-assistant[bot]
created_at: 2025-03-31T22:11:50Z
body: 
Hey there @mkmer, mind taking a look at this pull request as it has been labeled with an integration (`whirlpool`) you are listed as a [code owner](https://github.com/home-assistant/core/blob/dev/CODEOWNERS#L1720) for? Thanks!

<details>
<summary>Code owner commands</summary>


Code owners of `whirlpool` can trigger bot actions by commenting:

- `@home-assistant close` Closes the pull request.
- `@home-assistant rename Awesome new title` Renames the pull request.
- `@home-assistant reopen` Reopen the pull request.
- `@home-assistant unassign whirlpool` Removes the current integration label and assignees on the pull request, add the integration domain after the command.
- `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
- `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

</details>


author_association: CONTRIBUTOR
user: login: home-assistant[bot]
created_at: 2025-04-01T09:01:46Z
body: <!-- ReviewDrafterComment -->
Please take a look at the requested changes, and use the **Ready for review** button when you are done, thanks :+1:

[_Learn more about our pull request process._](https://developers.home-assistant.io/docs/review-process#prs-are-being-drafted-when-changes-are-needed)

author_association: CONTRIBUTOR
user: login: abmantis
created_at: 2025-04-01T18:23:25Z
body: Thanks @joostlek !
author_association: MEMBER