Improve internal naming (#128390)

* Improve internal naming

* revert select
This commit is contained in:
Thomas55555 2024-10-14 23:15:02 +02:00 committed by GitHub
parent a5ecbd547c
commit 11e8e56e05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 16 additions and 18 deletions

View File

@ -28,7 +28,7 @@ class AutomowerBinarySensorEntityDescription(BinarySensorEntityDescription):
value_fn: Callable[[MowerAttributes], bool] value_fn: Callable[[MowerAttributes], bool]
BINARY_SENSOR_TYPES: tuple[AutomowerBinarySensorEntityDescription, ...] = ( MOWER_BINARY_SENSOR_TYPES: tuple[AutomowerBinarySensorEntityDescription, ...] = (
AutomowerBinarySensorEntityDescription( AutomowerBinarySensorEntityDescription(
key="battery_charging", key="battery_charging",
value_fn=lambda data: data.mower.activity == MowerActivities.CHARGING, value_fn=lambda data: data.mower.activity == MowerActivities.CHARGING,
@ -57,7 +57,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
AutomowerBinarySensorEntity(mower_id, coordinator, description) AutomowerBinarySensorEntity(mower_id, coordinator, description)
for mower_id in coordinator.data for mower_id in coordinator.data
for description in BINARY_SENSOR_TYPES for description in MOWER_BINARY_SENSOR_TYPES
) )

View File

@ -46,7 +46,7 @@ class AutomowerButtonEntityDescription(ButtonEntityDescription):
press_fn: Callable[[AutomowerSession, str], Awaitable[Any]] press_fn: Callable[[AutomowerSession, str], Awaitable[Any]]
BUTTON_TYPES: tuple[AutomowerButtonEntityDescription, ...] = ( MOWER_BUTTON_TYPES: tuple[AutomowerButtonEntityDescription, ...] = (
AutomowerButtonEntityDescription( AutomowerButtonEntityDescription(
key="confirm_error", key="confirm_error",
translation_key="confirm_error", translation_key="confirm_error",
@ -73,7 +73,7 @@ async def async_setup_entry(
async_add_entities( async_add_entities(
AutomowerButtonEntity(mower_id, coordinator, description) AutomowerButtonEntity(mower_id, coordinator, description)
for mower_id in coordinator.data for mower_id in coordinator.data
for description in BUTTON_TYPES for description in MOWER_BUTTON_TYPES
if description.exists_fn(coordinator.data[mower_id]) if description.exists_fn(coordinator.data[mower_id])
) )

View File

@ -65,7 +65,7 @@ class AutomowerNumberEntityDescription(NumberEntityDescription):
set_value_fn: Callable[[AutomowerSession, str, float], Awaitable[Any]] set_value_fn: Callable[[AutomowerSession, str, float], Awaitable[Any]]
NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = ( MOWER_NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = (
AutomowerNumberEntityDescription( AutomowerNumberEntityDescription(
key="cutting_height", key="cutting_height",
translation_key="cutting_height", translation_key="cutting_height",
@ -81,7 +81,7 @@ NUMBER_TYPES: tuple[AutomowerNumberEntityDescription, ...] = (
@dataclass(frozen=True, kw_only=True) @dataclass(frozen=True, kw_only=True)
class AutomowerWorkAreaNumberEntityDescription(NumberEntityDescription): class WorkAreaNumberEntityDescription(NumberEntityDescription):
"""Describes Automower work area number entity.""" """Describes Automower work area number entity."""
value_fn: Callable[[WorkArea], int] value_fn: Callable[[WorkArea], int]
@ -91,8 +91,8 @@ class AutomowerWorkAreaNumberEntityDescription(NumberEntityDescription):
] ]
WORK_AREA_NUMBER_TYPES: tuple[AutomowerWorkAreaNumberEntityDescription, ...] = ( WORK_AREA_NUMBER_TYPES: tuple[WorkAreaNumberEntityDescription, ...] = (
AutomowerWorkAreaNumberEntityDescription( WorkAreaNumberEntityDescription(
key="cutting_height_work_area", key="cutting_height_work_area",
translation_key_fn=_work_area_translation_key, translation_key_fn=_work_area_translation_key,
entity_category=EntityCategory.CONFIG, entity_category=EntityCategory.CONFIG,
@ -117,7 +117,7 @@ async def async_setup_entry(
_work_areas = coordinator.data[mower_id].work_areas _work_areas = coordinator.data[mower_id].work_areas
if _work_areas is not None: if _work_areas is not None:
entities.extend( entities.extend(
AutomowerWorkAreaNumberEntity( WorkAreaNumberEntity(
mower_id, coordinator, description, work_area_id mower_id, coordinator, description, work_area_id
) )
for description in WORK_AREA_NUMBER_TYPES for description in WORK_AREA_NUMBER_TYPES
@ -126,7 +126,7 @@ async def async_setup_entry(
async_remove_work_area_entities(hass, coordinator, entry, mower_id) async_remove_work_area_entities(hass, coordinator, entry, mower_id)
entities.extend( entities.extend(
AutomowerNumberEntity(mower_id, coordinator, description) AutomowerNumberEntity(mower_id, coordinator, description)
for description in NUMBER_TYPES for description in MOWER_NUMBER_TYPES
if description.exists_fn(coordinator.data[mower_id]) if description.exists_fn(coordinator.data[mower_id])
) )
async_add_entities(entities) async_add_entities(entities)
@ -161,16 +161,16 @@ class AutomowerNumberEntity(AutomowerControlEntity, NumberEntity):
) )
class AutomowerWorkAreaNumberEntity(WorkAreaControlEntity, NumberEntity): class WorkAreaNumberEntity(WorkAreaControlEntity, NumberEntity):
"""Defining the AutomowerWorkAreaNumberEntity with AutomowerWorkAreaNumberEntityDescription.""" """Defining the WorkAreaNumberEntity with WorkAreaNumberEntityDescription."""
entity_description: AutomowerWorkAreaNumberEntityDescription entity_description: WorkAreaNumberEntityDescription
def __init__( def __init__(
self, self,
mower_id: str, mower_id: str,
coordinator: AutomowerDataUpdateCoordinator, coordinator: AutomowerDataUpdateCoordinator,
description: AutomowerWorkAreaNumberEntityDescription, description: WorkAreaNumberEntityDescription,
work_area_id: int, work_area_id: int,
) -> None: ) -> None:
"""Set up AutomowerNumberEntity.""" """Set up AutomowerNumberEntity."""

View File

@ -40,9 +40,7 @@ async def async_setup_entry(
_stay_out_zones = coordinator.data[mower_id].stay_out_zones _stay_out_zones = coordinator.data[mower_id].stay_out_zones
if _stay_out_zones is not None: if _stay_out_zones is not None:
entities.extend( entities.extend(
AutomowerStayOutZoneSwitchEntity( StayOutZoneSwitchEntity(coordinator, mower_id, stay_out_zone_uid)
coordinator, mower_id, stay_out_zone_uid
)
for stay_out_zone_uid in _stay_out_zones.zones for stay_out_zone_uid in _stay_out_zones.zones
) )
async_remove_entities(hass, coordinator, entry, mower_id) async_remove_entities(hass, coordinator, entry, mower_id)
@ -86,7 +84,7 @@ class AutomowerScheduleSwitchEntity(AutomowerControlEntity, SwitchEntity):
await self.coordinator.api.commands.resume_schedule(self.mower_id) await self.coordinator.api.commands.resume_schedule(self.mower_id)
class AutomowerStayOutZoneSwitchEntity(AutomowerControlEntity, SwitchEntity): class StayOutZoneSwitchEntity(AutomowerControlEntity, SwitchEntity):
"""Defining the Automower stay out zone switch.""" """Defining the Automower stay out zone switch."""
_attr_translation_key = "stay_out_zones" _attr_translation_key = "stay_out_zones"