mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix unnecessary logging of turn on/off feature flags in Climate (#121387)
This commit is contained in:
parent
f115efe51d
commit
ac8ea8356c
@ -377,6 +377,14 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
||||
# Return if integration has migrated already
|
||||
return
|
||||
|
||||
supported_features = self.supported_features
|
||||
if supported_features & (
|
||||
ClimateEntityFeature.TURN_ON | ClimateEntityFeature.TURN_ON
|
||||
):
|
||||
# The entity supports both turn_on and turn_off, the backwards compatibility
|
||||
# checks are not needed
|
||||
return
|
||||
|
||||
supported_features = self.supported_features
|
||||
if not supported_features & ClimateEntityFeature.TURN_OFF and (
|
||||
type(self).async_turn_off is not ClimateEntity.async_turn_off
|
||||
|
@ -709,6 +709,68 @@ async def test_no_warning_integration_has_migrated(
|
||||
)
|
||||
|
||||
|
||||
async def test_no_warning_integration_implement_feature_flags(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, config_flow_fixture: None
|
||||
) -> None:
|
||||
"""Test no warning when integration uses the correct feature flags."""
|
||||
|
||||
class MockClimateEntityTest(MockClimateEntity):
|
||||
"""Mock Climate device."""
|
||||
|
||||
_attr_supported_features = (
|
||||
ClimateEntityFeature.FAN_MODE
|
||||
| ClimateEntityFeature.PRESET_MODE
|
||||
| ClimateEntityFeature.SWING_MODE
|
||||
| ClimateEntityFeature.TURN_OFF
|
||||
| ClimateEntityFeature.TURN_ON
|
||||
)
|
||||
|
||||
async def async_setup_entry_init(
|
||||
hass: HomeAssistant, config_entry: ConfigEntry
|
||||
) -> bool:
|
||||
"""Set up test config entry."""
|
||||
await hass.config_entries.async_forward_entry_setups(config_entry, [DOMAIN])
|
||||
return True
|
||||
|
||||
async def async_setup_entry_climate_platform(
|
||||
hass: HomeAssistant,
|
||||
config_entry: ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up test climate platform via config entry."""
|
||||
async_add_entities(
|
||||
[MockClimateEntityTest(name="test", entity_id="climate.test")]
|
||||
)
|
||||
|
||||
mock_integration(
|
||||
hass,
|
||||
MockModule(
|
||||
"test",
|
||||
async_setup_entry=async_setup_entry_init,
|
||||
),
|
||||
built_in=False,
|
||||
)
|
||||
mock_platform(
|
||||
hass,
|
||||
"test.climate",
|
||||
MockPlatform(async_setup_entry=async_setup_entry_climate_platform),
|
||||
)
|
||||
|
||||
with patch.object(
|
||||
MockClimateEntityTest, "__module__", "tests.custom_components.climate.test_init"
|
||||
):
|
||||
config_entry = MockConfigEntry(domain="test")
|
||||
config_entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("climate.test")
|
||||
assert state is not None
|
||||
|
||||
assert "does not set ClimateEntityFeature" not in caplog.text
|
||||
assert "implements HVACMode(s):" not in caplog.text
|
||||
|
||||
|
||||
async def test_turn_on_off_toggle(hass: HomeAssistant) -> None:
|
||||
"""Test turn_on/turn_off/toggle methods."""
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user