Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark unused sync toggle method from ToggleEntity as final #72370

Merged
merged 1 commit into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions homeassistant/components/hdmi_cec/switch.py
Expand Up @@ -52,15 +52,6 @@ def turn_off(self, **kwargs) -> None:
self._state = STATE_OFF
self.schedule_update_ha_state(force_refresh=False)

def toggle(self, **kwargs):
"""Toggle the entity."""
self._device.toggle()
if self._state == STATE_ON:
self._state = STATE_OFF
else:
self._state = STATE_ON
self.schedule_update_ha_state(force_refresh=False)

@property
def is_on(self) -> bool:
"""Return True if entity is on."""
Expand Down
17 changes: 11 additions & 6 deletions homeassistant/helpers/entity.py
Expand Up @@ -1025,15 +1025,20 @@ async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the entity off."""
await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))

@final
def toggle(self, **kwargs: Any) -> None:
"""Toggle the entity."""
if self.is_on:
self.turn_off(**kwargs)
else:
self.turn_on(**kwargs)
"""Toggle the entity.

This method will never be called by Home Assistant and should not be implemented
by integrations.
"""

async def async_toggle(self, **kwargs: Any) -> None:
"""Toggle the entity."""
"""Toggle the entity.

This method should typically not be implemented by integrations, it's enough to
implement async_turn_on + async_turn_off or turn_on + turn_off.
"""
if self.is_on:
await self.async_turn_off(**kwargs)
else:
Expand Down