Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-codechimp committed Mar 21, 2024
1 parent d9555b9 commit eacd900
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions custom_components/battery_notes/sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sensor platform for battery_notes."""

from __future__ import annotations

from collections.abc import Mapping
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -248,6 +252,7 @@ async def async_setup_platform(

await async_setup_reload_service(hass, DOMAIN, PLATFORMS)


class BatteryNotesBatteryPlusSensor(
SensorEntity, CoordinatorEntity[BatteryNotesCoordinator]
):
Expand Down Expand Up @@ -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,
Expand All @@ -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 (
Expand Down Expand Up @@ -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)

Expand All @@ -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."""
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand Down

0 comments on commit eacd900

Please sign in to comment.