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
a704e7b40d
commit
2af4d2152b
3 changed files with 45 additions and 13 deletions
|
@ -119,11 +119,12 @@ SENSORS: tuple[WhirlpoolSensorEntityDescription, ...] = (
|
|||
key="DispenseLevel",
|
||||
name="Detergent Level",
|
||||
translation_key="whirlpool_tank",
|
||||
entity_registry_enabled_default=False,
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=list(TANK_FILL.values()),
|
||||
value_fn=lambda WasherDryer: TANK_FILL[
|
||||
value_fn=lambda WasherDryer: TANK_FILL.get(
|
||||
WasherDryer.get_attribute("WashCavity_OpStatusBulkDispense1Level")
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -265,6 +266,7 @@ class WasherDryerTimeClass(RestoreSensor):
|
|||
|
||||
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)
|
||||
await self._wd.disconnect()
|
||||
|
||||
@property
|
||||
|
|
|
@ -49,6 +49,21 @@ def fixture_mock_appliances_manager_api():
|
|||
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")
|
||||
def fixture_mock_backend_selector_api():
|
||||
"""Set up BackendSelector fixture."""
|
||||
|
@ -115,8 +130,6 @@ def side_effect_function(*args, **kwargs):
|
|||
return "0"
|
||||
if args[0] == "WashCavity_OpStatusBulkDispense1Level":
|
||||
return "3"
|
||||
if args[0] == "Cavity_TimeStatusEstTimeRemaining":
|
||||
return "4000"
|
||||
|
||||
|
||||
def get_sensor_mock(said):
|
||||
|
@ -141,13 +154,13 @@ def get_sensor_mock(said):
|
|||
|
||||
|
||||
@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."""
|
||||
return get_sensor_mock(MOCK_SAID3)
|
||||
|
||||
|
||||
@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."""
|
||||
return 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_sensor1_api,
|
||||
mock_sensor2_api,
|
||||
mock_sensor1_api,
|
||||
mock_sensor2_api,
|
||||
]
|
||||
yield mock_sensor_api
|
||||
|
|
|
@ -17,7 +17,7 @@ async def update_sensor_state(
|
|||
hass: HomeAssistant,
|
||||
entity_id: str,
|
||||
mock_sensor_api_instance: MagicMock,
|
||||
):
|
||||
) -> None:
|
||||
"""Simulate an update trigger from the API."""
|
||||
|
||||
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,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
mock_sensor2_api: MagicMock,
|
||||
):
|
||||
) -> None:
|
||||
"""Test the sensor value callbacks."""
|
||||
hass.state = CoreState.not_running
|
||||
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
||||
|
@ -108,7 +108,7 @@ async def test_washer_sensor_values(
|
|||
hass: HomeAssistant,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
mock_sensor1_api: MagicMock,
|
||||
):
|
||||
) -> None:
|
||||
"""Test the sensor value callbacks."""
|
||||
hass.state = CoreState.not_running
|
||||
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()
|
||||
|
||||
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)
|
||||
assert state is not None
|
||||
assert state.state == "50"
|
||||
|
@ -253,7 +268,7 @@ async def test_washer_sensor_values(
|
|||
async def test_restore_state(
|
||||
hass: HomeAssistant,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
):
|
||||
) -> None:
|
||||
"""Test sensor restore state."""
|
||||
# Home assistant is not running yet
|
||||
hass.state = CoreState.not_running
|
||||
|
@ -288,7 +303,7 @@ async def test_callback(
|
|||
hass: HomeAssistant,
|
||||
mock_sensor_api_instances: MagicMock,
|
||||
mock_sensor1_api: MagicMock,
|
||||
):
|
||||
) -> None:
|
||||
"""Test callback timestamp callback function."""
|
||||
hass.state = CoreState.not_running
|
||||
thetimestamp: datetime = datetime(2022, 11, 29, 00, 00, 00, 00, timezone.utc)
|
||||
|
@ -314,9 +329,9 @@ async def test_callback(
|
|||
# restore from cache
|
||||
state = hass.states.get("sensor.washer_end_time")
|
||||
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()
|
||||
# await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("sensor.washer_end_time")
|
||||
assert state.state == thetimestamp.isoformat()
|
||||
mock_sensor1_api.get_machine_state.return_value = MachineState.RunningMainCycle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue