Skip to content

Commit

Permalink
Adding integration version to logging
Browse files Browse the repository at this point in the history
  • Loading branch information
strawgate committed Jan 17, 2025
1 parent 4d458cc commit 3904db1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
17 changes: 16 additions & 1 deletion custom_components/elasticsearch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
from logging import Logger
from typing import TYPE_CHECKING

from elasticsearch.const import ELASTIC_DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady, IntegrationError
from homeassistant.loader import (
async_get_integration,
)

from custom_components.elasticsearch.config_flow import ElasticFlowHandler
from custom_components.elasticsearch.errors import (
Expand Down Expand Up @@ -38,7 +42,9 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ElasticIntegratio
# Create an specific logger for this config entry
_logger: Logger = have_child(name=config_entry.title)

_logger.info("Initializing integration for %s", config_entry.title)
version = await get_integration_version(hass)

_logger.info("Initializing integration v%s for %s", version, config_entry.title)

try:
integration = ElasticIntegration(hass=hass, config_entry=config_entry, log=_logger)
Expand Down Expand Up @@ -106,6 +112,15 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ElasticIntegrat

return True

async def get_integration_version(hass) -> str:
"""Return the version of the integration."""
integration = await async_get_integration(hass, ELASTIC_DOMAIN)

if integration is None or integration.version is None:
return "Unknown"

return integration.version.string


@log_enter_exit_debug
def migrate_data_and_options_to_version(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/elasticsearch/es_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry, log: Logger =
self._logger = log
self._config_entry = config_entry

self._logger.info("Initializing integration.")
self._logger.info("Initializing integration components.")

# Initialize our Elasticsearch Gateway
gateway_settings: Gateway8Settings = self.build_gateway_parameters(
Expand Down

0 comments on commit 3904db1

Please sign in to comment.