mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Honeywell disable detergent level by default (#88040)
* Disable fill by default * Fix tests * use TANK_FILL.get * Remove None from attribute get add reload to sensor test * Typing fix iteration error
This commit is contained in:
parent
7337cc8e89
commit
e3273a75da
@ -119,11 +119,12 @@ SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
|
|||||||
key="DispenseLevel",
|
key="DispenseLevel",
|
||||||
name="Detergent Level",
|
name="Detergent Level",
|
||||||
translation_key="whirlpool_tank",
|
translation_key="whirlpool_tank",
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=list(TANK_FILL.values()),
|
options=list(TANK_FILL.values()),
|
||||||
value_fn=lambda WasherDryer: TANK_FILL[
|
value_fn=lambda WasherDryer: TANK_FILL.get(
|
||||||
WasherDryer.get_attribute("WashCavity_OpStatusBulkDispense1Level")
|
WasherDryer.get_attribute("WashCavity_OpStatusBulkDispense1Level")
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -265,6 +266,7 @@ class WasherDryerTimeClass(RestoreSensor):
|
|||||||
|
|
||||||
async def async_will_remove_from_hass(self) -> None:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""Close Whrilpool Appliance sockets before removing."""
|
"""Close Whrilpool Appliance sockets before removing."""
|
||||||
|
self._wd.unregister_attr_callback(self.update_from_latest_data)
|
||||||
await self._wd.disconnect()
|
await self._wd.disconnect()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -49,6 +49,21 @@ def fixture_mock_appliances_manager_api():
|
|||||||
yield mock_appliances_manager
|
yield mock_appliances_manager
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(name="mock_appliances_manager_laundry_api")
|
||||||
|
def fixture_mock_appliances_manager_laundry_api():
|
||||||
|
"""Set up AppliancesManager fixture."""
|
||||||
|
with mock.patch(
|
||||||
|
"homeassistant.components.whirlpool.AppliancesManager"
|
||||||
|
) as mock_appliances_manager:
|
||||||
|
mock_appliances_manager.return_value.fetch_appliances = AsyncMock()
|
||||||
|
mock_appliances_manager.return_value.aircons = None
|
||||||
|
mock_appliances_manager.return_value.washer_dryers = [
|
||||||
|
{"SAID": MOCK_SAID3, "NAME": "washer"},
|
||||||
|
{"SAID": MOCK_SAID4, "NAME": "dryer"},
|
||||||
|
]
|
||||||
|
yield mock_appliances_manager
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_backend_selector_api")
|
@pytest.fixture(name="mock_backend_selector_api")
|
||||||
def fixture_mock_backend_selector_api():
|
def fixture_mock_backend_selector_api():
|
||||||
"""Set up BackendSelector fixture."""
|
"""Set up BackendSelector fixture."""
|
||||||
@ -115,8 +130,6 @@ def side_effect_function(*args, **kwargs):
|
|||||||
return "0"
|
return "0"
|
||||||
if args[0] == "WashCavity_OpStatusBulkDispense1Level":
|
if args[0] == "WashCavity_OpStatusBulkDispense1Level":
|
||||||
return "3"
|
return "3"
|
||||||
if args[0] == "Cavity_TimeStatusEstTimeRemaining":
|
|
||||||
return "4000"
|
|
||||||
|
|
||||||
|
|
||||||
def get_sensor_mock(said):
|
def get_sensor_mock(said):
|
||||||
@ -141,13 +154,13 @@ def get_sensor_mock(said):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_sensor1_api", autouse=False)
|
@pytest.fixture(name="mock_sensor1_api", autouse=False)
|
||||||
def fixture_mock_sensor1_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_sensor1_api(mock_auth_api, mock_appliances_manager_laundry_api):
|
||||||
"""Set up sensor API fixture."""
|
"""Set up sensor API fixture."""
|
||||||
yield get_sensor_mock(MOCK_SAID3)
|
yield get_sensor_mock(MOCK_SAID3)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="mock_sensor2_api", autouse=False)
|
@pytest.fixture(name="mock_sensor2_api", autouse=False)
|
||||||
def fixture_mock_sensor2_api(mock_auth_api, mock_appliances_manager_api):
|
def fixture_mock_sensor2_api(mock_auth_api, mock_appliances_manager_laundry_api):
|
||||||
"""Set up sensor API fixture."""
|
"""Set up sensor API fixture."""
|
||||||
yield get_sensor_mock(MOCK_SAID4)
|
yield get_sensor_mock(MOCK_SAID4)
|
||||||
|
|
||||||
@ -161,5 +174,7 @@ def fixture_mock_sensor_api_instances(mock_sensor1_api, mock_sensor2_api):
|
|||||||
mock_sensor_api.side_effect = [
|
mock_sensor_api.side_effect = [
|
||||||
mock_sensor1_api,
|
mock_sensor1_api,
|
||||||
mock_sensor2_api,
|
mock_sensor2_api,
|
||||||
|
mock_sensor1_api,
|
||||||
|
mock_sensor2_api,
|
||||||
]
|
]
|
||||||
yield mock_sensor_api
|
yield mock_sensor_api
|
||||||
|
@ -17,7 +17,7 @@ async def update_sensor_state(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entity_id: str,
|
entity_id: str,
|
||||||
mock_sensor_api_instance: MagicMock,
|
mock_sensor_api_instance: MagicMock,
|
||||||
):
|
) -> None:
|
||||||
"""Simulate an update trigger from the API."""
|
"""Simulate an update trigger from the API."""
|
||||||
|
|
||||||
for call in mock_sensor_api_instance.register_attr_callback.call_args_list:
|
for call in mock_sensor_api_instance.register_attr_callback.call_args_list:
|
||||||
@ -44,7 +44,7 @@ async def test_dryer_sensor_values(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_sensor_api_instances: MagicMock,
|
mock_sensor_api_instances: MagicMock,
|
||||||
mock_sensor2_api: MagicMock,
|
mock_sensor2_api: MagicMock,
|
||||||
):
|
) -> None:
|
||||||
"""Test the sensor value callbacks."""
|
"""Test the sensor value callbacks."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
||||||
@ -108,7 +108,7 @@ async def test_washer_sensor_values(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_sensor_api_instances: MagicMock,
|
mock_sensor_api_instances: MagicMock,
|
||||||
mock_sensor1_api: MagicMock,
|
mock_sensor1_api: MagicMock,
|
||||||
):
|
) -> None:
|
||||||
"""Test the sensor value callbacks."""
|
"""Test the sensor value callbacks."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
||||||
@ -147,6 +147,21 @@ async def test_washer_sensor_values(
|
|||||||
assert state.state == thetimestamp.isoformat()
|
assert state.state == thetimestamp.isoformat()
|
||||||
|
|
||||||
state_id = f"{entity_id.split('_')[0]}_detergent_level"
|
state_id = f"{entity_id.split('_')[0]}_detergent_level"
|
||||||
|
registry = entity_registry.async_get(hass)
|
||||||
|
entry = registry.async_get(state_id)
|
||||||
|
assert entry
|
||||||
|
assert entry.disabled
|
||||||
|
assert entry.disabled_by is entity_registry.RegistryEntryDisabler.INTEGRATION
|
||||||
|
|
||||||
|
update_entry = registry.async_update_entity(entry.entity_id, disabled_by=None)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert update_entry != entry
|
||||||
|
assert update_entry.disabled is False
|
||||||
|
state = hass.states.get(state_id)
|
||||||
|
assert state is None
|
||||||
|
|
||||||
|
await hass.config_entries.async_reload(entry.config_entry_id)
|
||||||
state = hass.states.get(state_id)
|
state = hass.states.get(state_id)
|
||||||
assert state is not None
|
assert state is not None
|
||||||
assert state.state == "50"
|
assert state.state == "50"
|
||||||
@ -253,7 +268,7 @@ async def test_washer_sensor_values(
|
|||||||
async def test_restore_state(
|
async def test_restore_state(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_sensor_api_instances: MagicMock,
|
mock_sensor_api_instances: MagicMock,
|
||||||
):
|
) -> None:
|
||||||
"""Test sensor restore state."""
|
"""Test sensor restore state."""
|
||||||
# Home assistant is not running yet
|
# Home assistant is not running yet
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
@ -288,7 +303,7 @@ async def test_callback(
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_sensor_api_instances: MagicMock,
|
mock_sensor_api_instances: MagicMock,
|
||||||
mock_sensor1_api: MagicMock,
|
mock_sensor1_api: MagicMock,
|
||||||
):
|
) -> None:
|
||||||
"""Test callback timestamp callback function."""
|
"""Test callback timestamp callback function."""
|
||||||
hass.state = CoreState.not_running
|
hass.state = CoreState.not_running
|
||||||
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
||||||
@ -314,9 +329,9 @@ async def test_callback(
|
|||||||
# restore from cache
|
# restore from cache
|
||||||
state = hass.states.get("sensor.washer_end_time")
|
state = hass.states.get("sensor.washer_end_time")
|
||||||
assert state.state == thetimestamp.isoformat()
|
assert state.state == thetimestamp.isoformat()
|
||||||
callback = mock_sensor1_api.register_attr_callback.call_args_list[2][0][0]
|
callback = mock_sensor1_api.register_attr_callback.call_args_list[1][0][0]
|
||||||
callback()
|
callback()
|
||||||
# await hass.async_block_till_done()
|
|
||||||
state = hass.states.get("sensor.washer_end_time")
|
state = hass.states.get("sensor.washer_end_time")
|
||||||
assert state.state == thetimestamp.isoformat()
|
assert state.state == thetimestamp.isoformat()
|
||||||
mock_sensor1_api.get_machine_state.return_value = MachineState.RunningMainCycle
|
mock_sensor1_api.get_machine_state.return_value = MachineState.RunningMainCycle
|
||||||
|
Loading…
x
Reference in New Issue
Block a user