Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
9dff7ab6
Commit
9dff7ab6
authored
2 years ago
by
J. Nick Koston
Committed by
Paulus Schoutsen
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Adjust time to remove stale connectable devices from the esphome ble to closer match bluez (#81356)
parent
d0ddbb5f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/esphome/bluetooth/scanner.py
+15
-1
15 additions, 1 deletion
homeassistant/components/esphome/bluetooth/scanner.py
with
15 additions
and
1 deletion
homeassistant/components/esphome/bluetooth/scanner.py
+
15
−
1
View file @
9dff7ab6
...
@@ -6,6 +6,7 @@ import datetime
...
@@ -6,6 +6,7 @@ import datetime
from
datetime
import
timedelta
from
datetime
import
timedelta
import
re
import
re
import
time
import
time
from
typing
import
Final
from
aioesphomeapi
import
BluetoothLEAdvertisement
from
aioesphomeapi
import
BluetoothLEAdvertisement
from
bleak.backends.device
import
BLEDevice
from
bleak.backends.device
import
BLEDevice
...
@@ -23,6 +24,15 @@ from homeassistant.util.dt import monotonic_time_coarse
...
@@ -23,6 +24,15 @@ from homeassistant.util.dt import monotonic_time_coarse
TWO_CHAR
=
re
.
compile
(
"
..
"
)
TWO_CHAR
=
re
.
compile
(
"
..
"
)
# The maximum time between advertisements for a device to be considered
# stale when the advertisement tracker can determine the interval for
# connectable devices.
#
# BlueZ uses 180 seconds by default but we give it a bit more time
# to account for the esp32's bluetooth stack being a bit slower
# than BlueZ's.
CONNECTABLE_FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
:
Final
=
195
class
ESPHomeScanner
(
BaseHaScanner
):
class
ESPHomeScanner
(
BaseHaScanner
):
"""
Scanner for esphome.
"""
"""
Scanner for esphome.
"""
...
@@ -45,8 +55,12 @@ class ESPHomeScanner(BaseHaScanner):
...
@@ -45,8 +55,12 @@ class ESPHomeScanner(BaseHaScanner):
self
.
_connector
=
connector
self
.
_connector
=
connector
self
.
_connectable
=
connectable
self
.
_connectable
=
connectable
self
.
_details
:
dict
[
str
,
str
|
HaBluetoothConnector
]
=
{
"
source
"
:
scanner_id
}
self
.
_details
:
dict
[
str
,
str
|
HaBluetoothConnector
]
=
{
"
source
"
:
scanner_id
}
self
.
_fallback_seconds
=
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
if
connectable
:
if
connectable
:
self
.
_details
[
"
connector
"
]
=
connector
self
.
_details
[
"
connector
"
]
=
connector
self
.
_fallback_seconds
=
(
CONNECTABLE_FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
)
@callback
@callback
def
async_setup
(
self
)
->
CALLBACK_TYPE
:
def
async_setup
(
self
)
->
CALLBACK_TYPE
:
...
@@ -61,7 +75,7 @@ class ESPHomeScanner(BaseHaScanner):
...
@@ -61,7 +75,7 @@ class ESPHomeScanner(BaseHaScanner):
expired
=
[
expired
=
[
address
address
for
address
,
timestamp
in
self
.
_discovered_device_timestamps
.
items
()
for
address
,
timestamp
in
self
.
_discovered_device_timestamps
.
items
()
if
now
-
timestamp
>
FALLBACK_MAXIMUM_STALE_ADVERTISEMENT_SECONDS
if
now
-
timestamp
>
self
.
_fallback_seconds
]
]
for
address
in
expired
:
for
address
in
expired
:
del
self
.
_discovered_device_advertisement_datas
[
address
]
del
self
.
_discovered_device_advertisement_datas
[
address
]
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment