Guard Guardian switches from redundant on/off calls (#78791)

This commit is contained in:
Aaron Bach 2022-09-19 13:15:32 -06:00 committed by GitHub
parent 691df5a394
commit d591787077
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -146,6 +146,9 @@ class ValveControllerSwitch(ValveControllerEntity, SwitchEntity):
async def async_turn_off(self, **kwargs: Any) -> None: async def async_turn_off(self, **kwargs: Any) -> None:
"""Turn the switch off.""" """Turn the switch off."""
if not self._attr_is_on:
return
try: try:
async with self._client: async with self._client:
await self.entity_description.off_action(self._client) await self.entity_description.off_action(self._client)
@ -159,6 +162,9 @@ class ValveControllerSwitch(ValveControllerEntity, SwitchEntity):
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the switch on.""" """Turn the switch on."""
if self._attr_is_on:
return
try: try:
async with self._client: async with self._client:
await self.entity_description.on_action(self._client) await self.entity_description.on_action(self._client)