Remove min rssi setting from iBeacon (#78843)

This commit is contained in:
J. Nick Koston 2022-09-22 17:39:00 -10:00 committed by GitHub
parent 0ccb495209
commit 2b8d582894
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 3 additions and 122 deletions

View File

@ -3,19 +3,11 @@ from __future__ import annotations
from typing import Any
import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components import bluetooth
from homeassistant.core import callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers.selector import (
NumberSelector,
NumberSelectorConfig,
NumberSelectorMode,
)
from .const import CONF_MIN_RSSI, DEFAULT_MIN_RSSI, DOMAIN
from .const import DOMAIN
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@ -37,38 +29,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
return self.async_create_entry(title="iBeacon Tracker", data={})
return self.async_show_form(step_id="user")
@staticmethod
@callback
def async_get_options_flow(
config_entry: config_entries.ConfigEntry,
) -> OptionsFlowHandler:
"""Get the options flow for this handler."""
return OptionsFlowHandler(config_entry)
class OptionsFlowHandler(config_entries.OptionsFlow):
"""Handle a option flow for iBeacons."""
def __init__(self, entry: config_entries.ConfigEntry) -> None:
"""Initialize options flow."""
self.entry = entry
async def async_step_init(self, user_input: dict | None = None) -> FlowResult:
"""Handle options flow."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
data_schema = vol.Schema(
{
vol.Required(
CONF_MIN_RSSI,
default=self.entry.options.get(CONF_MIN_RSSI) or DEFAULT_MIN_RSSI,
): NumberSelector(
NumberSelectorConfig(
min=-120, max=-30, step=1, mode=NumberSelectorMode.SLIDER
)
),
}
)
return self.async_show_form(step_id="init", data_schema=data_schema)

View File

@ -28,6 +28,3 @@ UPDATE_INTERVAL = timedelta(seconds=60)
MAX_IDS = 10
CONF_IGNORE_ADDRESSES = "ignore_addresses"
CONF_MIN_RSSI = "min_rssi"
DEFAULT_MIN_RSSI = -85

View File

@ -23,8 +23,6 @@ from homeassistant.helpers.event import async_track_time_interval
from .const import (
CONF_IGNORE_ADDRESSES,
CONF_MIN_RSSI,
DEFAULT_MIN_RSSI,
DOMAIN,
MAX_IDS,
SIGNAL_IBEACON_DEVICE_NEW,
@ -110,7 +108,6 @@ class IBeaconCoordinator:
"""Initialize the Coordinator."""
self.hass = hass
self._entry = entry
self._min_rssi = entry.options.get(CONF_MIN_RSSI) or DEFAULT_MIN_RSSI
self._dev_reg = registry
# iBeacon devices that do not follow the spec
@ -200,8 +197,6 @@ class IBeaconCoordinator:
"""Update from a bluetooth callback."""
if service_info.address in self._ignore_addresses:
return
if service_info.rssi < self._min_rssi:
return
if not (parsed := parse(service_info)):
return
group_id = f"{parsed.uuid}_{parsed.major}_{parsed.minor}"
@ -270,10 +265,6 @@ class IBeaconCoordinator:
cancel()
self._unavailable_trackers.clear()
async def _entry_updated(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
"""Handle options update."""
self._min_rssi = entry.options.get(CONF_MIN_RSSI) or DEFAULT_MIN_RSSI
@callback
def _async_check_unavailable_groups_with_random_macs(self) -> None:
"""Check for random mac groups that have not been seen in a while and mark them as unavailable."""
@ -349,7 +340,6 @@ class IBeaconCoordinator:
"""Start the Coordinator."""
self._async_restore_from_registry()
entry = self._entry
entry.async_on_unload(entry.add_update_listener(self._entry_updated))
entry.async_on_unload(
bluetooth.async_register_callback(
self.hass,

View File

@ -9,15 +9,5 @@
"description": "Do you want to setup iBeacon Tracker?"
}
}
},
"options": {
"step": {
"init": {
"data": {
"min_rssi": "Minimum RSSI"
},
"description": "iBeacons with an RSSI value lower than the Minimum RSSI will be ignored. If the integration is seeing neighboring iBeacons, increasing this value may help."
}
}
}
}

View File

@ -3,7 +3,7 @@
from unittest.mock import patch
from homeassistant import config_entries
from homeassistant.components.ibeacon.const import CONF_MIN_RSSI, DOMAIN
from homeassistant.components.ibeacon.const import DOMAIN
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry
@ -45,23 +45,3 @@ async def test_setup_user_already_setup(hass, enable_bluetooth):
)
assert result["type"] == FlowResultType.ABORT
assert result["reason"] == "single_instance_allowed"
async def test_options_flow(hass, enable_bluetooth):
"""Test setting up via user when already setup ."""
entry = MockConfigEntry(domain=DOMAIN)
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)
result = await hass.config_entries.options.async_init(entry.entry_id)
await hass.async_block_till_done()
assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "init"
result2 = await hass.config_entries.options.async_configure(
result["flow_id"], user_input={CONF_MIN_RSSI: -70}
)
assert result2["type"] == FlowResultType.CREATE_ENTRY
assert result2["data"] == {CONF_MIN_RSSI: -70}

View File

@ -5,7 +5,7 @@ from dataclasses import replace
import pytest
from homeassistant.components.ibeacon.const import CONF_MIN_RSSI, DOMAIN
from homeassistant.components.ibeacon.const import DOMAIN
from homeassistant.helpers.service_info.bluetooth import BluetoothServiceInfo
from . import BLUECHARM_BEACON_SERVICE_INFO
@ -54,39 +54,6 @@ async def test_many_groups_same_address_ignored(hass):
assert hass.states.get("sensor.bluecharm_177999_8105_estimated_distance") is None
async def test_ignore_anything_less_than_min_rssi(hass):
"""Test entities are not created when below the min rssi."""
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_MIN_RSSI: -60},
)
entry.add_to_hass(hass)
assert await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
inject_bluetooth_service_info(
hass, replace(BLUECHARM_BEACON_SERVICE_INFO, rssi=-100)
)
await hass.async_block_till_done()
assert hass.states.get("sensor.bluecharm_177999_8105_estimated_distance") is None
inject_bluetooth_service_info(
hass,
replace(
BLUECHARM_BEACON_SERVICE_INFO,
rssi=-10,
service_uuids=["0000180f-0000-1000-8000-00805f9b34fb"],
),
)
await hass.async_block_till_done()
assert (
hass.states.get("sensor.bluecharm_177999_8105_estimated_distance") is not None
)
async def test_ignore_not_ibeacons(hass):
"""Test we ignore non-ibeacon data."""
entry = MockConfigEntry(