From eacd900efa860b428bf12cb30a48f15846f37a09 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Thu, 21 Mar 2024 11:41:12 +0000 Subject: [PATCH] Linting --- custom_components/battery_notes/sensor.py | 30 +++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/custom_components/battery_notes/sensor.py b/custom_components/battery_notes/sensor.py index 705d85853..9cac23915 100644 --- a/custom_components/battery_notes/sensor.py +++ b/custom_components/battery_notes/sensor.py @@ -1,4 +1,5 @@ """Sensor platform for battery_notes.""" + from __future__ import annotations from collections.abc import Mapping @@ -113,10 +114,13 @@ def async_add_to_device(hass: HomeAssistant, entry: ConfigEntry) -> str | None: device_id = entry.data.get(CONF_DEVICE_ID) if device_registry.async_get(device_id): - device_registry.async_update_device(device_id, add_config_entry_id=entry.entry_id) + device_registry.async_update_device( + device_id, add_config_entry_id=entry.entry_id + ) return device_id return None + async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, @@ -248,6 +252,7 @@ async def async_setup_platform( await async_setup_reload_service(hass, DOMAIN, PLATFORMS) + class BatteryNotesBatteryPlusSensor( SensorEntity, CoordinatorEntity[BatteryNotesCoordinator] ): @@ -361,9 +366,7 @@ async def _entity_rename_listener(event: Event) -> None: ) entity_registry = er.async_get(self.hass) - if ( - entity_registry.async_get(entity_id) is not None - ): + if entity_registry.async_get(entity_id) is not None: entity_registry.async_update_entity_options( entity_id, DOMAIN, @@ -387,7 +390,7 @@ def _filter_entity_id(event_data: Mapping[str, Any] | Event) -> bool: """Only dispatch the listener for update events concerning the source entity.""" # Breaking change in 2024.4.0, check for Event for versions prior to this - if type(event_data) is Event: # Intentionally avoid `isinstance` because it's slow and we trust `Event` is not subclassed + if type(event_data) is Event: # pylint: disable=unidiomatic-typecheck event_data = event_data.data return ( @@ -618,8 +621,7 @@ def __init__( self.entity_description = description self._native_value = None - super().__init__( - coordinator=coordinator) + super().__init__(coordinator=coordinator) self._set_native_value(log_on_error=False) @@ -633,7 +635,9 @@ def __init__( identifiers=device_entry.identifiers, ) - self.entity_id = f"sensor.{coordinator.device_name.lower()}_{description.key}" + self.entity_id = ( + f"sensor.{coordinator.device_name.lower()}_{description.key}" + ) async def async_added_to_hass(self) -> None: """Handle added to Hass.""" @@ -643,7 +647,10 @@ def _set_native_value(self, log_on_error=True): # pylint: disable=unused-argument device_entry = self.coordinator.store.async_get_device(self._device_id) if device_entry: - if LAST_REPLACED in device_entry and device_entry[LAST_REPLACED] is not None: + if ( + LAST_REPLACED in device_entry + and device_entry[LAST_REPLACED] is not None + ): last_replaced_date = datetime.fromisoformat( str(device_entry[LAST_REPLACED]) + "+00:00" ) @@ -658,7 +665,10 @@ def _handle_coordinator_update(self) -> None: device_entry = self.coordinator.store.async_get_device(self._device_id) if device_entry: - if LAST_REPLACED in device_entry and device_entry[LAST_REPLACED] is not None: + if ( + LAST_REPLACED in device_entry + and device_entry[LAST_REPLACED] is not None + ): last_replaced_date = datetime.fromisoformat( str(device_entry[LAST_REPLACED]) + "+00:00" )