Skip to content

Commit

Permalink
Log some mqtt of the discovery logging at debug level (home-assistant…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored May 10, 2024
1 parent 9f32164 commit 96ccf7f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,7 @@ def _async_mqtt_on_connect(

self.connected = True
async_dispatcher_send(self.hass, MQTT_CONNECTED)
_LOGGER.info(
_LOGGER.debug(
"Connected to MQTT server %s:%s (%s)",
self.conf[CONF_BROKER],
self.conf.get(CONF_PORT, DEFAULT_PORT),
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/mqtt/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def set_discovery_hash(hass: HomeAssistant, discovery_hash: tuple[str, str]) ->

@callback
def async_log_discovery_origin_info(
message: str, discovery_payload: MQTTDiscoveryPayload
message: str, discovery_payload: MQTTDiscoveryPayload, level: int = logging.INFO
) -> None:
"""Log information about the discovery and origin."""
if CONF_ORIGIN not in discovery_payload:
_LOGGER.info(message)
_LOGGER.log(level, message)
return
origin_info: MqttOriginInfo = discovery_payload[CONF_ORIGIN]
sw_version_log = ""
Expand All @@ -136,7 +136,8 @@ def async_log_discovery_origin_info(
support_url_log = ""
if support_url := origin_info.get("support_url"):
support_url_log = f", support URL: {support_url}"
_LOGGER.info(
_LOGGER.log(
level,
"%s from external application %s%s%s",
message,
origin_info["name"],
Expand Down Expand Up @@ -343,7 +344,7 @@ def discovery_done(_: Any) -> None:
elif already_discovered:
# Dispatch update
message = f"Component has already been discovered: {component} {discovery_id}, sending update"
async_log_discovery_origin_info(message, payload)
async_log_discovery_origin_info(message, payload, logging.DEBUG)
async_dispatcher_send(
hass, MQTT_DISCOVERY_UPDATED.format(*discovery_hash), payload
)
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/mqtt/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def __init__(
self._remove_device_updated = async_track_device_registry_updated_event(
hass, device_id, self._async_device_removed
)
_LOGGER.info(
_LOGGER.debug(
"%s %s has been initialized",
self.log_name,
discovery_hash,
Expand All @@ -837,7 +837,7 @@ async def async_discovery_update(
) -> None:
"""Handle discovery update."""
discovery_hash = get_discovery_hash(self._discovery_data)
_LOGGER.info(
_LOGGER.debug(
"Got update for %s with hash: %s '%s'",
self.log_name,
discovery_hash,
Expand All @@ -847,8 +847,8 @@ async def async_discovery_update(
discovery_payload
and discovery_payload != self._discovery_data[ATTR_DISCOVERY_PAYLOAD]
):
_LOGGER.info(
"%s %s updating",
_LOGGER.debug(
"Updating %s with hash %s",
self.log_name,
discovery_hash,
)
Expand All @@ -864,15 +864,15 @@ async def async_discovery_update(
)
await self._async_tear_down()
send_discovery_done(self.hass, self._discovery_data)
_LOGGER.info(
_LOGGER.debug(
"%s %s has been removed",
self.log_name,
discovery_hash,
)
else:
# Normal update without change
send_discovery_done(self.hass, self._discovery_data)
_LOGGER.info(
_LOGGER.debug(
"%s %s no changes",
self.log_name,
discovery_hash,
Expand Down

0 comments on commit 96ccf7f

Please sign in to comment.