Makes entites available in Husqvarna Automower when mower is in error state (#149261)

This commit is contained in:
Thomas55555 2025-07-23 12:39:17 +02:00 committed by GitHub
parent 232b34609c
commit b37273ed33
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 30 deletions

View File

@ -14,11 +14,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import AutomowerConfigEntry from . import AutomowerConfigEntry
from .coordinator import AutomowerDataUpdateCoordinator from .coordinator import AutomowerDataUpdateCoordinator
from .entity import ( from .entity import AutomowerControlEntity, handle_sending_exception
AutomowerAvailableEntity,
_check_error_free,
handle_sending_exception,
)
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -45,7 +41,6 @@ MOWER_BUTTON_TYPES: tuple[AutomowerButtonEntityDescription, ...] = (
AutomowerButtonEntityDescription( AutomowerButtonEntityDescription(
key="sync_clock", key="sync_clock",
translation_key="sync_clock", translation_key="sync_clock",
available_fn=_check_error_free,
press_fn=lambda session, mower_id: session.commands.set_datetime(mower_id), press_fn=lambda session, mower_id: session.commands.set_datetime(mower_id),
), ),
) )
@ -71,7 +66,7 @@ async def async_setup_entry(
_async_add_new_devices(set(coordinator.data)) _async_add_new_devices(set(coordinator.data))
class AutomowerButtonEntity(AutomowerAvailableEntity, ButtonEntity): class AutomowerButtonEntity(AutomowerControlEntity, ButtonEntity):
"""Defining the AutomowerButtonEntity.""" """Defining the AutomowerButtonEntity."""
entity_description: AutomowerButtonEntityDescription entity_description: AutomowerButtonEntityDescription

View File

@ -37,15 +37,6 @@ ERROR_STATES = [
] ]
@callback
def _check_error_free(mower_attributes: MowerAttributes) -> bool:
"""Check if the mower has any errors."""
return (
mower_attributes.mower.state not in ERROR_STATES
or mower_attributes.mower.activity not in ERROR_ACTIVITIES
)
@callback @callback
def _work_area_translation_key(work_area_id: int, key: str) -> str: def _work_area_translation_key(work_area_id: int, key: str) -> str:
"""Return the translation key.""" """Return the translation key."""
@ -120,25 +111,20 @@ class AutomowerBaseEntity(CoordinatorEntity[AutomowerDataUpdateCoordinator]):
return super().available and self.mower_id in self.coordinator.data return super().available and self.mower_id in self.coordinator.data
class AutomowerAvailableEntity(AutomowerBaseEntity): class AutomowerControlEntity(AutomowerBaseEntity):
"""Replies available when the mower is connected.""" """Replies available when the mower is connected."""
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return True if the device is available.""" """Return True if the device is available."""
return super().available and self.mower_attributes.metadata.connected return (
super().available
and self.mower_attributes.metadata.connected
and self.mower_attributes.mower.state != MowerStates.OFF
)
class AutomowerControlEntity(AutomowerAvailableEntity): class WorkAreaAvailableEntity(AutomowerControlEntity):
"""Replies available when the mower is connected and not in error state."""
@property
def available(self) -> bool:
"""Return True if the device is available."""
return super().available and _check_error_free(self.mower_attributes)
class WorkAreaAvailableEntity(AutomowerAvailableEntity):
"""Base entity for work areas.""" """Base entity for work areas."""
def __init__( def __init__(

View File

@ -20,7 +20,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from . import AutomowerConfigEntry from . import AutomowerConfigEntry
from .const import DOMAIN, ERROR_STATES from .const import DOMAIN, ERROR_STATES
from .coordinator import AutomowerDataUpdateCoordinator from .coordinator import AutomowerDataUpdateCoordinator
from .entity import AutomowerAvailableEntity, handle_sending_exception from .entity import AutomowerBaseEntity, handle_sending_exception
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -89,7 +89,7 @@ async def async_setup_entry(
) )
class AutomowerLawnMowerEntity(AutomowerAvailableEntity, LawnMowerEntity): class AutomowerLawnMowerEntity(AutomowerBaseEntity, LawnMowerEntity):
"""Defining each mower Entity.""" """Defining each mower Entity."""
_attr_name = None _attr_name = None