mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
Add oven light to Whirlpool (#176364)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Abílio Costa <abmantis@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
Abílio Costa
Copilot Autofix powered by AI
parent
3576da27fd
commit
9fee812da9
@@ -21,6 +21,7 @@ PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.BUTTON,
|
||||
Platform.CLIMATE,
|
||||
Platform.LIGHT,
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
]
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Light platform for the Whirlpool Appliances integration."""
|
||||
|
||||
from typing import Any, override
|
||||
|
||||
from whirlpool.oven import Cavity as OvenCavity, Oven
|
||||
|
||||
from homeassistant.components.light import ColorMode, LightEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from . import WhirlpoolConfigEntry
|
||||
from .entity import WhirlpoolOvenEntity
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
config_entry: WhirlpoolConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the light platform."""
|
||||
appliances_manager = config_entry.runtime_data
|
||||
async_add_entities(
|
||||
WhirlpoolOvenLight(oven, cavity)
|
||||
for oven in appliances_manager.ovens
|
||||
for cavity in (OvenCavity.Upper, OvenCavity.Lower)
|
||||
if oven.get_oven_cavity_exists(cavity)
|
||||
)
|
||||
|
||||
|
||||
class WhirlpoolOvenLight(WhirlpoolOvenEntity, LightEntity):
|
||||
"""Light for an oven cavity."""
|
||||
|
||||
_appliance: Oven
|
||||
|
||||
_attr_color_mode = ColorMode.ONOFF
|
||||
_attr_supported_color_modes = {ColorMode.ONOFF}
|
||||
|
||||
def __init__(self, appliance: Oven, cavity: OvenCavity) -> None:
|
||||
"""Initialize the oven light."""
|
||||
super().__init__(appliance, cavity, "oven_light", "-light")
|
||||
|
||||
@property
|
||||
@override
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return whether the light is on."""
|
||||
return self._appliance.get_light(self.cavity)
|
||||
|
||||
@override
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn the light on."""
|
||||
WhirlpoolOvenLight._check_service_request(
|
||||
await self._appliance.set_light(True, self.cavity)
|
||||
)
|
||||
|
||||
@override
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn the light off."""
|
||||
WhirlpoolOvenLight._check_service_request(
|
||||
await self._appliance.set_light(False, self.cavity)
|
||||
)
|
||||
@@ -57,6 +57,17 @@
|
||||
"name": "Upper oven stop"
|
||||
}
|
||||
},
|
||||
"light": {
|
||||
"oven_light": {
|
||||
"name": "Light"
|
||||
},
|
||||
"oven_light_lower": {
|
||||
"name": "Lower oven light"
|
||||
},
|
||||
"oven_light_upper": {
|
||||
"name": "Upper oven light"
|
||||
}
|
||||
},
|
||||
"select": {
|
||||
"refrigerator_temperature_level": {
|
||||
"name": "Temperature level"
|
||||
|
||||
@@ -182,6 +182,7 @@ def mock_oven_single_cavity_api():
|
||||
mock_oven.get_oven_cavity_exists.side_effect = lambda cavity: (
|
||||
cavity == oven.Cavity.Upper
|
||||
)
|
||||
mock_oven.get_light.return_value = True
|
||||
mock_oven.get_temp.return_value = 180
|
||||
mock_oven.get_target_temp.return_value = 200
|
||||
return mock_oven
|
||||
@@ -205,6 +206,7 @@ def mock_oven_dual_cavity_api():
|
||||
oven.Cavity.Lower,
|
||||
)
|
||||
)
|
||||
mock_oven.get_light.side_effect = lambda cavity: cavity == oven.Cavity.Upper
|
||||
mock_oven.get_temp.return_value = 180
|
||||
mock_oven.get_target_temp.return_value = 200
|
||||
return mock_oven
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
# serializer version: 1
|
||||
# name: test_all_entities[light.dual_cavity_oven_lower_oven_light-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'light',
|
||||
'entity_category': None,
|
||||
'entity_id': 'light.dual_cavity_oven_lower_oven_light',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Lower oven light',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Lower oven light',
|
||||
'platform': 'whirlpool',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'oven_light_lower',
|
||||
'unique_id': 'said_oven_dual-light_lower',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[light.dual_cavity_oven_lower_oven_light-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<LightEntityStateAttribute.COLOR_MODE: 'color_mode'>: None,
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Dual cavity oven Lower oven light',
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <LightEntityFeature: 0>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'light.dual_cavity_oven_lower_oven_light',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[light.dual_cavity_oven_upper_oven_light-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'light',
|
||||
'entity_category': None,
|
||||
'entity_id': 'light.dual_cavity_oven_upper_oven_light',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Upper oven light',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Upper oven light',
|
||||
'platform': 'whirlpool',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'oven_light_upper',
|
||||
'unique_id': 'said_oven_dual-light_upper',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[light.dual_cavity_oven_upper_oven_light-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<LightEntityStateAttribute.COLOR_MODE: 'color_mode'>: <ColorMode.ONOFF: 'onoff'>,
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Dual cavity oven Upper oven light',
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <LightEntityFeature: 0>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'light.dual_cavity_oven_upper_oven_light',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[light.single_cavity_oven_light-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'light',
|
||||
'entity_category': None,
|
||||
'entity_id': 'light.single_cavity_oven_light',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Light',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': None,
|
||||
'original_name': 'Light',
|
||||
'platform': 'whirlpool',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'oven_light',
|
||||
'unique_id': 'said_oven_single-light',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_entities[light.single_cavity_oven_light-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<LightEntityStateAttribute.COLOR_MODE: 'color_mode'>: <ColorMode.ONOFF: 'onoff'>,
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'Single cavity oven Light',
|
||||
<LightEntityCapabilityAttribute.SUPPORTED_COLOR_MODES: 'supported_color_modes'>: list([
|
||||
<ColorMode.ONOFF: 'onoff'>,
|
||||
]),
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <LightEntityFeature: 0>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'light.single_cavity_oven_light',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,99 @@
|
||||
"""Test the Whirlpool light platform."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
import whirlpool
|
||||
|
||||
from homeassistant.components.light import (
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import init_integration, snapshot_whirlpool_entities
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
params=[
|
||||
(
|
||||
"light.single_cavity_oven_light",
|
||||
"mock_oven_single_cavity_api",
|
||||
whirlpool.oven.Cavity.Upper,
|
||||
),
|
||||
(
|
||||
"light.dual_cavity_oven_upper_oven_light",
|
||||
"mock_oven_dual_cavity_api",
|
||||
whirlpool.oven.Cavity.Upper,
|
||||
),
|
||||
(
|
||||
"light.dual_cavity_oven_lower_oven_light",
|
||||
"mock_oven_dual_cavity_api",
|
||||
whirlpool.oven.Cavity.Lower,
|
||||
),
|
||||
]
|
||||
)
|
||||
def oven_light_entity(
|
||||
request: pytest.FixtureRequest,
|
||||
) -> tuple[str, str, whirlpool.oven.Cavity]:
|
||||
"""Parametrize the oven light entities."""
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_all_entities(
|
||||
hass: HomeAssistant, snapshot: SnapshotAssertion, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test all entities."""
|
||||
await init_integration(hass)
|
||||
snapshot_whirlpool_entities(hass, entity_registry, snapshot, Platform.LIGHT)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("service", "expected_state"),
|
||||
[(SERVICE_TURN_ON, True), (SERVICE_TURN_OFF, False)],
|
||||
)
|
||||
async def test_turn_on_off(
|
||||
hass: HomeAssistant,
|
||||
oven_light_entity: tuple[str, str, whirlpool.oven.Cavity],
|
||||
request: pytest.FixtureRequest,
|
||||
service: str,
|
||||
expected_state: bool,
|
||||
) -> None:
|
||||
"""Test turning the oven light on and off."""
|
||||
entity_id, mock_fixture, cavity = oven_light_entity
|
||||
mock = request.getfixturevalue(mock_fixture)
|
||||
await init_integration(hass)
|
||||
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
mock.set_light.assert_called_once_with(expected_state, cavity)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("service", [SERVICE_TURN_ON, SERVICE_TURN_OFF])
|
||||
async def test_turn_on_off_failure(
|
||||
hass: HomeAssistant,
|
||||
oven_light_entity: tuple[str, str, whirlpool.oven.Cavity],
|
||||
request: pytest.FixtureRequest,
|
||||
service: str,
|
||||
) -> None:
|
||||
"""Test a failed light request raises HomeAssistantError."""
|
||||
entity_id, mock_fixture, _ = oven_light_entity
|
||||
mock = request.getfixturevalue(mock_fixture)
|
||||
mock.set_light.return_value = False
|
||||
await init_integration(hass)
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
service,
|
||||
{ATTR_ENTITY_ID: entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
Reference in New Issue
Block a user