Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Shabala committed Nov 12, 2024
1 parent bf508dc commit 26d0999
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions custom_components/bermuda/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
UnitOfLength,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import entity_registry as er
from homeassistant.helpers.dispatcher import async_dispatcher_connect

from .const import (
_LOGGER,
Expand Down Expand Up @@ -433,6 +433,7 @@ def name(self):
"""Gets the name of the sensor."""
return "Visible device count"


class BermudaSensorScannerEntity(BermudaSensor):
"""Sensor for entity ID of nearest detected scanner."""

Expand All @@ -447,21 +448,18 @@ def name(self):
@property
def native_value(self):
scanner_mac = next(
(mac for mac in self._device.scanners.keys()
if mac.upper() in self._device.area_scanner.upper()),
None
(mac for mac in self._device.scanners if mac.upper() in self._device.area_scanner.upper()), None
)

if scanner_mac:
device = self.devreg.async_get_device(
{}, {(dr.CONNECTION_NETWORK_MAC, scanner_mac.lower())}
)
device = self.devreg.async_get_device({}, {(dr.CONNECTION_NETWORK_MAC, scanner_mac.lower())})
if device:
# Get light/switch entity for this device
ent_reg = er.async_get(self.hass)
entities = [
entry.entity_id for entry in ent_reg.entities.values()
if entry.domain in ["light", "switch"] # Filter out devices unlikely to be bluetooth proxies
entry.entity_id
for entry in ent_reg.entities.values()
if entry.domain in ["light", "switch"] # Filter out devices unlikely to be bluetooth proxies
and entry.device_id == device.id
]
if entities:
Expand All @@ -471,19 +469,11 @@ def native_value(self):
@property
def extra_state_attributes(self) -> Mapping[str, Any] | None:
scanner_mac = next(
(mac for mac in self._device.scanners.keys()
if mac.upper() in self._device.area_scanner.upper()),
None
(mac for mac in self._device.scanners if mac.upper() in self._device.area_scanner.upper()), None
)

if scanner_mac:
device = self.devreg.async_get_device(
{}, {(dr.CONNECTION_NETWORK_MAC, scanner_mac.lower())}
)
device = self.devreg.async_get_device({}, {(dr.CONNECTION_NETWORK_MAC, scanner_mac.lower())})
if device:
return {
"scanner_mac": scanner_mac,
"device_name": device.name,
"area_id": device.area_id
}
return {"scanner_mac": scanner_mac, "device_name": device.name, "area_id": device.area_id}
return None

0 comments on commit 26d0999

Please sign in to comment.