Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove direct refs to homeassistant.helpers #1353

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test_commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setup Python
uses: "actions/setup-python@v5"
with:
python-version: "3.11"
python-version: "3.12"
- name: Install requirements
run: python3 -m pip install -r requirements_test.txt
- name: Run pytest
Expand Down
12 changes: 6 additions & 6 deletions custom_components/ble_monitor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
CONF_UNIQUE_ID, EVENT_HOMEASSISTANT_STOP)
from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.entity_registry import async_entries_for_device
from homeassistant.helpers import device_registry, entity_registry
from homeassistant.util import dt

from .ble_parser import BleParser
Expand Down Expand Up @@ -400,20 +400,20 @@ async def async_cleanup_entries_service(hass: HomeAssistant, service_data):
"""Remove orphaned entries from device and entity registries."""
_LOGGER.debug("async_cleanup_entries_service")

entity_registry = hass.helpers.entity_registry.async_get(hass)
device_registry = hass.helpers.device_registry.async_get(hass)
ent_registry = entity_registry.async_get(hass)
dev_registry = device_registry.async_get(hass)
config_entry_id = hass.data[DOMAIN]["config_entry_id"]

devices_to_be_removed = [
entry.id
for entry in device_registry.devices.values()
for entry in dev_registry.devices.values()
if config_entry_id in entry.config_entries
]

# Remove devices that don't belong to any entity
for device_id in devices_to_be_removed:
if len(async_entries_for_device(entity_registry, device_id)) == 0:
device_registry.async_remove_device(device_id)
if len(ent_registry.async_entries_for_device(ent_registry, device_id)) == 0:
dev_registry.async_remove_device(device_id)
_LOGGER.debug("device %s will be deleted", device_id)


Expand Down
7 changes: 4 additions & 3 deletions custom_components/ble_monitor/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.const import (ATTR_BATTERY_LEVEL, CONF_DEVICES, CONF_MAC,
CONF_NAME, CONF_UNIQUE_ID, STATE_OFF,
STATE_ON)
from homeassistant.helpers import device_registry, entity_registry
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import dt
Expand Down Expand Up @@ -131,8 +132,8 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man

# Set up binary sensors of configured devices on startup when device model is available in device registry
if self.config[CONF_DEVICES]:
dev_registry = hass.helpers.device_registry.async_get(hass)
ent_registry = hass.helpers.entity_registry.async_get(hass)
dev_registry = device_registry.async_get(hass)
ent_registry = entity_registry.async_get(hass)
for device in self.config[CONF_DEVICES]:
# get device_model and firmware from device registry to setup binary sensor
key = dict_get_or(device)
Expand All @@ -149,7 +150,7 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man
firmware = RENAMED_FIRMWARE_DICT.get(firmware, firmware)
manufacturer = RENAMED_MANUFACTURER_DICT.get(manufacturer, manufacturer)
# get all entities for this device
entity_list = hass.helpers.entity_registry.async_entries_for_device(
entity_list = entity_registry.async_entries_for_device(
registry=ent_registry, device_id=device_id, include_disabled_entities=False
)
# find the measurement key for each entity
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ble_monitor/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
"btsocket>=0.2.0",
"pyric>=0.1.6.3"
],
"version": "12.10.4"
"version": "12.11.1-beta"
}
7 changes: 4 additions & 3 deletions custom_components/ble_monitor/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from homeassistant.const import (ATTR_BATTERY_LEVEL, CONF_DEVICES, CONF_MAC,
CONF_NAME, CONF_TEMPERATURE_UNIT,
CONF_UNIQUE_ID, UnitOfMass, UnitOfTemperature)
from homeassistant.helpers import device_registry, entity_registry
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.typing import StateType
from homeassistant.util import dt
Expand Down Expand Up @@ -140,8 +141,8 @@ async def async_add_sensor(key, device_model, firmware, auto_sensors, manufactur

# setup sensors of configured devices on startup when device model is available in registry
if self.config[CONF_DEVICES]:
dev_registry = hass.helpers.device_registry.async_get(hass)
ent_registry = hass.helpers.entity_registry.async_get(hass)
dev_registry = device_registry.async_get(hass)
ent_registry = entity_registry.async_get(hass)
for device in self.config[CONF_DEVICES]:
# get device_model and firmware from device registry to setup sensor
key = dict_get_or(device)
Expand All @@ -158,7 +159,7 @@ async def async_add_sensor(key, device_model, firmware, auto_sensors, manufactur
firmware = RENAMED_FIRMWARE_DICT.get(firmware, firmware)
manufacturer = RENAMED_MANUFACTURER_DICT.get(manufacturer, manufacturer)
# get all entities for this device
entity_list = hass.helpers.entity_registry.async_entries_for_device(
entity_list = entity_registry.async_entries_for_device(
registry=ent_registry, device_id=device_id, include_disabled_entities=False
)
# find the measurement key for each entity
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pytest-homeassistant-custom-component==0.13.109
pytest-homeassistant-custom-component==0.13.119

# BLE montitor requirements
pycryptodomex==3.19.1
Expand Down
Loading