Skip to content

Commit 05b03a5

Browse files
committed
Only warn about new config once
1 parent 050dffb commit 05b03a5

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

custom_components/composite/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
CONF_OPTS,
3131
CONF_TIME_AS,
3232
CONF_TRACKERS,
33+
DATA_LEGACY_WARNED,
34+
DATA_TF,
3335
DOMAIN,
3436
TZ_DEVICE_LOCAL,
3537
TZ_DEVICE_UTC,
@@ -82,6 +84,8 @@ def _tracker_ids(value):
8284

8385

8486
async def async_setup(hass, config):
87+
hass.data[DOMAIN] = {DATA_LEGACY_WARNED: False}
88+
8589
# Get a list of all the object IDs in known_devices.yaml to see if any were created
8690
# when this integration was a legacy device tracker, or would otherwise conflict
8791
# with IDs in our config.
@@ -185,7 +189,7 @@ async def create_config(conf):
185189
from timezonefinder import TimezoneFinderL
186190

187191
tf = TimezoneFinderL()
188-
hass.data[DOMAIN] = tf
192+
hass.data[DOMAIN][DATA_TF] = tf
189193

190194
return True
191195

custom_components/composite/const.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
DOMAIN = "composite"
55

6+
DATA_LEGACY_WARNED = "legacy_warned"
7+
DATA_TF = "tf"
8+
69
CONF_ALL_STATES = "all_states"
710
CONF_ENTITY = "entity"
811
CONF_REQ_MOVEMENT = "require_movement"

custom_components/composite/device_tracker.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@
7171
CONF_REQ_MOVEMENT,
7272
CONF_TIME_AS,
7373
CONF_TRACKERS,
74+
DATA_LEGACY_WARNED,
75+
DATA_TF,
7476
DOMAIN,
7577
TIME_AS_OPTS,
7678
TZ_DEVICE_LOCAL,
@@ -141,30 +143,32 @@ def _entities(entities):
141143
def setup_scanner(hass, config, see, discovery_info=None):
142144
"""Set up a device scanner."""
143145
CompositeScanner(hass, config, see)
144-
_LOGGER.warning(
145-
'"%s: %s" under %s is deprecated. Move to "%s: %s"',
146-
CONF_PLATFORM,
147-
DOMAIN,
148-
DT_DOMAIN,
149-
DOMAIN,
150-
CONF_TRACKERS,
151-
)
152-
pn_async_create(
153-
hass,
154-
title="Composite configuration has changed",
155-
message="```text\n"
156-
f"{DT_DOMAIN}:\n"
157-
f"- platform: {DOMAIN}\n"
158-
" <TRACKER CONFIG>\n\n"
159-
"```\n"
160-
"is deprecated. Move to:\n\n"
161-
"```text\n"
162-
f"{DOMAIN}:\n"
163-
f" {CONF_TRACKERS}:\n"
164-
" - <TRACKER_CONFIG>\n"
165-
"```\n\n"
166-
"Also remove entries from known_devices.yaml.",
167-
)
146+
if not hass.data[DOMAIN][DATA_LEGACY_WARNED]:
147+
_LOGGER.warning(
148+
'"%s: %s" under %s is deprecated. Move to "%s: %s"',
149+
CONF_PLATFORM,
150+
DOMAIN,
151+
DT_DOMAIN,
152+
DOMAIN,
153+
CONF_TRACKERS,
154+
)
155+
pn_async_create(
156+
hass,
157+
title="Composite configuration has changed",
158+
message="```text\n"
159+
f"{DT_DOMAIN}:\n"
160+
f"- platform: {DOMAIN}\n"
161+
" <TRACKER CONFIG>\n\n"
162+
"```\n"
163+
"is deprecated. Move to:\n\n"
164+
"```text\n"
165+
f"{DOMAIN}:\n"
166+
f" {CONF_TRACKERS}:\n"
167+
" - <TRACKER_CONFIG>\n"
168+
"```\n\n"
169+
"Also remove entries from known_devices.yaml.",
170+
)
171+
hass.data[DOMAIN][DATA_LEGACY_WARNED] = True
168172
return True
169173

170174

@@ -322,7 +326,7 @@ def __init__(self, hass, config, see):
322326
self._entity_id = f"{DT_DOMAIN}.{self._dev_id}"
323327
self._time_as = config[CONF_TIME_AS]
324328
if self._time_as in [TZ_DEVICE_UTC, TZ_DEVICE_LOCAL]:
325-
self._tf = hass.data[DOMAIN]
329+
self._tf = hass.data[DOMAIN][DATA_TF]
326330
self._req_movement = config[CONF_REQ_MOVEMENT]
327331
self._lock = threading.Lock()
328332

0 commit comments

Comments
 (0)